Code

Added DNS and DHCP enable disable options into setup step 2
[gosa.git] / include / sieve / class_sieveElement_If.inc
index c488aca1400ab0eb26515703911d3b6ec9e501f2..acdcb94d5d6abd1b101abd8efcfb1010236d3fa7 100644 (file)
@@ -5,24 +5,27 @@ class sieve_if
 {
   var $_parsed         = array();
   var $TYPE    = "if";
-  var $id     = -1;
+  var $object_id     = -1;
 
   var $address_parts    = array();
   var $comparators      = array();
   var $match_types      = array();
   var $operators        = array();
-
+  var $parent           = NULL;
   
   /* Initialize class 
    *  $elements   contains all tokens that belongs to this if/else tag
    *  $object_id  cotains an unique tag id, to be able to create uniqe html post names
    */
-  function sieve_if($elements,$object_id)
+  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( 
-        ":all"       => _("Complete adress")." ("._("Default").")",
-        ":domain"    => _("Domian part") ,
+        ":all"       => _("Complete address")." ("._("Default").")",
+        ":domain"    => _("Domain part") ,
         ":localpart" => _("Local part"));
 
     /* comparator type */
@@ -34,6 +37,7 @@ class sieve_if
     /* Match types */
     $this->match_types  = array(  
         ":is"         => _("is"),
+        ":regex"      => _("regex"),
         ":contains"   => _("contains"),
         ":matches"    => _("matches"),
         ":count"      => _("count"),
@@ -48,9 +52,23 @@ class sieve_if
         "gt"  => _("greater than"),
         "ne"  => _("not equal"));
 
-    $this->id       = $object_id;
-    $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);
+      }
+    }
   }
 
 
@@ -59,11 +77,83 @@ class sieve_if
    */
   function get_sieve_script_part()
   {
-    $tmp = "if ".$this->get_sieve_script_part_recursive($parsed = NULL,$id = 1,$obj_id=1);
+    $tmp = $this->TYPE." ".$this->get_sieve_script_part_recursive($parsed = NULL,$id = 1,$obj_id=1);
     return($tmp);
   } 
 
 
+  /* Return error msgs */
+  function check()
+  {
+    $check = $this->check_recursive();
+    return($check);
+  }
+
+  /* Recursivly fetch all error msgs */
+  function check_recursive($parsed = NULL,$id = 1,$obj_id=1)
+  {
+    $ret = array();
+    if($parsed == NULL){
+      $parsed = $this->_parsed;
+    }
+
+    if($parsed == NULL) {
+        return(array(_("Can't save empty tests.")));
+    }
+
+    /* Walk through all elements */
+    foreach($parsed as $key => $data){
+
+      /* Create elements */
+      switch($key)
+      {
+        /*******************
+         * Allof / Anyof
+         *******************/
+        case "anyof" :
+        case "allof" :
+        { 
+          foreach($data as $key2 => $dat){
+            if(($key2 === "Inverse") && ($key2 == "Inverse")){
+              continue;
+            }
+            $msgs = $this->check_recursive($dat, ($id +1),$key2);
+
+            foreach($msgs as $msg){
+              $ret[] = $msg;
+            }
+          }
+          break;
+        }
+
+        /*******************
+         * True / False
+         *******************/
+
+        case "true" :
+        case "false" : 
+        {
+          /* Can't fail anyway */
+          break;
+        }
+    
+        /*******************
+         * Default
+         *******************/
+
+        default: 
+        {
+          if(isset($data['LastError']) && !empty($data['LastError'])){
+            $ret[] = $data['LastError'];
+          }
+        }
+      }
+    }
+    return($ret);
+  }
+
   /* Recursivly create a sieve script out of the given 
    *  tags and tokens provided by $parsed.
    *  $id       specifies the depth of the current element.
@@ -76,6 +166,11 @@ class sieve_if
       $parsed = $this->_parsed;
     }
 
+
+    if(!is_array($parsed)){
+      return;
+    }
+
     /* Walk through all elements */
     foreach($parsed as $key => $data){
 
@@ -101,9 +196,7 @@ class sieve_if
           if($Inverse){
             $script .= "not ";
           }
           $script .= $key;
-   
           break;
         }
 
