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