Code

Updated ldifExport for plugin ldapManager
[gosa.git] / gosa-plugins / ldapmanager / addons / ldapmanager / class_csvimport.inc
index bd84fa82e5ba6ad767291fa6f1330a7419e267b6..52d9e6a8f231f9ac1ecd25047a565c06ba97ebd3 100644 (file)
@@ -17,10 +17,14 @@ class csvimport extends plugin
 
   function csvimport (&$config, $dn= NULL)
   {
+    $this->initTime = microtime(TRUE);
     /* Include config object */
     $this->config= &$config;
 
     $this->ui = get_userinfo();
+    stats::log('plugin', $class = get_class($this), $category = array($this->acl_category),  $action = 'open',
+            $amount = 1, $duration = (microtime(TRUE) - $this->initTime));
+
   }
 
   function execute()
@@ -86,7 +90,7 @@ class csvimport extends plugin
 
       while($temp = $ldap->fetch($this->csvinfo['templates'])){
         $tempvar ++;
-        $this->csvinfo['arrtemplates'][$tempvar] = $temp['sn'][0]." - ".$this->config->idepartments[preg_replace("/^[^,]+,".get_people_ou()."/i", "", $temp['dn'])];
+        $this->csvinfo['arrtemplates'][$tempvar] = $temp['sn'][0]." - ".$this->config->idepartments[preg_replace("/^[^,]+,".preg_quote(get_people_ou(), '/')."/i", "", $temp['dn'])];
         $this->csvinfo['arrtempls']   [$tempvar]['name'] = $temp['sn'][0]; 
         $this->csvinfo['arrtempls']   [$tempvar]['dn']   = $temp['dn'];
       }
@@ -102,7 +106,7 @@ class csvimport extends plugin
     $acl = $this->ui->get_permissions($this->config->current['BASE'],"all/all");
     if(!preg_match("/w/",$acl)){
       if(isset($_POST['userfile']) || isset($_POST['sorted']) || isset($_POST['fileup'])){
-       msg_dialog::display(_("Permission error"), _("You've no permission to import CSV files."), ERROR_DIALOG);
+       msg_dialog::display(_("Permission error"), _("You've no permission to import CSV files!"), ERROR_DIALOG);
       }
       return ($smarty->fetch (get_template_path('contentcsv.tpl', TRUE)));
     }
@@ -162,7 +166,7 @@ class csvimport extends plugin
               (!isset($dat['sn']))||(!isset($dat['givenName']))||(!isset($dat['uid']))){
 
             /* Output Error */
-           msg_dialog::display(_("Error"), _("Need at least 'sn', 'givenName' and 'uid' to create users."), ERROR_DIALOG);
+           msg_dialog::display(_("Error"), sprintf(_("Need at least %s, %s and %s to create users!"), bold("sn"), bold("givenName"), bold("uid")), ERROR_DIALOG);
           } else {
 
             /* Register usertab to trigger edit dialog */
@@ -209,12 +213,12 @@ class csvimport extends plugin
 
             /* Insert in the LDAP tree */
             if(count($this->usertab->check())) {
-              show_errors($this->usertab->check());
+              msg_dialog::displayChecks($this->usertab->check());
               $this->csvinfo['sorteddata'][$i]['status']="<b>"._("failed")."</b>";
               $failing = $i+1;
               break;
             } else {
-              $this->csvinfo['sorteddata'][$i]['status']=_("ok");
+              $this->csvinfo['sorteddata'][$i]['status']=_("OK");
               $this->usertab->save();
               change_password($this->usertab->dn,$password); 
             }
@@ -282,7 +286,7 @@ class csvimport extends plugin
 
         /* Error? */
         if ($failing){
-         msg_dialog::display(_("Error"), sprintf(_("Cannot insert entry '%s'!"), $failing), ERROR_DIALOG);
+         msg_dialog::display(_("Error"), sprintf(_("Cannot add entry %s!"), bold($failing)), ERROR_DIALOG);
         }
         $smarty->assign("error",$failing);
 
@@ -362,7 +366,7 @@ class csvimport extends plugin
             $str .= fread($handle,1024);
           }
 
-          $lines = split("\n",$str);
+          $lines = preg_split("/\n/",$str);
           $anz  = 0;
           $rest = 0;
           $data = array();
@@ -376,7 +380,7 @@ class csvimport extends plugin
               }
 
               $line= str_replace ("\t","",$line);
-              $cells  = split(",",$line )  ;
+              $cells  = explode(",",$line )  ;
 
               if(count($cells)> $anz ){
                 $anz = count($cells);
@@ -401,7 +405,7 @@ class csvimport extends plugin
                 $line= str_replace ("\t"  ,"" ,$line);
 
                 /* get all elements  */
-                $cells  = split(",",$line )  ;
+                $cells  = explode(",",$line )  ;
 
                 /* attach all elements to data array */
                 if(is_array($cells))