From b4f0f6bf8f5af56a3cdbd3bd0564c49c75e002d1 Mon Sep 17 00:00:00 2001 From: Jared Hancock <jared@osticket.com> Date: Fri, 16 Nov 2012 16:44:04 -0600 Subject: [PATCH] Add support for start-/ends-with in filters --- include/class.filter.php | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/include/class.filter.php b/include/class.filter.php index 9c172edaa..c7f1d70c0 100644 --- a/include/class.filter.php +++ b/include/class.filter.php @@ -233,7 +233,9 @@ class Filter { 'equal' => array('strcmp', 0), 'not_equal' => array('strcmp', null, 0), 'contains' => array('strpos', null, false), - 'dn_contain'=> array('strpos', false) + 'dn_contain'=> array('strpos', false), + 'starts' => array('strpos', 0), + 'ends' => array('endsWith', true) ); $match = false; @@ -309,7 +311,9 @@ class Filter { 'equal'=> 'Equal', 'not_equal'=> 'Not Equal', 'contains'=> 'Contains', - 'dn_contain'=> 'Does Not Contain' + 'dn_contain'=> 'Does Not Contain', + 'starts'=> 'Starts With', + 'ends'=> 'Ends With' ); } @@ -366,8 +370,8 @@ class Filter { function save_rules($id,$vars,&$errors) { - $matches=array('name','email','subject','body','header'); - $types=array('equal','not_equal','contains','dn_contain'); + $matches = array_keys(self::getSupportedMatches()); + $types = array_keys(self::getSupportedMatchTypes()); $rules=array(); for($i=1; $i<=25; $i++) { //Expecting no more than 25 rules... @@ -903,4 +907,20 @@ class TicketFilter { return $sources[strtolower($origin)]; } } + +/** + * Function: endsWith + * + * Returns TRUE if the haystack ends with needle and FALSE otherwise. + * Thanks, http://stackoverflow.com/a/834355 + */ +function endsWith($haystack, $needle) +{ + $length = strlen($needle); + if ($length == 0) { + return true; + } + + return (substr($haystack, -$length) === $needle); +} ?> -- GitLab