From: hickert Date: Wed, 14 Mar 2007 11:13:39 +0000 (+0000) Subject: Added some templates && functionality X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=ae9d10bc127e2900c7d5a543a24b95315094e45b;p=gosa.git Added some templates && functionality git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@5781 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/html/images/sieve_add_test.png b/html/images/sieve_add_test.png new file mode 100644 index 000000000..ec67203ff 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 index 000000000..d632c8506 Binary files /dev/null and b/html/images/sieve_test_add.png differ diff --git a/include/sieve/class_My_Parser.inc b/include/sieve/class_My_Parser.inc index ea45beb99..434a80ff6 100644 --- a/include/sieve/class_My_Parser.inc +++ b/include/sieve/class_My_Parser.inc @@ -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(); + } } ?> diff --git a/include/sieve/class_My_Tree.inc b/include/sieve/class_My_Tree.inc index 10c30eeb4..c6355d407 100644 --- a/include/sieve/class_My_Tree.inc +++ b/include/sieve/class_My_Tree.inc @@ -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; } diff --git a/include/sieve/class_sieveElement_If.inc b/include/sieve/class_sieveElement_If.inc index 819ebe002..e9979a62a 100644 --- a/include/sieve/class_sieveElement_If.inc +++ b/include/sieve/class_sieveElement_If.inc @@ -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); } diff --git a/include/sieve/templates/element_allof.tpl b/include/sieve/templates/element_allof.tpl index 4a79f35da..d39d5985f 100644 --- a/include/sieve/templates/element_allof.tpl +++ b/include/sieve/templates/element_allof.tpl @@ -6,12 +6,13 @@ background-color: #BDBDBD; border: solid 1px #EEEEEE '> + {t}All of{/t} {if $Inverse} {else} {/if} - + {$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 index 000000000..a6c3e4631 --- /dev/null +++ b/include/sieve/templates/object_container_remove_only.tpl @@ -0,0 +1,11 @@ + + + + + +
+ + + %%OBJECT_CONTENT%% +
diff --git a/include/sieve/templates/object_test_container.tpl b/include/sieve/templates/object_test_container.tpl new file mode 100644 index 000000000..83e11183c --- /dev/null +++ b/include/sieve/templates/object_test_container.tpl @@ -0,0 +1,17 @@ + + + + + +
+ {if $DisplayAdd} + + {/if} + {if $DisplayDel} + + {/if} + + %%OBJECT_CONTENT%% +
diff --git a/include/sieve/templates/select_test_type.tpl b/include/sieve/templates/select_test_type.tpl new file mode 100644 index 000000000..39ab2f7ca --- /dev/null +++ b/include/sieve/templates/select_test_type.tpl @@ -0,0 +1,7 @@ +

{t}Select the test type you want to add{/t}

+ +{t}Available test types{/t} :  + +