fac16e2969e38c12667bae0b95dc9b7ec72eab89
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 $tmp = sieve_create_strings($this->data);
72 return("require ".$tmp.";\n");
73 }
75 function execute()
76 {
77 $Require = "";
78 foreach($this->data as $key){
79 $Require .= "\"".$key."\"".", ";
80 }
81 $Require = preg_replace("/,$/","",trim($Require));
83 $smarty = get_smarty();
84 $smarty->assign("Require",$Require);
85 $tmp = $this->check();
86 $smarty->assign("LastError",$tmp);
87 $smarty->assign("LastErrorCnt",count($tmp));
88 $smarty->assign("ID", $this->object_id);
89 $object_container = $smarty->fetch(get_template_path("templates/object_container.tpl",TRUE,dirname(__FILE__)));
90 $object= $smarty->fetch(get_template_path("templates/element_require.tpl",TRUE,dirname(__FILE__)));
91 $str = preg_replace("/%%OBJECT_CONTENT%%/",$object,$object_container);
92 return($str);
93 }
94 }
95 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
96 ?>