From 2f8b1036da42ec3d15a51c6b17a473f9f4df71d3 Mon Sep 17 00:00:00 2001
From: Thomas Bruederli <bruederli@kolabsys.com>
Date: Sat, 07 Feb 2015 12:33:24 -0500
Subject: [PATCH] Bump version and copyright year

---
 program/lib/Roundcube/rcube_ldap.php |   45 ++++++++++++++++++++++++---------------------
 1 files changed, 24 insertions(+), 21 deletions(-)

diff --git a/program/lib/Roundcube/rcube_ldap.php b/program/lib/Roundcube/rcube_ldap.php
index 274616a..13d55bd 100644
--- a/program/lib/Roundcube/rcube_ldap.php
+++ b/program/lib/Roundcube/rcube_ldap.php
@@ -64,7 +64,6 @@
 
     private $base_dn        = '';
     private $groups_base_dn = '';
-    private $group_url;
     private $group_data;
     private $group_search_cache;
     private $cache;
@@ -118,13 +117,14 @@
 
         // fieldmap property is given
         if (is_array($p['fieldmap'])) {
+            $p['fieldmap'] = array_filter($p['fieldmap']);
             foreach ($p['fieldmap'] as $rf => $lf)
                 $this->fieldmap[$rf] = $this->_attr_name(strtolower($lf));
         }
         else if (!empty($p)) {
             // read deprecated *_field properties to remain backwards compatible
             foreach ($p as $prop => $value)
-                if (preg_match('/^(.+)_field$/', $prop, $matches))
+                if (!empty($value) && preg_match('/^(.+)_field$/', $prop, $matches))
                     $this->fieldmap[$matches[1]] = $this->_attr_name(strtolower($value));
         }
 
@@ -766,16 +766,16 @@
         if ($this->prop['vlv_search'] && $this->ready && join(',', (array)$fields) == join(',', $list_fields)) {
             $this->result = new rcube_result_set(0);
 
-            $search_suffix = $this->prop['fuzzy_search'] && $mode != 1 ? '*' : '';
+            $this->ldap->config_set('fuzzy_search', intval($this->prop['fuzzy_search'] && $mode != 1));
             $ldap_data = $this->ldap->search($this->base_dn, $this->prop['filter'], $this->prop['scope'], $this->prop['attributes'],
-                array('search' => $value . $search_suffix /*, 'sort' => $this->prop['sort'] */));
+                array('search' => $value /*, 'sort' => $this->prop['sort'] */));
             if ($ldap_data === false) {
                 return $this->result;
             }
 
             // get all entries of this page and post-filter those that really match the query
             $search = mb_strtolower($value);
-            foreach ($ldap_data as $i => $entry) {
+            foreach ($ldap_data as $entry) {
                 $rec = $this->_ldap2result($entry);
                 foreach ($fields as $f) {
                     foreach ((array)$rec[$f] as $val) {
@@ -906,7 +906,6 @@
         return $this->result;
     }
 
-
     /**
      * Get a specific contact record
      *
@@ -946,6 +945,23 @@
         }
 
         return $assoc ? $res : $this->result;
+    }
+
+    /**
+     * Returns the last error occurred (e.g. when updating/inserting failed)
+     *
+     * @return array Hash array with the following fields: type, message
+     */
+    function get_error()
+    {
+        $err = $this->error;
+
+        // check ldap connection for errors
+        if (!$err && $this->ldap->get_error()) {
+            $err = array(self::ERROR_SEARCH, $this->ldap->get_error());
+        }
+
+        return $err;
     }
 
 
@@ -1515,7 +1531,6 @@
         return $ldap_data;
     }
 
-
     /**
      * Returns unified attribute name (resolving aliases)
      */
@@ -1547,17 +1562,6 @@
     }
 
     /**
-     * Prints debug info to the log
-     */
-    private function _debug($str)
-    {
-        if ($this->debug) {
-            rcube::write_log('ldap', $str);
-        }
-    }
-
-
-    /**
      * Activate/deactivate debug mode
      *
      * @param boolean $dbg True if LDAP commands should be logged
@@ -1570,7 +1574,6 @@
             $this->ldap->config_set('debug', $dbg);
         }
     }
-
 
     /**
      * Setter for the current group
@@ -1609,7 +1612,7 @@
 
         if ($search) {
             foreach ($group_cache as $group) {
-                if ($this->compare_search_value('name', $group['name'], $search, $mode)) {
+                if ($this->compare_search_value('name', $group['name'], mb_strtolower($search), $mode)) {
                     $groups[] = $group;
                 }
             }
@@ -1974,7 +1977,7 @@
         $filter = strtr("(|(member=$contact_dn)(uniqueMember=$contact_dn)$add_filter)", array('\\' => '\\\\'));
 
         $ldap_data = $this->ldap->search($base_dn, $filter, 'sub', array('dn', $name_attr));
-        if ($res === false) {
+        if ($ldap_data === false) {
             return array();
         }
 

--
Gitblit v1.9.1