Code

Updated table summary
[gosa.git] / gosa-plugins / mail / personal / mail / class_mailAccount.inc
index 3dcc585ea3111b22cf3076aca1decf5509478f5c..5be08f55851775a09c7fd643d8aca6760119ac26 100644 (file)
@@ -23,7 +23,6 @@ Functions :
  - addAlternate($address)
  - delAlternate($addresses)
  - prepare_vacation_template($contents)
- - display_forward_dialog()
  - remove_from_parent()
  - save()
  - check()
@@ -75,7 +74,7 @@ class mailAccount extends plugin
   var $sieveManagementUsed = FALSE;
   var $vacationTemplates = array();
   var $sieve_management = NULL;
-  var $forward_dialog = FALSE;
+  var $mailAddressSelect = FALSE;
   var $initial_uid    = "";
   var $mailDomainPart = "";
   var $mailDomainParts = array();
@@ -192,17 +191,6 @@ class mailAccount extends plugin
       $this->sieve_management = new sieveManagement($this->config,$this->dn,$this,$this->mailMethod->getUAttrib());
     }
 
-    /* Get global filter config used in add local forward
-     */
-    if (!session::is_set("mailfilter")){
-      $ui= get_userinfo();
-      $base= get_base_from_people($ui->dn);
-      $mailfilter= array( "depselect"       => $base,
-          "muser"            => "",
-          "regex"           => "*");
-      session::set("mailfilter", $mailfilter);
-    }
-
     /* Disconnect mailMethod. Connect on demand later. 
      */
     $this->mailMethod->disconnect();
@@ -256,9 +244,9 @@ class mailAccount extends plugin
         } else {
           $reason = "";
           if(!$this->mailMethod->accountCreateable($reason)){
-            $display= $this->show_disable_header(msgPool::addFeaturesButton(_("Mail")),$reason ,TRUE,TRUE);
+            $display= $this->show_enable_header(msgPool::addFeaturesButton(_("Mail")),$reason ,TRUE,TRUE);
           }else{
-            $display= $this->show_disable_header(msgPool::addFeaturesButton(_("Mail")),msgPool::featuresDisabled(_("Mail")));
+            $display= $this->show_enable_header(msgPool::addFeaturesButton(_("Mail")),msgPool::featuresDisabled(_("Mail")));
           }
           return ($display);
         }
@@ -291,31 +279,45 @@ class mailAccount extends plugin
     /****************
       Forward addresses 
      ****************/
+
     if (isset($_POST['add_local_forwarder'])){
-      $this->forward_dialog= TRUE;
+      $this->mailAddressSelect=  new mailAddressSelect($this->config, get_userinfo());
       $this->dialog= TRUE;
     }
