Code

Classname is now saved in Session
[gosa.git] / include / class_ldap.inc
index e6ed318e2f624375433b702a3c15cf42e20e6361..8f7fee1d2ba871bcb8c829944b230331d6ad9199 100644 (file)
@@ -325,6 +325,46 @@ class LDAP{
     }
   }
 
+  /**
+  *  Function rmdir_recursive
+  *
+  *  Description: Based in recursive_remove, adding two thing: full subtree remove, and delete own node.
+  *  Parameters:  The dn to delete
+  *  GiveBack:    True on sucessfull , 0 in error, and "" when we don't get a ldap conection
+  *
+  */
+
+  function rmdir_recursive($deletedn)
+  {
+    if($this->hascon){
+      if ($this->reconnect) $this->connect();
+      $delarray= array();
+        
+      /* Get sorted list of dn's to delete */
+      $this->ls ("(objectClass=*)",$deletedn);
+      while ($this->fetch()){
+        $deldn= $this->getDN();
+        $delarray[$deldn]= strlen($deldn);
+      }
+      arsort ($delarray);
+      reset ($delarray);
+
+      /* Really Delete ALL dn's in subtree */
+      foreach ($delarray as $key => $value){
+        $this->rmdir_recursive($key);
+      }
+      
+      /* Finally Delete own Node */
+      $r = @ldap_delete($this->cid, $deletedn);
+      $this->error = @ldap_error($this->cid);
+      return($r ? $r : 0);
+    }else{
+      $this->error = "Could not connect to LDAP server";
+      return("");
+    }
+  }
+
+
   function modify($attrs)
   {
     if($this->hascon){
@@ -353,7 +393,6 @@ class LDAP{
 
   function create_missing_trees($target)
   {
-    
     /* Ignore create_missing trees if the base equals target */
     if ($target == $this->basedn){
      return;
@@ -424,7 +463,7 @@ class LDAP{
     }
   }
 
-  function get_attribute($dn, $name)
+  function get_attribute($dn, $name,$r_array=0)
   {
     $data= "";
     if ($this->reconnect) $this->connect();
@@ -437,11 +476,18 @@ class LDAP{
         if ($info= @ldap_get_values_len($this->cid, $ei, "$name")){
           $data= $info[0];
         }
+
       }
     }
-
+    if($r_array==0)
     return ($data);
+    else
+    return ($info);
+  
+  
   }
+
 
   function get_additional_error()
   {
@@ -499,6 +545,28 @@ class LDAP{
     return ($display);
   }
 
+function gen_xls ($dn, $filter= "(objectClass=*)", $attributes= array('*'), $recursive= TRUE,$r_array=0)
+  {
+    $display= "";
+
+      $this->cd($dn);
+      $this->search("$filter");
+
+      $i=0;
+      while ($attrs= $this->fetch()){
+        $j=0;
+
+        foreach ($attributes as $at){
+          $display[$i][$j]= $this->get_attribute($attrs['dn'], $at,$r_array);
+          $j++;
+        }
+
+        $i++;
+      }
+
+    return ($display);
+  }
+
 
   function gen_one_entry($dn, $filter= "(objectClass=*)" , $name= array("*"))
   {
@@ -511,7 +579,7 @@ class LDAP{
     /* Searching Ldap Tree */
     $sr= @ldap_read($this->cid, $dn, $filter, $name);
 
-    /* Get the first entry */          
+    /* Get the first entry */   
     $entry= @ldap_first_entry($this->cid, $sr);
 
     /* Get all attributes related to that Objekt */
@@ -523,7 +591,7 @@ class LDAP{
 
     /* Reset index */
     $i = 1 ; 
-       $identifier = array();
+  $identifier = array();
     $attribute= @ldap_first_attribute($this->cid,$entry,$identifier);
     while ($attribute) {
       $i++;