Code

Some style fixes
[gosa.git] / include / sieve / class_sieveElement_If.inc
index 3b5bb2a1bed832d7731b3a0734949d6ae10fbd2e..99f170df244e134473815505e191704b24f9c672 100644 (file)
@@ -20,6 +20,7 @@ class sieve_if
   function sieve_if($elements,$object_id,$parent)
   {
     $this->parent = $parent;
+    $this->object_id       = $object_id;
   
     /* Possible address parts we can select */
     $this->address_parts = array( 
@@ -51,10 +52,22 @@ class sieve_if
         "gt"  => _("greater than"),
         "ne"  => _("not equal"));
 
-    $this->object_id       = $object_id;
-    if($elements!=NULL){
-      $this->elements = $elements;
-      $this->_parsed  = $this->_parse($elements['ELEMENTS'],1);
+    /* Skip parsing if this element is new */
+    if($elements != NULL){
+
+      /* Remove comments from tests */  
+      $tmp = array();
+      foreach($elements['ELEMENTS'] as $ele){
+        if($ele['class'] != "comment"){
+          $tmp[] = $ele;
+        }
+      }
+      $elements['ELEMENTS'] = $tmp;
+
+      if($elements!=NULL){
+        $this->elements = $elements;
+        $this->_parsed  = $this->_parse($elements['ELEMENTS'],1);
+      }
     }
   }
 
@@ -585,6 +598,9 @@ class sieve_if
             if(!isset($match_types[$mt])){
               $parsed[$key]['LastError'] = _("Invalid match type given.");
             }
+              if($mt == ":regex"){
+                $this->parent->add_require("regex");
+              }
             $parsed[$key]['Match_type'] = $mt;
           }
 
@@ -694,8 +710,9 @@ class sieve_if
           $Match_types = array( ":over" => _("greater than") ,
                                 ":under" => _("lower than"));
 
-          $Units       = array( "M" => _("Megabyte") ,
-                                "K" => _("Kilobyte"));
+          $Units       = array( "M" => _("Megabyte"),
+                                "K" => _("Kilobyte"),
+                                ""  => _("Bytes"));
 
           /* Toggle Inverse ? */
           if(isset($_POST['toggle_inverse_'.$element_id])){
@@ -825,7 +842,7 @@ class sieve_if
     }else{
       $object = $smarty->fetch(get_template_path("templates/element_elsif.tpl",TRUE,dirname(__FILE__)));
     }
-    $str = preg_replace("/%%OBJECT_CONTENT%%/",$object,$object_container);
+    $str = preg_replace("/%%OBJECT_CONTENT%%/",addcslashes($object,"\\"),$object_container);
     return($str);
   }
 
@@ -1017,7 +1034,6 @@ class sieve_if
           $smarty->assign("ID"  , $element_id); 
           $str = $smarty->fetch(get_template_path("templates/element_address.tpl",TRUE,dirname(__FILE__)));
           $ret .= $str;
-          echo htmlentities($str);
           break;
         }
       
@@ -1031,8 +1047,9 @@ class sieve_if
           $Match_types = array( ":over" => _("greater than") , 
                                 ":under" => _("lower than"));
 
-          $Units       = array( "M" => _("Megabyte") , 
-                                "K" => _("Kilobyte")); 
+          $Units       = array( "M" => _("Megabyte"),
+                                "K" => _("Kilobyte"),
+                                ""  => _("Bytes"));
 
           $Match_type   = $data['Match_type'];
           $Value        = preg_replace("/[^0-9]/","",$data['Value_List'][0]);
@@ -1157,7 +1174,7 @@ class sieve_if
     $smarty->assign("DisplayAdd",FALSE);
     $smarty->assign("DisplayDel",TRUE);
     $str = $smarty->fetch(get_template_path("templates/object_test_container.tpl",TRUE,dirname(__FILE__)));
-    $ret = preg_replace("/%%OBJECT_CONTENT%%/",$ret,$str);
+    $ret = preg_replace("/%%OBJECT_CONTENT%%/",addcslashes($ret,"\\"),$str);
     return($ret);
   }