enable auto subscribe code + treat the NL separate
authorx2000habouzit <x2000habouzit>
Sun, 10 Oct 2004 13:51:13 +0000 (13:51 +0000)
committerx2000habouzit <x2000habouzit>
Sun, 10 Oct 2004 13:51:13 +0000 (13:51 +0000)
htdocs/inscription/step4.php
htdocs/listes/index.php
include/inscription_listes_base.inc.php
scripts/mailman/mailman-rpc.py
templates/listes/index.tpl

index a32d4a2..83ea022 100644 (file)
@@ -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'");
index 24fe600..fc2a678 100644 (file)
@@ -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();
 ?>
index f9164bf..e90b556 100644 (file)
  *  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
  * @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();
 }
 
 ?>
index 3930a67..328155d 100755 (executable)
@@ -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
index 7b38126..2a753c5 100644 (file)
@@ -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 $
  ***************************************************************************}
 
 <div class="rubrique">
@@ -81,6 +81,32 @@ Tu peux demander <a href='create.php'>la cr
 {dynamic}
 
 <div class="rubrique">
+  Lettre mensuelle de Polytechnique.org
+</div>
+
+{if $nl}
+<p>
+Tu es actuellement inscrit à la lettre mensuelle de Polytechnique.org !
+</p>
+<p>
+Pour te désinscrire suis le lien :
+</p>
+<div class='center'>
+  [<a href='?nl_unsub=1'>me désinscrire</a>]
+</div>
+{else}
+<p>
+Tu n'es actuellement pas inscrit à la lettre mensuelle de Polytechnique.org.
+</p>
+<p>
+Pour t'y abonner suis le lien :
+</p>
+<div class='center'>
+  [<a href='?nl_sub=1'>m'inscrire</a>]
+</div>
+{/if}
+
+<div class="rubrique">
   Listes de diffusion publiques
 </div>