vid); $opt_catgory = db_get_options(5); $opt_unit = db_get_options(6); // ========== 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[':provname'] = gpc_get_string($_POST, 'provname'); $p[':number'] = gpc_get_int($_POST, 'number'); $p[':unit'] = gpc_get_int($_POST, 'unit'); $p[':storedate'] = gpc_get_string($_POST, 'storedate'); $p[':shelflife'] = gpc_get_string($_POST, 'shelflife'); $keys = array_keys($p); $fields = join(',', array_map(function($s) { return ltrim($s, ':'); }, $keys)); $pnames = join(',', $keys); $sth = $pdo->prepare("INSERT INTO provisions ($fields) VALUES ($pnames)"); try { $sth->execute($p); } catch (PDOexception $e) { $g_error->Add('SQL-Error: '. $e->getMessage()); } $id = $pdo->LastInsertId(); $action = ACT_VIEW; break; case 'update': $p[':provname'] = gpc_get_string($_POST, 'provname'); $p[':number'] = gpc_get_int($_POST, 'number'); $p[':unit'] = gpc_get_int($_POST, 'unit'); $p[':storedate'] = gpc_get_string($_POST, 'storedate'); $p[':shelflife'] = gpc_get_string($_POST, 'shelflife'); $p[':sid'] = gpc_get_int($_POST, 'sid'); $fields = join(',', array_map(function($s) { return ltrim($s, ':') . '=' . $s; }, array_keys($p))); $sth = $pdo->prepare("UPDATE provisions SET $fields WHERE provid=:provid"); $p[':provid'] = $id; try { $sth->execute($p); } catch (PDOexception $e) { $g_error->Add('SQL-Error: '. $e->getMessage()); } $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; } $action = ACT_DEFAULT; break; default: $g_error->Add(sprintf(_('Unknown function!'), $submit)); $valid = FALSE; } // ========== ACTIONS END ===================================================== require 'header.php'; // ========== PAGE CONTENT ==================================================== if ($action == ACT_DEFAULT): // ========== VARIANT: default behavior ======================================= echo "
| ', _('Description'), " | "; echo '', _('Number'), " | "; echo '', _('Unit'), " | "; echo '', _('Stored'), " | "; echo '', _('Best before'), " | "; echo ""; echo " | \n"; echo " |
|---|---|---|---|---|---|---|
| ". $row['provname'] ." | \n"; echo "". $row['number'] ." | \n"; echo "". $opt_unit[$row['unit']] ." | \n"; echo "". $row['storedate'] ." | \n"; echo "". $row['shelflife'] ." | \n"; echo "";
echo ' | \n";
echo "|
| ', sprintf(_('%d records'), count($res)), ' | ||||||
| ', _('Number')," | ", $prov->number, " |
|---|---|
| ', _('Unit')," | ", $opt_unit[$prov->unit], " |
| ', _('Storedate')," | ", $prov->storedate, " |
| ', _('Shelflife')," | ", $prov->shelflife, " |
| ', _('Storage')," | ", $opt_storage[$prov->sid], " |
', _('Unknown function call: Please report to system development!'), "
\n"; endif; // $action == ... // ========== END OF VARIANTS ================================================= include 'footer.php';