vid; $p[':sname'] = gpc_get_string($_POST, 'sname'); $p[':stype'] = gpc_get_int($_POST, 'stype'); $id = db_exec_insert('storage', $p); $action = ACT_VIEW; break; case 'update': $p[':sid'] = $id; $p[':sname'] = gpc_get_string($_POST, 'sname'); $p[':x'] = gpc_get_int($_POST, 'x'); $p[':y'] = gpc_get_int($_POST, 'y'); $p[':z'] = gpc_get_int($_POST, 'z'); $p[':wx'] = gpc_get_int($_POST, 'wx'); $p[':wy'] = gpc_get_int($_POST, 'wy'); $p[':wz'] = gpc_get_int($_POST, 'wz'); $p[':remarks'] = gpc_get_string($_POST, 'remarks', 150); db_exec_update('storage', $p, 'sid'); $action = ACT_VIEW; break; case 'delete': // Security token needed! if (gpc_get_string($_POST, 'token', 16) != $_SESSION['token']) { $g_error->Add(_('Delete prohibited, invalid security token!')); $action = ACT_VIEW; break; } unset($_SESSION['token']); // check if storage is empty // - no assigned boxes $sth = $pdo->prepare("SELECT COUNT(*) FROM box WHERE sid=?"); $sth->execute([$id]); if ($sth->fetchColumn() > 0) { $g_error->Add(_('Delete failed, assigned boxes detected!')); $action = ACT_VIEW; break; } // - no assigned equipment $sth = $pdo->prepare("SELECT COUNT(*) FROM inventory WHERE boxtype='storage' AND sid=?"); $sth->execute([$id]); if ($sth->fetchColumn() > 0) { $g_error->Add(_('Delete failed, assigned equipment detected!')); $action = ACT_VIEW; break; } $sth = $pdo->prepare("DELETE FROM storage WHERE sid=?"); $sth->execute([$id]); $g_message->Add(sprintf(_('Deleted storage no. %d'), $id)); $action = ACT_DEFAULT; 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"; // Storage // stype from dropdown $sql = "SELECT sid, sname, x, y, z, remarks " . "FROM storage " . "WHERE vid=? " . "ORDER BY sid"; $sth = $pdo->prepare($sql); $sth->execute([$user->vid]); $res = $sth->fetchAll(); echo '', "\n"; echo "\n"; echo ""; echo ""; echo ""; echo ""; echo ""; echo "\n"; echo "\n"; foreach ($res as $row) { echo "\n"; echo "\n"; echo "\n"; echo "\n"; form_action_buttons($g_scriptname, $row['sid']); echo "\n"; } echo "\n"; echo '', "\n"; echo "\n"; echo "
", _('Name'), "", _('Position'), "", _('Remarks'), " 
", $row['sname'], "", join(',', array($row['x'] ?? '?', $row['y'] ?? '?', $row['z'])), "", $row['remarks'], "
', sprintf(_('%d records'), count($res)), '
\n"; form_add_button($g_scriptname); // Boxes echo "

", _('Box'), "

\n"; $sql = "SELECT boxid, sid, label, color, content, remarks " . "FROM box " . "ORDER BY label"; $sth = $pdo->query($sql); $res = $sth->fetchAll(); echo '', "\n"; echo "\n"; echo ""; echo ""; echo ""; echo ""; echo ""; echo "\n"; foreach ($res as $row) { echo "\n"; echo "\n"; echo '\n"; echo "\n"; form_action_buttons('box.php', $row['boxid']); echo "\n"; } // Table summary echo "\n"; echo '', "\n"; echo "\n"; echo "
" . _('Label') . "" . _('Color') . "" . _('Content') . "
". $row['label'] ."', format_color($row['color']), "". $row['content'] ."
', sprintf(_('%d records'), count($res)), '
\n"; form_add_button('box.php'); elseif ($action == ACT_ADD): // ========== VARIANT: add record ============================================= echo '

', _('Add Storage'), "

\n"; ?>
prepare($sql); $sth->execute([$id]); $storage = $sth->fetch(PDO::FETCH_OBJ); echo '

', $storage->sname, "

\n"; echo '', "\n"; echo '\n"; echo '\n"; echo '\n"; echo '\n"; echo '\n"; echo "
', _('Typ'),"", $stype[$storage->stype], "
', _('Capacity'),"", $storage->capacity, ' ', $storage->capaunit, "
', _('Location (x, y, z)'),"(", $storage->x, ', ', $storage->y, ', ', $storage->z, ")
', _('Width (wx, wy, wz)'),"(", $storage->wx, ', ', $storage->wy, ', ', $storage->wz, ")
', _('Remarks'),"", $storage->remarks, "
\n"; form_view_buttons($g_scriptname, $id); // show assigned boxes here echo '

', _('Boxes in storage'), "

\n"; $sql = "SELECT boxid, label, color FROM box WHERE sid=?"; $sth = $pdo->prepare($sql); $sth->execute([$id]); $res = $sth->fetchall(); if (count($res) > 0) { echo ''; foreach ($res as $row) { echo ""; echo '"; echo '"; echo ''; echo "\n"; } echo "
', $row['label'], "', $row['color'], "
\n"; } else { echo '

', _('No boxes contained'), "

\n"; } echo '

', _('Provisions in storage'), "

\n"; $sql = "SELECT provid, provname, number, unit, storedate, shelflife FROM provisions WHERE sid=?"; $sth = $pdo->prepare($sql); $sth->execute([$id]); $res = $sth->fetchall(); if (count($res) > 0) { echo ''; foreach ($res as $row) { echo ""; echo ""; echo ""; echo ""; echo "\n"; } echo "
", $row['provname'], "", $row['number'], ' ', $opt_unit[$row['unit']], "", $row['storedate'], ' - ', $row['shelflife'], "
\n"; } else { echo '

', _('No provisions contained'), "

\n"; } elseif ($action == ACT_EDIT): // ========== VARIANT: edit single record ===================================== echo '

', _('Edit Storage'), "

\n"; $sql = "SELECT sid, sname, stype, x, y, z, wx, wy, wz, remarks " . "FROM storage " . "WHERE sid=?"; $sth = $pdo->prepare($sql); $sth->execute([$id]); $storage = $sth->fetch(PDO::FETCH_OBJ); ?>
prepare($sql); $sth->execute([$id]); $storage = $sth->fetch(PDO::FETCH_OBJ); echo '

', _('Delete Storage'), "

\n"; echo '

', sprintf(_('Record no. %d'), $id), "

\n"; echo '

Name: ', $storage->sname, "

"; echo '

Remarks: ', $storage->remarks, "

"; echo '

', _('Deleting a storage is final. There is no way back. Only delete if you are absolute sure.'), "

\n"; form_delete_buttons($g_scriptname, $id, $_SESSION['token']); else: // ========== ERROR UNKNOWN VARIANT =========================================== echo '

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

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