Code

Added some checks
[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   function save_object()
22   {
23     /* Get the values should check for, they are seperated by , */
24     if(isset($_POST['require_'.$this->object_id])){
25       $vls = stripslashes($_POST['require_'.$this->object_id]);
26       $tmp = array();
28       $tmp2 = split(",",$vls);
29       foreach($tmp2 as $val){
30         
31         $val = trim(preg_replace("/\"/","",$val));
32     
33         if(empty($val)) continue;        
34   
35         $tmp[] = "\"".$val."\"";
36       }
37       $this->data = $tmp;
38     }
39   }
41   function check()
42   {
43     $msgs = array();
44   
45     if(!count($this->data)){
46       $msgs[] = _("Please specify at least one valid requirement.");
47     }
48     return($msgs);
49   }
51   function get_sieve_script_part()
52   {
53     $tmp = sieve_create_strings($this->data);
54     return("require ".$tmp.";\n");
55   } 
56     
57   function execute()
58   {
59     $Require = "";
60     foreach($this->data as $key){
61       $Require .= $key.", ";
62     }
63     $Require = preg_replace("/,$/","",trim($Require));
65     $smarty = get_smarty();
66     $smarty->assign("Require",$Require);
67     $tmp = $this->check();
68     $smarty->assign("LastError",$tmp);
69     $smarty->assign("LastErrorCnt",count($tmp));
70     $smarty->assign("ID", $this->object_id);
71     $object_container = $smarty->fetch(get_template_path("templates/object_container.tpl",TRUE,dirname(__FILE__)));
72     $object= $smarty->fetch(get_template_path("templates/element_require.tpl",TRUE,dirname(__FILE__)));
73     $str = preg_replace("/%%OBJECT_CONTENT%%/",$object,$object_container);
74     return($str);
75   }
76 }
77 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
78 ?>