@ -719,10 +719,7 @@ class rcube_ldap extends rcube_addressbook
*
*
* @param mixed $fields The field name of array of field names to search in
* @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 mixed $value Search value (or array of values when $fields is array)
* @param int $mode Matching mode:
* @param int $mode Matching mode. Sum of rcube_addressbook::SEARCH_*
* 0 - partial (*abc*),
* 1 - strict (=),
* 2 - prefix (abc*)
* @param boolean $select True if results are requested, False if count only
* @param boolean $select True if results are requested, False if count only
* @param boolean $nocount (Not used)
* @param boolean $nocount (Not used)
* @param array $required List of fields that cannot be empty
* @param array $required List of fields that cannot be empty
@ -753,7 +750,7 @@ class rcube_ldap extends rcube_addressbook
if ($this->prop['vlv_search'] & & $this->ready & & join(',', (array)$fields) == join(',', $list_fields)) {
if ($this->prop['vlv_search'] & & $this->ready & & join(',', (array)$fields) == join(',', $list_fields)) {
$this->result = new rcube_result_set(0);
$this->result = new rcube_result_set(0);
$this->ldap->config_set('fuzzy_search', intval($this->prop['fuzzy_search'] & & $mode != 1 ));
$this->ldap->config_set('fuzzy_search', intval($this->prop['fuzzy_search'] & & !($mode & rcube_addressbook::SEARCH_STRICT) ));
$ldap_data = $this->ldap->search($this->base_dn, $this->prop['filter'], $this->prop['scope'], $this->prop['attributes'],
$ldap_data = $this->ldap->search($this->base_dn, $this->prop['filter'], $this->prop['scope'], $this->prop['attributes'],
array('search' => $value /*, 'sort' => $this->prop['sort'] */));
array('search' => $value /*, 'sort' => $this->prop['sort'] */));
if ($ldap_data === false) {
if ($ldap_data === false) {
@ -785,9 +782,9 @@ class rcube_ldap extends rcube_addressbook
// set wildcards
// set wildcards
$wp = $ws = '';
$wp = $ws = '';
if (!empty($this->prop['fuzzy_search']) & & $mode != 1 ) {
if (!empty($this->prop['fuzzy_search']) & & !($mode & rcube_addressbook::SEARCH_STRICT) ) {
$ws = '*';
$ws = '*';
if (!$mode) {
if (!( $mode & rcube_addressbook::SEARCH_PREFIX) ) {
$wp = '*';
$wp = '*';
}
}
}
}
@ -853,10 +850,12 @@ class rcube_ldap extends rcube_addressbook
// avoid double-wildcard if $value is empty
// avoid double-wildcard if $value is empty
$filter = preg_replace('/\*+/', '*', $filter);
$filter = preg_replace('/\*+/', '*', $filter);
if ($mode & rcube_addressbook::SEARCH_GROUPS) {
$filter = 'e:' . $filter;
}
// set filter string and execute search
// set filter string and execute search
// @FIXME: we need a better way to detect/define when groups are allowed in the result
$this->set_search_set($filter);
$prefix = empty($required) ? 'e:' : '';
$this->set_search_set($prefix . $filter);
if ($select)
if ($select)
$this->list_records();
$this->list_records();
@ -1669,10 +1668,7 @@ class rcube_ldap extends rcube_addressbook
* List all active contact groups of this source
* List all active contact groups of this source
*
*
* @param string Optional search string to match group name
* @param string Optional search string to match group name
* @param int Matching mode:
* @param int Matching mode. Sum of rcube_addressbook::SEARCH_*
* 0 - partial (*abc*),
* 1 - strict (=),
* 2 - prefix (abc*)
*
*
* @return array Indexed list of contact groups, each a hash array
* @return array Indexed list of contact groups, each a hash array
*/
*/
@ -1764,9 +1760,11 @@ class rcube_ldap extends rcube_addressbook
if ($search !== null) {
if ($search !== null) {
// set wildcards
// set wildcards
$wp = $ws = '';
$wp = $ws = '';
if (!empty($this->prop['fuzzy_search']) & & $mode != 1 ) {
if (!empty($this->prop['fuzzy_search']) & & !($mode & rcube_addressbook::SEARCH_STRICT) ) {
$ws = '*';
$ws = '*';
$wp = !$mode ? '*' : '';
if (!($mode & rcube_addressbook::SEARCH_PREFIX)) {
$wp = '*';
}
}
}
$filter = "(& $filter($name_attr=$wp" . rcube_ldap_generic::quote_string($search) . "$ws))";
$filter = "(& $filter($name_attr=$wp" . rcube_ldap_generic::quote_string($search) . "$ws))";
$props['search'] = $wp . $search . $ws;
$props['search'] = $wp . $search . $ws;