Code

Replaced in_array calls for gosa-plugins
[gosa.git] / gosa-plugins / goto / addons / goto / events / class_DaemonEvent.inc
index bf231e7714c5b7bcbfd38dea881671b91c659c7c..5dc1d254d956f6c082a76d3cc77fe95bc5699a87 100644 (file)
@@ -68,6 +68,12 @@ class DaemonEvent
   protected $server_list          = array();  // Used as cache in the target list.
 
   protected $visible_for          = HIDDEN_EVENT;
+
+  protected $periodType           = "days";
+  protected $periodValue          = 7;
+  protected $activate_periodical_job = FALSE;
+
+  protected $attributes           = array("timestamp");
  
   function set_type($type)
   {
@@ -103,6 +109,15 @@ class DaemonEvent
         $this->timestamp = $this->_event_to_timestamp($data['TIMESTAMP']);
       }
     }
+
+    if(isset($data['PERIODIC']) && !preg_match("/none/i",$data['PERIODIC'])){
+      $tmp = explode("_",$data['PERIODIC']);
+      if(count($tmp) == 2){
+        $this->activate_periodical_job = TRUE;
+        $this->periodValue = $tmp[0];
+        $this->periodType = $tmp[1];
+      }
+    }
   }
 
 
@@ -114,7 +129,7 @@ class DaemonEvent
     $this->time_select_used = FALSE;
     $this->target_list_used = FALSE;
 
-    $str = "<h2>"._("This job has no template.")."</h2>";
+    $str = "<h2>"._("This job 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='".msgPool::cancelButton()."'>
@@ -199,6 +214,19 @@ class DaemonEvent
       $seconds[$e] = $e;
     }
 
+    $periodTypes = array(
+        "minutes" => _("Minutes"),
+        "hours"   => _("Hours"),
+        "days"    => _("Days"),
+        "weeks"   => _("Weeks"),
+        "months"  => _("Months"));
+    
+
+    $smarty->assign("periodTypes", $periodTypes);
+    $smarty->assign("periodType", $this->periodType);
+    $smarty->assign("periodValue", $this->periodValue);
+    $smarty->assign("activate_periodical_job", $this-> activate_periodical_job);
+
     $smarty->assign("years", $years);
     $smarty->assign("months", $months);
     $smarty->assign("days", $days);
@@ -225,7 +253,7 @@ class DaemonEvent
     foreach($this->a_targets as $key => $target){
       $divlist->AddEntry(array(
             array("string"  => $target),
-            array("string"  => "<input type='image' src='images/edittrash.png' title='"._("Remove")."' name='del_target_".$key."'>",
+            array("string"  => "<input type='image' src='images/lists/trash.png' title='"._("Remove")."' name='del_target_".$key."'>",
               "attach"  => "style='width:20px; border-right:0px;'")
             ));
     }
@@ -235,19 +263,18 @@ class DaemonEvent
 
 
   /*! \brief  Returns HTML content, displaying a dialog which allows to add new targets.
-    @return String HTML content. (EventTargetAddList)
+    @return String HTML content. (EventAddSystemDialog)
    */
   public function get_target_add_list()
   {
     $this->target_add_list_used = TRUE;
 
     if($this->target_divlist == NULL){ 
-      $this->target_divlist = new EventTargetAddList($this->config,$this);
+      $this->target_divlist = new EventAddSystemDialog($this->config,$this);
     }
-    $this->target_divlist->execute();
 
     $smarty = get_smarty();
-    $smarty->assign("divlist",$this->target_divlist->Draw());
+    $smarty->assign("divlist",$this->target_divlist->execute());
     return($smarty->fetch(get_template_path('target_list.tpl', TRUE, dirname(__FILE__))));
   }
 
@@ -269,22 +296,7 @@ class DaemonEvent
       }
       if(isset($_POST['save_target_dialog'])){
         $this->target_add_list_used =FALSE;
-        foreach($this->list_get_selected_items() as $id){
-          if(in_array("gosaGroupOfNames",$this->target_divlist->_target_list[$id]['objectClass'])){
-            foreach($this->target_divlist->_target_list[$id]['member'] as $mem_dn){
-              if(isset($this->target_divlist->workstation_list[$mem_dn])){
-                $this->a_targets[] = $this->target_divlist->workstation_list[$mem_dn]['macAddress'][0];  
-              }
-              if(isset($this->target_divlist->server_list[$mem_dn])){
-                $this->a_targets[] = $this->target_divlist->server_list[$mem_dn]['macAddress'][0];  
-              }
-            } 
-          }else{
-            if(isset($this->target_divlist->_target_list[$id]['macAddress'][0])){
-              $this->a_targets[] = $this->target_divlist->_target_list[$id]['macAddress'][0];
-            }
-          }
-        }
+        $this->add_targets($this->target_divlist->get_selected_targets());
         $this->target_divlist = NULL;
       }
     }
