Code

Updated list handling
[gosa.git] / gosa-core / include / class_filterLDAP.inc
index 53084d28a2463c119143d842c47c24838d3ecf1e..7697462049580281c7976e3314516cdeafd5e74f 100644 (file)
@@ -14,8 +14,8 @@ class filterLDAP {
 
   static function get_list($base, $filter, $attributes, $category, $objectStorage, $flags= GL_SUBSEARCH)
   {
-    global $ui;
-    global $config;
+    $ui= session::global_get('ui');
+    $config= session::global_get('config');
 
     // Move to arrays for category and objectStorage
     if (!is_array($category)) {
@@ -24,29 +24,34 @@ class filterLDAP {
     if (!is_array($objectStorage)) {
       $objectStorage= array($objectStorage);
     }
+    $method= (empty($objectStorage) && !($flags & GL_SUBSEARCH))?"ls":"search";
 
     // Initialize search bases
     $bases= array();
     
     // Get list of sub bases to search on
-    foreach ($objectStorage as $oc) {
-      $oc= preg_replace('/,$/', '', $oc);
-      $tmp= split(',', $oc);
-      if (count($tmp) == 1) {
-        preg_match('/([^=]+)=(.*)$/', $oc, $m);
-        if ($flags & GL_SUBSEARCH) {
-          $bases[$base][]= $m[1].":dn:=".$m[2];
-        } else {
-          $bases["$oc,$base"][]= $m[1].":dn:=".$m[2];
-        }
-      } else {
-        // No, there's no \, in pre defined RDN values
-        preg_match('/^([^,]+),(.*)$/', $oc, $matches);
-        preg_match('/([^=]+)=(.*)$/', $matches[1], $m);
-        if ($flags & GL_SUBSEARCH) {
-          $bases[$base][]= $m[1].":dn:=".$m[2];
+    if (count($objectStorage) == 0) {
+      $bases[$base]= "";
+    } else {
+      foreach ($objectStorage as $oc) {
+        $oc= preg_replace('/,$/', '', $oc);
+        $tmp= split(',', $oc);
+        if (count($tmp) == 1) {
+          preg_match('/([^=]+)=(.*)$/', $oc, $m);
+          if ($flags & GL_SUBSEARCH) {
+            $bases[$base][]= $m[1].":dn:=".$m[2];
+          } else {
+            $bases["$oc,$base"][]= $m[1].":dn:=".$m[2];
+          }
         } else {
-          $bases[$matches[2].",$base"][]= $m[1].":dn:=".$m[2];
+          // No, there's no \, in pre defined RDN values
+          preg_match('/^([^,]+),(.*)$/', $oc, $matches);
+          preg_match('/([^=]+)=(.*)$/', $matches[1], $m);
+          if ($flags & GL_SUBSEARCH) {
+            $bases[$base][]= $m[1].":dn:=".$m[2];
+          } else {
+            $bases[$matches[2].",$base"][]= $m[1].":dn:=".$m[2];
+          }
         }
       }
     }
@@ -65,13 +70,21 @@ class filterLDAP {
       }
 
       // Switch to new base and search
+      if (is_array($dnFilters)){
+        $dnFilter= "(|";
+        foreach ($dnFilters as $df) {
+          $dnFilter.= "($df)";
+        }
+        $dnFilter.= ")";
+      } else {
+        $dnFilter= "";
+      }
       $ldap->cd($base);
-      $dnFilter= "(|";
-      foreach ($dnFilters as $df) {
-        $dnFilter.= "($df)";
+      if ($method == "ls") {
+        $ldap->ls("(&$filter$dnFilter)", $base, $attributes);
+      } else {
+        $ldap->search("(&$filter$dnFilter)", $attributes);
       }
-      $dnFilter.= ")";
-      $ldap->search ("(&$filter$dnFilter)", $attributes);
 
       // Check for size limit exceeded messages for GUI feedback
       if (preg_match("/size limit/i", $ldap->get_error())){