Code

Replaced in_array calls with in_array_strict
[gosa.git] / gosa-plugins / mail / personal / mail / sieve / class_sieveElement_Require.inc
1 <?php
3 class sieve_require 
4 {
5   var $data = array();
6   var $object_id = -1;
7   var $parent = NULL;  
8   var $skip_save_object =FALSE;
10   function sieve_require($data,$object_id,$parent)
11   {
12     $this->parent = $parent;
13     $this->object_id = $object_id;
14     if($data !== NULL){
16       for($i = 0 ; $i < count($data['ELEMENTS']) ; $i++){
17         $tmp = sieve_get_strings($data['ELEMENTS'],$i);
18         $i  = $i + $tmp['OFFSET'];
19         foreach($tmp['STRINGS'] as $str){
20           $this->data[]= $str;
21         }
22       }
23     }
24   }
27   /* Add a new require statement and ensure 
28    *  that it is not specified twice 
29    */
30   function Add_Require($str)
31   {
32     $current = array();
33     foreach($this->data as $dat){
34       $current[] = $dat;
35     }
36     if(!in_array_strict($str,$current)){
37       $this->data[] = $str;
38     }
39     $this->data = array_unique($this->data);
40     $this->skip_save_object = TRUE;
41   }
43   function save_object()
44   {
45     if($this->skip_save_object){
46       $this->skip_save_object = FALSE;
47       return;
48     }
50     /* Get the values should check for, they are seperated by , */
51     if(isset($_POST['require_'.$this->object_id])){
52       $vls = stripslashes($_POST['require_'.$this->object_id]);
53       $tmp = array();
55       $tmp2 = explode(",",$vls);
56       foreach($tmp2 as $val){
57         
58         $val = trim($val);
59     
60         if(empty($val)) continue;        
61   
62         $tmp[] = $val;
63       }
64       $this->data = $tmp;
65     }
66   }
68   function check()
69   {
70     $msgs = array();
71   
72     if(!count($this->data)){
73       $msgs[] = _("Please specify at least one valid requirement.");
74     }
75     return($msgs);
76   }
78   function get_sieve_script_part()
79   {
80     if(count($this->data)){
81     $tmp = sieve_create_strings($this->data);
82     return("require ".$tmp.";\n");
83     }else{
84       return("");
85     }
86   } 
87     
88   function execute()
89   {
90     $Require = "";
91     foreach($this->data as $key){
92       $Require .= $key.", ";
93     }
94     $Require = preg_replace("/,$/","",trim($Require));
96     $smarty = get_smarty();
97     $smarty->assign("Require",$Require);
98     $tmp = $this->check();
99     $smarty->assign("LastError",$tmp);
100     $smarty->assign("LastErrorCnt",count($tmp));
101     $smarty->assign("ID", $this->object_id);
102     $object_container = $smarty->fetch(get_template_path("templates/object_container.tpl",TRUE,dirname(__FILE__)));
103     $object= $smarty->fetch(get_template_path("templates/element_require.tpl",TRUE,dirname(__FILE__)));
104     $str = preg_replace("/%%OBJECT_CONTENT%%/",addcslashes($object,"\\"),$object_container);
105     return($str);
106   }
108 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
109 ?>