vid, [0 => _('*** unassigned ***')]); $opt_state = db_load_enum('maintenance', 'maintstate', true, true); // ========== 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['equip'] = gpc_get_int($_POST, 'flt_equip'); $flt['txt'] = gpc_get_string($_POST, 'flt_txt'); db_save_filter($flt, 204); $action = ACT_DEFAULT; break; case 'freset': db_clear_filter(204); $action = ACT_DEFAULT; break; case 'insert': $p[':vid'] = $user->vid; $p[':eid'] = gpc_get_int($_POST, 'eid'); $p[':activities'] = gpc_get_string($_POST, 'activities', 80); $id = db_exec_insert('maintenance', $p); $action = ACT_VIEW; break; case 'update': $p[':maintid'] = $id; $p[':eid'] = gpc_get_int($_POST, 'eid'); $p[':activities'] = gpc_get_string($_POST, 'activities', 80); $p[':remarks'] = gpc_get_string($_POST, 'remarks', 150); $p[':series'] = gpc_get_int($_POST, 'series'); $p[':maintstate'] = gpc_get_string($_POST, 'maintstate'); db_exec_update('maintenance', $p, 'maintid'); $action = ACT_VIEW; break; case 'delete': 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 ======================================= page_caption_search($pagetitle); // load filter from db $flt = db_get_filter($user->id, 204, ['equip','txt']); // Filter $opt_special = array( -2 => _('― all ―'), -1 => _('― none ―') ); ?>
'm.maintid', 2 => 'm.maintid DESC' ); $w = array('m.vid=:vid'); $p = array(':vid' => $user->vid); if (isset($flt->equip) and ($flt->equip == -1 or $flt->equip == 0)) { $w[] = 'm.eid IS NULL'; } elseif ($flt->equip > 0) { $w[] = 'm.eid=:eid'; $p[':eid'] = $flt->equip; } if (strlen($flt->txt) > 1) { $w[] = '(m.activities LIKE :txt OR m.remarks LIKE :txt)'; $p[':txt'] = '%'.$flt->txt.'%'; } $where = join(' AND ', $w); $order = ' ORDER BY m.maintid'; $sql = "SELECT COUNT(*) FROM maintenance AS m 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', $user->rows_pp); $lastpage = ceil($numrows/$rows_pp); $sql = "SELECT m.maintid, m.activities, m.remarks, e.ename " . "FROM maintenance AS m LEFT OUTER JOIN equipment AS e USING (eid)"; $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(); // Pagination on top $pagination = get_pagination($g_scriptname, '', $page, $lastpage); echo $pagination; echo '