@@ -136,7 +229,7 @@ class sieve_if
 
           /* Add comparator */
           if(!empty($data['Comparator']) && $data['Comparator'] != ""){
-            $script .= ":comparator ".$data['Comparator']." ";
+            $script .= preg_replace('/\"\"/',"\"", ":comparator \"".$data['Comparator']."\" ");
           }
     
           /* Add match type */
@@ -144,7 +237,7 @@ class sieve_if
 
           /* Add special match type for count and value */
           if(in_array($data['Match_type'], array(":value",":count")) && !empty($data['Match_type_value'])) {
-            $script .= $data['Match_type_value']." ";
+            $script .= sieve_create_strings($data['Match_type_value'])." ";
           }
 
           $script .= sieve_create_strings($data['Key_List']);
@@ -181,7 +274,7 @@ class sieve_if
 
           /* Add comparator */
           if(!empty($data['Comparator']) && $data['Comparator'] != ""){
-            $script .= ":comparator ".$data['Comparator']." ";
+            $script .= preg_replace('/\"\"/',"\"", ":comparator \"".$data['Comparator']."\" ");
           }
     
           /* Add match type */
@@ -189,7 +282,7 @@ class sieve_if
 
           /* Add special match type for count and value */
           if(in_array($data['Match_type'], array(":value",":count")) && !empty($data['Match_type_value'])) {
-            $script .= $data['Match_type_value']." ";
+            $script .= sieve_create_strings($data['Match_type_value'])." ";
           }
 
           $script .= sieve_create_strings($data['Key_List']);
@@ -227,7 +320,7 @@ class sieve_if
 
           /* Add comparator */
           if(!empty($data['Comparator']) && $data['Comparator'] != ""){
-            $script .= ":comparator ".$data['Comparator']." ";
+            $script .= preg_replace('/\"\"/',"\"", ":comparator \"".$data['Comparator']."\" ");
           }
     
           /* Add match type */
@@ -235,7 +328,7 @@ class sieve_if
 
           /* Add special match type for count and value */
           if(in_array($data['Match_type'], array(":value",":count")) && !empty($data['Match_type_value'])) {
-            $script .= $data['Match_type_value']." ";
+            $script .= sieve_create_strings($data['Match_type_value'])." ";
           }
 
           $script .= sieve_create_strings($data['Key_List']);
@@ -306,7 +399,10 @@ class sieve_if
           }          
 
           /* Add allof/anyof tag */
-          $script.= " ".$key." ( ";
+          if($Inverse){
+            $script .= "not ";
+          }
+          $script.= $key." ( ";
 
           /* Add each test parameter */
           foreach($data as $key2 => $dat){
@@ -331,12 +427,90 @@ class sieve_if
     return($script);
   }
 
+  
+  function add_test($data,$type)
+  {
+    switch($type)
+    {
+      case "header" : 
+      case "address" : 
+      case "envelope" : 
+      {
+        /* Add to Tree */
+        $values = array(        "Inverse"         => FALSE,
+                                "Comparator"      => "",
+                                "Expert"          => FALSE,
+                                "LastError"       => "",
+                                "Match_type"      => ":contains",
+                                "Match_type_value"=> "",
+                                "Key_List"        => array(_("emtpy")),
+                                "Value_List"      => array(_("empty"))) ;
+        if($type == "address"){
+          $values["Address_Part"]    = ":all";
+        }
+        $data[$type]=$values;
+
+        $this->parent->add_require("relational");
+        if($type == "envelope"){
+          $this->parent->add_require("envelope");
+        }
+    
+
+        break;
+      }
+      case "allof" :
+      case "anyof" :
+      {
+        $data[$type] = array("Inverse" => FALSE);
+        break;
+      }
+      case "size" :
+      {
+        $tmp= array( 
+            "Inverse"    => FALSE,
+            "Match_type" => ":over",
+            "Value_List" => array("1M"));
+
+        $tmp['LastError'] = "";
+        $data[$type] = $tmp;
+        break;
+      }
+      case "true":
+      {
+        $data['true'] = "true";
+        $data['true']['LastError'] = "";
+        break;
+      }
+      case "false":
+      {
+        $data['false'] = "false";
+        $data['false']['LastError'] = "";
+        break;
+      }
+      case "exists" :
+      {
+        $data['exists'] = array('Inverse' => FALSE,
+                                'Values'  => array(_("Nothing specified right now")),
+                                'LastError' => "");
+        break;
+      }
+      default : echo "Still buggy ";exit;
+    }
+
+    return($data);
+  }
+
 
   /* Ensure that all changes made on the ui 
    *  will be saved. 
    */
   function save_object()
   {
+  
+    if(isset($_POST['add_type']) && isset($_POST["test_type_to_add_".$this->object_id])){
+      $this->_parsed = $this->add_test($this->_parsed,$_POST["test_type_to_add_".$this->object_id]);
+    }
+
     $tmp = $this->save_object_recursive($parsed = NULL,$id = 1,$obj_id=1);
     $this->_parsed = $tmp;
   }
