Code

Added new function get_sieve
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Fri, 16 Mar 2007 10:12:11 +0000 (10:12 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Fri, 16 Mar 2007 10:12:11 +0000 (10:12 +0000)
Move code from parser to management class

git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@5795 594d385d-05f5-0310-b6e9-bd551577e9d8

include/sieve/class_My_Parser.inc
include/sieve/class_My_Tree.inc
include/sieve/class_sieveManagement.inc
include/sieve/templates/edit_frame_base.tpl

index 698fbbadf33eebd4fb03ab54ff5346b5c7ce123c..816950e996427df90eb7ddabfcb58826dc818b81 100644 (file)
@@ -10,27 +10,6 @@ class My_Parser extends Parser
 
        function execute()
        {
-               /* Create dump of current sieve script */
-               if(isset($_POST['Save_Copy'])){
-
-                       /* force download dialog */
-                       header("Content-type: application/tiff\n");
-                       if (preg_match('/MSIE 5.5/', $HTTP_USER_AGENT) ||
-                                       preg_match('/MSIE 6.0/', $HTTP_USER_AGENT)) {
-                               header('Content-Disposition: filename="dump.script"');
-                       } else {
-                               header('Content-Disposition: attachment; filename="dump.script"');
-                       }
-                       header("Content-transfer-encoding: binary\n");
-                       header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
-                       header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
-                       header("Cache-Control: no-cache");
-                       header("Pragma: no-cache");
-                       header("Cache-Control: post-check=0, pre-check=0");
-                       echo $this->get_sieve_script(); 
-                       exit(); 
-               }
-
                $ret = $this->dumpParseTree();
                return($ret);
        }
index 0dd19a21eab158856cb90dc5615415054f0ff403..0d718b2e517746c7cd7e9c94868d815887e09fb3 100644 (file)
@@ -69,14 +69,14 @@ class My_Tree extends Tree
     if($node['class'] == "block-start"){
       $tmp = array_pop($this->mode_stack);
       $this->handle_elements($tmp,$node_id);
-      $this->handle_elements(array("TYPE" => "block_start"),$node_id);
+      $this->handle_elements(array("TYPE" => "block_start"),preg_replace("/[^0-9]/","",microtime()));
     }
 
     /* This closes the last mode */
     if($node['class'] == "block-end"){
       $tmp = array_pop($this->mode_stack);
       $this->handle_elements($tmp,$node_id);
-      $this->handle_elements(array("TYPE" => "block_end"),$node_id);
+      $this->handle_elements(array("TYPE" => "block_end"),preg_replace("/[^0-9]/","",microtime()));
     }
 
     /* Semicolon indicates a new command */
@@ -518,12 +518,6 @@ class My_Tree extends Tree
     return($tmp);
   }
 
-  function Add_Element()
-  {
-    $tmp = array("ELEMENTS" => array(array("class" => "qouted-string","text"=> "Bla bla, later more")));
-    $this->pap[] = new sieve_comment($tmp,rand(1000,100000));
-  }
-
   function check()
   {
                $msgs = array();
index 81b6b34525b76c3328130ab3c8549fa5b204b550..3a4cc1f7a4cadf13eadebd2ee17441d1f2657c21 100644 (file)
@@ -51,28 +51,6 @@ class sieveManagement extends plugin
   var $add_element_type   = "sieve_comment";
 
 
-  function get_sieve()
-  {
-    /* Connect to sieve class and try to get all available sieve scripts */
-    $cfg=  $this->config->data['SERVERS']['IMAP'][$this->parent->gosaMailServer];
-    $this->Sieve_Error = "";
-  
-    /* Log into the mail server */
-    $sieve= new sieve(
-        $cfg["sieve_server"], 
-        $cfg["sieve_port"], 
-        $this->parent->uid, 
-        $cfg["password"], 
-        $cfg["admin"]);
-
-    /* Try to login */
-    if (!$sieve->sieve_login()){
-      $this->Sieve_Error = $sieve->error_raw;
-      return(FALSE);
-    }
-    return($sieve);
-  }
-
   /* Initialize the class and load all sieve scripts 
    *  try to parse them and display errors 
    */ 
@@ -140,6 +118,32 @@ class sieveManagement extends plugin
   }
 
 
