From ec8864dddb2b51d05ae4d0c06486ab8c72e476ca Mon Sep 17 00:00:00 2001 From: hickert Date: Tue, 19 Feb 2008 14:44:21 +0000 Subject: [PATCH] Updated gotomasses. -Added new event folder. -Added DaemonEvent class, which is used as mother class for new events. -Added some events (Not all and not complete yet) git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@8959 594d385d-05f5-0310-b6e9-bd551577e9d8 --- .../addons/gotomasses/class_gotomasses.inc | 148 +++++++----- .../gotomasses/events/DaemonEvent_wakeup.tpl | 18 ++ .../gotomasses/events/class_DaemonEvent.inc | 224 ++++++++++++++++++ .../events/class_DaemonEvent_halt.inc | 16 ++ .../events/class_DaemonEvent_reinstall.inc | 16 ++ .../events/class_DaemonEvent_update.inc | 16 ++ .../events/class_DaemonEvent_wakeup.inc | 39 +++ .../addons/gotomasses/events/target_list.tpl | 9 + .../gotomasses/events/timestamp_select.tpl | 43 ++++ 9 files changed, 471 insertions(+), 58 deletions(-) create mode 100644 gosa-plugins/goto/addons/gotomasses/events/DaemonEvent_wakeup.tpl create mode 100644 gosa-plugins/goto/addons/gotomasses/events/class_DaemonEvent.inc create mode 100644 gosa-plugins/goto/addons/gotomasses/events/class_DaemonEvent_halt.inc create mode 100644 gosa-plugins/goto/addons/gotomasses/events/class_DaemonEvent_reinstall.inc create mode 100644 gosa-plugins/goto/addons/gotomasses/events/class_DaemonEvent_update.inc create mode 100644 gosa-plugins/goto/addons/gotomasses/events/class_DaemonEvent_wakeup.inc create mode 100644 gosa-plugins/goto/addons/gotomasses/events/target_list.tpl create mode 100644 gosa-plugins/goto/addons/gotomasses/events/timestamp_select.tpl diff --git a/gosa-plugins/goto/addons/gotomasses/class_gotomasses.inc b/gosa-plugins/goto/addons/gotomasses/class_gotomasses.inc index 8df328051..1fb655a36 100644 --- a/gosa-plugins/goto/addons/gotomasses/class_gotomasses.inc +++ b/gosa-plugins/goto/addons/gotomasses/class_gotomasses.inc @@ -16,6 +16,8 @@ class gotomasses extends plugin var $ids_to_remove = array(); var $divlist = NULL; + var $events = array(); + var $sort_by = "Schedule"; var $sort_dir = "down"; var $entries = array(); @@ -27,13 +29,14 @@ class gotomasses extends plugin /* Include config object */ $this->config= &$config; $this->o_queue = new gosaSupportDaemon(TRUE,10); + $this->events = DaemonEvent::get_event_types(); } function execute() { $smarty = get_smarty(); - + /************ * Handle posts ************/ @@ -63,6 +66,11 @@ class gotomasses extends plugin } } + /* Menu actions */ + if(isset($_POST['menu_action'])){ + $s_action = $_POST['menu_action']; + } + /* Edit posted from list link */ if(isset($_GET['act']) && $_GET['act'] == "edit" && isset($_GET['id']) && isset($this->tasks[$_GET['id']])){ $s_action = "edit"; @@ -101,6 +109,23 @@ class gotomasses extends plugin } } + /************ + * ADD + ************/ + + if(preg_match("/^add_event_/",$s_action)){ + $type = preg_replace("/^add_event_/","",$s_action); + if(isset($this->events[$type])){ + $e_data = $this->events[$type]; + $this->dialog = new $e_data['NAME']($this->config); + } + } + + /************ + * ADD/EDIT Dialog Handling + ************/ + + /************ * REMOVE ************/ @@ -146,63 +171,63 @@ class gotomasses extends plugin } - /************ - * EDIT - ************/ - - /* Edit selected entry */ - if($s_action == "edit"){ - $entry = $this->o_queue->get_entry_by_id($s_entry); - if($entry){ - $this->dialog = new goto_task($this->config,$this,$entry); - $this->current = $s_entry; - } - } - - /* New entry */ - if($s_action== "new_task" && $this->acl_is_createable()){ - $this->dialog = new goto_task($this->config,$this); - $this->current = -1; - } - - /* Close dialog */ - if(isset($_POST['close_goto_task'])){ - $this->dialog = FALSE; - $this->current = -1; - } - - /* Close dialog */ - if((isset($_POST['save_goto_task']) || isset($_POST['apply_goto_task'])) && is_object($this->dialog) ){ - $this->dialog->save_object(); - $msgs = $this->dialog->check(); - if(count($msgs)){ - foreach($msgs as $msg){ - msg_dialog::display(_("Error"), $msg, ERROR_DIALOG); - } - }else{ - - if($this->o_queue->id_exists($this->current)){ - $this->o_queue->update_entries(array($this->current),$this->dialog->save()); - }else{ - $tmp = $this->dialog->save(); - $tmp2= array(); - $targets =$tmp['Target']; - foreach($targets as $target){ - $tmp['Target'] = array($target); - $tmp2[] = $tmp; - } - if(!$this->o_queue->add_multiple($tmp2)){ - msg_dialog::display(_("Error"), $this->o_queue->get_error(), ERROR_DIALOG); - } - } - if(!isset($_POST['apply_goto_task'])){ - $this->dialog = FALSE; - $this->current = -1; - } - $this->save(); - } - } - +# /************ +# * EDIT +# ************/ +# +# /* Edit selected entry */ +# if($s_action == "edit"){ +# $entry = $this->o_queue->get_entry_by_id($s_entry); +# if($entry){ +# $this->dialog = new goto_task($this->config,$this,$entry); +# $this->current = $s_entry; +# } +# } +# +# /* New entry */ +# if($s_action== "new_task" && $this->acl_is_createable()){ +# $this->dialog = new goto_task($this->config,$this); +# $this->current = -1; +# } +# + /* Close dialog */ + if(isset($_POST['abort_event_dialog'])){ + $this->dialog = FALSE; + $this->current = -1; + } +# +# /* Close dialog */ +# if((isset($_POST['save_goto_task']) || isset($_POST['apply_goto_task'])) && is_object($this->dialog) ){ +# $this->dialog->save_object(); +# $msgs = $this->dialog->check(); +# if(count($msgs)){ +# foreach($msgs as $msg){ +# msg_dialog::display(_("Error"), $msg, ERROR_DIALOG); +# } +# }else{ +# +# if($this->o_queue->id_exists($this->current)){ +# $this->o_queue->update_entries(array($this->current),$this->dialog->save()); +# }else{ +# $tmp = $this->dialog->save(); +# $tmp2= array(); +# $targets =$tmp['Target']; +# foreach($targets as $target){ +# $tmp['Target'] = array($target); +# $tmp2[] = $tmp; +# } +# if(!$this->o_queue->add_multiple($tmp2)){ +# msg_dialog::display(_("Error"), $this->o_queue->get_error(), ERROR_DIALOG); +# } +# } +# if(!isset($_POST['apply_goto_task'])){ +# $this->dialog = FALSE; +# $this->current = -1; +# } +# $this->save(); +# } +# } +# /* Display dialogs if currently opened */ if(is_object($this->dialog)){ $this->dialog->save_object(); @@ -219,6 +244,13 @@ class gotomasses extends plugin $divlist->EnableCloseButton(FALSE); $divlist->EnableSaveButton(FALSE); $divlist->SetHeadpageMode(); + $s = ".|"._("Actions")."|\n"; + $s.= "..| "._("Create")."\n"; + foreach($this->events as $name => $event){ + $s.= "...|".$event['MenuImage']." ".$event['MenuName']."|add_event_".$name."\n"; + } + + $divlist->SetDropDownHeaderMenu($s); if($this->sort_dir == "up"){ $sort_img = "/\"; diff --git a/gosa-plugins/goto/addons/gotomasses/events/DaemonEvent_wakeup.tpl b/gosa-plugins/goto/addons/gotomasses/events/DaemonEvent_wakeup.tpl new file mode 100644 index 000000000..27c4f8d0b --- /dev/null +++ b/gosa-plugins/goto/addons/gotomasses/events/DaemonEvent_wakeup.tpl @@ -0,0 +1,18 @@ + + + + + + + + + + + + +
{t}Timestamp{/t}{$timestamp}
{t}Target objects{/t}
+
+ 00:00:00:00:00:00 +
+ +
diff --git a/gosa-plugins/goto/addons/gotomasses/events/class_DaemonEvent.inc b/gosa-plugins/goto/addons/gotomasses/events/class_DaemonEvent.inc new file mode 100644 index 000000000..e742f1886 --- /dev/null +++ b/gosa-plugins/goto/addons/gotomasses/events/class_DaemonEvent.inc @@ -0,0 +1,224 @@ +CreateNew + protected $s_Event_Name = ""; // Will be displayed in the Management list. + protected $s_action = ""; // The deamon command name. + protected $s_Menu_Image = "images/empty.png"; // The deamon command name. + + protected $config; // GOsa configuration file + protected $data; // The event data + protected $timestamp = 0; // Event execution time; + + protected $time_select_used = FALSE; // Indicates that we have used the timestamp select boxes. + protected $target_list_used = FALSE; // Indicates that the target list was used. + + public function __construct($config,$data = array()) + { + $this->data = $data; + $this->config = $config; + timezone::get_default_timezone(); + $this->timestamp = time(); + } + + public function execute() + { + $this->time_select_used = FALSE; + + $str = "

