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 'freset': db_clear_filter(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[':weight'] = min(gpc_get_float($_POST, 'weight'), 999.99); // limit max value $p[':weight_net'] = min(gpc_get_float($_POST, 'weight_net'), 999.99); $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'); if ($p[':sid'] <= 0) $p[':sid'] = NULL; 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 ======================================= page_caption_search($pagetitle); // 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 ($flt->cat == -1) { $w[] = 'provcat IS NULL'; } elseif ($flt->cat > 0) { $w[] = 'provcat=:provcat'; $p[':provcat'] = $flt->cat; } if (strlen($flt->txt) > 1) { $w[] = 'provname LIKE :txt'; $p[':txt'] = '%'.$flt->txt.'%'; } $where = join(' AND ', $w); $order = ' ORDER BY provid'; // get total record count for pagination and limit $sql = "SELECT COUNT(*) FROM provisions LEFT OUTER JOIN storage USING (sid) WHERE " . $where; $sth = $pdo->prepare($sql); try { $sth->execute($p); } catch(PDOException $e) { $g_error->Add($e->getMessage()); $g_error->Add($sql); $g_error->Add(print_r($p, true)); $g_error->PrintOut(); } $numrows = $sth->fetchColumn(); $page = gpc_get_int($_REQUEST, 'p', 1); $rows_pp = gpc_get_int($_REQUEST, 'n', $g_rows_pp); $lastpage = ceil($numrows/$rows_pp); // provisions can be assigned to a store or be free // d0 is the maximum number of days age // d1 is the current age in days. If negative then it is over limit // TODO display over with warning levels: 50% over, 100% over etc. $sql = "SELECT provid, provname, number, unit, storedate, shelflife, sid," . " DATEDIFF(shelflife, storedate) AS d0, DATEDIFF (shelflife, CURDATE()) AS d1 " . "FROM provisions LEFT OUTER JOIN storage USING (sid)"; $sql .= ' WHERE ' . $where; $sql .= $order; // if pagination: $sql .= ' LIMIT ' . ($page - 1) * $rows_pp . ',' . $rows_pp; $sth = $pdo->prepare($sql); $sth->execute($p); $res = $sth->fetchAll(); ?>
', "\n"; echo "\n"; echo "| ', _('Number')," | ", $prov->number, " |
|---|---|
| ", _('Weight'), " | ", format_float($prov->weight, 2, 'kg'), " |
| ", _('Weight net'), " | ", format_float($prov->weight_net, 2, 'kg'), " |
| ', _('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';