@@ -355,16 +529,30 @@ class sieve_if
       $parsed = $this->_parsed;
     }
 
+    if(!is_array($parsed)) {
+      return;
+    }
+
     /* Walk through all elements */
     foreach($parsed as $key => $data){
 
       /* Id used to have unique html names */
-      $element_id = $this->id."_".$id."_".$obj_id;
+      $element_id = $this->object_id."_".$id."_".$obj_id;
+      
+      foreach($_POST as $name => $value){
+        if(preg_match("/Remove_Test_Object_".$element_id."_(x|y)/",$name)) {
+          return(false); 
+        }
+      }
+
+      
+      if(isset($_POST['add_type']) && isset($_POST["test_type_to_add_".$element_id])){
+        $parsed[$key][] = $this->add_test(array(),$_POST["test_type_to_add_".$element_id]);
+      }
 
       /* Create elements */
       switch($key)
       {
         /*******************
          * Address 
          *******************/
@@ -387,6 +575,8 @@ class sieve_if
           $match_types   = $this->match_types; 
           $operators     = $this->operators;
 
+          $parsed[$key]['LastError'] = "";
+
           /* Toggle Inverse ? */
           if(isset($_POST['toggle_inverse_'.$element_id])){
             $parsed[$key]['Inverse'] = !$parsed[$key]['Inverse'];
@@ -401,26 +591,39 @@ class sieve_if
           if(isset($_POST['address_part_'.$element_id])){
             $ap = $_POST['address_part_'.$element_id];
 
-            if(isset($address_parts[$ap])){
-              $parsed[$key]['Address_Part'] = $ap;
+            if(!isset($address_parts[$ap])){
+              $parsed[$key]['LastError'] = _("Invalid type of address part.") ;
             }
+            $parsed[$key]['Address_Part'] = $ap;
           }
 
           /* Check if match type has changed */
           if(isset($_POST['matchtype_'.$element_id])){
             $mt = $_POST['matchtype_'.$element_id];
 
-            if(isset($match_types[$mt])){
-              $parsed[$key]['Match_type'] = $mt;
+            if(!isset($match_types[$mt])){
+              $parsed[$key]['LastError'] = _("Invalid match type given.");
+            }
+            if($mt == ":regex"){
+              $this->parent->add_require("regex");
             }
+            if($mt == ":count"){
+              $this->parent->add_require("comparator-i;ascii-numeric");
+            }
+            $parsed[$key]['Match_type'] = $mt;
           }
 
           /* Get the comparator tag, if posted */
           if(isset($_POST['comparator_'.$element_id])){
             $cp = $_POST['comparator_'.$element_id];
 
-            if(isset($comparators[$cp])){
-              $parsed[$key]['Comparator'] = $cp;
+            if(!isset($comparators[$cp])){
+              $parsed[$key]['LastError'] = _("Invalid operator given.");
+            }
+            $parsed[$key]['Comparator'] = $cp;
+
+            if($cp == "i;ascii-numeric"){
+              $this->parent->add_require("comparator-i;ascii-numeric");
             }
           }
 
@@ -431,9 +634,10 @@ class sieve_if
             if(isset($_POST['operator_'.$element_id])){
               $op = $_POST['operator_'.$element_id];
 
-              if(isset($operators[$op])){
-                $parsed[$key]['Match_type_value'] = $op;
+              if(!isset($operators[$op])){
+                $parsed[$key]['LastError'] = _("Please specify a valid operator.");
               }
+              $parsed[$key]['Match_type_value'] = $op;
             }
           }
 
@@ -444,7 +648,11 @@ class sieve_if
 
             $tmp2 = split(",",$vls);
             foreach($tmp2 as $val){
-              $tmp[] = "\"".trim(preg_replace("/\"/","",$val))."\"";
+              $tmp[] = trim($val);
+  
+              if(preg_match("/\"/",$val)){
+                $parsed[$key]['LastError'] = _("Invalid character found in address attribute. Quotes are not allowed here.");
+              }
             }
             $parsed[$key]['Key_List'] = $tmp;
           }
@@ -456,7 +664,10 @@ class sieve_if
 
             $tmp2 = split(",",$vls);
             foreach($tmp2 as $val){
-              $tmp[] = "\"".trim(preg_replace("/\"/","",$val))."\"";
+              $tmp[] = trim($val);
+              if(preg_match("/\"/",$val)){
+                $parsed[$key]['LastError'] = _("Invalid character found in value attribute. Quotes are not allowed here.");
+              }
             }
             $parsed[$key]['Value_List'] = $tmp;
           }
@@ -515,49 +726,52 @@ 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])){
+            $parsed[$key]['Inverse'] = !$parsed[$key]['Inverse'];
+          }
 
           /* Reset error */
-          $parsed['size']['LastError'] ="";
+          $parsed[$key]['LastError'] ="";
 
           /* Get match type */
           if(isset($_POST['Match_type_'.$element_id])){
             $mt = $_POST['Match_type_'.$element_id];
-            if(isset($Match_types[$mt])){
-              $parsed['size']['Match_type'] = $mt;
-            }else{
-              $parsed['size']['LastError'] = _("Please select a valid match type in the list box below.");
+            if(!isset($Match_types[$mt])){
+              $parsed[$key]['LastError'] = _("Please select a valid match type in the list box below.");
             }
+            $parsed[$key]['Match_type'] = $mt;
           }
 
           /* Get old values */
-          $value = preg_replace("/[^0-9]*$/","",$parsed['size']['Value_List'][0]);
-          $unit  = preg_replace("/^[0-9]*/","",$parsed['size']['Value_List'][0]);
+          $value = preg_replace("/[^0-9]*$/","",$parsed[$key]['Value_List'][0]);
+          $unit  = preg_replace("/^[0-9]*/","",$parsed[$key]['Value_List'][0]);
 
           /* Get value */
           if(isset($_POST['Value_'.$element_id])){
             $vl = $_POST['Value_'.$element_id];
          
-            if(is_numeric($vl) && preg_match("/^[0-9]*$/",$vl)){
-              $value = $vl;
-            }else{
-              $parsed['size']['LastError'] = _("Only numeric values are allowed here.");
+            if(!(is_numeric($vl) && preg_match("/^[0-9]*$/",$vl))){
+              $parsed[$key]['LastError'] = _("Only numeric values are allowed here.");
             }
+            $value = preg_replace("/[^0-9]/","",$vl);
           }        
 
           /* Get unit */
           if(isset($_POST['Value_Unit_'.$element_id])){
             $ut = $_POST['Value_Unit_'.$element_id];
        
-            if(isset($Units[$ut])){
-              $unit = $ut;
-            }else{
-              $parsed['size']['LastError'] = _("No valid unit selected");
+            if(!isset($Units[$ut])){
+              $parsed[$key]['LastError'] = _("No valid unit selected");
             }
-          }        
-
-          $parsed['size']['Value_List'][0] = $value.$unit;
+            $unit = $ut;
+          }       
+          $parsed[$key]['Value_List'] = array(); 
+          $parsed[$key]['Value_List'][0] = $value.$unit;
           break;
         }
 
@@ -574,7 +788,12 @@ class sieve_if
             if(($key2 === "Inverse") && ($key2 == "Inverse")){
               continue;
             }
-            $parsed[$key][$key2] = $this->save_object_recursive($dat, ($id +1),$key2);
+            $tmp_data = $this->save_object_recursive($dat, ($id +1),$key2."-".$obj_id);
+            if($tmp_data != false){
+              $parsed[$key][$key2] = $tmp_data;
+            }else{
+              unset( $parsed[$key][$key2]);
+            }
           }
           break ;
         } 