-    if (isset($_POST['add_locals_cancel'])){
-      $this->forward_dialog= FALSE;
+    if (isset($_POST['mailAddressSelect_cancel'])){
+      $this->mailAddressSelect= FALSE;
       $this->dialog= FALSE;
     }
-    if (isset($_POST['add_locals_finish'])){
-      if (isset($_POST['local_list'])){
-        if($this->acl_is_writeable("gosaMailForwardingAddress")){
-          foreach ($_POST['local_list'] as $val){
-            if (!in_array ($val, $this->gosaMailAlternateAddress) &&
-                $val != $this->mail){
-              $this->addForwarder($val);
-              $this->is_modified= TRUE;
-            }
+
+    if (isset($_POST['mailAddressSelect_save']) && $this->mailAddressSelect instanceOf mailAddressSelect){
+
+      if($this->acl_is_writeable("gosaMailForwardingAddress")){
+        $list = $this->mailAddressSelect->save();
+        foreach ($list as $entry){
+          $val = $entry['mail'][0];
+          if (!in_array ($val, $this->gosaMailAlternateAddress) && $val != $this->mail){
+            $this->addForwarder($val);
+            $this->is_modified= TRUE;
           }
         }
-        $this->forward_dialog= FALSE;
+        $this->mailAddressSelect= FALSE;
         $this->dialog= FALSE;
       } else {
         msg_dialog::display(_("Error"), _("Please select an entry!"), ERROR_DIALOG);
       }
     }
+
+    if($this->mailAddressSelect instanceOf mailAddressSelect){
+      $used  = array();
+      $used['mail'] = array_values($this->gosaMailAlternateAddress);  
+      $used['mail'] = array_merge($used['mail'], array_values($this->gosaMailForwardingAddress));  
+      $used['mail'][] = $this->mail;
+
+      // Build up blocklist
+      session::set('filterBlacklist', $used);
+      return($this->mailAddressSelect->execute());
+    }
+
     if (isset($_POST['add_forwarder'])){
       if ($_POST['forward_address'] != ""){
         $address= $_POST['forward_address'];
@@ -346,8 +348,9 @@ class mailAccount extends plugin
     if (isset($_POST['delete_forwarder'])){
       $this->delForwarder ($_POST['forwarder_list']);
     }
-    if ($this->forward_dialog){
-      return($this->display_forward_dialog());
+    if ($this->mailAddressSelect instanceOf mailAddressSelect){
+    
+      return($this->mailAddressSelect->execute());
     }
 
 
@@ -396,10 +399,9 @@ class mailAccount extends plugin
     $smarty->assign("isModifyableServer", $this->mailMethod->isModifyableServer());
     $smarty->assign("mailEqualsCN", $this->mailMethod->mailEqualsCN());
 
-    $SkipWrite = (!isset($this->parent) || !$this->parent) && !session::is_set('edit');
     $tmp  = $this->plInfo();
     foreach($tmp['plProvidedAcls'] as $name => $transl){
-      $smarty->assign("$name"."ACL", $this->getacl($name,$SkipWrite));
+      $smarty->assign("$name"."ACL", $this->getacl($name));
     }
     foreach($this->attributes as $attr){
       $smarty->assign($attr,$this->$attr);
@@ -743,6 +745,10 @@ class mailAccount extends plugin
       }
 
       foreach ($attrs as $val){
+
+        // We can only replace strings here
+        if(!is_string($obj->$val)) continue;
+
         if(preg_match("/dateOfBirth/",$val)){
           if($obj->use_dob){
             $contents= preg_replace("/%$val/",date("Y-d-m",$obj->dateOfBirth),$contents);
@@ -759,90 +765,6 @@ class mailAccount extends plugin
   }
 
 
-  /*! \brief  Displays a dialog that allows mail address selection.
-   */ 
-  function display_forward_dialog()
-  {
-    restore_error_handler();
-
-    $smarty = get_smarty();
-    $ldap= $this->config->get_ldap_link();
-
-    /* Save data */
-    $mailfilter= session::get("mailfilter");
-    foreach( array("depselect", "muser", "regex") as $type){
-      if (isset($_POST[$type])){
-        $mailfilter[$type]= $_POST[$type];
-      }
-    }
-    if (isset($_GET['search'])){
-      $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
-      if ($s == "**"){
-        $s= "*";
-      }
-      $mailfilter['regex']= $s;
-    }
-    session::set("mailfilter", $mailfilter);
-
-    /* Get actual list */
-    $mailusers= array ();
-    if ($mailfilter['regex'] != '*' && $mailfilter['regex'] != ""){
-      $regex= $mailfilter['regex'];
-      $filter= "(|(mail=$regex)(gosaMailAlternateAddress=$regex))";
-    } else {
-      $filter= "";
-    }
-    if ($mailfilter['muser'] != ""){
-      $user= $mailfilter['muser'];
-      $filter= "$filter(|(uid=$user)(cn=$user)(givenName=$user)(sn=$user))";
-    }
-
-    /* Add already present people to the filter */
-    $exclude= "";
-    foreach ($this->gosaMailForwardingAddress as $mail){
-      $exclude.= "(mail=$mail)";
-    }
-    if ($exclude != ""){
-      $filter.= "(!(|$exclude))";
-    }
-    $res= get_list("(&(objectClass=gosaMailAccount)$filter)", "users", $mailfilter['depselect'],
-        array("sn", "mail", "givenName"), GL_SIZELIMIT | GL_SUBSEARCH);
-    $ldap->cd($mailfilter['depselect']);
-    $ldap->search ("(&(objectClass=gosaMailAccount)$filter)", array("sn", "mail", "givenName"));
-    while ($attrs= $ldap->fetch()){
-      if(preg_match('/%/', $attrs['mail'][0])){
-        continue;
-      }
-      $name= $this->make_name($attrs);
-      $mailusers[$attrs['mail'][0]]= $name."<".
-        $attrs['mail'][0].">";
-    }
-    natcasesort ($mailusers);
-    reset ($mailusers);
-
-    /* Show dialog */
-    $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/lists/action.png'));
-    $smarty->assign("mailusers", $mailusers);
-    if (isset($_POST['depselect'])){
-      $smarty->assign("depselect", $_POST['depselect']);
-    }
-    $smarty->assign("deplist", $this->config->idepartments);
-    $smarty->assign("apply", apply_filter());
-    $smarty->assign("alphabet", generate_alphabet());
-    $smarty->assign("hint", print_sizelimit_warning());
-    foreach( array("depselect", "muser", "regex") as $type){
-      $smarty->assign("$type", $mailfilter[$type]);
-    }
-    $smarty->assign("hint", print_sizelimit_warning());
-    $display= $smarty->fetch (get_template_path('mail_locals.tpl', TRUE, dirname(__FILE__)));
-    return ($display);
-  }
-
-
   /*! \brief  Removes the mailAccount extension from ldap 
    */  
   function remove_from_parent()
@@ -953,9 +875,9 @@ class mailAccount extends plugin
       unset($this->attrs['gosaVacationStop']);
     } else {
       /* Adapt values to be timestamps */
-      list($day, $month, $year)= split('\.', $this->gosaVacationStart);
+      list($day, $month, $year)= explode('.', $this->gosaVacationStart);
       $this->attrs['gosaVacationStart']= mktime(0,0,0,$month, $day, $year);
-      list($day, $month, $year)= split('\.', $this->gosaVacationStop);
+      list($day, $month, $year)= explode('.', $this->gosaVacationStop);
       $this->attrs['gosaVacationStop']= mktime(0,0,0,$month, $day, $year);
     }
 
@@ -1147,9 +1069,9 @@ class mailAccount extends plugin
 
       #TODO: take care of date format
       if ($state) {
-        list($day, $month, $year)= split('\.', $this->gosaVacationStart);
+        list($day, $month, $year)= explode('.', $this->gosaVacationStart);
         $start= mktime(0,0,0,$month, $day, $year);
-        list($day, $month, $year)= split('\.', $this->gosaVacationStop);
+        list($day, $month, $year)= explode('.', $this->gosaVacationStop);
         $stop= mktime(0,0,0,$month, $day, $year);
         if($start > $stop){
           $message[]= msgPool::invalid(_("Vacation interval"));
@@ -1186,6 +1108,15 @@ class mailAccount extends plugin
       }
     }
     $this->mail= strtolower(rewrite($this->mail));
+
+    // Fix mail address when using templates
+    if($this->is_account && $this->mailMethod->domainSelectionEnabled()){
+      $this->mailDomainPart = preg_replace("/^[^@]*+@/","",$this->mail);
+      $this->mail = preg_replace("/@.*$/","\\1",$this->mail);
+      if(!in_array($this->mailDomainPart,$this->mailDomainParts)){
+        $this->mailDomainParts[] = $this->mailDomainPart;
+      }
+    }
   }
 
 
@@ -1318,9 +1249,9 @@ class mailAccount extends plugin
 
       #TODO: take care of date format
       if ($state) {
-        list($day, $month, $year)= split('\.', $this->gosaVacationStart);
+        list($day, $month, $year)= explode('.', $this->gosaVacationStart);
         $start= mktime(0,0,0,$month, $day, $year);
-        list($day, $month, $year)= split('\.', $this->gosaVacationStop);
+        list($day, $month, $year)= explode('.', $this->gosaVacationStop);
         $stop= mktime(0,0,0,$month, $day, $year);
         if($start > $stop){
           $message[]= msgPool::invalid(_("Vacation interval"));