Code

e742f18867eb20d44176a648ef382dbec0a9132a
[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   public function __construct($config,$data = array())
39   {
40     $this->data   = $data;
41     $this->config = $config;
42     timezone::get_default_timezone();
43     $this->timestamp = time();
44   }
46   public function execute()
47   {
48     $this->time_select_used = FALSE;
50     $str = "<h2>"._("This event has no template.")."</h2>";
51     $str.= "<p class='seperator'></p>";
52     $str.= "<div style='text-align:right;width:100%;padding:3px;'>
53               <input type='submit' name='abort_event_dialog' value='"._("Cancel")."'>
54             </div>";
55     return($str);
56   }
58  
59   public function get_header()
60   {
61     $str = "<h2>"._("Daemon event")."&nbsp;-&nbsp;".$this->s_Event_Name."</h2>";
62     return($str);
63   }
66   public function get_footer()
67   {
68     if($this->target_list_used){
69       return("");
70     }
71     $str = "<p class='seperator'></p>";
72     $str.= "<div style='text-align:right;width:100%;padding:5px;'>
73               <input type='submit' name='save_event_dialog' value='"._("Save")."'>&nbsp;
74               <input type='submit' name='abort_event_dialog' value='"._("Cancel")."'>
75             </div>";
76     return($str);
77   }
78  
80   public function get_time_select()
81   {
82     $this->time_select_used = TRUE;
84     $smarty = get_smarty();
86     $year   = date("Y",$this->timestamp);
87     $month  = date("m",$this->timestamp);
88     $day    = date("d",$this->timestamp);
90     $hour   = date("H",$this->timestamp);
91     $minute = date("i",$this->timestamp);
92     $second = date("s",$this->timestamp);
94     $years = array();
95     for($i = date("Y",time()); $i <= 2037 ;$i ++){
96       $years[$i] = $i;
97     }
98     $months = array();
99     for($i = 1; $i <= 12; $i ++){
100       $e = str_pad($i,2,"0",STR_PAD_LEFT);
101       $months[$e] = $e;
102     }
103     $days = array();
104     for($i = 1; $i <= cal_days_in_month(CAL_GREGORIAN,$month,$year); $i ++){
105       $e = str_pad($i,2,"0",STR_PAD_LEFT);
106       $days[$e] = $e;
107     }
108     $hours = array();
109     for($i = 0; $i < 24; $i ++){
110       $e = str_pad($i,2,"0",STR_PAD_LEFT);
111       $hours[$e] = $e;
112     }
113     $minutes = array();
114     for($i = 0; $i < 60; $i ++){
115       $e = str_pad($i,2,"0",STR_PAD_LEFT);
116       $minutes[$e] = $e;
117     }
118     $seconds = array();
119     for($i = 0; $i < 60; $i ++){
120       $e = str_pad($i,2,"0",STR_PAD_LEFT);
121       $seconds[$e] = $e;
122     }
124     $smarty->assign("years", $years);
125     $smarty->assign("months", $months);
126     $smarty->assign("days", $days);
127     $smarty->assign("hours", $hours);
128     $smarty->assign("minutes", $minutes);
129     $smarty->assign("seconds", $seconds);
130     $smarty->assign("time_year",$year);
131     $smarty->assign("time_month",$month);
132     $smarty->assign("time_day",$day);
133     $smarty->assign("time_hour",$hour);
134     $smarty->assign("time_minute",$minute);
135     $smarty->assign("time_second",$second);
136     return($smarty->fetch(get_template_path('timestamp_select.tpl', TRUE, dirname(__FILE__))));
137   } 
140   public function get_target_list()
141   {
142     $this->target_list_used = TRUE;
143     $smarty = get_smarty();
145     return($smarty->fetch(get_template_path('target_list.tpl', TRUE, dirname(__FILE__))));
146   }
147  
148   public function save_object()
149   {
150     if(isset($_POST['open_target_list'])){
151       $this->target_list_used =TRUE;
152     }
153     if($this->target_list_used){
154       if(isset($_POST['abort_target_dialog'])){
155         $this->target_list_used =FALSE;
156       }
157       if(isset($_POST['save_target_dialog'])){
158         $this->target_list_used =FALSE;
159         echo "Targets auslesen";
160       }
161     }
163     if($this->time_select_used){
164       $time_stamp_values_found = TRUE;
165       foreach(array("time_year","time_month","time_day","time_hour","time_minute","time_second") as $attr){
166         $time_stamp_values_found &= isset($_POST[$attr]);
167       }
168       if($time_stamp_values_found){
169         $this->timestamp = mktime(
170             $_POST['time_hour'],
171             $_POST['time_minute'],        
172             $_POST['time_second'],        
173             $_POST['time_month'],        
174             $_POST['time_day'],        
175             $_POST['time_year']);
176       }
177     }
178   }
179  
180   public function _event_to_timestamp($str)
181   {
182     return(strtotime($str));
183   }
185   public function _timestamp_to_event($stamp)
186   {
187     return(date("YmdHis",$stamp));
188   }
191   public function get_event_info()
192   {
193     $data =array();
194     $data['NAME']         = get_class($this);
195     $data['MenuName']     = $this->s_Menu_Name;
196     $data['EventName']   = $this->s_Event_Name;
197     $data['Action']       = $this->s_action;
198     $data['MenuImage']    = "<img src='".$this->s_Menu_Image."' alt='".$this->s_Menu_Name."' border='0' class='center'>";
199     return($data);
200   }
203   protected function is_target_list_open()
204   {
205     return($this->target_list_used);
206   }
208   
209   static function get_event_types()
210   {
211     global $class_mapping,$config;
212     $list = array();
213     foreach($class_mapping as $name => $path){
214       if(preg_match("/^DaemonEvent_/",$name)){
215         $tmp  = new $name($config);
216         $list[$name] = $tmp->get_event_info();
217       }
218     }
219     return($list);
220   }
223 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
224 ?>