Code

Managed to edit script that can't be parsed ... .
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Thu, 15 Mar 2007 11:03:14 +0000 (11:03 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Thu, 15 Mar 2007 11:03:14 +0000 (11:03 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@5786 594d385d-05f5-0310-b6e9-bd551577e9d8

include/sieve/class_My_Tree.inc
include/sieve/class_sieveManagement.inc
include/sieve/templates/edit_frame_base.tpl

index b6e59a5810dfdebed08e9b7c3750867b7cc4ea1e..0ac92a0c12b079763af3c95746afa4914b1a53f0 100644 (file)
@@ -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_);
   }
 
 
index b1980adb727bcda384821fcdc82326d43416aa9d..e16bbdce6bab75192520240447e5b0c21dbc3a3b 100644 (file)
@@ -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']   = "<font color='red'>".$p->status_text."</font>";
-        $this->scripts[$key]['STATUS'] = _("Parse failed")."<font color='red'>".$p->status_text."</font>";
+        $this->scripts[$key]['STATUS']   = FALSE;
+        $this->scripts[$key]['MODE']    = "Source-Only";
+        $this->scripts[$key]['MSG'] = _("Parse failed")."<font color='red'>".$p->status_text."</font>";
       }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']   = "<font color='red'>".$p->status_text."</font>";
-          $sc['STATUS'] = _("Parse failed")."<font color='red'>".$p->status_text."</font>";
+          $sc['STATUS']   = FALSE;
+          $sc['MODE']    = "Source-Only";
+          $sc['MSG'] = _("Parse failed")."<font color='red'>".$p->status_text."</font>";
         }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")."&nbsp;:&nbsp;".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'] = "<font color='red'>".
+          $this->scripts[$key]['MSG'] = "<font color='red'>".
                                            _("Failed to save sieve script").": ".
                                            to_string($this->sieve_handle->error_raw).
                                            "</font>";
-          echo nl2br($data);
         }
       }
     }
index 93953fabc401c2de29511621dc717eba85cb8f58..ad18e89c0f3cd33f6019eac44d29ad8f32aebc20 100644 (file)
@@ -7,9 +7,10 @@
                        <input type='submit' name='Save_Copy' value="{t}Save copy{/t}">
                        <input type='submit' name='Import_Copy' value="{t}Import copy{/t}">
 
-                       
-                       <input type='submit' name='View_Source' value="{t}View source{/t}">
-                       <input type='submit' name='View_Structured' value="{t}View structured{/t}">
+                       {if $Mode != "Source-Only"}                     
+                               <input type='submit' name='View_Source' value="{t}View source{/t}">
+                               <input type='submit' name='View_Structured' value="{t}View structured{/t}">
+                       {/if}
                </td>
        </tr>
        <tr>