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
+27 -15
View File
@@ -47,7 +47,7 @@ switch ($submit = form_get_action()) {
case 'filter':
$flt = array();
$flt['name'] = gpc_get_string($_POST, 'flt_name');
$flt['state'] = $_POST['flt_state']; // Array! gpc_get_string($_POST, 'flt_state');
$flt['state'] = gpc_get_string($_POST, 'flt_state'); // TODO perhaps change to checkboxes
$flt['remarks'] = gpc_get_string($_POST, 'flt_remarks');
db_save_filter($flt, 205);
$action = ACT_DEFAULT;
@@ -107,16 +107,22 @@ if ($action == ACT_DEFAULT):
page_caption_search($pagetitle);
// load filter from db
$flt = db_get_filter($user->id, 205);
// name, status, text
$flt = db_get_filter($user->id, 205, ['name','state','remarks']);
$w = array('vid=:vid');
$p = array(':vid' => $user->vid);
if (strlen($flt->txt) > 1) {
$w[] = '(projname LIKE :txt OR remarks LIKE :txt)';
$p[':txt'] = '%'.$flt->txt.'%';
if ($flt->state > 0) {
$w[] = 'projstate=:state';
$p[':state'] = $flt->state;
}
if (strlen($flt->name) > 1) {
$w[] = '(projname LIKE :name)';
$p[':name'] = '%'.$flt->name.'%';
}
if (strlen($flt->remarks) > 1) {
$w[] = '(remarks LIKE :remarks)';
$p[':remarks'] = '%'.$flt->remarks.'%';
}
$where = join(' AND ', $w);
@@ -134,7 +140,7 @@ try {
}
$numrows = $sth->fetchColumn();
$page = gpc_get_int($_REQUEST, 'p', 1);
$rows_pp = gpc_get_int($_REQUEST, 'n', $g_rows_pp);
$rows_pp = gpc_get_int($_REQUEST, 'n', $user->rows_pp);
$lastpage = ceil($numrows/$rows_pp);
// $grandtotal = $pdo->query("SELECT COUNT(*) FROM project WHERE " . $where)->fetchColumn();
@@ -145,7 +151,7 @@ $sql .= " WHERE " . $where;
$sql .= $order;
// if pagination:
$sql .= ' LIMIT ' . ($page - 1) * $g_rows_pp . ',' . $g_rows_pp;
$sql .= ' LIMIT ' . ($page - 1) * $rows_pp . ',' . $rows_pp;
$sth = $pdo->prepare($sql);
$sth->execute($p);
@@ -158,15 +164,15 @@ $res = $sth->fetchAll();
<div class="card-header"><i class="bi bi-funnel me-2"></i>Filter</div>
<div class="card-body d-flex flex-wrap gap-3">
<div class="d-flex flex-nowrap gap-2">
<label for="flt_name">Name</label>
<input type="text" class="form-control" name="flt_name" size="15" maxlength="30" value="<?=$flt->name;?>">
<label for="flt_name"><?=_('Name')?></label>
<input type="text" class="form-control" name="flt_name" size="15" maxlength="30" value="<?=$flt->name ?? '';?>">
</div>
<?php
filter_create_select('flt_state[]', _('State'), $g_opt_all + $opt_state, $flt->state, FALSE);
filter_create_select('flt_state', _('State'), $g_opt_all + $opt_state, $flt->state ?? -2, FALSE);
?>
<div class="d-flex flex-nowrap gap-2">
<label for="flt_remarks">Text</label>
<input type="text" class="form-control" name="flt_remarks" size="15" maxlength="30" value="<?=$flt->remarks ?>">
<label for="flt_remarks"><?=_('Remarks')?></label>
<input type="text" class="form-control" name="flt_remarks" size="15" maxlength="30" value="<?=$flt->remarks ?? '' ?>">
</div>
</div>
<div class="card-footer">
@@ -177,6 +183,9 @@ filter_create_select('flt_state[]', _('State'), $g_opt_all + $opt_state, $flt->s
</form>
<?php
// Pagination on top
$pagination = get_pagination($g_scriptname, '', $page, $lastpage);
echo $pagination;
echo '<table class="table table-striped">'. "\n";
echo "<thead>\n";
@@ -210,11 +219,14 @@ foreach ($res as $row) {
echo "</tr>\n";
}
// Table summary
echo "<tfoot>\n";
echo '<tr><td colspan="5">', 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);
echo "<h1>", _('Generic Tasks'), "</h1>\n";