Code

Updated add element handling.
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 11 Apr 2007 06:46:37 +0000 (06:46 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 11 Apr 2007 06:46:37 +0000 (06:46 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@6000 594d385d-05f5-0310-b6e9-bd551577e9d8

include/sieve/class_sieveManagement.inc
include/sieve/templates/object_container.tpl

index 96035b5b2079e9307d576b223beec3fb4113b5dd..90e87bf23b22bff02d4ee041dd397d54e346464c 100644 (file)
@@ -709,6 +709,72 @@ class sieveManagement extends plugin
       return(FALSE);
     }
 
+    /* These element types are allowed to be added here */
+    $element_types= array(
+        "sieve_keep"      => _("Keep"),
+        "sieve_comment"   => _("Comment"),
+        "sieve_fileinto"  => _("File into"),
+        "sieve_keep"      => _("Keep"),
+        "sieve_discard"   => _("Discard"),
+        "sieve_redirect"  => _("Redirect"),
+        "sieve_reject"    => _("Reject"),
+        "sieve_require"   => _("Require"),
+        "sieve_stop"      => _("Stop"),
+        "sieve_vacation"  => _("Vacation message"),
+        "sieve_if"        => _("If"));
+
+    /* Check if we should add else/elsif to the select box
+     *  or not. We can't add else twice!.
+     */
+
+    /* Get posistion of the current element
+     */
+    foreach($this->current_handler->tree_->pap as $key => $obj){
+
+      if($obj->object_id == $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;
+          }
+        }
+
+        if($this->add_above_below == "below"){
+
+          /* 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");
+        }else{
+         
+          /* Allow adding elsif above elsif */ 
+          if(in_array(get_class($obj),array("sieve_elsif"))){
+            $element_types['sieve_elsif'] = _("Else if");
+          }
+        }
+      }
+    }
+
+    if(!isset($element_types[$type])){
+      print_red(sprintf(_("Can't add the specified element at the given position.")));
+      return;
+    }
+
+
     /* Create elements we should add 
      * -Some element require also surrounding block elements
      */
index 967338323ff9a55ece3fae5a05f5f214b8897b15..7662b67f772235bb8ba65b898685d6cb16c6dc5b 100644 (file)
        
                        <select name='element_type_{$ID}'>
                                <option value=''>&nbsp;</option>
-                               <option value='sieve_comment'>comment</option>
-                               <option value='sieve_fileinto'>sieve_fileinto</option>
-                               <option value='sieve_keep'>sieve_keep</option>
-                               <option value='sieve_discard'>sieve_discard</option>
-                               <option value='sieve_redirect'>sieve_redirect</option>
-                               <option value='sieve_reject'>sieve_reject</option>
-                               <option value='sieve_require'>sieve_require</option>
-                               <option value='sieve_stop'>sieve_stop</option>
-                               <option value='sieve_vacation'>sieve_vacation</option>
-                               <option value='sieve_if'>sieve_if</option>
-                               <option value='sieve_elsif'>sieve_elsif</option>
-                               <option value='sieve_else'>sieve_else</option>
+                               <option value='sieve_keep'>{t}Keep{/t}</option>
+                               <option value='sieve_comment'>{t}Comment{/t}</option>
+                               <option value='sieve_fileinto'>{t}Fileinto{/t}</option>
+                               <option value='sieve_keep'>{t}Keep{/t}</option>
+                               <option value='sieve_discard'>{t}Discard{/t}</option>
+                               <option value='sieve_redirect'>{t}Redirect{/t}</option>
+                               <option value='sieve_reject'>{t}Reject{/t}</option>
+                               <option value='sieve_require'>{t}Require{/t}</option>
+                               <option value='sieve_stop'>{t}Stop{/t}</option>
+                               <option value='sieve_vacation'>{t}Vacationmessage{/t}</option>
+                               <option value='sieve_if'>{t}If{/t}</option>
+                               <option value='sieve_else'>{t}Else{/t}</option>
+                               <option value='sieve_elsif'>{t}Else if{/t}</option>
                        </select>
 
                        <input type='image' src='images/sieve_add_new_top.png' name='Add_Object_Top_{$ID}'