Code

Added some templates && functionality
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 14 Mar 2007 11:13:39 +0000 (11:13 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 14 Mar 2007 11:13:39 +0000 (11:13 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@5781 594d385d-05f5-0310-b6e9-bd551577e9d8

html/images/sieve_add_test.png [new file with mode: 0644]
html/images/sieve_test_add.png [new file with mode: 0644]
include/sieve/class_My_Parser.inc
include/sieve/class_My_Tree.inc
include/sieve/class_sieveElement_If.inc
include/sieve/templates/element_allof.tpl
include/sieve/templates/object_container_remove_only.tpl [new file with mode: 0644]
include/sieve/templates/object_test_container.tpl [new file with mode: 0644]
include/sieve/templates/select_test_type.tpl [new file with mode: 0644]

diff --git a/html/images/sieve_add_test.png b/html/images/sieve_add_test.png
new file mode 100644 (file)
index 0000000..ec67203
Binary files /dev/null and b/html/images/sieve_add_test.png differ
diff --git a/html/images/sieve_test_add.png b/html/images/sieve_test_add.png
new file mode 100644 (file)
index 0000000..d632c85
Binary files /dev/null and b/html/images/sieve_test_add.png differ
index ea45beb998a90393108f1cfd02c5c62351fe060d..434a80ff6d7761b010c5adec543d7f64adf99b31 100644 (file)
@@ -10,14 +10,6 @@ class My_Parser extends Parser
 
        function execute()
        {
-
-
-               /* Add Element requested */
-               if(isset($_POST['Add_Element'])){
-                       $this->tree_->Add_Element();
-                       echo "Move this into Management";
-               }
-
                /* Create dump of current sieve script */
                if(isset($_POST['Save_Copy'])){
                        echo "Move this into Management";
@@ -52,8 +44,6 @@ class My_Parser extends Parser
        }
        
 
-       
-
        /* Initiate parser, but use some other 
      *  classes, that are rewritten.
      */
@@ -102,5 +92,11 @@ class My_Parser extends Parser
                }
                return strval($token);
        }
+
+
+       function dumpParseTree()
+       {
+               return $this->tree_->execute();
+       }
 }
 ?>
index 10c30eeb427447819c1f25e3c170be8dcf1b856f..c6355d40784d809987b22fe405aa0cc686f4163e 100644 (file)
@@ -21,6 +21,36 @@ class My_Tree extends Tree
   var $add_type         = "top";
   var $add_element_type = "";
 
+  function execute()
+  {
+    foreach($_POST as $name => $value){
+      if(preg_match("/Add_Test_Object_/",$name)) {
+        $name = preg_replace("/Add_Test_Object_/","",$name);
+        $name = preg_replace("/_(x|y)$/","",$name);
+    
+        $test_types_to_add = array(
+          "address" =>_("Address"),
+          "header"  =>_("Header"),
+          "envelope"=>_("Envelope"),
+          "size"    =>_("Size"),
+          "exists"  =>_("Exists"),
+          "allof"   =>_("All of"),
+          "anyof"   =>_("Any of"),
+          "true"    =>_("True"),
+          "false"   =>_("False"));
+        $smarty = get_smarty();
+        $smarty->assign("ID",$name); 
+        $smarty->assign("test_types_to_add",$test_types_to_add); 
+        $ret = $smarty->fetch(get_template_path("templates/select_test_type.tpl",TRUE,dirname(__FILE__)));
+        return($ret);
+      }
+    }
+
+
+    return($this->dump());
+  }
+
   /* Create a html interface for the current sieve filter 
    */
   function dump()
@@ -59,7 +89,11 @@ class My_Tree extends Tree
       /* Create new element and add it at the selected position */
       if(isset($_POST['select_new_element_type'])){
 
-        $ele = new $this->add_element_type(NULL, preg_replace("/[^0-9]/","",microtime()));
+        $ele[] = new $this->add_element_type(NULL, preg_replace("/[^0-9]/","",microtime()));
+        if($this->add_element_type == "sieve_if"){
+          $ele[] = new sieve_block_start(NULL,preg_replace("/[^0-9]/","",microtime()));
+          $ele[] = new sieve_block_end(NULL,preg_replace("/[^0-9]/","",microtime()));
+        }
         $start = $end = array();
         $found = false;  
 
@@ -95,7 +129,9 @@ class My_Tree extends Tree
           foreach($start as $obj){
             $new[] = $obj;
           }      
-          $new[] = $ele;
+          foreach($ele as $el){
+            $new[] = $el;
+          }
           foreach($end as $obj){
             $new[] = $obj;
           }
index 819ebe00296cb397372ebf8787c230022bbfff23..e9979a62aced383568b6ce1c7053298a21a59451 100644 (file)
@@ -49,8 +49,10 @@ class sieve_if
         "ne"  => _("not equal"));
 
     $this->object_id       = $object_id;
