1 <?php
2 /*
3 This code is part of GOsa (https://gosa.gonicus.de)
4 Copyright (C) 2003-2007 - Fabian Hickert <hickert@gonicus.de>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
22 /* The sieve management class displays a list of sieve
23 * scripts for the given mail account.
24 * The account is identified by the parents uid attribute.
25 *
26 * $config The config object
27 * $dn The object edited
28 * $parent The parent object that provides the uid attribute
29 */
30 class sieveManagement extends plugin
31 {
32 var $parent = NULL;
33 var $scripts= array();
35 var $current_script = -1;
36 var $current_handler = NULL;
37 var $script_to_delete =-1;
38 var $sieve_handle = NULL;
39 var $Script_Error = "";
40 var $Sieve_Error = "";
41 var $create_script = FALSE;
43 /* To add new elements we need to know
44 * Where to the element -> add_new_id
45 * Whould we add above or below this id -> add_above_below
46 * What kind of element should we add -> add_element_type
47 */
48 var $add_new_element = FALSE;
49 var $add_new_id = -1;
50 var $add_above_below = "below";
51 var $add_element_type = "sieve_comment";
53 /* If this variable is TRUE, this indicates that we have the
54 * import dialog opened.
55 */
56 var $Import_Script = FALSE;
58 /* Initialize the class and load all sieve scripts
59 * try to parse them and display errors
60 */
61 function sieveManagement($config,$dn,$parent)
62 {
63 $this->parent = $parent;
64 plugin::plugin($config,$dn);
66 /* Get sieve */
67 if(!$sieve = $this->get_sieve()){
68 print_red(
69 sprintf(
70 _("Can't log into SIEVE server. Server says '%s'."),
71 to_string($this->Sieve_Error)));
72 return;
73 }
76 /* Get all sieve scripts names */
77 if($sieve->sieve_listscripts()){
78 if (is_array($sieve->response)){
79 foreach($sieve->response as $key => $name){
81 $data = array();
82 $data['NAME'] = $name;
84 if($key == "ACTIVE" && $key === "ACTIVE"){
85 $data['ACTIVE'] = TRUE;
86 }else{
87 $data['ACTIVE'] = FALSE;
88 }
89 $this->scripts[] = $data;
90 }
91 }
92 }
94 /* Get script contents */
95 foreach($this->scripts as $key => $script){
96 $p = new My_Parser;
97 $sieve->sieve_getscript($script['NAME']);
99 $script = "";
100 foreach($sieve->response as $line){
101 $script.=$line;
102 }
104 $this->scripts[$key]['IS_NEW'] = FALSE;;
105 $this->scripts[$key]['SCRIPT'] = $script;
106 $this->scripts[$key]['ORIG_SCRIPT'] = $script;
107 $this->scripts[$key]['MSG'] = "";
108 $ret = $p->parse($script);
109 if(!$ret){
110 $this->scripts[$key]['STATUS'] = FALSE;
111 $this->scripts[$key]['MODE'] = "Source";
112 $this->scripts[$key]['MSG'] = _("Parse failed")."<font color='red'>".$p->status_text."</font>";
113 }else{
114 $this->scripts[$key]['STATUS'] = TRUE;
115 $this->scripts[$key]['MODE'] = "Structured";
116 $this->scripts[$key]['MSG'] = _("Parse successful");
117 }
118 $this->scripts[$key]['PARSER'] = $p;
119 $this->scripts[$key]['EDITED'] = FALSE;
120 }
121 $this->sieve_handle = $sieve;
122 }
125 /* Return a sieve class hanlde,
126 * false if login fails
127 */
128 function get_sieve()
129 {
130 /* Connect to sieve class and try to get all available sieve scripts */
131 $cfg= $this->config->data['SERVERS']['IMAP'][$this->parent->gosaMailServer];
132 $this->Sieve_Error = "";
134 /* Log into the mail server */
135 $sieve= new sieve(
136 $cfg["sieve_server"],
137 $cfg["sieve_port"],
138 $this->parent->uid,
139 $cfg["password"],
140 $cfg["admin"]);
142 /* Try to login */
143 if (!$sieve->sieve_login()){
144 $this->Sieve_Error = $sieve->error_raw;
145 return(FALSE);
146 }
147 return($sieve);
148 }
151 /* Handle sieve list
152 */
153 function execute()
154 {
155 /***************
156 * Create a new Script
157 ***************/
159 /* Force opening the add script dialog */
160 if(isset($_POST['create_new_script'])){
161 $this->create_script = TRUE;
162 }
164 /* Close add script dialog, without adding a new one */
165 if(isset($_POST['create_script_cancel'])){
166 $this->create_script = FALSE;
167 }
169 /* Display create script dialog
170 * handle posts, display warnings if specified
171 * name is not useable.
172 * Create a new script with given name
173 */
174 if($this->create_script){
176 /* Set initial name or used posted name if available */
177 $name = "";
178 if(isset($_POST['NewScriptName'])){
179 $name = trim($_POST['NewScriptName']);
180 }
182 /* Check given name */
183 $err = "";
185 /* Is given name in lower case characters ? */
186 if(isset($_POST['create_script_save'])){
187 if(!strlen($name)){
188 $err = _("You should specify a name for your new script.");
189 }
190 /* Is given name in lower case characters ? */
191 if($name != strtolower($name)){
192 $err = _("Only lower case names are allowed here.");
193 }
195 /* Only chars are allowed here */
196 if(preg_match("/[^a-z]/i",$name)){
197 $err = _("Only a-z are allowed in script names.");
198 }
199 }
201 /* Create script if everything is ok */
202 if($this->create_script && isset($_POST['create_script_save']) && $err == "" ){
204 /* Close dialog */
205 $this->create_script = FALSE;
207 /* Script contents to use */
208 $script = "/*New script */".
209 "stop;";
211 /* Create a new parser and initialize default values */
212 $p = new My_Parser;
213 $ret = $p->parse($script);
214 $sc['SCRIPT'] = $script;
215 $sc['ORIG_SCRIPT'] = $script;
216 $sc['IS_NEW'] = TRUE;
217 $sc['MSG'] = "";
218 if(!$ret){
219 $sc['STATUS'] = FALSE;
220 $sc['MODE'] = "Source-Only";
221 $sc['MSG'] = _("Parse failed")."<font color='red'>".$p->status_text."</font>";
222 }else{
223 $sc['STATUS'] = TRUE;
224 $sc['MODE'] = "Strucktured";
225 $sc['MSG'] = _("Parse successful");
226 }
227 $sc['PARSER'] = $p;
228 $sc['EDITED'] = TRUE;
229 $sc['ACTIVE'] = FALSE;
230 $sc['NAME'] = $name;
232 /* Add script */
233 $this->scripts[$name] = $sc;
234 }else{
236 /* Display dialog to enter new script name */
237 $smarty = get_smarty();
238 $smarty->assign("NewScriptName",$name);
239 $smarty->assign("Error",$err);
240 return($smarty->fetch(get_template_path("templates/create_script.tpl",TRUE,dirname(__FILE__))));
241 }
242 }
245 /*************
246 * Handle several posts
247 *************/
249 $once = TRUE;
250 foreach($_POST as $name => $value){
252 /* Edit script requested */
253 if(preg_match("/^editscript_/",$name) && $once && !$this->current_handler){
254 $script = preg_replace("/^editscript_/","",$name);
255 $script = preg_replace("/_(x|y)/","",$script);
256 $once = FALSE;
258 $this->current_script = $script;
259 $this->current_handler = $this->scripts[$script]['PARSER'];
260 }
262 /* remove script requested */
263 if(preg_match("/^delscript_/",$name) && $once && !$this->current_handler){
264 $script = preg_replace("/^delscript_/","",$name);
265 $script = preg_replace("/_(x|y)/","",$script);
266 $once = FALSE;
268 $this->script_to_delete = $script;
269 }
271 /* Activate script */
272 if(preg_match("/^active_script_/",$name) && $once && !$this->current_handler){
273 $script = preg_replace("/^active_script_/","",$name);
274 $script = preg_replace("/_(x|y)/","",$script);
275 $once = FALSE;
277 /* Get sieve */
278 if(!$sieve = $this->get_sieve()){
279 print_red(
280 sprintf(
281 _("Can't log into SIEVE server. Server says '%s'."),
282 to_string($this->Sieve_Error)));
283 }
285 /* Try to activate the given script and update
286 * class script array.
287 */
288 if(!$sieve->sieve_setactivescript($this->scripts[$script]['NAME'])){
289 print_red(sprintf(_("Can't activate sieve script on server. Server says '%s'."),to_string($sieve->error_raw)));
290 }else{
291 foreach($this->scripts as $key => $data){
292 if($key == $script){
293 $this->scripts[$key]['ACTIVE'] = TRUE;
294 }else{
295 $this->scripts[$key]['ACTIVE'] = FALSE;
296 }
297 }
298 }
299 }
300 }
303 /*************
304 * Remove script handling
305 *************/
307 /* Remove aborted */
308 if(isset($_POST['delete_cancel'])){
309 $this->script_to_delete = -1;
310 }
312 /* Remove confirmed */
313 if(isset($_POST['delete_script_confirm'])){
315 $script = $this->scripts[$this->script_to_delete];
317 /* Just remove from array if it is a new script */
318 if($script['IS_NEW']){
319 unset($this->scripts[$this->script_to_delete]);
320 }else{
322 /* Get sieve */
323 if(!$sieve = $this->get_sieve()){
324 print_red(
325 sprintf(
326 _("Can't log into SIEVE server. Server says '%s'."),
327 to_string($this->Sieve_Error)));
328 }
330 if(!$sieve->sieve_deletescript($this->scripts[$this->script_to_delete]['NAME'])){
331 print_red(sprintf(_("Can't remove sieve script from server. Server says '%s'."),to_string($sieve->error_raw)));
332 }else{
333 unset($this->scripts[$this->script_to_delete]);
334 }
335 }
336 $this->script_to_delete = -1;
337 }
339 /* Display confirm dialog */
340 if($this->script_to_delete != -1){
341 $smarty = get_smarty();
342 $smarty->assign("Warning",
343 sprintf(_("You are going to remove the sieve script '%s' from your mail server."),
344 $this->scripts[$this->script_to_delete]['NAME']));
345 return($smarty->fetch(get_template_path("templates/remove_script.tpl",TRUE,dirname(__FILE__))));
346 }
349 /**************
350 * Save script changes
351 **************/
353 /* Abort saving */
354 if(isset($_POST['cancel_sieve_changes'])){
355 $this->current_handler = NULL;
356 }
358 /* Save currently edited sieve script. */
359 if(isset($_POST['save_sieve_changes'])){
360 $chk = $this->current_handler->check();
361 if(!count($chk)){
363 $sc = $this->scripts[$this->current_script]['SCRIPT'];
364 $p = new My_Parser;
365 if($p -> parse($sc)){
367 if($this->scripts[$this->current_script]['MODE'] == "Source-Only"){
368 $this->scripts[$this->current_script]['MODE'] = "Source";
369 }
371 $this->scripts[$this->current_script]['PARSER'] = $p;
372 $this->scripts[$this->current_script]['EDITED'] = TRUE;
373 $this->scripts[$this->current_script]['STATUS'] = TRUE;
374 $this->scripts[$this->current_script]['MSG'] = _("Edited");
375 $this->current_handler = NULL;
376 }else{
377 print_red($p->status_text);;
378 }
379 }else{
380 print_red(_("Please fix all errors before saving."));
381 }
382 }
385 /*************
386 * Display edit dialog
387 *************/
389 /* Display edit dialog, depending on Mode display different uis
390 */
391 if($this->current_handler){
393 if(isset($_POST['Import_Script'])){
394 $this->Import_Script = TRUE;
395 }
397 if(isset($_POST['Import_Script_Cancel'])){
398 $this->Import_Script = FALSE;
399 }
401 if(isset($_POST['Import_Script_Save']) && isset($_FILES['Script_To_Import'])){
403 $file = $_FILES['Script_To_Import'];
405 if($file['size'] == 0){
406 print_red(_("Specified file seams to empty."));
407 }elseif(!file_exists($file['tmp_name'])){
408 print_red(_("Upload failed, somehow nothing was uploaded or the temporary file can't be accessed."));
409 }elseif(!is_readable ($file['tmp_name'])){
410 print_red(sprintf(_("Can't open file '%s' to read uploaded file contents."),$file['tmp_name']));
411 }else{
415 $contents = file_get_contents($file['tmp_name']);
417 $this->scripts[$this->current_script]['SCRIPT'] = $contents;
418 if(!$this->current_handler->parse($contents)){
419 $this->scripts[$this->current_script]['MODE'] = "Source";
420 }else{
421 $this->scripts[$this->current_script]['MODE'] = "Structured";
422 }
423 $this->Import_Script = FALSE;
424 }
425 }
427 if($this->Import_Script){
428 $smarty = get_smarty();
429 $str = $smarty->fetch(get_template_path("templates/import_script.tpl",TRUE,dirname(__FILE__)));
430 return($str);
431 }
434 /* Create dump of current sieve script */
435 if(isset($_POST['Save_Copy'])){
437 /* force download dialog */
438 header("Content-type: application/tiff\n");
439 if (preg_match('/MSIE 5.5/', $HTTP_USER_AGENT) ||
440 preg_match('/MSIE 6.0/', $HTTP_USER_AGENT)) {
441 header('Content-Disposition: filename="dump.script"');
442 } else {
443 header('Content-Disposition: attachment; filename="dump.script"');
444 }
445 header("Content-transfer-encoding: binary\n");
446 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
447 header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
448 header("Cache-Control: no-cache");
449 header("Pragma: no-cache");
450 header("Cache-Control: post-check=0, pre-check=0");
451 echo $this->scripts[$this->current_script]['SCRIPT'];
452 exit();
453 }
456 /****
457 * Add new element to ui
458 ****/
460 /* Abort add dialog */
461 if(isset($_POST['select_new_element_type_cancel'])){
462 $this->add_new_element = FALSE;
463 }
465 /* Add a new element */
466 if($this->add_new_element){
468 $element_types= array(
469 "sieve_keep" => _("Keep"),
470 "sieve_comment" => _("Comment"),
471 "sieve_fileinto" => _("File into"),
472 "sieve_keep" => _("Keep"),
473 "sieve_discard" => _("Discard"),
474 "sieve_redirect" => _("Redirect"),
475 "sieve_reject" => _("Reject"),
476 "sieve_require" => _("Require"),
477 "sieve_stop" => _("Stop"),
478 "sieve_vacation" => _("Vacation message"),
479 "sieve_if" => _("If"));
482 /* Element selected */
483 if(isset($_POST['element_type']) && isset($element_types[$_POST['element_type']])
484 || isset($_POST['element_type']) &&in_array($_POST['element_type'],array("sieve_else","sieve_elsif"))){
485 $this->add_element_type = $_POST['element_type'];
486 }
488 /* Create new element and add it to
489 * the selected position
490 */
491 if(isset($_POST['select_new_element_type'])){
493 $this->add_new_id;
494 $data = $this->current_handler->tree_->pap;
496 /* Get index of the element identified by object_id == $this->add_new_id; */
497 $index = -1;
498 foreach($data as $key => $obj){
499 if($obj->object_id == $this->add_new_id && $index==-1){
500 $index = $key;
501 }
502 }
504 /* We have found the specified object_id
505 * and want to detect the next free position
506 * to insert the new element.
507 */
508 if($index != -1){
509 if($this->add_above_below == "above"){
510 $direction ="up";
511 $next_free = $this->current_handler->tree_->_get_next_free_move_slot($index,$direction);
512 $next_free ++;
513 }else{
514 $direction = "down";
515 $next_free = $this->current_handler->tree_->_get_next_free_move_slot($index,$direction);
516 }
517 $this->add_new_id = $this->current_handler->tree_->pap[$next_free]->object_id;
518 }
520 /* Create elements we should add */
521 if($this->add_element_type == "sieve_if"){
522 $ele[] = new $this->add_element_type(NULL, preg_replace("/[^0-9]/","",microtime()));
523 $ele[] = new sieve_block_start(NULL,preg_replace("/[^0-9]/","",microtime()));
524 $ele[] = new sieve_block_end(NULL,preg_replace("/[^0-9]/","",microtime()));
525 }elseif($this->add_element_type == "sieve_else"){
526 $ele[] = new sieve_block_end(NULL,preg_replace("/[^0-9]/","",microtime()));
527 $ele[] = new $this->add_element_type(NULL, preg_replace("/[^0-9]/","",microtime()));
528 $ele[] = new sieve_block_start(NULL,preg_replace("/[^0-9]/","",microtime()));
529 }elseif($this->add_element_type == "sieve_elsif"){
530 $ele[] = new sieve_block_end(NULL,preg_replace("/[^0-9]/","",microtime()));
531 $ele[] = new $this->add_element_type(NULL, preg_replace("/[^0-9]/","",microtime()));
532 $ele[] = new sieve_block_start(NULL,preg_replace("/[^0-9]/","",microtime()));
533 }else{
534 $ele[] = new $this->add_element_type(NULL, preg_replace("/[^0-9]/","",microtime()));
535 }
537 $start = $end = array();
538 $found = false;
540 /* Add above current element*/
541 if($this->add_above_below == "above"){
542 foreach($data as $key => $obj){
543 if($obj->object_id == $this->add_new_id){
544 $found = true;
545 }
546 if(!$found){
547 $start[] = $obj;
548 }else{
549 $end[] = $obj;
550 }
551 }
552 }else{
553 /* Add below current element */
554 foreach($data as $key => $obj){
555 if(!$found){
556 $start[] = $obj;
557 }else{
558 $end[] = $obj;
559 }
560 if($obj->object_id == $this->add_new_id){
561 $found = true;
562 }
563 }
564 }
567 /* Only add, if current element could be located */
568 if($found){
569 $new = array();
570 foreach($start as $obj){
571 $new[] = $obj;
572 }
573 foreach($ele as $el){
574 $new[] = $el;
575 }
576 foreach($end as $obj){
577 $new[] = $obj;
578 }
579 $data= $new;
580 $this->current_handler->tree_->pap = $data;
581 $this->add_new_element = FALSE;
582 }else{
583 print_red(_("Something went wrong while adding a new entry."));
584 }
585 }
586 }
588 /* Only display select dialog if it is necessary */
589 if($this->add_new_element){
590 $smarty = get_smarty();
592 $add_else_elsif = FALSE;
593 foreach($this->current_handler->tree_->pap as $obj){
594 if($obj->object_id == $this->add_new_id && in_array(get_class($obj),array("sieve_if","sieve_elsif"))){
595 $add_else_elsif = TRUE;
596 }
597 }
599 if($add_else_elsif && $this->add_above_below == "below"){
600 $element_types['sieve_else'] = _("Else");
601 $element_types['sieve_elsif'] = _("Else if");
602 }
604 $smarty->assign("element_types",$element_types );
605 $smarty->assign("element_type",$this->add_element_type);
606 $str = $smarty->fetch(get_template_path("templates/add_element.tpl",TRUE,dirname(__FILE__)));
607 return($str);
608 }
612 /****************
613 * Handle test posts
614 ****************/
616 /* handle some special posts from test elements
617 */
618 foreach($_POST as $name => $value){
619 if(preg_match("/^Add_Test_Object_/",$name)) {
620 $name = preg_replace("/^Add_Test_Object_/","",$name);
621 $name = preg_replace("/_(x|y)$/","",$name);
623 $test_types_to_add = array(
624 "address" =>_("Address"),
625 "header" =>_("Header"),
626 "envelope"=>_("Envelope"),
627 "size" =>_("Size"),
628 "exists" =>_("Exists"),
629 "allof" =>_("All of"),
630 "anyof" =>_("Any of"),
631 "true" =>_("True"),
632 "false" =>_("False"));
634 $smarty = get_smarty();
635 $smarty->assign("ID",$name);
636 $smarty->assign("test_types_to_add",$test_types_to_add);
637 $ret = $smarty->fetch(get_template_path("templates/select_test_type.tpl",TRUE,dirname(__FILE__)));
638 return($ret);
639 }
640 }
642 $current = $this->scripts[$this->current_script];
644 /* Create html results */
645 $smarty = get_smarty();
646 $smarty->assign("Mode",$current['MODE']);
647 if($current['MODE'] == "Structured"){
648 $smarty->assign("Contents",$this->current_handler->tree_->execute());
649 }else{
650 $smarty->assign("Contents",$current['SCRIPT']);
651 }
652 $smarty->assign("Script_Error",$this->Script_Error);
653 $ret = $smarty->fetch(get_template_path("templates/edit_frame_base.tpl",TRUE,dirname(__FILE__)));
654 return($ret);
655 }
658 /* Create list of available sieve scripts
659 */
660 $List = new divSelectBox("sieveManagement");
661 foreach($this->scripts as $key => $script){
663 $edited = $script['EDITED'];
664 $active = $script['ACTIVE'];
666 $field1 = array("string" => " ",
667 "attach" => "style='width:20px;'");
668 if($active){
669 $field1 = array("string" => "<img src='images/true.png' alt='"._("Active")."'>",
670 "attach" => "style='width:20px;'");
671 }
672 $field2 = array("string" => $script['NAME']);
673 $field3 = array("string" => $script['MSG']);
674 $field4 = array("string" => _("Script length")." : ".strlen($script['SCRIPT']));
676 if($edited){
677 $field5 = array("string" => "<img src='images/fai_new_hook.png' alt='"._("Edited")."'>",
678 "attach" => "style='width:30px;'");
679 }else{
680 $field5 = array("string" => "",
681 "attach" => "style='width:30px;'");
682 }
684 if($active){
685 $field6 = array("string" => "<img src='images/empty.png' alt=' '>".
686 "<input type='image' name='editscript_".$key."' src='images/edit.png'>".
687 "<input type='image' name='delscript_".$key."' src='images/edittrash.png'>");
688 }else{
689 $field6 = array("string" => "<input type='image' name='active_script_".$key."' src='images/true.png'>".
690 "<input type='image' name='editscript_".$key."' src='images/edit.png'>".
691 "<input type='image' name='delscript_".$key."' src='images/edittrash.png'>");
692 }
693 $List ->AddEntry(array($field1,$field2,$field3,$field4,$field5,$field6));
694 }
696 $display ="<h2>Sieve script management</h2>";
697 $display .= _("Be careful. All your changes will be saved directly to sieve, if you use the save button below.");
698 $display .= "<br><input type='submit' name='create_new_script' value='"._("Create new script")."'>";
699 $display .= $List->DrawList();
701 $display .= "<p style=\"text-align:right\">\n";
702 $display .= "<input type=submit name=\"sieve_finish\" style=\"width:80px\" value=\""._("Ok")."\">\n";
703 $display .= " \n";
704 $display .= "<input type=submit name=\"sieve_cancel\" value=\""._("Cancel")."\">\n";
705 $display .= "</p>";
706 return($display);;
707 }
709 function save_object()
710 {
711 if($this->current_handler){
713 /* Check if there is an add object requested
714 */
715 $data = $this->current_handler->tree_->pap;
716 $once = TRUE;
717 foreach($_POST as $name => $value){
718 foreach($data as $key => $obj){
719 if(isset($obj->object_id) && preg_match("/^Add_Object_Top_".$obj->object_id."_/",$name) && $once){
720 $once = FALSE;
721 $this->add_new_element = TRUE;
722 $this->add_new_id = $obj->object_id;
723 $this->add_above_below = "above";
724 }
725 if(isset($obj->object_id) && preg_match("/^Add_Object_Bottom_".$obj->object_id."_/",$name) && $once){
726 $once = FALSE;
727 $this->add_new_element = TRUE;
728 $this->add_new_id = $obj->object_id;
729 $this->add_above_below = "below";
730 }
732 if(isset($obj->object_id) && preg_match("/^Remove_Object_".$obj->object_id."_/",$name) && $once){
733 $once = FALSE;
734 $this->current_handler->tree_->remove_object($key);
735 }
736 if(isset($obj->object_id) && preg_match("/^Move_Up_Object_".$obj->object_id."_/",$name) && $once){
737 $this->current_handler->tree_->move_up_down($key,"up");
738 $once = FALSE;
739 }
740 if(isset($obj->object_id) && preg_match("/^Move_Down_Object_".$obj->object_id."_/",$name) && $once){
741 $this->current_handler->tree_->move_up_down($key,"down");
742 $once = FALSE;
743 }
744 }
745 }
747 /* Skip Mode changes and Parse tests
748 * if we are currently in a subdialog
749 */
751 $this->current_handler->save_object();
752 $Mode = $this->scripts[$this->current_script]['MODE'];
753 $skip_mode_change = false;
754 if(in_array($Mode,array("Source-Only","Source"))){
755 if(isset($_POST['script_contents'])){
756 $sc = stripslashes($_POST['script_contents']);
757 $this->scripts[$this->current_script]['SCRIPT'] = $sc;
758 $p = new My_Parser;
759 if($p -> parse($sc)){
760 $this->Script_Error = "";
761 } else {
762 $this->Script_Error = $p->status_text;
763 $skip_mode_change = TRUE;
764 }
765 }
766 }
767 if(in_array($Mode,array("Structured"))){
768 $sc = $this->current_handler->get_sieve_script();
769 $this->scripts[$this->current_script]['SCRIPT'] = $sc;
770 $p = new My_Parser;
771 if($p -> parse($sc)){
772 $this->Script_Error = "";
773 } else {
774 $this->Script_Error = $p->status_text;
775 $skip_mode_change = TRUE;
776 }
777 }
778 if(!$skip_mode_change){
779 if($this->scripts[$this->current_script]['MODE'] != "Source-Only"){
780 $old_mode = $this->scripts[$this->current_script]['MODE'];
781 if(isset($_POST['View_Source'])){
782 $this->scripts[$this->current_script]['MODE'] = "Source";
783 }
784 if(isset($_POST['View_Structured'])){
785 $this->scripts[$this->current_script]['MODE'] = "Structured";
786 }
787 $new_mode = $this->scripts[$this->current_script]['MODE'];
789 if($old_mode != $new_mode){
791 $sc = $this->scripts[$this->current_script]['SCRIPT'];
792 $p = new My_Parser;
794 if($p -> parse($sc)){
795 $this->current_handler->parse($sc);
796 $this->Script_Error = "";
797 } else {
798 $this->Script_Error = $p->status_text;
799 }
800 }
801 }
802 }
803 }
804 }
807 function save()
808 {
809 /* Get sieve */
810 if(!$sieve = $this->get_sieve()){
811 print_red(
812 sprintf(
813 _("Can't log into SIEVE server. Server says '%s'."),
814 to_string($this->Sieve_Error)));
815 }
817 $everything_went_fine = TRUE;
819 foreach($this->scripts as $key => $script){
820 if($script['EDITED']){
821 $data = $this->scripts[$key]['SCRIPT'];
822 if(!$sieve->sieve_sendscript($script['NAME'], $data)){
823 gosa_log("Failed to save sieve script named '".$script['NAME']."': ".to_string($sieve->error_raw));
824 $everything_went_fine = FALSE;
825 print_red(to_string($sieve->error_raw));
826 $this->scripts[$key]['MSG'] = "<font color='red'>".
827 _("Failed to save sieve script").": ".
828 to_string($sieve->error_raw).
829 "</font>";
830 }
831 }
832 }
833 return($everything_went_fine);
834 }
835 }
836 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
837 ?>