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 "
| ', _('Inventory'), " | "; echo '', _('Weight'), " | "; echo ""; echo " |
|---|---|---|
| ", $row['invname'], " | \n"; echo "", format_float($row['weight'], 2, 'kg'), " | \n"; form_action_buttons('inventory.php', $row['invid']); echo "|
| ', format_float($weight_total, 2, 'kg'), ' | ', "\n"; 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 '