From 75303a4176a3f512fc4b26fc3c5eba2891665833 Mon Sep 17 00:00:00 2001 From: hickert Date: Mon, 19 Mar 2007 08:50:52 +0000 Subject: [PATCH] Fixed size test. Don't allow adding 'else' twice. Don't allow adding 'else' before 'elsif' git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@5812 594d385d-05f5-0310-b6e9-bd551577e9d8 --- include/sieve/class_sieveElement_If.inc | 2 +- include/sieve/class_sieveManagement.inc | 45 ++++++++++++++++++++----- 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/include/sieve/class_sieveElement_If.inc b/include/sieve/class_sieveElement_If.inc index 9df232b5d..edaec6c04 100644 --- a/include/sieve/class_sieveElement_If.inc +++ b/include/sieve/class_sieveElement_If.inc @@ -438,7 +438,7 @@ class sieve_if { $tmp= array( "Inverse" => FALSE, - "Match_type" => ":contains", + "Match_type" => ":over", "Value_List" => array(1,"M")); $tmp['LastError'] = ""; diff --git a/include/sieve/class_sieveManagement.inc b/include/sieve/class_sieveManagement.inc index a406403bd..ad8b63ae5 100644 --- a/include/sieve/class_sieveManagement.inc +++ b/include/sieve/class_sieveManagement.inc @@ -601,17 +601,46 @@ class sieveManagement extends plugin $smarty = get_smarty(); $add_else_elsif = FALSE; - foreach($this->current_handler->tree_->pap as $obj){ - if($obj->object_id == $this->add_new_id && in_array(get_class($obj),array("sieve_if","sieve_elsif"))){ - $add_else_elsif = TRUE; + + /* Check if we should add else/elsif to the select box + * or not. We can't add else twice!. + */ + if($this->add_above_below == "below"){ + + /* Get posistion of the current element + */ + foreach($this->current_handler->tree_->pap as $key => $obj){ + + if($obj->object_id == $this->add_new_id && in_array(get_class($obj),array("sieve_if","sieve_elsif"))){ + + /* Get block start/end */ + $end_id = $this->current_handler->tree_->get_block_end($key); + $else_found = FALSE; + $elsif_found = FALSE; + + /* Check if there is already an else in this block + */ + for($i = $key ; $i < $end_id ; $i ++){ + if(get_class($this->current_handler->tree_->pap[$i]) == "sieve_else"){ + $else_found = TRUE; + } + if(get_class($this->current_handler->tree_->pap[$i]) == "sieve_elsif"){ + $elsif_found = TRUE; + } + } + + /* Only allow adding 'else' if there is currently + * no 'else' statement. And don't allow adding + * 'else' before 'elseif' + */ + if(!$else_found && (!(get_class($obj) == "sieve_if" && $elsif_found))){ + $element_types['sieve_else'] = _("Else"); + } + $element_types['sieve_elsif'] = _("Else if"); + } } } - if($add_else_elsif && $this->add_above_below == "below"){ - $element_types['sieve_else'] = _("Else"); - $element_types['sieve_elsif'] = _("Else if"); - } - $smarty->assign("element_types",$element_types ); $smarty->assign("element_type",$this->add_element_type); $str = $smarty->fetch(get_template_path("templates/add_element.tpl",TRUE,dirname(__FILE__))); -- 2.30.2