Code

Put each class in a single file.
[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     $this->object_id = $object_id;
11     foreach($data['ELEMENTS'] as $node ){
12       if(in_array($node['class'],array("quoted-string","text"))){
13         $this->data[] = preg_replace("/\"/","",$node['text']);
14       }
15     }
16   }
18   function save_object()
19   {
20     /* Get the values should check for, they are seperated by , */
21     if(isset($_POST['require_'.$this->object_id])){
22       $vls = stripslashes($_POST['require_'.$this->object_id]);
23       $tmp = array();
25       $tmp2 = split(",",$vls);
26       foreach($tmp2 as $val){
27         
28         $val = trim(preg_replace("/\"/","",$val));
29     
30         if(empty($val)) continue;        
31   
32         $tmp[] = "\"".$val."\"";
33       }
34       $this->data = $tmp;
35     }
36   }
38   function check()
39   {
40     $msgs = array();
41   
42     if(!count($this->data)){
43       $msgs[] = _("Please specify at least one valid requirement.");
44     }
45     return($msgs);
46   }
48   function get_sieve_script_part()
49   {
50     $tmp = sieve_create_strings($this->data);
51     return("require ".$tmp.";\n");
52   } 
53     
54   function execute()
55   {
56     $Require = "";
57     foreach($this->data as $key){
58       $Require .= $key.", ";
59     }
60     $Require = preg_replace("/,$/","",trim($Require));
62     $smarty = get_smarty();
63     $smarty->assign("Require",$Require);
64     $tmp = $this->check();
65     $smarty->assign("LastError",$tmp);
66     $smarty->assign("LastErrorCnt",count($tmp));
67     $smarty->assign("ID", $this->object_id);
68     $object_container = $smarty->fetch(get_template_path("templates/object_container_clear.tpl",TRUE,dirname(__FILE__)));
69     $object= $smarty->fetch(get_template_path("templates/element_require.tpl",TRUE,dirname(__FILE__)));
70     $str = preg_replace("/%%OBJECT_CONTENT%%/",$object,$object_container);
71     return($str);
72   }
73 }
74 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
75 ?>