Ongoing webgui work

This commit is contained in:
2025-04-01 14:49:03 +02:00
parent 0c09ce2916
commit c293ca1caa
20 changed files with 572 additions and 166 deletions
+46 -25
View File
@@ -14,6 +14,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);
$opt_equipment = db_get_opt_equip($user->vid, [-1 => _('― none ―')]);
// ========== ACTIONS START ===================================================
@@ -59,6 +60,7 @@ switch ($submit = form_get_action()) {
$p[':purchdate'] = gpc_get_date($_POST, 'purchdate');
$p[':invcond'] = gpc_get_string($_POST, 'invcond');
$p[':remarks'] = gpc_get_string($_POST, 'remarks', 150);
$p[':eid'] = gpc_get_int($_POST, 'eid');
db_exec_update('inventory', $p, 'invid');
$action = ACT_VIEW;
break;
@@ -92,6 +94,8 @@ require 'header.php';
if ($action == ACT_DEFAULT):
// ========== VARIANT: default behavior =======================================
page_caption_search($pagetitle);
$flt = db_get_filter($user->id, 201);
/*
@@ -99,8 +103,6 @@ The only way to find out whether the inventory is on the current boat is to use
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) {
@@ -109,10 +111,10 @@ if ($flt->stor == -1) {
$w[] = 'i.sid=:sid';
$p[':sid'] = $flt->stor;
}
/*if ($flt->cond <> 'all') {
$w[] = 'indcond=:indcond';
$p[':indcond'] = $flt->cond;
}*/
if (strlen($flt->cond) > 2 ) {
$w[] = 'invcond=:invcond';
$p[':invcond'] = $flt->cond;
}
if (strlen($flt->txt) > 1) {
$w[] = 'invname LIKE :txt';
$p[':txt'] = '%'.$flt->txt.'%';
@@ -120,6 +122,22 @@ if (strlen($flt->txt) > 1) {
$where = join(' AND ', $w);
$order = ' ORDER BY invname';
$sql = "SELECT "
. "(SELECT COUNT(*) FROM inventory AS i JOIN storage AS s ON (i.conttype='storage' AND i.sid=s.sid) WHERE $where)"
. "+"
. "(SELECT COUNT(*) FROM inventory AS i JOIN box AS b ON (i.conttype='box' AND i.boxid=b.boxid) JOIN storage AS s ON (b.sid=s.sid) WHERE $where)";
$sth = $pdo->prepare($sql);
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);
$sql = "SELECT i.invid, i.invname, i.number, i.invcond, s.sname AS container "
. "FROM inventory AS i JOIN storage AS s ON (i.conttype='storage' AND i.sid=s.sid)";
$sql .= ' WHERE ' . $where;
@@ -128,6 +146,10 @@ $sql .= " UNION SELECT i.invid, i.invname, i.number, i.invcond, b.label AS conta
. " JOIN storage AS s ON (b.sid=s.sid) ";
$sql .= ' WHERE ' . $where;
$sql .= $order;
// if pagination:
$sql .= ' LIMIT ' . ($page - 1) * $g_rows_pp . ',' . $g_rows_pp;
$sth = $pdo->prepare($sql);
try {
$sth->execute($p);
@@ -169,6 +191,9 @@ foreach ($opt_special + $opt_storage as $k => $v) {
<label for="flt_cond"><?=_('Condition')?></label>
<select id="flt_cond" name="flt_cond">
<?php
$opt_special = array(
-2 => _('&horbar; all &horbar;'),
);
foreach ($opt_special + $opt_invcond as $k => $v) {
echo '<option value="', $k,'"';
if ($k == $flt->cond) {
@@ -186,6 +211,10 @@ foreach ($opt_special + $opt_invcond as $k => $v) {
</form>
<?php
// Pagination on top
$pagination = get_pagination($g_scriptname, '', $page, $lastpage);
echo $pagination;
echo '<table class="table table-striped">', "\n";
echo "<thead>\n";
echo "<tr>\n";
@@ -213,6 +242,8 @@ echo '<tr><td colspan="5">', sprintf(_('%d records'), count($res)), '</td></tr>'
echo "</tfoot>\n";
echo "</table>\n";
echo $pagination;
form_add_button($g_scriptname);
elseif ($action == ACT_ADD):
@@ -299,10 +330,11 @@ echo "<tr><th>", _('Number'), "</th><td>", $inventory->number, "</td></tr>\n";
echo "<tr><th>", _('Weight'), "</th><td>", format_float($inventory->weight, 2, 'kg'), "</td></tr>\n";
echo "<tr><th>", _('Price'), "</th><td>", format_currency($inventory->price), "</td></tr>\n";
echo "<tr><th>", _('Purchase date'), "</th><td>", $inventory->purchdate, "</td></tr>\n";
echo "<tr><th>", _('Condition'), "</th><td>", $inventory->invcond, "</td></tr>\n";
echo "<tr><th>", _('Condition'), "</th><td>", $opt_invcond[$inventory->invcond], "</td></tr>\n";
echo "<tr><th>", _('Remarks'), "</th><td>", $inventory->remarks, "</td></tr>\n";
form_tag_assignment($g_scriptname, $id);
$tags = db_load_taglist('inv', $id);
form_tag_assignment($g_scriptname, $id, $tags);
echo "</table>\n";
@@ -312,7 +344,7 @@ elseif ($action == ACT_EDIT):
// ========== VARIANT: edit single record =====================================
$sql = "SELECT invname, conttype, sid, boxid, number, weight, price, purchdate, "
. " invcond, remarks "
. " invcond, eid, remarks "
. "FROM inventory "
. "WHERE invid=?";
$sth = $pdo->prepare($sql);
@@ -335,14 +367,9 @@ $inventory = $sth->fetch(PDO::FETCH_OBJ);
<label for="weight" class="form-label"><?=_('Weight, kg')?></label>
<input type="text" class="form-control" id="weight" name="weight" value="<?=format_float($inventory->weight); ?>">
</div>
<div class="mb-3">
<label for="conttype" class="form-label"><?=_('Container type')?></label>
<select class="form-select" name="conttype" id="conttype">
<option value="box"><?=_('Box')?></option>
<option value="storage"><?=_('Storage')?></option>
</select>
</div>
<?php
<?php
$opt_conttype = db_load_enum('inventory', 'conttype', true, true);
form_create_select('conttype', _('Container type'), $opt_conttype, $inventory->conttype);
form_create_select('sid', _('Storage'), $opt_storage, $inventory->sid);
form_create_select('boxid', _('Box'), $opt_box, $inventory->boxid);
?>
@@ -358,14 +385,7 @@ form_create_select('boxid', _('Box'), $opt_box, $inventory->boxid);
<label for="invcond" class="form-label"><?=_('Condition')?></label>
<select name="invcond" id="invcond" class="form-control">
<?php
$cond = array(
'good' => _('Good'),
'normal' => _('Normal'),
'bad' => _('Bad'),
'repairable' => _('Repairable'),
'defect' => _('Defect'),
'unknown' => _('Unknown')
);
$cond = db_load_enum('inventory', 'invcond', true, true);
foreach ($cond as $k => $v) {
echo '<option value="', $k, '"';
if ($k == $inventory->invcond) {
@@ -376,6 +396,7 @@ foreach ($cond as $k => $v) {
?>
</select>
</div>
<?php form_create_select('eid', _('Equipment'), $opt_equipment, $inventory->eid); ?>
<div class="mb-3">
<label for="remarks" class="form-label"><?=_('Remarks')?></label>
<textarea class="form-control" id="remarks" name="remarks" rows="3"><?=$inventory->remarks ?></textarea>