From: hickert Date: Thu, 15 Mar 2007 11:03:14 +0000 (+0000) Subject: Managed to edit script that can't be parsed ... . X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=8dffdb07822a6f0d865afb1000a1b5437fa40492;p=gosa.git Managed to edit script that can't be parsed ... . git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@5786 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/include/sieve/class_My_Tree.inc b/include/sieve/class_My_Tree.inc index b6e59a581..0ac92a0c1 100644 --- a/include/sieve/class_My_Tree.inc +++ b/include/sieve/class_My_Tree.inc @@ -172,20 +172,7 @@ class My_Tree extends Tree } } - /* Create html results */ - $smarty = get_smarty(); - $smarty->assign("Mode",$this->Mode); - if($this->Mode == "Structured"){ - $smarty->assign("Contents",$this->dump_); - }else{ - if(isset($_POST['script_contents'])){ - $smarty->assign("Contents",stripslashes($_POST['script_contents'])); - }else{ - $smarty->assign("Contents",$this->get_sieve_script()); - } - } - $ret = $smarty->fetch(get_template_path("templates/edit_frame_base.tpl",TRUE,dirname(__FILE__))); - return ($ret); + return($this->dump_); } diff --git a/include/sieve/class_sieveManagement.inc b/include/sieve/class_sieveManagement.inc index b1980adb7..e16bbdce6 100644 --- a/include/sieve/class_sieveManagement.inc +++ b/include/sieve/class_sieveManagement.inc @@ -91,13 +91,17 @@ class sieveManagement extends plugin } $this->scripts[$key]['SCRIPT'] = $script; + $this->scripts[$key]['ORIG_SCRIPT'] = $script; $this->scripts[$key]['MSG'] = ""; $ret = $p->parse($script); if(!$ret){ - $this->scripts[$key]['MSG'] = "".$p->status_text.""; - $this->scripts[$key]['STATUS'] = _("Parse failed")."".$p->status_text.""; + $this->scripts[$key]['STATUS'] = FALSE; + $this->scripts[$key]['MODE'] = "Source-Only"; + $this->scripts[$key]['MSG'] = _("Parse failed")."".$p->status_text.""; }else{ - $this->scripts[$key]['STATUS'] = _("Parse successful"); + $this->scripts[$key]['STATUS'] = TRUE; + $this->scripts[$key]['MODE'] = "Structured"; + $this->scripts[$key]['MSG'] = _("Parse successful"); } $this->scripts[$key]['PARSER'] = $p; $this->scripts[$key]['EDITED'] = FALSE; @@ -143,14 +147,18 @@ class sieveManagement extends plugin $p = new My_Parser; $sc['SCRIPT'] = $script; + $sc['ORIG_SCRIPT'] = $script; $sc['MSG'] = ""; $ret = $p->parse($script); if(!$ret){ - $sc['MSG'] = "".$p->status_text.""; - $sc['STATUS'] = _("Parse failed")."".$p->status_text.""; + $sc['STATUS'] = FALSE; + $sc['MODE'] = "Source-Only"; + $sc['MSG'] = _("Parse failed")."".$p->status_text.""; }else{ - $sc['STATUS'] = _("Parse successful"); + $sc['STATUS'] = TRUE; + $sc['MODE'] = "Strucktured"; + $sc['MSG'] = _("Parse successful"); } $sc['PARSER'] = $p; $sc['EDITED'] = TRUE; @@ -262,43 +270,52 @@ class sieveManagement extends plugin $chk = $this->current_handler->check(); $chk =array(); if(!count($chk)){ - $this->scripts[$this->current_script]['PARSER'] = $this->current_handler; - $this->scripts[$this->current_script]['EDITED'] = TRUE; - $this->current_handler = NULL; + + $sc = $this->scripts[$this->current_script]['SCRIPT']; + $p = new My_Parser; + if($p -> parse($sc)){ + + if($this->scripts[$this->current_script]['MODE'] == "Source-Only"){ + $this->scripts[$this->current_script]['MODE'] = "Source"; + } + + $this->scripts[$this->current_script]['PARSER'] = $p; + $this->scripts[$this->current_script]['EDITED'] = TRUE; + $this->scripts[$this->current_script]['STATUS'] = TRUE; + $this->scripts[$this->current_script]['MSG'] = _("Edited"); + $this->current_handler = NULL; + }else{ + print_red($p->status_text);; + } }else{ - print_a($chk); print_red(_("Please fix all errors before saving.")); } } - /* Create output for currently opened sieve script */ - if($this->current_handler){ - if(isset($_POST['script_contents']) && $this->current_handler->tree_->Mode == "Source"){ - $script = stripslashes($_POST['script_contents']); + /************* + * Display edit dialog + *************/ - $new_p = new My_Parser; - if($new_p->parse($script)){ - $this->current_handler->parse($script); - $this->current_handler->tree_->Mode = "Source"; - }else{ - print_red($new_p->status_text); - $this->current_handler->tree_->Mode = "Source"; - } - } + /* Display edit dialog, depending on Mode display different uis + */ + if($this->current_handler){ - if(isset($_POST['View_Source'])){ - $this->current_handler->tree_->Mode = "Source"; - } + $current = $this->scripts[$this->current_script]; - if(isset($_POST['View_Structured'])){ - $this->current_handler->tree_->Mode = "Structured"; + /* Create html results */ + $smarty = get_smarty(); + $smarty->assign("Mode",$current['MODE']); + if($current['MODE'] == "Structured"){ + $smarty->assign("Contents",$this->current_handler->tree_->execute()); + }else{ + $smarty->assign("Contents",$current['SCRIPT']); } - - $ret = $this->current_handler->execute(); + $ret = $smarty->fetch(get_template_path("templates/edit_frame_base.tpl",TRUE,dirname(__FILE__))); return($ret); } + /* Create list of available sieve scripts */ $List = new divSelectBox("sieveManagement"); @@ -314,7 +331,7 @@ class sieveManagement extends plugin "attach" => "style='width:20px;'"); } $field2 = array("string" => $script['NAME']); - $field3 = array("string" => $script['STATUS']); + $field3 = array("string" => $script['MSG']); $field4 = array("string" => _("Script length")." : ".strlen($script['SCRIPT'])); if($edited){ @@ -353,6 +370,32 @@ class sieveManagement extends plugin function save_object() { if($this->current_handler){ + + $Mode = $this->scripts[$this->current_script]['MODE']; + $skip_mode_change = false; + if(in_array($Mode,array("Source-Only","Source"))){ + if(isset($_POST['script_contents'])){ + $sc = stripslashes($_POST['script_contents']); + $this->scripts[$this->current_script]['SCRIPT'] = $sc; + $p = new My_Parser; + if($p -> parse($sc)){ + $this->current_handler = $p; + } else { + print_red($p->status_text); + $skip_mode_change = TRUE; + } + } + } + if(!$skip_mode_change){ + if($this->scripts[$this->current_script]['MODE'] != "Source-Only"){ + if(isset($_POST['View_Source'])){ + $this->scripts[$this->current_script]['MODE'] = "Source"; + } + if(isset($_POST['View_Structured'])){ + $this->scripts[$this->current_script]['MODE'] = "Structured"; + } + } + } $this->current_handler->save_object(); } } @@ -379,16 +422,15 @@ class sieveManagement extends plugin foreach($this->scripts as $key => $script){ if($script['EDITED']){ - $data = $script['PARSER']->get_sieve_script(); + $data = $this->scripts[$key]['SCRIPT']; if(!$this->sieve_handle->sieve_sendscript($script['NAME'], $data)){ gosa_log("Failed to save sieve script named '".$script['NAME']."': ".to_string($this->sieve_handle->error_raw)); $everything_went_fine = FALSE; print_red(to_string($this->sieve_handle->error_raw)); - $this->scripts[$key]['STATUS'] = "". + $this->scripts[$key]['MSG'] = "". _("Failed to save sieve script").": ". to_string($this->sieve_handle->error_raw). ""; - echo nl2br($data); } } } diff --git a/include/sieve/templates/edit_frame_base.tpl b/include/sieve/templates/edit_frame_base.tpl index 93953fabc..ad18e89c0 100644 --- a/include/sieve/templates/edit_frame_base.tpl +++ b/include/sieve/templates/edit_frame_base.tpl @@ -7,9 +7,10 @@ - - - + {if $Mode != "Source-Only"} + + + {/if}