New page to add users in the database
[platal.git] / modules / lists.php
index e00ecc0..8266f50 100644 (file)
@@ -81,7 +81,7 @@ class ListsModule extends PLModule
 
         function filter_member($list)
         {
-            return $list['ins'];
+            return $list['sub'];
         }
 
         $this->prepare_client($page);
@@ -404,8 +404,7 @@ class ListsModule extends PLModule
                         ."    Sujet : « {$mail['subj']} »\n"
                         ."    Date  : ".strftime("le %d %b %Y à %H:%M:%S", (int)$mail['stamp'])."\n\n"
                         .$append;
-            require_once 'diogenes/diogenes.hermes.inc.php';
-            $mailer = new HermesMailer();
+            $mailer = new PlMailer();
             $mailer->addTo("$liste-owner@{$domain}");
             $mailer->setFrom("$liste-bounces@{$domain}");
             $mailer->addHeader('Reply-To', "$liste-owner@{$domain}");
@@ -436,12 +435,16 @@ class ListsModule extends PLModule
             $this->client->handle_request($liste,Env::v('sadd'),4,'');
             pl_redirect('lists/moderate/'.$liste);
         }
-
         if (Post::has('sdel')) { /* 2 = REJECT */
             $this->client->handle_request($liste,Post::v('sdel'),2,Post::v('reason'));
         }
 
-        if (Env::has('mid')) {
+        if (Post::has('moderate_mails') && Post::has('select_mails')) {
+            $mails = array_keys(Post::v('select_mails'));
+            foreach($mails as $mail) {
+                $this->moderate_mail($domain, $liste, $mail);
+            }
+        } elseif (Env::has('mid')) {
             $mail = $this->moderate_mail($domain, $liste, Env::i('mid'));
 
             if (Get::has('mid') && is_array($mail)) {
@@ -451,6 +454,7 @@ class ListsModule extends PLModule
                 $msg = str_replace("%(reason)s",    "<< TON EXPLICATION >>",  $msg);
                 $msg = str_replace("%(listname)s",  $liste, $msg);
 
+                $mail['stamp'] = strftime("%Y%m%d%H%M%S", $mail['stamp']);
                 $page->assign('msg', $msg);
             
                 $page->changeTpl('listes/moderate_mail.tpl');
@@ -458,7 +462,6 @@ class ListsModule extends PLModule
                 return;
             }   
         } elseif (Env::has('sid')) {
-
             if (list($subs,$mails) = $this->client->get_pending_ops($liste)) {
                 foreach($subs as $user) {
                     if ($user['id'] == Env::v('sid')) {
@@ -472,6 +475,9 @@ class ListsModule extends PLModule
         }
 
         if (list($subs,$mails) = $this->client->get_pending_ops($liste)) {
+            foreach ($mails as $key=>$mail) {
+                $mails[$key]['stamp'] = strftime("%Y%m%d%H%M%S", $mail['stamp']);
+            }
             $page->assign_by_ref('subs', $subs);
             $page->assign_by_ref('mails', $mails);
         } else {
@@ -543,7 +549,9 @@ class ListsModule extends PLModule
             $page->assign('np_m', count($mem));
 
         } else {
-            $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer");
+            $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer.<br />"
+                       ." Si tu penses qu'il s'agit d'une erreur, "
+                       ."<a href='mailto:support@polytechnique.org'>contact le support</a>");
         }
     }
 
@@ -600,23 +608,36 @@ class ListsModule extends PLModule
 
     function handler_delete(&$page, $liste = null)
     {
+        global $globals;
         if (is_null($liste)) {
             return PL_NOT_FOUND;
         }
 
-        $this->prepare_client($page);
+        $domain = $this->prepare_client($page);
+        if ($domain == $globals->mail->domain || $domain == $globals->mail->domain2) {
+            $domain = '';
+            $table  = 'aliases';
+            $type   = 'liste';
+        } else {
+            $domain = '@' . $domain;
+            $table  = 'virtual';
+            $type   = 'list';
+        }
 
         $page->changeTpl('listes/delete.tpl');
-
-        if (Post::v('valid') == 'OUI'
-        && $this->client->delete_list($liste, Post::b('del_archive')))
-        {
-            foreach (array('', '-owner', '-admin', '-bounces') as $app) {
-                XDB::execute("DELETE FROM  aliases
-                                              WHERE  type='liste' AND alias='{?}'",
-                                       $liste.$app);
+        if (Post::v('valid') == 'OUI') {
+            if ($this->client->delete_list($liste, Post::b('del_archive'))) {
+                foreach (array('', '-owner', '-admin', '-bounces') as $app) {
+                    XDB::execute("DELETE FROM  $table
+                                        WHERE  type={?} AND alias={?}",
+                                 $type, $liste.$app.$domain);
+                }
+                $page->assign('deleted', true);
+            } else {
+                $page->kill('Une erreur est survenue lors de la suppression de la liste.<br />'
+                         . 'Contact les administrateurs du site pour régler le problème : '
+                         . '<a href="mailto:support@polytechnique.org">support@polytechnique.org</a>');
             }
-            $page->assign('deleted', true);
         } elseif (list($details,$options) = $this->client->get_owner_options($liste)) {
             $page->assign_by_ref('details', $details);
             $page->assign_by_ref('options', $options);