"._("This event has no template.")."

"; + $str.= "

"; + $str.= "
+ +
"; + return($str); + } + + + public function get_header() + { + $str = "

"._("Daemon event")." - ".$this->s_Event_Name."

"; + return($str); + } + + + public function get_footer() + { + if($this->target_list_used){ + return(""); + } + $str = "

"; + $str.= "
+   + +
"; + return($str); + } + + + public function get_time_select() + { + $this->time_select_used = TRUE; + + $smarty = get_smarty(); + + $year = date("Y",$this->timestamp); + $month = date("m",$this->timestamp); + $day = date("d",$this->timestamp); + + $hour = date("H",$this->timestamp); + $minute = date("i",$this->timestamp); + $second = date("s",$this->timestamp); + + $years = array(); + for($i = date("Y",time()); $i <= 2037 ;$i ++){ + $years[$i] = $i; + } + $months = array(); + for($i = 1; $i <= 12; $i ++){ + $e = str_pad($i,2,"0",STR_PAD_LEFT); + $months[$e] = $e; + } + $days = array(); + for($i = 1; $i <= cal_days_in_month(CAL_GREGORIAN,$month,$year); $i ++){ + $e = str_pad($i,2,"0",STR_PAD_LEFT); + $days[$e] = $e; + } + $hours = array(); + for($i = 0; $i < 24; $i ++){ + $e = str_pad($i,2,"0",STR_PAD_LEFT); + $hours[$e] = $e; + } + $minutes = array(); + for($i = 0; $i < 60; $i ++){ + $e = str_pad($i,2,"0",STR_PAD_LEFT); + $minutes[$e] = $e; + } + $seconds = array(); + for($i = 0; $i < 60; $i ++){ + $e = str_pad($i,2,"0",STR_PAD_LEFT); + $seconds[$e] = $e; + } + + $smarty->assign("years", $years); + $smarty->assign("months", $months); + $smarty->assign("days", $days); + $smarty->assign("hours", $hours); + $smarty->assign("minutes", $minutes); + $smarty->assign("seconds", $seconds); + $smarty->assign("time_year",$year); + $smarty->assign("time_month",$month); + $smarty->assign("time_day",$day); + $smarty->assign("time_hour",$hour); + $smarty->assign("time_minute",$minute); + $smarty->assign("time_second",$second); + return($smarty->fetch(get_template_path('timestamp_select.tpl', TRUE, dirname(__FILE__)))); + } + + + public function get_target_list() + { + $this->target_list_used = TRUE; + $smarty = get_smarty(); + + return($smarty->fetch(get_template_path('target_list.tpl', TRUE, dirname(__FILE__)))); + } + + public function save_object() + { + if(isset($_POST['open_target_list'])){ + $this->target_list_used =TRUE; + } + if($this->target_list_used){ + if(isset($_POST['abort_target_dialog'])){ + $this->target_list_used =FALSE; + } + if(isset($_POST['save_target_dialog'])){ + $this->target_list_used =FALSE; + echo "Targets auslesen"; + } + } + + 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){ + $this->timestamp = mktime( + $_POST['time_hour'], + $_POST['time_minute'], + $_POST['time_second'], + $_POST['time_month'], + $_POST['time_day'], + $_POST['time_year']); + } + } + } + + public function _event_to_timestamp($str) + { + return(strtotime($str)); + } + + public function _timestamp_to_event($stamp) + { + return(date("YmdHis",$stamp)); + } + + + public function get_event_info() + { + $data =array(); + $data['NAME'] = get_class($this); + $data['MenuName'] = $this->s_Menu_Name; + $data['EventName'] = $this->s_Event_Name; + $data['Action'] = $this->s_action; + $data['MenuImage'] = "".$this->s_Menu_Name.""; + return($data); + } + + + protected function is_target_list_open() + { + return($this->target_list_used); + } + + + static function get_event_types() + { + global $class_mapping,$config; + $list = array(); + foreach($class_mapping as $name => $path){ + if(preg_match("/^DaemonEvent_/",$name)){ + $tmp = new $name($config); + $list[$name] = $tmp->get_event_info(); + } + } + return($list); + } +} + +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> diff --git a/gosa-plugins/goto/addons/gotomasses/events/class_DaemonEvent_halt.inc b/gosa-plugins/goto/addons/gotomasses/events/class_DaemonEvent_halt.inc new file mode 100644 index 000000000..76b2cc92c --- /dev/null +++ b/gosa-plugins/goto/addons/gotomasses/events/class_DaemonEvent_halt.inc @@ -0,0 +1,16 @@ +s_Menu_Name = _("Shutdown"); + $this->s_Event_Name = _("Shutdown"); + $this->s_action = "trigger_action_halt"; + $this->s_Menu_Image = "images/status_stopped.png"; + } + +} +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> diff --git a/gosa-plugins/goto/addons/gotomasses/events/class_DaemonEvent_reinstall.inc b/gosa-plugins/goto/addons/gotomasses/events/class_DaemonEvent_reinstall.inc new file mode 100644 index 000000000..d10e76d2e --- /dev/null +++ b/gosa-plugins/goto/addons/gotomasses/events/class_DaemonEvent_reinstall.inc @@ -0,0 +1,16 @@ +s_Menu_Name = _("Reinstall"); + $this->s_Event_Name = _("Reinstall"); + $this->s_action = "trigger_action_reinstall"; + $this->s_Menu_Image = "images/fai_small.png"; + } + +} +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> diff --git a/gosa-plugins/goto/addons/gotomasses/events/class_DaemonEvent_update.inc b/gosa-plugins/goto/addons/gotomasses/events/class_DaemonEvent_update.inc new file mode 100644 index 000000000..17e229078 --- /dev/null +++ b/gosa-plugins/goto/addons/gotomasses/events/class_DaemonEvent_update.inc @@ -0,0 +1,16 @@ +s_Menu_Name = _("Software update"); + $this->s_Event_Name = _("software update"); + $this->s_action = "trigger_action_update"; + $this->s_Menu_Image = "images/time.png"; + } + +} +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> diff --git a/gosa-plugins/goto/addons/gotomasses/events/class_DaemonEvent_wakeup.inc b/gosa-plugins/goto/addons/gotomasses/events/class_DaemonEvent_wakeup.inc new file mode 100644 index 000000000..7456b9b2c --- /dev/null +++ b/gosa-plugins/goto/addons/gotomasses/events/class_DaemonEvent_wakeup.inc @@ -0,0 +1,39 @@ +s_Menu_Name = _("Wake up"); + $this->s_Event_Name = _("Wake up"); + $this->s_action = "trigger_action_wake"; + $this->s_Menu_Image = "images/status_running.png"; + } + + public function execute() + { + DaemonEvent::execute(); + + $display = $this->get_header(); + + /* Check if target add dialog is open */ + if($this->is_target_list_open()){ + $display .= $this->get_target_list(); + }else{ + $smarty = get_smarty(); + $smarty->assign("timestamp",$this->get_time_select()); + $display.= $smarty->fetch(get_template_path('DaemonEvent_wakeup.tpl', TRUE, dirname(__FILE__))); + } + + $display.= $this->get_footer(); + return($display); + } + + public function save_object() + { + DaemonEvent::save_object(); + } +} +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> diff --git a/gosa-plugins/goto/addons/gotomasses/events/target_list.tpl b/gosa-plugins/goto/addons/gotomasses/events/target_list.tpl new file mode 100644 index 000000000..9e7fcfaf2 --- /dev/null +++ b/gosa-plugins/goto/addons/gotomasses/events/target_list.tpl @@ -0,0 +1,9 @@ +Target List . + + + +

+
+   + +
diff --git a/gosa-plugins/goto/addons/gotomasses/events/timestamp_select.tpl b/gosa-plugins/goto/addons/gotomasses/events/timestamp_select.tpl new file mode 100644 index 000000000..c9a206bd0 --- /dev/null +++ b/gosa-plugins/goto/addons/gotomasses/events/timestamp_select.tpl @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + +
{t}Jahr{/t}{t}Monat{/t}{t}Tag{/t}{t}Stunde{/t}{t}Minute{/t}{t}Sekunde{/t}
+   + +   + +   + +   + +   + + +
+ -- 2.30.2