Code

Added debug line
[gosa.git] / gosa-plugins / mail / personal / mail / class_mailAccount.inc
index 34c66cb5211b552c2ee3d13d4138e2429ccc9455..3dcc585ea3111b22cf3076aca1decf5509478f5c 100644 (file)
@@ -55,8 +55,8 @@ class mailAccount extends plugin
 
   /* GOsa mail attributes */
   var $mail                               = "";
-  var $gosaVacationStart                  = 0;
-  var $gosaVacationStop                   = 0;
+  var $gosaVacationStart                  = "";
+  var $gosaVacationStop                   = "";
   var $gosaMailAlternateAddress           = array();
   var $gosaMailForwardingAddress          = array();
   var $gosaMailDeliveryMode               = "[L        ]";
@@ -206,6 +206,11 @@ class mailAccount extends plugin
     /* Disconnect mailMethod. Connect on demand later. 
      */
     $this->mailMethod->disconnect();
+
+    /* Convert start/stop dates */
+    #TODO: use date format
+    $this->gosaVacationStart= date('d.m.Y', $this->gosaVacationStart);
+    $this->gosaVacationStop= date('d.m.Y', $this->gosaVacationStop);
   }
 
 
@@ -367,10 +372,14 @@ class mailAccount extends plugin
       }
       if ($valid && ($user= $this->addAlternate ($_POST['alternate_address'])) != ""){
         $ui= get_userinfo();
-        if ($user != $ui->username){
-          msg_dialog::display(_("Error"), msgPool::duplicated(_("Mail address"))." ".
-              sprintf(_("Address is already in use by user '%s'."), $user), ERROR_DIALOG);
+        $addon= "";
+        if ($user[0] == "!") {
+          $addon= sprintf(_("Address is already in use by group '%s'."), mb_substr($user, 1));
+        } else {
+          $addon= sprintf(_("Address is already in use by user '%s'."), $user);
         }
+        msg_dialog::display(_("Error"), msgPool::duplicated(_("Mail address"))."<br><br><i>".
+            "$addon</i>", ERROR_DIALOG);
       }
     }
     if (isset($_POST['delete_alternate']) && isset($_POST['alternates_list'])){
@@ -381,6 +390,7 @@ class mailAccount extends plugin
       SMARTY- Assign smarty variables 
      ****************/
     $smarty = get_smarty();
+    $smarty->assign("usePrototype", "true");
     $smarty->assign("initially_was_account", $this->initially_was_account);
     $smarty->assign("isModifyableMail"  , $this->mailMethod->isModifyableMail());
     $smarty->assign("isModifyableServer", $this->mailMethod->isModifyableServer());
@@ -460,36 +470,6 @@ class mailAccount extends plugin
      */
     if($this->mailMethod->vacationRangeEnabled()){
       $smarty->assign("rangeEnabled", TRUE);
-      if($this->gosaVacationStop ==0){
-        $date= getdate(time());
-        $date["mday"]++;
-      }else{
-        $date= getdate($this->gosaVacationStop);
-      }
-      $smarty->assign("end_day", $date["mday"]);
-      $smarty->assign("end_month", $date["mon"]-1);
-      $smarty->assign("end_year", $date["year"]);
-
-      if($this->gosaVacationStart == 0){
-        $date= getdate(time());
-      }else{
-        $date= getdate($this->gosaVacationStart);
-      }
-      $smarty->assign("start_day", $date["mday"]);
-      $smarty->assign("start_month", $date["mon"]-1);
-      $smarty->assign("start_year", $date["year"]);
-      $days= array();
-      for($d= 1; $d<32; $d++){
-        $days[$d]= $d;
-      }
-      $years= array();
-      for($y= $date['year']-10; $y<$date['year']+10; $y++){
-        $years[]= $y;
-      }
-      $months= msgPool::months();
-      $smarty->assign("months", $months);
-      $smarty->assign("years", $years);
-      $smarty->assign("days", $days);
     }
 
     /* fill filter settings 
@@ -692,9 +672,12 @@ class mailAccount extends plugin
       /* Is this address already assigned in LDAP? */
       $ldap->cd ($this->config->current['BASE']);
       $ldap->search ("(&(!(objectClass=gosaUserTemplate))(objectClass=gosaMailAccount)(|(mail=$address)".
-          "(alias=$address)(gosaMailAlternateAddress=$address)))", array("uid"));
+          "(alias=$address)(gosaMailAlternateAddress=$address)))", array("uid", "cn"));
       if ($ldap->count() > 0){
         $attrs= $ldap->fetch ();
+        if (!isset($attrs["uid"])) {
+          return ("!".$attrs["cn"][0]);
+        }
         return ($attrs["uid"][0]);
       }
       if (!in_array($address, $this->gosaMailAlternateAddress)){
@@ -745,10 +728,10 @@ class mailAccount extends plugin
       /* Replace vacation start and end time */
       if($this->mailMethod->vacationRangeEnabled()){
         if(preg_match("/%start/",$contents)){
-          $contents = preg_replace("/%start/",date("d.m.Y",$this->gosaVacationStart),$contents);
+          $contents = preg_replace("/%start/",$this->gosaVacationStart,$contents);
         }
         if(preg_match("/%end/",$contents)){
-          $contents = preg_replace("/%end/",date("d.m.Y",$this->gosaVacationStop),$contents);
+          $contents = preg_replace("/%end/",$this->gosaVacationStop,$contents);
         }
       }else{
         if(preg_match("/%start/",$contents)){
@@ -968,6 +951,12 @@ class mailAccount extends plugin
     }elseif (!preg_match('/V/', $this->gosaMailDeliveryMode)){
       unset($this->attrs['gosaVacationStart']);
       unset($this->attrs['gosaVacationStop']);
+    } else {
+      /* Adapt values to be timestamps */
+      list($day, $month, $year)= split('\.', $this->gosaVacationStart);
+      $this->attrs['gosaVacationStart']= mktime(0,0,0,$month, $day, $year);
+      list($day, $month, $year)= split('\.', $this->gosaVacationStop);
+      $this->attrs['gosaVacationStop']= mktime(0,0,0,$month, $day, $year);
     }
 
     /* Map method attributes */ 
@@ -1015,13 +1004,15 @@ class mailAccount extends plugin
                 "Skipping sieve settings, the account doesn't seem to be created already.</b>","");
           }else{
             if(!$this->mailMethod->saveSieveSettings()){
-              msg_dialog::display(_("Mail error"), $this->mailMethod->get_error(), ERROR_DIALOG);
+              msg_dialog::display(_("Mail error saving sieve settings"), $this->mailMethod->get_error(), ERROR_DIALOG);
             }
           }
         }else{
-          @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__, 
-              "User uses an own sieve script, skipping sieve update.".$str."</b>","");
-          $this->sieve_management->save();
+          if ($this->sieve_management) {
+            @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__, 
+                "User uses an own sieve script, skipping sieve update.".$str."</b>","");
+            $this->sieve_management->save();
+          }
         }
       }
     }
