1 <?php
3 class sieve_require
4 {
5 var $data = array();
6 var $object_id = -1;
7 var $parent = NULL;
9 function sieve_require($data,$object_id,$parent)
10 {
11 $this->parent = $parent;
12 $this->object_id = $object_id;
13 if($data != NULL){
15 for($i = 0 ; $i < count($data['ELEMENTS']) ; $i++){
16 $tmp = sieve_get_strings($data['ELEMENTS'],$i);
17 $i = $i + $tmp['OFFSET'];
18 foreach($tmp['STRINGS'] as $str){
19 $this->data[]= $str;
20 }
21 }
22 }
23 }
26 /* Add a new require statement and ensure
27 * that it is not specified twice
28 */
29 function Add_Require($str)
30 {
31 $current = array();
32 foreach($this->data as $dat){
33 $current[] = $dat;
34 }
35 if(!in_array($str,$current)){
36 $this->data[] = $str;
37 }
38 $this->data = array_unique($this->data);;
39 }
41 function save_object()
42 {
43 /* Get the values should check for, they are seperated by , */
44 if(isset($_POST['require_'.$this->object_id])){
45 $vls = stripslashes($_POST['require_'.$this->object_id]);
46 $tmp = array();
48 $tmp2 = split(",",$vls);
49 foreach($tmp2 as $val){
51 $val = trim($val);
53 if(empty($val)) continue;
55 $tmp[] = $val;
56 }
57 $this->data = $tmp;
58 }
59 }
61 function check()
62 {
63 $msgs = array();
65 if(!count($this->data)){
66 $msgs[] = _("Please specify at least one valid requirement.");
67 }
68 return($msgs);
69 }
71 function get_sieve_script_part()
72 {
73 if(count($this->data)){
74 $tmp = sieve_create_strings($this->data);
75 return("require ".$tmp.";\n");
76 }else{
77 return("");
78 }
79 }
81 function execute()
82 {
83 $Require = "";
84 foreach($this->data as $key){
85 $Require .= $key.", ";
86 }
87 $Require = preg_replace("/,$/","",trim($Require));
89 $smarty = get_smarty();
90 $smarty->assign("Require",$Require);
91 $tmp = $this->check();
92 $smarty->assign("LastError",$tmp);
93 $smarty->assign("LastErrorCnt",count($tmp));
94 $smarty->assign("ID", $this->object_id);
95 $object_container = $smarty->fetch(get_template_path("templates/object_container.tpl",TRUE,dirname(__FILE__)));
96 $object= $smarty->fetch(get_template_path("templates/element_require.tpl",TRUE,dirname(__FILE__)));
97 $str = preg_replace("/%%OBJECT_CONTENT%%/",addcslashes($object,"\\"),$object_container);
98 return($str);
99 }
100 }
101 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
102 ?>