@@ -302,6 +314,15 @@ class DaemonEvent
             $_POST['time_month'],        
             $_POST['time_day'],        
             $_POST['time_year']);
+
+        if(isset($_POST['periodValue'])) $this->periodValue = get_post('periodValue');
+        if(isset($_POST['periodType'])) $this->periodType = get_post('periodType');
+
+        if(isset($_POST['activate_periodical_job'])){
+          $this->activate_periodical_job = TRUE;
+        }else{
+          $this->activate_periodical_job = FALSE;
+        }
       }
     }
 
@@ -371,6 +392,26 @@ class DaemonEvent
   }
 
 
+  /*! \brief  Returns a complete list of all available events.
+    @return   Array   Containing $this->get_event_info() for all available events.
+   */
+  static function get_event_types_by_category($categories)
+  {
+    $types= array();
+
+    foreach ($categories as $category) {
+      if (preg_match('/^users$/', $category)) {
+        $types= array_merge($types, DaemonEvent::get_event_types(USER_EVENT));
+      }
+      if (preg_match('/^systems$/', $category)) {
+        $types= array_merge($types, DaemonEvent::get_event_types(SYSTEM_EVENT));
+      }
+    }
+
+    return $types;
+  }
+
+
   /*! \brief  Returns a complete list of all available events.
     @return   Array   Containing $this->get_event_info() for all available events.
    */
@@ -424,7 +465,7 @@ class DaemonEvent
     return($this->s_Schedule_Action);
   }
 
-  //
+
   /*! \brief  Returns the event tag to schedule a new action 
     @param    Returns the event e.g. 'trigger_action_wake'
    */
@@ -433,13 +474,31 @@ class DaemonEvent
     return($this->s_Trigger_Action);
   }
 
+
   /*! brief  Returns an array containig all attributes \
     That should be written.
     @return Array e.g. 'status' => 'bla blub'  
    */ 
   public function save()
   {
-    return(array("timestamp" => $this->_timestamp_to_event($this->timestamp)));
+    $ret = array();
+    foreach($this->attributes as $attr){
+      $ret[$attr] = $this->$attr;
+    }
+    if($this->mode == SCHEDULED_EVENT){
+      $ret['timestamp'] = $this->_timestamp_to_event($this->timestamp);
+    }elseif(isset($ret['timestamp'])){
+      unset($ret['timestamp']);
+    }
+
+    if(isset($ret['periodic'])){
+      unset($ret['periodic']);
+    }
+    if($this->activate_periodical_job){
+      $ret['periodic']= $this->periodValue."_".$this->periodType;
+    }
+
+    return($ret);
   }
 
 
@@ -478,22 +537,6 @@ class DaemonEvent
   }
 
 
-  /*! \brief  Returns a set of elements selected in a MultiSelectWindow
-    @return Array[integer]=integer
-   */
-  protected  function list_get_selected_items()
-  {
-    $ids = array();
-    foreach($_POST as $name => $value){
-      if(preg_match("/^item_selected_[0-9]*$/",$name)){
-        $id   = preg_replace("/^item_selected_/","",$name);
-        $ids[$id] = $id;
-      }
-    }
-    return($ids);
-  }
-
-
   /*! \brief Add a target MAC address 
       @param Array A List of all target that should be added.
    */
@@ -512,6 +555,22 @@ class DaemonEvent
       $this->a_targets[] = $target;
     }
   }
+
+  public function check()
+  {
+    return(array());
+  }
+
+
+  /*! \brief Update a class variable from outside 
+   */
+  public function set_value($name,$value)
+  {
+    $name = strtolower($name);
+    if(isset($this->$name) && in_array_strict($name,$this->attributes)){
+      $this->$name = $value;
+    }
+  }
 }
 
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: