Code

Some changes
[gosa.git] / include / sieve / class_sieveElement_Vacation.inc
1 <?php
3 class sieve_vacation 
4 {
5   var $days     = FALSE;
6   var $subject  = FALSE;
7   var $from     = "";
8   var $mime     = "";
9   var $handle   = "";
10   var $reason   = "";
11   var $addresses= array();
12   var $object_id= -1;
13   var $Expert   = FALSE;
15   function sieve_vacation($data,$object_id)
16   {
17     /* Usage:   vacation [":days" number] [":subject" string]
18        [":from" string] [":addresses" string-list]
19        [":mime"] [":handle" string] <reason: string> */
21     /* Not all attribute types are supported by the sieve class right now */
22     $known_attrs = array(":days",":subject",":from",":mime",":handle");
24     /* skip if empty */
25     if($data == NULL) return;
27     /* Walk through elements */
28     for($i = 0 ; $i < count($data['ELEMENTS']) ; $i ++){
30       /* get current element */
31       $node = $data['ELEMENTS'][$i];
33       /* Check if tag is in the specified list of attributes */
34       if($node['class'] == "tag" && in_array($node['text'],$known_attrs)){
36         $var = preg_replace("/\:/","",$node['text']);
37         $this->$var = $data['ELEMENTS'][$i+1]['text'];
38         $i ++;
39       }
41       /* Check for addresses */
42       if($node['class'] == "tag" && $node['text'] == ":addresses") {
43         $this->addresses = array();
44         $i ++;
46         /* Multiple or single address given */
47         if($data['ELEMENTS'][$i]['class'] == "left-bracket"){
48           while($data['ELEMENTS'][$i]['class'] != "right-bracket" && ($i < count($data['ELEMENTS']))){
49             $i ++;
50             if($data['ELEMENTS'][$i]['class'] == "quoted-string"){
51               $this->addresses[] = preg_replace("/\"/i","",$data['ELEMENTS'][$i]['text']);
52             }
53           }
54         }else{
55                $this->addresses[] = $data['ELEMENTS'][$i]['text'] ;
56         }
57       }
59       /* Add the vacation message */
60       if($node['class'] == "quoted-string"){
61         $this->reason = $node['text'];
62       }
63     }
64   }
66   function get_sieve_script_part()
67   {
68     $str = "vacation ";
69     if($this->days){
70       $str.= ":days ".$this->days;
71     }
72     $str .= ":addresses ".sieve_create_strings($this->addresses);
73     if($this->subject){
74       $str.= ":subject ".sieve_create_strings($this->subject);
75     }
76     if($this->mime){
77       $str.= ":mime ".sieve_create_strings($this->mime);
78     }
79     $str .= "\n ".sieve_create_strings($this->reason);
80     return($str." ; \n");
81   }
83   function save_object()
84   {
85     /* Get release date */
86     if(isset($_POST['vacation_release_'.$this->object_id])){
87       $this->days = $_POST['vacation_release_'.$this->object_id];
88     }
90     /* Check if we want to toggle the expert mode */
91     if(isset($_POST['Toggle_Expert_'.$this->object_id])){
92       $this->Expert = !$this->Expert;
93     }
95     /* Get release date */
96     if(isset($_POST['vacation_receiver_'.$this->object_id])){
97       $vr = stripslashes ($_POST['vacation_receiver_'.$this->object_id]);
98       $tmp = array();
99       $tmp2 = split(",",$vr);
100       foreach($tmp2 as $val){
101         $tmp[] = "\"".trim(preg_replace("/\"/","",$val))."\"";
102       }
103       $this->addresses = $tmp;
104     }
106     /* Get reason */
107     if(isset($_POST['vacation_reason_'.$this->object_id])){
108       $vr = stripslashes ($_POST['vacation_reason_'.$this->object_id]);
109       $this->reason = "\"".trim(preg_replace("/\"/","",$vr))."\"";
110     }
111   }
113   function check()
114   {
115     return(array())  ;
116   }
118   function execute()
119   {
120     $Addresses = "";
121     foreach($this->addresses as $key){
122       $Addresses .= $key.", ";
123     }
124     $Addresses = preg_replace("/,$/","",trim($Addresses));
126     $smarty = get_smarty();
127     $smarty->assign("Reason",$this->reason);
128     $smarty->assign("Addresses",$Addresses);
129     $smarty->assign("Subject",$this->subject);
130     $smarty->assign("Days",$this->days);
131     $smarty->assign("ID",$this->object_id);
132     $smarty->assign("Expert",$this->Expert);
134     $object_container = $smarty->fetch(get_template_path("templates/object_container.tpl",TRUE,dirname(__FILE__)));
135     $object= $smarty->fetch(get_template_path("templates/element_vacation.tpl",TRUE,dirname(__FILE__)));
136     $str = preg_replace("/%%OBJECT_CONTENT%%/",$object,$object_container);
137     return($str);
138   }
141 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
142 ?>