Prepare combo list reload with revisions and fix box/storage in webgui
This commit is contained in:
1 parent
ee947b772f
commit
aee50ecb4f
17 files changed
+128
-43
No files matched your search
+10
-4
@@ -50,6 +50,7 @@ switch ($submit = form_get_action()) {
|
||||
$p[':content'] = gpc_get_string($_POST, 'content');
|
||||
$p[':remarks'] = gpc_get_string($_POST, 'remarks');
|
||||
$id = db_exec_insert('box', $p);
|
||||
db_set_revision('table', TBL_BOXES);
|
||||
$action = ACT_VIEW;
|
||||
break;
|
||||
|
||||
@@ -88,10 +89,12 @@ if ($action == ACT_DEFAULT):
|
||||
|
||||
echo "<h1>$pagetitle</h1>\n";
|
||||
|
||||
$sql = "SELECT boxid, boxtype, sid, label, color, content, weight, remarks "
|
||||
. "FROM box "
|
||||
. "ORDER BY label";
|
||||
$sth = $pdo->query($sql);
|
||||
$sql = "SELECT b.boxid, b.boxtype, b.sid, b.label, b.color, b.content, b.weight, b.remarks "
|
||||
. "FROM box AS b JOIN storage AS s USING (sid) "
|
||||
. "WHERE s.vid=? "
|
||||
. "ORDER BY b.label";
|
||||
$sth = $pdo->prepare($sql);
|
||||
$sth->execute([$user->vid]);
|
||||
$res = $sth->fetchAll();
|
||||
echo '<table class="table table-striped">', "\n";
|
||||
echo "<thead>\n";
|
||||
@@ -122,6 +125,9 @@ foreach ($res as $row) {
|
||||
echo "</td>\n";
|
||||
echo "</tr>\n";
|
||||
}
|
||||
// Table summary
|
||||
$numrows = count($res);
|
||||
table_rec_summary($i, $numrows, $numrows, 6);
|
||||
echo "</table>\n";
|
||||
|
||||
form_add_button('box.php');
|
||||
|
||||
@@ -47,6 +47,7 @@ switch ($submit = form_get_action()) {
|
||||
$p[':conductors'] = gpc_get_int($_POST, 'conductors');
|
||||
$p[':xsection'] = gpc_get_float($_POST, 'xsection');
|
||||
$id = db_exec_insert('cable', $p);
|
||||
db_set_revision('table', TBL_CABLES);
|
||||
$action = ACT_VIEW;
|
||||
break;
|
||||
|
||||
|
||||
@@ -87,10 +87,17 @@ $res = $sth->fetchAll();
|
||||
<?php
|
||||
foreach ($res as $row) {
|
||||
echo "<tr>\n";
|
||||
echo '<td>', $row['clid'], "</td>\n";
|
||||
echo '<td>', $row['clid'];
|
||||
echo '<a class="text-nowrap" title="', _('View'), '" href="', $g_scriptname, '?f=view&id=', $row['clid'], '"><i class="bi bi-eye ms-2"></i></a>', "\n";
|
||||
// TODO view icon
|
||||
echo "</td>\n";
|
||||
echo '<td>', $row['title'], "</td>\n";
|
||||
echo '<td>', $row['clstate'], "</td>\n";
|
||||
form_action_buttons($g_scriptname, $row['clid']);
|
||||
// Edit current record button
|
||||
echo '<td>';
|
||||
echo '<a title="', _('Edit'), '" href="', $g_scriptname, '?f=edit&id=', $row['clid'], '"><i class="bi-pencil"></i></a>', "\n";
|
||||
echo "</td>\n";
|
||||
|
||||
echo "</tr>\n";
|
||||
}
|
||||
// Table summary
|
||||
|
||||
@@ -43,6 +43,7 @@ switch ($submit = form_get_action()) {
|
||||
$p[':compname'] = gpc_get_string($_POST, 'compname');
|
||||
$p[':comptype'] = gpc_get_int($_POST, 'comptype');
|
||||
$id = db_exec_insert('company', $p);
|
||||
db_set_revision('table', TBL_COMPANIES);
|
||||
$action = ACT_VIEW;
|
||||
break;
|
||||
|
||||
|
||||
@@ -160,7 +160,6 @@ foreach ($sth->fetchAll() as $row) {
|
||||
echo '</td>';
|
||||
echo '<td>', $row['ddtext'], '</td>';
|
||||
echo '<td>', $num[$row['ddval']] ?? 0, '</td>';
|
||||
// form_action_buttons($g_scriptname, $row['ddval']);
|
||||
echo "<td>";
|
||||
if ($row['flags'] == 'locked') {
|
||||
echo _('Locked');
|
||||
@@ -268,7 +267,6 @@ foreach ($sth->fetchAll() as $row) {
|
||||
echo '<i class="bi-trash"></i>';
|
||||
echo '</td>', "\n";
|
||||
// TODO extend function to accept additional parameters
|
||||
// form_action_buttons($g_scriptname, $row['ddid'];
|
||||
}
|
||||
echo "</tr>\n";
|
||||
}
|
||||
|
||||
@@ -57,6 +57,7 @@ switch ($submit = form_get_action()) {
|
||||
$p[':model'] = gpc_get_string($_POST, 'model');
|
||||
$p[':remarks'] = gpc_get_string($_POST, 'remarks', 150);
|
||||
$id = db_exec_insert('equipment', $p);
|
||||
db_set_revision('table', TBL_EQUIPMENT);
|
||||
$action = ACT_VIEW;
|
||||
break;
|
||||
|
||||
|
||||
@@ -49,6 +49,7 @@ switch ($submit = form_get_action()) {
|
||||
$p[':location'] = gpc_get_int($_POST, 'location');;
|
||||
$p[':description'] = gpc_get_string($_POST, 'description');
|
||||
$id = db_exec_insert('fuse', $p);
|
||||
db_set_revision('table', TBL_FUSES);
|
||||
$action = ACT_VIEW;
|
||||
break;
|
||||
|
||||
|
||||
+46
-22
@@ -64,6 +64,19 @@ define('DD_INVENTORY_CATEGORY', 13);
|
||||
define('DD_BBN_VESSELDATA', 14);
|
||||
define('DD_MEASUREMENT_CATEGORY', 15);
|
||||
|
||||
// table indices which are used for combo lists
|
||||
define('TBL_VESSEL', 1);
|
||||
define('TBL_USERS', 2);
|
||||
define('TBL_COMPANIES', 3);
|
||||
define('TBL_STORAGE', 4);
|
||||
define('TBL_BOXES', 5);
|
||||
define('TBL_EQUIPMENT', 6);
|
||||
// define('TBL_INVENTORY', 7);
|
||||
define('TBL_PROJECTS', 8);
|
||||
define('TBL_CABLES', 9);
|
||||
define('TBL_FUSES', 10);
|
||||
define('TBL_TAGS', 11);
|
||||
|
||||
// ========== PAGE START CODE =================================================
|
||||
|
||||
// global version string
|
||||
@@ -840,27 +853,30 @@ function form_get_action() {
|
||||
return strtolower($submit);
|
||||
}
|
||||
|
||||
function form_create_input($fieldname, $label, $value) {
|
||||
function form_create_numeric($fieldname, $label, $value=NULL, $float=NULL) {
|
||||
// TODO WIP
|
||||
echo '<div class="mb-3">', "\n";
|
||||
echo "</div>\n";
|
||||
}
|
||||
|
||||
function form_create_text($fieldname, $label, $value) {
|
||||
// TODO WIP
|
||||
function form_create_text($fieldname, $label, $value=NULL, $maxlen=NULL) {
|
||||
// create generic text entry with assigned label
|
||||
// TODO maxlength, required, errortext
|
||||
echo '<div class="mb-3">', "\n";
|
||||
echo "</div>\n";
|
||||
}
|
||||
|
||||
function form_create_check($fieldname, $label, $checked) {
|
||||
// create single checkbox with assigned label
|
||||
echo '<div class="mb-3">', "\n";
|
||||
echo '<input type="checkbox" class="form-check-input" name="', $fieldname, '" id="', $fieldname, '"';
|
||||
if ($checked) {
|
||||
echo ' checked';
|
||||
echo '<label for="', $fieldname, '" class="form-label">', $label, "</label>\n";
|
||||
echo '<input type="text" class="form-control" id="', $fieldname, '" name="', $fieldname;
|
||||
if ($value !== NULL) {
|
||||
echo ' value="', $value, '"';
|
||||
}
|
||||
echo ">\n";
|
||||
echo '<label for="', $fieldname, '">', $label, "</label>\n";
|
||||
echo '">', "\n";
|
||||
echo "</div>\n";
|
||||
}
|
||||
|
||||
function form_create_textarea($fieldname, $label, $value) {
|
||||
// TBD
|
||||
echo '<div class="mb-3">', "\n";
|
||||
echo '<textarea>';
|
||||
echo '</textarea>', "\n";
|
||||
echo "</div>\n";
|
||||
}
|
||||
|
||||
@@ -879,6 +895,22 @@ function form_create_select($fieldname, $label, $optlist, $selval=NULL, $multipl
|
||||
echo "</div>\n";
|
||||
}
|
||||
|
||||
function form_create_option($fieldname, $label) {
|
||||
// TBD
|
||||
}
|
||||
|
||||
function form_create_check($fieldname, $label, $checked) {
|
||||
// create single checkbox with assigned label
|
||||
echo '<div class="mb-3">', "\n";
|
||||
echo '<input type="checkbox" class="form-check-input" name="', $fieldname, '" id="', $fieldname, '"';
|
||||
if ($checked) {
|
||||
echo ' checked';
|
||||
}
|
||||
echo ">\n";
|
||||
echo '<label for="', $fieldname, '">', $label, "</label>\n";
|
||||
echo "</div>\n";
|
||||
}
|
||||
|
||||
function form_create_checks($fieldname, $label, $optlist, $selected = []) {
|
||||
// create multiple combined checkboxes with title
|
||||
echo '<fieldset class="mb-3">';
|
||||
@@ -897,14 +929,6 @@ function form_create_checks($fieldname, $label, $optlist, $selected = []) {
|
||||
echo '</fieldset>';
|
||||
}
|
||||
|
||||
// TODO DEPRECATED for touch multiple adjacent buttuns are not well suited.
|
||||
function form_action_buttons($script, $id) {
|
||||
echo "<td>";
|
||||
echo '<a title="', _('View'), '" href="', $script, '?f=view&id=', $id, '"><i class="bi-eye"></i></a>', "\n";
|
||||
echo '<a title="', _('Edit'), '" href="', $script, '?f=edit&id=', $id, '"><i class="bi-pencil"></i></a>', "\n";
|
||||
echo "</td>\n";
|
||||
}
|
||||
|
||||
function form_add_button($script, $id=NULL, $idname='id') {
|
||||
echo '<div class="container-fluid px-0 my-3">', "\n";
|
||||
echo '<a href="', $script, '?f=add';
|
||||
|
||||
+2
-1
@@ -49,6 +49,7 @@ switch ($submit = form_get_action()) {
|
||||
$p[':model'] = gpc_get_string($_POST, 'model');
|
||||
$p[':remarks'] = gpc_get_string($_POST, 'remarks', 150);
|
||||
$id = db_exec_insert('vessel', $p);
|
||||
db_set_revision('table', TBL_VESSEL);
|
||||
// autoselect newly created vessel
|
||||
$sql = "UPDATE settings SET valint=? WHERE userid=? AND sno=1";
|
||||
$sth = $pdo->prepare($sql);
|
||||
@@ -179,7 +180,7 @@ if ($vessel->shipyard && $vessel->shipyard > 0) {
|
||||
}
|
||||
|
||||
if (strlen($vessel->remarks) > 0) {
|
||||
echo h($vessel->remarks, br:true);
|
||||
echo ' ', h($vessel->remarks, br:true);
|
||||
}
|
||||
echo "</div>\n";
|
||||
echo "</div>\n"; // row 2
|
||||
|
||||
@@ -180,10 +180,12 @@ $page = gpc_get_int($_REQUEST, 'p', 1);
|
||||
$rows_pp = gpc_get_int($_REQUEST, 'n', $user->rows_pp);
|
||||
$lastpage = ceil($numrows/$rows_pp);
|
||||
|
||||
$sql = "SELECT i.invid, i.invname, i.number, i.invcond, i.eid, s.sname AS container "
|
||||
$sql = "SELECT i.invid, i.invname, i.number, i.invcond, i.eid, s.sname AS container,"
|
||||
. " IF(CHAR_LENGTH(i.remarks)>40, CONCAT(LEFT(i.remarks, 40), '…'), i.remarks) AS remarks "
|
||||
. "FROM inventory AS i JOIN storage AS s ON (i.conttype='storage' AND i.sid=s.sid)";
|
||||
$sql .= ' WHERE ' . $where;
|
||||
$sql .= " UNION SELECT i.invid, i.invname, i.number, i.invcond, i.eid, b.label AS container "
|
||||
$sql .= " UNION SELECT i.invid, i.invname, i.number, i.invcond, i.eid, b.label AS container,"
|
||||
. " IF(CHAR_LENGTH(i.remarks)>40, CONCAT(LEFT(i.remarks, 40), '…'), i.remarks) AS remarks "
|
||||
. "FROM inventory AS i JOIN box AS b ON (i.conttype='box' AND i.boxid=b.boxid) "
|
||||
. " JOIN storage AS s ON (b.sid=s.sid) ";
|
||||
$sql .= ' WHERE ' . $where;
|
||||
@@ -275,6 +277,7 @@ echo "<th>", _('Name'), "</th>\n";
|
||||
echo "<th>", _('Container'), "</th>\n";
|
||||
echo "<th>", _('Number'), "</th>\n";
|
||||
echo "<th>", _('Condition'), "</th>\n";
|
||||
echo "<th>", _('Remarks'), "</th>\n";
|
||||
echo "<th>", _('Tags'), "</th>\n";
|
||||
echo "<td></td>\n";
|
||||
echo "</tr>\n";
|
||||
@@ -293,6 +296,7 @@ foreach ($res as $row) {
|
||||
echo "<td>", $row['container'], "</td>\n";
|
||||
echo "<td>", $row['number'], "</td>\n";
|
||||
echo "<td>", ($opt_invcond[$row['invcond']] ?? ''), "</td>\n";
|
||||
echo "<td>", $row['remarks'], "</td>\n";
|
||||
echo "<td>", _('No tags assigned'), "</td>\n";
|
||||
// Edit current record button
|
||||
echo "<td>";
|
||||
@@ -301,7 +305,7 @@ foreach ($res as $row) {
|
||||
echo "</tr>\n";
|
||||
}
|
||||
// Table summary
|
||||
table_rec_summary($i0, $i, $numrows, 7);
|
||||
table_rec_summary($i0, $i, $numrows, 8);
|
||||
echo "</table>\n";
|
||||
|
||||
echo $pagination;
|
||||
|
||||
@@ -53,6 +53,20 @@ function db_get_ddtext($ddid, $ddval) {
|
||||
return $sth->fetchColumn();
|
||||
}
|
||||
|
||||
function db_set_revision($revtype, $revid) {
|
||||
global $pdo;
|
||||
global $g_error;
|
||||
$sql = "INSERT INTO revision (revtype, revid, changed) "
|
||||
. "VALUES (?, ?, NOW()) "
|
||||
. "ON DUPLICATE KEY UPDATE changed = NOW()";
|
||||
try {
|
||||
$sth = $pdo->prepare($sql);
|
||||
$sth->execute([$revtype, $revid]);
|
||||
} catch(PDOException $e) {
|
||||
$g_error->Add($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// ========== OPTION FUNCTIONS ================================================
|
||||
|
||||
// Functions to get option lists (key/value)
|
||||
|
||||
+17
-3
@@ -85,13 +85,18 @@ if ($action == ACT_DEFAULT):
|
||||
|
||||
echo '<h1>', $pagetitle, "</h1>\n";
|
||||
|
||||
// TODO This is not so beautiful. Make it prettier
|
||||
$sql = "SELECT n.noteid, n.notetype, n.refid,"
|
||||
. " IF(CHAR_LENGTH(n.annotation) > 60, CONCAT(LEFT(n.annotation, 60), '…'), n.annotation) AS annotation "
|
||||
. "FROM note AS n JOIN task AS t ON (n.notetype='task' AND n.refid=t.taskid AND t.vid=:vid) "
|
||||
. "FROM note AS n LEFT OUTER JOIN task AS t ON (n.notetype='task' AND n.refid=t.taskid AND t.vid=:vid) "
|
||||
. "UNION "
|
||||
. "SELECT n.noteid, n.notetype, n.refid,"
|
||||
. " IF(CHAR_LENGTH(n.annotation) > 60, CONCAT(LEFT(n.annotation, 60), '…'), n.annotation) AS annotation "
|
||||
. "FROM note AS n JOIN maintenance AS m ON (n.notetype='maint' AND n.refid=m.maintid AND m.vid=:vid) "
|
||||
. "FROM note AS n LEFT OUTER JOIN maintenance AS m ON (n.notetype='maint' AND n.refid=m.maintid AND m.vid=:vid) "
|
||||
. "UNION "
|
||||
. "SELECT n.noteid, n.notetype, n.refid,"
|
||||
. " IF(CHAR_LENGTH(n.annotation) > 60, CONCAT(LEFT(n.annotation, 60), '…'), n.annotation) AS annotation "
|
||||
. "FROM note AS n LEFT OUTER JOIN equipment AS e ON (n.notetype='equip' AND n.refid=e.eid AND e.vid=:vid) "
|
||||
. "ORDER BY noteid";
|
||||
$sth = $pdo->prepare($sql);
|
||||
$sth->execute([':vid' => $user->vid]);
|
||||
@@ -101,6 +106,7 @@ $res = $sth->fetchAll();
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>#</th>
|
||||
<th><?=_('ID')?></th>
|
||||
<th><?=_('Reference')?></th>
|
||||
<th><?=_('Type')?></th>
|
||||
@@ -109,13 +115,21 @@ $res = $sth->fetchAll();
|
||||
</thead>
|
||||
<?php
|
||||
|
||||
$i = 0;
|
||||
foreach ($res as $row) {
|
||||
$i++; // record number
|
||||
echo "<tr>\n";
|
||||
echo '<td>', $i;
|
||||
echo '<a class="text-nowrap" title="', _('View'), '" href="', $g_scriptname, '?f=view&id=', $row['noteid'], '"><i class="bi bi-eye ms-2"></i></a>', "\n";
|
||||
echo "</td>\n";
|
||||
echo "<td>", $row['noteid'], "</td>\n";
|
||||
echo "<td>", $row['refid'], "</td>\n";
|
||||
echo "<td>", $row['notetype'], "</td>\n";
|
||||
echo "<td>", $row['annotation'], "</td>\n";
|
||||
form_action_buttons($g_scriptname, $row['noteid']);
|
||||
// Edit current record button
|
||||
echo '<td>';
|
||||
echo '<a title="', _('Edit'), '" href="', $g_scriptname, '?f=edit&id=', $row['noteid'], '"><i class="bi-pencil"></i></a>', "\n";
|
||||
echo "</td>\n";
|
||||
echo "</tr>\n";
|
||||
}
|
||||
|
||||
|
||||
@@ -69,6 +69,7 @@ switch ($submit = form_get_action()) {
|
||||
$p[':responsible'] = gpc_get_int($_POST, 'responsible');
|
||||
$p[':remarks'] = gpc_get_string($_POST, 'remarks', 150);
|
||||
$id = db_exec_insert('project', $p);
|
||||
db_set_revision('table', TBL_PROJECTS);
|
||||
$action = ACT_VIEW;
|
||||
break;
|
||||
|
||||
|
||||
@@ -380,6 +380,13 @@ elseif ($action == ACT_VIEW_LIST):
|
||||
|
||||
echo '<h2>', _('Shopping list'), "</h2>\n";
|
||||
|
||||
// TODO Distinguish between provisions belonging to the boat and provisions
|
||||
// that are freely available.
|
||||
// - storage with vid
|
||||
// - box in storage with vid
|
||||
// - box without sid is free
|
||||
// - prov without sid and boxid is free
|
||||
|
||||
$sql = "SELECT provid, provname, unit, target - number AS buy "
|
||||
. "FROM provisions "
|
||||
. "WHERE target IS NOT NULL AND number < target "
|
||||
|
||||
+7
-4
@@ -33,6 +33,7 @@ switch ($submit = form_get_action()) {
|
||||
$p[':sname'] = gpc_get_string($_POST, 'sname');
|
||||
$p[':stype'] = gpc_get_int($_POST, 'stype');
|
||||
$id = db_exec_insert('storage', $p);
|
||||
db_set_revision('table', TBL_STORAGE);
|
||||
$action = ACT_VIEW;
|
||||
break;
|
||||
|
||||
@@ -157,10 +158,12 @@ form_add_button($g_scriptname);
|
||||
|
||||
// Boxes
|
||||
echo "<h1>", _('Box'), "</h1>\n";
|
||||
$sql = "SELECT boxid, sid, label, color, content, remarks "
|
||||
. "FROM box "
|
||||
. "ORDER BY label";
|
||||
$sth = $pdo->query($sql);
|
||||
$sql = "SELECT b.boxid, b.sid, b.label, b.color, b.content, b.remarks "
|
||||
. "FROM box AS b JOIN storage AS s USING (sid) "
|
||||
. "WHERE s.vid=? "
|
||||
. "ORDER BY b.label";
|
||||
$sth = $pdo->prepare($sql);
|
||||
$sth->execute([$user->vid]);
|
||||
$res = $sth->fetchAll();
|
||||
echo '<table class="table table-striped">', "\n";
|
||||
echo "<thead>\n";
|
||||
|
||||
@@ -40,6 +40,7 @@ switch ($submit = form_get_action()) {
|
||||
case 'insert':
|
||||
$p[':tagname'] = gpc_get_string($_POST, 'tagname');;
|
||||
$id = db_exec_insert('tag', $p);
|
||||
db_set_revision('table', TBL_TAGS);
|
||||
$action = ACT_VIEW;
|
||||
break;
|
||||
|
||||
|
||||
Reference in new issue
Block a user