More webgui work. Filters e.g.
This commit is contained in:
+97
-17
@@ -13,6 +13,7 @@ $id = gpc_get_int($_REQUEST, 'id', 0);
|
||||
|
||||
$opt_storage = db_get_opt_storage($user->vid);
|
||||
$opt_box = db_get_opt_box($user->vid);
|
||||
$opt_invcond = db_load_enum('inventory', 'invcond', true, true);
|
||||
|
||||
// ========== ACTIONS START ===================================================
|
||||
|
||||
@@ -26,6 +27,12 @@ switch ($submit = form_get_action()) {
|
||||
case 'del': $action = ACT_DELETE; break;
|
||||
|
||||
case 'filter':
|
||||
$flt = array();
|
||||
$flt['stor'] = gpc_get_string($_POST, 'flt_stor');
|
||||
//$flt['box'] = gpc_get_string($_POST, 'flt_box');
|
||||
$flt['cond'] = gpc_get_string($_POST, 'flt_cond');
|
||||
$flt['txt'] = gpc_get_string($_POST, 'flt_txt');
|
||||
db_save_filter($flt, 201);
|
||||
$action = ACT_DEFAULT;
|
||||
break;
|
||||
|
||||
@@ -94,40 +101,113 @@ the box assignment. But this is also intentional to allow easy rearrangement.
|
||||
|
||||
echo "<h1>$pagetitle</h1>\n";
|
||||
|
||||
$w = array('vid=:vid');
|
||||
$p = array(':vid' => $user->vid);
|
||||
if ($flt->stor == -1) {
|
||||
$w[] = 'i.sid IS NULL';
|
||||
} elseif ($flt->stor > 0) {
|
||||
$w[] = 'i.sid=:sid';
|
||||
$p[':sid'] = $flt->stor;
|
||||
}
|
||||
/*if ($flt->cond <> 'all') {
|
||||
$w[] = 'indcond=:indcond';
|
||||
$p[':indcond'] = $flt->cond;
|
||||
}*/
|
||||
if (strlen($flt->txt) > 1) {
|
||||
$w[] = 'invname LIKE :txt';
|
||||
$p[':txt'] = '%'.$flt->txt.'%';
|
||||
}
|
||||
$where = join(' AND ', $w);
|
||||
$order = ' ORDER BY invname';
|
||||
|
||||
$sql = "SELECT i.invid, i.invname, i.number, i.invcond, s.sname AS container "
|
||||
. "FROM inventory AS i JOIN storage AS s ON (i.boxtype='storage' AND i.sid=s.sid)"
|
||||
. "WHERE s.vid=:vid "
|
||||
. "UNION "
|
||||
. "SELECT i.invid, i.invname, i.number, i.invcond, b.label AS container "
|
||||
. "FROM inventory AS i JOIN storage AS s ON (i.boxtype='storage' AND i.sid=s.sid)";
|
||||
$sql .= ' WHERE ' . $where;
|
||||
$sql .= " UNION SELECT i.invid, i.invname, i.number, i.invcond, b.label AS container "
|
||||
. "FROM inventory AS i JOIN box AS b ON (i.boxtype='box' AND i.boxid=b.boxid) "
|
||||
. " JOIN storage AS s ON (b.sid=s.sid) "
|
||||
. "WHERE s.vid=:vid "
|
||||
. "ORDER BY invname";
|
||||
. " JOIN storage AS s ON (b.sid=s.sid) ";
|
||||
$sql .= ' WHERE ' . $where;
|
||||
$sql .= $order;
|
||||
$sth = $pdo->prepare($sql);
|
||||
$sth->bindValue(':vid', $user->vid, PDO::PARAM_INT);
|
||||
$sth->execute();
|
||||
try {
|
||||
$sth->execute($p);
|
||||
} catch(PDOException $e) {
|
||||
$g_error->Add($e->getMessage());
|
||||
$g_error->Add($sql);
|
||||
$g_error->Add(print_r($p, true));
|
||||
}
|
||||
$res = $sth->fetchAll();
|
||||
|
||||
// Filter
|
||||
$opt_special = array(
|
||||
-2 => _('― all ―'),
|
||||
-1 => _('― none ―')
|
||||
);
|
||||
?>
|
||||
<form method="post" action="<?=$g_scriptname?>">
|
||||
<div id="filter" class="card">
|
||||
<div class="card-header">Filter</div>
|
||||
<div class="card-body">
|
||||
<?php
|
||||
// page specific filter start
|
||||
// - selection for storage
|
||||
// - selection for box
|
||||
// page specific filter end
|
||||
?>
|
||||
<label for="flt_stor"><?=_('Storage')?></label>
|
||||
<select id="flt_stor" name="flt_stor">
|
||||
<?php
|
||||
foreach ($opt_special + $opt_storage as $k => $v) {
|
||||
echo '<option value="', $k,'"';
|
||||
if ($k == $flt->stor) {
|
||||
echo ' selected';
|
||||
}
|
||||
echo '>', $v, '</option>';
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
<label for="flt_cond"><?=_('Condition')?></label>
|
||||
<select id="flt_cond" name="flt_cond">
|
||||
<?php
|
||||
foreach ($opt_special + $opt_invcond as $k => $v) {
|
||||
echo '<option value="', $k,'"';
|
||||
if ($k == $flt->cond) {
|
||||
echo ' selected';
|
||||
}
|
||||
echo '>', $v, '</option>';
|
||||
}
|
||||
?>
|
||||
</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>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<?php
|
||||
echo '<table class="table table-striped">', "\n";
|
||||
echo "<thead>\n";
|
||||
echo "<tr>\n";
|
||||
echo "<th>" . _('Name') . "</th>\n";
|
||||
echo "<th>" . _('Container') . "</th>";
|
||||
echo "<th>" . _('Number') . "</th>";
|
||||
echo "<th>" . _('Condition') . "</th>";
|
||||
echo "<th>", _('Name'), "</th>\n";
|
||||
echo "<th>", _('Container'), "</th>\n";
|
||||
echo "<th>", _('Number'), "</th>\n";
|
||||
echo "<th>", _('Condition'), "</th>\n";
|
||||
echo "<td></td>\n";
|
||||
echo "</tr>\n";
|
||||
echo "</thead>\n";
|
||||
foreach ($res as $row) {
|
||||
echo "<tr>\n";
|
||||
echo '<td>', $row['invname'], "</td>\n";
|
||||
echo "<td>". $row['container'] ."</td>\n";
|
||||
echo "<td>". $row['number'] ."</td>\n";
|
||||
echo "<td>". $row['invcond'] ."</td>\n";
|
||||
echo "<td>", $row['container'], "</td>\n";
|
||||
echo "<td>", $row['number'], "</td>\n";
|
||||
echo "<td>", ($opt_invcond[$row['invcond']] ?? ''), "</td>\n";
|
||||
form_action_buttons($g_scriptname, $row['invid']);
|
||||
echo "</tr>\n";
|
||||
}
|
||||
// Table summary
|
||||
echo "<tfoot>\n";
|
||||
echo '<tr><td colspan="6">', sprintf(_('%d records'), count($res)), '</td></tr>', "\n";
|
||||
echo '<tr><td colspan="5">', sprintf(_('%d records'), count($res)), '</td></tr>', "\n";
|
||||
echo "</tfoot>\n";
|
||||
echo "</table>\n";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user