Code

Updated table summary
[gosa.git] / gosa-plugins / goto / addons / goto / class_goto_import_file.inc
index bc3e7563f53ec3dceef800eaae70228bbe89ff4d..5b966dad80762332ed4cfa2bf1634aae0d38bc80 100644 (file)
@@ -5,12 +5,13 @@ class goto_import_file extends plugin
 
   var $events     = array();
   var $csv_fields = array();
+  var $import_successful = FALSE; // Indicates that we have successfully imported everything.
 
   public function __construct($config,&$parent)
   {
     plugin::plugin($config,NULL);
     $this->parent = $parent;
-    $this->daemon_events  = DaemonEvent::get_event_types( SYSTEM_EVENT);
+    $this->daemon_events  = DaemonEvent::get_event_types( SYSTEM_EVENT | HIDDEN_EVENT);
 
     $this->csv_fields = array(
         "0"=>"TIMESTAMP","1" => "MAC",  "2" => "HEADER", "3" => "OGROUP",
@@ -23,9 +24,9 @@ class goto_import_file extends plugin
     
     /* Some file checks 
      */
-    $lines = split("\n",$str);
+    $lines = preg_split("/\n/",$str);
     if(empty($str) || !count($lines)){
-      msg_dialog::display(_("Import"),_("Could not import file, it seems to be empty."),ERROR_DIALOG);
+      msg_dialog::display(_("Import"), msgPool::incorrectUpload(_("file is empty")),ERROR_DIALOG);
       return;
     }
 
@@ -42,7 +43,7 @@ class goto_import_file extends plugin
 
       /* Load values from file 
        */
-      $fields = split(";",$line);
+      $fields = explode(";",$line);
       $event = array();
       foreach($this->csv_fields as $key => $val) {
         $event[$val] = "";
@@ -58,6 +59,8 @@ class goto_import_file extends plugin
 
   public function execute()
   {
+    plugin::execute();
+
     /* Import file 
      */
     if(isset($_POST['import']) && isset($_FILES['file'])) {
@@ -86,7 +89,7 @@ class goto_import_file extends plugin
         }
         if($error){
           msg_dialog::display(_("Import"),
-              _("Entries marked as having errors will be skippen, do you still want to proceed?"),CONFIRM_DIALOG);
+              _("Selected entries will be skipped because of errors. Do you want to proceed?"),CONFIRM_DIALOG);
         }
       }
       if(!$error){
@@ -99,10 +102,18 @@ class goto_import_file extends plugin
             $fail ++;
             continue;
           }
+
+          /* Create event 
+           */
           $class= $this->daemon_events['QUEUED'][$event['HEADER']];
+          $o_data = $this->daemon_events['BY_CLASS'][$class];
           $object = new $class($this->config);
-          $object->set_type(TRIGGERED_EVENT);
           $object->add_targets(array($event['MAC']));
+          if($o_data['s_Schedule_Action'] == $event['HEADER']){
+            $object->set_type(SCHEDULED_EVENT);
+          }else{
+            $object->set_type(TRIGGERED_EVENT);
+          }
 
           /* Update values like fqdn a.s.o 
            */
@@ -119,7 +130,8 @@ class goto_import_file extends plugin
             $success ++;
           }
         }
-        msg_dialog::display(_("Import"),sprintf(_("Import complete: %s events successfully send, %s failed."),$success,$fail),INFO_DIALOG);
+        msg_dialog::display(_("Import"),sprintf(_("Import complete: %s events successfully send, %s failed"),$success,$fail),INFO_DIALOG);
+        $this->import_successful = count($this->events) == 0;
       }
     }
 
@@ -155,7 +167,7 @@ class goto_import_file extends plugin
     foreach($this->events as $key => $event){
       $this->events[$key]['ERROR'] = "";
       if(empty($event['MAC']) || !tests::is_mac($event['MAC'])){
-        $this->events[$key]['ERROR'] .=  msgPool::invalid(_("Mac")).", ";
+        $this->events[$key]['ERROR'] .=  msgPool::invalid(_("MAC")).", ";
       }
       if(empty($event['HEADER']) || !isset($this->daemon_events['QUEUED'][$event['HEADER']])){
         $this->events[$key]['ERROR'] .=  msgPool::invalid(_("Event")).", ";