@@ -592,12 +811,17 @@ class sieve_if
             if(($key2 === "Inverse") && ($key2 == "Inverse")){
               continue;
             }
-            $parsed[$key][$key2] =  $this->save_object_recursive($dat, ($id + 1),$key2);
+            $tmp_data = $this->save_object_recursive($dat, ($id +1),$key2."-".$obj_id);
+            if($tmp_data != false){
+              $parsed[$key][$key2] = $tmp_data;
+            }else{
+              unset( $parsed[$key][$key2]);
+            }
           }
           break ;
         } 
       }
-    }
+    } 
     return($parsed);
   }  
 
@@ -610,14 +834,28 @@ class sieve_if
     $name .= "<b>"._("Condition")."</b>";
     if($this->TYPE == "if"){
       $name .= "&nbsp;-&nbsp;"._("If");
+    }elseif($this->TYPE == "elsif"){
+      $name .= "&nbsp;-&nbsp;"._("Else If");
     }else{
       $name .= "&nbsp;-&nbsp;"._("Else");
     }
 
     $smarty = get_smarty();
+    $smarty->assign("ID", $this->object_id);
+
+    /* Get navigation element container */
+    $object_container = $smarty->fetch(get_template_path("templates/object_container.tpl",TRUE,dirname(__FILE__)));
+
     $smarty->assign("Name", $name);
     $smarty->assign("Contents", $this->get_as_html());
