More webgui development
This commit is contained in:
+15
-5
@@ -20,6 +20,8 @@ foreach ($sth->fetchAll() as $row) {
|
||||
$opt_storage[$row['sid']] = $row['sname'];
|
||||
}
|
||||
|
||||
$opt_boxtype = db_get_options(9);
|
||||
|
||||
// ========== ACTIONS START ===================================================
|
||||
|
||||
switch ($submit = form_get_action()) {
|
||||
@@ -42,6 +44,8 @@ switch ($submit = form_get_action()) {
|
||||
|
||||
case 'update':
|
||||
$p[':boxid'] = $id;
|
||||
$p[':boxtype'] = gpc_get_int($_POST, 'boxtype');
|
||||
if ($p[':boxtype'] == -1) $p[':boxtype'] = NULL;
|
||||
$p[':label'] = gpc_get_string($_POST, 'label');
|
||||
$p[':content'] = gpc_get_string($_POST, 'content');
|
||||
$p[':color'] = gpc_get_color($_POST, 'color');
|
||||
@@ -67,7 +71,7 @@ if ($action == ACT_DEFAULT):
|
||||
|
||||
echo "<h1>$pagetitle</h1>\n";
|
||||
|
||||
$sql = "SELECT boxid, sid, label, color, content, weight, remarks "
|
||||
$sql = "SELECT boxid, boxtype, sid, label, color, content, weight, remarks "
|
||||
. "FROM box "
|
||||
. "ORDER BY label";
|
||||
$sth = $pdo->query($sql);
|
||||
@@ -76,6 +80,7 @@ echo '<table class="table table-striped">', "\n";
|
||||
echo "<thead>\n";
|
||||
echo "<tr>";
|
||||
echo "<th>" . _('Label') . "</th>";
|
||||
echo "<th>" . _('Type') . "</th>";
|
||||
echo "<th>" . _('Color') . "</th>";
|
||||
echo "<th>" . _('Content') . "</th>";
|
||||
echo '<th class="text-end">', _('Weight'), "</th>";
|
||||
@@ -84,6 +89,7 @@ echo "</tr>\n";
|
||||
foreach ($res as $row) {
|
||||
echo "<tr>\n";
|
||||
echo '<td>', $row['label'], "</td>\n";
|
||||
echo '<td>', ($opt_boxtype[$row['boxtype']] ?? ''), "</td>\n";
|
||||
echo '<td>', format_color(strtoupper($row['color'])), "</td>\n";
|
||||
echo '<td>', $row['content'], "</td>\n";
|
||||
echo '<td class="text-end">', format_float($row['weight'], 2), "</td>\n";
|
||||
@@ -137,7 +143,7 @@ foreach ($opt_storage as $k => $v) {
|
||||
elseif ($action == ACT_VIEW):
|
||||
// ========== VARIANT: view single record =====================================
|
||||
|
||||
$sql = "SELECT label, content, color, weight, box.remarks, box.sid, sname "
|
||||
$sql = "SELECT boxtype, label, content, color, weight, box.remarks, box.sid, sname "
|
||||
. "FROM box LEFT JOIN storage USING (sid) "
|
||||
. "WHERE boxid=?";
|
||||
$sth = $pdo->prepare($sql);
|
||||
@@ -147,7 +153,8 @@ $box = $sth->fetch(PDO::FETCH_OBJ);
|
||||
echo '<h2>', $box->label, "</h2>\n";
|
||||
|
||||
echo '<table class="table">', "\n";
|
||||
echo '<tr><th style="width:20%">', _('Content'),"</th><td>", $box->content, "</td></tr>\n";
|
||||
echo '<tr><th style="width:20%">', _('Box type'),"</th><td>", ($opt_boxtype[$box->boxtype] ?? ''), "</td></tr>\n";
|
||||
echo '<tr><th>', _('Content'),"</th><td>", $box->content, "</td></tr>\n";
|
||||
echo '<tr><th>', _('Color'), '</th><td>', format_color($box->color), "</td></tr>\n";
|
||||
echo '<tr><th>', _('Weight'), '</th><td>', format_float($box->weight, 2, 'kg'), "</td></tr>\n";
|
||||
echo '<tr><th>', _('Storage'),"</th><td>", $box->sname;
|
||||
@@ -160,7 +167,7 @@ form_view_buttons($g_scriptname, $id);
|
||||
|
||||
// Inventory in box
|
||||
// WIP
|
||||
$sql = "SELECT invid, invname, weight FROM inventory WHERE boxtype='box' AND boxid=?";
|
||||
$sql = "SELECT invid, invname, weight FROM inventory WHERE conttype='box' AND boxid=?";
|
||||
$sth = $pdo->prepare($sql);
|
||||
$sth->execute([$id]);
|
||||
$res = $sth->fetchAll();
|
||||
@@ -194,13 +201,15 @@ if ($res) {
|
||||
elseif ($action == ACT_EDIT):
|
||||
// ========== VARIANT: edit single record =====================================
|
||||
|
||||
$sql = "SELECT label, content, color, weight, remarks "
|
||||
$sql = "SELECT boxtype, label, content, color, weight, remarks "
|
||||
. "FROM box "
|
||||
. "WHERE boxid=?";
|
||||
$sth = $pdo->prepare($sql);
|
||||
$sth->execute([$id]);
|
||||
$box = $sth->fetch(PDO::FETCH_OBJ);
|
||||
|
||||
$opt_none = [ -1 => _('― none ―')];
|
||||
|
||||
echo '<h2>', _('Edit Box'), "</h2>\n";
|
||||
?>
|
||||
<form method="post" action="<?=$g_scriptname?>">
|
||||
@@ -209,6 +218,7 @@ echo '<h2>', _('Edit Box'), "</h2>\n";
|
||||
<label for="label" class="form-label"><?=_('Label')?></label>
|
||||
<input type="text" class="form-control" id="label" name="label" value="<?=$box->label ?>">
|
||||
</div>
|
||||
<?php form_create_select('boxtype', _('Box type'), $opt_none + $opt_boxtype, $box->boxtype); ?>
|
||||
<div class="mb-3">
|
||||
<label for="content" class="form-label"><?=_('Content')?></label>
|
||||
<input type="text" class="form-control" id="content" name="content" value="<?=$box->content ?>">
|
||||
|
||||
Reference in New Issue
Block a user