From 51a1d511fbf36ae78f7ba20466789d8d07dfd00e Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Fri, 26 May 2023 16:36:40 -0400 Subject: [PATCH] Fix incorect merging of terms in sort. Fixes #3715. Also always show text op in simple_widget --- web/includes/Filter.php | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/web/includes/Filter.php b/web/includes/Filter.php index 6287c0e17..aced8a606 100644 --- a/web/includes/Filter.php +++ b/web/includes/Filter.php @@ -1028,12 +1028,13 @@ class Filter extends ZM_Object { $html .= ''; $html .= html_input("filter[Query][terms][$i][attr]", 'hidden', $term['attr']); $html .= html_input("filter[Query][terms][$i][op]", 'hidden', $term['op']).PHP_EOL; + $html .= ''. $term['op'].''.PHP_EOL; + #$html .= ''.htmlSelect("filter[Query][terms][$i][op]", $opTypes, $term['op']).''.PHP_EOL; + if ( $term['attr'] == 'Archived' ) { $html .= htmlSelect("filter[Query][terms][$i][val]", $archiveTypes, $term['val']).PHP_EOL; } else if ( $term['attr'] == 'DateTime' || $term['attr'] == 'StartDateTime' || $term['attr'] == 'EndDateTime') { - #$html .= ''. $term['op'].''.PHP_EOL; - #$html .= ''.htmlSelect("filter[Query][terms][$i][op]", $opTypes, $term['op']).''.PHP_EOL; $html .= ''.PHP_EOL; } else if ( $term['attr'] == 'Date' || $term['attr'] == 'StartDate' || $term['attr'] == 'EndDate' ) { - #$html .= ''. $term['op'].''.PHP_EOL; - #$html .= ''.htmlSelect("filter[Query][terms][$i][op]", $opTypes, $term['op']).''.PHP_EOL; $html .= ''.PHP_EOL; $html .= ''.PHP_EOL; } else if ( $term['attr'] == 'ExistsInFileSystem' ) { $html .= $term['attr']; - $html .= ''.htmlSelect("filter[Query][terms][$i][op]", $is_isnot_opTypes, $term['op']).''.PHP_EOL; $html .= ''.htmlSelect("filter[Query][terms][$i][val]", $booleanValues, $term['val']).''.PHP_EOL; } else if ( $term['attr'] == 'Group') { - #$html .= ''.htmlSelect("filter[Query][terms][$i][op]", $opTypes, $term['op']).''.PHP_EOL; $html .= ''.htmlSelect("filter[Query][terms][$i][val]", Group::get_dropdown_options(), $term['val'], ['class'=>'chosen', 'multiple'=>'multiple', 'data-placeholder'=>translate('All Groups')]).''.PHP_EOL; } else if ( $term['attr'] == 'StateId' ) { - $html .= ''.htmlSelect("filter[Query][terms][$i][op]", $opTypes, $term['op']).''.PHP_EOL; $html .= ''.htmlSelect("filter[Query][terms][$i][val]", $states, $term['val']).''.PHP_EOL; } else if ( strpos($term['attr'], 'Weekday') !== false ) { - $html .= ''.htmlSelect("filter[Query][terms][$i][op]", $opTypes, $term['op']).''.PHP_EOL; $html .= ''.htmlSelect("filter[Query][terms][$i][val]", $weekdays, $term['val']).''.PHP_EOL; } else if ( $term['attr'] == 'Monitor' ) { $monitors = []; @@ -1085,7 +1079,6 @@ class Filter extends ZM_Object { $monitors[$m->Id()] = $m->Id().' '.validHtmlStr($m->Name()); } } - #$html .= ''. $term['op'].''.PHP_EOL; $selected = explode(',', $term['val']); if (count($selected) == 1 and !$selected[0]) { $selected = null; @@ -1097,7 +1090,6 @@ class Filter extends ZM_Object { if (!$selected and isset($_COOKIE[$term['cookie']]) and $_COOKIE[$term['cookie']]) $selected = explode(',', $_COOKIE[$term['cookie']]); } - #$html .= ''.htmlSelect("filter[Query][terms][$i][op]", $opTypes, $term['op']).''.PHP_EOL; $html .= ''.htmlSelect("filter[Query][terms][$i][val]", $monitors, $selected, $options).''.PHP_EOL; } else if ( $term['attr'] == 'MonitorName' ) { $monitor_names = []; @@ -1106,26 +1098,21 @@ class Filter extends ZM_Object { $monitor_names[$m->Name()] = validHtmlStr($m->Name()); } } - $html .= ''.htmlSelect("filter[Query][terms][$i][op]", $opTypes, $term['op']).''.PHP_EOL; $html .= ''.htmlSelect("filter[Query][terms][$i][val]", array_combine($monitor_names,$monitor_names), $term['val'], ['class'=>'chosen', 'multiple'=>'multiple', 'data-placeholder'=>translate('All Monitors')]).''.PHP_EOL; } else if ( $term['attr'] == 'ServerId' || $term['attr'] == 'MonitorServerId' || $term['attr'] == 'StorageServerId' || $term['attr'] == 'FilterServerId' ) { - $html .= ''.htmlSelect("filter[Query][terms][$i][op]", $opTypes, $term['op']).''.PHP_EOL; $html .= ''.htmlSelect("filter[Query][terms][$i][val]", $servers, $term['val'], ['class'=>'chosen', 'multiple'=>'multiple']).''.PHP_EOL; } else if ( ($term['attr'] == 'StorageId') || ($term['attr'] == 'SecondaryStorageId') ) { if (!$storageareas) { $storageareas = array('' => array('Name'=>'NULL Unspecified'), '0' => array('Name'=>'Zero')) + ZM_Object::Objects_Indexed_By_Id('ZM\Storage'); } - $html .= ''.htmlSelect("filter[Query][terms][$i][op]", $opTypes, $term['op']).''.PHP_EOL; $html .= ''.htmlSelect("filter[Query][terms][$i][val]", $storageareas, $term['val'], ['class'=>'chosen', 'multiple'=>'multiple']).''.PHP_EOL; } else if ( $term['attr'] == 'AlarmedZoneId' ) { - $html .= ''.htmlSelect("filter[Query][terms][$i][op]", $opTypes, $term['op']).''.PHP_EOL; $html .= ''.htmlSelect("filter[Query][terms][$i][val]", $zones, $term['val'], ['class'=>'chosen', 'multiple'=>'multiple']).''.PHP_EOL; } else if ( $term['attr'] == 'Notes' ) { - #$html .= ''.htmlSelect("filter[Query][terms][$i][op]", $opTypes, $term['op']).''.PHP_EOL; $attrs = ['class'=>'chosen', 'multiple'=>'multiple', 'data-placeholder'=>translate('Event Type')]; $selected = explode(',', $term['val']); if (count($selected) == 1 and !$selected[0]) { @@ -1149,12 +1136,10 @@ class Filter extends ZM_Object { 'vehicle' => 'Vehicle']; $html .= ''.htmlSelect("filter[Query][terms][$i][val]", $options, $selected, $attrs).''.PHP_EOL; } else { - $html .= $term['attr']; - $html .= ''.htmlSelect("filter[Query][terms][$i][op]", $opTypes, $term['op']).''.PHP_EOL; + #$html .= $term['attr']; $html .= ''.PHP_EOL; } } else { # no attr ? - $html .= ''.htmlSelect("filter[Query][terms][$i][op]", $opTypes, $term['op']).''.PHP_EOL; $html .= ''.PHP_EOL; } @@ -1186,7 +1171,9 @@ class Filter extends ZM_Object { } } } - if (count($old_terms)) $new_terms += $old_terms; + if (count($old_terms)) { + $new_terms = array_merge($new_terms, $old_terms); + } $this->terms($new_terms); }