Merge commit 'origin/fusionax' into account
[platal.git] / modules / lists.php
index 78fba96..fa3232b 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2008 Polytechnique.org                              *
+ *  Copyright (C) 2003-2009 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
@@ -31,6 +31,7 @@ class ListsModule extends PLModule
             'lists/create'    => $this->make_hook('create',    AUTH_MDP),
 
             'lists/members'   => $this->make_hook('members',   AUTH_COOKIE),
+            'lists/csv'       => $this->make_hook('csv',       AUTH_COOKIE),
             'lists/annu'      => $this->make_hook('annu',      AUTH_COOKIE),
             'lists/archives'  => $this->make_hook('archives',  AUTH_COOKIE),
             'lists/archives/rss' => $this->make_hook('rss',    AUTH_PUBLIC, 'user', NO_HTTPS),
@@ -46,13 +47,16 @@ class ListsModule extends PLModule
         );
     }
 
-    function prepare_client(&$page)
+    function prepare_client(&$page, $user = null)
     {
         global $globals;
 
         $this->load('lists.inc.php');
+        if (is_null($user)) {
+            $user = S::user();
+        }
 
-        $this->client = new MMList(S::v('uid'), S::v('password'));
+        $this->client = new MMList($user);
         return $globals->mail->domain;
     }
 
@@ -337,6 +341,25 @@ class ListsModule extends PLModule
         }
     }
 
+    function handler_csv(PlPage &$page, $liste = null)
+    {
+        if (is_null($liste)) {
+            return PL_NOT_FOUND;
+        }
+        $this->prepare_client($page);
+        $members = $this->client->get_members($liste);
+        $list = list_fetch_names(list_extract_members($members[1]));
+        header('Content-Type: text/x-csv; charset=utf-8;');
+        header('Pragma: ');
+        header('Cache-Control: ');
+
+        echo "email,nom,prenom,promo\n";
+        foreach ($list as $member) {
+            echo @$member['email'] . ',' . @$member['nom'] . ',' . @$member['prenom'] . ',' . @$member['promo'] . "\n";
+        }
+        exit;
+    }
+
     function handler_annu(&$page, $liste = null, $action = null, $subaction = null)
     {
         if (is_null($liste)) {
@@ -416,27 +439,22 @@ class ListsModule extends PLModule
 
     function handler_rss(&$page, $liste = null, $alias = null, $hash = null)
     {
-        require_once('rss.inc.php');
-        $uid = init_rss(null, $alias, $hash);
-        if (!$uid || !$liste) {
-            exit;
+        if (!$liste) {
+            return PL_NOT_FOUND;
+        }
+        $user = Platal::session()->tokenAuth($alias, $hash);
+        if (is_null($user)) {
+            return PL_FORBIDDEN;
         }
 
-        $res = XDB::query("SELECT user_id AS uid, password, alias AS forlife
-                             FROM auth_user_md5 AS u
-                       INNER JOIN aliases       AS a ON (a.id = u.user_id AND a.type = 'a_vie')
-                            WHERE u.user_id = {?}", $uid);
-        $row = $res->fetchOneAssoc();
-        $_SESSION = array_merge($row, $_SESSION);
-
-        $domain = $this->prepare_client($page);
+        $domain = $this->prepare_client($page, $user);
         if (list($det) = $this->client->get_members($liste)) {
             if (substr($liste,0,5) != 'promo' && ($det['ins'] || $det['priv'])
                     && !$det['own'] && ($det['sub'] < 2)) {
                 exit;
             }
             require_once('banana/ml.inc.php');
-            $banana = new MLBanana(S::user(), Array('listname' => $liste, 'domain' => $domain, 'action' => 'rss2'));
+            $banana = new MLBanana($user, Array('listname' => $liste, 'domain' => $domain, 'action' => 'rss2'));
             $banana->run();
         }
         exit;
@@ -876,12 +894,13 @@ class ListsModule extends PLModule
         }
     }
 
-    function handler_admin_all(&$page) {
+    function handler_admin_all(&$page)
+    {
         $page->changeTpl('lists/admin_all.tpl');
         $page->setTitle('Administration - Mailing lists');
 
-        $client = new MMList(S::v('uid'), S::v('password'));
-        $listes = $client->get_all_lists();
+        $this->prepare_client($page);
+        $listes = $this->client->get_all_lists();
         $page->assign_by_ref('listes', $listes);
     }
 }