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(!$this->sieve_handle = $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($this->sieve_handle->sieve_listscripts()){
78 if (is_array($this->sieve_handle->response)){
79 foreach($this->sieve_handle->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 $this->sieve_handle->sieve_getscript($script['NAME']);
99 $script = "";
100 foreach($this->sieve_handle->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 = $this->sieve_handle;
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 $this->sieve_handle= 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 (!$this->sieve_handle->sieve_login()){
144 $this->Sieve_Error = $this->sieve_handle->error_raw;
145 return(FALSE);
146 }
147 return($this->sieve_handle);
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 }
200 $tmp = $this->get_used_script_names();
201 if(in_array_ics($name,$tmp)){
202 $err =_("The specified name is already in use.");
203 }
204 }
206 /* Create script if everything is ok */
207 if($this->create_script && isset($_POST['create_script_save']) && $err == "" ){
209 /* Close dialog */
210 $this->create_script = FALSE;
212 /* Script contents to use */
213 $script = "/*New script */".
214 "stop;";
216 /* Create a new parser and initialize default values */
217 $p = new My_Parser;
218 $ret = $p->parse($script);
219 $sc['SCRIPT'] = $script;
220 $sc['ORIG_SCRIPT'] = $script;
221 $sc['IS_NEW'] = TRUE;
222 $sc['MSG'] = "";
223 if(!$ret){
224 $sc['STATUS'] = FALSE;
225 $sc['MODE'] = "Source-Only";
226 $sc['MSG'] = _("Parse failed")."<font color='red'>".$p->status_text."</font>";
227 }else{
228 $sc['STATUS'] = TRUE;
229 $sc['MODE'] = "Strucktured";
230 $sc['MSG'] = _("Parse successful");
231 }
232 $sc['PARSER'] = $p;
233 $sc['EDITED'] = TRUE;
234 $sc['ACTIVE'] = FALSE;
235 $sc['NAME'] = $name;
237 /* Add script */
238 $this->scripts[$name] = $sc;
239 }else{
241 /* Display dialog to enter new script name */
242 $smarty = get_smarty();
243 $smarty->assign("NewScriptName",$name);
244 $smarty->assign("Error",$err);
245 return($smarty->fetch(get_template_path("templates/create_script.tpl",TRUE,dirname(__FILE__))));
246 }
247 }
250 /*************
251 * Handle several posts
252 *************/
254 $once = TRUE;
255 foreach($_POST as $name => $value){
257 /* Edit script requested */
258 if(preg_match("/^editscript_/",$name) && $once && !$this->current_handler){
259 $script = preg_replace("/^editscript_/","",$name);
260 $script = preg_replace("/_(x|y)/","",$script);
261 $once = FALSE;
263 $this->current_script = $script;
264 $this->current_handler = $this->scripts[$script]['PARSER'];
265 }
267 /* remove script requested */
268 if(preg_match("/^delscript_/",$name) && $once && !$this->current_handler){
269 $script = preg_replace("/^delscript_/","",$name);
270 $script = preg_replace("/_(x|y)/","",$script);
271 $once = FALSE;
273 $this->script_to_delete = $script;
274 }
276 /* Activate script */
277 if(preg_match("/^active_script_/",$name) && $once && !$this->current_handler){
278 $script = preg_replace("/^active_script_/","",$name);
279 $script = preg_replace("/_(x|y)/","",$script);
280 $once = FALSE;
282 /* We can only activate existing scripts */
283 if(!$this->scripts[$script]['IS_NEW']){
285 /* Get sieve */
286 if(!$this->sieve_handle = $this->get_sieve()){
287 print_red(
288 sprintf(
289 _("Can't log into SIEVE server. Server says '%s'."),
290 to_string($this->Sieve_Error)));
291 }
293 /* Try to activate the given script and update
294 * class script array.
295 */
296 if(!$this->sieve_handle->sieve_setactivescript($this->scripts[$script]['NAME'])){
297 print_red(sprintf(_("Can't activate sieve script on server. Server says '%s'."),to_string($this->sieve_handle->error_raw)));
298 }else{
299 foreach($this->scripts as $key => $data){
300 if($key == $script){
301 $this->scripts[$key]['ACTIVE'] = TRUE;
302 }else{
303 $this->scripts[$key]['ACTIVE'] = FALSE;
304 }
305 }
306 }
307 }
308 }
309 }
312 /*************
313 * Remove script handling
314 *************/
316 /* Remove aborted */
317 if(isset($_POST['delete_cancel'])){
318 $this->script_to_delete = -1;
319 }
321 /* Remove confirmed */
322 if(isset($_POST['delete_script_confirm'])){
324 $script = $this->scripts[$this->script_to_delete];
326 /* Just remove from array if it is a new script */
327 if($script['IS_NEW']){
328 unset($this->scripts[$this->script_to_delete]);
329 }else{
331 /* Get sieve */
332 if(!$this->sieve_handle = $this->get_sieve()){
333 print_red(
334 sprintf(
335 _("Can't log into SIEVE server. Server says '%s'."),
336 to_string($this->Sieve_Error)));
337 }
339 if(!$this->sieve_handle->sieve_deletescript($this->scripts[$this->script_to_delete]['NAME'])){
340 print_red(sprintf(_("Can't remove sieve script from server. Server says '%s'."),to_string($this->sieve_handle->error_raw)));
341 }else{
342 unset($this->scripts[$this->script_to_delete]);
343 }
344 }
345 $this->script_to_delete = -1;
346 }
348 /* Display confirm dialog */
349 if($this->script_to_delete != -1){
350 $smarty = get_smarty();
351 $smarty->assign("Warning",
352 sprintf(_("You are going to remove the sieve script '%s' from your mail server."),
353 $this->scripts[$this->script_to_delete]['NAME']));
354 return($smarty->fetch(get_template_path("templates/remove_script.tpl",TRUE,dirname(__FILE__))));
355 }
358 /**************
359 * Save script changes
360 **************/
362 /* Abort saving */
363 if(isset($_POST['cancel_sieve_changes'])){
364 $this->current_handler = NULL;
365 }
367 /* Save currently edited sieve script. */
368 if(isset($_POST['save_sieve_changes'])){
369 $chk = $this->current_handler->check();
370 if(!count($chk)){
372 $sc = $this->scripts[$this->current_script]['SCRIPT'];
373 $p = new My_Parser;
374 if($p -> parse($sc)){
376 if($this->scripts[$this->current_script]['MODE'] == "Source-Only"){
377 $this->scripts[$this->current_script]['MODE'] = "Source";
378 }
380 $this->scripts[$this->current_script]['PARSER'] = $p;
381 $this->scripts[$this->current_script]['EDITED'] = TRUE;
382 $this->scripts[$this->current_script]['STATUS'] = TRUE;
383 $this->scripts[$this->current_script]['MSG'] = _("Edited");
384 $this->current_handler = NULL;
385 }else{
386 print_red($p->status_text);;
387 }
388 }else{
389 print_red(_("Please fix all errors before saving."));
390 }
391 }
394 /*************
395 * Display edit dialog
396 *************/
398 /* Display edit dialog, depending on Mode display different uis
399 */
400 if($this->current_handler){
402 if(isset($_POST['Import_Script'])){
403 $this->Import_Script = TRUE;
404 }
406 if(isset($_POST['Import_Script_Cancel'])){
407 $this->Import_Script = FALSE;
408 }
410 if(isset($_POST['Import_Script_Save']) && isset($_FILES['Script_To_Import'])){
412 $file = $_FILES['Script_To_Import'];
414 if($file['size'] == 0){
415 print_red(_("Specified file seams to empty."));
416 }elseif(!file_exists($file['tmp_name'])){
417 print_red(_("Upload failed, somehow nothing was uploaded or the temporary file can't be accessed."));
418 }elseif(!is_readable ($file['tmp_name'])){
419 print_red(sprintf(_("Can't open file '%s' to read uploaded file contents."),$file['tmp_name']));
420 }else{
424 $contents = file_get_contents($file['tmp_name']);
426 $this->scripts[$this->current_script]['SCRIPT'] = $contents;
427 if(!$this->current_handler->parse($contents)){
428 $this->scripts[$this->current_script]['MODE'] = "Source";
429 }else{
430 $this->scripts[$this->current_script]['MODE'] = "Structured";
431 }
432 $this->Import_Script = FALSE;
433 }
434 }
436 if($this->Import_Script){
437 $smarty = get_smarty();
438 $str = $smarty->fetch(get_template_path("templates/import_script.tpl",TRUE,dirname(__FILE__)));
439 return($str);
440 }
443 /* Create dump of current sieve script */
444 if(isset($_POST['Save_Copy'])){
446 /* force download dialog */
447 header("Content-type: application/tiff\n");
448 if (preg_match('/MSIE 5.5/', $HTTP_USER_AGENT) ||
449 preg_match('/MSIE 6.0/', $HTTP_USER_AGENT)) {
450 header('Content-Disposition: filename="dump.script"');
451 } else {
452 header('Content-Disposition: attachment; filename="dump.script"');
453 }
454 header("Content-transfer-encoding: binary\n");
455 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
456 header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
457 header("Cache-Control: no-cache");
458 header("Pragma: no-cache");
459 header("Cache-Control: post-check=0, pre-check=0");
460 echo $this->scripts[$this->current_script]['SCRIPT'];
461 exit();
462 }
465 /****
466 * Add new element to ui
467 ****/
469 /* Abort add dialog */
470 if(isset($_POST['select_new_element_type_cancel'])){
471 $this->add_new_element = FALSE;
472 }
474 /* Add a new element */
475 if($this->add_new_element){
477 $element_types= array(
478 "sieve_keep" => _("Keep"),
479 "sieve_comment" => _("Comment"),
480 "sieve_fileinto" => _("File into"),
481 "sieve_keep" => _("Keep"),
482 "sieve_discard" => _("Discard"),
483 "sieve_redirect" => _("Redirect"),
484 "sieve_reject" => _("Reject"),
485 "sieve_require" => _("Require"),
486 "sieve_stop" => _("Stop"),
487 "sieve_vacation" => _("Vacation message"),
488 "sieve_if" => _("If"));
491 /* Element selected */
492 if(isset($_POST['element_type']) && isset($element_types[$_POST['element_type']])
493 || isset($_POST['element_type']) &&in_array($_POST['element_type'],array("sieve_else","sieve_elsif"))){
494 $this->add_element_type = $_POST['element_type'];
495 }
497 /* Create new element and add it to
498 * the selected position
499 */
500 if(isset($_POST['select_new_element_type'])){
502 $this->add_new_id;
503 $data = $this->current_handler->tree_->pap;
505 /* Get index of the element identified by object_id == $this->add_new_id; */
506 $index = -1;
507 foreach($data as $key => $obj){
508 if($obj->object_id == $this->add_new_id && $index==-1){
509 $index = $key;
510 }
511 }
513 /* We have found the specified object_id
514 * and want to detect the next free position
515 * to insert the new element.
516 */
517 if($index != -1){
518 if($this->add_above_below == "above"){
519 $direction ="up";
520 $next_free = $this->current_handler->tree_->_get_next_free_move_slot($index,$direction);
521 $next_free ++;
522 }else{
523 $direction = "down";
524 $next_free = $this->current_handler->tree_->_get_next_free_move_slot($index,$direction);
525 }
526 $this->add_new_id = $this->current_handler->tree_->pap[$next_free]->object_id;
527 }
529 /* Create elements we should add */
530 if($this->add_element_type == "sieve_if"){
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 $ele[] = new sieve_block_end(NULL,preg_replace("/[^0-9]/","",microtime()));
534 }elseif($this->add_element_type == "sieve_else"){
535 $ele[] = new sieve_block_end(NULL,preg_replace("/[^0-9]/","",microtime()));
536 $ele[] = new $this->add_element_type(NULL, preg_replace("/[^0-9]/","",microtime()));
537 $ele[] = new sieve_block_start(NULL,preg_replace("/[^0-9]/","",microtime()));
538 }elseif($this->add_element_type == "sieve_elsif"){
539 $ele[] = new sieve_block_end(NULL,preg_replace("/[^0-9]/","",microtime()));
540 $ele[] = new $this->add_element_type(NULL, preg_replace("/[^0-9]/","",microtime()));
541 $ele[] = new sieve_block_start(NULL,preg_replace("/[^0-9]/","",microtime()));
542 }else{
543 $ele[] = new $this->add_element_type(NULL, preg_replace("/[^0-9]/","",microtime()));
544 }
546 $start = $end = array();
547 $found = false;
549 /* Add above current element*/
550 if($this->add_above_below == "above"){
551 foreach($data as $key => $obj){
552 if($obj->object_id == $this->add_new_id){
553 $found = true;
554 }
555 if(!$found){
556 $start[] = $obj;
557 }else{
558 $end[] = $obj;
559 }
560 }
561 }else{
562 /* Add below current element */
563 foreach($data as $key => $obj){
564 if(!$found){
565 $start[] = $obj;
566 }else{
567 $end[] = $obj;
568 }
569 if($obj->object_id == $this->add_new_id){
570 $found = true;
571 }
572 }
573 }
576 /* Only add, if current element could be located */
577 if($found){
578 $new = array();
579 foreach($start as $obj){
580 $new[] = $obj;
581 }
582 foreach($ele as $el){
583 $new[] = $el;
584 }
585 foreach($end as $obj){
586 $new[] = $obj;
587 }
588 $data= $new;
589 $this->current_handler->tree_->pap = $data;
590 $this->add_new_element = FALSE;
591 }else{
592 print_red(_("Something went wrong while adding a new entry."));
593 }
594 }
595 }
597 /* Only display select dialog if it is necessary */
598 if($this->add_new_element){
599 $smarty = get_smarty();
601 $add_else_elsif = FALSE;
602 foreach($this->current_handler->tree_->pap as $obj){
603 if($obj->object_id == $this->add_new_id && in_array(get_class($obj),array("sieve_if","sieve_elsif"))){
604 $add_else_elsif = TRUE;
605 }
606 }
608 if($add_else_elsif && $this->add_above_below == "below"){
609 $element_types['sieve_else'] = _("Else");
610 $element_types['sieve_elsif'] = _("Else if");
611 }
613 $smarty->assign("element_types",$element_types );
614 $smarty->assign("element_type",$this->add_element_type);
615 $str = $smarty->fetch(get_template_path("templates/add_element.tpl",TRUE,dirname(__FILE__)));
616 return($str);
617 }
621 /****************
622 * Handle test posts
623 ****************/
625 /* handle some special posts from test elements
626 */
627 foreach($_POST as $name => $value){
628 if(preg_match("/^Add_Test_Object_/",$name)) {
629 $name = preg_replace("/^Add_Test_Object_/","",$name);
630 $name = preg_replace("/_(x|y)$/","",$name);
632 $test_types_to_add = array(
633 "address" =>_("Address"),
634 "header" =>_("Header"),
635 "envelope"=>_("Envelope"),
636 "size" =>_("Size"),
637 "exists" =>_("Exists"),
638 "allof" =>_("All of"),
639 "anyof" =>_("Any of"),
640 "true" =>_("True"),
641 "false" =>_("False"));
643 $smarty = get_smarty();
644 $smarty->assign("ID",$name);
645 $smarty->assign("test_types_to_add",$test_types_to_add);
646 $ret = $smarty->fetch(get_template_path("templates/select_test_type.tpl",TRUE,dirname(__FILE__)));
647 return($ret);
648 }
649 }
651 $current = $this->scripts[$this->current_script];
653 /* Create html results */
654 $smarty = get_smarty();
655 $smarty->assign("Mode",$current['MODE']);
656 if($current['MODE'] == "Structured"){
657 $smarty->assign("Contents",$this->current_handler->tree_->execute());
658 }else{
659 $smarty->assign("Contents",$current['SCRIPT']);
660 }
661 $smarty->assign("Script_Error",$this->Script_Error);
662 $ret = $smarty->fetch(get_template_path("templates/edit_frame_base.tpl",TRUE,dirname(__FILE__)));
663 return($ret);
664 }
667 /* Create list of available sieve scripts
668 */
669 $List = new divSelectBox("sieveManagement");
670 foreach($this->scripts as $key => $script){
672 $edited = $script['EDITED'];
673 $active = $script['ACTIVE'];
675 $field1 = array("string" => " ",
676 "attach" => "style='width:20px;'");
677 if($active){
678 $field1 = array("string" => "<img src='images/true.png' alt='"._("Active")."'>",
679 "attach" => "style='width:20px;'");
680 }
681 $field2 = array("string" => $script['NAME']);
682 $field3 = array("string" => $script['MSG']);
683 $field4 = array("string" => _("Script length")." : ".strlen($script['SCRIPT']));
685 if($edited){
686 $field5 = array("string" => "<img src='images/fai_new_hook.png' alt='"._("Edited")."'>",
687 "attach" => "style='width:30px;'");
688 }else{
689 $field5 = array("string" => "",
690 "attach" => "style='width:30px;'");
691 }
693 if($active || $script['IS_NEW']){
694 $field6 = array("string" => "<img src='images/empty.png' alt=' '>".
695 "<input type='image' name='editscript_".$key."' src='images/edit.png'>".
696 "<input type='image' name='delscript_".$key."' src='images/edittrash.png'>");
697 }else{
698 $field6 = array("string" => "<input type='image' name='active_script_".$key."' src='images/true.png'>".
699 "<input type='image' name='editscript_".$key."' src='images/edit.png'>".
700 "<input type='image' name='delscript_".$key."' src='images/edittrash.png'>");
701 }
702 $List ->AddEntry(array($field1,$field2,$field3,$field4,$field5,$field6));
703 }
705 $display ="<h2>Sieve script management</h2>";
706 $display .= _("Be careful. All your changes will be saved directly to sieve, if you use the save button below.");
707 $display .= "<br><input type='submit' name='create_new_script' value='"._("Create new script")."'>";
708 $display .= $List->DrawList();
710 $display .= "<p style=\"text-align:right\">\n";
711 $display .= "<input type=submit name=\"sieve_finish\" style=\"width:80px\" value=\""._("Ok")."\">\n";
712 $display .= " \n";
713 $display .= "<input type=submit name=\"sieve_cancel\" value=\""._("Cancel")."\">\n";
714 $display .= "</p>";
715 return($display);;
716 }
718 function save_object()
719 {
720 if($this->current_handler){
722 /* Check if there is an add object requested
723 */
724 $data = $this->current_handler->tree_->pap;
725 $once = TRUE;
726 foreach($_POST as $name => $value){
727 foreach($data as $key => $obj){
728 if(isset($obj->object_id) && preg_match("/^Add_Object_Top_".$obj->object_id."_/",$name) && $once){
729 $once = FALSE;
730 $this->add_new_element = TRUE;
731 $this->add_new_id = $obj->object_id;
732 $this->add_above_below = "above";
733 }
734 if(isset($obj->object_id) && preg_match("/^Add_Object_Bottom_".$obj->object_id."_/",$name) && $once){
735 $once = FALSE;
736 $this->add_new_element = TRUE;
737 $this->add_new_id = $obj->object_id;
738 $this->add_above_below = "below";
739 }
741 if(isset($obj->object_id) && preg_match("/^Remove_Object_".$obj->object_id."_/",$name) && $once){
742 $once = FALSE;
743 $this->current_handler->tree_->remove_object($key);
744 }
745 if(isset($obj->object_id) && preg_match("/^Move_Up_Object_".$obj->object_id."_/",$name) && $once){
746 $this->current_handler->tree_->move_up_down($key,"up");
747 $once = FALSE;
748 }
749 if(isset($obj->object_id) && preg_match("/^Move_Down_Object_".$obj->object_id."_/",$name) && $once){
750 $this->current_handler->tree_->move_up_down($key,"down");
751 $once = FALSE;
752 }
753 }
754 }
756 /* Skip Mode changes and Parse tests
757 * if we are currently in a subdialog
758 */
760 $this->current_handler->save_object();
761 $Mode = $this->scripts[$this->current_script]['MODE'];
762 $skip_mode_change = false;
763 if(in_array($Mode,array("Source-Only","Source"))){
764 if(isset($_POST['script_contents'])){
765 $sc = stripslashes($_POST['script_contents']);
766 $this->scripts[$this->current_script]['SCRIPT'] = $sc;
767 $p = new My_Parser;
768 if($p -> parse($sc)){
769 $this->Script_Error = "";
770 } else {
771 $this->Script_Error = $p->status_text;
772 $skip_mode_change = TRUE;
773 }
774 }
775 }
776 if(in_array($Mode,array("Structured"))){
777 $sc = $this->current_handler->get_sieve_script();
778 $this->scripts[$this->current_script]['SCRIPT'] = $sc;
779 $p = new My_Parser;
780 if($p -> parse($sc)){
781 $this->Script_Error = "";
782 } else {
783 $this->Script_Error = $p->status_text;
784 $skip_mode_change = TRUE;
785 }
786 }
787 if(!$skip_mode_change){
788 if($this->scripts[$this->current_script]['MODE'] != "Source-Only"){
789 $old_mode = $this->scripts[$this->current_script]['MODE'];
790 if(isset($_POST['View_Source'])){
791 $this->scripts[$this->current_script]['MODE'] = "Source";
792 }
793 if(isset($_POST['View_Structured'])){
794 $this->scripts[$this->current_script]['MODE'] = "Structured";
795 }
796 $new_mode = $this->scripts[$this->current_script]['MODE'];
798 if($old_mode != $new_mode){
800 $sc = $this->scripts[$this->current_script]['SCRIPT'];
801 $p = new My_Parser;
803 if($p -> parse($sc)){
804 $this->current_handler->parse($sc);
805 $this->Script_Error = "";
806 } else {
807 $this->Script_Error = $p->status_text;
808 }
809 }
810 }
811 }
812 }
813 }
816 function get_used_script_names()
817 {
818 $ret = array();
819 foreach($this->scripts as $script){
820 $ret[] = $script['NAME'];
821 }
822 return($ret);
823 }
827 function save()
828 {
829 /* Get sieve */
830 if(!$this->sieve_handle = $this->get_sieve()){
831 print_red(
832 sprintf(
833 _("Can't log into SIEVE server. Server says '%s'."),
834 to_string($this->Sieve_Error)));
835 }
837 $everything_went_fine = TRUE;
839 foreach($this->scripts as $key => $script){
840 if($script['EDITED']){
841 $data = $this->scripts[$key]['SCRIPT'];
842 if(!$this->sieve_handle->sieve_sendscript($script['NAME'], $data)){
843 gosa_log("Failed to save sieve script named '".$script['NAME']."': ".to_string($this->sieve_handle->error_raw));
844 $everything_went_fine = FALSE;
845 print_red(to_string($this->sieve_handle->error_raw));
846 $this->scripts[$key]['MSG'] = "<font color='red'>".
847 _("Failed to save sieve script").": ".
848 to_string($this->sieve_handle->error_raw).
849 "</font>";
850 }
851 }
852 }
853 return($everything_went_fine);
854 }
855 }
856 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
857 ?>