From 49911a658c471aeada4e5e90ec17d2e6d7742359 Mon Sep 17 00:00:00 2001 From: hickert Date: Wed, 14 Mar 2007 08:41:54 +0000 Subject: [PATCH] Some changes git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@5780 594d385d-05f5-0310-b6e9-bd551577e9d8 --- include/sieve/class_My_Tree.inc | 34 ++++++++++- include/sieve/class_sieveElement_Require.inc | 13 +++-- include/sieve/class_sieveElement_Vacation.inc | 7 ++- include/sieve/class_sieveManagement.inc | 58 ++++++++++++++++++- include/sieve/templates/create_script.tpl | 22 +++++++ 5 files changed, 126 insertions(+), 8 deletions(-) create mode 100644 include/sieve/templates/create_script.tpl diff --git a/include/sieve/class_My_Tree.inc b/include/sieve/class_My_Tree.inc index 3774ef0db..10c30eeb4 100644 --- a/include/sieve/class_My_Tree.inc +++ b/include/sieve/class_My_Tree.inc @@ -31,6 +31,10 @@ class My_Tree extends Tree * Handle new elements **************/ + if(isset($_POST['select_new_element_type_cancel'])){ + $this->add_new = FALSE; + } + if($this->add_new){ $element_types= array( @@ -648,8 +652,36 @@ class My_Tree extends Tree function check() { $msgs = array(); - foreach($this->pap as $obj){ + /* Some logical checks. + * like : only sieve_comment can appear before require. + */ + + /* Ensure that there are no command before require + * - Get id of last require tag + * - Collect object types in from of this tag. + * - Check if there are tags collected that are not allowed + */ + $last_found_at = -1; + $objs = array(); + foreach($this->pap as $key => $obj){ + if(get_class($obj) == "sieve_require"){ + $last_found_at = $key; + } + } + foreach($this->pap as $key => $obj){ + if($key == $last_found_at) break; + if(!in_array(get_class($obj),array("sieve_comment","sieve_require"))){ + $objs[] = get_class($obj); + } + } + if(count($objs) && $last_found_at != -1){ + $str = _("Require must be the first command in the script."); + $msgs[] = $str; + print_red($str);; + } + + foreach($this->pap as $obj){ $o_msgs = $obj->check(); foreach($o_msgs as $o_msg){ $msgs[] = $o_msg; diff --git a/include/sieve/class_sieveElement_Require.inc b/include/sieve/class_sieveElement_Require.inc index dffbf375b..3b91b8205 100644 --- a/include/sieve/class_sieveElement_Require.inc +++ b/include/sieve/class_sieveElement_Require.inc @@ -7,10 +7,13 @@ class sieve_require function sieve_require($data,$object_id) { - $this->object_id = $object_id; - foreach($data['ELEMENTS'] as $node ){ - if(in_array($node['class'],array("quoted-string","text"))){ - $this->data[] = preg_replace("/\"/","",$node['text']); + if($data != NULL){ + + $this->object_id = $object_id; + foreach($data['ELEMENTS'] as $node ){ + if(in_array($node['class'],array("quoted-string","text"))){ + $this->data[] = preg_replace("/\"/","",$node['text']); + } } } } @@ -65,7 +68,7 @@ class sieve_require $smarty->assign("LastError",$tmp); $smarty->assign("LastErrorCnt",count($tmp)); $smarty->assign("ID", $this->object_id); - $object_container = $smarty->fetch(get_template_path("templates/object_container_clear.tpl",TRUE,dirname(__FILE__))); + $object_container = $smarty->fetch(get_template_path("templates/object_container.tpl",TRUE,dirname(__FILE__))); $object= $smarty->fetch(get_template_path("templates/element_require.tpl",TRUE,dirname(__FILE__))); $str = preg_replace("/%%OBJECT_CONTENT%%/",$object,$object_container); return($str); diff --git a/include/sieve/class_sieveElement_Vacation.inc b/include/sieve/class_sieveElement_Vacation.inc index 7de20b9d6..ec3250d48 100644 --- a/include/sieve/class_sieveElement_Vacation.inc +++ b/include/sieve/class_sieveElement_Vacation.inc @@ -122,6 +122,7 @@ class sieve_vacation $Addresses .= $key.", "; } $Addresses = preg_replace("/,$/","",trim($Addresses)); + $smarty = get_smarty(); $smarty->assign("Reason",$this->reason); $smarty->assign("Addresses",$Addresses); @@ -129,7 +130,11 @@ class sieve_vacation $smarty->assign("Days",$this->days); $smarty->assign("ID",$this->object_id); $smarty->assign("Expert",$this->Expert); - return($smarty->fetch(get_template_path("templates/element_vacation.tpl",TRUE,dirname(__FILE__)))); + + $object_container = $smarty->fetch(get_template_path("templates/object_container.tpl",TRUE,dirname(__FILE__))); + $object= $smarty->fetch(get_template_path("templates/element_vacation.tpl",TRUE,dirname(__FILE__))); + $str = preg_replace("/%%OBJECT_CONTENT%%/",$object,$object_container); + return($str); } } diff --git a/include/sieve/class_sieveManagement.inc b/include/sieve/class_sieveManagement.inc index cfbbb748e..c4b8d338a 100644 --- a/include/sieve/class_sieveManagement.inc +++ b/include/sieve/class_sieveManagement.inc @@ -37,6 +37,7 @@ class sieveManagement extends plugin var $script_to_delete =-1; var $sieve_handle = NULL; + var $create_script = FALSE; /* Initialize the class and load all sieve scripts * try to parse them and display errors @@ -109,6 +110,60 @@ class sieveManagement extends plugin */ function execute() { + if(isset($_POST['create_new_script'])){ + $this->create_script = TRUE; + } + + if(isset($_POST['create_script_cancel'])){ + $this->create_script = FALSE; + } + + if($this->create_script){ + $smarty = get_smarty(); + + $name = ""; + if(isset($_POST['NewScriptName'])){ + $name = $_POST['NewScriptName']; + } + + $err = ""; + if($name != strtolower($name)){ + $err = _("Only lower case names are allowed here."); + } + + if(preg_match("/[^a-z]/i",$name)){ + $err = _("Only a-z are allowed in script names."); + } + + if($this->create_script && isset($_POST['create_script_save']) && $err == "" ){ + $this->create_script = FALSE; + + $script = "/*New script */". + "stop;"; + $p = new My_Parser; + + $sc['SCRIPT'] = $script; + $sc['MSG'] = ""; + + $ret = $p->parse($script); + if(!$ret){ + $sc['MSG'] = "".$p->status_text.""; + $sc['STATUS'] = _("Parse failed")."".$p->status_text.""; + }else{ + $sc['STATUS'] = _("Parse successful"); + } + $sc['PARSER'] = $p; + $sc['EDITED'] = TRUE; + $sc['ACTIVE'] = FALSE; + $sc['NAME'] = $name; + $this->scripts[$name] = $sc; + }else{ + $smarty->assign("NewScriptName",$name); + $smarty->assign("Error",$err); + return($smarty->fetch(get_template_path("templates/create_script.tpl",TRUE,dirname(__FILE__)))); + } + } + $once = TRUE; foreach($_POST as $name => $value){ if(preg_match("/^editscript_/",$name) && $once && !$this->current_handler){ @@ -261,6 +316,7 @@ class sieveManagement extends plugin $display ="

Sieve script management

"; $display .= _("Be careful. All your changes will be saved directly to sieve, if you use the save button below."); + $display .= "
"; $display .= $List->DrawList(); $display .= "

\n"; @@ -309,7 +365,7 @@ class sieveManagement extends plugin _("Failed to save sieve script").": ". to_string($this->sieve_handle->error_raw). ""; -# echo nl2br($data); + echo nl2br($data); } } } diff --git a/include/sieve/templates/create_script.tpl b/include/sieve/templates/create_script.tpl new file mode 100644 index 000000000..0559f54a9 --- /dev/null +++ b/include/sieve/templates/create_script.tpl @@ -0,0 +1,22 @@ +

Create a new sieve script

+{t}Please enter the name for yout new script below.{/t}
+{t}Script names must be lower case and only characters are allowed.{/t} + +
+
+{if $Error != ""} + {$Error} +
+{/if} +{t}Script name{/t} :  + +
+ +
+ +   + +
+ -- 2.30.2