-    return($smarty->fetch(get_template_path("templates/element_if_else.tpl",TRUE,dirname(__FILE__))));
+
+    if($this->TYPE == "if"){
+      $object = $smarty->fetch(get_template_path("templates/element_if.tpl",TRUE,dirname(__FILE__)));
+    }else{
+      $object = $smarty->fetch(get_template_path("templates/element_elsif.tpl",TRUE,dirname(__FILE__)));
+    }
+    $str = preg_replace("/%%OBJECT_CONTENT%%/",addcslashes($object,"\\"),$object_container);
+    return($str);
   }
 
   
@@ -629,20 +867,28 @@ class sieve_if
       $parsed = $this->_parsed;
     }
 
+    if((!is_array($parsed)) || !count($parsed)) {
+      $smarty = get_smarty();
+      $smarty->assign("ID",$this->object_id);
+      $smarty->assign("DisplayAdd",TRUE);
+      $smarty->assign("DisplayDel",FALSE);
+      $str = $smarty->fetch(get_template_path("templates/object_test_container.tpl",TRUE,dirname(__FILE__)));
+      $ret .= preg_replace("/%%OBJECT_CONTENT%%/",_("Empty"),$str);
+      return($ret);
+    }
+
     /* Walk through all elements */
     foreach($parsed as $key => $data){
 
       /* Create Inverse Tag */
       if(is_array($data) && isset($data['Inverse']) && $data['Inverse']){
-        $str_inverse = "<font color='red'><b>"._("Not")."</b></font>&nbsp;";
         $Inverse = TRUE;
       }else{
-        $str_inverse = "";
         $Inverse = FALSE;
       }
 
       /* Id used to have unique html names */
-      $element_id = $this->id."_".$id."_".$obj_id;
+      $element_id = $this->object_id."_".$id."_".$obj_id;
 
       /* Create elements */
       switch($key)
@@ -689,11 +935,10 @@ class sieve_if
           $smarty->assign("comparators",$comparators);
           $smarty->assign("match_types",$match_types);
           $smarty->assign("operators",$operators);
-
+          $smarty->assign("LastError",$data['LastError']);
           $smarty->assign("match_type", $data['Match_type']);
           $smarty->assign("operator"  , preg_replace("/\"/","",$data['Match_type_value']));
-          $smarty->assign("comparator", $data['Comparator']);
-        
+          $smarty->assign("comparator", preg_replace("/\"/","",$data['Comparator']));
 
           $keys = "";
           foreach($data['Key_List'] as $key){
@@ -711,7 +956,6 @@ class sieve_if
           $smarty->assign("Inverse",$Inverse);
           $smarty->assign("values",$values);
           $smarty->assign("Expert", $data['Expert']);
-
  
           $smarty->assign("ID"  , $element_id); 
           $ret .= $smarty->fetch(get_template_path("templates/element_header.tpl",TRUE,dirname(__FILE__)));
@@ -736,10 +980,10 @@ class sieve_if
           $smarty->assign("Expert", $data['Expert']);
           $smarty->assign("match_types",$match_types);
           $smarty->assign("operators",$operators);
-
+          $smarty->assign("LastError",$data['LastError']);
           $smarty->assign("match_type", $data['Match_type']);
           $smarty->assign("operator"  , preg_replace("/\"/","",$data['Match_type_value']));
-          $smarty->assign("comparator", $data['Comparator']);
+          $smarty->assign("comparator", preg_replace("/\"/","",$data['Comparator']));
 
           $keys = "";
           foreach($data['Key_List'] as $key){
@@ -777,13 +1021,12 @@ class sieve_if
           $smarty->assign("address_parts",$address_parts);
           $smarty->assign("comparators",$comparators);
           $smarty->assign("match_types",$match_types);
+          $smarty->assign("LastError",$data['LastError']);
           $smarty->assign("operators",$operators);
-
           $smarty->assign("match_type", $data['Match_type']);
           $smarty->assign("operator"  , preg_replace("/\"/","",$data['Match_type_value']));
-          $smarty->assign("comparator", $data['Comparator']);
+          $smarty->assign("comparator", preg_replace("/\"/","",$data['Comparator']));
           $smarty->assign("address_part", $data['Address_Part']);
-
           $smarty->assign("Expert", $data['Expert']);
         
           $keys = "";
@@ -797,12 +1040,12 @@ class sieve_if
             $values .= $key.", ";
           }
           $values = preg_replace("/,$/","",trim($values));
-          $smarty->assign("keys",$keys);
-          $smarty->assign("values",$values);
 
+          $smarty->assign("keys",$keys);
+          $smarty->assign("values", $values);
           $smarty->assign("ID"  , $element_id); 
-          $ret .= $smarty->fetch(get_template_path("templates/element_address.tpl",TRUE,dirname(__FILE__)));
+          $str = $smarty->fetch(get_template_path("templates/element_address.tpl",TRUE,dirname(__FILE__)));
+          $ret .= $str;
           break;
         }
       
@@ -816,8 +1059,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]);
@@ -844,7 +1088,6 @@ class sieve_if
         /*******************
          * Exists 
          *******************/
