Code

modified templates
[gosa.git] / include / sieve / class_sieveManagement.inc
index b436808a41a8c2d4552db4c1977efc18987b7bfc..94b8a1116a3667a421f0d85af585fe721261282f 100644 (file)
@@ -108,7 +108,7 @@ class sieveManagement extends plugin
       $ret = $p->parse($script);
       if(!$ret){
         $this->scripts[$key]['STATUS']   = FALSE;
-        $this->scripts[$key]['MODE']    = "Source-Only";
+        $this->scripts[$key]['MODE']    = "Source";
         $this->scripts[$key]['MSG'] = _("Parse failed")."<font color='red'>".$p->status_text."</font>";
       }else{
         $this->scripts[$key]['STATUS']   = TRUE;
@@ -285,8 +285,8 @@ class sieveManagement extends plugin
         /* Try to activate the given script and update 
          *  class script array. 
          */
-        if(!$this->sieve_handle->sieve_setactivescript($this->scripts[$script]['NAME'])){
-          print_red(sprintf(_("Can't activate sieve script on server. Server says '%s'."),to_string($this->sieve_handle->error_raw)));
+        if(!$sieve->sieve_setactivescript($this->scripts[$script]['NAME'])){
+          print_red(sprintf(_("Can't activate sieve script on server. Server says '%s'."),to_string($sieve->error_raw)));
         }else{
           foreach($this->scripts as $key => $data){
             if($key == $script){
@@ -328,7 +328,7 @@ class sieveManagement extends plugin
         }
 
         if(!$sieve->sieve_deletescript($this->scripts[$this->script_to_delete]['NAME'])){
-          print_red(sprintf(_("Can't remove sieve script from server. Server says '%s'."),to_string($this->sieve_handle->error_raw)));
+          print_red(sprintf(_("Can't remove sieve script from server. Server says '%s'."),to_string($sieve->error_raw)));
         }else{
           unset($this->scripts[$this->script_to_delete]);
         }
@@ -480,7 +480,8 @@ class sieveManagement extends plugin
 
 
         /* Element selected */
-        if(isset($_POST['element_type']) && isset($element_types[$_POST['element_type']])){
+        if(isset($_POST['element_type']) && isset($element_types[$_POST['element_type']]) 
+           || isset($_POST['element_type']) &&in_array($_POST['element_type'],array("sieve_else","sieve_elsif"))){
           $this->add_element_type = $_POST['element_type'];
         }
 
@@ -490,7 +491,6 @@ class sieveManagement extends plugin
         if(isset($_POST['select_new_element_type'])){
 
           $this->add_new_id;
-
           $data = $this->current_handler->tree_->pap;
 
           /* Get index of the element identified by object_id == $this->add_new_id; */
@@ -518,11 +518,22 @@ class sieveManagement extends plugin
           }
 
           /* Create elements we should add */
-          $ele[] = new $this->add_element_type(NULL, preg_replace("/[^0-9]/","",microtime()));
           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()));
+          }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()));
+          }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()));
+          }else{
+            $ele[] = new $this->add_element_type(NULL, preg_replace("/[^0-9]/","",microtime()));
           }
+
           $start = $end = array();
           $found = false;
 
@@ -546,10 +557,8 @@ class sieveManagement extends plugin
               }else{
                 $end[] = $obj;
               }
-              echo $obj->object_id." --> ".$this->add_new_id."<br>";
               if($obj->object_id == $this->add_new_id){
                 $found = true;
-                echo "Jop";
               }
             }
           }
@@ -579,6 +588,19 @@ class sieveManagement extends plugin
       /* Only display select dialog if it is necessary */
       if($this->add_new_element){
         $smarty = get_smarty();
+    
+        $add_else_elsif = FALSE;
+        foreach($this->current_handler->tree_->pap as $obj){
+          if($obj->object_id == $this->add_new_id && in_array(get_class($obj),array("sieve_if","sieve_elsif"))){
+            $add_else_elsif = TRUE;
+          }
+        }
+
+        if($add_else_elsif && $this->add_above_below == "below"){
+          $element_types['sieve_else'] = _("Else");
+          $element_types['sieve_elsif'] = _("Else if");
+        }
+  
         $smarty->assign("element_types",$element_types );
         $smarty->assign("element_type",$this->add_element_type);
         $str = $smarty->fetch(get_template_path("templates/add_element.tpl",TRUE,dirname(__FILE__)));
@@ -726,6 +748,7 @@ class sieveManagement extends plugin
        *  if we are currently in a subdialog 
        */
 
+      $this->current_handler->save_object();
       $Mode = $this->scripts[$this->current_script]['MODE'];
       $skip_mode_change = false;
       if(in_array($Mode,array("Source-Only","Source"))){
@@ -777,26 +800,18 @@ class sieveManagement extends plugin
           } 
         }
       }
-      $this->current_handler->save_object();
     }
   }
 
 
   function save()
   {
-    /* Connect to sieve class and try to get all available sieve scripts */
-    $cfg=  $this->config->data['SERVERS']['IMAP'][$this->parent->gosaMailServer];
-
-    $this->sieve_handle= 
-        new sieve(  $cfg["sieve_server"], 
-                    $cfg["sieve_port"], 
-                    $this->parent->mail,
-                    $cfg["password"], 
-                    $cfg["admin"]);
-
-    if (!$this->sieve_handle->sieve_login()){
-      print_red(sprintf(_("Can't log into SIEVE server. Server says '%s'."),to_string($this->sieve_handle->error_raw)));
-      return;
+    /* Get sieve */
+    if(!$sieve = $this->get_sieve()){
+      print_red(
+          sprintf(
+            _("Can't log into SIEVE server. Server says '%s'."),
+            to_string($this->Sieve_Error)));
     }
 
     $everything_went_fine = TRUE;
@@ -804,13 +819,13 @@ class sieveManagement extends plugin
     foreach($this->scripts as $key => $script){
       if($script['EDITED']){
         $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));
+        if(!$sieve->sieve_sendscript($script['NAME'], $data)){
+          gosa_log("Failed to save sieve script named '".$script['NAME']."': ".to_string($sieve->error_raw));
           $everything_went_fine = FALSE;
-          print_red(to_string($this->sieve_handle->error_raw));
+          print_red(to_string($sieve->error_raw));
           $this->scripts[$key]['MSG'] = "<font color='red'>".
                                            _("Failed to save sieve script").": ".
-                                           to_string($this->sieve_handle->error_raw).
+                                           to_string($sieve->error_raw).
                                            "</font>";
         }
       }