Support !(negation) of any instance in "instances" field of accounts search

This commit is contained in:
Bofh 2022-12-19 16:13:20 +01:00
parent addb800ec5
commit 5795a7fc0d
1 changed files with 20 additions and 4 deletions

View File

@ -59,20 +59,36 @@ $sql_all = '
'; ';
$instances = null; $instances = null;
$ninstances = null;
if (isset($_GET['instances'])) { if (isset($_GET['instances'])) {
$instances = []; $instances = [];
$ninstances = [];
foreach (explode(',',$_GET['instances']) as $instance) { foreach (explode(',',$_GET['instances']) as $instance) {
$instance = trim($instance); $instance = trim($instance);
if (valid_domain_name($instance)) $not_bool = $instance[0] === '!';
$instances []= "'".$instance."'"; if ($not_bool)
$instance = substr($instance, 1);
if (valid_domain_name($instance)) {
if ($not_bool)
$ninstances []= "'".$instance."'";
else $instances []= "'".$instance."'";
}
} }
if (count($instances) > 0) if (count($instances) > 0)
$instances = implode(',', $instances); $instances = implode(',', $instances);
else $instances = null; else $instances = null;
if (count($ninstances) > 0)
$ninstances = implode(',', $ninstances);
else $ninstances = null;
} }
$_ = '';
if ($instances !== null) if ($instances !== null)
$sql_all = str_replace('{instanceFilter}', "a.domain IN ($instances) AND", $sql_all); $_ .= "a.domain IN ($instances) AND ";
else $sql_all = str_replace('{instanceFilter}', '', $sql_all); if ($ninstances !== null)
$_ .= "NOT a.domain IN ($ninstances) AND ";
$_ = trim($_);
$sql_all = str_replace('{instanceFilter}', $_, $sql_all);
unset($_);
$user_filter = 'local'; $user_filter = 'local';
if (isset($_GET['user_filter'])) { if (isset($_GET['user_filter'])) {