Code

Apply fix for #4271
[gosa.git] / trunk / gosa-plugins / goto / addons / goto / events / class_DaemonEvent.inc
index b163d1b0552aff03fe479d7fa38caf4b1677b736..6268d9c0eb24fd1fffe0f5a875b0ecbeb58da89a 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,33 @@ class DaemonEvent
   }
 
 
+  public function get_time_offset_select()
+  {
+    $this->time_offset_used = TRUE;
+    $smarty = get_smarty();
+    
+    $opts_minutes = array();
+    $opts_operations = array();
+    foreach(range(0,120) as $i) {
+      $opts_minutes[$i] = $i;
+    }
+    foreach(range(1,100) as $i) {
+      $opts_operations[$i] = $i;
+    }
+
+    $smarty->assign('offset_minutes', $opts_minutes);
+    $smarty->assign('offset_operations', $opts_operations);
+    $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 +306,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 ($this->concurrent_operations != 0 && 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 +340,7 @@ class DaemonEvent
             $_POST['time_day'],        
             $_POST['time_year']);
       }
+
     }
 
     if($this->target_list_used){
@@ -432,7 +483,14 @@ class DaemonEvent
       $ret[$attr] = $this->$attr;
     }
 
-    $ret['timestamp'] = $this->_timestamp_to_event($this->timestamp);
+    if(!isset($ret['timestamp'])){
+      $ret['timestamp'] = time();
+    }
+
+    # 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);
   }