From ae9d10bc127e2900c7d5a543a24b95315094e45b Mon Sep 17 00:00:00 2001 From: hickert Date: Wed, 14 Mar 2007 11:13:39 +0000 Subject: [PATCH] Added some templates && functionality git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@5781 594d385d-05f5-0310-b6e9-bd551577e9d8 --- html/images/sieve_add_test.png | Bin 0 -> 895 bytes html/images/sieve_test_add.png | Bin 0 -> 609 bytes include/sieve/class_My_Parser.inc | 16 ++-- include/sieve/class_My_Tree.inc | 40 ++++++++- include/sieve/class_sieveElement_If.inc | 82 ++++++++++++++++-- include/sieve/templates/element_allof.tpl | 3 +- .../object_container_remove_only.tpl | 11 +++ .../sieve/templates/object_test_container.tpl | 17 ++++ include/sieve/templates/select_test_type.tpl | 7 ++ 9 files changed, 156 insertions(+), 20 deletions(-) create mode 100644 html/images/sieve_add_test.png create mode 100644 html/images/sieve_test_add.png create mode 100644 include/sieve/templates/object_container_remove_only.tpl create mode 100644 include/sieve/templates/object_test_container.tpl create mode 100644 include/sieve/templates/select_test_type.tpl diff --git a/html/images/sieve_add_test.png b/html/images/sieve_add_test.png new file mode 100644 index 0000000000000000000000000000000000000000..ec67203ff55906923fe585c86b124778c2406f9d GIT binary patch literal 895 zcmV-_1AzRAP)g;9V0Xh6Kntg0}M$- zK~y-)Wzt)Slw};p@$d7z&%5)^!EtAX*;!|{5K(bs6=jK~bjidbkqnBW8|fxcx`>Wm zbS+U7MA2P01qC8u7C}TI6haoe)~dOp?bZuKHYTT=Ktn*_u+f-7u+j3#F1^kmc*vRiYVNbOrRDctsZv#U1Ic7`wARa6 zSFe>haa57dkK=kFj+V3=ACTW$L-T{MDCyB z^w~vDJU(RVfvxCrja1|tWF1(zL}x+TZ53aH9x9?Zl1qlC>b=msP#LxQu8$IuR&+Zb ze!Il0B4nHQH5Nr^0!{ecnvSc9al5)wQH~pN5BqFnGjmjbE`sg4;2R?W%xWfRu>tlC)I&FvI%59eKEaP-d zbWKn#Jj{KEpJ6N&XE5kGYVq=Ko%NVsbKEelB-x=z32!9NTBDCxo#*((N6hXUqM8=X zw!+?ZjNC*XN_dbX*n#Lb`c%z#z zBO`=?W@N;`Fch&^RBiy4{#t3BJ@aM4P!eI7AOxZBf;P|uXbn2lNGWKwJ1A4R{{oD_ VQ#Zs>3H$&6002ovPDHLkV1kZDm+$}p literal 0 HcmV?d00001 diff --git a/html/images/sieve_test_add.png b/html/images/sieve_test_add.png new file mode 100644 index 0000000000000000000000000000000000000000..d632c8506b649e04f78081276918e207b7940fc4 GIT binary patch literal 609 zcmV-n0-pVeP)uIg@kF+-&>xkFB}ZOxvOoYQfinuVU&>aHD{C z)AQ&A@fA{^{3-6-YP?-*m+Qe9Rb|wbQVosKNU27~C{yxGQ8j!}G&i(R%pADxw_>qu zuCFbY)HMv7P&HvV1H&TqMg~O&xd8$wNE47i?GD$AjRoWB26!(V{p_*aSwSL10TBq1 zgd_N1#Av7(5|y2IImO~EJY0sV@|<)(v-N0&>q^y7RYX#cQQ7^NQDDYR72ZEXe|!KS zfAR)h*g!Sqkro++>3BiE-)C=c4}eamL))EVqu)tE3=?EUL{Zi01+7+#rKKeR%Cfv- zK`(6Br5!V)un7xgS+csi3V@j*k9RQ9OTsttree_->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} :  + + -- 2.30.2