Code

Updated fileinto class.
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 19 Mar 2007 08:15:47 +0000 (08:15 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 19 Mar 2007 08:15:47 +0000 (08:15 +0000)
Some other fixes

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

include/sieve/class_My_Parser.inc
include/sieve/class_My_Tree.inc
include/sieve/class_sieveElement_Fileinto.inc
include/sieve/class_sieveManagement.inc
include/sieve/class_tree.inc
include/sieve/templates/element_fileinto.tpl

index 816950e996427df90eb7ddabfcb58826dc818b81..912422360f1cedd5cc95741e3c2ff4375ed6fa2d 100644 (file)
@@ -7,6 +7,12 @@ define("SIEVE_INDENT_TAB","  ");
  */
 class My_Parser extends Parser 
 {
+       var $parent = NULL;
+
+       function My_Parser($parent)
+       {
+               $this->parent = $parent;
+       }
 
        function execute()
        {
@@ -29,7 +35,7 @@ class My_Parser extends Parser
        {
         $this->status_text = "incomplete";
         $this->script_ = $script;
-        $this->tree_ = new My_Tree(@Scanner::scriptStart());
+        $this->tree_ = new My_Tree(@Scanner::scriptStart(),$this);
         $this->tree_->setDumpFunc(array(&$this, 'dumpToken_'));
         $this->scanner_ = new Scanner($this->script_);
         $this->scanner_->setCommentFunc(array($this, 'comment_'));
index f38f3bab81eb608f548871ba84a78b5674dc6fbb..8792f98f7a855b60f86f76dadf77a43b21b99ea3 100644 (file)
@@ -15,6 +15,13 @@ class My_Tree extends Tree
 
   var $mode_stack = array();
   var $pap             = array();
+  var $parent = NULL;
+
+       function My_Tree(&$root,$parent)
+       {
+    $this->parent = $parent;
+               $this->_construct($root);
+       }
 
   function execute()
   {
@@ -136,7 +143,7 @@ class My_Tree extends Tree
     
     $class_name= "sieve_".$type ;
     if(class_exists($class_name)){
-      $this->pap[] = new $class_name($data,$id);
+      $this->pap[] = new $class_name($data,$id,$this);
     }else{
       echo "<font color='red'>Missing : ".$class_name."</font>"."<br>";
     }
index 16b8c26d735d4b240ca1fc7ad098e63876f90c32..1c1707ef45d4b64bf7f36734bb2e305f00216d15 100644 (file)
@@ -5,6 +5,8 @@ class sieve_fileinto
   var $data     = array();
   var $object_id= -1;
   var $options  = array();
+  var $parent   = NULL;
+  var $user_mode= FALSE;
 
   function save_object()
   {
@@ -13,33 +15,56 @@ class sieve_fileinto
     if(isset($_POST['fileinto_'.$this->object_id])){
       $mb = $_POST['fileinto_'.$this->object_id];
 
-      if(isset($mbs[$mb])) {
-        $this->data[0] = $mb; 
+
+      /* Depending on the user mode we only accept 
+       *  existing mailboxes 
+       */
+      if($this->user_mode){
+        $this->data = $mb;
+      }else{
+        if(in_array_ics($mb,$mbs)){
+          $this->data = $mb; 
+        }
+      }
+
+      /* Check Mode */
+      if(isset($_POST['user_mode_'.$this->object_id])){
+        $this->user_mode = !$this->user_mode;
       }
     }
   }
 
-  function sieve_fileinto($data,$object_id)
+  function sieve_fileinto($data,$object_id,$parent)
   {
     $this->object_id = $object_id;
+    $this->parent = $parent;
 
+    $mbs = $this->get_mail_boxes();
+      
+    /* Set the default mailbox */
     if($data == NULL){
-      $data = array('ELEMENTS' => array(array('class' => "quoted-string" ,"text" => _(""))));
+      $data = array('ELEMENTS' => array(array('class' => "quoted-string" ,"text" => $mbs[key($mbs)])));
     }
 
+    /* Set mailbox */
     foreach($data['ELEMENTS'] as $node ){
       if(in_array($node['class'],array("quoted-string","text"))){
-        $this->data[] = preg_replace("/\"/","",$node['text']);
+        $this->data = preg_replace("/\"/","",$node['text']);
       }
     }
+
+    /* Set user mode to active, so we are able to insert 
+     *  the destination mail folder manually 
+     */
+    if(!in_array_ics($this->data,$mbs)){
+      $this->user_mode = TRUE;
+    }
   }
 
   function get_sieve_script_part()
   {
     $tmp = "";
-    foreach($this->data as $dat){
-      $tmp.= "\"".$dat."\", ";
-    }
+      $tmp.= "\"".$this->data."\", ";
     $tmp = preg_replace("/,$/","",trim($tmp));
     $tmp = preg_replace ("/\"\"/","\"",$tmp);
     return("fileinto ".$tmp.";\n");
@@ -48,8 +73,9 @@ class sieve_fileinto
   function execute()
   {
     $smarty = get_smarty();
-    $smarty->assign("Selected",$this->data[0]);
+    $smarty->assign("Selected",$this->data);
     $smarty->assign("Boxes", $this->get_mail_boxes());
+    $smarty->assign("User_Mode", $this->user_mode);
     $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_fileinto.tpl",TRUE,dirname(__FILE__)));
@@ -65,7 +91,8 @@ class sieve_fileinto
 
   function get_mail_boxes()
   {
-    return(array("not"=>"not","impplemented/yet"=>"impplemented/yet"));
+    $list  = $this->parent->parent->parent->parent->mailboxList;
+    return($list);
   }
 }
 
index 4f47fbc721ab91a7816c3671ea397212e94281d3..a406403bdfb161abdc4126e96998e71931909fec 100644 (file)
@@ -93,7 +93,7 @@ class sieveManagement extends plugin
 
     /* Get script contents */
     foreach($this->scripts as $key => $script){
-      $p = new My_Parser;
+      $p = new My_Parser($this);
       $this->sieve_handle->sieve_getscript($script['NAME']);
 
       $script = "";
@@ -214,7 +214,7 @@ class sieveManagement extends plugin
                   "stop;";
 
         /* Create a new parser and initialize default values */
-        $p = new My_Parser;
+        $p = new My_Parser($this);
         $ret = $p->parse($script);
         $sc['SCRIPT'] = $script;
         $sc['ORIG_SCRIPT'] = $script;
@@ -370,7 +370,7 @@ class sieveManagement extends plugin
       if(!count($chk)){
 
         $sc = $this->scripts[$this->current_script]['SCRIPT'];
-        $p = new My_Parser;
+        $p = new My_Parser($this);
         if($p -> parse($sc)){
 
           if($this->scripts[$this->current_script]['MODE'] == "Source-Only"){
@@ -526,21 +526,23 @@ class sieveManagement extends plugin
             $this->add_new_id = $this->current_handler->tree_->pap[$next_free]->object_id;
           }
 
+          $parent = $this->current_handler->tree_;
+
           /* Create elements we should add */
           if($this->add_element_type == "sieve_if"){
-            $ele[] = new $this->add_element_type(NULL, preg_replace("/[^0-9]/","",microtime()));
-            $ele[] = new sieve_block_start(NULL,preg_replace("/[^0-9]/","",microtime()));
-            $ele[] = new sieve_block_end(NULL,preg_replace("/[^0-9]/","",microtime()));
+            $ele[] = new $this->add_element_type(NULL, preg_replace("/[^0-9]/","",microtime()),$parent);
+            $ele[] = new sieve_block_start(NULL,preg_replace("/[^0-9]/","",microtime()),$parent);
+            $ele[] = new sieve_block_end(NULL,preg_replace("/[^0-9]/","",microtime()),$parent);
           }elseif($this->add_element_type == "sieve_else"){
-            $ele[] = new sieve_block_end(NULL,preg_replace("/[^0-9]/","",microtime()));
-            $ele[] = new $this->add_element_type(NULL, preg_replace("/[^0-9]/","",microtime()));
-            $ele[] = new sieve_block_start(NULL,preg_replace("/[^0-9]/","",microtime()));
+            $ele[] = new sieve_block_end(NULL,preg_replace("/[^0-9]/","",microtime()),$parent);
+            $ele[] = new $this->add_element_type(NULL, preg_replace("/[^0-9]/","",microtime()),$parent);
+            $ele[] = new sieve_block_start(NULL,preg_replace("/[^0-9]/","",microtime()),$parent);
           }elseif($this->add_element_type == "sieve_elsif"){
-            $ele[] = new sieve_block_end(NULL,preg_replace("/[^0-9]/","",microtime()));
-            $ele[] = new $this->add_element_type(NULL, preg_replace("/[^0-9]/","",microtime()));
-            $ele[] = new sieve_block_start(NULL,preg_replace("/[^0-9]/","",microtime()));
+            $ele[] = new sieve_block_end(NULL,preg_replace("/[^0-9]/","",microtime()),$parent);
+            $ele[] = new $this->add_element_type(NULL, preg_replace("/[^0-9]/","",microtime()),$parent);
+            $ele[] = new sieve_block_start(NULL,preg_replace("/[^0-9]/","",microtime()),$parent);
           }else{
-            $ele[] = new $this->add_element_type(NULL, preg_replace("/[^0-9]/","",microtime()));
+            $ele[] = new $this->add_element_type(NULL, preg_replace("/[^0-9]/","",microtime()),$parent);
           }
 
           $start = $end = array();
@@ -764,7 +766,7 @@ class sieveManagement extends plugin
         if(isset($_POST['script_contents'])){
           $sc = stripslashes($_POST['script_contents']);
           $this->scripts[$this->current_script]['SCRIPT'] = $sc;
-          $p = new My_Parser;
+          $p = new My_Parser($this);
           if($p -> parse($sc)){
             $this->Script_Error = "";
           } else {
@@ -776,7 +778,7 @@ class sieveManagement extends plugin
       if(in_array($Mode,array("Structured"))){
         $sc = $this->current_handler->get_sieve_script();
         $this->scripts[$this->current_script]['SCRIPT'] = $sc;
-        $p = new My_Parser;
+        $p = new My_Parser($this);
         if($p -> parse($sc)){
           $this->Script_Error = "";
         } else {
@@ -798,7 +800,7 @@ class sieveManagement extends plugin
           if($old_mode != $new_mode){
 
             $sc = $this->scripts[$this->current_script]['SCRIPT'];
-            $p = new My_Parser;
+            $p = new My_Parser($this);
 
             if($p -> parse($sc)){
               $this->current_handler->parse($sc);
index 96bc7a822800db0fa9ae20a2f4be2c5df1aedc14..920b809ce28e65417ee4ffb2a56dd3e30f4ba4ac 100644 (file)
@@ -172,4 +172,4 @@ class Tree
        }
 }
 
-?>
\ No newline at end of file
+?>
index b73dc5a030a150d5af2c83a0f4e71c6adc42d39f..977fa37b90b8cdf3f97a528a184ef780684ceb53 100644 (file)
@@ -1,10 +1,26 @@
-<table cellspacing=0 width='100%'>
+<table cellspacing=0 width='100%' style='width:100%;background-color: #d8e1f2; '>
        <tr>
-               <td style='width:100%;background-color: #d8e1f2; height:50px;'>
+               <td>
                        {t}Move mail into folder{/t}
-                       <select name='fileinto_{$ID}'>
-                               {html_options options=$Boxes selected=$Selected}
-                   </select>
+               </td>
+               <td style='text-align:right;'>
+                       {if $User_Mode}
+                               <input type='submit' name='user_mode_{$ID}' value='{t}Select from list{/t}'>
+                       {else}
+                               <input type='submit' name='user_mode_{$ID}' value='{t}Manual selection{/t}'>
+                       {/if}
+               </td>
+       </tr>
+       <tr>
+               <td colspan=2>
+                       <b>{t}Folder{/t}</b>
+                       {if $User_Mode}
+                               <input type='text' value='{$Selected}' name='fileinto_{$ID}' style='width:300px;'>
+                       {else}
+                               <select name='fileinto_{$ID}'>
+                                       {html_options values=$Boxes output=$Boxes selected=$Selected}
+                               </select>
+                       {/if}
                </td>
        </tr>
 </table>