Updates education and adapts AX data to merge them into Xorg data (Closes #891).
[platal.git] / modules / register.php
index cb15051..f77841c 100644 (file)
@@ -89,7 +89,7 @@ class RegisterModule extends PLModule
                     $sub_state['step'] = 1;
                     if (isset($sub_state['hash'])) {
                         $sub_state['step'] = 3;
-                        require_once(dirname(__FILE__) . '/register/register.inc.php');
+                        $this->load('register.inc.php');
                         create_aliases($sub_state);
                     }
                 }
@@ -119,7 +119,7 @@ class RegisterModule extends PLModule
 
             case 2:
                 if (count($_POST)) {
-                    require_once(dirname(__FILE__) . '/register/register.inc.php');
+                    $this->load('register.inc.php');
                     $sub_state['prenom'] = Post::v('prenom');
                     $sub_state['nom']    = Post::v('nom');
                     $sub_state['mat']    = Post::v('mat');
@@ -136,7 +136,8 @@ class RegisterModule extends PLModule
 
             case 3:
                 if (count($_POST)) {
-                    require_once(dirname(__FILE__) . '/register/register.inc.php');
+                    $this->load('register.inc.php');
+                    require_once 'emails.inc.php';
                     if (!isvalid_email(Post::v('email'))) {
                         $err[] = "Le champ 'E-mail' n'est pas valide.";
                     } elseif (!isvalid_email_redirection(Post::v('email'))) {
@@ -296,26 +297,48 @@ class RegisterModule extends PLModule
         }
 
         require_once('emails.inc.php');
-        $redirect = new Redirect($uid);
+        $user = User::getSilent($uid);
+        $redirect = new Redirect($user);
         $redirect->add_email($email);
 
         // on cree un objet logger et on log l'inscription
-        $logger = new PlLogger($uid);
-        S::logger()->log('inscription', $email);
-
+        S::logger($uid)->log('inscription', $email);
         XDB::execute('UPDATE register_pending SET hash="INSCRIT" WHERE uid={?}', $uid);
 
-        global $platal;
-        $platal->on_subscribe($forlife, $uid, $promo, $password);
 
         $mymail = new PlMailer('register/inscription.reussie.tpl');
         $mymail->assign('forlife', $forlife);
         $mymail->assign('prenom', $prenom);
         $mymail->send();
 
+        // Enable search on the user
         require_once('user.func.inc.php');
         user_reindex($uid);
 
+        // Add notification for people looking for this registration
+        require_once 'notifs.inc.php';
+        register_watch_op($uid, WATCH_INSCR);
+        inscription_notifs_base($uid);
+
+        // Default registration on forums
+        $p_for = 'xorg.promo.x' . $promo;
+        $cible = array('xorg.general', 'xorg.pa.divers', 'xorg.pa.logements', $p_for);
+        foreach ($cible as $val) {
+            XDB::execute("INSERT INTO  forums.abos (fid,uid)
+                               SELECT  fid, {?} FROM forums.list WHERE nom={?}", $uid, $val);
+            if (XDB::affectedRows() == 0 && $val == $p_for) {
+                $res = XDB::query("SELECT  SUM(perms IN ('admin','user') AND deces = 0), COUNT(*)
+                                     FROM  auth_user_md5
+                                    WHERE  promo = {?}", $promo);
+                list($effau, $effid) = $res->fetchOneRow();
+                if (5 * $effau > $effid) { // + 
+                    $mymail = new PlMailer('admin/forums-promo.mail.tpl');
+                    $mymail->assign('promo', $promo);
+                    $mymail->send();
+                }
+            }
+        }
+
         // update number of subscribers (perms has changed)
         $globals->updateNbIns();
 
@@ -396,6 +419,7 @@ class RegisterModule extends PLModule
     {
         global $globals;
         $page->changeTpl('register/success.tpl');
+        $page->assign('user', S::user());
 
         $_SESSION['sub_state'] = array('step' => 5);
         if (Env::has('response2'))  {
@@ -406,11 +430,11 @@ class RegisterModule extends PLModule
                                    S::v('uid'));
 
             // If GoogleApps is enabled, and the user did choose to use synchronized passwords,
-            // and if the (stupid) user has decided to user /register/success another time,
+            // and if the (stupid) user has decided to use /register/success another time,
             // updates the Google Apps password as well.
             if ($globals->mailstorage->googleapps_domain) {
                 require_once 'googleapps.inc.php';
-                $account = new GoogleAppsAccount(S::v('uid'), S::v('forlife'));
+                $account = new GoogleAppsAccount(S::user());
                 if ($account->active() && $account->sync_password) {
                     $account->set_password($password);
                 }
@@ -463,7 +487,7 @@ class RegisterModule extends PLModule
             NewsLetter::subscribe();
         }
         if (Post::v('add_to_ax')) {
-            require_once dirname(__FILE__) . '/axletter/axletter.inc.php';
+            Platal::load('axletter', 'axletter.inc.php');
             AXLetter::subscribe();
         }
         if (Post::v('add_to_promo')) {