Code

Updated css und div framework.
[gosa.git] / plugins / admin / groups / class_groupMail.inc
index ce5ec423e47a96e40de78dac34a4cd192e3d14f7..03c9987d1affa5473b0e2659ecc479fc6ec661a5 100644 (file)
@@ -9,6 +9,7 @@ class mailgroup extends plugin
 
   var $uid                        = "";       // User id 
   var $cn                         = "";       // cn
+  var $orig_cn                    = "";       // cn
 
   var $method                     = "mailMethod"; // Used Mail method 
   var $mmethod                    = "";           // Contains the gosa.conf MAILMETHOD
@@ -40,7 +41,8 @@ class mailgroup extends plugin
   var $perms                      = array();
   var $gosaMailDeliveryMode       = "[L        ]";   // 
   var $gosaMailMaxSize            = "";       // 
-
+  
+  var $remove_folder_from_imap    = true;
 
   /* Helper */
   var $indexed_acl= array();
@@ -53,7 +55,7 @@ class mailgroup extends plugin
       "acl","gosaSharedFolderTarget", "gosaVacationMessage");
 
   var $objectclasses= array("gosaMailAccount");
-
+  var $CopyPasteVars          = array("quotaUsage","imapacl");
 
   function mailgroup ($config, $dn= NULL, $ui= NULL)
   {
@@ -61,6 +63,8 @@ class mailgroup extends plugin
      */
     plugin::plugin($config, $dn);
 
+    $this->orig_cn = $this->cn;
+
     /* Set mailMethod to the one defined in gosa.conf 
      */
     if (isset($this->config->current['MAILMETHOD'])){
@@ -286,6 +290,7 @@ class mailgroup extends plugin
     $this->perms["p"]= _("external post");
     $this->perms["lrsip"]= _("append");
     $this->perms["lrswipcd"]= _("write");
+    $this->perms[""]= _("none");
   }
 
   function execute()
@@ -317,10 +322,12 @@ class mailgroup extends plugin
       }
     }
 
+    $display = "";
 
     /* Do we represent a valid account? */
     if (!$this->is_account && $this->parent == NULL){
-      $display= "<img alt=\"\" src=\"images/stop.png\" align=middle>&nbsp;<b>".
+
+      $display.= "<img alt=\"\" src=\"images/stop.png\" align=middle>&nbsp;<b>".
         _("This 'dn' has no valid mail extensions.")."</b>";
       return ($display);
     }