+  /* Return a sieve class hanlde,
+   *  false if login fails
+   */
+  function get_sieve()
+  {
+    /* Connect to sieve class and try to get all available sieve scripts */
+    $cfg=  $this->config->data['SERVERS']['IMAP'][$this->parent->gosaMailServer];
+    $this->Sieve_Error = "";
+  
+    /* Log into the mail server */
+    $sieve= new sieve(
+        $cfg["sieve_server"], 
+        $cfg["sieve_port"], 
+        $this->parent->uid, 
+        $cfg["password"], 
+        $cfg["admin"]);
+
+    /* Try to login */
+    if (!$sieve->sieve_login()){
+      $this->Sieve_Error = $sieve->error_raw;
+      return(FALSE);
+    }
+    return($sieve);
+  }
+
+
   /* Handle sieve list 
    */
   function execute()
@@ -382,6 +386,28 @@ class sieveManagement extends plugin
      */
     if($this->current_handler){
 
+        /* Create dump of current sieve script */
+        if(isset($_POST['Save_Copy'])){
+
+            /* force download dialog */
+            header("Content-type: application/tiff\n");
+            if (preg_match('/MSIE 5.5/', $HTTP_USER_AGENT) ||
+                    preg_match('/MSIE 6.0/', $HTTP_USER_AGENT)) {
+                header('Content-Disposition: filename="dump.script"');
+            } else {
+                header('Content-Disposition: attachment; filename="dump.script"');
+            }
+            header("Content-transfer-encoding: binary\n");
+            header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
+            header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
+            header("Cache-Control: no-cache");
+            header("Pragma: no-cache");
+            header("Cache-Control: post-check=0, pre-check=0");
+            echo $this->scripts[$this->current_script]['SCRIPT'];
+            exit();
+        }
+
+
       /****
        * Add new element to ui
        ****/
@@ -418,6 +444,34 @@ class sieveManagement extends plugin
          */
         if(isset($_POST['select_new_element_type'])){
 
+          $this->add_new_id;
+
+          $data = $this->current_handler->tree_->pap;
+
+          /* Get index of the element identified by object_id == $this->add_new_id; */
+          $index = -1;
+          foreach($data as $key => $obj){
+            if($obj->object_id == $this->add_new_id && $index==-1){
+              $index = $key;
+            }
+          }
+          /* We have found the specified object_id 
+           *  and want to detect the next free position 
+           *  to insert the new element.
+           */
+          if($index != -1){
+            if($this->add_above_below == "above"){
+              $direction ="up";
+              $next_free = $this->current_handler->tree_->_get_next_free_move_slot($index,$direction);
+              $next_free ++;
+            }else{
+              $next_free = $this->current_handler->tree_->_get_next_free_move_slot($index,$direction);
+              $direction = "down";
+            }
+            $this->add_new_id = $this->current_handler->tree_->pap[$next_free]->object_id;
+          }
+
           /* Create elements we should add */
           $ele[] = new $this->add_element_type(NULL, preg_replace("/[^0-9]/","",microtime()));
           if($this->add_element_type == "sieve_if"){
@@ -426,7 +480,6 @@ class sieveManagement extends plugin
           }
           $start = $end = array();
           $found = false;
-          $data = $this->current_handler->tree_->pap;
 
           /* Add above current element*/
           if($this->add_above_below == "above"){
index 1f80feb967952f05a0e9886f2ac046aee40c43e6..a5552beb4b02360ac654129d37bf34fa60e93486 100644 (file)
@@ -3,7 +3,6 @@
        <tr>
                <td style='background-color: #CCCCCC; padding:5px;'>
                        
-                       <input type='submit' name='Add_Element' value="{t}Add element{/t}">
                        <input type='submit' name='Save_Copy' value="{t}Save copy{/t}">
                        <input type='submit' name='Import_Copy' value="{t}Import copy{/t}">