Code

d62f9014e2b5d55a03e3b44f154e2ae1071a64bb
[gosa.git] / gosa-plugins / goto / addons / gotomasses / events / class_DaemonEvent.inc
1 <?php
4 /*
6 trigger_action_wake
7 ping
8 set_activated_for_installation
9 new_key_for_client
10 detect_hardware
11 trigger_action_localboot
12 trigger_action_reboot
13 trigger_action_halt
14 trigger_action_update
15 trigger_action_reinstall
16 trigger_action_memcheck
17 trigger_action_sysinfo
18 trigger_action_instant_update
19 trigger_action_rescan
20 */
23 class DaemonEvent 
24 {
26   protected $s_Menu_Name  = ""; // Diplayed in the ActionsMenu->CreateNew
27   protected $s_Event_Name = ""; // Will be displayed in the Management list.
28   protected $s_action     = ""; // The deamon command name.
29   protected $s_Menu_Image = "images/empty.png"; // The deamon command name.
31   protected $config;          // GOsa configuration file 
32   protected $data;            // The event data 
33   protected $timestamp = 0;   // Event execution time; 
35   protected $time_select_used = FALSE; // Indicates that we have used the timestamp select boxes.
36   protected $target_list_used = FALSE; // Indicates that the target list was used.
38   protected $target_divlist = FALSE; // The divlist used by the target add dialog
40   public function __construct($config,$data = array())
41   {
42     $this->data   = $data;
43     $this->config = $config;
44     timezone::get_default_timezone();
45     $this->timestamp = time();
46   }
48   public function execute()
49   {
50     $this->time_select_used = FALSE;
52     $str = "<h2>"._("This event has no template.")."</h2>";
53     $str.= "<p class='seperator'></p>";
54     $str.= "<div style='text-align:right;width:100%;padding:3px;'>
55               <input type='submit' name='abort_event_dialog' value='"._("Cancel")."'>
56             </div>";
57     return($str);
58   }
60  
61   public function get_header()
62   {
63     $str = "<h2>"._("Daemon event")."&nbsp;-&nbsp;".$this->s_Event_Name."</h2>";
64     return($str);
65   }
68   public function get_footer()
69   {
70     if($this->target_list_used){
71       return("");
72     }
73     $str = "<p class='seperator'></p>";
74     $str.= "<div style='text-align:right;width:100%;padding:5px;'>
75               <input type='submit' name='save_event_dialog' value='"._("Save")."'>&nbsp;
76               <input type='submit' name='abort_event_dialog' value='"._("Cancel")."'>
77             </div>";
78     return($str);
79   }
80  
82   public function get_time_select()
83   {
84     $this->time_select_used = TRUE;
86     $smarty = get_smarty();
88     $year   = date("Y",$this->timestamp);
89     $month  = date("m",$this->timestamp);
90     $day    = date("d",$this->timestamp);
92     $hour   = date("H",$this->timestamp);
93     $minute = date("i",$this->timestamp);
94     $second = date("s",$this->timestamp);
96     $years = array();
97     for($i = date("Y",time()); $i <= 2037 ;$i ++){
98       $years[$i] = $i;
99     }
100     $months = array();
101     for($i = 1; $i <= 12; $i ++){
102       $e = str_pad($i,2,"0",STR_PAD_LEFT);
103       $months[$e] = $e;
104     }
105     $days = array();
106     for($i = 1; $i <= cal_days_in_month(CAL_GREGORIAN,$month,$year); $i ++){
107       $e = str_pad($i,2,"0",STR_PAD_LEFT);
108       $days[$e] = $e;
109     }
110     $hours = array();
111     for($i = 0; $i < 24; $i ++){
112       $e = str_pad($i,2,"0",STR_PAD_LEFT);
113       $hours[$e] = $e;
114     }
115     $minutes = array();
116     for($i = 0; $i < 60; $i ++){
117       $e = str_pad($i,2,"0",STR_PAD_LEFT);
118       $minutes[$e] = $e;
119     }
120     $seconds = array();
121     for($i = 0; $i < 60; $i ++){
122       $e = str_pad($i,2,"0",STR_PAD_LEFT);
123       $seconds[$e] = $e;
124     }
126     $smarty->assign("years", $years);
127     $smarty->assign("months", $months);
128     $smarty->assign("days", $days);
129     $smarty->assign("hours", $hours);
130     $smarty->assign("minutes", $minutes);
131     $smarty->assign("seconds", $seconds);
132     $smarty->assign("time_year",$year);
133     $smarty->assign("time_month",$month);
134     $smarty->assign("time_day",$day);
135     $smarty->assign("time_hour",$hour);
136     $smarty->assign("time_minute",$minute);
137     $smarty->assign("time_second",$second);
138     return($smarty->fetch(get_template_path('timestamp_select.tpl', TRUE, dirname(__FILE__))));
139   } 
142   public function get_target_list()
143   {
144     $this->target_list_used = TRUE;
145     $smarty = get_smarty();
146  
147     if(!$this->target_divlist){ 
148       $this->target_divlist = new MultiSelectWindow($this->config,"EventTargets","gotomasses");
149       $this->target_divlist->SetSummary(_("Targets"));
150       $this->target_divlist->SetInformation(_("This dialog shows all available targets for your event, check the targets you want to add and use the 'Use' button to accept."));
151       $this->target_divlist->EnableCloseButton(FALSE); 
152       $this->target_divlist->EnableSaveButton(FALSE); 
153     }
154     
155     $smarty->assign("divlist",$this->target_divlist->Draw());
157     return($smarty->fetch(get_template_path('target_list.tpl', TRUE, dirname(__FILE__))));
158   }
159  
160   public function save_object()
161   {
162     if(isset($_POST['open_target_list'])){
163       $this->target_list_used =TRUE;
164     }
165     if($this->target_divlist){
166       $this->target_divlist->save_object();
167     }
168     if($this->target_list_used){
169       if(isset($_POST['abort_target_dialog'])){
170         $this->target_list_used =FALSE;
171         $this->target_divlist = FALSE;
172       }
173       if(isset($_POST['save_target_dialog'])){
174         $this->target_list_used =FALSE;
175         echo "Targets auslesen";
176         $this->target_divlist = FALSE;
177       }
178     }
180     if($this->time_select_used){
181       $time_stamp_values_found = TRUE;
182       foreach(array("time_year","time_month","time_day","time_hour","time_minute","time_second") as $attr){
183         $time_stamp_values_found &= isset($_POST[$attr]);
184       }
185       if($time_stamp_values_found){
186         $this->timestamp = mktime(
187             $_POST['time_hour'],
188             $_POST['time_minute'],        
189             $_POST['time_second'],        
190             $_POST['time_month'],        
191             $_POST['time_day'],        
192             $_POST['time_year']);
193       }
194     }
195   }
196  
197   public function _event_to_timestamp($str)
198   {
199     return(strtotime($str));
200   }
202   public function _timestamp_to_event($stamp)
203   {
204     return(date("YmdHis",$stamp));
205   }
208   public function get_event_info()
209   {
210     $data =array();
211     $data['NAME']         = get_class($this);
212     $data['MenuName']     = $this->s_Menu_Name;
213     $data['EventName']   = $this->s_Event_Name;
214     $data['Action']       = $this->s_action;
215     $data['MenuImage']    = "<img src='".$this->s_Menu_Image."' alt='".$this->s_Menu_Name."' border='0' class='center'>";
216     return($data);
217   }
220   protected function is_target_list_open()
221   {
222     return($this->target_list_used);
223   }
225   
226   static function get_event_types()
227   {
228     global $class_mapping,$config;
229     $list = array();
230     foreach($class_mapping as $name => $path){
231       if(preg_match("/^DaemonEvent_/",$name)){
232         $tmp  = new $name($config);
233         $list[$name] = $tmp->get_event_info();
234       }
235     }
236     return($list);
237   }
240 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
241 ?>