Webgui improve filter functions
This commit is contained in:
1 parent
b3825cb1b3
commit
9d09b1e120
17 files changed
+435
-458
No files matched your search
+25
-22
@@ -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 => _('― all ―'),
|
||||
);
|
||||
?>
|
||||
<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>
|
||||
|
||||
Reference in new issue
Block a user