diff options
author | alecpl <alec@alec.pl> | 2011-06-03 11:03:13 +0000 |
---|---|---|
committer | alecpl <alec@alec.pl> | 2011-06-03 11:03:13 +0000 |
commit | e9a9f2f6c52e41f3e85fc3ab0ee93afecd080892 (patch) | |
tree | 325e109797a408c5ec14ba5952dbc24882971285 /program/include/rcube_ldap.php | |
parent | 4649969c16a7dc938032de8f2b5bfcfb20e7bb03 (diff) |
- Added addressbook advanced search
Diffstat (limited to 'program/include/rcube_ldap.php')
-rw-r--r-- | program/include/rcube_ldap.php | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/program/include/rcube_ldap.php b/program/include/rcube_ldap.php index 7f0ea84fa..0c865a9c7 100644 --- a/program/include/rcube_ldap.php +++ b/program/include/rcube_ldap.php @@ -451,12 +451,13 @@ class rcube_ldap extends rcube_addressbook /** * Search contacts * - * @param array List of fields to search in - * @param string Search value - * @param boolean True for strict, False for partial (fuzzy) matching - * @param boolean True if results are requested, False if count only - * @param boolean (Not used) - * @param array List of fields that cannot be empty + * @param mixed $fields The field name of array of field names to search in + * @param mixed $value Search value (or array of values when $fields is array) + * @param boolean $strict True for strict, False for partial (fuzzy) matching + * @param boolean $select True if results are requested, False if count only + * @param boolean $nocount (Not used) + * @param array $required List of fields that cannot be empty + * * @return array Indexed list of contact records and 'count' value */ function search($fields, $value, $strict=false, $select=true, $nocount=false, $required=array()) @@ -477,8 +478,10 @@ class rcube_ldap extends rcube_addressbook return $result; } - $filter = '(|'; - $wc = !$strict && $this->prop['fuzzy_search'] ? '*' : ''; + // use AND operator for advanced searches + $filter = is_array($value) ? '(&' : '(|'; + $wc = !$strict && $this->prop['fuzzy_search'] ? '*' : ''; + if ($fields == '*') { // search_fields are required for fulltext search @@ -490,15 +493,19 @@ class rcube_ldap extends rcube_addressbook } if (is_array($this->prop['search_fields'])) { - foreach ($this->prop['search_fields'] as $k => $field) + foreach ($this->prop['search_fields'] as $field) { $filter .= "($field=$wc" . $this->_quote_string($value) . "$wc)"; + } } } else { - foreach ((array)$fields as $field) - if ($f = $this->_map_field($field)) - $filter .= "($f=$wc" . $this->_quote_string($value) . "$wc)"; + foreach ((array)$fields as $idx => $field) { + $val = is_array($value) ? $value[$idx] : $value; + if ($f = $this->_map_field($field)) { + $filter .= "($f=$wc" . $this->_quote_string($val) . "$wc)"; + } + } } $filter .= ')'; |