X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=trunk%2Fgosa-plugins%2Fgoto%2Faddons%2Fgoto%2Fevents%2Fclass_DaemonEvent.inc;h=13f80c9dcbff83c2aa5ff3717b0206f652e17fd9;hb=91469489a819afc65b191fe090f5d06aaa4af5b8;hp=c06fa68ccb7208f9ce16913a1d56741db6d0b11d;hpb=b39468bfe1f506501af829cea88aa23eda4b6d3e;p=gosa.git diff --git a/trunk/gosa-plugins/goto/addons/goto/events/class_DaemonEvent.inc b/trunk/gosa-plugins/goto/addons/goto/events/class_DaemonEvent.inc index c06fa68cc..13f80c9dc 100644 --- a/trunk/gosa-plugins/goto/addons/goto/events/class_DaemonEvent.inc +++ b/trunk/gosa-plugins/goto/addons/goto/events/class_DaemonEvent.inc @@ -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 ", "attach" => "style='width:20px; border-right:0px;'") )); @@ -276,12 +320,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 +354,7 @@ class DaemonEvent $_POST['time_day'], $_POST['time_year']); } + } if($this->target_list_used){ @@ -358,6 +423,65 @@ 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(); + $tmp_array[0] = $targets[0]; + foreach ($targets as $current) { + $add_flag = 1; + foreach ($tmp_array as $tmp) { + if ($current["mac"]==$tmp["mac"]) { + $add_flag = 0; break; + } + } + if ($add_flag) $tmp_array[] = $current; + } + $targets = $tmp_array; + $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. */ @@ -432,10 +556,15 @@ class DaemonEvent $ret[$attr] = $this->$attr; } + 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); }