@@ -329,11 +336,23 @@ class mailgroup extends plugin
     $display= "";
     if ($this->parent != NULL){
       if ($this->is_account){
-        $display= $this->show_disable_header(_("Remove mail account"),
+        $display.= $this->show_disable_header(_("Remove mail account"),
             _("This account has mail features enabled. You can disable them by clicking below."));
       } else {
-        $display= $this->show_enable_header(_("Create mail account"),
+        $display.= $this->show_enable_header(_("Create mail account"),
             _("This account has mail features disabled. You can enable them by clicking below."));
+  
+        /* Show checkbox that allows us to remove imap entry too*/
+        if($this->initially_was_account){
+          $c = "";
+          if($this->remove_folder_from_imap){
+            $c= " checked ";
+          }
+          $display .= "<h2>Shared folder delete options</h2>
+                       <input class='center' type='checkbox' name='remove_folder_from_imap' value='1' ".$c."
+                        title='"._("Remove shared folder from mail server database when entry gets removed in LDAP")."'>";
+          $display .= _("Remove the shared folder and all its contents after saving this account");
+        }
         return ($display);
       }
     }
@@ -547,6 +566,13 @@ class mailgroup extends plugin
           $Dis = " disabled ";
         }
   
+        /* Reset given Acls to ensure that nobody can read username and acls if not allwoed */
+        if(!preg_match("/r/",$perm)){
+          $user = "";
+          $nr   = "none";
+          $key  = "none";  
+        }
+
         $tmp.= "<tr>  
                  <td>
                   <input name=\"user_$nr\" size=20 maxlength=60 value=\"$user\" ".$Dis.">
@@ -636,18 +662,19 @@ class mailgroup extends plugin
 
     /* Connect to IMAP server for account deletion */
     if ($this->initially_was_account){
       $method= new $this->method($this->config);
-      if ($method->connect($this->gosaMailServer)){
+      $method->fixAttributesOnRemove($this);
+      if ($method->connect($this->gosaMailServer) && $this->remove_folder_from_imap){
+
         /* Remove account from IMAP server */
         $method->deleteMailbox($this->uid);
         $method->disconnect();
       }
-      $method->fixAttributesOnRemove($this);
     }
     /* Keep uid */
     unset ($this->attrs['uid']);
 
-
     $ldap->cd($this->dn);
     $ldap->modify ($this->attrs); 
     show_ldap_error($ldap->get_error(), sprintf(_("Removing of groups/mail with dn '%s' failed."),$this->dn));
@@ -660,6 +687,16 @@ class mailgroup extends plugin
   /* Save data to object */
   function save_object()
   {
+
+    /* Check if user wants to remove the shared folder from imap too */
+    if($this->initially_was_account && !$this->is_account){
+      if(isset($_POST['remove_folder_from_imap'])){
+        $this->remove_folder_from_imap = true;
+      }else{
+        $this->remove_folder_from_imap = false;
+      }
+    }
+
     /* Assemble mail delivery mode
        The mode field in ldap consists of values between braces, this must
        be called when 'mail' is set, because checkboxes may not be set when
@@ -784,17 +821,6 @@ I: Only insider delivery */
     }  
 
 
-    if ((!$this->is_template)&&(!empty($this->gosaMailServer))){
-      $method= new $this->method($this->config);
-      $method->fixAttributesOnStore($this);
-      if (($method->connect($this->gosaMailServer))){
-        $method->updateMailbox($this->uid);
-        $method->setQuota($this->uid, $this->gosaMailQuota);
-        $method->setSharedFolderPermissions($this->uid, $this->imapacl);
-        $method->disconnect();
-      }
-    }
-
     /* Exchange '%member%' pseudo entry */
     $memberacl= $this->imapacl['%members%'];
 
@@ -812,12 +838,37 @@ I: Only insider delivery */
       }
     }
     $this->attrs['acl'] = array();
+    
+    
     foreach($this->imapacl as $user => $acl){
-      if(preg_match("/%members%/",$user) || empty($user)) continue;
-      
+
+      /* Remove empty user entry, to avoid entry like this im imap 
+       *   "" lrs
+       */
+      if(empty($user)){
+        unset($this->imapacl[$user]);
+      }
+   
+      /* Skip invalid values */
+      if(preg_match("/%members%/",$user) || empty($user)){
+        continue;
+      }
+
+      /* Append ldap acl entries */
       $this->attrs['acl'][] = $user." ".$acl;
     }
 
+    if ((!$this->is_template)&&(!empty($this->gosaMailServer))){
+      $method= new $this->method($this->config);
+      $method->fixAttributesOnStore($this);
+      if (($method->connect($this->gosaMailServer))){
+        $method->updateMailbox($this->uid);
+        $method->setQuota($this->uid, $this->gosaMailQuota);
+        $method->setSharedFolderPermissions($this->uid, $this->imapacl);
+        $method->disconnect();
+      }
+    }
+
     /* Save data to LDAP */
     $ldap->cd($this->dn);
     $this->cleanup();
@@ -855,7 +906,7 @@ I: Only insider delivery */
     }
     $ldap->cd($this->config->current['BASE']);
     $ldap->search ("(&(!(objectClass=gosaUserTemplate))(objectClass=gosaMailAccount)(|(mail=".$this->mail.")(gosaMailAlternateAddress=".
-        $this->mail."))(!(uid=".$this->cn."))(!(cn=".$this->cn.")))");
+        $this->mail."))(!(uid=".$this->orig_cn."))(!(cn=".$this->orig_cn.")))");
     if ($ldap->count() != 0){
       $message[]= _("The primary address you've entered is already in use.");
     }
@@ -1021,6 +1072,15 @@ I: Only insider delivery */
   }
 
 
+  function PrepareForCopyPaste($source)
+  {
+    plugin::PrepareForCopyPaste($source);
+    /* Reset alternate mail addresses */
+    $this->gosaMailAlternateAddress = array();
+  }
+
+
   /* Return plugin informations for acl handling  */
   function plInfo()
   {