prepare($sql); $sth->execute([$user->vid]); $opt_storage = array(); foreach ($sth->fetchAll() as $row) { $opt_storage[$row['sid']] = $row['sname']; } // ========== 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[':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, 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 "\n"; foreach ($res as $row) { echo "\n"; echo '\n"; echo '\n"; echo '\n"; echo '\n"; form_action_buttons($g_scriptname, $row['boxid']); echo "\n"; } // Table summary echo "\n"; echo '', "\n"; echo "\n"; echo "
" . _('Label') . "" . _('Color') . "" . _('Content') . "', _('Weight'), "
', $row['label'], "', format_color(strtoupper($row['color'])), "', $row['content'], "', format_float($row['weight'], 2), "
', 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 "
', _('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 FROM inventory WHERE boxtype='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 "\n"; foreach ($res as $row) { echo "\n"; echo "\n"; echo "\n"; form_action_buttons('inventory.php', $row['invid']); echo "\n"; $weight_total += $row['weight']; } echo ""; echo '', "\n"; echo "\n"; echo "
', _('Inventory'), "', _('Weight'), "
", $row['invname'], "", format_float($row['weight'], 2, 'kg'), "
', format_float($weight_total, 2, 'kg'), '
\n"; } else { echo '

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

\n"; } elseif ($action == ACT_EDIT): // ========== VARIANT: edit single record ===================================== $sql = "SELECT label, content, color, weight, remarks " . "FROM box " . "WHERE boxid=?"; $sth = $pdo->prepare($sql); $sth->execute([$id]); $box = $sth->fetch(PDO::FETCH_OBJ); echo '

', _('Edit Box'), "

\n"; ?>
\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';