Adapts upgrade scripts to domain.
[platal.git] / modules / register.php
index af6b4cc..6a1defc 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2010 Polytechnique.org                              *
+ *  Copyright (C) 2003-2011 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
@@ -29,7 +29,7 @@ class RegisterModule extends PLModule
         );
     }
 
-    function handler_register(&$page, $hash = null)
+    function handler_register($page, $hash = null)
     {
         $alert = null;
         $subState = new PlDict(S::v('subState', array()));
@@ -52,7 +52,7 @@ class RegisterModule extends PLModule
             $nameTypes = DirEnum::getOptions(DirEnum::NAMETYPES);
             $nameTypes = array_flip($nameTypes);
             $res = XDB::query("SELECT  a.uid, pd.promo, pnl.name AS lastname, pnf.name AS firstname, p.xorg_id AS xorgid,
-                                       p.birthdate_ref AS birthdateRef, FIND_IN_SET('watch', a.flags) AS watch, m.hash, a.type as eduType
+                                       p.birthdate_ref AS birthdateRef, FIND_IN_SET('watch', a.flags) AS watch, m.hash
                                  FROM  register_marketing AS m
                            INNER JOIN  accounts           AS a   ON (m.uid = a.uid)
                            INNER JOIN  account_profiles   AS ap  ON (a.uid = ap.uid AND FIND_IN_SET('owner', ap.perms))
@@ -171,13 +171,8 @@ class RegisterModule extends PLModule
                     }
 
                     // Register the optional services requested by the user.
-                    if ($subState->v('eduType') == 'x') {
-                        $proposedServices = array('ax_letter', 'imap', 'ml_promo', 'nl');
-                    } else {
-                        $proposedServices = array('ax_letter', 'nl');
-                    }
                     $services = array();
-                    foreach ($proposedServices as $service) {
+                    foreach (array('ax_letter', 'imap', 'ml_promo', 'nl') as $service) {
                         if (Post::b($service)) {
                             $services[] = $service;
                         }
@@ -254,13 +249,12 @@ class RegisterModule extends PLModule
         }
 
         $page->changeTpl('register/step' . $subState->i('step') . '.tpl');
-        $page->addJsLink('password.js');
         if (isset($error)) {
             $page->trigError($error);
         }
     }
 
-    function handler_end(&$page, $hash = null)
+    function handler_end($page, $hash = null)
     {
         global $globals;
         $_SESSION['subState'] = array('step' => 5);
@@ -314,7 +308,6 @@ class RegisterModule extends PLModule
 
         // Prepare the template for display.
         $page->changeTpl('register/end.tpl');
-        $page->addJsLink('do_challenge_response_logged.js');
         $page->assign('forlife', $forlife);
         $page->assign('firstname', $firstname);
 
@@ -354,15 +347,8 @@ class RegisterModule extends PLModule
 
         // Add the registration email address as first and only redirection.
         require_once 'emails.inc.php';
-        $user = User::getSilentWithUID($uid);
-        if ($isX) {
-            $redirect = new Redirect($user);
-            $redirect->add_email($email);
-        } else {
-            XDB::execute('UPDATE  accounts
-                             SET  email = {?}
-                           WHERE  uid = {?}', $email, $uid);
-        }
+        $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.
@@ -370,10 +356,13 @@ class RegisterModule extends PLModule
 
         // Subscribe the user to the services she did request at registration time.
         foreach (explode(',', $services) as $service) {
+            require_once 'newsletter.inc.php';
             switch ($service) {
                 case 'ax_letter':
-                    Platal::load('axletter', 'axletter.inc.php');
-                    AXLetter::subscribe($uid);
+                    NewsLetter::forGroup(NewsLetter::GROUP_AX)->subscribe($user);
+                    break;
+                case 'nl':
+                    NewsLetter::forGroup(NewsLetter::GROUP_XORG)->subscribe($user);
                     break;
                 case 'imap':
                     $storage = new EmailStorage($user, 'imap');
@@ -386,14 +375,15 @@ class RegisterModule extends PLModule
                         XDB::execute('INSERT IGNORE INTO  group_members (uid, asso_id)
                                                   VALUES  ({?}, {?})',
                                      $uid, $asso_id);
-                        $mmlist = new MMList($user);
-                        $mmlist->subscribe("promo" . $yearpromo);
+                        try {
+                            $mmlist = new MMList($user);
+                            $mmlist->subscribe("promo" . $yearpromo);
+                        } catch (Exception $e) {
+                            PlErrorReport::report($e);
+                            $page->trigError("L'inscription à la liste promo" . $yearpromo . " a échouée.");
+                        }
                     }
                     break;
-                case 'nl':
-                    require_once 'newsletter.inc.php';
-                    NewsLetter::subscribe($uid);
-                    break;
             }
         }
 
@@ -405,11 +395,10 @@ class RegisterModule extends PLModule
 
         // Congratulate our newly registered user by email.
         $mymail = new PlMailer('register/success.mail.tpl');
+        $mymail->addTo("\"{$user->fullName()}\" <{$user->forlifeEmail()}>");
         if ($isX) {
-            $mymail->addTo("\"{$user->fullName()}\" <{$user->forlifeEmail()}>");
             $mymail->setSubject('Bienvenue parmi les X sur le web !');
         } else {
-            $mymail->addTo($email);
             $mymail->setSubject('Bienvenue sur Polytechnique.org !');
         }
         $mymail->assign('forlife', $forlife);