Webgui: filter and pagination working

This commit is contained in:
2026-07-15 19:42:55 +02:00
parent 2177834b39
commit a183a4725f
33 changed files with 2088 additions and 750 deletions
+23 -3
View File
@@ -79,7 +79,7 @@ if ($action == ACT_DEFAULT):
page_caption_search($pagetitle);
// load filter from db
$flt = db_get_filter($user->id, 204);
$flt = db_get_filter($user->id, 204, ['equip','txt']);
// Filter
$opt_special = array(
@@ -140,6 +140,20 @@ if (strlen($flt->txt) > 1) {
$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)";
@@ -147,12 +161,16 @@ $sql .= ' WHERE ' . $where;
$sql .= $order;
// if pagination:
// $sql .= ' LIMIT ' . ($page - 1) * $rows_pp . ',' . $rows_pp;
$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 '<table class="table table-striped">', "\n";
echo "<thead>\n";
echo "<tr>";
@@ -182,10 +200,12 @@ foreach ($res as $row) {
}
// Table summary
echo "<tfoot>\n";
echo '<tr><td colspan="6">', sprintf(_('%d records'), count($res)), '</td></tr>', "\n";
echo '<tr><td colspan="6">', sprintf(_('Records %d to %d of %d'), $i0, $i, $numrows), '</td></tr>', "\n";
echo "</tfoot>\n";
echo "</table>\n";
echo $pagination;
form_add_button($g_scriptname);