vid); $opt_category = 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 'filter': $flt = array(); $flt['cat'] = gpc_get_enum($_POST, 'flt_cat', array_merge(array_keys($opt_category), ['-2', '-1'])); $flt['txt'] = gpc_get_string($_POST, 'flt_txt'); db_save_filter($flt, 202); $action = ACT_DEFAULT; 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'); $id = db_exec_insert('provisions', $p); $action = ACT_VIEW; break; case 'update': $p[':provid'] = $id; $p[':provname'] = gpc_get_string($_POST, 'provname'); $p[':provcat'] = gpc_get_int($_POST, 'provcat'); $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'); db_exec_update('provisions', $p, 'provid'); $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 ======================================= // load filter from db $flt = db_get_filter($user->id, 202); $w = array('(vid=:vid OR sid IS NULL)'); $p = array(':vid' => $user->vid); if (strlen($flt->txt) > 1) { $w[] = 'provname LIKE :txt'; $p[':txt'] = '%'.$flt->txt.'%'; } $where = join(' AND ', $w); $order = ' ORDER BY provid'; // provisions can be assigned to a store or be free $sql = "SELECT provid, provname, number, unit, storedate, shelflife, sid," . " DATEDIFF(shelflife, storedate) AS d0, DATEDIFF (CURDATE(), storedate) AS d1 " . "FROM provisions LEFT OUTER JOIN storage USING (sid)"; $sql .= ' WHERE ' . $where; $sql .= $order; $sth = $pdo->prepare($sql); $sth->execute($p); $res = $sth->fetchAll(); page_caption_search($pagetitle); ?>
', "\n"; echo "\n"; echo "| ', _('Number')," | ", $prov->number, " |
|---|---|
| ', _('Unit')," | ", $opt_unit[$prov->unit], " |
| ', _('Category')," | ", $opt_category[$prov->provcat] ?? 'n/a', " |
| ', _('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';