From 5fd6c68b4fd45d03d186cb870970e19ff1ba659d Mon Sep 17 00:00:00 2001 From: Thomas Hooge Date: Sun, 20 Sep 2026 09:19:18 +0200 Subject: [PATCH] Added position to equipment --- Makefile | 2 ++ db/mariadb.sql | 18 +++++++++++++----- db/minimal.sql | 4 +++- db/minimal_en.sql | 4 +++- webgui/equipment.php | 27 ++++++++++++++++++++++++--- webgui/lib/db.inc | 25 +++++++++++++++++++------ webgui/lib/gpc.inc | 18 +++++++++--------- webgui/storage.php | 2 +- 8 files changed, 74 insertions(+), 26 deletions(-) diff --git a/Makefile b/Makefile index 30ff7af..b9f7a9c 100644 --- a/Makefile +++ b/Makefile @@ -39,6 +39,8 @@ locale/de/LC_MESSAGES/ymsgui.mo: locale/de.po # Clean generated files clean: + find . -type d -name "__pycache__" -prune -exec rm -rf {} + + find . -type f -name "*.pyc" -delete rm -f locale/program.pot rm -f locale/ui.pot rm -f locale/combined.pot diff --git a/db/mariadb.sql b/db/mariadb.sql index b9ea87c..08fd26c 100644 --- a/db/mariadb.sql +++ b/db/mariadb.sql @@ -122,7 +122,7 @@ CREATE TABLE storage ( sname varchar(40) NOT NULL, stype tinyint(3) NOT NULL DEFAULT 0, -- ddid=3 capacity smallint(6) DEFAULT NULL, - capaunit enum('kg','l') DEFAULT NULL, + capaunit enum('kg','l','pcs') DEFAULT NULL, x smallint(6) UNSIGNED NOT NULL DEFAULT 0, y smallint(6) NOT NULL DEFAULT 0, z smallint(6) NOT NULL DEFAULT 0, @@ -205,6 +205,9 @@ CREATE TABLE equipment ( purchdate date DEFAULT NULL, price decimal(12,2) DEFAULT NULL, weight float(5,2) UNSIGNED DEFAULT NULL, + x smallint(6) UNSIGNED NOT NULL DEFAULT 0, + y smallint(6) NOT NULL DEFAULT 0, + z smallint(6) NOT NULL DEFAULT 0, remarks varchar(150) DEFAULT NULL, flags set('ordered','removed','deleted') DEFAULT NULL, PRIMARY KEY(eid), @@ -216,7 +219,12 @@ CREATE TABLE equipment ( ON DELETE RESTRICT, FOREIGN KEY fk_equipment_manufacturer (manufacturer) REFERENCES company(compid) - ON DELETE RESTRICT + ON DELETE RESTRICT, + CONSTRAINT chk_equipment_pos CHECK ( + (x IS NULL AND y IS NULL AND z IS NULL) + OR + (x IS NOT NULL AND y IS NOT NULL AND z IS NOT NULL) + ) ) ENGINE=InnoDB; CREATE TABLE inventory ( @@ -245,7 +253,7 @@ CREATE TABLE inventory ( FOREIGN KEY fk_inventory_equipment (eid) REFERENCES equipment(eid) ON DELETE RESTRICT, - CHECK ( + CONSTRAINT chk_inventory_stor CHECK ( (sid IS NOT NULL AND boxid IS NULL) OR (sid IS NULL AND boxid IS NOT NULL) @@ -306,7 +314,6 @@ CREATE table fuse ( ) ENGINE=InnoDB; -- change vals to decimal(12,4)? --- additional signalk id? CREATE TABLE measurement ( mid smallint(6) NOT NULL AUTO_INCREMENT, mname varchar(80) NOT NULL, @@ -518,7 +525,7 @@ CREATE TABLE checkref ( ON DELETE CASCADE ) ENGINE=InnoDB; -/* Expansion for future use: signalk mapping (just an idea) */ +/* Expansion for future use: signalk mapping (experimental) */ CREATE TABLE signalk ( skid int(10) NOT NULL AUTO_INCREMENT, vid smallint(6) NOT NULL, @@ -526,6 +533,7 @@ CREATE TABLE signalk ( objid int(10) NOT NULL, datatype enum('engine_hours','tank_level') NOT NULL, skpath varchar(255) NOT NULL, + mid smallint(6) DEFAULT NULL, PRIMARY KEY (skid), UNIQUE KEY ix_signalk (vid, objtype, objid, datatype), diff --git a/db/minimal.sql b/db/minimal.sql index 9a13a8a..692b5cf 100644 --- a/db/minimal.sql +++ b/db/minimal.sql @@ -18,7 +18,8 @@ INSERT INTO settings (userid, sno, valint, valstr) VALUES (0, 20, 1280, NULL), -- Image width limit (0, 21, 1024, NULL), -- Image height limit (0, 4, NULL, '€'), -- Currency symbol -(0, 5, 0, 'http://127.0.0.1:3000'); -- Signal K: to enable set valint=1 +(0, 5, 0, 'http://127.0.0.1:3000'), -- Signal K: to enable set valint=1 +(0, 6, 0, 'localhost:2597'); -- NMEA2000 (for future use) /* setting descriptions */ INSERT INTO settings (userid, sno, valstr) VALUES @@ -28,6 +29,7 @@ INSERT INTO settings (userid, sno, valstr) VALUES (-1, 3, 'user menu'), (-1, 4, 'currency symbol e.g. €, $, £, ¥'), (-1, 5, 'signalk connection'), +(-1, 6, 'nmea2000 connection'), (-1, 10, 'rows in table'), (-1, 20, 'maximum image width'), (-1, 21, 'maximum image height'), diff --git a/db/minimal_en.sql b/db/minimal_en.sql index 85dd6b4..488302f 100644 --- a/db/minimal_en.sql +++ b/db/minimal_en.sql @@ -18,7 +18,8 @@ INSERT INTO settings (userid, sno, valint, valstr) VALUES (0, 20, 1280, NULL), -- Image width limit (0, 21, 1024, NULL), -- Image height limit (0, 4, NULL, '€'), -- Currency symbol -(0, 5, 0, 'http://127.0.0.1:3000'); -- Signal K: to enable set valint=1 +(0, 5, 0, 'http://127.0.0.1:3000'), -- Signal K: to enable set valint=1 +(0, 6, 0, 'localhost:2597'); -- NMEA2000 (for future use) /* setting descriptions */ INSERT INTO settings (userid, sno, valstr) VALUES @@ -27,6 +28,7 @@ INSERT INTO settings (userid, sno, valstr) VALUES (-1, 3, 'user menu'), (-1, 4, 'currency symbol e.g. €, $, £, ¥'), (-1, 5, 'signalk connection'), +(-1, 6, 'nmea2000 connection'), (-1, 10, 'rows in table'), (-1, 20, 'maximum image width'), (-1, 21, 'maximum image height'), diff --git a/webgui/equipment.php b/webgui/equipment.php index fbbdbfd..783b5f6 100644 --- a/webgui/equipment.php +++ b/webgui/equipment.php @@ -75,6 +75,9 @@ switch ($submit = form_get_action()) { if ($p[':manufacturer'] <= 0) $p[':manufacturer'] = NULL; $p[':ecat'] = gpc_get_int($_POST, 'category'); if ($p[':ecat'] <= 0) $p[':ecat'] = NULL; + $p[':x'] = gpc_get_uint($_POST, 'x'); + $p[':y'] = gpc_get_int($_POST, 'y'); + $p[':z'] = gpc_get_int($_POST, 'z'); $p[':remarks'] = gpc_get_string($_POST, 'remarks', 150); $allowed = db_load_enum('equipment', 'flags'); $p[':flags'] = gpc_get_set($_POST, 'flags', $allowed, true, NULL); @@ -443,7 +446,8 @@ elseif ($action == ACT_VIEW): // ========== VARIANT: view single record ===================================== $sql = "SELECT eid, ename, model, serial, purchdate, price, weight, " - . " supplier, manufacturer, ecat, shortname, remarks, flags " + . "supplier, manufacturer, ecat, shortname, x, y, z, flags, " + . "remarks " . "FROM equipment " . "WHERE eid=?"; $sth = $pdo->prepare($sql); @@ -468,6 +472,9 @@ echo '', _('Price'),"", format_currency($equipment->price), "', _('Purchase date'),"", format_date($equipment->purchdate), "\n"; echo '', _('Supplier'),"", $equipment->supplier ? $opt_supplier[$equipment->supplier] : 'n/a', "\n"; echo '', _('Category'),"", $opt_ecat[$equipment->ecat], "\n"; +if (!empty($equipment->x)) { + echo '', _('Location (x, y, z)'),"(", $equipment->x, ', ', $equipment->y, ', ', $equipment->z, ")\n"; +} echo '', _('Remarks'),"", h($equipment->remarks, br:true), "\n"; echo '', _('Flags'),"", $equipment->flags, "\n"; echo "\n"; @@ -695,8 +702,8 @@ foreach ($sth->fetchAll() as $row) { $supplier[$row['compid']] = $row['compname']; } -$sql = "SELECT eid, ename, model, serial, weight, price, purchdate," - . " supplier, manufacturer, ecat, shortname, remarks, flags " +$sql = "SELECT eid, ename, model, serial, weight, price, purchdate, " + . "supplier, manufacturer, ecat, shortname, x, y, z, remarks, flags " . "FROM equipment " . "WHERE eid=?"; $sth = $pdo->prepare($sql); @@ -739,6 +746,20 @@ $equipment = $sth->fetch(PDO::FETCH_OBJ); form_create_select('supplier', _('Supplier'), $opt_supplier, $equipment->supplier); form_create_select('category', _('Category'), $g_opt_unknown + $opt_ecat, $equipment->ecat); ?> +
+ +
+
+ +
+
+ +
+
+ +
+
+
diff --git a/webgui/lib/db.inc b/webgui/lib/db.inc index e4741ff..98e7854 100644 --- a/webgui/lib/db.inc +++ b/webgui/lib/db.inc @@ -8,17 +8,31 @@ */ -function db_get_setting($sno, $default=NULL) { - // TODO WIP +function db_get_setting($sno, $userid, $autocreate=false, $default=NULL) { global $pdo; - $sql = "SELECT valint, valstr FROM settings WHERE userid=0 AND sno=?"; + global $g_error; + global $g_warning; + $sql = "SELECT valint, valstr FROM settings WHERE userid=? AND sno=?"; $sth = $pdo->prepare($sql); try { - $sth->execute([$sno]); + $sth->execute([$userid, $sno]); } catch (Exception $e) { + $g_error->Add('SQL-Error: '. $e->getMessage()); + $g_error->Add($sql); + $g_error->Add("userid=$userid, sno=$sno", true)); + return $default; + } + $row = $sth->fetch(); + if ($row === false) { + if ($autocreate) { + // create empty settings record if it not exists + $p[':userid'] = $userid; + $p[':sno'] = $sno; + db_exec_insert('settings', $p); + $g_warning->Add("Added missing settings record with id=$sno"); + } return $default; } - $row = $sth->fetchOne(); return $row; } @@ -61,7 +75,6 @@ function db_lock_refresh($token) { return $sth->rowCount() === 1; } - function db_lock_release($token) { global $pdo; $sql = "DELETE FROM recordlock WHERE token=?"; diff --git a/webgui/lib/gpc.inc b/webgui/lib/gpc.inc index 0fa16d9..c996710 100644 --- a/webgui/lib/gpc.inc +++ b/webgui/lib/gpc.inc @@ -13,7 +13,7 @@ function gpc_get_string(&$GPC, $varname, $maxlen = NULL, $default = NULL) { // TODO Parameter nullval: single value or array of values which considered as null // Default value for nullval is "-1" - if (!isset($GPC[$varname]) or (strlen(trim($GPC[$varname])) == 0)) { + if (!isset($GPC[$varname]) || (strlen(trim($GPC[$varname])) == 0)) { return $default; } $s = trim($GPC[$varname]); @@ -24,14 +24,14 @@ function gpc_get_string(&$GPC, $varname, $maxlen = NULL, $default = NULL) { } function gpc_get_int(&$GPC, $varname, $default = NULL) { - if (!isset($GPC[$varname])) { + if (!isset($GPC[$varname]) || $GPC[$varname] === '') { return $default; } return (int)$GPC[$varname]; } function gpc_get_uint(&$GPC, $varname, $default = NULL) { - if (!isset($GPC[$varname])) { + if (!isset($GPC[$varname]) || $GPC[$varname] === '') { return $default; } $val = (int)$GPC[$varname]; @@ -43,7 +43,7 @@ function gpc_get_uint(&$GPC, $varname, $default = NULL) { function gpc_get_float(&$GPC, $varname, $default = NULL) { global $g_lconv; - if (!isset($GPC[$varname]) or (strlen(trim($GPC[$varname])) == 0)) { + if (!isset($GPC[$varname]) || (strlen(trim($GPC[$varname])) == 0)) { return $default; } $var = str_replace($g_lconv['thousands_sep'], '', $GPC[$varname]); @@ -55,7 +55,7 @@ function gpc_get_float(&$GPC, $varname, $default = NULL) { function gpc_get_currency(&$GPC, $varname, $default = NULL) { global $g_lconv; - if (!isset($GPC[$varname]) or (strlen(trim($GPC[$varname])) == 0)) { + if (!isset($GPC[$varname]) || (strlen(trim($GPC[$varname])) == 0)) { return $default; } $var = str_replace($g_lconv['thousands_sep'], '', $GPC[$varname]); @@ -132,21 +132,21 @@ function gpc_get_datetime(&$GPC, $varname, $default = NULL) { } function gpc_get_color(&$GPC, $varname, $default = NULL) { - if (!isset($GPC[$varname]) or (strlen(trim($GPC[$varname])) == 0)) { + if (!isset($GPC[$varname]) || (strlen(trim($GPC[$varname])) == 0)) { return $default; } $color = $GPC[$varname]; - if ((strlen($color) == 7) and (substr($color, 0, 1) == '#')) { + if ((strlen($color) == 7) && (substr($color, 0, 1) == '#')) { $color = substr($color, 1); } - if ((strlen($color) != 6) or (! ctype_xdigit($color))) { + if ((strlen($color) != 6) || (! ctype_xdigit($color))) { return $default; } return strtoupper($color); } function gpc_get_enum(&$GPC, $varname, $values, $default = NULL) { - if (!isset($GPC[$varname]) or (strlen(trim($GPC[$varname])) == 0)) { + if (!isset($GPC[$varname]) || (strlen(trim($GPC[$varname])) == 0)) { return $default; } if (! in_array($GPC[$varname], $values)) { diff --git a/webgui/storage.php b/webgui/storage.php index 637b693..9f1d442 100644 --- a/webgui/storage.php +++ b/webgui/storage.php @@ -40,7 +40,7 @@ switch ($submit = form_get_action()) { $p[':sid'] = $id; $p[':sname'] = gpc_get_string($_POST, 'sname'); $p[':stype'] = gpc_get_string($_POST, 'stype'); - $p[':x'] = gpc_get_int($_POST, 'x'); + $p[':x'] = gpc_get_uint($_POST, 'x'); $p[':y'] = gpc_get_int($_POST, 'y'); $p[':z'] = gpc_get_int($_POST, 'z'); $p[':wx'] = gpc_get_int($_POST, 'wx');