1 <?php
3 class sieve_reject
4 {
5 var $data = "";
6 var $object_id = -1;
7 var $parent = NULL;
9 function save_object()
10 {
11 if(isset($_POST['reject_message_'.$this->object_id])){
12 $msg = stripslashes($_POST['reject_message_'.$this->object_id]);
13 $this->data = $msg;
14 }
15 }
17 function check()
18 {
19 $msgs = array();
20 if(preg_match("/\"/",$this->data)){
21 $msgs [] = _("Invalid character found, quotes are not allowed in a reject message.");
22 }
23 return($msgs);
24 }
26 function sieve_reject($data,$object_id,$parent)
27 {
28 $this->object_id = $object_id;
29 $this->parent = $parent;
30 $this->parent->add_require("reject");
32 /* If the given data is emtpy
33 * (This is the case when we add new elements in the ui)
34 * Set a default text.
35 */
36 if($data === NULL){
37 $this->data = _("Your reject text here");
38 }else{
40 for($i = 0 ; $i < count($data['ELEMENTS']) ; $i++){
41 $tmp = sieve_get_strings($data['ELEMENTS'],$i);
42 $i = $i + $tmp['OFFSET'];
43 foreach($tmp['STRINGS'] as $str){
44 $this->data .= $str;
45 }
46 }
47 }
48 }
50 function get_sieve_script_part()
51 {
52 return("reject ".sieve_create_strings($this->data).";");
53 }
55 function execute()
56 {
57 /* check if this will be a
58 * - single string ""
59 * - or a multi line text: ... ;
60 */
61 $Multiline = preg_match("/\n/",$this->data);
63 $smarty = get_smarty();
64 $smarty->assign("ID", $this->object_id);
65 $smarty->assign("Message",$this->data);
66 $smarty->assign("Multiline",$Multiline);
67 $smarty->assign("LastError" , $this->check());
68 $smarty->assign("LastErrorCnt" , count($this->check()));
69 $object_container = $smarty->fetch(get_template_path("templates/object_container.tpl",TRUE,dirname(__FILE__)));
70 $object= $smarty->fetch(get_template_path("templates/element_reject.tpl",TRUE,dirname(__FILE__)));
71 $str = preg_replace("/%%OBJECT_CONTENT%%/",addcslashes($object,"\\"),$object_container);
72 return($str);
73 }
74 }
75 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
76 ?>