Code

Apply fix for #4271
[gosa.git] / trunk / gosa-plugins / goto / addons / goto / events / class_DaemonEvent.inc
index 6268d9c0eb24fd1fffe0f5a875b0ecbeb58da89a..e46fd57e5b002ebf0dc45237afc3d421a93c87e6 100644 (file)
@@ -409,6 +409,54 @@ class DaemonEvent
   }
 
 
+  /*! \brief Save an event dialog and check if multiple events needs to be created */
+  static function save_event_dialog($dialog, $current, $o_queue, $config)
+  {
+    if(is_object($dialog)){
+      $dialog->save_object();
+      if($dialog->multiple_events) {
+        $event_type = get_class($dialog);
+        $targets = $dialog->get_targets();
+        $timestamp = $dialog->timestamp;
+
+        $i = 1;
+        $count = count($targets);
+        while($i <= $count) {
+          $operations = $dialog->concurrent_operations;
+          $event = new $event_type($config);
+          $event->set_timestamp($timestamp);
+          $event->set_type(SCHEDULED_EVENT);
+
+          while($operations > 0) {
+            $i++;
+            $target = array_shift($targets);
+            $event->add_targets(array($target));
+            $operations--;
+          }
+
+          $event->save_object();
+          $event->get_targets();
+          if(!$o_queue->append($event)){
+            msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
+          }
+
+          # Calculate start time for the next run
+          $timestamp = $timestamp + ($dialog->time_offset*60);
+       }
+
+       return(array(FALSE, -1));
+     } else {
+       $dialog->save_object();
+       if(!$o_queue->append($dialog)){
+        msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
+        return(array($dialog, $current));
+       }else{
+        return(array(FALSE, -1));
+       } 
+     }
+   }
+}
+
   /*! \brief  Returns a complete list of all available events.
     @return   Array   Containing $this->get_event_info() for all available events.
    */