From 40c143c8434523c8f57b122367e07d4ef11d7b71 Mon Sep 17 00:00:00 2001 From: Stefan Becker Date: Wed, 18 Jun 2008 10:12:11 +0000 Subject: [PATCH] "Patch for negate the seaching in custom fields, starting with \"!\" " --- addressbook/inc/class.addressbook_sql.inc.php | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/addressbook/inc/class.addressbook_sql.inc.php b/addressbook/inc/class.addressbook_sql.inc.php index da8ca97c26..f9ea2b99fc 100644 --- a/addressbook/inc/class.addressbook_sql.inc.php +++ b/addressbook/inc/class.addressbook_sql.inc.php @@ -287,17 +287,14 @@ class addressbook_sql extends so_sql } else { $valarray[]=$val; } + $negate = false; //negate the search funktion + if ($criteria[$col][0] == '!') $negate = True; unset($criteria[$col]); foreach ($valarray as $vkey => $part) { - if ($op=='AND') { - $criteria[] =$this->extra_table.'.contact_id in (select '.$this->extra_table.'.contact_id from '.$this->extra_table.' where '. - "(".$this->extra_table.".contact_name='".substr($col,1)."' AND ".$this->extra_table.".contact_value".($wildcard?' LIKE ':'=')."'".$wildcard.$part.$wildcard."'))"; - } else { - $criteria[] = $this->db->expression($this->extra_table,'(',array( - $this->extra_table.'.contact_name='."'".substr($col,1)."'", - $this->extra_table.'.contact_value'.($wildcard?' LIKE ':'=')."'".$wildcard.$part.$wildcard."'"),')'); - } + $criteria[] =$this->table_name.'.contact_id'.($negate ? ' not ' :'').' in (select '.$this->extra_table.'.contact_id from '.$this->extra_table.' where '. + "(".$this->extra_table.".contact_name='".substr($col,1)."' AND ".$this->extra_table.".contact_value".(!$wildcard?' = ':' LIKE ')."'".$wildcard.($negate?substr($part,1):$part).$wildcard."'"."))"; + } $search_customfields = true; }