From: hickert Date: Mon, 19 Mar 2007 08:15:47 +0000 (+0000) Subject: Updated fileinto class. X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=ab3442f7c19920383533ed52d55c88769f9ebaa9;p=gosa.git Updated fileinto class. Some other fixes git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@5810 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/include/sieve/class_My_Parser.inc b/include/sieve/class_My_Parser.inc index 816950e99..912422360 100644 --- a/include/sieve/class_My_Parser.inc +++ b/include/sieve/class_My_Parser.inc @@ -7,6 +7,12 @@ define("SIEVE_INDENT_TAB"," "); */ class My_Parser extends Parser { + var $parent = NULL; + + function My_Parser($parent) + { + $this->parent = $parent; + } function execute() { @@ -29,7 +35,7 @@ class My_Parser extends Parser { $this->status_text = "incomplete"; $this->script_ = $script; - $this->tree_ = new My_Tree(@Scanner::scriptStart()); + $this->tree_ = new My_Tree(@Scanner::scriptStart(),$this); $this->tree_->setDumpFunc(array(&$this, 'dumpToken_')); $this->scanner_ = new Scanner($this->script_); $this->scanner_->setCommentFunc(array($this, 'comment_')); diff --git a/include/sieve/class_My_Tree.inc b/include/sieve/class_My_Tree.inc index f38f3bab8..8792f98f7 100644 --- a/include/sieve/class_My_Tree.inc +++ b/include/sieve/class_My_Tree.inc @@ -15,6 +15,13 @@ class My_Tree extends Tree var $mode_stack = array(); var $pap = array(); + var $parent = NULL; + + function My_Tree(&$root,$parent) + { + $this->parent = $parent; + $this->_construct($root); + } function execute() { @@ -136,7 +143,7 @@ class My_Tree extends Tree $class_name= "sieve_".$type ; if(class_exists($class_name)){ - $this->pap[] = new $class_name($data,$id); + $this->pap[] = new $class_name($data,$id,$this); }else{ echo "Missing : ".$class_name.""."
"; } diff --git a/include/sieve/class_sieveElement_Fileinto.inc b/include/sieve/class_sieveElement_Fileinto.inc index 16b8c26d7..1c1707ef4 100644 --- a/include/sieve/class_sieveElement_Fileinto.inc +++ b/include/sieve/class_sieveElement_Fileinto.inc @@ -5,6 +5,8 @@ class sieve_fileinto var $data = array(); var $object_id= -1; var $options = array(); + var $parent = NULL; + var $user_mode= FALSE; function save_object() { @@ -13,33 +15,56 @@ class sieve_fileinto if(isset($_POST['fileinto_'.$this->object_id])){ $mb = $_POST['fileinto_'.$this->object_id]; - if(isset($mbs[$mb])) { - $this->data[0] = $mb; + + /* Depending on the user mode we only accept + * existing mailboxes + */ + if($this->user_mode){ + $this->data = $mb; + }else{ + if(in_array_ics($mb,$mbs)){ + $this->data = $mb; + } + } + + /* Check Mode */ + if(isset($_POST['user_mode_'.$this->object_id])){ + $this->user_mode = !$this->user_mode; } } } - function sieve_fileinto($data,$object_id) + function sieve_fileinto($data,$object_id,$parent) { $this->object_id = $object_id; + $this->parent = $parent; + $mbs = $this->get_mail_boxes(); + + /* Set the default mailbox */ if($data == NULL){ - $data = array('ELEMENTS' => array(array('class' => "quoted-string" ,"text" => _("")))); + $data = array('ELEMENTS' => array(array('class' => "quoted-string" ,"text" => $mbs[key($mbs)]))); } + /* Set mailbox */ foreach($data['ELEMENTS'] as $node ){ if(in_array($node['class'],array("quoted-string","text"))){ - $this->data[] = preg_replace("/\"/","",$node['text']); + $this->data = preg_replace("/\"/","",$node['text']); } } + + /* Set user mode to active, so we are able to insert + * the destination mail folder manually + */ + if(!in_array_ics($this->data,$mbs)){ + $this->user_mode = TRUE; + } } function get_sieve_script_part() { $tmp = ""; - foreach($this->data as $dat){ - $tmp.= "\"".$dat."\", "; - } + $tmp.= "\"".$this->data."\", "; $tmp = preg_replace("/,$/","",trim($tmp)); $tmp = preg_replace ("/\"\"/","\"",$tmp); return("fileinto ".$tmp.";\n"); @@ -48,8 +73,9 @@ class sieve_fileinto function execute() { $smarty = get_smarty(); - $smarty->assign("Selected",$this->data[0]); + $smarty->assign("Selected",$this->data); $smarty->assign("Boxes", $this->get_mail_boxes()); + $smarty->assign("User_Mode", $this->user_mode); $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_fileinto.tpl",TRUE,dirname(__FILE__))); @@ -65,7 +91,8 @@ class sieve_fileinto function get_mail_boxes() { - return(array("not"=>"not","impplemented/yet"=>"impplemented/yet")); + $list = $this->parent->parent->parent->parent->mailboxList; + return($list); } } diff --git a/include/sieve/class_sieveManagement.inc b/include/sieve/class_sieveManagement.inc index 4f47fbc72..a406403bd 100644 --- a/include/sieve/class_sieveManagement.inc +++ b/include/sieve/class_sieveManagement.inc @@ -93,7 +93,7 @@ class sieveManagement extends plugin /* Get script contents */ foreach($this->scripts as $key => $script){ - $p = new My_Parser; + $p = new My_Parser($this); $this->sieve_handle->sieve_getscript($script['NAME']); $script = ""; @@ -214,7 +214,7 @@ class sieveManagement extends plugin "stop;"; /* Create a new parser and initialize default values */ - $p = new My_Parser; + $p = new My_Parser($this); $ret = $p->parse($script); $sc['SCRIPT'] = $script; $sc['ORIG_SCRIPT'] = $script; @@ -370,7 +370,7 @@ class sieveManagement extends plugin if(!count($chk)){ $sc = $this->scripts[$this->current_script]['SCRIPT']; - $p = new My_Parser; + $p = new My_Parser($this); if($p -> parse($sc)){ if($this->scripts[$this->current_script]['MODE'] == "Source-Only"){ @@ -526,21 +526,23 @@ class sieveManagement extends plugin $this->add_new_id = $this->current_handler->tree_->pap[$next_free]->object_id; } + $parent = $this->current_handler->tree_; + /* Create elements we should add */ if($this->add_element_type == "sieve_if"){ - $ele[] = new $this->add_element_type(NULL, preg_replace("/[^0-9]/","",microtime())); - $ele[] = new sieve_block_start(NULL,preg_replace("/[^0-9]/","",microtime())); - $ele[] = new sieve_block_end(NULL,preg_replace("/[^0-9]/","",microtime())); + $ele[] = new $this->add_element_type(NULL, preg_replace("/[^0-9]/","",microtime()),$parent); + $ele[] = new sieve_block_start(NULL,preg_replace("/[^0-9]/","",microtime()),$parent); + $ele[] = new sieve_block_end(NULL,preg_replace("/[^0-9]/","",microtime()),$parent); }elseif($this->add_element_type == "sieve_else"){ - $ele[] = new sieve_block_end(NULL,preg_replace("/[^0-9]/","",microtime())); - $ele[] = new $this->add_element_type(NULL, preg_replace("/[^0-9]/","",microtime())); - $ele[] = new sieve_block_start(NULL,preg_replace("/[^0-9]/","",microtime())); + $ele[] = new sieve_block_end(NULL,preg_replace("/[^0-9]/","",microtime()),$parent); + $ele[] = new $this->add_element_type(NULL, preg_replace("/[^0-9]/","",microtime()),$parent); + $ele[] = new sieve_block_start(NULL,preg_replace("/[^0-9]/","",microtime()),$parent); }elseif($this->add_element_type == "sieve_elsif"){ - $ele[] = new sieve_block_end(NULL,preg_replace("/[^0-9]/","",microtime())); - $ele[] = new $this->add_element_type(NULL, preg_replace("/[^0-9]/","",microtime())); - $ele[] = new sieve_block_start(NULL,preg_replace("/[^0-9]/","",microtime())); + $ele[] = new sieve_block_end(NULL,preg_replace("/[^0-9]/","",microtime()),$parent); + $ele[] = new $this->add_element_type(NULL, preg_replace("/[^0-9]/","",microtime()),$parent); + $ele[] = new sieve_block_start(NULL,preg_replace("/[^0-9]/","",microtime()),$parent); }else{ - $ele[] = new $this->add_element_type(NULL, preg_replace("/[^0-9]/","",microtime())); + $ele[] = new $this->add_element_type(NULL, preg_replace("/[^0-9]/","",microtime()),$parent); } $start = $end = array(); @@ -764,7 +766,7 @@ class sieveManagement extends plugin if(isset($_POST['script_contents'])){ $sc = stripslashes($_POST['script_contents']); $this->scripts[$this->current_script]['SCRIPT'] = $sc; - $p = new My_Parser; + $p = new My_Parser($this); if($p -> parse($sc)){ $this->Script_Error = ""; } else { @@ -776,7 +778,7 @@ class sieveManagement extends plugin if(in_array($Mode,array("Structured"))){ $sc = $this->current_handler->get_sieve_script(); $this->scripts[$this->current_script]['SCRIPT'] = $sc; - $p = new My_Parser; + $p = new My_Parser($this); if($p -> parse($sc)){ $this->Script_Error = ""; } else { @@ -798,7 +800,7 @@ class sieveManagement extends plugin if($old_mode != $new_mode){ $sc = $this->scripts[$this->current_script]['SCRIPT']; - $p = new My_Parser; + $p = new My_Parser($this); if($p -> parse($sc)){ $this->current_handler->parse($sc); diff --git a/include/sieve/class_tree.inc b/include/sieve/class_tree.inc index 96bc7a822..920b809ce 100644 --- a/include/sieve/class_tree.inc +++ b/include/sieve/class_tree.inc @@ -172,4 +172,4 @@ class Tree } } -?> \ No newline at end of file +?> diff --git a/include/sieve/templates/element_fileinto.tpl b/include/sieve/templates/element_fileinto.tpl index b73dc5a03..977fa37b9 100644 --- a/include/sieve/templates/element_fileinto.tpl +++ b/include/sieve/templates/element_fileinto.tpl @@ -1,10 +1,26 @@ - +
- + + + +
+ {t}Move mail into folder{/t} - + + {if $User_Mode} + + {else} + + {/if} +
+ {t}Folder{/t} + {if $User_Mode} + + {else} + + {/if}