Webgui improve filter functions

This commit is contained in:
thooge committed 2026-10-24 10:47:44 +02:00
1 parent b3825cb1b3
commit 9d09b1e120
17 files changed
+424 -447

No files matched your search

+1 -1
View File
@@ -349,7 +349,7 @@ CREATE TABLE provisions (
provname varchar(40) NOT NULL,
provcat tinyint(3) DEFAULT NULL,
sid smallint(6) UNSIGNED DEFAULT NULL,
boxid smallint(6) UNSIGNED NOT NULL DEFAULT 1,
boxid smallint(6) UNSIGNED DEFAULT NULL,
number smallint(6) UNSIGNED NOT NULL DEFAULT 1,
target smallint(6) UNSIGNED DEFAULT NULL, -- for shopping list
weight float(5,2) UNSIGNED DEFAULT NULL,
+18 -4
View File
@@ -95,7 +95,17 @@ if ($action == ACT_DEFAULT):
// ========== VARIANT: default behavior =======================================
// load filter from db
$flt = db_get_filter($user->id, 211);
$flt = db_get_filter($user->id, 211, ['txt']);
$w = array('vid=:vid');
$p = array(':vid' => $user->vid);
if (strlen($flt->txt) > 1) {
$w[] = 'cablename LIKE :txt OR remarks LIKE :txt';
$p[':txt'] = '%'.$flt->txt.'%';
}
$where = join(' AND ', $w);
$order = ' ORDER BY cablename';
echo "<h1>$pagetitle</h1>\n";
@@ -119,10 +129,14 @@ echo "<h1>$pagetitle</h1>\n";
<?php
$sql = "SELECT cableid, cablename, conductors, length, xsection, color, cablecond "
. "FROM cable "
. "ORDER BY cablename";
$sth = $pdo->query($sql);
. "FROM cable ";
$sql .= ' WHERE ' . $where;
$sql .= $order;
$sth = $pdo->prepare($sql);
$sth->execute($p);
$res = $sth->fetchAll();
echo '<table class="table table-striped">', "\n";
echo "<thead>\n";
echo "<tr>\n";
+25 -22
View File
@@ -30,12 +30,17 @@ switch ($submit = form_get_action()) {
$flt = array();
$flt['type'] = gpc_get_int($_POST, 'flt_type');
$flt['txt'] = gpc_get_string($_POST, 'flt_txt');
$allowed = db_load_enum('company', 'flags');
$flt['flags'] = gpc_get_set($_POST, 'flt_flags', $allowed);
db_save_filter($flt, 208);
$action = ACT_DEFAULT;
break;
case 'freset':
db_clear_filter(208);
//db_clear_filter(208);
// set status checkboxes to useful defaults
$flt = array('flags' => ['historic']);
db_save_filter($flt, 208);
$action = ACT_DEFAULT;
break;
@@ -103,7 +108,7 @@ if ($action == ACT_DEFAULT):
page_caption_search($pagetitle);
// load filter from db
$flt = db_get_filter($user->id, 208, ['type','txt']);
$flt = db_get_filter($user->id, 208, ['type','txt','flags']);
$w = array();
$p = array();
@@ -115,6 +120,19 @@ if (strlen($flt->txt) > 1) {
$w[] = '(compname LIKE :txt OR remarks LIKE :txt)';
$p[':txt'] = '%'.$flt->txt.'%';
}
// condition for multiple flags is OR
$parts = ["flags=''", 'flags IS NULL'];
foreach ($flt->flags as $f) {
$parts[] = "FIND_IN_SET('$f', flags)";
}
if (!empty($parts)) {
if (count($parts) > 1) {
$w[] = '(' . join(' OR ', $parts) . ')';
} else {
$w[] = $parts[0];
}
}
$where = join(' AND ', $w);
$order = ' ORDER BY comptype, compname';
@@ -159,32 +177,17 @@ try {
$res = $sth->fetchAll();
// Filter
$opt_special = array(
-2 => _('&horbar; all &horbar;'),
);
?>
<form method="post" action="<?=$g_scriptname?>">
<form id="filterform" method="post" action="<?=$g_scriptname?>">
<div id="filter" class="card">
<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_type">Type</label>
<select id="flt_type" class="form-select" name="flt_type">
<?php
foreach ($opt_special + $opt_comptype as $k => $v) {
echo '<option value="', $k,'"';
if ($k == $flt->type) {
echo ' selected';
}
echo '>', $v, '</option>';
}
filter_create_select('flt_type', _('Type'), $g_opt_all + $opt_comptype, $flt->type);
filter_create_text('flt_txt', _('Text'), $flt->txt, 15, 30);
$opt_flags = db_load_enum('company', 'flags', true, true, false);
filter_create_checks('flt_flags', _('Also show '), $opt_flags, $flt->flags ?? []);
?>
</select>
</div>
<div class="d-flex flex-nowrap gap-2">
<label for="flt_txt">Text</label>
<input type="text" class="form-control" name="flt_txt" size="15" maxlength="30" value="<?=$flt->txt;?>">
</div>
</div>
<div class="card-footer">
<button name="submit[filter]" class="btn btn-sm btn-primary" title="<?=_('Apply')?>"><?=_('Go')?></button>
+4 -41
View File
@@ -334,58 +334,21 @@ $sth->execute($p);
$res = $sth->fetchAll();
// Filter
$opt_special = array(
'all' => _('&horbar; all &horbar;'),
);
?>
<form method="post" action="<?=$g_scriptname?>">
<form id="filterform" method="post" action="<?=$g_scriptname?>">
<div id="filter" class="card">
<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_doctype">Type</label>
<select class="form-select" id="flt_doctype" name="flt_doctype">
<?php
foreach ($opt_special + $opt_doctype as $k => $v) {
echo '<option value="', $k,'"';
if ($k == $flt->doctype) {
echo ' selected';
}
echo '>', $v, '</option>';
}
filter_create_select('flt_doctype', _('Type'), $g_opt_all + $opt_doctype, $flt->doctype);
filter_create_select('flt_reftype', _('Reference'), $g_opt_none + $opt_reftype, $flt->reftype);
filter_create_text('flt_txt', _('Text'), $flt->txt, 15, 30);
?>
</select>
</div>
<div class="d-flex flex-nowrap gap-2">
<label for="flt_reftype"><?=_('Reference')?></label>
<select class="form-select" id="flt_reftype" name="flt_reftype">
<?php
$opt_special['none'] = _('&horbar; none &horbar;');
foreach ($opt_special + $opt_reftype as $k => $v) {
echo '<option value="', $k,'"';
if ($k == $flt->reftype) {
echo ' selected';
}
echo '>', $v, '</option>';
}
?>
</select>
</div>
<div class="d-flex flex-nowrap gap-2">
<label for="flt_txt">Text</label>
<input type="text" class="form-control" name="flt_txt" size="15" maxlength="30" value="<?=$flt->txt ?>">
</div>
</div>
<div class="card-footer">
<button name="submit[filter]" class="btn btn-sm btn-primary" title="<?=_('Apply')?>"><?=_('Go')?></button>
<button name="submit[freset]" class="btn btn-sm btn-secondary float-end" title="<?=_('Reset filter to defaults')?>"><?=_('Clear')?></button>
</div>
</div>
</form>
+5 -11
View File
@@ -45,7 +45,9 @@ switch ($submit = form_get_action()) {
break;
case 'freset':
db_clear_filter(200);
// set status checkboxes to useful defaults
$flt = array('flags' => ['ordered']);
db_save_filter($flt, 200);
$action = ACT_DEFAULT;
break;
@@ -329,19 +331,11 @@ $opt_none_male = array(-1 => pgettext('male', '&horbar; none &horbar;'));
filter_create_select('flt_category', _('Category'), $g_opt_all + $g_opt_none + $opt_ecat, $flt->cat);
filter_create_select('flt_manuf', _('Manufacturer'), $g_opt_all + $opt_none_male + $opt_manufacturer, $flt->manuf);
filter_create_select('flt_supp', _('Supplier'), $g_opt_all + $opt_none_male + $opt_supplier, $flt->supp);
?>
<div class="d-flex flex-nowrap gap-2">
<label for="flt_txt"><?=_('Text')?></label>
<input type="text" class="form-control" name="flt_txt" maxlength="30" value="<?=$flt->txt ?>">
</div>
<div class="d-flex flex-nowrap gap-2">
<?php
filter_create_text('flt_txt', _('Text'), $flt->txt, 15, 30);
$opt_flags = db_load_enum('equipment', 'flags', true, true, false);
filter_create_checks('flt_flags', _('Flags'), $opt_flags, $flt->flags ?? []);
filter_create_checks('flt_flags', _('Also show '), $opt_flags, $flt->flags ?? []);
?>
</div>
</div>
<div class="card-footer">
<button name="submit[filter]" class="btn btn-sm btn-primary" title="<?=_('Apply')?>"><?=_('Go')?></button>
<button name="submit[freset]" class="btn btn-sm btn-secondary float-end" title="<?=_('Reset filter to defaults')?>"><?=_('Clear')?></button>
+1 -1
View File
@@ -98,7 +98,7 @@ if ($action == ACT_DEFAULT):
$opt_ftype_short = db_get_options(DD_FUSE_TYPE, '', true);
// load filter from db
$flt = db_get_filter($user->id, 212);
$flt = db_get_filter($user->id, 212, ['txt','location']);
$w = array('vid=:vid');
$p = array(':vid' => $user->vid);
+37 -17
View File
@@ -157,6 +157,9 @@ $g_db_scheme_version = $sth->fetchColumn();
$g_db_scheme_required = 1;
// Schema version check
if ($g_db_scheme_version !== $g_db_scheme_required) {
// TODO if required schema version is smaller than found version then
// an database scheme update is neccessary
// otherwise our program code is outdated an should be updated
echo "<pre>\n";
echo "Database schema is wrong: detected version $g_db_scheme_version, but required version $g_db_scheme_required!\n";
echo "</pre>\n";
@@ -948,20 +951,20 @@ function form_create_check($fieldname, $label, $checked) {
function form_create_checks($fieldname, $label, $optlist, $selected = []) {
// create multiple combined checkboxes with title
echo '<fieldset class="mb-3">';
echo '<fieldset class="mb-3">', "\n";
echo '<legend class="fs-6 mb-1 border-bottom pb-1">', $label, "</legend>\n";
echo '<div class="d-flex flex-wrap gap-3">';
foreach ($optlist as $k => $v) {
echo '<div class="form-check">';
echo '<div class="form-check">', "\n";
$checked = in_array($k, $selected, true) ? ' checked' : '';
echo '<label class="form-check-label">';
echo '<input type="checkbox" class="form-check-input" name="', $fieldname, '[', $k, ']"', $checked, '>';
echo $v;
echo '</label>';
echo '</div>';
echo "</div>\n";
}
echo '</div>';
echo '</fieldset>';
echo "</div>\n";
echo "</fieldset>\n";
}
function form_add_button($script, $id=NULL, $idname='id') {
@@ -1025,6 +1028,20 @@ function form_tag_assignment($script, $id, $tags) {
echo "</tr>";
}
function filter_create_text($fieldname, $label, $value, $size=NULL, $maxlength=NULL) {
echo '<div class="d-flex flex-nowrap gap-2 align-items-start">', "\n";
echo '<label for="', $fieldname,'">', $label,'</label>', "\n";
echo '<input class="form-control" type="text" name="', $fieldname, '"';
if (isset($size)) {
echo ' size="', $size,'"';
}
if (isset($maxlength)) {
echo ' maxlength="', $maxlength, '"';
}
echo ' value="', h($value), '">', "\n";
echo "</div>\n";
}
function filter_create_select($fieldname, $label, $optlist, $selval=NULL, $multiple=FALSE) {
// - Wenn multiple gesetzt ist, muß selval ein array sein
// ansonsten ein einfacher String
@@ -1032,7 +1049,7 @@ function filter_create_select($fieldname, $label, $optlist, $selval=NULL, $multi
if (!is_array($selval)) {
}
} */
echo '<div class="d-flex flex-nowrap gap-2">', "\n";
echo '<div class="d-flex flex-nowrap gap-2 align-items-start">', "\n";
echo '<label for="', $fieldname,'">', $label,'</label>', "\n";
echo '<select class="form-select" id="', $fieldname, '" name="', $fieldname, '"', $multiple ? ' multiple' : '', ">\n";
foreach ($optlist as $k => $v) {
@@ -1043,25 +1060,25 @@ function filter_create_select($fieldname, $label, $optlist, $selval=NULL, $multi
echo '>', $v, '</option>', "\n";
}
echo "</select>\n";
echo "</div>";
echo "</div>\n";
}
function filter_create_checks($fieldname, $label, $optlist, $selected = []) {
// TODO WIP
echo '<fieldset class="mb-3">';
echo '<fieldset class="mb-3">', "\n";
echo '<legend class="fs-6 mb-1 border-bottom pb-1">', $label, "</legend>\n";
echo '<div class="d-flex flex-wrap gap-3">';
echo '<div class="d-flex flex-wrap gap-3">', "\n";
foreach ($optlist as $k => $v) {
echo '<div class="form-check">';
echo '<div class="form-check">', "\n";
$checked = in_array($k, $selected, true) ? ' checked' : '';
echo '<label class="form-check-label">';
echo '<input type="checkbox" class="form-check-input" name="', $fieldname, '[', $k, ']"', $checked, '>';
echo $v;
echo '</label>';
echo '</div>';
echo '<label class="form-check-label">', "\n";
echo '<input type="checkbox" class="form-check-input" name="', $fieldname, '[', $k, ']"', $checked, ">\n";
echo $v, "\n";
echo "</label>\n";
echo "</div>\n";
}
echo '</div>';
echo '</fieldset>';
echo "</div>\n";
echo "</fieldset>\n";
}
// ========== FORMAT FUNCTIONS ================================================
@@ -1179,6 +1196,9 @@ function format_measurement($n, $unit, $v1, $v2, $v3) {
function h($value, $br=false) {
// escape value coming from db for safe html output
// optional convert line breaks to <br> tags
if (!isset($value)) {
return '';
}
$value = htmlspecialchars($value, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
return $br ? nl2br($value) : $value;
}
+4 -35
View File
@@ -220,42 +220,11 @@ $opt_special = array(
// - selection for storage
// - selection for box
// page specific filter end
filter_create_select('flt_stor', _('Storage'), $g_opt_all + $g_opt_none + $opt_storage, $flt->stor);
filter_create_select('flt_cond', _('Condition'), $g_opt_all + $opt_invcond, $flt->cond);
filter_create_text('flt_text', _('Text'), $flt->txt, 15, 30);
?>
<div class="d-flex flex-nowrap gap-2">
<label for="flt_stor"><?=_('Storage')?></label>
<select class="form-select" id="flt_stor" name="flt_stor">
<?php
foreach ($opt_special + $opt_storage as $k => $v) {
echo '<option value="', $k,'"';
if ($k == $flt->stor) {
echo ' selected';
}
echo '>', $v, '</option>';
}
?>
</select>
</div>
<div class="d-flex flex-nowrap gap-2">
<label for="flt_cond"><?=_('Condition')?></label>
<select class="form-select" id="flt_cond" name="flt_cond">
<?php
$opt_special = array(
-2 => _('&horbar; all &horbar;'),
);
foreach ($opt_special + $opt_invcond as $k => $v) {
echo '<option value="', h($k), '"';
if ($k == $flt->cond) {
echo ' selected';
}
echo '>', $v, '</option>';
}
?>
</select>
</div>
<div class="d-flex flex-nowrap gap-2">
<label for="flt_txt">Text</label>
<input type="text" class="form-control" name="flt_txt" size="15" maxlength="30" value="<?=h($flt->txt)?>">
</div>
</div>
<div class="card-footer">
<button name="submit[filter]" class="btn btn-sm btn-primary" title="<?=_('Apply')?>"><?=_('Go')?></button>
+285 -281
View File
File diff suppressed because it is too large. Load diff
Binary file not shown.
+3 -1
View File
@@ -57,7 +57,9 @@ switch ($submit = form_get_action()) {
break;
case 'freset':
db_clear_filter(204);
// set status checkboxes to useful defaults
$flt = array('status' => ['new','plan','ongoing']);
db_save_filter($flt, 204);
$action = ACT_DEFAULT;
break;
+21 -8
View File
@@ -53,8 +53,9 @@ switch ($submit = form_get_action()) {
case 'filter':
$flt = array();
$flt['precision'] = gpc_get_string($_POST, 'flt_precision');
$flt['txt'] = gpc_get_string($_POST, 'flt_txt');
$flt['cat'] = gpc_get_string($_POST, 'flt_cat');
$flt['acc'] = gpc_get_string($_POST, 'flt_acc');
db_save_filter($flt, 207);
$action = ACT_DEFAULT;
break;
@@ -145,7 +146,7 @@ if ($action == ACT_DEFAULT):
page_caption_search($pagetitle);
// load filter from db
$flt = db_get_filter($user->id, 207, ['txt']);
$flt = db_get_filter($user->id, 207, ['txt', 'cat', 'acc']);
$w = array('(vid=:vid OR vid IS NULL)');
$p = array(':vid' => $user->vid);
@@ -153,9 +154,20 @@ $p = array(':vid' => $user->vid);
// TODO precision additionally as filter
if (strlen($flt->txt) > 1) {
$w[] = 'mname LIKE :txt';
$w[] = 'mname LIKE :txt OR note LIKE :txt';
$p[':txt'] = '%'.$flt->txt.'%';
}
if ($flt->cat > 0) {
$w[] = 'mcat=:mcat';
$p[':mcat'] = $flt->cat;
} elseif ($flt->mcat == -1) {
$w[] = 'mcat IS NULL';
}
if ($flt->acc > 0) {
$w[] = 'accuracy=:accuracy';
$p[':accuracy'] = $flt->acc;
}
$where = join(' AND ', $w);
$order = ' ORDER BY mname';
@@ -180,14 +192,15 @@ $opt_special = array(
-1 => _('&horbar; none &horbar;')
);
?>
<form method="post" action="<?=$g_scriptname?>">
<form id="filterform" method="post" action="<?=$g_scriptname?>">
<div id="filter" class="card">
<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_txt">Text</label>
<input type="text" class="form-control" name="flt_txt" size="15" maxlength="30" value="<?=$flt->txt ?>">
</div>
<?php
filter_create_text('flt_txt', _('Text'), $flt->txt, 30, 45);
filter_create_select('flt_cat', _('Category'), $g_opt_all + $g_opt_none + $opt_category, $flt->cat);
filter_create_select('flt_acc', _('Accuracy'), $g_opt_all + $opt_accuracy, $flt->acc);
?>
</div>
<div class="card-footer">
<button name="submit[filter]" class="btn btn-sm btn-primary" title="<?=_('Apply')?>"><?=_('Go')?></button>
+2 -8
View File
@@ -172,17 +172,11 @@ $res = $sth->fetchAll();
<div id="filter" class="card">
<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 ?? '';?>">
</div>
<?php
filter_create_text('flt_name', _('Name'), $flt->name, 15, 30);
filter_create_select('flt_state', _('State'), $g_opt_all + $opt_state, $flt->state ?? -2, FALSE);
filter_create_text('flt_remarks', _('Remarks'), $flt->remarks, 15, 30);
?>
<div class="d-flex flex-nowrap gap-2">
<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">
<button name="submit[filter]" class="btn btn-sm btn-primary" title="<?=_('Apply')?>"><?=_('Go')?></button>
+2 -5
View File
@@ -102,7 +102,7 @@ if ($action == ACT_DEFAULT):
page_caption_search($pagetitle);
// load filter from db
$flt = db_get_filter($user->id, 202);
$flt = db_get_filter($user->id, 202, ['cat','txt']);
$w = array('(vid=:vid OR sid IS NULL)');
$p = array(':vid' => $user->vid);
@@ -160,11 +160,8 @@ $res = $sth->fetchAll();
<div class="card-body d-flex flex-wrap gap-3">
<?php
filter_create_select('flt_cat', _('Category'), $g_opt_all + $g_opt_none + $opt_category, $flt->cat);
filter_create_text('flt_txt', _('Text'), $flt->txt, 15, 30);
?>
<div class="d-flex flex-nowrap gap-2">
<label for="flt_txt">Text</label>
<input type="text" class="form-control" name="flt_txt" maxlength="30" value="<?=$flt->txt;?>">
</div>
</div>
<div class="card-footer">
<button name="submit[filter]" class="btn btn-sm btn-primary" title="<?=_('Apply')?>"><?=_('Go')?></button>
+4 -5
View File
@@ -90,14 +90,13 @@ echo "<h1>$pagetitle</h1>\n";
// Filter
?>
<form method="post" action="<?=$g_scriptname?>">
<form id="filterform" method="post" action="<?=$g_scriptname?>">
<div id="filter" class="card">
<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_txt">Text</label>
<input type="text" class="form-control" name="flt_txt" size="15" maxlength="30" value="<?=$flt->txt ?? ''?>">
</div>
<?php
filter_create_text('flt_txt', _('Text'), $flt->txt, 30, 45);
?>
</div>
<div class="card-footer">
<button name="submit[filter]" class="btn btn-sm btn-primary" title="<?=_('Apply')?>"><?=_('Go')?></button>
+2 -7
View File
@@ -201,7 +201,7 @@ try {
$res = $sth->fetchAll();
?>
<form method="post" action="<?=$g_scriptname?>">
<form id="filterform" method="post" action="<?=$g_scriptname?>">
<div id="filter" class="card">
<div class="card-header"><i class="bi bi-funnel me-2"></i>Filter</div>
<div class="card-body d-flex flex-wrap gap-3">
@@ -209,12 +209,7 @@ $res = $sth->fetchAll();
$opt_proj_filter = db_get_opt_proj($user->vid, ['finished']);
filter_create_select('flt_proj', _('Project'), $g_opt_all + $g_opt_none + $opt_proj_filter, $flt->proj);
filter_create_select('flt_prio', _('Priority'), $g_opt_all + $g_opt_none + $opt_priority, $flt->prio);
?>
<div class="d-flex flex-nowrap gap-2">
<label for="flt_txt">Text</label>
<input type="text" class="form-control" name="flt_txt" size="15" maxlength="30" value="<?=$flt->txt ?>">
</div>
<?php
filter_create_text('flt_txt', _('Text'), $flt->txt, 15, 30);
$opt_status = db_load_enum('task', 'taskstate', true, true, false);
filter_create_checks('flt_stat', _('Status'), $opt_status, $flt->stat ?? []);
?>
+10
View File
@@ -0,0 +1,10 @@
.field-name {
color: #3D3846;
}
.field-value {
color: black;
}
.invalid {
color: #cc0000;
background-color: #ffdddd;
}