@@ -1100,9 +1091,16 @@ class mailAccount extends plugin
       $filter = "(&(!(objectClass=gosaUserTemplate))(!(uid=".$this->uid."))".
         "(objectClass=gosaMailAccount)".
         "(|(mail=".$mail.")(alias=".$mail.")(gosaMailAlternateAddress=".$mail.")))";
-      $ldap->search($filter,array("uid"));
+      $ldap->search($filter,array("uid", "cn"));
       if ($ldap->count() != 0){
-        $message[]= msgPool::duplicated(_("Mail address"));
+        $entry= $ldap->fetch();
+        $addon= "";
+        if (!isset($entry['uid'])) {
+           $addon= sprintf(_("Address is already in use by group '%s'."), $entry['cn'][0]);
+        } else {
+           $addon= sprintf(_("Address is already in use by user '%s'."), $entry['uid'][0]);
+        }
+        $message[]= msgPool::duplicated(_("Mail address"))."<br><br><i>$addon</i>";
       }
     }
 
@@ -1134,10 +1132,29 @@ class mailAccount extends plugin
       $message[]= msgPool::required(_("Spam folder"));
     }
 
-    if ($this->mailMethod->vacationRangeEnabled() 
-        && preg_match('/V/', $this->gosaMailDeliveryMode) 
-        && $this->gosaVacationStart > $this->gosaVacationStop){
-      $message[]= msgPool::invalid(_("Vacation interval"));
+    if ($this->mailMethod->vacationRangeEnabled() && preg_match('/V/', $this->gosaMailDeliveryMode)){ 
+
+      /* Check date strings */
+      $state= true;
+      if ($this->gosaVacationStart == "" || !tests::is_date($this->gosaVacationStart)) {
+        $message[]= msgPool::invalid(_("from"),$this->gosaVacationStart);
+        $state= false;
+      }
+      if ($this->gosaVacationStart == "" || !tests::is_date($this->gosaVacationStop)) {
+        $message[]= msgPool::invalid(_("to"),$this->gosaVacationStop);
+        $state= false;
+      }
+
+      #TODO: take care of date format
+      if ($state) {
+        list($day, $month, $year)= split('\.', $this->gosaVacationStart);
+        $start= mktime(0,0,0,$month, $day, $year);
+        list($day, $month, $year)= split('\.', $this->gosaVacationStop);
+        $stop= mktime(0,0,0,$month, $day, $year);
+        if($start > $stop){
+          $message[]= msgPool::invalid(_("Vacation interval"));
+        }
+      }
     }
     return($message);
   }
@@ -1286,9 +1303,29 @@ class mailAccount extends plugin
       $message[]= msgPool::required(_("Spam folder"));
     }
 
-    if ($this->mailMethod->vacationRangeEnabled() && in_array("use_vacation",$this->multi_boxes) &&
-        preg_match('/V/', $this->gosaMailDeliveryMode) && $this->gosaVacationStart > $this->gosaVacationStop){
-      $message[]= msgPool::invalid(_("Vacation interval"));
+    if ($this->mailMethod->vacationRangeEnabled() && preg_match('/V/', $this->gosaMailDeliveryMode)){ 
+
+      /* Check date strings */
+      $state= true;
+      if ($this->gosaVacationStart == "" || !tests::is_date($this->gosaVacationStart)) {
+        $message[]= msgPool::invalid(_("from"),$this->gosaVacationStart);
+        $state= false;
+      }
+      if ($this->gosaVacationStart == "" || !tests::is_date($this->gosaVacationStop)) {
+        $message[]= msgPool::invalid(_("to"),$this->gosaVacationStop);
+        $state= false;
+      }
+
+      #TODO: take care of date format
+      if ($state) {
+        list($day, $month, $year)= split('\.', $this->gosaVacationStart);
+        $start= mktime(0,0,0,$month, $day, $year);
+        list($day, $month, $year)= split('\.', $this->gosaVacationStop);
+        $stop= mktime(0,0,0,$month, $day, $year);
+        if($start > $stop){
+          $message[]= msgPool::invalid(_("Vacation interval"));
+        }
+      }
     }
     return($message);
   }