Added position to equipment

This commit is contained in:
2026-09-20 09:19:18 +02:00
parent 2fc74c0677
commit 5fd6c68b4f
8 changed files with 74 additions and 26 deletions
+2
View File
@@ -39,6 +39,8 @@ locale/de/LC_MESSAGES/ymsgui.mo: locale/de.po
# Clean generated files # Clean generated files
clean: clean:
find . -type d -name "__pycache__" -prune -exec rm -rf {} +
find . -type f -name "*.pyc" -delete
rm -f locale/program.pot rm -f locale/program.pot
rm -f locale/ui.pot rm -f locale/ui.pot
rm -f locale/combined.pot rm -f locale/combined.pot
+13 -5
View File
@@ -122,7 +122,7 @@ CREATE TABLE storage (
sname varchar(40) NOT NULL, sname varchar(40) NOT NULL,
stype tinyint(3) NOT NULL DEFAULT 0, -- ddid=3 stype tinyint(3) NOT NULL DEFAULT 0, -- ddid=3
capacity smallint(6) DEFAULT NULL, 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, x smallint(6) UNSIGNED NOT NULL DEFAULT 0,
y smallint(6) NOT NULL DEFAULT 0, y smallint(6) NOT NULL DEFAULT 0,
z smallint(6) NOT NULL DEFAULT 0, z smallint(6) NOT NULL DEFAULT 0,
@@ -205,6 +205,9 @@ CREATE TABLE equipment (
purchdate date DEFAULT NULL, purchdate date DEFAULT NULL,
price decimal(12,2) DEFAULT NULL, price decimal(12,2) DEFAULT NULL,
weight float(5,2) UNSIGNED 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, remarks varchar(150) DEFAULT NULL,
flags set('ordered','removed','deleted') DEFAULT NULL, flags set('ordered','removed','deleted') DEFAULT NULL,
PRIMARY KEY(eid), PRIMARY KEY(eid),
@@ -216,7 +219,12 @@ CREATE TABLE equipment (
ON DELETE RESTRICT, ON DELETE RESTRICT,
FOREIGN KEY fk_equipment_manufacturer (manufacturer) FOREIGN KEY fk_equipment_manufacturer (manufacturer)
REFERENCES company(compid) 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; ) ENGINE=InnoDB;
CREATE TABLE inventory ( CREATE TABLE inventory (
@@ -245,7 +253,7 @@ CREATE TABLE inventory (
FOREIGN KEY fk_inventory_equipment (eid) FOREIGN KEY fk_inventory_equipment (eid)
REFERENCES equipment(eid) REFERENCES equipment(eid)
ON DELETE RESTRICT, ON DELETE RESTRICT,
CHECK ( CONSTRAINT chk_inventory_stor CHECK (
(sid IS NOT NULL AND boxid IS NULL) (sid IS NOT NULL AND boxid IS NULL)
OR OR
(sid IS NULL AND boxid IS NOT NULL) (sid IS NULL AND boxid IS NOT NULL)
@@ -306,7 +314,6 @@ CREATE table fuse (
) ENGINE=InnoDB; ) ENGINE=InnoDB;
-- change vals to decimal(12,4)? -- change vals to decimal(12,4)?
-- additional signalk id?
CREATE TABLE measurement ( CREATE TABLE measurement (
mid smallint(6) NOT NULL AUTO_INCREMENT, mid smallint(6) NOT NULL AUTO_INCREMENT,
mname varchar(80) NOT NULL, mname varchar(80) NOT NULL,
@@ -518,7 +525,7 @@ CREATE TABLE checkref (
ON DELETE CASCADE ON DELETE CASCADE
) ENGINE=InnoDB; ) ENGINE=InnoDB;
/* Expansion for future use: signalk mapping (just an idea) */ /* Expansion for future use: signalk mapping (experimental) */
CREATE TABLE signalk ( CREATE TABLE signalk (
skid int(10) NOT NULL AUTO_INCREMENT, skid int(10) NOT NULL AUTO_INCREMENT,
vid smallint(6) NOT NULL, vid smallint(6) NOT NULL,
@@ -526,6 +533,7 @@ CREATE TABLE signalk (
objid int(10) NOT NULL, objid int(10) NOT NULL,
datatype enum('engine_hours','tank_level') NOT NULL, datatype enum('engine_hours','tank_level') NOT NULL,
skpath varchar(255) NOT NULL, skpath varchar(255) NOT NULL,
mid smallint(6) DEFAULT NULL,
PRIMARY KEY (skid), PRIMARY KEY (skid),
UNIQUE KEY ix_signalk UNIQUE KEY ix_signalk
(vid, objtype, objid, datatype), (vid, objtype, objid, datatype),
+3 -1
View File
@@ -18,7 +18,8 @@ INSERT INTO settings (userid, sno, valint, valstr) VALUES
(0, 20, 1280, NULL), -- Image width limit (0, 20, 1280, NULL), -- Image width limit
(0, 21, 1024, NULL), -- Image height limit (0, 21, 1024, NULL), -- Image height limit
(0, 4, NULL, '€'), -- Currency symbol (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 */ /* setting descriptions */
INSERT INTO settings (userid, sno, valstr) VALUES INSERT INTO settings (userid, sno, valstr) VALUES
@@ -28,6 +29,7 @@ INSERT INTO settings (userid, sno, valstr) VALUES
(-1, 3, 'user menu'), (-1, 3, 'user menu'),
(-1, 4, 'currency symbol e.g. €, $, £, ¥'), (-1, 4, 'currency symbol e.g. €, $, £, ¥'),
(-1, 5, 'signalk connection'), (-1, 5, 'signalk connection'),
(-1, 6, 'nmea2000 connection'),
(-1, 10, 'rows in table'), (-1, 10, 'rows in table'),
(-1, 20, 'maximum image width'), (-1, 20, 'maximum image width'),
(-1, 21, 'maximum image height'), (-1, 21, 'maximum image height'),
+3 -1
View File
@@ -18,7 +18,8 @@ INSERT INTO settings (userid, sno, valint, valstr) VALUES
(0, 20, 1280, NULL), -- Image width limit (0, 20, 1280, NULL), -- Image width limit
(0, 21, 1024, NULL), -- Image height limit (0, 21, 1024, NULL), -- Image height limit
(0, 4, NULL, '€'), -- Currency symbol (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 */ /* setting descriptions */
INSERT INTO settings (userid, sno, valstr) VALUES INSERT INTO settings (userid, sno, valstr) VALUES
@@ -27,6 +28,7 @@ INSERT INTO settings (userid, sno, valstr) VALUES
(-1, 3, 'user menu'), (-1, 3, 'user menu'),
(-1, 4, 'currency symbol e.g. €, $, £, ¥'), (-1, 4, 'currency symbol e.g. €, $, £, ¥'),
(-1, 5, 'signalk connection'), (-1, 5, 'signalk connection'),
(-1, 6, 'nmea2000 connection'),
(-1, 10, 'rows in table'), (-1, 10, 'rows in table'),
(-1, 20, 'maximum image width'), (-1, 20, 'maximum image width'),
(-1, 21, 'maximum image height'), (-1, 21, 'maximum image height'),
+24 -3
View File
@@ -75,6 +75,9 @@ switch ($submit = form_get_action()) {
if ($p[':manufacturer'] <= 0) $p[':manufacturer'] = NULL; if ($p[':manufacturer'] <= 0) $p[':manufacturer'] = NULL;
$p[':ecat'] = gpc_get_int($_POST, 'category'); $p[':ecat'] = gpc_get_int($_POST, 'category');
if ($p[':ecat'] <= 0) $p[':ecat'] = NULL; 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); $p[':remarks'] = gpc_get_string($_POST, 'remarks', 150);
$allowed = db_load_enum('equipment', 'flags'); $allowed = db_load_enum('equipment', 'flags');
$p[':flags'] = gpc_get_set($_POST, 'flags', $allowed, true, NULL); $p[':flags'] = gpc_get_set($_POST, 'flags', $allowed, true, NULL);
@@ -443,7 +446,8 @@ elseif ($action == ACT_VIEW):
// ========== VARIANT: view single record ===================================== // ========== VARIANT: view single record =====================================
$sql = "SELECT eid, ename, model, serial, purchdate, price, weight, " $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 " . "FROM equipment "
. "WHERE eid=?"; . "WHERE eid=?";
$sth = $pdo->prepare($sql); $sth = $pdo->prepare($sql);
@@ -468,6 +472,9 @@ echo '<tr><th>', _('Price'),"</th><td>", format_currency($equipment->price), "</
echo '<tr><th>', _('Purchase date'),"</th><td>", format_date($equipment->purchdate), "</td></tr>\n"; echo '<tr><th>', _('Purchase date'),"</th><td>", format_date($equipment->purchdate), "</td></tr>\n";
echo '<tr><th>', _('Supplier'),"</th><td>", $equipment->supplier ? $opt_supplier[$equipment->supplier] : 'n/a', "</td></tr>\n"; echo '<tr><th>', _('Supplier'),"</th><td>", $equipment->supplier ? $opt_supplier[$equipment->supplier] : 'n/a', "</td></tr>\n";
echo '<tr><th>', _('Category'),"</th><td>", $opt_ecat[$equipment->ecat], "</td></tr>\n"; echo '<tr><th>', _('Category'),"</th><td>", $opt_ecat[$equipment->ecat], "</td></tr>\n";
if (!empty($equipment->x)) {
echo '<tr><th>', _('Location (x, y, z)'),"</th><td>(", $equipment->x, ', ', $equipment->y, ', ', $equipment->z, ")</td></tr>\n";
}
echo '<tr><th>', _('Remarks'),"</th><td>", h($equipment->remarks, br:true), "</td></tr>\n"; echo '<tr><th>', _('Remarks'),"</th><td>", h($equipment->remarks, br:true), "</td></tr>\n";
echo '<tr><th>', _('Flags'),"</th><td>", $equipment->flags, "</td></tr>\n"; echo '<tr><th>', _('Flags'),"</th><td>", $equipment->flags, "</td></tr>\n";
echo "</table>\n"; echo "</table>\n";
@@ -695,8 +702,8 @@ foreach ($sth->fetchAll() as $row) {
$supplier[$row['compid']] = $row['compname']; $supplier[$row['compid']] = $row['compname'];
} }
$sql = "SELECT eid, ename, model, serial, weight, price, purchdate," $sql = "SELECT eid, ename, model, serial, weight, price, purchdate, "
. " supplier, manufacturer, ecat, shortname, remarks, flags " . "supplier, manufacturer, ecat, shortname, x, y, z, remarks, flags "
. "FROM equipment " . "FROM equipment "
. "WHERE eid=?"; . "WHERE eid=?";
$sth = $pdo->prepare($sql); $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('supplier', _('Supplier'), $opt_supplier, $equipment->supplier);
form_create_select('category', _('Category'), $g_opt_unknown + $opt_ecat, $equipment->ecat); form_create_select('category', _('Category'), $g_opt_unknown + $opt_ecat, $equipment->ecat);
?> ?>
<div class="mb-3">
<label class="form-label"><?=_('Position (x, y, z) in mm')?></label>
<div class="row">
<div class="col">
<input type="number" class="form-control" id="x" name="x" min="0" value="<?=$equipment->x ?>">
</div>
<div class="col">
<input type="number" class="form-control" id="y" name="y" value="<?=$equipment->y ?>">
</div>
<div class="col">
<input type="number" class="form-control" id="z" name="z" value="<?=$equipment->z ?>">
</div>
</div>
</div>
<div class="mb-3"> <div class="mb-3">
<label for="remarks" class="form-label"><?=_('Remarks')?></label> <label for="remarks" class="form-label"><?=_('Remarks')?></label>
<textarea class="form-control" id="remarks" name="remarks" rows="3"><?=h($equipment->remarks, br:false)?></textarea> <textarea class="form-control" id="remarks" name="remarks" rows="3"><?=h($equipment->remarks, br:false)?></textarea>
+19 -6
View File
@@ -8,17 +8,31 @@
*/ */
function db_get_setting($sno, $default=NULL) { function db_get_setting($sno, $userid, $autocreate=false, $default=NULL) {
// TODO WIP
global $pdo; 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); $sth = $pdo->prepare($sql);
try { try {
$sth->execute([$sno]); $sth->execute([$userid, $sno]);
} catch (Exception $e) { } 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; return $default;
} }
$row = $sth->fetchOne();
return $row; return $row;
} }
@@ -61,7 +75,6 @@ function db_lock_refresh($token) {
return $sth->rowCount() === 1; return $sth->rowCount() === 1;
} }
function db_lock_release($token) { function db_lock_release($token) {
global $pdo; global $pdo;
$sql = "DELETE FROM recordlock WHERE token=?"; $sql = "DELETE FROM recordlock WHERE token=?";
+9 -9
View File
@@ -13,7 +13,7 @@
function gpc_get_string(&$GPC, $varname, $maxlen = NULL, $default = NULL) { function gpc_get_string(&$GPC, $varname, $maxlen = NULL, $default = NULL) {
// TODO Parameter nullval: single value or array of values which considered as null // TODO Parameter nullval: single value or array of values which considered as null
// Default value for nullval is "-1" // 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; return $default;
} }
$s = trim($GPC[$varname]); $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) { function gpc_get_int(&$GPC, $varname, $default = NULL) {
if (!isset($GPC[$varname])) { if (!isset($GPC[$varname]) || $GPC[$varname] === '') {
return $default; return $default;
} }
return (int)$GPC[$varname]; return (int)$GPC[$varname];
} }
function gpc_get_uint(&$GPC, $varname, $default = NULL) { function gpc_get_uint(&$GPC, $varname, $default = NULL) {
if (!isset($GPC[$varname])) { if (!isset($GPC[$varname]) || $GPC[$varname] === '') {
return $default; return $default;
} }
$val = (int)$GPC[$varname]; $val = (int)$GPC[$varname];
@@ -43,7 +43,7 @@ function gpc_get_uint(&$GPC, $varname, $default = NULL) {
function gpc_get_float(&$GPC, $varname, $default = NULL) { function gpc_get_float(&$GPC, $varname, $default = NULL) {
global $g_lconv; global $g_lconv;
if (!isset($GPC[$varname]) or (strlen(trim($GPC[$varname])) == 0)) { if (!isset($GPC[$varname]) || (strlen(trim($GPC[$varname])) == 0)) {
return $default; return $default;
} }
$var = str_replace($g_lconv['thousands_sep'], '', $GPC[$varname]); $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) { function gpc_get_currency(&$GPC, $varname, $default = NULL) {
global $g_lconv; global $g_lconv;
if (!isset($GPC[$varname]) or (strlen(trim($GPC[$varname])) == 0)) { if (!isset($GPC[$varname]) || (strlen(trim($GPC[$varname])) == 0)) {
return $default; return $default;
} }
$var = str_replace($g_lconv['thousands_sep'], '', $GPC[$varname]); $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) { 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; return $default;
} }
$color = $GPC[$varname]; $color = $GPC[$varname];
if ((strlen($color) == 7) and (substr($color, 0, 1) == '#')) { if ((strlen($color) == 7) && (substr($color, 0, 1) == '#')) {
$color = substr($color, 1); $color = substr($color, 1);
} }
if ((strlen($color) != 6) or (! ctype_xdigit($color))) { if ((strlen($color) != 6) || (! ctype_xdigit($color))) {
return $default; return $default;
} }
return strtoupper($color); return strtoupper($color);
} }
function gpc_get_enum(&$GPC, $varname, $values, $default = NULL) { 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; return $default;
} }
if (! in_array($GPC[$varname], $values)) { if (! in_array($GPC[$varname], $values)) {
+1 -1
View File
@@ -40,7 +40,7 @@ switch ($submit = form_get_action()) {
$p[':sid'] = $id; $p[':sid'] = $id;
$p[':sname'] = gpc_get_string($_POST, 'sname'); $p[':sname'] = gpc_get_string($_POST, 'sname');
$p[':stype'] = gpc_get_string($_POST, 'stype'); $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[':y'] = gpc_get_int($_POST, 'y');
$p[':z'] = gpc_get_int($_POST, 'z'); $p[':z'] = gpc_get_int($_POST, 'z');
$p[':wx'] = gpc_get_int($_POST, 'wx'); $p[':wx'] = gpc_get_int($_POST, 'wx');