Activate message sources visualisation for the admins
[platal.git] / modules / lists.php
index e00ecc0..8375dbc 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2006 Polytechnique.org                              *
+ *  Copyright (C) 2003-2007 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
@@ -61,17 +61,6 @@ class ListsModule extends PLModule
         return $globals->mail->domain;
     }
 
-    function clean_html($res)
-    {
-        $res = html_entity_decode($res);
-        $res = preg_replace('@<a[^>]*href=["\']([^ >]+)["\'][^>]*>([^<]*)</a>@ie',
-                            "'\\2 [' . htmlentities('\\1') . ']'", $res);
-        $res = preg_replace("@<(/br|p|/div)[^>]*>(\\s*\n)?@i", "\n", $res); 
-        $res = trim(strip_tags($res));
-        $res = preg_replace("/\n(\\s*\n)+/", "\n\n", $res);
-        return $res;
-    }
-
     function handler_lists(&$page)
     {
         function filter_owner($list)
@@ -81,12 +70,12 @@ class ListsModule extends PLModule
 
         function filter_member($list)
         {
-            return $list['ins'];
+            return $list['sub'];
         }
 
         $this->prepare_client($page);
 
-        $page->changeTpl('listes/index.tpl');
+        $page->changeTpl('lists/index.tpl');
         $page->addJsLink('ajax.js');
         $page->assign('xorg_title','Polytechnique.org - Listes de diffusion');
 
@@ -127,7 +116,7 @@ class ListsModule extends PLModule
     {
         header('Content-Type: text/html; charset="iso-8859-15"');
         $domain = $this->prepare_client($page);
-        $page->changeTpl('listes/liste.inc.tpl', NO_SKIN);
+        $page->changeTpl('lists/liste.inc.tpl', NO_SKIN);
         if (Get::has('unsubscribe')) {
             $this->client->unsubscribe($list);
         }
@@ -153,7 +142,7 @@ class ListsModule extends PLModule
 
     function handler_create(&$page)
     {
-        $page->changeTpl('listes/create.tpl');
+        $page->changeTpl('lists/create.tpl');
 
         $owners  = preg_split("/[\s]+/", Post::v('owners'), -1, PREG_SPLIT_NO_EMPTY);
         $members = preg_split("/[\s]+/", Post::v('members'), -1, PREG_SPLIT_NO_EMPTY);
@@ -243,7 +232,7 @@ class ListsModule extends PLModule
 
         $this->prepare_client($page);
 
-        $page->changeTpl('listes/members.tpl');
+        $page->changeTpl('lists/members.tpl');
 
         if (Get::has('del')) {
             $this->client->unsubscribe($liste);
@@ -302,7 +291,7 @@ class ListsModule extends PLModule
 
         $this->prepare_client($page);
 
-        $page->changeTpl('listes/trombi.tpl');
+        $page->changeTpl('lists/trombi.tpl');
 
         if (Get::has('del')) {
             $this->client->unsubscribe($liste);
@@ -328,7 +317,7 @@ class ListsModule extends PLModule
         }
     }
 
-    function handler_archives(&$page, $liste = null)
+    function handler_archives(&$page, $liste = null, $action = null, $artid = null)
     {
         global $globals;
 
@@ -338,35 +327,45 @@ class ListsModule extends PLModule
 
         $domain = $this->prepare_client($page);
 
-        $page->changeTpl('listes/archives.tpl');
+        $page->changeTpl('lists/archives.tpl');
 
-        $page->addCssLink('lists.archives.css');
         if (list($det) = $this->client->get_members($liste)) {
             if (substr($liste,0,5) != 'promo' && ($det['ins'] || $det['priv'])
-            && !$det['own'] && ($det['sub'] < 2))
-            {
+                    && !$det['own'] && ($det['sub'] < 2)) {
                 $page->kill("La liste n'existe pas ou tu n'as pas le droit de la consulter");
-            } elseif (Get::has('file')) {
-                $file = Get::v('file');
-                $rep  = Get::v('rep');
-                if (strstr('/', $file)!==false || !preg_match(',^\d+/\d+$,', $rep)) {
-                    $page->kill("La liste n'existe pas ou tu n'as pas le droit de la consulter");
-                } else { 
-                    $page->assign('archives', $globals->lists->spool
-                                  ."/{$domain}{$globals->lists->vhost_sep}$liste/$rep/$file");
-                }
-            } else {
-                $archs = Array();
-                foreach (glob($globals->lists->spool
-                              ."/{$domain}{$globals->lists->vhost_sep}$liste/*/*") as $rep)
-                {
-                    if (preg_match(",/(\d*)/(\d*)$,", $rep, $matches)) {
-                        $archs[intval($matches[1])][intval($matches[2])] = true;
+            }
+            $get = Array('listname' => $liste, 'domain' => $domain);
+            if (Post::has('updateall')) {
+                $get['updateall'] = Post::v('updateall');
+            }
+            if (!is_null($action)) {
+                if ($action == 'new') {
+                    $get['action'] = 'new';
+                } elseif (!is_null($artid)) {
+                    $get['artid'] = $artid;
+                    if ($action == 'reply') {
+                        $get['action'] = 'new';
+                    } elseif ($action == 'cancel') {
+                        $get['action'] = $action;
+                    } elseif ($action == 'from') {
+                        $get['first'] = $artid;
+                        unset($get['artid']);
+                    } elseif ($action == 'read') {
+                        $get['part']  = @$_GET['part'];
+                    } elseif ($action == 'source') {
+                        $get['part'] = 'source';
+                    } elseif ($action == 'xface') {
+                        $get['part']  = 'xface';
+                    } elseif ($action) {
+                        $get['part'] = str_replace('.', '/', $action);
                     }
                 }
-                $page->assign('archs', $archs);
-                $page->assign('range', range(1,12));
             }
+            require_once('banana/ml.inc.php');
+            $banana = new MLBanana($get);
+            $page->assign('banana', $banana->run());
+            $page->addCssInline($banana->css());
+            $page->addCssLink('banana.css');
         } else {
             $page->kill("La liste n'existe pas ou tu n'as pas le droit de la consulter");
         }
@@ -404,8 +403,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}");
@@ -426,43 +424,50 @@ class ListsModule extends PLModule
 
         $domain = $this->prepare_client($page);
 
-        $page->changeTpl('listes/moderate.tpl');
+        $page->changeTpl('lists/moderate.tpl');
 
-        $page->register_modifier('qpd', 'quoted_printable_decode');
         $page->register_modifier('hdc', 'list_header_decode');
-        $page->register_modifier('clean_html', array($this, 'clean_html'));
 
         if (Env::has('sadd')) { /* 4 = SUBSCRIBE */
             $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')) {
-            $mail = $this->moderate_mail($domain, $liste, Env::i('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')) {
+            if (Get::has('mid')) {
+                require_once('banana/moderate.inc.php');
+                $params = array('listname' => $liste, 'domain' => $domain, 'artid' => Get::i('mid'), 'part' => Get::v('part'));
+                $banana = new ModerationBanana($params, $this->client);
+                $res    = $banana->run();
+                $page->addCssInline($banana->css());
 
-            if (Get::has('mid') && is_array($mail)) {
                 $msg = file_get_contents('/etc/mailman/fr/refuse.txt');
                 $msg = str_replace("%(adminaddr)s", "$liste-owner@{$domain}", $msg);
                 $msg = str_replace("%(request)s",   "<< SUJET DU MAIL >>",    $msg);
                 $msg = str_replace("%(reason)s",    "<< TON EXPLICATION >>",  $msg);
                 $msg = str_replace("%(listname)s",  $liste, $msg);
-
                 $page->assign('msg', $msg);
-            
-                $page->changeTpl('listes/moderate_mail.tpl');
-                $page->assign_by_ref('mail', $mail);
+
+                $page->addCssLink('banana.css');
+                $page->changeTpl('lists/moderate_mail.tpl');
+                $page->assign_by_ref('mail', $res);
                 return;
-            }   
-        } elseif (Env::has('sid')) {
+            }
 
+            $mail = $this->moderate_mail($domain, $liste, Env::i('mid'));
+        } elseif (Env::has('sid')) {
             if (list($subs,$mails) = $this->client->get_pending_ops($liste)) {
                 foreach($subs as $user) {
                     if ($user['id'] == Env::v('sid')) {
-                        $page->changeTpl('listes/moderate_sub.tpl');
+                        $page->changeTpl('lists/moderate_sub.tpl');
                         $page->assign('del_user', $user);
                         return;
                     }
@@ -472,6 +477,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 {
@@ -489,7 +497,7 @@ class ListsModule extends PLModule
 
         $this->prepare_client($page);
 
-        $page->changeTpl('listes/admin.tpl');
+        $page->changeTpl('lists/admin.tpl');
 
         if (Env::has('add_member')) {
             require_once('user.func.inc.php');
@@ -543,7 +551,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>");
         }
     }
 
@@ -555,7 +565,7 @@ class ListsModule extends PLModule
 
         $this->prepare_client($page);
 
-        $page->changeTpl('listes/options.tpl');
+        $page->changeTpl('lists/options.tpl');
 
         if (Post::has('submit')) {
             $values = $_POST;
@@ -600,23 +610,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);
-
-        $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);
+        $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('lists/delete.tpl');
+        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);
@@ -634,7 +657,7 @@ class ListsModule extends PLModule
 
         $this->prepare_client($page);
 
-        $page->changeTpl('listes/soptions.tpl');
+        $page->changeTpl('lists/soptions.tpl');
 
         if (Post::has('submit')) {
             $values = $_POST;
@@ -660,7 +683,7 @@ class ListsModule extends PLModule
 
         $this->prepare_client($page);
 
-        $page->changeTpl('listes/check.tpl');
+        $page->changeTpl('lists/check.tpl');
 
         if (Post::has('correct')) {
             $this->client->check_options($liste, true);
@@ -675,7 +698,7 @@ class ListsModule extends PLModule
     }
 
     function handler_admin_all(&$page) {
-        $page->changeTpl('listes/admin_all.tpl');
+        $page->changeTpl('lists/admin_all.tpl');
         $page->assign('xorg_title','Polytechnique.org - Administration - Mailing lists');
 
         $client = new MMList(S::v('uid'), S::v('password'));