Allows users to subscribe to our main services (ax letter, imap, ml promo, nl) direct...
authorVincent Zanotti <vincent.zanotti@m4x.org>
Mon, 27 Jul 2009 00:10:38 +0000 (02:10 +0200)
committerVincent Zanotti <vincent.zanotti@m4x.org>
Mon, 27 Jul 2009 14:02:25 +0000 (16:02 +0200)
Signed-off-by: Vincent Zanotti <vincent.zanotti@m4x.org>
modules/register.php
modules/register/register.inc.php
templates/register/step3.tpl
upgrade/0.10.1/00_inscription.sql

index 61a7dfa..f2cd5e6 100644 (file)
@@ -157,6 +157,15 @@ class RegisterModule extends PLModule
                         }
                     }
 
+                    // Register the optional services requested by the user.
+                    $services = array();
+                    foreach (array('ax_letter', 'imap', 'ml_promo', 'nl') as $service) {
+                        if (Post::b($service)) {
+                            $services[] = $service;
+                        }
+                    }
+                    $sub_state['services'] = $services;
+
                     // Validate the password.
                     if (!Post::v('response2', false)) {
                         $err[] = "Le mot de passe n'est pas valide.";
@@ -253,7 +262,7 @@ class RegisterModule extends PLModule
         if ($hash) {
             $res = XDB::query(
                     "SELECT  r.uid, r.forlife, r.bestalias, r.mailorg2,
-                             r.password, r.email, r.naissance, u.nom, u.prenom,
+                             r.password, r.email, r.services, r.naissance, u.nom, u.prenom,
                              u.promo, FIND_IN_SET('femme', u.flags), u.naissance_ini
                        FROM  register_pending AS r
                  INNER JOIN  auth_user_md5    AS u ON r.uid = u.user_id
@@ -274,7 +283,7 @@ class RegisterModule extends PLModule
                         </ol>");
         }
 
-        list($uid, $forlife, $bestalias, $mailorg2, $password, $email,
+        list($uid, $forlife, $bestalias, $mailorg2, $password, $email, $services,
              $naissance, $nom, $prenom, $promo, $femme, $naiss_ini) = $res->fetchOneRow();
 
         // Prepare the template for display.
@@ -321,6 +330,41 @@ class RegisterModule extends PLModule
         $redirect = new Redirect($user);
         $redirect->add_email($email);
 
+        // Try to start a session (so the user don't have to log in); we will use
+        // the password available in Post:: to authenticate the user.
+        Platal::session()->start(AUTH_MDP);
+
+        // Subscribe the user to the services she did request at registration time.
+        foreach (explode(',', $services) as $service) {
+            switch ($service) {
+                case 'ax_letter':
+                    Platal::load('axletter', 'axletter.inc.php');
+                    AXLetter::subscribe();
+                    break;
+                case 'imap':
+                    require_once 'emails.inc.php';
+                    $user = S::user();
+                    $storage = new EmailStorage($user, 'imap');
+                    $storage->activate();
+                    break;
+                case 'ml_promo':
+                    $r = XDB::query('SELECT id FROM groupex.asso WHERE diminutif = {?}', S::user()->promo());
+                    if ($r->numRows()) {
+                        $asso_id = $r->fetchOneCell();
+                        XDB::execute('REPLACE INTO  groupex.membres (uid, asso_id)
+                                            VALUES  ({?}, {?})',
+                                     S::user()->id(), $asso_id);
+                        $mmlist = new MMList(S::user()->id(), S::v('password'));
+                        $mmlist->subscribe("promo" . S::v('promo'));
+                    }
+                    break;
+                case 'nl':
+                    require_once 'newsletter.inc.php';
+                    NewsLetter::subscribe();
+                    break;
+            }
+        }
+
         // Log the registration in the user session.
         S::logger($uid)->log('inscription', $email);
         XDB::execute("UPDATE  register_pending
@@ -369,10 +413,6 @@ class RegisterModule extends PLModule
         // Update the global registration count stats.
         $globals->updateNbIns();
 
-        // Try to start a session (so the user don't have to log in); we will use
-        // the password available in Post:: to authenticate the user.
-        Platal::session()->start(AUTH_MDP);
-
         //
         // Update collateral data sources, and inform watchers by email.
         //
index 5e153d7..19cd7f2 100644 (file)
@@ -237,9 +237,9 @@ function finish_ins($sub_state)
                 SET  last_known_email = {?}
               WHERE  matricule = {?}", $email, $mat);
     XDB::execute(
-            "REPLACE INTO  register_pending (uid, forlife, bestalias, mailorg2, password, email, date, relance, naissance, hash)
-                   VALUES  ({?}, {?}, {?}, {?}, {?}, {?}, NOW(), 0, {?}, {?})",
-            $uid, $forlife, $bestalias, $mailorg2, $password, $email, $naissance, $hash);
+            "REPLACE INTO  register_pending (uid, forlife, bestalias, mailorg2, password, email, date, relance, naissance, hash, services)
+                   VALUES  ({?}, {?}, {?}, {?}, {?}, {?}, NOW(), 0, {?}, {?}, {?})",
+            $uid, $forlife, $bestalias, $mailorg2, $password, $email, $naissance, $hash, implode(',', $services));
 
     $mymail = new PlMailer('register/inscrire.mail.tpl');
     $mymail->assign('mailorg', $bestalias);
index 4a8c003..d48eb3f 100644 (file)
         {checkpasswd prompt="password" text="Terminer la pré-inscription"}
       </td>
     </tr>
+  </table>
+  <table class="bicol">
     <tr>
-      <td colspan="2" class="center">
+      <th>Services supplémentaires</th>
+    </tr>
+    <tr class="impair">
+      <td>Pour profiter pleinement de ta nouvelle inscription, nous te proposons&nbsp;:</td>
+    </tr>
+    <tr class="pair">
+      <td>
+        <dl>
+          <dt><label><input type="checkbox" checked="checked" name="nl" /> lettre mensuelle</label></dt>
+          <dd>
+            de recevoir chaque mois la lettre mensuelle de Polytechnique.org contenant les activités et nouvelles de la communauté des X.
+          </dd>
+          <dt><label><input type="checkbox" checked="checked" name="ax_letter" /> envois de l'AX</label></dt>
+          <dd>
+            de recevoir les informations importantes de l'AX.
+          </dd>
+          <dt><label><input type="checkbox" checked="checked" name="ml_promo" /> ta promotion</label></dt>
+          <dd>
+            de recevoir les informations plus spécifiques de ta promotion pour pouvoir participer plus facilement aux événements
+            qu'elle organise. Nous t'inscrivons donc dans le groupe de la promotion {$smarty.session.sub_state.promo}.
+          </dd>
+          <dt><label><input type="checkbox" checked="checked" name="imap" />sauvegardes d'emails</label></dt>
+          <dd>
+            d'avoir un accès de secours aux 30 derniers jours d'emails reçus sur ton adresse Polytechnique.org.
+          </dd>
+        </dl>
+      </td>
+    </tr>
+    <tr class="impair">
+      <td>Valider mon inscription&nbsp;:</td>
+    </tr>
+    <tr class="impair">
+      <td class="center">
         <input type="submit" name="submitn" value="Continuer" onclick="EncryptedResponseInNestedForm(); return false;" />
       </td>
     </tr>
index a23ef9e..199aad9 100644 (file)
@@ -33,4 +33,6 @@ CREATE TABLE IF NOT EXISTS reminder (
   PRIMARY KEY(uid, type_id)
 ) CHARSET=utf8;
 
+ALTER TABLE register_pending ADD services SET('ax_letter', 'imap', 'ml_promo', 'nl') NOT NULL DEFAULT '' AFTER hash;
+
 -- vim:set syntax=mysql: