Code

Updated gotomasses.
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 19 Feb 2008 14:44:21 +0000 (14:44 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 19 Feb 2008 14:44:21 +0000 (14:44 +0000)
-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

gosa-plugins/goto/addons/gotomasses/class_gotomasses.inc
gosa-plugins/goto/addons/gotomasses/events/DaemonEvent_wakeup.tpl [new file with mode: 0644]
gosa-plugins/goto/addons/gotomasses/events/class_DaemonEvent.inc [new file with mode: 0644]
gosa-plugins/goto/addons/gotomasses/events/class_DaemonEvent_halt.inc [new file with mode: 0644]
gosa-plugins/goto/addons/gotomasses/events/class_DaemonEvent_reinstall.inc [new file with mode: 0644]
gosa-plugins/goto/addons/gotomasses/events/class_DaemonEvent_update.inc [new file with mode: 0644]
gosa-plugins/goto/addons/gotomasses/events/class_DaemonEvent_wakeup.inc [new file with mode: 0644]
gosa-plugins/goto/addons/gotomasses/events/target_list.tpl [new file with mode: 0644]
gosa-plugins/goto/addons/gotomasses/events/timestamp_select.tpl [new file with mode: 0644]

index 8df328051dba25f105145dc343d0a709bc677e24..1fb655a36c5a391a5341a66831505c55d7493541 100644 (file)
@@ -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.= "..|<img src='images/list_new.png' alt='' border='0' class='center'>&nbsp;"._("Create")."\n";
+    foreach($this->events as $name =>  $event){
+      $s.= "...|".$event['MenuImage']."&nbsp;".$event['MenuName']."|add_event_".$name."\n";
+    }
+
+    $divlist->SetDropDownHeaderMenu($s);
 
     if($this->sort_dir == "up"){
       $sort_img = "<img src='images/sort_up.png' alt='/\' border=0>";
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 (file)
index 0000000..27c4f8d
--- /dev/null
@@ -0,0 +1,18 @@
+
+<table>
+       <tr>
+               <td style='vertical-align:top'>{t}Timestamp{/t}</td>
+               <td>{$timestamp}</td>
+       </tr>
+       <tr>
+               <td>{t}Target objects{/t}</td>
+       </tr>
+       <tr>
+               <td colspan="2">
+                       <div style='width:400px;height:180px;background-color:#BBBBBB;'>
+                               00:00:00:00:00:00
+                       </div>
+                       <input type='submit' name='open_target_list' value='{t}Add target{/t}'>
+               </td>
+       </tr>
+</table>
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 (file)
index 0000000..e742f18
--- /dev/null
@@ -0,0 +1,224 @@
+<?php
+
+
+/*
+
+trigger_action_wake
+ping
+set_activated_for_installation
+new_key_for_client
+detect_hardware
+trigger_action_localboot
+trigger_action_reboot
+trigger_action_halt
+trigger_action_update
+trigger_action_reinstall
+trigger_action_memcheck
+trigger_action_sysinfo
+trigger_action_instant_update
+trigger_action_rescan
+*/
+
+
+class DaemonEvent 
+{
+
+  protected $s_Menu_Name  = ""; // Diplayed in the ActionsMenu->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 = "<h2>"._("This event has no template.")."</h2>";
+    $str.= "<p class='seperator'></p>";
+    $str.= "<div style='text-align:right;width:100%;padding:3px;'>
+              <input type='submit' name='abort_event_dialog' value='"._("Cancel")."'>
+            </div>";
+    return($str);
+  }
+
+  public function get_header()
+  {
+    $str = "<h2>"._("Daemon event")."&nbsp;-&nbsp;".$this->s_Event_Name."</h2>";
+    return($str);
+  }
+
+
+  public function get_footer()
+  {
+    if($this->target_list_used){
+      return("");
+    }
+    $str = "<p class='seperator'></p>";
+    $str.= "<div style='text-align:right;width:100%;padding:5px;'>
+              <input type='submit' name='save_event_dialog' value='"._("Save")."'>&nbsp;
+              <input type='submit' name='abort_event_dialog' value='"._("Cancel")."'>
+            </div>";
+    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']    = "<img src='".$this->s_Menu_Image."' alt='".$this->s_Menu_Name."' border='0' class='center'>";
+    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 (file)
index 0000000..76b2cc9
--- /dev/null
@@ -0,0 +1,16 @@
+<?php
+
+class DaemonEvent_halt extends DaemonEvent
+{
+  public function __construct($config,$data = array())
+  {
+    DaemonEvent::__construct($config,$data);
+    $this->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 (file)
index 0000000..d10e76d
--- /dev/null
@@ -0,0 +1,16 @@
+<?php
+
+class DaemonEvent_reinstall extends DaemonEvent
+{
+  public function __construct($config,$data = array())
+  {
+    DaemonEvent::__construct($config,$data);
+    $this->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 (file)
index 0000000..17e2290
--- /dev/null
@@ -0,0 +1,16 @@
+<?php
+
+class DaemonEvent_update extends DaemonEvent
+{
+  public function __construct($config,$data = array())
+  {
+    DaemonEvent::__construct($config,$data);
+    $this->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 (file)
index 0000000..7456b9b
--- /dev/null
@@ -0,0 +1,39 @@
+<?php
+
+class DaemonEvent_wakeup extends DaemonEvent
+{
+  public function __construct($config,$data = array())
+  {
+    DaemonEvent::__construct($config,$data);
+    $this->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 (file)
index 0000000..9e7fcfa
--- /dev/null
@@ -0,0 +1,9 @@
+Target List .
+
+<input type='submit'>
+
+<p class='seperator'></p>
+<div style='text-align:right;width:100%;padding:5px;'>
+       <input type='submit' name='save_target_dialog' value='{t}Use{/t}'>&nbsp;
+       <input type='submit' name='abort_target_dialog' value='{t}Close{/t}'>
+</div>
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 (file)
index 0000000..c9a206b
--- /dev/null
@@ -0,0 +1,43 @@
+<table cellspacing="0" cellpadding="0">
+       <tr>
+               <td>{t}Jahr{/t}</td>
+               <td>{t}Monat{/t}</td>
+               <td>{t}Tag{/t}</td>
+               <td>{t}Stunde{/t}</td>
+               <td>{t}Minute{/t}</td>
+               <td>{t}Sekunde{/t}</td>
+       </tr>
+       <tr>
+               <td>
+                       <select name="time_year" onChange="document.mainform.submit();">
+                               {html_options values=$years options=$years selected=$time_year}
+                       </select>&nbsp;
+               </td>
+               <td>
+                       <select name="time_month" onChange="document.mainform.submit();">
+                               {html_options values=$months options=$months selected=$time_month}
+                       </select>&nbsp;
+               </td>
+               <td>
+                       <select name="time_day">
+                               {html_options values=$days options=$days selected=$time_day}
+                       </select>&nbsp;
+               </td>
+               <td>
+                       <select name="time_hour">
+                               {html_options values=$hours options=$hours selected=$time_hour}
+                       </select>&nbsp;
+               </td>
+               <td>
+                       <select name="time_minute">
+                               {html_options values=$minutes options=$minutes selected=$time_minute}
+                       </select>&nbsp;
+               </td>
+               <td>
+                       <select name="time_second">
+                               {html_options values=$seconds options=$seconds selected=$time_second}
+                       </select>
+               </td>
+       </tr>
+</table>
+