Code

Added "relational" to require element when :value :contains is used within address...
[gosa.git] / include / sieve / class_sieveElement_Require.inc
1 <?php
3 class sieve_require 
4 {
5   var $data = array();
6   var $object_id = -1;
7   
8   function sieve_require($data,$object_id)
9   {
10     if($data != NULL){
12       $this->object_id = $object_id;
13       foreach($data['ELEMENTS'] as $node ){
14         if(in_array($node['class'],array("quoted-string","text"))){
15           $this->data[] = preg_replace("/\"/","",$node['text']);
16         }
17       }
18     }
19   }
21   /* Add a new require statement and ensure 
22    *  that it is not specified twice 
23    */
24   function Add_Require($str)
25   {
26     $current = array();
28     foreach($this->data as $dat){
29       $current[] = preg_replace("/\"/","",$dat);
30     }
31     if(!in_array($str,$current)){
32       $this->data[] = $str;
33     }
34     $this->data = array_unique($this->data);;
35   }
37   function save_object()
38   {
39     /* Get the values should check for, they are seperated by , */
40     if(isset($_POST['require_'.$this->object_id])){
41       $vls = stripslashes($_POST['require_'.$this->object_id]);
42       $tmp = array();
44       $tmp2 = split(",",$vls);
45       foreach($tmp2 as $val){
46         
47         $val = trim(preg_replace("/\"/","",$val));
48     
49         if(empty($val)) continue;        
50   
51         $tmp[] = $val;
52       }
53       $this->data = $tmp;
54     }
55   }
57   function check()
58   {
59     $msgs = array();
60   
61     if(!count($this->data)){
62       $msgs[] = _("Please specify at least one valid requirement.");
63     }
64     return($msgs);
65   }
67   function get_sieve_script_part()
68   {
69     $tmp = sieve_create_strings($this->data);
70     return("require ".$tmp.";\n");
71   } 
72     
73   function execute()
74   {
75     $Require = "";
76     foreach($this->data as $key){
77       $Require .= "\"".$key."\"".", ";
78     }
79     $Require = preg_replace("/,$/","",trim($Require));
81     $smarty = get_smarty();
82     $smarty->assign("Require",$Require);
83     $tmp = $this->check();
84     $smarty->assign("LastError",$tmp);
85     $smarty->assign("LastErrorCnt",count($tmp));
86     $smarty->assign("ID", $this->object_id);
87     $object_container = $smarty->fetch(get_template_path("templates/object_container.tpl",TRUE,dirname(__FILE__)));
88     $object= $smarty->fetch(get_template_path("templates/element_require.tpl",TRUE,dirname(__FILE__)));
89     $str = preg_replace("/%%OBJECT_CONTENT%%/",$object,$object_container);
90     return($str);
91   }
92 }
93 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
94 ?>