Code

Some changes
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 13 Mar 2007 13:25:11 +0000 (13:25 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 13 Mar 2007 13:25:11 +0000 (13:25 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@5774 594d385d-05f5-0310-b6e9-bd551577e9d8

include/sieve/class_My_Tree.inc
include/sieve/class_sieveElement_Discard.inc [new file with mode: 0644]
include/sieve/class_sieveManagement.inc
include/sieve/templates/edit_frame_base.tpl
include/sieve/templates/object_container.tpl

index 1cb41a3a7e586215e3e14e6e4e9b318312432edd..1816f92b74695e5b4279a1d8eec2b7f218aa8ef5 100644 (file)
@@ -16,12 +16,51 @@ class My_Tree extends Tree
   var $mode_stack = array();
   var $pap             = array();
 
+  var $add_new          = FALSE;
+  var $add_new_id       = 0;
+  var $add_type         = "up";
+  var $add_element_type = "";
 
   /* Create a html interface for the current sieve filter 
    */
   function dump()
   {
     error_reporting(E_ALL);
+      $element_types= array(
+          "sieve_keep"      => _("Keep"),
+          "sieve_comment"   => _("Comment"),
+          "sieve_fileinto"  => _("File into"),
+          "sieve_keep"      => _("Keep"),
+          "sieve_redirect"  => _("Redirect"),
+          "sieve_reject"    => _("Reject"),
+          "sieve_require"   => _("Require"),
+          "sieve_stop"      => _("Stop"),
+          "sieve_vacation"  => _("Vacation message"),
+          "sieve_if"        => _("If"));
+
+
+    if($this->add_new && isset($_POST['element_type']) && isset($element_types[$_POST['element_type']])){
+      $this->add_element_type = $_POST['element_type'];
+    }
+
+
+    if($this->add_new && isset($_POST['select_new_element_type'])){
+     
+      $ele = new $this->add_element_type(array(),microtime());
+      
+      $this->pap[] = $ele; 
+      $this->add_new = FALSE;
+    }
+
+    if($this->add_new){
+
+      $smarty = get_smarty();
+      $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__)));
+      return($str);
+    }
 
     /* Only parse the tokens once */
     if(!count($this->pap)){
@@ -33,7 +72,6 @@ class My_Tree extends Tree
 
     /* Create html results */
     $smarty = get_smarty();
-    $smarty->fetch(get_template_path("templates/element_stop.tpl",TRUE,dirname(__FILE__)));
 
     $this -> dump_ = "";
     foreach($this->pap as $key => $object){
@@ -146,7 +184,14 @@ class My_Tree extends Tree
     reset($this->pap);
     foreach($this->pap as $key => $obj){
 
-      if(in_array(get_class($obj),array("sieve_if","sieve_elsif","sieve_vacation","sieve_comment","sieve_reject","sieve_fileinto","sieve_require","sieve_redirect"))){
+      if(in_array(get_class($obj),array("sieve_if",
+                                        "sieve_elsif",
+                                        "sieve_vacation",
+                                        "sieve_comment",
+                                        "sieve_reject",
+                                        "sieve_fileinto",
+                                        "sieve_require",
+                                        "sieve_redirect"))){
 
 
         if(isset($this->pap[$key]) && method_exists($this->pap[$key],"save_object")){
@@ -169,29 +214,41 @@ class My_Tree extends Tree
           $this->move_up_down($key,"down");
           $once = FALSE;
         }
+        if(isset($obj->object_id) && preg_match("/^Add_Object_Top_".$obj->object_id."_/",$name) && $once){
+          $this->add_new_object($obj->object_id,"top");
+          $once = FALSE;
+        }
+        if(isset($obj->object_id) && preg_match("/^Add_Object_Bottom_".$obj->object_id."_/",$name) && $once){
+          $this->add_new_object($obj->object_id,"bottom");
+          $once = FALSE;
+        }
       }
     }
   }
 
 
+  /* Add a new object at the given position */
+  function add_new_object($id,$top_bottom = "bottom")
+  {
+    $this->add_new    = TRUE;
+    $this->add_new_id = $id;
+    $this->add_type   = $top_bottom;
+  }
+
+
+  /* Remove the object at the given position */
   function remove_object($key_id)
   {
-    
     $class = get_class($this->pap[$key_id]);
-
     if(in_array($class,array("sieve_if"))){
-   
       $block_start= $key_id;
       $block_end  = $this->get_block_end($key_id);
       for($i = $block_start ; $i <= $block_end ; $i ++ ){
         unset($this->pap[$i]);
       }
-
     }else{
       unset($this->pap[$key_id]);
     }
-
     $tmp = array();
     foreach($this->pap as $element){
       $tmp[] = $element;
diff --git a/include/sieve/class_sieveElement_Discard.inc b/include/sieve/class_sieveElement_Discard.inc
new file mode 100644 (file)
index 0000000..5998164
--- /dev/null
@@ -0,0 +1,35 @@
+<?php
+
+class sieve_discard 
+{
+  var $data = array();
+  var $object_id = -1;
+
+  function sieve_discard($data,$object_id)
+  {
+    $this->object_id = $object_id;
+  }
+
+  function get_sieve_script_part()
+  {
+    return("discard;\n");
+  } 
+    
+  function save_object()
+  {
+  
+  }
+
+  function execute()
+  {
+    $smarty = get_smarty();
+    $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_discard.tpl",TRUE,dirname(__FILE__)));
+    $str = preg_replace("/%%OBJECT_CONTENT%%/",$object,$object_container);
+    return($str);
+  }
+}
+
+// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
+?>
index fdce9e31c5527ca9968589a4186534e525ef9d10..cfbbb748ec2520d443a5d2751e14df5ab754cf23 100644 (file)
@@ -218,11 +218,6 @@ class sieveManagement extends plugin
     /* Create output for currently opened sieve script */
     if($this->current_handler){
       $ret = $this->current_handler->execute();
-      $ret .= "<div class='seperator' style='text-align:right; width:100%;'>
-        <input type='submit' name='save_sieve_changes' value='"._("Save")."'>
-        &nbsp;
-      <input type='submit' name='cancel_sieve_changes' value='"._("Cancel")."'>
-        </div>";
       return($ret);
     }
 
index 9de761cfb073613ea722524af1203be13ef9d562..d99edbba0560ffc571472073b01a039bdc18e62b 100644 (file)
@@ -19,3 +19,8 @@
                </td>
        </tr>
 </table>
+<div class='seperator' style='text-align:right; width:100%;'>
+       <input type='submit' name='save_sieve_changes' value='{t}Save{/t}'>
+        &nbsp;
+    <input type='submit' name='cancel_sieve_changes' value='{t}Cancel{/t}'>
+</div>
index cbd6dd938e6df853b349608350a17dd6da45b494..94d539888ac2face64a9d373d15efd3cdb1d12a8 100644 (file)
@@ -1,4 +1,15 @@
 <table cellspacing=0 style='width:100%;background-color:#EEEEEE;border: solid 1px #BBB;346575;'>
+       <tr>
+               <td  style='background-color: #235464; text-align:center;'>
+                       &nbsp;  
+               </td>
+               <td  style='background-color: #235464; text-align:left; padding:2px;' >
+                       <input type='image' src='images/sieve_add_new_top.png' name='Add_Object_Top_{$ID}'
+                               alt='{t}Add new{/t}' title='{t}Add a new new object on top of this one.{/t}' class='center'>&nbsp;      
+                       <input type='image' src='images/sieve_add_new_bottom.png' name='Add_Object_Bottom_{$ID}'
+                               alt='{t}Add new{/t}' title='{t}Add a new new object at the bottom of this one.{/t}' class='center'>     
+               </td>
+       </tr>
        <tr>
                <td style='width:20px; background-color: #235464; text-align:center;'>  
                        <input type='image' src='images/sieve_del_object.png' name='Remove_Object_{$ID}'