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_int($_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[':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 ""; echo ""; echo ""; echo ""; echo '"; echo ""; echo "\n"; $i = 0; foreach ($res as $row) { $i++; // record number echo "\n"; echo '\n"; echo '\n"; echo '\n"; echo '\n"; echo '\n"; echo '\n"; // Edit current record button echo "\n"; echo "\n"; } // Table summary echo "\n"; echo '', "\n"; echo "\n"; echo "
#", _('Label'), "", _('Type'), "", _('Color'), "", _('Content'), "', _('Weight'), "
', $i; echo '', "\n"; echo "', $row['label'], "', ($opt_boxtype[$row['boxtype']] ?? ''), "', format_color(strtoupper($row['color'])), "', $row['content'], "', format_float($row['weight'], 2), ""; echo '', "\n"; echo "
', sprintf(_('%d records'), count($res)), '
\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"; echo '', "\n"; echo '\n"; echo '\n"; echo '\n"; echo '\n"; echo '\n"; echo '\n"; echo "
', _('Box type'),"", ($opt_boxtype[$box->boxtype] ?? ''), "
', _('Content'),"", $box->content, "
', _('Color'), '', format_color($box->color), "
', _('Weight'), '', format_float($box->weight, 2, 'kg'), "
', _('Storage'),"", $box->sname, ' '; echo ''; echo "
', _('Remarks'),"", $box->remarks, "
\n"; form_view_buttons($g_scriptname, $id); // 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 '"; echo '"; echo '"; echo "\n"; echo "\n"; $i = 1; foreach ($res as $row) { echo "\n"; echo '\n"; echo '\n"; echo '\n"; echo '\n"; echo "\n"; } echo ""; echo '', "\n"; echo "\n"; echo "
#', _('Inventory'), "', _('Number'), "', _('Weight'), "
', $i++, ' '; echo ''; echo "', $row['invname'], "', $row['number'], "'; $weight_item = $row['weight'] * $row['number']; if ($weight_item > 0) { $weight_total += $weight_item; echo format_float($weight_item, 2, 'kg'); } else { echo '-'; } echo "
', format_float($weight_total, 2, 'kg'), '
\n"; } else { echo '

', _('Box is empty'), "

\n"; } elseif ($action == ACT_EDIT): // ========== VARIANT: edit single record ===================================== $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 '

', _('Edit Box'), "

\n"; ?>
boxtype); ?>
\n"; elseif ($action == ACT_DELETE): // ========== VARIANT: delete record ========================================== else: // ========== ERROR UNKNOWN VARIANT =========================================== echo '

', _('Unknown function call: Please report to system development!'), "

\n"; endif; // $action == ... // ========== END OF VARIANTS ================================================= include 'footer.php';