-       
         
         case "exists" : 
         {
@@ -880,13 +1123,22 @@ class sieve_if
             if(($key === "Inverse") && ($key == "Inverse")){
               continue;
             }
-            $Contents .=        $this->get_as_html($dat, ($id +1),$key);
+            $Contents .=        $this->get_as_html($dat, ($id +1),$key."-".$obj_id);
           }
+
           $smarty = get_smarty();
+          $smarty->assign("ID"  , $element_id); 
+          $smarty->assign("DisplayAdd",TRUE);
+          $smarty->assign("DisplayDel",FALSE);
+          $cont_tmp = $smarty->fetch(get_template_path("templates/object_test_container.tpl",TRUE,dirname(__FILE__)));
+          $cont_tmp = preg_replace("/%%OBJECT_CONTENT%%/","<b>"._("Click here to add a new test")."</b>",$cont_tmp);
+
           $smarty->assign("Inverse",$Inverse);
-          $smarty->assign("Contents",$Contents);
+          $smarty->assign("Contents",$cont_tmp.$Contents);
           $smarty->assign("ID"  , $element_id); 
-          $ret .= $smarty->fetch(get_template_path("templates/element_allof.tpl",TRUE,dirname(__FILE__)));
+          $allof_tmp = $smarty->fetch(get_template_path("templates/element_allof.tpl",TRUE,dirname(__FILE__)));
+
+          $ret = $allof_tmp;
           break ;
         } 
 
