Webgui: improve box, maintenance and date handling

This commit is contained in:
2026-09-16 06:12:50 +02:00
parent a76848e1da
commit 9b45fd3700
10 changed files with 116 additions and 31 deletions
+1 -3
View File
@@ -122,9 +122,6 @@ foreach ($res as $row) {
echo "</td>\n"; echo "</td>\n";
echo "</tr>\n"; echo "</tr>\n";
} }
// Table summary
$numrows = count($res);
table_rec_summary($i, $numrows, $numrows, 5);
echo "</table>\n"; echo "</table>\n";
form_add_button('box.php'); form_add_button('box.php');
@@ -187,6 +184,7 @@ echo '<table class="table">', "\n";
echo '<tr><th style="width:20%">', _('Box type'),"</th><td>", ($opt_boxtype[$box->boxtype] ?? ''), "</td></tr>\n"; echo '<tr><th style="width:20%">', _('Box type'),"</th><td>", ($opt_boxtype[$box->boxtype] ?? ''), "</td></tr>\n";
echo '<tr><th>', _('Content'),"</th><td>", $box->content, "</td></tr>\n"; echo '<tr><th>', _('Content'),"</th><td>", $box->content, "</td></tr>\n";
echo '<tr><th>', _('Color'), '</th><td>', format_color($box->color), "</td></tr>\n"; echo '<tr><th>', _('Color'), '</th><td>', format_color($box->color), "</td></tr>\n";
echo '<tr><th>', _('Dimensions'), '</th><td>', format_measurement(3, 'mm', $box->wx, $box->wy, $box->wz), "</td></tr>\n";
# TODO also show sum of content weights for comparison # TODO also show sum of content weights for comparison
echo '<tr><th>', _('Weight'), '</th><td>', format_float($box->weight, 2, 'kg'), "</td></tr>\n"; echo '<tr><th>', _('Weight'), '</th><td>', format_float($box->weight, 2, 'kg'), "</td></tr>\n";
echo '<tr><th>', _('Empty&nbsp;Weight'), '</th><td>', format_float($box->weight_net, 2, 'kg'), "</td></tr>\n"; echo '<tr><th>', _('Empty&nbsp;Weight'), '</th><td>', format_float($box->weight_net, 2, 'kg'), "</td></tr>\n";
+3 -3
View File
@@ -299,10 +299,10 @@ echo "</table>\n";
form_view_buttons($g_scriptname, $id); form_view_buttons($g_scriptname, $id);
// show referenced equipment // show referenced equipment for current vessel
$sql = "SELECT eid, ename FROM equipment WHERE supplier=:id OR manufacturer=:id"; $sql = "SELECT eid, ename FROM equipment WHERE vid=:vid AND (supplier=:id OR manufacturer=:id)";
$sth = $pdo->prepare($sql); $sth = $pdo->prepare($sql);
$sth->execute([':id' => $id]); $sth->execute([':vid' => $user->vid, ':id' => $id]);
if ($sth->rowCount() > 0) { if ($sth->rowCount() > 0) {
echo '<p>', _('Referenced in equipment'), ":</p>\n"; echo '<p>', _('Referenced in equipment'), ":</p>\n";
echo "<ul>\n"; echo "<ul>\n";
+4 -2
View File
@@ -91,6 +91,7 @@ switch ($submit = form_get_action()) {
} }
// for images check maximum size and scale down if needed // for images check maximum size and scale down if needed
if (($file_mimetype == 'image/png') or ($file_mimetype == 'image/jpeg')) {
if (isset($_POST['noscale'])) { if (isset($_POST['noscale'])) {
$g_message->Add(_('Image has not been scaled down')); $g_message->Add(_('Image has not been scaled down'));
} else { } else {
@@ -103,6 +104,7 @@ switch ($submit = form_get_action()) {
image_scale($file_tmp, $file_mimetype, $width, $height, $factor); image_scale($file_tmp, $file_mimetype, $width, $height, $factor);
} }
} }
}
// ok let's go // ok let's go
$file_hash = md5_file($file_tmp); $file_hash = md5_file($file_tmp);
@@ -590,9 +592,9 @@ foreach ($sth->fetchAll() as $row) {
$eids = array(); $eids = array();
$sql = "SELECT drid, reftype, refid, ename AS target " $sql = "SELECT drid, reftype, refid, ename AS target "
. "FROM docref INNER JOIN equipment ON (docref.reftype='equipment' AND docref.refid=equipment.eid) " . "FROM docref INNER JOIN equipment ON (docref.reftype='equipment' AND docref.refid=equipment.eid) "
. "WHERE docid=?"; . "WHERE docid=? AND vid=?";
$sth = $pdo->prepare($sql); $sth = $pdo->prepare($sql);
$sth->execute([$id]); $sth->execute([$id, $user->vid]);
foreach ($sth->fetchAll() as $row) { foreach ($sth->fetchAll() as $row) {
$references[] = $row; $references[] = $row;
$eids[] = $row['refid']; $eids[] = $row['refid'];
+9
View File
@@ -134,6 +134,15 @@ if ($g_db_scheme_version !== $g_db_scheme_required) {
$sth = $pdo->query("SELECT valint FROM settings WHERE userid=0 AND sno=4"); $sth = $pdo->query("SELECT valint FROM settings WHERE userid=0 AND sno=4");
$g_currsym = $sth->fetchColumn(); $g_currsym = $sth->fetchColumn();
// allowed date formats
$g_opt_datefmt = array(
'Y-m-d' => _('YYYY-MM-DD'),
'Y/m/d' => _('YYYY/MM/DD'),
'd.m.Y' => _('DD.MM.YYYY'),
'd/m/Y' => _('DD/MM/YYYY'),
'm-d-Y' => _('MM-DD-YYYY')
);
$user = User::GetInstance(); // There can be only one $user = User::GetInstance(); // There can be only one
if ($g_scriptname != 'login.php') { if ($g_scriptname != 'login.php') {
$user->init_from_session(); $user->init_from_session();
+14
View File
@@ -8,6 +8,20 @@
*/ */
function db_get_setting($sno, $default=NULL) {
// TODO WIP
global $pdo;
$sql = "SELECT valint, valstr FROM settings WHERE userid=0 AND sno=?";
$sth = $pdo->prepare($sql);
try {
$sth->execute([$sno]);
} catch (Exception $e) {
return $default;
}
$row = $sth->fetchOne();
return $row;
}
function db_lock_acquire($table, $key, $userid) { function db_lock_acquire($table, $key, $userid) {
global $pdo; global $pdo;
$token = bin2hex(random_bytes(8)); $token = bin2hex(random_bytes(8));
+36 -3
View File
@@ -83,11 +83,44 @@ function gpc_get_bool(&$GPC, $varname, $default = FALSE) {
} }
function gpc_get_date(&$GPC, $varname, $default = NULL) { function gpc_get_date(&$GPC, $varname, $default = NULL) {
// TODO improve global $g_opt_datefmt;
if (!isset($GPC[$varname]) || $GPC[$varname] == '') { if (!isset($GPC[$varname]) || !is_scalar($GPC[$varname])) {
return $default; return $default;
} }
return $GPC[$varname]; $value = trim((string)$GPC[$varname]);
if ($value === '') {
return $default;
}
foreach (array_keys($g_opt_datefmt) as $format) {
if (preg_match_all('/[Ymd]/', $format, $tokens) !== 3) {
continue;
}
$regex = preg_quote($format, '/');
$regex = str_replace('d', '(\d{2})', $regex);
$regex = str_replace('m', '(\d{2})', $regex);
$regex = str_replace('Y', '(\d{4})', $regex);
if (!preg_match('/^' . $regex . '$/', $value, $matches)) {
continue;
}
$year = $month = $day = NULL;
foreach ($tokens[0] as $i => $token) {
switch ($token) {
case 'Y':
$year = (int)$matches[$i + 1];
break;
case 'm':
$month = (int)$matches[$i + 1];
break;
case 'd':
$day = (int)$matches[$i + 1];
break;
}
}
if (checkdate($month, $day, $year)) {
return sprintf('%04d-%02d-%02d', $year, $month, $day);
}
}
return $default;
} }
function gpc_get_datetime(&$GPC, $varname, $default = NULL) { function gpc_get_datetime(&$GPC, $varname, $default = NULL) {
+29 -4
View File
@@ -55,6 +55,8 @@ switch ($submit = form_get_action()) {
$p[':activities'] = gpc_get_string($_POST, 'activities', 80); $p[':activities'] = gpc_get_string($_POST, 'activities', 80);
$p[':remarks'] = gpc_get_string($_POST, 'remarks', 150); $p[':remarks'] = gpc_get_string($_POST, 'remarks', 150);
$p[':series'] = gpc_get_int($_POST, 'series'); $p[':series'] = gpc_get_int($_POST, 'series');
$p[':plan_date'] = gpc_get_date($_POST, 'plan_date');
$p[':completion_date'] = gpc_get_date($_POST, 'completion_date');
$p[':maintstate'] = gpc_get_string($_POST, 'maintstate'); $p[':maintstate'] = gpc_get_string($_POST, 'maintstate');
db_exec_update('maintenance', $p, 'maintid'); db_exec_update('maintenance', $p, 'maintid');
$action = ACT_VIEW; $action = ACT_VIEW;
@@ -247,7 +249,8 @@ elseif ($action == ACT_VIEW):
echo '<h2>', _('View Maintenance'), "</h2>\n"; echo '<h2>', _('View Maintenance'), "</h2>\n";
// load maintenance record // load maintenance record
$sql = "SELECT m.activities, m.eid, m.remarks, m.series, m.maintstate, e.ename " $sql = "SELECT m.activities, m.eid, m.remarks, m.series, m.maintstate, e.ename, "
. "m.plan_date, m.completion_date, m.interval_hours, m.last_hours "
. "FROM maintenance AS m LEFT OUTER JOIN equipment AS e USING (eid) " . "FROM maintenance AS m LEFT OUTER JOIN equipment AS e USING (eid) "
. "WHERE m.maintid=?"; . "WHERE m.maintid=?";
$sth = $pdo->prepare($sql); $sth = $pdo->prepare($sql);
@@ -282,6 +285,10 @@ if (isset($maint->eid) and $maint->eid>0) {
echo "</td></tr>\n"; echo "</td></tr>\n";
echo '<tr><th>', _('Remarks'),"</th><td>", h($maint->remarks), "</td></tr>\n"; echo '<tr><th>', _('Remarks'),"</th><td>", h($maint->remarks), "</td></tr>\n";
echo '<tr><th>', _('Series'),"</th><td>", $maint->series, "</td></tr>\n"; echo '<tr><th>', _('Series'),"</th><td>", $maint->series, "</td></tr>\n";
echo '<tr><th>', _('Interval'),"</th><td>", $maint->interval_hours, " h</td></tr>\n";
echo '<tr><th>', _('Last'),"</th><td>", $maint->last_hours, "</td></tr>\n";
echo '<tr><th>', _('Plan date'),"</th><td>", format_date($maint->plan_date), "</td></tr>\n";
echo '<tr><th>', _('Completion&nbsp;date'),"</th><td>", format_date($maint->completion_date), "</td></tr>\n";
echo '<tr><th scope="row">', _('State'),"</th><td>", get_enum($maint->maintstate), "</td></tr>\n"; echo '<tr><th scope="row">', _('State'),"</th><td>", get_enum($maint->maintstate), "</td></tr>\n";
echo "</table>\n"; echo "</table>\n";
@@ -293,7 +300,9 @@ echo '<h4>Documents for ', h($maint->ename), "</h4>\n";
if (isset($docs)) { if (isset($docs)) {
echo '<ul>', "\n"; echo '<ul>', "\n";
foreach ($docs as $d) { foreach ($docs as $d) {
echo '<li>', $d['title'] ?? $d['filename'], ' (', $d['docid'], ")</li>\n"; echo '<li>', $d['title'] ?? $d['filename'], ' (', $d['docid'], ')';
echo ' <a href="documents.php?f=view&id=', $d['docid'], '"><i class="bi-eye"></i></a>';
echo "</li>\n";
} }
echo "</ul>\n"; echo "</ul>\n";
} else { } else {
@@ -332,7 +341,7 @@ echo "</div>\n";
elseif ($action == ACT_EDIT): elseif ($action == ACT_EDIT):
// ========== VARIANT: edit single record ===================================== // ========== VARIANT: edit single record =====================================
$sql = "SELECT activities, eid, remarks, series, maintstate " $sql = "SELECT activities, eid, remarks, series, plan_date, completion_date, maintstate "
. "FROM maintenance " . "FROM maintenance "
. "WHERE maintid=?"; . "WHERE maintid=?";
$sth = $pdo->prepare($sql); $sth = $pdo->prepare($sql);
@@ -351,12 +360,28 @@ echo '<h2>', _('Edit Maintenance'), "</h2>\n";
<?php form_create_select('eid', _('Equipment'), $opt_equipment, $maint->eid); ?> <?php form_create_select('eid', _('Equipment'), $opt_equipment, $maint->eid); ?>
<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($maint->remarks, br:true)?></textarea> <textarea class="form-control" id="remarks" name="remarks" rows="3"><?=h($maint->remarks)?></textarea>
</div> </div>
<div class="mb-3"> <div class="mb-3">
<label for="series" class="form-label"><?=_('Series')?></label> <label for="series" class="form-label"><?=_('Series')?></label>
<input type="text" class="form-control" id="series" name="series" maxlength="4" value="<?=$maint->series ?>"> <input type="text" class="form-control" id="series" name="series" maxlength="4" value="<?=$maint->series ?>">
</div> </div>
<div class="mb-3">
<label for="interval_hours" class="form-label"><?=_('Interval hours')?></label>
<input type="number" class="form-control" id="interval_hours" name="interval_hours" inputmode="numeric" maxlength="6" value="<?=$maint->interval_hours ?>">
</div>
<div class="mb-3">
<label for="last_hours" class="form-label"><?=_('Last hours')?></label>
<input type="number" class="form-control" id="last_hours" name="last_hours" inputmode="numeric" maxlength="6" value="<?=$maint->last_hours ?>">
</div>
<div class="mb-3">
<label for="plan_date"><?=_('Plan date')?></label>
<input type="date" class="form-control" id="plan_date" name="plan_date" value="<?=$maint->plan_date ?>">
</div>
<div class="mb-3">
<label for="completion_date"><?=_('Completion date')?></label>
<input type="date" class="form-control" id="completion_date" name="completion_date" value="<?=$maint->completion_date ?>">
</div>
<?php <?php
form_create_select('maintstate', _('Status'), $opt_state, $maint->maintstate); form_create_select('maintstate', _('Status'), $opt_state, $maint->maintstate);
+2 -2
View File
@@ -63,8 +63,8 @@ switch ($submit = form_get_action()) {
$p[':weight_net'] = min(gpc_get_float($_POST, 'weight_net'), 999.99); $p[':weight_net'] = min(gpc_get_float($_POST, 'weight_net'), 999.99);
$p[':unit'] = gpc_get_int($_POST, 'unit'); $p[':unit'] = gpc_get_int($_POST, 'unit');
$p[':calories'] = gpc_get_uint($_POST, 'calories'); $p[':calories'] = gpc_get_uint($_POST, 'calories');
$p[':storedate'] = gpc_get_string($_POST, 'storedate'); $p[':storedate'] = gpc_get_date($_POST, 'storedate');
$p[':shelflife'] = gpc_get_string($_POST, 'shelflife'); $p[':shelflife'] = gpc_get_date($_POST, 'shelflife');
$p[':price'] = gpc_get_currency($_POST, 'price'); $p[':price'] = gpc_get_currency($_POST, 'price');
$p[':sid'] = gpc_get_int($_POST, 'sid'); $p[':sid'] = gpc_get_int($_POST, 'sid');
if ($p[':sid'] <= 0) $p[':sid'] = NULL; if ($p[':sid'] <= 0) $p[':sid'] = NULL;
+7 -3
View File
@@ -86,13 +86,17 @@ if ($res = $sth->fetch(PDO::FETCH_NUM)) {
} }
$curdate = new DateTime(); $curdate = new DateTime();
$opt_datefmt = array( $opt_datefmt = array();
foreach ($g_opt_datefmt as $format => $description) {
$opt_datefmt[$format] = $description . $curdate->format(' - ' . $format);
}
/* $opt_datefmt = array(
'Y-m-d' => _('YYYY-MM-DD'). $curdate->format(' - Y-m-d'), 'Y-m-d' => _('YYYY-MM-DD'). $curdate->format(' - Y-m-d'),
'Y/m/d' => _('YYYY/MM/DD'). $curdate->format(' - Y/m/d'), 'Y/m/d' => _('YYYY/MM/DD'). $curdate->format(' - Y/m/d'),
'd.m.Y' => _('DD.MM.YYYY'). $curdate->format(' - d.m.Y'), 'd.m.Y' => _('DD.MM.YYYY'). $curdate->format(' - d.m.Y'),
'd/m/Y' => _('DD/MM/YYYY'). $curdate->format(' - d/m/Y'), 'd/m/Y' => _('DD/MM/YYYY'). $curdate->format(' - d/m/Y'),
'm-d-Y' => _('MM/DD/YYYY'). $curdate->format(' - m-d-Y') 'm-d-Y' => _('MM-DD-YYYY'). $curdate->format(' - m-d-Y')
); ); */
$rowspp = 10; $rowspp = 10;
$sql = "SELECT valint FROM settings WHERE userid=? AND sno=10"; $sql = "SELECT valint FROM settings WHERE userid=? AND sno=10";
+1 -1
View File
@@ -177,7 +177,7 @@ try {
} }
$numrows = $sth->fetchColumn(); $numrows = $sth->fetchColumn();
$page = gpc_get_int($_REQUEST, 'p', 1); $page = gpc_get_int($_REQUEST, 'p', 1);
$rows_pp = gpc_get_int($_REQUEST, 'n', $g_rows_pp); $rows_pp = gpc_get_int($_REQUEST, 'n', $user->rows_pp);
$lastpage = ceil($numrows/$rows_pp); $lastpage = ceil($numrows/$rows_pp);
$sql = "SELECT t.taskid, t.vid, t.projid, t.taskname, t.priority, t.taskstate," $sql = "SELECT t.taskid, t.vid, t.projid, t.taskname, t.priority, t.taskstate,"