From 3e70524da07aa968d89bec35427824c4635201a2 Mon Sep 17 00:00:00 2001 From: x2000habouzit Date: Sun, 10 Oct 2004 13:51:13 +0000 Subject: [PATCH] enable auto subscribe code + treat the NL separate --- htdocs/inscription/step4.php | 15 +++++------ htdocs/listes/index.php | 6 ++++- include/inscription_listes_base.inc.php | 42 +++++------------------------- scripts/mailman/mailman-rpc.py | 46 +++++++++++++++++++++++++++++++-- templates/listes/index.tpl | 28 +++++++++++++++++++- 5 files changed, 88 insertions(+), 49 deletions(-) diff --git a/htdocs/inscription/step4.php b/htdocs/inscription/step4.php index a32d4a2..83ea022 100644 --- a/htdocs/inscription/step4.php +++ b/htdocs/inscription/step4.php @@ -18,7 +18,7 @@ * Foundation, Inc., * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * *************************************************************************** - $Id: step4.php,v 1.1 2004-09-06 09:58:59 x2000habouzit Exp $ + $Id: step4.php,v 1.2 2004-10-10 13:51:13 x2000habouzit Exp $ ***************************************************************************/ require("auto.prepend.inc.php"); @@ -109,14 +109,11 @@ if (!empty($_REQUEST['ref'])) { } - /****************** inscription à la liste promo ****************/ -// $inspromo = inscription_liste_promo($uid,$promo); - /****************** inscription à la newsletter ****************/ -// $insnewsletter = inscription_newsletter($uid); - /****************** inscription à la newsletter ****************/ -// $insforumpromo = inscription_forum_promo($uid,$promo); - /****************** inscription à la newsletter ****************/ -// $insforums = inscription_forums($uid); + /****************** inscription à la liste promo +nl ****************/ + $inspromo = inscription_listes_base($uid,$password,$promo); + /****************** inscription aux forums de base ****************/ + $insforumpromo = inscription_forum_promo($uid,$promo); + $insforums = inscription_forums($uid); // effacer la pré-inscription devenue $globals->db->query("update en_cours set loginbis='INSCRIT' WHERE username='$forlife'"); diff --git a/htdocs/listes/index.php b/htdocs/listes/index.php index 24fe600..fc2a678 100644 --- a/htdocs/listes/index.php +++ b/htdocs/listes/index.php @@ -18,7 +18,7 @@ * Foundation, Inc., * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * *************************************************************************** - $Id: index.php,v 1.6 2004-09-25 16:30:25 x2000habouzit Exp $ + $Id: index.php,v 1.7 2004-10-10 13:51:15 x2000habouzit Exp $ ***************************************************************************/ require("auto.prepend.inc.php"); @@ -44,8 +44,12 @@ 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(); $listes = $client->get_lists('polytechnique.org'); +$nl = $client->get_nl_state(); $page->assign_by_ref('listes',$listes); +$page->assign('nl',$nl); $page->run(); ?> diff --git a/include/inscription_listes_base.inc.php b/include/inscription_listes_base.inc.php index f9164bf..e90b556 100644 --- a/include/inscription_listes_base.inc.php +++ b/include/inscription_listes_base.inc.php @@ -18,11 +18,10 @@ * Foundation, Inc., * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * *************************************************************************** - $Id: inscription_listes_base.inc.php,v 1.2 2004-08-31 11:16:48 x2000habouzit Exp $ + $Id: inscription_listes_base.inc.php,v 1.3 2004-10-10 13:51:17 x2000habouzit Exp $ ***************************************************************************/ - - +include('xml-rpc-client.inc.php'); /** inscrit l'uid donnée à la promo * @param $uid UID @@ -31,41 +30,12 @@ * @see admin/RegisterNewUser.php * @see step4.php */ -function inscription_liste_promo($uid,$promo) { +function inscription_listes_base($uid,$pass,$promo) { global $globals; // récupération de l'id de la liste promo - $result=$globals->db->query("select id from aliases where alias = 'promo$promo' and type = 'liste'"); - if (!list($Lid)=mysql_fetch_row($result)) { // pas de liste promo, il faut la créer - $mymail = new TplMailer('listes.promo.tpl'); - $mymail->assign('promo', $promo); - $mymail->send(); - $Lid=false; - } - mysql_free_result($result); - if ($Lid) { - $globals->db->query("insert into listes_ins set idl=$Lid, idu=$uid"); - $res = !($globals->db->err()); - } else $res = false; - return $res; -} - - - -/** inscription à la newsletter - * @param $uid UID - * @return reponse MySQL - * @see admin/RegisterNewUser.php - * @see step4.php - */ -function inscription_newsletter($uid) { - global $globals; - $result=$globals->db->query("select id from aliases where alias = 'newsletter' and type = 'liste'"); - if (list($Lid)=mysql_fetch_row($result)) { - $globals->db->query("insert into listes_ins set idl=$Lid, idu=$uid"); - $res = !($globals->db->err()); - } else $res = false; - mysql_free_result($result); - return $res; + $client = new xmlrpc_client("http://$uid:$pass@localhost:4949"); + $client->subscribe('polytechnique.org',"promo$promo"); + $client->subscribe_nl(); } ?> diff --git a/scripts/mailman/mailman-rpc.py b/scripts/mailman/mailman-rpc.py index 3930a67..328155d 100755 --- a/scripts/mailman/mailman-rpc.py +++ b/scripts/mailman/mailman-rpc.py @@ -18,7 +18,7 @@ #* Foundation, Inc., * #* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * #*************************************************************************** -# $Id: mailman-rpc.py,v 1.52 2004-10-10 08:47:47 x2000habouzit Exp $ +# $Id: mailman-rpc.py,v 1.53 2004-10-10 13:51:20 x2000habouzit Exp $ #*************************************************************************** import base64, MySQLdb, os, getopt, sys, MySQLdb.converters, sha @@ -205,7 +205,7 @@ def get_lists((userdesc,perms),vhost): names.sort() result = [] for name in names: - if not name.startswith(prefix): + if not name.startswith(prefix) or name == mm_cfg.MAIN_NEWSLETTER: continue try: mlist = MailList.MailList(name,lock=0) @@ -253,6 +253,45 @@ def unsubscribe((userdesc,perms),vhost,listname): mlist.Unlock() return 0 +def subscribe_nl((userdesc,perms)): + try: + mlist = MailList.MailList(mm_cfg.MAIN_NEWSLETTER) + except: + return 0 + try: + mlist.ApprovedAddMember(userdesc) + mlist.Save() + mlist.Unlock() + return 1 + except: + mlist.Unlock() + return 0 + +def unsubscribe_nl((userdesc,perms)): + try: + mlist = MailList.MailList(mm_cfg.MAIN_NEWSLETTER) + except: + return 0 + try: + mlist.ApprovedDeleteMember(userdesc.address) + 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 ] # @@ -704,6 +743,9 @@ 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 diff --git a/templates/listes/index.tpl b/templates/listes/index.tpl index 7b38126..2a753c5 100644 --- a/templates/listes/index.tpl +++ b/templates/listes/index.tpl @@ -17,7 +17,7 @@ * Foundation, Inc., * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * *************************************************************************** - $Id: index.tpl,v 1.11 2004-10-09 12:49:38 x2000habouzit Exp $ + $Id: index.tpl,v 1.12 2004-10-10 13:51:22 x2000habouzit Exp $ ***************************************************************************}
@@ -81,6 +81,32 @@ Tu peux demander la cr {dynamic}
+ Lettre mensuelle de Polytechnique.org +
+ +{if $nl} +

+Tu es actuellement inscrit à la lettre mensuelle de Polytechnique.org ! +

+

+Pour te désinscrire suis le lien : +

+
+{else} +

+Tu n'es actuellement pas inscrit à la lettre mensuelle de Polytechnique.org. +

+

+Pour t'y abonner suis le lien : +

+
+ [m'inscrire] +
+{/if} + +
Listes de diffusion publiques
-- 2.1.4