From 7479d3f1f145ff6ae4335a379b61a47d55ddbc77 Mon Sep 17 00:00:00 2001 From: externo6 Date: Sat, 28 Sep 2019 13:03:16 +0100 Subject: [PATCH 1/3] Add LIKE and NOT LIKE to filter options This is useful for filtering notes. EG filtering detected objects from zmeventnofification; WHERE notes LIKE %detect% WHERE notes NOT LIKE %car% --- web/includes/functions.php | 2 ++ web/lang/en_gb.php | 2 ++ web/skins/classic/views/filter.php | 2 ++ 3 files changed, 6 insertions(+) diff --git a/web/includes/functions.php b/web/includes/functions.php index 7d8ace272..fc4c398c5 100644 --- a/web/includes/functions.php +++ b/web/includes/functions.php @@ -1275,6 +1275,8 @@ function parseFilter(&$filter, $saveToSession=false, $querySep='&') { case '>' : case '<' : case '<=' : + case 'LIKE' : + case 'NOT LIKE': $filter['sql'] .= ' '.$term['op'].' '. $value; break; case '=~' : diff --git a/web/lang/en_gb.php b/web/lang/en_gb.php index b2890a605..38799c9a0 100644 --- a/web/lang/en_gb.php +++ b/web/lang/en_gb.php @@ -579,6 +579,8 @@ $SLANG = array( 'OpNotMatches' => 'does not match', 'OpIs' => 'is', 'OpIsNot' => 'is not', + 'OpLike' => 'like', + 'OpNotLike' => 'not like', 'OptionalEncoderParam' => 'Optional Encoder Parameters', 'OptionHelp' => 'Option Help', 'OptionRestartWarning' => 'These changes may not come into effect fully\nwhile the system is running. When you have\nfinished making your changes please ensure that\nyou restart ZoneMinder.', diff --git a/web/skins/classic/views/filter.php b/web/skins/classic/views/filter.php index 67eaf7fc2..425e914c9 100644 --- a/web/skins/classic/views/filter.php +++ b/web/skins/classic/views/filter.php @@ -115,6 +115,8 @@ $opTypes = array( '![]' => translate('OpNotIn'), 'IS' => translate('OpIs'), 'IS NOT' => translate('OpIsNot'), + 'LIKE' => translate('OpLike'), + 'NOT LIKE' => translate('OpNotLike'), ); $archiveTypes = array( From 4b71bc75eab113240cf5a69650c2149839083ac4 Mon Sep 17 00:00:00 2001 From: externo6 Date: Wed, 16 Oct 2019 00:35:49 +0100 Subject: [PATCH 2/3] Change language to Contains / Not Contains and update perl filter. --- scripts/ZoneMinder/lib/ZoneMinder/Filter.pm | 9 +++++++++ web/includes/functions.php | 3 +++ web/lang/en_gb.php | 4 ++-- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/scripts/ZoneMinder/lib/ZoneMinder/Filter.pm b/scripts/ZoneMinder/lib/ZoneMinder/Filter.pm index 611bea059..7a78e3b71 100644 --- a/scripts/ZoneMinder/lib/ZoneMinder/Filter.pm +++ b/scripts/ZoneMinder/lib/ZoneMinder/Filter.pm @@ -236,6 +236,11 @@ sub Sql { || $term->{attr} eq 'Cause' || $term->{attr} eq 'Notes' ) { + if ( $term->{op} eq 'LIKE' + || $term->{op} eq 'NOT LIKE' + ) { + $temp_value = '%'.$temp_value.'%'; + } $value = "'$temp_value'"; } elsif ( $term->{attr} eq 'DateTime' or $term->{attr} eq 'StartDateTime' or $term->{attr} eq 'EndDateTime' ) { if ( $temp_value eq 'NULL' ) { @@ -295,6 +300,10 @@ sub Sql { $self->{Sql} .= ' IN ('.join(',', @value_list).')'; } elsif ( $term->{op} eq '!~' ) { $self->{Sql} .= ' NOT IN ('.join(',', @value_list).')'; + } elsif ( $term->{op} eq 'LIKE' ) { + $self->{Sql} .= " LIKE $value"; + } elsif ( $term->{op} eq 'NOT LIKE' ) { + $self->{Sql} .= " NOT LIKE $value"; } else { $self->{Sql} .= ' '.$term->{op}.' '.$value; } diff --git a/web/includes/functions.php b/web/includes/functions.php index fc4c398c5..825467fb4 100644 --- a/web/includes/functions.php +++ b/web/includes/functions.php @@ -1223,6 +1223,9 @@ function parseFilter(&$filter, $saveToSession=false, $querySep='&') { case 'Name': case 'Cause': case 'Notes': + if($term['op'] == 'LIKE' || $term['op'] == 'NOT LIKE') { + $value = '%'.$value.'%'; + } $value = dbEscape($value); break; case 'MonitorServerId': diff --git a/web/lang/en_gb.php b/web/lang/en_gb.php index 38799c9a0..94236dc81 100644 --- a/web/lang/en_gb.php +++ b/web/lang/en_gb.php @@ -579,8 +579,8 @@ $SLANG = array( 'OpNotMatches' => 'does not match', 'OpIs' => 'is', 'OpIsNot' => 'is not', - 'OpLike' => 'like', - 'OpNotLike' => 'not like', + 'OpLike' => 'Contains', + 'OpNotLike' => 'Does not Contain', 'OptionalEncoderParam' => 'Optional Encoder Parameters', 'OptionHelp' => 'Option Help', 'OptionRestartWarning' => 'These changes may not come into effect fully\nwhile the system is running. When you have\nfinished making your changes please ensure that\nyou restart ZoneMinder.', From e232c22b3d461b8fa2e4cc762fea0eac443b9aac Mon Sep 17 00:00:00 2001 From: externo6 Date: Wed, 16 Oct 2019 10:10:23 +0100 Subject: [PATCH 3/3] Only add % to value if % is not present. --- scripts/ZoneMinder/lib/ZoneMinder/Filter.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/ZoneMinder/lib/ZoneMinder/Filter.pm b/scripts/ZoneMinder/lib/ZoneMinder/Filter.pm index 7a78e3b71..e14ae8d14 100644 --- a/scripts/ZoneMinder/lib/ZoneMinder/Filter.pm +++ b/scripts/ZoneMinder/lib/ZoneMinder/Filter.pm @@ -239,7 +239,7 @@ sub Sql { if ( $term->{op} eq 'LIKE' || $term->{op} eq 'NOT LIKE' ) { - $temp_value = '%'.$temp_value.'%'; + $temp_value = '%'.$temp_value.'%' if $temp_value !~ /%/; } $value = "'$temp_value'"; } elsif ( $term->{attr} eq 'DateTime' or $term->{attr} eq 'StartDateTime' or $term->{attr} eq 'EndDateTime' ) {