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 foreach($data['ELEMENTS'] as $node ){
16 if(in_array($node['class'],array("quoted-string","text"))){
17 $this->data[] = preg_replace("/\"/","",$node['text']);
18 }
19 }
20 }
21 }
23 /* Add a new require statement and ensure
24 * that it is not specified twice
25 */
26 function Add_Require($str)
27 {
28 $current = array();
30 foreach($this->data as $dat){
31 $current[] = preg_replace("/\"/","",$dat);
32 }
33 if(!in_array($str,$current)){
34 $this->data[] = $str;
35 }
36 $this->data = array_unique($this->data);;
37 }
39 function save_object()
40 {
41 /* Get the values should check for, they are seperated by , */
42 if(isset($_POST['require_'.$this->object_id])){
43 $vls = stripslashes($_POST['require_'.$this->object_id]);
44 $tmp = array();
46 $tmp2 = split(",",$vls);
47 foreach($tmp2 as $val){
49 $val = trim(preg_replace("/\"/","",$val));
51 if(empty($val)) continue;
53 $tmp[] = $val;
54 }
55 $this->data = $tmp;
56 }
57 }
59 function check()
60 {
61 $msgs = array();
63 if(!count($this->data)){
64 $msgs[] = _("Please specify at least one valid requirement.");
65 }
66 return($msgs);
67 }
69 function get_sieve_script_part()
70 {
71 if(count($this->data)){
72 $tmp = sieve_create_strings($this->data);
73 return("require ".$tmp.";\n");
74 }else{
75 return("");
76 }
77 }
79 function execute()
80 {
81 $Require = "";
82 foreach($this->data as $key){
83 $Require .= "\"".$key."\"".", ";
84 }
85 $Require = preg_replace("/,$/","",trim($Require));
87 $smarty = get_smarty();
88 $smarty->assign("Require",$Require);
89 $tmp = $this->check();
90 $smarty->assign("LastError",$tmp);
91 $smarty->assign("LastErrorCnt",count($tmp));
92 $smarty->assign("ID", $this->object_id);
93 $object_container = $smarty->fetch(get_template_path("templates/object_container.tpl",TRUE,dirname(__FILE__)));
94 $object= $smarty->fetch(get_template_path("templates/element_require.tpl",TRUE,dirname(__FILE__)));
95 $str = preg_replace("/%%OBJECT_CONTENT%%/",$object,$object_container);
96 return($str);
97 }
98 }
99 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
100 ?>