Code

Some changes.
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Fri, 9 Mar 2007 12:35:54 +0000 (12:35 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Fri, 9 Mar 2007 12:35:54 +0000 (12:35 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@5762 594d385d-05f5-0310-b6e9-bd551577e9d8

include/sieve/class_My_Tree.inc
include/sieve/class_sieveElement_If.inc
include/sieve/class_sieveElements.inc

index bcf52cb2d3c93e9c259f48a713f805de54083fcd..a8321a4502bef0c73afe47e197e0ff0135c85b6a 100644 (file)
@@ -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)."<br>";
+      $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();
index 21ff52309490c6318a10ce5d9e5a8e92c25d53b7..4c61ca676729c75536d519f266aef809938c5fac 100644 (file)
@@ -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);
   }
 
index f40d9b8b356f7ab46cb9769f84a19c6b61b496ab..870e380100c035acb9e57f44fc7a3f99a13a1941 100644 (file)
@@ -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()