@@ -902,27 +1154,39 @@ class sieve_if
             if(($key === "Inverse") && ($key == "Inverse")){
               continue;
             }
-            $Contents .=        $this->get_as_html($dat, ($id +1),$key);
+            $Contents .=        $this->get_as_html($dat, ($id +1),$key."-".$obj_id);
           }
           $smarty = get_smarty();
-          $smarty->assign("Inverse",$Inverse);
-          $smarty->assign("Contents",$Contents);
           $smarty->assign("ID"  , $element_id); 
-          $ret .= $smarty->fetch(get_template_path("templates/element_anyof.tpl",TRUE,dirname(__FILE__)));
+          $smarty->assign("DisplayAdd",TRUE);
+          $smarty->assign("DisplayDel",FALSE);
+          $cont_tmp = $smarty->fetch(get_template_path("templates/object_test_container.tpl",TRUE,dirname(__FILE__)));
+          $cont_tmp = preg_replace("/%%OBJECT_CONTENT%%/",_("Click here to add a new test"),$cont_tmp);
+
+          $smarty->assign("Inverse",$Inverse);
+          $smarty->assign("Contents",$cont_tmp.$Contents);
+          $allof_tmp = $smarty->fetch(get_template_path("templates/element_anyof.tpl",TRUE,dirname(__FILE__)));
+
+          $ret = $allof_tmp;
+
           break ;
         } 
         default : 
         {
-          $ret = "<table width='100%'  cellspacing=0 cellpadding=0>
-                    <tr>
-                      <td style='background-color: #FEDCA9 ; border: solid 1px        #EEEEEE'>";
-          $ret.= $key."<br>"; 
-          $ret.= "    </td>
-                    </tr>
-                  </table>";
+          trigger_error(_("Unhandled switch type"));
         }
       }
     }
+    
+    if(!isset($smarty)){
+      $smarty =get_smarty();
+    }
+
+    $smarty->assign("ID",$element_id);
+    $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%%/",addcslashes($ret,"\\"),$str);
     return($ret);
   }
 
@@ -932,8 +1196,16 @@ class sieve_if
    */
   function _parse($data,$id = 0)
   {
-    $av_methods   = array("address","allof","anyof","exists","false","header","not","size","true","envelope");
-    $av_match_type= array(":is",":contains",":matches",":over",":count",":value",":under");
+    $av_match_type = array();
+    foreach($this->match_types as $name => $description){
+      $av_match_type[] = $name;
+    }
+    $av_match_type[] = ":over";
+    $av_match_type[] = ":under";
+
+
+
+    $av_methods= array("address","allof","anyof","exists","false","header","not","size","true","envelope");
     $type = $data[$id]['text'];
     $tmp = array();
 
@@ -968,7 +1240,7 @@ class sieve_if
    
         
         $part     = "(:all|:localpart|:domain)";
-        $operator = "(:contains|:is|:matches|:count|:value)";
+        $operator = "(:regex|:contains|:is|:matches|:count|:value)";
         $value_op = "(lt|le|eq|ge|gt|ne)";
 
         $Address_Part     = "";
@@ -1038,6 +1310,7 @@ class sieve_if
           $values["Address_Part"]    = $Address_Part;
         }
         $tmp[$type] = $values;
+        $tmp[$type]['LastError'] = "";
         break;
       }
 
@@ -1075,6 +1348,7 @@ class sieve_if
         $tmp[$type]= array( "Inverse"    => $Inverse,
                             "Match_type" => $Match_type,
                             "Value_List" => $Value_List);
+        $tmp[$type]['LastError'] = "";
         break;
       }
 
@@ -1086,11 +1360,13 @@ class sieve_if
       case "true": 
       {
         $tmp['true'] = "true";
+        $tmp['true']['LastError'] = "";
         break;
       }
       case "false":
       {
         $tmp['false'] = "false";
+        $tmp['false']['LastError'] = "";
         break;
       }
 
@@ -1115,6 +1391,7 @@ class sieve_if
         
         $tmp['exists'] = array('Inverse' => $Inverse,
                                'Values'  => $tmp2['STRINGS']);
+        $tmp[$type]['LastError'] = "";
         break;
       }