diff options
| author | alec <alec@208e9e7b-5314-0410-a742-e7e81cd9613c> | 2011-06-03 11:03:13 +0000 |
|---|---|---|
| committer | alec <alec@208e9e7b-5314-0410-a742-e7e81cd9613c> | 2011-06-03 11:03:13 +0000 |
| commit | 9e1831bf53bdddcd9e03677b066a53a5b94c581f (patch) | |
| tree | e1e6247743101bf9d08ffddce9c892cb8c0df853 /roundcubemail/program/include/rcube_ldap.php | |
| parent | 9befba3a75c6fa25a987c1d2009d85bc34462caa (diff) | |
- Added addressbook advanced search
git-svn-id: https://svn.roundcube.net/trunk@4834 208e9e7b-5314-0410-a742-e7e81cd9613c
Diffstat (limited to 'roundcubemail/program/include/rcube_ldap.php')
| -rw-r--r-- | roundcubemail/program/include/rcube_ldap.php | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/roundcubemail/program/include/rcube_ldap.php b/roundcubemail/program/include/rcube_ldap.php index 7f0ea84fa..0c865a9c7 100644 --- a/roundcubemail/program/include/rcube_ldap.php +++ b/roundcubemail/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 .= ')'; |
