Code

Migration to get_value
[gosa.git] / gosa-plugins / mail / personal / mail / class_mailAccount.inc
index 3c2393106a411c9159383bce5213cf6011bda43d..4918868bec066c7ef7ed8eb2e8952063e03a5ba2 100644 (file)
@@ -82,8 +82,8 @@ class mailAccount extends plugin
     $this->initially_was_account= $this->is_account;
 
     /*  Set mailMethod to the one defined in gosa.conf */
-    if (isset($this->config->current['MAILMETHOD'])){
-      $method= $this->config->current['MAILMETHOD'];
+    if ($this->config->get_cfg_value("mailmethod") != ""){
+      $method= $this->config->get_cfg_value("mailmethod");
 
       $cls = get_correct_class_name("mailMethod$method");
       if ($cls && class_exists($cls)){
@@ -97,9 +97,7 @@ class mailAccount extends plugin
     /* Create the account prefix  user. user/ 
        Preset folder prefix. Will change it later to respect
        altnamespace. */
-    if (isset($this->config->current['CYRUSUNIXSTYLE']) && $this->config->current['CYRUSUNIXSTYLE'] == "true"){
-      $this->folder_prefix= "user/";
-    }elseif (isset($this->config->data['MAIN']['CYRUSUNIXSTYLE']) && $this->config->data['MAIN']['CYRUSUNIXSTYLE'] == "true"){
+    if ($this->config->get_cfg_value("cyrusunixstyle") == "true"){
       $this->folder_prefix= "user/";
     } else {
       $this->folder_prefix= "user.";
@@ -168,8 +166,8 @@ class mailAccount extends plugin
 
     /* Fill vacation array */
     $this->vacation= array();
-    if (isset($this->config->current['VACATIONDIR'])){
-      $dir= $this->config->current['VACATIONDIR'];
+    if ($this->config->get_cfg_value("vacationdir") != ""){
+      $dir= $this->config->get_cfg_value("vacationdir");
       if (is_dir($dir) && is_readable($dir)){
 
         /* Look for files and build the vacation array */
@@ -241,8 +239,12 @@ class mailAccount extends plugin
 
     /* Get available mailserver */
     $mailserver= array();
+    $ui = get_userinfo();
     foreach ($this->config->data['SERVERS']['IMAP'] as $key => $val){
-      $mailserver[]= $key;
+      if( $this->gosaMailServer == $key || 
+          preg_match("/r/",$ui->get_permissions($val['server_dn'],"server/goImapServer",""))){
+        $mailserver[]= $key;
+      }
     }
 
     /* 
@@ -285,7 +287,7 @@ class mailAccount extends plugin
     /* Do we represent a valid account? */
     if(!$this->multiple_support_active){
       if (!$this->is_account && $this->parent === NULL){
-        $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\">&nbsp;<b>".
+        $display= "<img alt=\"\" src=\"images/small-error.png\" align=\"middle\">&nbsp;<b>".
           msgPool::noValidExtension(_("Mail"))."</b>";
 
         $display.= back_to_main();
@@ -327,21 +329,26 @@ class mailAccount extends plugin
     /* Finished adding of locals? */
     if (isset($_POST['add_locals_finish'])){
 
-      /* Check if we are able to write gosaMailForwardingAddress */
-      if($this->acl_is_writeable("gosaMailForwardingAddress")){
+      if (isset($_POST['local_list'])){
 
-        /* Walk through list of forwarders, ignore own addresses */
-        foreach ($_POST['local_list'] as $val){
-          if (!in_array ($val, $this->gosaMailAlternateAddress) &&
-              $val != $this->mail){
+        /* Check if we are able to write gosaMailForwardingAddress */
+        if($this->acl_is_writeable("gosaMailForwardingAddress")){
 
-            $this->addForwarder($val);
-            $this->is_modified= TRUE;
+          /* Walk through list of forwarders, ignore own addresses */
+          foreach ($_POST['local_list'] as $val){
+            if (!in_array ($val, $this->gosaMailAlternateAddress) &&
+                $val != $this->mail){
+
+              $this->addForwarder($val);
+              $this->is_modified= TRUE;
+            }
           }
         }
+        $this->forward_dialog= FALSE;
+        $this->dialog= FALSE;
+      } else {
+        msg_dialog::display(_("Error"), _("Please select an entry!"), ERROR_DIALOG);
       }
-      $this->forward_dialog= FALSE;
-      $this->dialog= FALSE;
     }
 
     /* Add forward email addresses */
@@ -357,7 +364,7 @@ class mailAccount extends plugin
               $valid= TRUE;
             } else {
               msg_dialog::display(_("Error"), 
-                  msgPool::invalid(_("Mail address"),"","","example@your-domain.com"),
+                  msgPool::invalid(_("Mail address"),"","","your-domain@your-domain.com"),
                   ERROR_DIALOG);
             }
           }
@@ -393,7 +400,7 @@ class mailAccount extends plugin
         if ($this->is_template){
           if (!(tests::is_email($_POST['alternate_address'], TRUE))){
             msg_dialog::display(_("Error"), 
-                msgPool::invalid(_("Mail address"),"","","example@your-domain.com"),
+                msgPool::invalid(_("Mail address"),"","","your-domain@your-domain.com"),
                 ERROR_DIALOG);
 
           } else {
@@ -401,7 +408,7 @@ class mailAccount extends plugin
           }
         } else {
           msg_dialog::display(_("Error"), 
-              msgPool::invalid(_("Mail address"),"","","example@your-domain.com"),
+              msgPool::invalid(_("Mail address"),"","","your-domain@your-domain.com"),
               ERROR_DIALOG);
         }
 
@@ -502,11 +509,11 @@ class mailAccount extends plugin
       reset ($mailusers);
 
       /* Show dialog */
-      $smarty->assign("search_image", get_template_path('images/search.png'));
-      $smarty->assign("usearch_image", get_template_path('images/search_user.png'));
-      $smarty->assign("tree_image", get_template_path('images/tree.png'));
+      $smarty->assign("search_image", get_template_path('images/lists/search.png'));
+      $smarty->assign("usearch_image", get_template_path('images/lists/search-user.png'));
+      $smarty->assign("tree_image", get_template_path('images/lists/search-subtree.png'));
       $smarty->assign("infoimage", get_template_path('images/info.png'));
-      $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
+      $smarty->assign("launchimage", get_template_path('images/lists/action.png'));
       $smarty->assign("mailusers", $mailusers);
       if (isset($_POST['depselect'])){
         $smarty->assign("depselect", $_POST['depselect']);
@@ -599,9 +606,7 @@ class mailAccount extends plugin
     for($y= $date['year']-10; $y<$date['year']+10; $y++){
       $years[]= $y;
     }
-    $months= array(_("January"), _("February"), _("March"), _("April"),
-        _("May"), _("June"), _("July"), _("August"), _("September"),
-        _("October"), _("November"), _("December"));
+    $months= msgPool::months();
     $smarty->assign("start_day", $date["mday"]);
     $smarty->assign("days", $days);
     $smarty->assign("months", $months);
@@ -688,7 +693,9 @@ class mailAccount extends plugin
     /* Add "view" to logging class */ 
     new log("remove","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
 
-    show_ldap_error($ldap->get_error(), sprintf(_("Removing of user/mail account with dn '%s' failed."),$this->dn));
+    if (!$ldap->success()){
+      msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
+    }
 
     /* Connect to IMAP server for account deletion */
     if ($this->gosaMailServer != ""){
@@ -854,7 +861,9 @@ class mailAccount extends plugin
     $this->cleanup();
     $ldap->modify ($this->attrs); 
 
-    show_ldap_error($ldap->get_error(), sprintf(_("Saving of user/mail account with dn '%s' failed."),$this->dn));
+    if (!$ldap->success()){
+      msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
+    }
 
     /* Log last action */ 
     if($this->initially_was_account){
@@ -930,15 +939,21 @@ class mailAccount extends plugin
       }
     } else {
       if (!tests::is_email($this->mail)){
-        $message[]= msgPool::invalid(_("Mail address"),"","","example@your-domain.com");
+        $message[]= msgPool::invalid(_("Mail address"),"","","your-domain@your-domain.com");
       }
     }
+
     $ldap->cd($this->config->current['BASE']);
-    $ldap->search ("(&(!(objectClass=gosaUserTemplate))(objectClass=gosaMailAccount)(|(mail=".$this->mail.")(gosaMailAlternateAddress=".$this->mail."))(!(uid=".$this->uid."))(!(cn=".$this->uid.")))", array("uid"));
+    $filter = "(&(!(objectClass=gosaUserTemplate))(!(uid=".$this->uid."))".
+      "(objectClass=gosaMailAccount)".
+      "(|(mail=".$this->mail.")(alias=".$this->mail.")(gosaMailAlternateAddress=".$this->mail.")))";
+
+    $ldap->search($filter,array("uid"));
     if ($ldap->count() != 0){
       $message[]= msgPool::duplicated(_("Mail address"));
     }
 
+
     /* Check quota */
     if ($this->gosaMailQuota != '' && $this->acl_is_writeable("gosaMailQuota")){
       if (!is_numeric($this->gosaMailQuota)) {
@@ -975,11 +990,16 @@ class mailAccount extends plugin
 
 
   /* Adapt from template, using 'dn' */
-  function adapt_from_template($dn)
+  function adapt_from_template($dn, $skip= array())
   {
-    plugin::adapt_from_template($dn);
+    plugin::adapt_from_template($dn, $skip);
 
     foreach (array("gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){
+
+      if (in_array($val, $skip)){
+        continue;
+      }
+
       $this->$val= array();
       if (isset($this->attrs["$val"]["count"])){
         for ($i= 0; $i<$this->attrs["$val"]["count"]; $i++){
@@ -1034,8 +1054,8 @@ class mailAccount extends plugin
 
       /* Is this address already assigned in LDAP? */
       $ldap->cd ($this->config->current['BASE']);
-      $ldap->search ("(&(objectClass=gosaMailAccount)(|(mail=$address)"."(gosaMailAlternateAddress=$address)))", array("uid"));
-      $ldap->search ("(&(!(objectClass=gosaUserTemplate))(objectClass=gosaMailAccount)(|(mail=$address)"."(gosaMailAlternateAddress=$address)))", array("uid"));
+      $ldap->search ("(&(!(objectClass=gosaUserTemplate))(objectClass=gosaMailAccount)(|(mail=$address)".
+          "(alias=$address)(gosaMailAlternateAddress=$address)))", array("uid"));
 
       if ($ldap->count() > 0){
         $attrs= $ldap->fetch ();
@@ -1119,8 +1139,8 @@ class mailAccount extends plugin
 
   function allow_remove()
   {
-    if (isset($this->config->current['MAILMETHOD'])){
-      $method= $this->config->current['MAILMETHOD'];
+    if ($this->config->get_cfg_value("mailmethod") != ""){
+      $method= $this->config->get_cfg_value("mailmethod");
       if(preg_match("/olab/i",$method)){
         $ldap = $this->config->get_ldap_link();
         $ldap->cd($this->config->current['BASE']);