-    $this->elements = $elements;
-    $this->_parsed  = $this->_parse($elements['ELEMENTS'],1);
+    if($elements!=NULL){
+      $this->elements = $elements;
+      $this->_parsed  = $this->_parse($elements['ELEMENTS'],1);
+    }
   }
 
 
@@ -388,12 +390,44 @@ 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,
+                                "Match_type"      => ":contains",
+                                "Match_type_value"=> "",
+                                "Key_List"        => array("emtpy"),
+                                "Value_List"      => array("empty")) ;
+        if($type == "address"){
+          $values["Address_Part"]    = ":all";
+        }
+        $data['address']=$values;
+      }
+    }
+
+    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;
   }
@@ -412,16 +446,22 @@ 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->object_id."_".$id."_".$obj_id;
-
+      
+      foreach($_POST as $name => $value){
+        if(preg_match("/Remove_Test_Object_".$element_id."_(x|y)/",$name)) {
+          return(false); 
+        }
+      }
       /* Create elements */
       switch($key)
       {
         /*******************
          * Address 
          *******************/
@@ -633,7 +673,12 @@ class sieve_if
             if(($key2 === "Inverse") && ($key2 == "Inverse")){
               continue;
             }
-            $parsed[$key][$key2] = $this->save_object_recursive($dat, ($id +1),$key2."-".$obj_id);
+            $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 ;
         } 
@@ -651,12 +696,17 @@ class sieve_if
             if(($key2 === "Inverse") && ($key2 == "Inverse")){
               continue;
             }
-            $parsed[$key][$key2] =  $this->save_object_recursive($dat, ($id + 1),$key2."-".$obj_id);
+            $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);
   }  
 
@@ -699,6 +749,16 @@ 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){
 
@@ -985,6 +1045,14 @@ class sieve_if
         }
       }
     }
+    
+    if(!isset($smarty)){
+      $smarty =get_smarty();
+    }
+    $smarty->assign("DisplayAdd",TRUE);
+    $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);
     return($ret);
   }
 
index 4a79f35da6a327496366be868d9ac785d77b06d9..d39d5985fea35b71501421e365efc48cf064ebda 100644 (file)
@@ -6,12 +6,13 @@
                                        background-color: #BDBDBD;
                                        border: solid 1px #EEEEEE 
                                        '>
+                       <b>{t}All of{/t}</b>
             {if $Inverse}
                 <input type='submit' name='toggle_inverse_{$ID}' value='{t}Not{/t}'>
             {else}
                 <input type='submit' name='toggle_inverse_{$ID}' value='{t}-{/t}'>
             {/if}
-            <img alt='' class='center' src='images/select_ogroup.png'>
+
                </td>
         <td style='background-color:#BDBDBD ; border: solid 1px #EEEEEE'>
                        {$Contents}
diff --git a/include/sieve/templates/object_container_remove_only.tpl b/include/sieve/templates/object_container_remove_only.tpl
new file mode 100644 (file)
index 0000000..a6c3e46
--- /dev/null
@@ -0,0 +1,11 @@
+<table cellspacing=0 style='width:100%;background-color:#EEEEEE;border: solid 1px #BBB;346575;'>
+       <tr>
+               <td style='width:20px; background-color: #235464; text-align:center;'>  
+                       <input type='image' src='images/sieve_del_object.png' name='Remove_Test_Object_{$ID}' 
+                               title='{t}Remove this object{/t}' alt='R'>
+               </td>
+               <td>
+                       %%OBJECT_CONTENT%%
+               </td>
+       </tr>
+</table>
diff --git a/include/sieve/templates/object_test_container.tpl b/include/sieve/templates/object_test_container.tpl
new file mode 100644 (file)
index 0000000..83e1118
--- /dev/null
@@ -0,0 +1,17 @@
+<table cellspacing=0 style='width:100%;background-color:#EEEEEE;border: solid 1px #BBB;346575;'>
+       <tr>
+               <td style='width:20px; background-color: #235464; text-align:center;'>  
+                       {if $DisplayAdd}
+                               <input type='image' src='images/sieve_add_test.png' name='Add_Test_Object_{$ID}' 
+                                       title='{t}Add this object{/t}' alt='R' class='center'>
+                       {/if}
+                       {if $DisplayDel}
+                               <input type='image' src='images/sieve_del_object.png' name='Remove_Test_Object_{$ID}' 
+                                       title='{t}Remove this object{/t}' alt='R' class='center'>
+                       {/if}
+               </td>
+               <td>
+                       %%OBJECT_CONTENT%%
+               </td>
+       </tr>
+</table>
diff --git a/include/sieve/templates/select_test_type.tpl b/include/sieve/templates/select_test_type.tpl
new file mode 100644 (file)
index 0000000..39ab2f7
--- /dev/null
@@ -0,0 +1,7 @@
+<h2>{t}Select the test type you want to add{/t}</h2>
+
+<b>{t}Available test types{/t}</b>&nbsp;:&nbsp;
+<select name='test_type_to_add_{$ID}'>
+       {html_options options=$test_types_to_add}
+</select>
+<input type='submit' name='add_type'>