Code

Implement reinstall with offsets (#4271)
[gosa.git] / trunk / gosa-plugins / goto / addons / goto / events / class_DaemonEvent.inc
index adcea31410e9fd9ffd0ed381fe3d03c502e74547..f47a552d45d985a34386f2635b2a3d7bf4b1f1be 100644 (file)
@@ -51,7 +51,9 @@ class DaemonEvent
   protected $s_Schedule_Action = "";       // The deamon command name when newly created. (e.g. job_trigger_action_halt)
   protected $s_Trigger_Action= "";       // The deamon command name when edited. (e.g. trigger_action_halt)
   protected $s_Queued_Action= "";       // The deamon command name when edited. (e.g. trigger_action_halt)
-  protected $timestamp    = 0;        // Event execution time; 
+  public $timestamp    = 0;        // Event execution time; 
+  public $time_offset = 0;    // An offset when an event should start (normally not used)
+  public $concurrent_operations = 1; // Number of concurrent operations when a timestamp offset is used
   protected $id           = -1;       // The Table ID
   protected $status       = "unknown";// The current event status
   protected $is_new       = TRUE;     // Is TRUE if this is a new event
@@ -70,6 +72,12 @@ class DaemonEvent
   protected $visible_for          = HIDDEN_EVENT;
 
   protected $attributes           = array("timestamp");
+
+  protected $time_offset_used = FALSE;
+
+  /* Indicate that multiple events have to be created from this event */
+  public $multiple_events = FALSE;
+
  
   function set_type($type)
   {
@@ -154,11 +162,21 @@ class DaemonEvent
   }
 
 
+  public function get_time_offset_select()
+  {
+    $this->time_offset_used = TRUE;
+    $smarty = get_smarty();
+    $smarty->assign('time_offset', $this->time_offset);
+    $smarty->assign('concurrent_operations', $this->concurrent_operations);
+    return($smarty->fetch(get_template_path('time_offset.tpl', TRUE, dirname(__FILE__))));
+  }
+
   /*! \brief  Returns HTML representation of a timestamp using <select> boxes. 
     @return Returns HTML content.
    */
   public function get_time_select()
   {
+    timezone::get_default_timezone();
     $this->time_select_used = TRUE;
 
     $smarty = get_smarty();
@@ -276,12 +294,32 @@ class DaemonEvent
       }
     }
 
+    if (isset($_POST['concurrent_operations'])) {
+        $this->concurrent_operations = $_POST['concurrent_operations'];
+    }
+    if (isset($_POST['time_offset'])) {
+        $this->time_offset = $_POST['time_offset'];
+    }
+    
+    if ($this->time_offset_used){
+        /* Check that multiple events makes sense at all (e.g. there are more targets
+         * then allowed concurrent operations */
+        if (count($this->a_targets) > $this->concurrent_operations) {
+            if ($this->time_offset > 0) {
+                $this->multiple_events = TRUE;
+            }
+        }
+    }
+
     if($this->time_select_used){
       $time_stamp_values_found = TRUE;
       foreach(array("time_year","time_month","time_day","time_hour","time_minute","time_second") as $attr){
         $time_stamp_values_found &= isset($_POST[$attr]);
       }
       if($time_stamp_values_found){
+        /* Make sure the following conversion happens with the right timezone */
+        timezone::get_default_timezone();
+
         $this->timestamp = mktime(
             $_POST['time_hour'],
             $_POST['time_minute'],        
@@ -290,6 +328,7 @@ class DaemonEvent
             $_POST['time_day'],        
             $_POST['time_year']);
       }
+
     }
 
     if($this->target_list_used){
@@ -439,7 +478,8 @@ class DaemonEvent
     # Check if timestamp is in gosa-si-time-format 
     if(!tests::is_gosa_si_time($ret['timestamp'])){ 
       $ret['timestamp'] = $this->_timestamp_to_event($this->timestamp); 
-    } 
+    }
+
     return($ret);
   }