new mailing list interface
authorx2000habouzit <x2000habouzit>
Thu, 14 Oct 2004 22:16:01 +0000 (22:16 +0000)
committerx2000habouzit <x2000habouzit>
Thu, 14 Oct 2004 22:16:01 +0000 (22:16 +0000)
htdocs/listes/index.php
include/inscription_listes_base.inc.php
include/newsletter.inc.php [new file with mode: 0644]
scripts/mailman/mailman-rpc.py

index fc2a678..7d55a4e 100644 (file)
  *  Foundation, Inc.,                                                      *
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
  ***************************************************************************
-        $Id: index.php,v 1.7 2004-10-10 13:51:15 x2000habouzit Exp $
+        $Id: index.php,v 1.8 2004-10-14 22:16:01 x2000habouzit Exp $
  ***************************************************************************/
 
 require("auto.prepend.inc.php");
 new_skinned_page('listes/index.tpl', AUTH_MDP);
 include('xml-rpc-client.inc.php');
+include('newsletter.inc.php');
 
 $res = $globals->db->query("SELECT password FROM auth_user_md5 WHERE user_id={$_SESSION['uid']}");
 list($pass) = mysql_fetch_row($res);
@@ -44,12 +45,11 @@ if(isset($_POST['promo_add'])) {
        $client->subscribe('polytechnique.org',"promo$promo");
     }
 }
-if(!empty($_GET['nl_unsub'])) $client->unsubscribe_nl();
-if(!empty($_GET['nl_sub']))   $client->subscribe_nl();
+if(!empty($_GET['nl_unsub'])) unsubscribe_nl();
+if(!empty($_GET['nl_sub']))   subscribe_nl();
 
 $listes = $client->get_lists('polytechnique.org');
-$nl = $client->get_nl_state();
 $page->assign_by_ref('listes',$listes);
-$page->assign('nl',$nl);
+$page->assign('nl',get_nl_state());
 $page->run();
 ?>
index e90b556..e6a9f92 100644 (file)
  *  Foundation, Inc.,                                                      *
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
  ***************************************************************************
-        $Id: inscription_listes_base.inc.php,v 1.3 2004-10-10 13:51:17 x2000habouzit Exp $
+        $Id: inscription_listes_base.inc.php,v 1.4 2004-10-14 22:16:01 x2000habouzit Exp $
  ***************************************************************************/
 
 include('xml-rpc-client.inc.php');
+include('newsletter.inc.php');
 
 /** inscrit l'uid donnée à la promo
  * @param $uid UID
@@ -35,7 +36,7 @@ function inscription_listes_base($uid,$pass,$promo) {
   // récupération de l'id de la liste promo
   $client = new xmlrpc_client("http://$uid:$pass@localhost:4949");
   $client->subscribe('polytechnique.org',"promo$promo");
-  $client->subscribe_nl();
+  subscribe_nl();
 }
 
 ?>
diff --git a/include/newsletter.inc.php b/include/newsletter.inc.php
new file mode 100644 (file)
index 0000000..432e8c3
--- /dev/null
@@ -0,0 +1,46 @@
+<?php
+/***************************************************************************
+ *  Copyright (C) 2003-2004 Polytechnique.org                              *
+ *  http://opensource.polytechnique.org/                                   *
+ *                                                                         *
+ *  This program is free software; you can redistribute it and/or modify   *
+ *  it under the terms of the GNU General Public License as published by   *
+ *  the Free Software Foundation; either version 2 of the License, or      *
+ *  (at your option) any later version.                                    *
+ *                                                                         *
+ *  This program is distributed in the hope that it will be useful,        *
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
+ *  GNU General Public License for more details.                           *
+ *                                                                         *
+ *  You should have received a copy of the GNU General Public License      *
+ *  along with this program; if not, write to the Free Software            *
+ *  Foundation, Inc.,                                                      *
+ *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
+ ***************************************************************************
+        $Id: newsletter.inc.php,v 1.1 2004-10-14 22:16:01 x2000habouzit Exp $
+ ***************************************************************************/
+
+class NewsLetter {
+    function NewsLetter() { }
+}
+
+function get_nl_state() {
+    global $globals;
+    $res = $globals->db->query("SELECT COUNT(*)>0 FROM newsletter_ins WHERE user_id={$_SESSION['uid']}");
+    list($b) = mysql_fetch_row($res);
+    mysql_free_result($res);
+    return $b;
+}
+function unsubscribe_nl() {
+    global $globals;
+    $globals->db->query("DELETE FROM newsletter_ins WHERE user_id={$_SESSION['uid']}");
+}
+function subscribe_nl() {
+    global $globals;
+    $globals->db->query("INSERT INTO newsletter_ins (user_id) VALUES ({$_SESSION['uid']})");
+}
+?>
index e0b6e17..cb59edf 100755 (executable)
@@ -18,7 +18,7 @@
 #*  Foundation, Inc.,                                                      *
 #*  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
 #***************************************************************************
-#   $Id: mailman-rpc.py,v 1.58 2004-10-13 10:05:00 x2000habouzit Exp $
+#   $Id: mailman-rpc.py,v 1.59 2004-10-14 22:16:01 x2000habouzit Exp $
 #***************************************************************************
 
 import base64, MySQLdb, os, getopt, sys, MySQLdb.converters, sha
@@ -215,7 +215,7 @@ def get_lists((userdesc,perms),vhost):
     names.sort()
     result = []
     for name in names:
-        if not name.startswith(prefix) or name == mm_cfg.MAIN_NEWSLETTER:
+        if not name.startswith(prefix):
             continue
         try:
             mlist = MailList.MailList(name,lock=0)
@@ -265,47 +265,6 @@ def unsubscribe((userdesc,perms),vhost,listname):
         mlist.Unlock()
         return 0
 
-def subscribe_nl((userdesc,perms)):
-    try:
-        mlist = MailList.MailList(mm_cfg.MAIN_NEWSLETTER,lock=0)
-    except:
-        return 0
-    try:
-        mlist.Lock()
-        mlist.ApprovedAddMember(userdesc,0,0)
-        mlist.Save()
-        mlist.Unlock()
-        return 1
-    except:
-        mlist.Unlock()
-        return 0
-
-def unsubscribe_nl((userdesc,perms)):
-    try:
-        mlist = MailList.MailList(mm_cfg.MAIN_NEWSLETTER,lock=0)
-    except:
-        return 0
-    try:
-        mlist.Lock()
-        mlist.ApprovedDeleteMember(userdesc.address,0,0)
-        mlist.Save()
-        mlist.Unlock()
-        return 1
-    except:
-        mlist.Unlock()
-        return 0
-
-def get_nl_state((userdesc,perms)):
-    try:
-        mlist = MailList.MailList(mm_cfg.MAIN_NEWSLETTER,lock=0)
-    except:
-        return 0
-    try:
-        return ( userdesc.address in mlist.getRegularMemberKeys() )
-    except:
-        return 0
-
-
 #-------------------------------------------------------------------------------
 # users procedures for [ index.php ]
 #
@@ -776,9 +735,6 @@ server = FastXMLRPCServer(("localhost", 4949), BasicAuthXMLRPCRequestHandler)
 server.register_function(get_lists)
 server.register_function(subscribe)
 server.register_function(unsubscribe)
-server.register_function(subscribe_nl)
-server.register_function(unsubscribe_nl)
-server.register_function(get_nl_state)
 # members.php
 server.register_function(get_members)
 # trombi.php