Code

Updated error msgs in semantic class
[gosa.git] / include / sieve / class_sieveElement_If.inc
index d9a70f3b9084bb41fb45d63bbc11c79f23c1bd95..05f4895141ed53d8f739a4e24f7e1888d3b6964b 100644 (file)
@@ -11,14 +11,16 @@ class sieve_if
   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;
+  
     /* Possible address parts we can select */
     $this->address_parts = array( 
         ":all"       => _("Complete adress")." ("._("Default").")",
@@ -61,7 +63,7 @@ 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);
   } 
 
@@ -106,6 +108,17 @@ class sieve_if
           }
           break;
         }
+
+        /*******************
+         * True / False
+         *******************/
+
+        case "true" :
+        case "false" : 
+        {
+          /* Can't fail anyway */
+          break;
+        }
     
         /*******************
          * Default
@@ -115,8 +128,6 @@ class sieve_if
         {
           if(isset($data['LastError']) && !empty($data['LastError'])){
             $ret[] = $data['LastError'];
-      
-            echo "'".$data['LastError']."' ".$key."<br>" ;
           }
         }
       }
@@ -137,6 +148,11 @@ class sieve_if
       $parsed = $this->_parsed;
     }
 
+
+    if(!is_array($parsed)){
+      return;
+    }
+
     /* Walk through all elements */
     foreach($parsed as $key => $data){
 
@@ -365,7 +381,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){
@@ -412,6 +431,13 @@ class sieve_if
           $values["Address_Part"]    = ":all";
         }
         $data[$type]=$values;
+
+        $this->parent->add_require("relational");
+        if($type == "envelope"){
+          $this->parent->add_require("envelope");
+        }
+    
+
         break;
       }
       case "allof" :
@@ -424,8 +450,8 @@ class sieve_if
       {
         $tmp= array( 
             "Inverse"    => FALSE,
-            "Match_type" => ":contains",
-            "Value_List" => array(1,"M"));
+            "Match_type" => ":over",
+            "Value_List" => array("1M"));
 
         $tmp['LastError'] = "";
         $data[$type] = $tmp;
@@ -569,6 +595,10 @@ class sieve_if
               $parsed[$key]['LastError'] = _("Invalid operator given.");
             }
             $parsed[$key]['Comparator'] = $cp;
+
+            if($cp == "i;ascii-numeric"){
+              $this->parent->add_require("comparator-i;ascii-numeric");
+            }
           }
 
           /* In case of :count and :value match types 
@@ -666,6 +696,11 @@ class sieve_if
           $Units       = array( "M" => _("Megabyte") ,
                                 "K" => _("Kilobyte"));
 
+          /* Toggle Inverse ? */
+          if(isset($_POST['toggle_inverse_'.$element_id])){
+            $parsed[$key]['Inverse'] = !$parsed[$key]['Inverse'];
+          }
+
           /* Reset error */
           $parsed[$key]['LastError'] ="";
 
@@ -765,6 +800,8 @@ 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");
     }
@@ -781,7 +818,12 @@ class sieve_if
 
     $smarty->assign("Name", $name);
     $smarty->assign("Contents", $this->get_as_html());
-    $object = $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%%/",$object,$object_container);
     return($str);
   }
@@ -1056,7 +1098,7 @@ class sieve_if
           $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%%/",_("Klick here to add a new test"),$cont_tmp);
+          $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);
@@ -1098,13 +1140,7 @@ class sieve_if
         } 
         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"));
         }
       }
     }