prepare($sql);
$sth->execute([$user->vid]);
$opt_storage = array();
foreach ($sth->fetchAll() as $row) {
$opt_storage[$row['sid']] = $row['sname'];
}
$opt_boxtype = db_get_options(9);
// ========== ACTIONS START ===================================================
switch ($submit = form_get_action()) {
case NULL: break;
case 'add': $action = ACT_ADD; break;
case 'view': $action = ACT_VIEW; break;
case 'edit': $action = ACT_EDIT; break;
case 'del': $action = ACT_DELETE; break;
case 'insert':
$p[':label'] = gpc_get_string($_POST, 'label');
$p[':sid'] = gpc_get_uint($_POST, 'sid');
$p[':content'] = gpc_get_string($_POST, 'content');
$p[':remarks'] = gpc_get_string($_POST, 'remarks');
$id = db_exec_insert('box', $p);
$action = ACT_VIEW;
break;
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');
$p[':weight'] = min(gpc_get_float($_POST, 'weight'), 99.99);
$p[':sid'] = gpc_get_uint($_POST, 'sid');
$p[':remarks'] = gpc_get_string($_POST, 'remarks', 150);
db_exec_update('box', $p, 'boxid');
$action = ACT_VIEW;
break;
default:
$g_error->Add(sprintf(_("Unknown function '%s'!"), $submit));
$valid = FALSE;
}
// ========== ACTIONS END =====================================================
require 'header.php';
// ========== PAGE CONTENT ====================================================
if ($action == ACT_DEFAULT):
// ========== VARIANT: default behavior =======================================
echo "
$pagetitle
\n";
$sql = "SELECT boxid, boxtype, sid, label, color, content, weight, remarks "
. "FROM box "
. "ORDER BY label";
$sth = $pdo->query($sql);
$res = $sth->fetchAll();
echo '', "\n";
echo "\n";
echo "";
echo '| # | ';
echo "", _('Label'), " | ";
echo "", _('Type'), " | ";
echo "", _('Color'), " | ";
echo "", _('Content'), " | ";
echo '', _('Weight'), " | ";
echo " | ";
echo "
\n";
$i = 0;
foreach ($res as $row) {
$i++; // record number
echo "\n";
echo '| ', $i;
echo '', "\n";
echo " | \n";
echo '', $row['label'], " | \n";
echo '', ($opt_boxtype[$row['boxtype']] ?? ''), " | \n";
echo '', format_color(strtoupper($row['color'])), " | \n";
echo '', $row['content'], " | \n";
echo '', format_float($row['weight'], 2), " | \n";
// Edit current record button
echo "";
echo '', "\n";
echo " | \n";
echo "
\n";
}
// Table summary
$numrows = count($res);
table_rec_summary($i, $numrows, $numrows, 5);
echo "
\n";
form_add_button('box.php');
elseif ($action == ACT_ADD):
// ========== VARIANT: add record =============================================
echo '', _('Add Box'), "
\n";
?>
prepare($sql);
$sth->execute([$id]);
$box = $sth->fetch(PDO::FETCH_OBJ);
echo '', $box->label, "
\n";
// Bootstrap grid
echo '';
echo '
';
echo '
';
echo '
', "\n";
echo '| ', _('Box type')," | ", ($opt_boxtype[$box->boxtype] ?? ''), " |
\n";
echo '| ', _('Content')," | ", $box->content, " |
\n";
echo '| ', _('Color'), ' | ', format_color($box->color), " |
\n";
echo '| ', _('Weight'), ' | ', format_float($box->weight, 2, 'kg'), " |
\n";
echo '| ', _('Storage')," | ", $box->sname, ' ';
echo '';
echo " |
\n";
echo '| ', _('Remarks')," | ", $box->remarks, " |
\n";
echo "
\n";
form_view_buttons($g_scriptname, $id);
echo '
'; // Column break
echo '
', "\n";
echo '
', "\n";
echo '\n";
echo '
', "\n";
$sql = "SELECT d.docid, d.title "
. "FROM docref AS r INNER JOIN document AS d using (docid) "
. "WHERE d.doctype='picture' AND r.reftype='box' AND r.refid=? "
. "ORDER BY d.title";
$sth = $pdo->prepare($sql);
$sth->execute([$id]);
$res = $sth->fetchAll();
// TODO hübsche Darstellung
$doccount = 0;
foreach ($res as $row) {
$doccount += 1;
echo '
';
echo '
';
// echo '
';
echo '
';
echo "\n";
// additionally direct download and go to document details page
echo '
';
echo '
';
echo '
';
echo "
\n";
echo "
\n"; // card-body
echo "
\n"; // card
echo '
'; // col
echo '
'; // row
echo '
'; // container
// Inventory in box
// WIP
$sql = "SELECT invid, invname, weight, number FROM inventory WHERE conttype='box' AND boxid=?";
$sth = $pdo->prepare($sql);
$sth->execute([$id]);
$res = $sth->fetchAll();
echo '
', _('Inventory in box'), "
\n";
$weight_total = 0.0;
if ($res) {
echo '
', "\n";
echo "\n";
echo '';
echo '| # | ';
echo '', _('Inventory'), " | ";
echo '', _('Number'), " | ";
echo '', _('Weight'), " | ";
echo "
\n";
echo "\n";
$i = 1;
foreach ($res as $row) {
echo "\n";
echo '| ', $i++, ' ';
echo '';
echo " | \n";
echo '', $row['invname'], " | \n";
echo '', $row['number'], " | \n";
echo '';
$weight_item = $row['weight'] * $row['number'];
if ($weight_item > 0) {
$weight_total += $weight_item;
echo format_float($weight_item, 2, 'kg');
} else {
echo '-';
}
echo " | \n";
echo "
\n";
}
echo "";
echo ' | ', format_float($weight_total, 2, 'kg'), ' | ', "\n";
echo "
\n";
echo "
\n";
} else {
echo '
', _('Box is empty'), "
\n";
}
elseif ($action == ACT_EDIT):
// ========== VARIANT: edit single record =====================================
$sql = "SELECT boxtype, label, content, color, weight, sid, remarks "
. "FROM box "
. "WHERE boxid=?";
$sth = $pdo->prepare($sql);
$sth->execute([$id]);
$box = $sth->fetch(PDO::FETCH_OBJ);
$opt_none = [ -1 => _('― none ―')];
echo '
', _('Edit Box'), "
\n";
?>