diff --git a/db/mariadb.sql b/db/mariadb.sql
index aeb461f..508ff26 100644
--- a/db/mariadb.sql
+++ b/db/mariadb.sql
@@ -576,10 +576,11 @@ CREATE TABLE recordlock (
UNIQUE KEY ix_lock_token (token)
) ENGINE=MEMORY;
-/* Use with: UPDATE revision SET changed=CURRENT_TIMESTAMP WHERE revid=? */
+/* Use with: UPDATE revision SET changed=CURRENT_TIMESTAMP WHERE revtype=? AND revid=? */
CREATE TABLE revision (
+ revtype enum('dropdown','table') NOT NULL,
revid smallint(6) UNSIGNED NOT NULL,
changed timestamp NOT NULL,
- PRIMARY KEY (revid),
+ PRIMARY KEY (revtype, revid),
INDEX ix_revision_ts (changed) -- for select by timestamp
) ENGINE=MEMORY;
diff --git a/webgui/box.php b/webgui/box.php
index bc0f5ec..a173481 100644
--- a/webgui/box.php
+++ b/webgui/box.php
@@ -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 "
$pagetitle \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 '', "\n";
echo "\n";
@@ -122,6 +125,9 @@ foreach ($res as $row) {
echo "\n";
echo "\n";
}
+// Table summary
+$numrows = count($res);
+table_rec_summary($i, $numrows, $numrows, 6);
echo "
\n";
form_add_button('box.php');
diff --git a/webgui/cable.php b/webgui/cable.php
index edda1c3..9354e28 100644
--- a/webgui/cable.php
+++ b/webgui/cable.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;
diff --git a/webgui/checklist.php b/webgui/checklist.php
index 9b526f9..4634999 100644
--- a/webgui/checklist.php
+++ b/webgui/checklist.php
@@ -87,10 +87,17 @@ $res = $sth->fetchAll();
\n";
- echo '', $row['clid'], " \n";
+ echo '', $row['clid'];
+ echo ' ', "\n";
+ // TODO view icon
+ echo " \n";
echo '', $row['title'], " \n";
echo '', $row['clstate'], " \n";
- form_action_buttons($g_scriptname, $row['clid']);
+ // Edit current record button
+ echo '';
+ echo ' ', "\n";
+ echo " \n";
+
echo "\n";
}
// Table summary
diff --git a/webgui/company.php b/webgui/company.php
index 6761ec7..53e1b96 100644
--- a/webgui/company.php
+++ b/webgui/company.php
@@ -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;
diff --git a/webgui/dropdown.php b/webgui/dropdown.php
index 6c52356..04ec848 100644
--- a/webgui/dropdown.php
+++ b/webgui/dropdown.php
@@ -160,7 +160,6 @@ foreach ($sth->fetchAll() as $row) {
echo '';
echo '', $row['ddtext'], ' ';
echo '', $num[$row['ddval']] ?? 0, ' ';
- // form_action_buttons($g_scriptname, $row['ddval']);
echo "";
if ($row['flags'] == 'locked') {
echo _('Locked');
@@ -268,7 +267,6 @@ foreach ($sth->fetchAll() as $row) {
echo ' ';
echo ' ', "\n";
// TODO extend function to accept additional parameters
- // form_action_buttons($g_scriptname, $row['ddid'];
}
echo "\n";
}
diff --git a/webgui/equipment.php b/webgui/equipment.php
index 8bdfc65..e41923f 100644
--- a/webgui/equipment.php
+++ b/webgui/equipment.php
@@ -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;
diff --git a/webgui/fuse.php b/webgui/fuse.php
index 1914da4..8249049 100644
--- a/webgui/fuse.php
+++ b/webgui/fuse.php
@@ -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;
diff --git a/webgui/globals.inc b/webgui/globals.inc
index 7097cf5..dda67c2 100644
--- a/webgui/globals.inc
+++ b/webgui/globals.inc
@@ -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 '', "\n";
echo "
\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 '', "\n";
- echo "
\n";
-}
-
-function form_create_check($fieldname, $label, $checked) {
- // create single checkbox with assigned label
- echo '', "\n";
- echo ' ', $label, "\n";
+ echo ' \n";
- echo '', $label, " \n";
+ echo '">', "\n";
+ echo "
\n";
+}
+
+function form_create_textarea($fieldname, $label, $value) {
+ // TBD
+ echo '', "\n";
+ echo '', "\n";
echo "
\n";
}
@@ -879,6 +895,22 @@ function form_create_select($fieldname, $label, $optlist, $selval=NULL, $multipl
echo "\n";
}
+function form_create_option($fieldname, $label) {
+ // TBD
+}
+
+function form_create_check($fieldname, $label, $checked) {
+ // create single checkbox with assigned label
+ echo '', "\n";
+ echo ' \n";
+ echo '', $label, " \n";
+ echo "
\n";
+}
+
function form_create_checks($fieldname, $label, $optlist, $selected = []) {
// create multiple combined checkboxes with title
echo '';
@@ -897,14 +929,6 @@ function form_create_checks($fieldname, $label, $optlist, $selected = []) {
echo ' ';
}
-// TODO DEPRECATED for touch multiple adjacent buttuns are not well suited.
-function form_action_buttons($script, $id) {
- echo "";
- echo ' ', "\n";
- echo ' ', "\n";
- echo " \n";
-}
-
function form_add_button($script, $id=NULL, $idname='id') {
echo '\n";
echo "\n"; // row 2
diff --git a/webgui/inventory.php b/webgui/inventory.php
index 31c0a5e..c5846e0 100644
--- a/webgui/inventory.php
+++ b/webgui/inventory.php
@@ -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 "", _('Name'), " \n";
echo "", _('Container'), " \n";
echo "", _('Number'), " \n";
echo "", _('Condition'), " \n";
+echo "", _('Remarks'), " \n";
echo "", _('Tags'), " \n";
echo " \n";
echo "\n";
@@ -293,6 +296,7 @@ foreach ($res as $row) {
echo "", $row['container'], " \n";
echo "", $row['number'], " \n";
echo "", ($opt_invcond[$row['invcond']] ?? ''), " \n";
+ echo "", $row['remarks'], " \n";
echo "", _('No tags assigned'), " \n";
// Edit current record button
echo "";
@@ -301,7 +305,7 @@ foreach ($res as $row) {
echo "\n";
}
// Table summary
-table_rec_summary($i0, $i, $numrows, 7);
+table_rec_summary($i0, $i, $numrows, 8);
echo "\n";
echo $pagination;
diff --git a/webgui/lib/db.inc b/webgui/lib/db.inc
index c248115..2c28695 100644
--- a/webgui/lib/db.inc
+++ b/webgui/lib/db.inc
@@ -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)
diff --git a/webgui/note.php b/webgui/note.php
index 62aca2e..3a493b3 100644
--- a/webgui/note.php
+++ b/webgui/note.php
@@ -85,13 +85,18 @@ if ($action == ACT_DEFAULT):
echo '', $pagetitle, " \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();
+#
=_('ID')?>
=_('Reference')?>
=_('Type')?>
@@ -109,13 +115,21 @@ $res = $sth->fetchAll();
\n";
+ echo '', $i;
+ echo ' ', "\n";
+ echo " \n";
echo "", $row['noteid'], " \n";
echo "", $row['refid'], " \n";
echo "", $row['notetype'], " \n";
echo "", $row['annotation'], " \n";
- form_action_buttons($g_scriptname, $row['noteid']);
+ // Edit current record button
+ echo '';
+ echo ' ', "\n";
+ echo " \n";
echo "\n";
}
diff --git a/webgui/projects.php b/webgui/projects.php
index 3609668..66c22ce 100644
--- a/webgui/projects.php
+++ b/webgui/projects.php
@@ -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;
diff --git a/webgui/provisions.php b/webgui/provisions.php
index d92c57b..0908e60 100644
--- a/webgui/provisions.php
+++ b/webgui/provisions.php
@@ -380,6 +380,13 @@ elseif ($action == ACT_VIEW_LIST):
echo '', _('Shopping list'), " \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 "
diff --git a/webgui/storage.php b/webgui/storage.php
index e4b6296..39f36b7 100644
--- a/webgui/storage.php
+++ b/webgui/storage.php
@@ -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 "", _('Box'), " \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 '', "\n";
echo "\n";
diff --git a/webgui/tag.php b/webgui/tag.php
index 20a6907..a7b29db 100644
--- a/webgui/tag.php
+++ b/webgui/tag.php
@@ -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;