Code

Replaced in_array calls for gosa-plugins
[gosa.git] / gosa-plugins / goto / addons / goto / events / class_DaemonEvent.inc
index 575626165251341721be9b18f95388cc4bf8fef2..5dc1d254d956f6c082a76d3cc77fe95bc5699a87 100644 (file)
@@ -69,6 +69,10 @@ class DaemonEvent
 
   protected $visible_for          = HIDDEN_EVENT;
 
+  protected $periodType           = "days";
+  protected $periodValue          = 7;
+  protected $activate_periodical_job = FALSE;
+
   protected $attributes           = array("timestamp");
  
   function set_type($type)
@@ -105,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];
+      }
+    }
   }
 
 
@@ -201,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);
@@ -237,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__))));
   }
 
@@ -289,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;
+        }
       }
     }
 
@@ -358,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.
    */
@@ -436,6 +490,14 @@ class DaemonEvent
     }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);
   }
 
@@ -505,7 +567,7 @@ class DaemonEvent
   public function set_value($name,$value)
   {
     $name = strtolower($name);
-    if(isset($this->$name) && in_array($name,$this->attributes)){
+    if(isset($this->$name) && in_array_strict($name,$this->attributes)){
       $this->$name = $value;
     }
   }