Code

Updated fileinto class.
[gosa.git] / include / sieve / class_sieveElement_Fileinto.inc
1 <?php
3 class sieve_fileinto 
4 {
5   var $data     = array();
6   var $object_id= -1;
7   var $options  = array();
8   var $parent   = NULL;
9   var $user_mode= FALSE;
11   function save_object()
12   {
13     $mbs = $this->get_mail_boxes();
14     
15     if(isset($_POST['fileinto_'.$this->object_id])){
16       $mb = $_POST['fileinto_'.$this->object_id];
19       /* Depending on the user mode we only accept 
20        *  existing mailboxes 
21        */
22       if($this->user_mode){
23         $this->data = $mb;
24       }else{
25         if(in_array_ics($mb,$mbs)){
26           $this->data = $mb; 
27         }
28       }
30       /* Check Mode */
31       if(isset($_POST['user_mode_'.$this->object_id])){
32         $this->user_mode = !$this->user_mode;
33       }
34     }
35   }
37   function sieve_fileinto($data,$object_id,$parent)
38   {
39     $this->object_id = $object_id;
40     $this->parent = $parent;
42     $mbs = $this->get_mail_boxes();
43       
44     /* Set the default mailbox */
45     if($data == NULL){
46       $data = array('ELEMENTS' => array(array('class' => "quoted-string" ,"text" => $mbs[key($mbs)])));
47     }
49     /* Set mailbox */
50     foreach($data['ELEMENTS'] as $node ){
51       if(in_array($node['class'],array("quoted-string","text"))){
52         $this->data = preg_replace("/\"/","",$node['text']);
53       }
54     }
56     /* Set user mode to active, so we are able to insert 
57      *  the destination mail folder manually 
58      */
59     if(!in_array_ics($this->data,$mbs)){
60       $this->user_mode = TRUE;
61     }
62   }
64   function get_sieve_script_part()
65   {
66     $tmp = "";
67       $tmp.= "\"".$this->data."\", ";
68     $tmp = preg_replace("/,$/","",trim($tmp));
69     $tmp = preg_replace ("/\"\"/","\"",$tmp);
70     return("fileinto ".$tmp.";\n");
71   } 
72     
73   function execute()
74   {
75     $smarty = get_smarty();
76     $smarty->assign("Selected",$this->data);
77     $smarty->assign("Boxes", $this->get_mail_boxes());
78     $smarty->assign("User_Mode", $this->user_mode);
79     $smarty->assign("ID", $this->object_id);
80     $object_container = $smarty->fetch(get_template_path("templates/object_container.tpl",TRUE,dirname(__FILE__)));
81     $object= $smarty->fetch(get_template_path("templates/element_fileinto.tpl",TRUE,dirname(__FILE__)));
82     $str = preg_replace("/%%OBJECT_CONTENT%%/",$object,$object_container);
84     return($str);
85   }
87   function check()
88   {
89     return(array());
90   }
92   function get_mail_boxes()
93   {
94     $list  = $this->parent->parent->parent->parent->mailboxList;
95     return($list);
96   }
97 }
99 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
100 ?>