Webgui improve maintenance list and filter

This commit is contained in:
thooge committed 2026-10-21 20:06:15 +02:00
1 parent 06a9834688
commit c2df7e8013
3 files changed
+79 -22

No files matched your search

+29 -4
View File
@@ -32,6 +32,8 @@ switch ($submit = form_get_action()) {
$flt = array();
$flt['equip'] = gpc_get_int($_POST, 'flt_equip');
$flt['txt'] = gpc_get_string($_POST, 'flt_txt');
$allowed = db_load_enum('maintenance', 'maintstate');
$flt['status'] = gpc_get_set($_POST, 'flt_status', $allowed);
db_save_filter($flt, 204);
$action = ACT_DEFAULT;
break;
@@ -112,6 +114,9 @@ foreach ($opt_special + $opt_equipment as $k => $v) {
<label for="flt_txt">Text</label>
<input type="text" class="form-control" name="flt_txt" maxlength="30" value="<?=$flt->txt ?? ''?>">
</div>
<?php
filter_create_checks('flt_status', _('Status'), $opt_state, $flt->status ?? []);
?>
</div>
<div class="card-footer">
<button name="submit[filter]" class="btn btn-sm btn-primary" title="<?=_('Apply')?>"><?=_('Go')?></button>
@@ -139,6 +144,19 @@ if (strlen($flt->txt) > 1) {
$w[] = '(m.activities LIKE :txt OR m.remarks LIKE :txt)';
$p[':txt'] = '%'.$flt->txt.'%';
}
// condition for multiple flags is OR
// $parts = ["maintstate=''", 'maintstate IS NULL'];
$parts = [];
foreach ($flt->status as $s) {
$parts[] = "maintstate='$s'";
}
if (!empty($parts)) {
if (count($parts) > 1) {
$w[] = '(' . join(' OR ', $parts) . ')';
} else {
$w[] = $parts[0];
}
}
$where = join(' AND ', $w);
$order = ' ORDER BY m.maintid';
@@ -158,8 +176,10 @@ $page = gpc_get_int($_REQUEST, 'p', 1);
$rows_pp = gpc_get_int($_REQUEST, 'n', $user->rows_pp);
$lastpage = ceil($numrows/$rows_pp);
$sql = "SELECT m.maintid, m.activities, m.remarks, e.ename "
$sql = "SELECT m.maintid, m.activities, m.plan_date, m.interval_hours, m.maintstate, e.ename, "
. " IF(CHAR_LENGTH(m.remarks)>40, CONCAT(LEFT(m.remarks, 40), '\u{2026}'), m.remarks) AS remarks "
. "FROM maintenance AS m LEFT OUTER JOIN equipment AS e USING (eid)";
$sql .= ' WHERE ' . $where;
$sql .= $order;
@@ -180,6 +200,8 @@ echo "<tr>";
echo '<th>#</th>';
echo "<th>", _('Activities'), "</th>";
echo "<th>", _('Equipment'), "</th>";
echo "<th>", _('Upcoming'), "</th>"; // Date ou Hours
echo "<th>", _('Status'), "</th>";
echo "<th>", _('Remarks'), "</th>";
echo "</tr>\n";
echo "</thead>\n";
@@ -192,9 +214,12 @@ foreach ($res as $row) {
echo '<td>', $i;
echo '<a title="', _('View'), '" href="', $g_scriptname, '?f=view&id=', $row['maintid'], '"><i class="bi-eye ms-2"></i></a>', "\n";
echo "</td>\n";
echo "<td>". $row['activities'] ."</td>\n";
echo "<td>". $row['ename'] ."</td>\n";
echo "<td>". $row['remarks'] ."</td>\n";
echo "<td>", h($row['activities']) ,"</td>\n";
echo "<td>", $row['ename'] ,"</td>\n";
// next plan date or hours
echo "<td>", $row['plan_date'], "</td>\n";
echo "<td>", $row['maintstate'], "</td>\n";
echo "<td>", h($row['remarks']) ,"</td>\n";
echo "<td>";
// Edit current record button
echo '<a title="', _('Edit'), '" href="', $g_scriptname, '?f=edit&id=', $row['maintid'], '"><i class="bi-pencil"></i></a>', "\n";