More webgui work. Filters e.g.
This commit is contained in:
+42
-36
@@ -27,16 +27,12 @@ switch ($submit = form_get_action()) {
|
||||
case 'del': $action = ACT_DELETE; break;
|
||||
|
||||
case 'filter':
|
||||
// TODO save new filter settings
|
||||
$flt = array();
|
||||
$flt['cat'] = gpc_get_int($_POST, 'flt_category');
|
||||
$flt['manuf'] = gpc_get_int($_POST, 'flt_manuf');
|
||||
$flt['supp'] = gpc_get_int($_POST, 'flt_supp');
|
||||
$flt['txt'] = gpc_get_string($_POST, 'flt_txt');
|
||||
$sql = "UPDATE settings SET valstr=? WHERE userid=? AND sno=200";
|
||||
$sth = $pdo->prepare($sql);
|
||||
$sth->execute([json_encode($flt), $user->id]);
|
||||
// Only warning in case of failure
|
||||
db_save_filter($flt, 200);
|
||||
$action = ACT_DEFAULT;
|
||||
break;
|
||||
|
||||
@@ -54,6 +50,7 @@ switch ($submit = form_get_action()) {
|
||||
case 'update':
|
||||
$p[':eid'] = $id;
|
||||
$p[':ename'] = gpc_get_string($_POST, 'ename');
|
||||
$p[':shortname'] = gpc_get_string($_POST, 'shortname', 20);
|
||||
$p[':model'] = gpc_get_string($_POST, 'model');
|
||||
$p[':serial'] = gpc_get_string($_POST, 'serial');
|
||||
$p[':weight'] = min(gpc_get_float($_POST, 'weight'), 999.99); // limit max value
|
||||
@@ -185,21 +182,6 @@ if ($action == ACT_DEFAULT):
|
||||
|
||||
// load filter from db
|
||||
$flt = db_get_filter($user->id, 200);
|
||||
/*$flt = new stdClass();
|
||||
$sth = $pdo->prepare("SELECT valstr FROM settings WHERE userid=? AND sno=200");
|
||||
try {
|
||||
$sth->execute([$user->id]);
|
||||
$json = $sth->fetchColumn();
|
||||
if (!$json) {
|
||||
// no settings record. create empty one for later updates
|
||||
$sth = $pdo->prepare("INSERT INTO settings (userid, sno, valstr) VALUES (?, 200, '[]')");
|
||||
$sth->execute([$user->id]);
|
||||
} else {
|
||||
$flt = json_decode($json);
|
||||
}
|
||||
} catch (PDOexception $e) {
|
||||
$g_warning->Add('SQL-Error: '. $e->getMessage());
|
||||
} */
|
||||
|
||||
$sort = array(
|
||||
1 => 'ename',
|
||||
@@ -223,7 +205,7 @@ if ($flt->supp > 0) {
|
||||
$p[':supp'] = $flt->supp;
|
||||
}
|
||||
if (strlen($flt->txt) > 1) {
|
||||
$w[] = '(ename LIKE :txt OR model LIKE :txt OR remarks LIK :txt';
|
||||
$w[] = '(ename LIKE :txt OR model LIKE :txt OR remarks LIKE :txt)';
|
||||
$p[':txt'] = '%'.$flt->txt.'%';
|
||||
}
|
||||
$where = join(' AND ', $w);
|
||||
@@ -231,7 +213,13 @@ $order = ' ORDER BY ename';
|
||||
|
||||
// get total recond count for pagination and limit
|
||||
$sth = $pdo->prepare("SELECT COUNT(*) FROM equipment WHERE " . $where);
|
||||
$sth->execute($p);
|
||||
try {
|
||||
$sth->execute($p);
|
||||
} catch(PDOException $e) {
|
||||
$g_error->Add($e->getMessage());
|
||||
$g_error->Add($sql);
|
||||
$g_error->Add(print_r($p, true));
|
||||
}
|
||||
$numrows = $sth->fetchColumn();
|
||||
$lastpage = ceil($numrows/$g_rows_pp);
|
||||
$page = gpc_get_int($_REQUEST, 'p', 1);
|
||||
@@ -299,7 +287,7 @@ foreach ($opt_special + $opt_supplier as $k => $v) {
|
||||
</select>
|
||||
<label for="flt_txt">Text</label>
|
||||
<input type="text" name="flt_txt" size="15" maxlength="30" value="<?=$flt->txt?>">
|
||||
<button name="submit[filter]" class="btn btn-sm btn-primary" title="<?=_('Apply')?>">Go</button>
|
||||
<button name="submit[filter]" class="btn btn-sm btn-primary" title="<?=_('Apply')?>"><?=_('Go')?></button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
@@ -347,15 +335,6 @@ foreach ($res as $row) {
|
||||
</tfoot>
|
||||
</table>
|
||||
<?php
|
||||
/*
|
||||
<nav>
|
||||
<ul class="pagination justify-content-center">
|
||||
<li class="page-item"><a class="page-link" href="#">Previous</a></li>
|
||||
<li class="page-item"><a class="page-link" href="#">1</a></li>
|
||||
<li class="page-item"><a class="page-link" href="#">2</a></li>
|
||||
<li class="page-item"><a class="page-link" href="#">Next</a></li>
|
||||
</ul>
|
||||
</nav> */
|
||||
echo $pagination;
|
||||
|
||||
form_add_button($g_scriptname);
|
||||
@@ -394,7 +373,7 @@ elseif ($action == ACT_VIEW):
|
||||
// ========== VARIANT: view single record =====================================
|
||||
|
||||
$sql = "SELECT eid, ename, model, serial, purchdate, price, weight, "
|
||||
. " supplier, manufacturer, ecat, remarks "
|
||||
. " supplier, manufacturer, ecat, shortname, remarks "
|
||||
. "FROM equipment "
|
||||
. "WHERE eid=?";
|
||||
$sth = $pdo->prepare($sql);
|
||||
@@ -408,6 +387,7 @@ echo '<div class="row">';
|
||||
echo '<div class="col">';
|
||||
|
||||
echo '<table class="table">', "\n";
|
||||
echo '<tr><th>', _('Short name'),"</th><td>", $equipment->shortname, "</td></tr>\n";
|
||||
echo '<tr><th>', _('Manufacturer'),"</th><td>", $opt_manufacturer[$equipment->manufacturer], "</td></tr>\n";
|
||||
echo '<tr><th>', _('Model'),"</th><td>", $equipment->model, "</td></tr>\n";
|
||||
echo '<tr><th>', _('Serial'),"</th><td>", $equipment->serial, "</td></tr>\n";
|
||||
@@ -426,7 +406,8 @@ echo '<div class="col">';
|
||||
<?php
|
||||
$sql = "SELECT d.docid, d.doctype, d.title "
|
||||
. "FROM docref AS r INNER JOIN document AS d using (docid) "
|
||||
. "WHERE r.refid=?";
|
||||
. "WHERE r.refid=? "
|
||||
. "ORDER BY d.doctype";
|
||||
$sth = $pdo->prepare($sql);
|
||||
$sth->execute([$id]);
|
||||
$res = $sth->fetchAll();
|
||||
@@ -438,7 +419,8 @@ foreach ($res as $row) {
|
||||
echo "</a>\n";
|
||||
} elseif ($row['doctype'] == 'generic') {
|
||||
echo '<a href="dl.php?id=', $row['docid'], '">';
|
||||
echo $row['title'];
|
||||
echo '<img width="120" src="dl.php?id=', $row['docid'], '&t=s" alt="', $row['title'], '">';
|
||||
// echo $row['title'];
|
||||
echo "</a>\n";
|
||||
}
|
||||
}
|
||||
@@ -460,6 +442,26 @@ echo '</div>'; // container
|
||||
// Buttons at bottom of data area
|
||||
form_view_buttons($g_scriptname, $id);
|
||||
|
||||
|
||||
// Maintenance records
|
||||
|
||||
echo '<h3>', _('Maintenances'), "</h3>";
|
||||
|
||||
$sql = "SELECT maintid, series, activities FROM maintenance WHERE eid=?";
|
||||
$sth = $pdo->prepare($sql);
|
||||
$sth->execute([$id]);
|
||||
if ($sth->rowCount() > 0) {
|
||||
echo "<ul>\n";
|
||||
foreach ($sth->fetchAll() as $row) {
|
||||
echo "<li>", $row['activities'], ' ';
|
||||
echo '<a title="', _('View'), '" href="maintenance.php?f=view&id=', $row['maintid'], '"><i class="bi-eye"></i></a>';
|
||||
echo "</li>\n";
|
||||
}
|
||||
echo "</ul>\n";
|
||||
} else {
|
||||
echo '<p>', _('No maintenance records found.'), "<p>\n";
|
||||
}
|
||||
|
||||
elseif ($action == ACT_EDIT):
|
||||
// ========== VARIANT: edit single record =====================================
|
||||
|
||||
@@ -471,7 +473,7 @@ foreach ($sth->fetchAll() as $row) {
|
||||
}
|
||||
|
||||
$sql = "SELECT eid, ename, model, serial, weight, price, purchdate,"
|
||||
. " supplier, manufacturer, ecat, remarks "
|
||||
. " supplier, manufacturer, ecat, shortname, remarks "
|
||||
. "FROM equipment "
|
||||
. "WHERE eid=?";
|
||||
$sth = $pdo->prepare($sql);
|
||||
@@ -485,6 +487,10 @@ $equipment = $sth->fetch(PDO::FETCH_OBJ);
|
||||
<label for="ename" class="form-label"><?=_('Name')?></label>
|
||||
<input type="text" class="form-control" id="ename" name="ename" value="<?=$equipment->ename ?>">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="shortname" class="form-label"><?=_('Short name')?></label>
|
||||
<input type="text" class="form-control" id="shortname" name="shortname" value="<?=$equipment->shortname ?>">
|
||||
</div>
|
||||
<?php form_create_select('manufacturer', _('Manufacturer'), $opt_manufacturer, $equipment->manufacturer); ?>
|
||||
<div class="mb-3">
|
||||
<label for="model" class="form-label"><?=_('Model')?></label>
|
||||
|
||||
Reference in New Issue
Block a user