Code

Fixed undefined index
[gosa.git] / include / class_ldap.inc
index 7b82a8b327bf262cc2a9804681c47bfc3b71f7b4..39482bf6a0a6193e244742f4b4eb64292cdd96e9 100644 (file)
@@ -803,19 +803,27 @@ class LDAP{
 
     if ($recursive){
       $this->cd($dn);
-      $this->search("$filter", array('dn'));
+      $this->ls($filter,$dn, array('dn','objectClass'));
+      $deps = array();
       while ($attrs= $this->fetch()){
         $display.= $this->gen_one_entry($attrs['dn'], $filter, $attributes);
         $display.= "\n";
+
+        if(in_array("organizationalUnit",$attrs['objectClass'])){
+          $deps[] = $attrs['dn'];
+        }
+      }
+      foreach($deps as $dn){
+        $display .= $this->gen_ldif($dn, $filter,$attributes,$recursive);
       }
     } else {
       $display.= $this->gen_one_entry($dn);
     }
-
     return ($display);
   }
 
-function gen_xls ($dn, $filter= "(objectClass=*)", $attributes= array('*'), $recursive= TRUE,$r_array=0)
+
+  function gen_xls ($dn, $filter= "(objectClass=*)", $attributes= array('*'), $recursive= TRUE,$r_array=0)
   {
     $display= "";
 
@@ -936,12 +944,12 @@ function gen_xls ($dn, $filter= "(objectClass=*)", $attributes= array('*'), $rec
             $attr  = $encoded[0];
             $value = base64_decode($encoded[1]);
             /* Add linenumber */
-            $data .= $current_line."#".$attr.":".$value."\n";
+            $data .= $current_line."#".base64_encode($attr.":".$value)."\n";
           }
           else
           {
             /* Add Linenumber */ 
-            $data .= $current_line."#".$entry."\n";
+            $data .= $current_line."#".base64_encode($entry)."\n";
           }
         }
       }
@@ -957,7 +965,7 @@ function gen_xls ($dn, $filter= "(objectClass=*)", $attributes= array('*'), $rec
     foreach ( $all as $single) {
       $lineone = split("\n",$single);  
       $ndn = split("#", $lineone[0]);
-      $line = $ndn[1];
+      $line = base64_decode($ndn[1]);
 
       $dnn = split (":",$line);
       $current_line = $ndn[0];
@@ -1009,6 +1017,8 @@ function gen_xls ($dn, $filter= "(objectClass=*)", $attributes= array('*'), $rec
   {
     if($this->reconnect) $this->connect();
 
+    
+
     $ret = false;
     $rows= split("\n",$str_attr);
     $data= false;
@@ -1018,13 +1028,13 @@ function gen_xls ($dn, $filter= "(objectClass=*)", $attributes= array('*'), $rec
       /* Check if we use Linenumbers (when import_complete_ldif is called we use
          Linenumbers) Linenumbers are use like this 123#attribute : value */
       if(!empty($row)) {
-        if((strpos($row,"#")!=FALSE)&&(strpos($row,"#")<strpos($row,":"))) {
+        if(strpos($row,"#")!=FALSE) {
 
           /* We are using line numbers 
              Because there is a # before a : */
           $tmp1= split("#",$row);
           $current_line= $tmp1[0];
-          $row= $tmp1[1];
+          $row= base64_decode($tmp1[1]);
         }
 
         /* Split the line into  attribute  and value */
@@ -1052,7 +1062,6 @@ function gen_xls ($dn, $filter= "(objectClass=*)", $attributes= array('*'), $rec
         }
       }
     } 
-    
     /* If dn is an index of data, we should try to insert the data */
     if(isset($data['dn'])) {
       /* Creating Entry */
@@ -1060,7 +1069,7 @@ function gen_xls ($dn, $filter= "(objectClass=*)", $attributes= array('*'), $rec
 
       /* Delete existing entry */
       if($delete){
-        $this->rmdir($data['dn']);
+        $this->rmdir_recursive($data['dn']);
       }
       
       /* Create missing trees */
@@ -1074,7 +1083,7 @@ function gen_xls ($dn, $filter= "(objectClass=*)", $attributes= array('*'), $rec
         $ret = $this->modify($data);
       }
     }
-
+    show_ldap_error($this->get_error(),_("Ldap import failed"));
     return($ret);
   }