Code

f357d37d96d961bd4e1ea2065d8468deb9f985b8
[gosa.git] / include / sieve / class_sieveElement_Fileinto.inc
1 <?php
3 class sieve_fileinto 
4 {
5   var $data     = "";
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 = stripslashes($_POST['fileinto_'.$this->object_id]);
18       /* Depending on the user mode we only accept 
19        *  existing mailboxes 
20        */
21       if($this->user_mode){
22         $this->data = $mb;
23       }else{
24         if(in_array_ics($mb,$mbs)){
25           $this->data = $mb; 
26         }
27       }
29       /* Check Mode */
30       if(isset($_POST['user_mode_'.$this->object_id])){
31         $this->user_mode = !$this->user_mode;
32       }
33     }
34   }
36   function sieve_fileinto($data,$object_id,$parent)
37   {
38     $this->object_id = $object_id;
39     $this->parent = $parent;
40     $this->parent->add_require("fileinto");
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     /* Load element contents, should normaly be only one string 
50      *  but if we found more than one, just append the following strings.
51      */
52     for($i = 0 ; $i < count($data['ELEMENTS']) ; $i++){
53       $tmp = sieve_get_strings($data['ELEMENTS'],$i);
54       $i  = $i + $tmp['OFFSET'];
55       foreach($tmp['STRINGS'] as $str){
56         $this->data .= $str;
57       }
58     }
60     /* Set user mode to active, so we are able to insert 
61      *  the destination mail folder manually 
62      */
63     if(!in_array_ics($this->data,$mbs)){
64       $this->user_mode = TRUE;
65     }
66   }
68   function get_sieve_script_part()
69   {
70     $tmp = "";
71     $tmp.= "\"".$this->data."\", ";
72     $tmp = preg_replace("/,$/","",trim($tmp));
73     $tmp = preg_replace ("/\"\"/","\"",$tmp);
74     return("fileinto ".$tmp.";");
75   } 
76     
77   function execute()
78   {
79     $smarty = get_smarty();
80     $smarty->assign("Selected",htmlentities($this->data));
81     $smarty->assign("Boxes", $this->get_mail_boxes());
82     $smarty->assign("User_Mode", $this->user_mode);
83     $smarty->assign("ID", $this->object_id);
84     $object_container = $smarty->fetch(get_template_path("templates/object_container.tpl",TRUE,dirname(__FILE__)));
85     $object= $smarty->fetch(get_template_path("templates/element_fileinto.tpl",TRUE,dirname(__FILE__)));
86     $str = preg_replace("/%%OBJECT_CONTENT%%/",addcslashes($object,"\\"),$object_container);
88     return($str);
89   }
91   function check()
92   {
93     return(array());
94   }
96   function get_mail_boxes()
97   {
98     $list  = $this->parent->parent->parent->parent->mailboxList;
99     return($list);
100   }
103 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
104 ?>