More webgui work. Filters e.g.
This commit is contained in:
+46
-9
@@ -26,6 +26,13 @@ switch ($submit = form_get_action()) {
|
||||
case 'edit': $action = ACT_EDIT; break;
|
||||
case 'del': $action = ACT_DELETE; break;
|
||||
|
||||
case 'filter':
|
||||
$flt = array();
|
||||
$flt['txt'] = gpc_get_string($_POST, 'flt_txt');
|
||||
db_save_filter($flt, 202);
|
||||
$action = ACT_DEFAULT;
|
||||
break;
|
||||
|
||||
case 'insert':
|
||||
$p[':provname'] = gpc_get_string($_POST, 'provname');
|
||||
$p[':number'] = gpc_get_int($_POST, 'number');
|
||||
@@ -74,14 +81,44 @@ require 'header.php';
|
||||
if ($action == ACT_DEFAULT):
|
||||
// ========== VARIANT: default behavior =======================================
|
||||
|
||||
echo "<h1>", $pagetitle, "</h1>\n";
|
||||
// load filter from db
|
||||
$flt = db_get_filter($user->id, 202);
|
||||
|
||||
$sql = "SELECT provid, provname, number, unit, storedate, shelflife, "
|
||||
$w = array('(vid=:vid OR sid IS NULL)');
|
||||
$p = array(':vid' => $user->vid);
|
||||
if (strlen($flt->txt) > 1) {
|
||||
$w[] = 'provname LIKE :txt';
|
||||
$p[':txt'] = '%'.$flt->txt.'%';
|
||||
}
|
||||
$where = join(' AND ', $w);
|
||||
|
||||
$order = ' ORDER BY provid';
|
||||
|
||||
// provisions can be assigned to a store or be free
|
||||
$sql = "SELECT provid, provname, number, unit, storedate, shelflife, sid,"
|
||||
. " DATEDIFF(shelflife, storedate) AS d0, DATEDIFF (CURDATE(), storedate) AS d1 "
|
||||
. "FROM provisions "
|
||||
. "ORDER BY provid";
|
||||
$sth = $pdo->query($sql);
|
||||
. "FROM provisions LEFT OUTER JOIN storage USING (sid)";
|
||||
$sql .= ' WHERE ' . $where;
|
||||
$sql .= $order;
|
||||
$sth = $pdo->prepare($sql);
|
||||
$sth->execute($p);
|
||||
$res = $sth->fetchAll();
|
||||
|
||||
echo "<h1>", $pagetitle, "</h1>\n";
|
||||
?>
|
||||
<form method="post" action="<?=$g_scriptname?>">
|
||||
<div id="filter" class="card">
|
||||
<div class="card-header">Filter</div>
|
||||
<div class="card-body">
|
||||
<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";
|
||||
@@ -96,7 +133,7 @@ echo "</tr>\n";
|
||||
echo "</thead>\n";
|
||||
foreach ($res as $row) {
|
||||
echo "<tr>\n";
|
||||
echo "<td>". $row['provname'] ."</td>\n";
|
||||
echo "<td>", ! isset($row['sid']) ? '<i class="bi bi-basket"></i> ' : '', $row['provname'], "</td>\n";
|
||||
echo "<td>". $row['number'] ."</td>\n";
|
||||
echo "<td>". $opt_unit[$row['unit']] ."</td>\n";
|
||||
echo "<td>". $row['storedate'] ."</td>\n";
|
||||
@@ -139,7 +176,7 @@ echo '<h2>', _('Add provisions'), "</h2>\n";
|
||||
<label for="shelflife"><?=_('Shelflife')?></label>
|
||||
<input type="date" class="form-control" id="shelflife" name="shelflife">
|
||||
</div>
|
||||
<?php form_create_select('sid', _('Storage'), $opt_storage); ?>
|
||||
<?php form_create_select('sid', _('Storage'), [-1 => '- none -'] + $opt_storage); ?>
|
||||
<div class="container-fluid px-0 my-3">
|
||||
<button type="submit" name="submit[insert]" class="btn btn-primary"><?=_('Save')?></button>
|
||||
<a href="<?=$g_scriptname?>" class="btn btn-secondary"><?=_('Back')?></a>
|
||||
@@ -163,8 +200,8 @@ echo '<table class="table">', "\n";
|
||||
echo '<tr><th style="width:20%">', _('Number'),"</th><td>", $prov->number, "</td></tr>\n";
|
||||
echo '<tr><th>', _('Unit'),"</th><td>", $opt_unit[$prov->unit], "</td></tr>\n";
|
||||
echo '<tr><th>', _('Storedate'),"</th><td>", $prov->storedate, "</td></tr>\n";
|
||||
echo '<tr><th>', _('Shelflife'),"</th><td>", $prov->shelflife, "</td></tr>\n";
|
||||
echo '<tr><th>', _('Storage'),"</th><td>", $opt_storage[$prov->sid], "</td></tr>\n";
|
||||
echo '<tr><th>', _('Shelflife'),"</th><td>$prov->shelflife</td></tr>\n";
|
||||
echo '<tr><th>', _('Storage'),"</th><td>", ($opt_storage[$prov->sid] ?? ''), "</td></tr>\n";
|
||||
echo "</table>\n";
|
||||
|
||||
form_view_buttons($g_scriptname, $id);
|
||||
|
||||
Reference in New Issue
Block a user