Code

Fixed new script status
[gosa.git] / include / sieve / class_sieveElement_Require.inc
index dffbf375b0762c0b221154072083f3da47ff8345..c7138deb569e76f8eb22d79fecf2cda365c61d67 100644 (file)
@@ -7,14 +7,33 @@ class sieve_require
   
   function sieve_require($data,$object_id)
   {
-    $this->object_id = $object_id;
-    foreach($data['ELEMENTS'] as $node ){
-      if(in_array($node['class'],array("quoted-string","text"))){
-        $this->data[] = preg_replace("/\"/","",$node['text']);
+    if($data != NULL){
+
+      $this->object_id = $object_id;
+      foreach($data['ELEMENTS'] as $node ){
+        if(in_array($node['class'],array("quoted-string","text"))){
+          $this->data[] = preg_replace("/\"/","",$node['text']);
+        }
       }
     }
   }
 
+  /* Add a new require statement and ensure 
+   *  that it is not specified twice 
+   */
+  function Add_Require($str)
+  {
+    $current = array();
+
+    foreach($this->data as $dat){
+      $current[] = preg_replace("/\"/","",$dat);
+    }
+    if(!in_array($str,$current)){
+      $this->data[] = $str;
+    }
+    $this->data = array_unique($this->data);;
+  }
+
   function save_object()
   {
     /* Get the values should check for, they are seperated by , */
@@ -29,7 +48,7 @@ class sieve_require
     
         if(empty($val)) continue;        
   
-        $tmp[] = "\"".$val."\"";
+        $tmp[] = $val;
       }
       $this->data = $tmp;
     }
@@ -55,7 +74,7 @@ class sieve_require
   {
     $Require = "";
     foreach($this->data as $key){
-      $Require .= $key.", ";
+      $Require .= "\"".$key."\"".", ";
     }
     $Require = preg_replace("/,$/","",trim($Require));
 
@@ -65,7 +84,7 @@ class sieve_require
     $smarty->assign("LastError",$tmp);
     $smarty->assign("LastErrorCnt",count($tmp));
     $smarty->assign("ID", $this->object_id);
-    $object_container = $smarty->fetch(get_template_path("templates/object_container_clear.tpl",TRUE,dirname(__FILE__)));
+    $object_container = $smarty->fetch(get_template_path("templates/object_container.tpl",TRUE,dirname(__FILE__)));
     $object= $smarty->fetch(get_template_path("templates/element_require.tpl",TRUE,dirname(__FILE__)));
     $str = preg_replace("/%%OBJECT_CONTENT%%/",$object,$object_container);
     return($str);