From: hickert Date: Fri, 9 Mar 2007 12:35:54 +0000 (+0000) Subject: Some changes. X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=a73f69f614f7fe7ad04b8554bb7755c77575b2d7;p=gosa.git Some changes. git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@5762 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/include/sieve/class_My_Tree.inc b/include/sieve/class_My_Tree.inc index bcf52cb2d..a8321a450 100644 --- a/include/sieve/class_My_Tree.inc +++ b/include/sieve/class_My_Tree.inc @@ -158,11 +158,11 @@ class My_Tree extends Tree $this->remove_object($key); } if(isset($obj->object_id) && preg_match("/^Move_Up_Object_".$obj->object_id."_/",$name) && $once){ - $this->move_object_up($key); + $this->move_up_down($key,"up"); $once = FALSE; } if(isset($obj->object_id) && preg_match("/^Move_Down_Object_".$obj->object_id."_/",$name) && $once){ - $this->move_object_down($key); + $this->move_up_down($key,"down"); $once = FALSE; } } @@ -175,6 +175,161 @@ class My_Tree extends Tree } + /* This function moves a given element to another position. + * Single elements like "keep;" will simply be moved one posisition down/up. + * Multiple elements like if-elsif-else will be moved as block. + * + * $key_id specified the element that should be moved. + * $direction specifies to move elements "up" or "down" + */ + function move_up_down($key_id,$direction = "down") + { + + /* Get the current element to decide what to move. */ + $e_class = get_class($this->pap[$key_id]); + + + if(in_array($e_class,array("sieve_if"))){ + echo "move block"; + } + + if(in_array($e_class,array("sieve_stop","sieve_keep","sieve_require", "sieve_stop", "sieve_reject", "sieve_fileinto", "sieve_redirect", "sieve_discard"))){ + echo "move single ".$key_id." to ".$this->_get_next_free_move_slot($key_id,$direction)."
"; + $this->move_single_element_to($key_id,$this->_get_next_free_move_slot($key_id,$direction)); + } + } + + + function move_single_element_to($from,$to) + { + if($from == $to) return; + + $ret = array(); + + + $tmp = $this->pap; + +# $tmp = array(); + # foreach($this->pap as $class){ + # $tmp[] = get_class($class); + # } + + if($from > $to ){ + + $element = $this->pap[$from]; + + $begin = array(); + $middle = array(); + $end = array(); + + /* Get all element in fron to element to move */ + if($from != 0){ + $begin = array_slice($tmp,0,$to); + } + + /* Get all elements between */ + $middle = array_slice($tmp,$to , ($from - ($to) )); + + /* Get the rest */ + $end = array_slice($tmp,$from+1); + + foreach($begin as $data){ + $ret[] = $data; + } + $ret[] = $element; + foreach($middle as $data){ + $ret[] = $data; + } + foreach($end as $data){ + $ret[] = $data; + } + +# print_a(array("Anfang" => $begin ,$element, "middle" => $middle, "end" => $end)); + + $this->pap = $ret; + } + if($from < $to ){ + + $element = $this->pap[$from]; + + $begin = array(); + $middle = array(); + $end = array(); + + /* Get all element in fron to element to move */ + if($from != 0){ + $begin = array_slice($tmp,0,$from); + } + + /* Get all elements between */ + $middle = array_slice($tmp,$from+1 , ($to - ($from))); + + /* Get the rest */ + $end = array_slice($tmp,$to+1); + + foreach($begin as $data){ + $ret[] = $data; + } + foreach($middle as $data){ + $ret[] = $data; + } + $ret[] = $element; + foreach($end as $data){ + $ret[] = $data; + } + $this->pap = $ret; + } + } + + + function _get_next_free_move_slot($key_id,$direction) + { + $last_class = ""; + $current_class =""; + $next_class = ""; + + $allowed_to_add_after = array("sieve_keep", + "sieve_require", + "sieve_stop", + "sieve_reject", + "sieve_fileinto", + "sieve_redirect", + "sieve_discard", + "sieve_block_end"); + + if($direction == "down"){ + $test = $this->pap; + + + while($key_id < count($test)){ + + if(($key_id+1) == count($test)) return($key_id); + + $key_id ++; + + $current_class = get_class($test[$key_id]); + if(in_array($current_class, $allowed_to_add_after)){ + return($key_id); + } + } + }else{ + + $test = $this->pap; + + if($key_id == 0) return($key_id); + + $key_id --; + while($key_id >=0 ){ + + $current_class = get_class($test[$key_id]); + if(in_array($current_class, $allowed_to_add_after)){ + return($key_id); + } + $key_id --; + } + } + } + function move_object_up($key_id) { $new = array(); diff --git a/include/sieve/class_sieveElement_If.inc b/include/sieve/class_sieveElement_If.inc index 21ff52309..4c61ca676 100644 --- a/include/sieve/class_sieveElement_If.inc +++ b/include/sieve/class_sieveElement_If.inc @@ -616,15 +616,23 @@ class sieve_if $smarty = get_smarty(); $smarty->assign("ID", $this->id); - $object_container = $smarty->fetch(get_template_path("templates/object_container.tpl",TRUE,dirname(__FILE__))); + + /* Only display navigation elements if necessary */ + if($this->TYPE == "if"){ + $object_container = $smarty->fetch(get_template_path("templates/object_container.tpl",TRUE,dirname(__FILE__))); + }else{ + $object_container = $smarty->fetch(get_template_path("templates/object_container_clear.tpl",TRUE,dirname(__FILE__))); + } $smarty->assign("Name", $name); $smarty->assign("Contents", $this->get_as_html()); $object = $smarty->fetch(get_template_path("templates/element_if_else.tpl",TRUE,dirname(__FILE__))); - $str = preg_replace("/%%OBJECT_CONTENT%%/",$object,$object_container); + $str = preg_replace("/%%OBJECT_CONTENT%%/",$object,$object_container); + + return($str); } diff --git a/include/sieve/class_sieveElements.inc b/include/sieve/class_sieveElements.inc index f40d9b8b3..870e38010 100644 --- a/include/sieve/class_sieveElements.inc +++ b/include/sieve/class_sieveElements.inc @@ -533,10 +533,25 @@ class sieve_keep /* This class handles the stop statement */ class sieve_stop { + var $object_id = -1; + + function sieve_stop($data,$object_id) + { + $this->object_id = $object_id; + } + + function save_object() + { + } + function execute() { $smarty = get_smarty(); - return($smarty->fetch(get_template_path("templates/element_stop.tpl",TRUE,dirname(__FILE__)))); + $smarty->assign("ID", $this->object_id); + $object_container = $smarty->fetch(get_template_path("templates/object_container.tpl",TRUE,dirname(__FILE__))); + $object= $smarty->fetch(get_template_path("templates/element_stop.tpl",TRUE,dirname(__FILE__))); + $str = preg_replace("/%%OBJECT_CONTENT%%/",$object,$object_container); + return($str); } function get_sieve_script_part()