Code

Update ldap filter to handle empty object storage
[gosa.git] / gosa-core / include / class_filter.inc
index cce5f48cae679dd4efae6d7e1cfa8bd618e2361b..365f9da631389b3ba0c44c0e4b343109c26db419 100644 (file)
@@ -127,13 +127,6 @@ class filter {
         }
       }
 
-      // Sort elements for element length to allow proper replacing later on
-      function strlenSort($a, $b) {
-        if (strlen($a['tag']) == strlen($b['tag'])) {
-          return 0;
-        }
-       return (strlen($a['tag']) < strlen($b['tag']) ? -1 : 1);
-      } 
       uasort($this->elements, 'strlenSort');
       $this->elements= array_reverse($this->elements);
 
@@ -183,7 +176,7 @@ class filter {
       $checked= " checked";
     }
 
-    $result= "<input class='filter_checkbox' name='$tag' type='checkbox' onClick='document.mainform.submit();' value='true'$checked>";
+    $result= "<input class='filter_checkbox' id='$tag' name='$tag' type='checkbox' onClick='document.mainform.submit();' value='true'$checked>";
     return $result;
   }
 
@@ -313,7 +306,7 @@ class filter {
   function renderScope()
   {
     $checked= $this->scope == "sub"?" checked":"";
-    return "<input type='checkbox' name='SCOPE' value='1' onClick='document.mainform.submit();'$checked>&nbsp;"._("Search in subtrees");
+    return "<input type='checkbox' id='SCOPE' name='SCOPE' value='1' onClick='document.mainform.submit();'$checked>&nbsp;<LABEL for='SCOPE'>"._("Search in subtrees")."</LABEL>";
   }
 
 
@@ -425,13 +418,9 @@ class filter {
 
   function update()
   {
-
     /* React on alphabet links if needed */
     if (isset($_GET['filter'])){
-      $s= mb_substr(validate($_GET['filter']), 0, 1, "UTF8")."*";
-      if ($s == "**"){
-        $s= "*";
-      }
+      $s= mb_substr(validate($_GET['filter']), 0, 1, "UTF8");
       foreach ($this->alphabetElements as $tag) {
         $this->elementValues[$tag]= $s;
       }
@@ -531,6 +520,38 @@ class filter {
   }
 
 
+  function getObjectBase($dn)
+  {
+    global $config;
+    $base= "";
+
+    // Try every object storage
+    $storage= $this->objectStorage;
+    if (!is_array($storage)){
+      $storage= array($storage);
+    }
+    foreach ($storage as $location) {
+      $pattern= "/^[^,]+,".preg_quote($location, '/')."/i";
+      $base= preg_replace($pattern, '', $dn);
+    }
+
+    /* Set to base, if we're not on a correct subtree */
+    if (!isset($config->idepartments[$base])){
+      $base= $config->current['BASE'];
+    }
+
+    return $base;
+  }
+
+
 }
 
+// Sort elements for element length to allow proper replacing later on
+function strlenSort($a, $b) {
+  if (strlen($a['tag']) == strlen($b['tag'])) {
+    return 0;
+  }
+  return (strlen($a['tag']) < strlen($b['tag']) ? -1 : 1);
+} 
+
 ?>