diff --git a/scripts/ZoneMinder/lib/ZoneMinder/Filter.pm b/scripts/ZoneMinder/lib/ZoneMinder/Filter.pm index 73e7b8321..b7fee879c 100644 --- a/scripts/ZoneMinder/lib/ZoneMinder/Filter.pm +++ b/scripts/ZoneMinder/lib/ZoneMinder/Filter.pm @@ -346,7 +346,7 @@ sub Sql { $self->{Sql} .= ' LIKE '.$value; } elsif ( $term->{op} eq 'NOT LIKE' ) { $self->{Sql} .= ' NOT LIKE '.$value; - } elsif ( $term->{attr} eq 'Tags' and ($term->{op} eq 'LIKE' or $term->{op} eq 'IS') and $term->{val} eq '') { + } elsif ( $term->{attr} eq 'Tags' and ($term->{op} eq 'LIKE' or $term->{op} eq 'IS') and $term->{val} eq 0) { $self->{Sql} .= 'NOT EXISTS (SELECT NULL FROM `Events_Tags` AS ET WHERE ET.EventId = E.Id)'; } else { $self->{Sql} .= ' '.$term->{op}.' '.$value; diff --git a/web/ajax/events.php b/web/ajax/events.php index dadb5963b..e5bf3a120 100644 --- a/web/ajax/events.php +++ b/web/ajax/events.php @@ -46,7 +46,7 @@ if (!empty($_REQUEST['MonitorId'])) { $filter->addTerm(array('cnj'=>'and', 'attr'=>'MonitorId', 'op'=> '=', 'val'=>$_REQUEST['MonitorId'])); } if (!empty($_REQUEST['Tag'])) { - $filter->addTerm(array('cnj'=>'and', 'attr'=>'Tag', 'op'=>'=', 'val'=>'')); + $filter->addTerm(array('cnj'=>'and', 'attr'=>'Tag', 'op'=>'=', 'val'=>$_REQUEST['Tag'])); } // Search contains a user entered string to search on diff --git a/web/includes/Filter.php b/web/includes/Filter.php index fe5b62aca..1eca3402b 100644 --- a/web/includes/Filter.php +++ b/web/includes/Filter.php @@ -924,6 +924,9 @@ class Filter extends ZM_Object { return self::$archiveTypes; } + // + // This displays filters from the filters page. + // public function widget() { $html = ''; $opTypes = $this->opTypes(); @@ -976,7 +979,7 @@ class Filter extends ZM_Object { } } } - $availableTags = array(''=>translate('No Tag')); + $availableTags = array('0'=>translate('No Tag')); foreach ( dbFetchAll('SELECT Id, Name FROM Tags ORDER BY lower(`Name`) ASC') AS $tag ) { $availableTags[$tag['Id']] = validHtmlStr($tag['Name']); } @@ -1011,14 +1014,11 @@ class Filter extends ZM_Object { $html .= ''.PHP_EOL; $options = ['class'=>'chosen chosen-full-width', 'multiple'=>'multiple']; $selected = explode(',', $term['val']); - if (count($selected) == 1 and !$selected[0]) { - $selected = null; - } $html .= ''.PHP_EOL; - // ZM\Debug('$availableTags: '.$availableTags); - // ZM\Debug('$selected: '.$selected); - - + // These echo statements print these variables at the top of the view for debugging. + // echo '
availableTags: '; print_r($availableTags); echo '
'; + // echo '
selected: '; print_r($selected); echo '
'; + // echo '
options: '; print_r($options); echo '
'; } else if ( $term['attr'] == 'DateTime' || $term['attr'] == 'StartDateTime' || $term['attr'] == 'EndDateTime') { $html .= ''.PHP_EOL; @@ -1088,6 +1088,9 @@ class Filter extends ZM_Object { return $html; } # end function widget() + // + // This displays filters from the events page. + // public function simple_widget() { $html = '
'; $terms = $this->terms(); @@ -1112,7 +1115,7 @@ class Filter extends ZM_Object { for ( $i = 0; $i < 7; $i++ ) { $weekdays[$i] = date('D', mktime(12, 0, 0, 1, $i+1, 2001)); } - $availableTags = array(''=>translate('No Tag')); + $availableTags = array('0'=>translate('No Tag')); foreach ( dbFetchAll('SELECT Id, Name FROM Tags ORDER BY lower(`Name`) ASC') AS $tag ) { $availableTags[$tag['Id']] = validHtmlStr($tag['Name']); } @@ -1146,11 +1149,7 @@ class Filter extends ZM_Object { $html .= htmlSelect("filter[Query][terms][$i][val]", $archiveTypes, $term['val'],['id'=>'filterArchived', 'class'=>'chosen chosen-auto-width']).PHP_EOL; $html .= ''; } else if ( $term['attr'] == 'Tags' ) { - $selected = empty($term['val']) ? [] : json_decode($term['val']); - // echo '
selected: '; print_r($selected); echo '
'; - if (count($selected) == 1 and !$selected[0]) { - $selected = null; - } + $selected = explode(',', $term['val']); $options = ['id'=>'filterTags', 'class'=>'chosen chosen-auto-width', 'multiple'=>'multiple', 'data-placeholder'=>translate('All Tags')]; if (isset($term['cookie'])) { $options['data-cookie'] = $term['cookie']; @@ -1158,10 +1157,10 @@ class Filter extends ZM_Object { if (!$selected and isset($_COOKIE[$term['cookie']]) and $_COOKIE[$term['cookie']]) $selected = json_decode($_COOKIE[$term['cookie']]); } - // These echo statements print these variables at the top of the view. - // echo '
availableTags: '; print_r($availableTags); echo '
'; - // echo '
selected: '; print_r($selected); echo '
'; - // echo '
options: '; print_r($options); echo '
'; + // These echo statements print these variables at the top of the view for debugging. + // echo '
availableTags: '; print_r($availableTags); echo '
'; + // echo '
selected: '; print_r($selected); echo '
'; + // echo '
options: '; print_r($options); echo '
'; $html .= ''; $html .= htmlSelect("filter[Query][terms][$i][val]", $availableTags, $selected, $options).PHP_EOL; diff --git a/web/includes/FilterTerm.php b/web/includes/FilterTerm.php index cc8aa30e2..95d6a8941 100644 --- a/web/includes/FilterTerm.php +++ b/web/includes/FilterTerm.php @@ -343,7 +343,7 @@ class FilterTerm { $subterms[] = $subterm; } $sql .= '('.implode(' OR ', $subterms).')'; - } elseif (($this->attr === 'Tags') && ($values[0] === '')) { + } elseif (($this->attr === 'Tags') && ($values[0] === "'0'")) { $sql .= 'NOT EXISTS (SELECT NULL FROM Events_Tags AS ET WHERE ET.EventId = E.Id)'; } else { $sql .= $this->sql_attr(); diff --git a/web/skins/classic/views/filter.php b/web/skins/classic/views/filter.php index 870403408..b8413587e 100644 --- a/web/skins/classic/views/filter.php +++ b/web/skins/classic/views/filter.php @@ -132,7 +132,7 @@ foreach (ZM\Zone::find([], ['order'=>'lower(`Name`) ASC']) as $zone ) { } } -$availableTags = array(''=>translate('No Tag')); +$availableTags = array('0'=>translate('No Tag')); foreach ( dbFetchAll('SELECT Id, Name FROM Tags ORDER BY LastAssignedDate DESC') AS $tag ) { $availableTags[$tag['Id']] = validHtmlStr($tag['Name']); }
'.htmlSelect("filter[Query][terms][$i][op]", $opTypes, $term['op'], ['class'=>'chosen chosen-full-width']).''.htmlSelect("filter[Query][terms][$i][val]", $availableTags, $selected, $options).''.htmlSelect("filter[Query][terms][$i][op]", $opTypes, $term['op'], ['class'=>'chosen chosen-full-width']).'