Adapts advanced search on addresses to our new geocoding engine (gmaps v3).
[platal.git] / modules / register.php
CommitLineData
f59bc2fb 1<?php
2/***************************************************************************
5e1513f6 3 * Copyright (C) 2003-2011 Polytechnique.org *
f59bc2fb 4 * http://opensource.polytechnique.org/ *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software *
18 * Foundation, Inc., *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
21
22class RegisterModule extends PLModule
23{
24 function handlers()
25 {
26 return array(
94590511
SJ
27 'register' => $this->make_hook('register', AUTH_PUBLIC),
28 'register/end' => $this->make_hook('end', AUTH_PUBLIC),
f59bc2fb 29 );
30 }
31
26ba053e 32 function handler_register($page, $hash = null)
f59bc2fb 33 {
94590511
SJ
34 $alert = null;
35 $subState = new PlDict(S::v('subState', array()));
36 if (!$subState->has('step')) {
37 $subState->set('step', 0);
f59bc2fb 38 }
94590511
SJ
39 if (!$subState->has('backs')) {
40 $subState->set('backs', new PlDict());
2efe5355 41 }
94590511
SJ
42 if (Get::has('back') && Get::i('back') < $subState->i('step')) {
43 $subState->set('step', max(0, Get::i('back')));
c9910f75
SJ
44 $subState->v('backs')->set($subState->v('backs')->count() + 1, $subState->dict());
45 $subState->v('backs')->kill('backs');
94590511 46 if ($subState->v('backs')->count() == 3) {
97a82cd2 47 $alert .= "Tentative d'inscription très hésitante - ";
eaf30d86 48 }
f59bc2fb 49 }
50
20d90835 51 if ($hash) {
94590511 52 $nameTypes = DirEnum::getOptions(DirEnum::NAMETYPES);
94660e07 53 $nameTypes = array_flip($nameTypes);
e4860774
SJ
54 $res = XDB::query("SELECT a.uid, a.hruid, pnl.name AS lastname, pnf.name AS firstname, p.xorg_id AS xorgid,
55 pd.promo, pe.promo_year AS yearpromo, pde.degree AS edu_type,
f036c896 56 p.birthdate_ref AS birthdateRef, FIND_IN_SET('watch', a.flags) AS watch, m.hash, a.type
f59bc2fb 57 FROM register_marketing AS m
94660e07 58 INNER JOIN accounts AS a ON (m.uid = a.uid)
4b0cf4e4 59 INNER JOIN account_profiles AS ap ON (a.uid = ap.uid AND FIND_IN_SET('owner', ap.perms))
9f1cd432 60 INNER JOIN profiles AS p ON (p.pid = ap.pid)
7733ade1
SJ
61 INNER JOIN profile_display AS pd ON (p.pid = pd.pid)
62 INNER JOIN profile_education AS pe ON (pe.pid = p.pid AND FIND_IN_SET('primary', pe.flags))
e4860774 63 INNER JOIN profile_education_degree_enum AS pde ON (pde.id = pe.degreeid)
94660e07
SJ
64 INNER JOIN profile_name AS pnl ON (p.pid = pnl.pid AND pnl.typeid = {?})
65 INNER JOIN profile_name AS pnf ON (p.pid = pnf.pid AND pnf.typeid = {?})
4c5a5921 66 WHERE m.hash = {?} AND a.state = 'pending'",
94660e07
SJ
67 $nameTypes['name_ini'], $nameTypes['firstname_ini'], $hash);
68
94590511
SJ
69 if ($res->numRows() == 1) {
70 $subState->merge($res->fetchOneRow());
f036c896 71 $subState->set('main_mail_domain', User::$sub_mail_domains[$subState->v('type')]);
94660e07 72
00ba8a74
SJ
73 XDB::execute('INSERT INTO register_mstats (uid, sender, success)
74 SELECT m.uid, m.sender, 0
75 FROM register_marketing AS m
76 WHERE m.hash
a245a3e1 77 ON DUPLICATE KEY UPDATE sender = VALUES(sender), success = VALUES(success)',
94590511 78 $subState->s('hash'));
f59bc2fb 79 }
80 }
81
94590511 82 switch ($subState->i('step')) {
f59bc2fb 83 case 0:
8f201b69
FB
84 $wp = new PlWikiPage('Reference.Charte');
85 $wp->buildCache();
f59bc2fb 86 if (Post::has('step1')) {
94590511
SJ
87 $subState->set('step', 1);
88 if ($subState->has('hash')) {
89 $subState->set('step', 3);
460d8f55 90 $this->load('register.inc.php');
94590511 91 createAliases($subState);
f59bc2fb 92 }
93 }
94 break;
95
96 case 1:
94590511 97 if (Post::has('yearpromo')) {
f0a52f1b 98 $edu_type = Post::t('edu_type');
94590511 99 $yearpromo = Post::i('yearpromo');
e4860774 100 $promo = Profile::$cycle_prefixes[$edu_type] . $yearpromo;
94660e07 101 $res = XDB::query("SELECT COUNT(*)
94590511
SJ
102 FROM accounts AS a
103 INNER JOIN account_profiles AS ap ON (a.uid = ap.uid AND FIND_IN_SET('owner', ap.perms))
104 INNER JOIN profiles AS p ON (p.pid = ap.pid)
761f6f96 105 INNER JOIN profile_education AS pe ON (pe.pid = p.pid AND FIND_IN_SET('primary', pe.flags))
7733ade1 106 WHERE a.state = 'pending' AND p.deathdate IS NULL AND pe.promo_year = {?}",
761f6f96 107 $yearpromo);
94660e07 108
a41bf2f8 109 if (!$res->fetchOneCell()) {
94660e07 110 $error = 'La promotion saisie est incorrecte ou tous les camarades de cette promotion sont inscrits !';
f59bc2fb 111 } else {
94590511
SJ
112 $subState->set('step', 2);
113 $subState->set('promo', $promo);
114 $subState->set('yearpromo', $yearpromo);
f0a52f1b 115 $subState->set('edu_type', $edu_type);
e4860774 116 if ($edu_type == Profile::DEGREE_X) {
f0a52f1b
SJ
117 if ($yearpromo >= 1996 && $yearpromo < 2000) {
118 $subState->set('schoolid', ($yearpromo % 100) * 10 . '???');
e4860774
SJ
119 $subState->set('schoolid_exemple', ($yearpromo % 100) * 10000 + 532);
120 $subState->set('schoolid_exemple_ev2', (($yearpromo + 1) % 100) * 10000 + 532);
f0a52f1b
SJ
121 } elseif($yearpromo >= 2000) {
122 $subState->set('schoolid', 100 + ($yearpromo % 100) . '???');
e4860774
SJ
123 $subState->set('schoolid_exemple', (100 + ($yearpromo % 100)) * 1000 + 532);
124 $subState->set('schoolid_exemple_ev2', (100 + (($yearpromo + 1) % 100)) * 1000 + 532);
f0a52f1b 125 }
f59bc2fb 126 }
127 }
128 }
129 break;
130
131 case 2:
132 if (count($_POST)) {
460d8f55 133 $this->load('register.inc.php');
94590511
SJ
134 $subState->set('firstname', Post::t('firstname'));
135 $subState->set('lastname', Post::t('lastname'));
e4860774
SJ
136 if (Post::has('schoolid')) {
137 $subState->set('schoolid', Post::i('schoolid'));
138 }
94590511 139 $error = checkNewUser($subState);
f59bc2fb 140
94660e07
SJ
141 if ($error !== true) {
142 break;
143 }
94590511 144 $error = createAliases($subState);
94660e07
SJ
145 if ($error === true) {
146 unset($error);
94590511 147 $subState->set('step', 3);
f59bc2fb 148 }
149 }
150 break;
151
152 case 3:
153 if (count($_POST)) {
460d8f55 154 $this->load('register.inc.php');
97a82cd2
VZ
155
156 // Validate the email address format and domain.
c6310567 157 require_once 'emails.inc.php';
94660e07 158
5e2307dc 159 if (!isvalid_email(Post::v('email'))) {
94660e07 160 $error[] = "Le champ 'Email' n'est pas valide.";
5e2307dc 161 } elseif (!isvalid_email_redirection(Post::v('email'))) {
94590511 162 $error[] = $subState->s('forlife') . ' doit renvoyer vers un email existant '
94660e07 163 . 'valide, en particulier, il ne peut pas être renvoyé vers lui-même.';
f59bc2fb 164 }
97a82cd2
VZ
165
166 // Validate the birthday format and range.
94590511 167 $birth = Post::t('birthdate');
12e5d7a6 168 if (!preg_match('@^[0-3]?\d/[01]?\d/(19|20)?\d{2}$@', $birth)) {
94660e07 169 $error[] = "La 'Date de naissance' n'est pas correcte.";
35cd1be1 170 } else {
12e5d7a6 171 $birth = explode('/', $birth, 3);
94660e07 172 for ($i = 0; $i < 3; ++$i)
7caaaf6d 173 $birth[$i] = intval($birth[$i]);
94660e07
SJ
174 if ($birth[2] < 100) {
175 $birth[2] += 1900;
176 }
e4860774
SJ
177 $year = $birth[2];
178 $ref_year = substr($subState->v('birthdateRef'), 0, 4);
179 if (abs($ref_year - $year) > 2) {
94660e07 180 $error[] = "La 'Date de naissance' n'est pas correcte.";
97a82cd2 181 $alert = "Date de naissance incorrecte à l'inscription - ";
94590511 182 $subState->set('wrong_birthdate', $birth);
35cd1be1 183 }
f59bc2fb 184 }
185
3546b253
VZ
186 // Register the optional services requested by the user.
187 $services = array();
4b1a8575 188 foreach (array('ax_letter', 'imap', 'ml_promo', 'nl') as $service) {
3546b253
VZ
189 if (Post::b($service)) {
190 $services[] = $service;
191 }
192 }
94590511 193 $subState->set('services', $services);
3546b253 194
97a82cd2 195 // Validate the password.
81b5a6c9 196 if (!Post::v('pwhash', false)) {
94660e07 197 $error[] = "Le mot de passe n'est pas valide.";
97a82cd2
VZ
198 }
199
200 // Check if the given email is known as dangerous.
94590511
SJ
201 $res = XDB::query("SELECT state, description
202 FROM email_watch
203 WHERE email = {?} AND state != 'safe'",
94660e07 204 Post::v('email'));
94590511 205 $bannedEmail = false;
15836cdd
FB
206 if ($res->numRows()) {
207 list($state, $description) = $res->fetchOneRow();
97a82cd2 208 $alert .= "Email surveillé proposé à l'inscription - ";
94590511 209 $subState->set('email_desc', $description);
706ed3ef 210 if ($state == 'dangerous') {
94590511 211 $bannedEmail = true;
706ed3ef 212 }
5480a216 213 }
4b0cf4e4 214 if ($subState->i('watch') != 0) {
4653799f 215 $alert .= "Inscription d'un utilisateur surveillé - ";
0be07aa6 216 }
5480a216 217
94590511 218 if (($bannedIp = check_ip('unsafe'))) {
94660e07 219 unset($error);
bf273d6a 220 }
221
94660e07
SJ
222 if (isset($error)) {
223 $error = join('<br />', $error);
f59bc2fb 224 } else {
94590511
SJ
225 $subState->set('birthdate', sprintf("%04d-%02d-%02d",
226 intval($birth[2]), intval($birth[1]), intval($birth[0])));
227 $subState->set('email', Post::t('email'));
81b5a6c9 228 $subState->set('password', Post::t('pwhash'));
97a82cd2
VZ
229
230 // Update the current alert if the birthdate is incorrect,
231 // or if the IP address of the user has been banned.
94590511
SJ
232 if ($subState->s('birthdateRef') != '0000-00-00'
233 && $subState->s('birthdateRef') != $subState->s('birthdate')) {
ecc734a5 234 $alert .= "Date de naissance incorrecte à l'inscription - ";
235 }
94590511 236 if ($bannedIp) {
97a82cd2 237 $alert .= "Tentative d'inscription depuis une IP surveillée";
706ed3ef 238 }
97a82cd2
VZ
239
240 // Prevent banned user from actually registering; save the current state for others.
94590511 241 if ($bannedEmail || $bannedIp) {
115c90db 242 global $globals;
94660e07 243 $error = "Une erreur s'est produite lors de l'inscription."
1d55fe45 244 . " Merci de contacter <a href='mailto:register@{$globals->mail->domain}>"
245 . " register@{$globals->mail->domain}</a>"
94660e07 246 . " pour nous faire part de cette erreur.";
5480a216 247 } else {
94590511 248 $subState->set('step', 4);
4b0cf4e4 249 if ($subState->v('backs')->count() >= 3) {
94660e07 250 $alert .= "Fin d'une inscription hésitante.";
2efe5355 251 }
94590511 252 finishRegistration($subState);
5480a216 253 }
bf273d6a 254 }
f59bc2fb 255 }
256 break;
257 }
258
94590511 259 $_SESSION['subState'] = $subState->dict();
4653799f 260 if (!empty($alert)) {
5480a216 261 send_warning_mail($alert);
262 }
97a82cd2 263
94590511 264 $page->changeTpl('register/step' . $subState->i('step') . '.tpl');
94660e07
SJ
265 if (isset($error)) {
266 $page->trigError($error);
f59bc2fb 267 }
f59bc2fb 268 }
269
26ba053e 270 function handler_end($page, $hash = null)
f59bc2fb 271 {
272 global $globals;
94590511 273 $_SESSION['subState'] = array('step' => 5);
ecc734a5 274
97a82cd2
VZ
275 // Reject registration requests from unsafe IP addresses (and remove the
276 // registration information from the database, to prevent IP changes).
ecc734a5 277 if (check_ip('unsafe')) {
94660e07 278 send_warning_mail('Une IP surveillée a tenté de finaliser son inscription.');
97a82cd2
VZ
279 XDB::execute("DELETE FROM register_pending
280 WHERE hash = {?} AND hash != 'INSCRIT'", $hash);
ecc734a5 281 return PL_FORBIDDEN;
282 }
283
94590511
SJ
284 $nameTypes = DirEnum::getOptions(DirEnum::NAMETYPES);
285 $nameTypes = array_flip($nameTypes);
286
97a82cd2
VZ
287 // Retrieve the pre-registration information using the url-provided
288 // authentication token.
94590511
SJ
289 $res = XDB::query("SELECT r.uid, p.pid, r.forlife, r.bestalias, r.mailorg2,
290 r.password, r.email, r.services, r.naissance,
2bf73be5
SJ
291 pnl.name AS lastname, pnf.name AS firstname, pe.promo_year,
292 pd.promo, p.sex, p.birthdate_ref, a.type
94590511
SJ
293 FROM register_pending AS r
294 INNER JOIN accounts AS a ON (r.uid = a.uid)
295 INNER JOIN account_profiles AS ap ON (a.uid = ap.uid AND FIND_IN_SET('owner', ap.perms))
9f1cd432 296 INNER JOIN profiles AS p ON (p.pid = ap.pid)
94590511
SJ
297 INNER JOIN profile_name AS pnl ON (p.pid = pnl.pid AND pnl.typeid = {?})
298 INNER JOIN profile_name AS pnf ON (p.pid = pnf.pid AND pnf.typeid = {?})
299 INNER JOIN profile_display AS pd ON (p.pid = pd.pid)
7733ade1 300 INNER JOIN profile_education AS pe ON (pe.pid = p.pid AND FIND_IN_SET('primary', pe.flags))
4c5a5921 301 WHERE hash = {?} AND hash != 'INSCRIT' AND a.state = 'pending'",
94590511 302 $nameTypes['name_ini'], $nameTypes['firstname_ini'], $hash);
97a82cd2 303 if (!$hash || $res->numRows() == 0) {
f59bc2fb 304 $page->kill("<p>Cette adresse n'existe pas, ou plus, sur le serveur.</p>
97a82cd2 305 <p>Causes probables&nbsp;:</p>
f59bc2fb 306 <ol>
a7de4ef7 307 <li>Vérifie que tu visites l'adresse du dernier
97a82cd2 308 email reçu s'il y en a eu plusieurs.</li>
a7de4ef7 309 <li>Tu as peut-être mal copié l'adresse reçue par
97a82cd2 310 email, vérifie-la à la main.</li>
a7de4ef7 311 <li>Tu as peut-être attendu trop longtemps pour
94590511 312 confirmer. Les pré-inscriptions sont annulées
f59bc2fb 313 tous les 30 jours.</li>
a7de4ef7 314 <li>Tu es en fait déjà inscrit.</li>
f59bc2fb 315 </ol>");
316 }
317
94590511 318 list($uid, $pid, $forlife, $bestalias, $emailXorg2, $password, $email, $services,
2bf73be5
SJ
319 $birthdate, $lastname, $firstname, $promo, $yearpromo, $sex, $birthdate_ref, $type) = $res->fetchOneRow();
320 $isX = ($type == 'x');
321 $mail_domain = User::$sub_mail_domains[$type] . $globals->mail->domain;
f59bc2fb 322
97a82cd2
VZ
323 // Prepare the template for display.
324 $page->changeTpl('register/end.tpl');
97a82cd2 325 $page->assign('forlife', $forlife);
94590511 326 $page->assign('firstname', $firstname);
97a82cd2
VZ
327
328 // Check if the user did enter a valid password; if not (or if none is found),
329 // get her an information page.
94590511
SJ
330 if (Post::has('response')) {
331 $expected_response = sha1("$forlife:$password:" . S::v('challenge'));
332 if (Post::v('response') != $expected_response) {
97a82cd2
VZ
333 $page->trigError("Mot de passe invalide.");
334 S::logger($uid)->log('auth_fail', 'bad password (register/end)');
335 return;
336 }
337 } else {
338 return;
339 }
f59bc2fb 340
97a82cd2
VZ
341 //
342 // Create the user account.
343 //
dd9b3613 344 XDB::startTransaction();
94590511
SJ
345 XDB::execute("UPDATE accounts
346 SET password = {?}, state = 'active',
33a4f3f9 347 registration_date = NOW(), email = NULL
94590511
SJ
348 WHERE uid = {?}", $password, $uid);
349 XDB::execute("UPDATE profiles
350 SET birthdate = {?}, last_change = NOW()
351 WHERE pid = {?}", $birthdate, $pid);
c0436d0b
SJ
352 XDB::execute('INSERT INTO email_source_account (email, uid, type, flags, domain)
353 SELECT {?}, {?}, \'forlife\', \'\', id
354 FROM email_virtual_domains
355 WHERE name = {?}',
f036c896 356 $forlife, $uid, $mail_domain);
c0436d0b
SJ
357 XDB::execute('INSERT INTO email_source_account (email, uid, type, flags, domain)
358 SELECT {?}, {?}, \'alias\', \'bestalias\', id
359 FROM email_virtual_domains
360 WHERE name = {?}',
f036c896 361 $bestalias, $uid, $mail_domain);
94590511 362 if ($emailXorg2) {
c0436d0b
SJ
363 XDB::execute('INSERT INTO email_source_account (email, uid, type, flags, domain)
364 SELECT {?}, {?}, \'alias\', \'\', id
365 FROM email_virtual_domains
366 WHERE name = {?}',
f036c896 367 $emailXorg2, $uid, $mail_domain);
f59bc2fb 368 }
dd9b3613 369 XDB::commit();
f59bc2fb 370
97a82cd2 371 // Add the registration email address as first and only redirection.
726eaf7a 372 require_once 'emails.inc.php';
f0a52f1b 373 $user = User::getSilentWithUID($uid);
4b1a8575
SJ
374 $redirect = new Redirect($user);
375 $redirect->add_email($email);
f25e42eb 376 fix_bestalias($user);
f59bc2fb 377
3546b253
VZ
378 // Try to start a session (so the user don't have to log in); we will use
379 // the password available in Post:: to authenticate the user.
f0a52f1b 380 Platal::session()->start(AUTH_MDP);
3546b253
VZ
381
382 // Subscribe the user to the services she did request at registration time.
2bf73be5 383 require_once 'newsletter.inc.php';
3546b253
VZ
384 foreach (explode(',', $services) as $service) {
385 switch ($service) {
386 case 'ax_letter':
6ae6840d
RB
387 NewsLetter::forGroup(NewsLetter::GROUP_AX)->subscribe($user);
388 break;
389 case 'nl':
390 NewsLetter::forGroup(NewsLetter::GROUP_XORG)->subscribe($user);
3546b253
VZ
391 break;
392 case 'imap':
5ad556d3 393 Email::activate_storage($user, 'imap', Bogo::IMAP_DEFAULT);
3546b253
VZ
394 break;
395 case 'ml_promo':
d1d7fe34
SJ
396 if ($isX) {
397 $r = XDB::query('SELECT id FROM groups WHERE diminutif = {?}', $yearpromo);
398 if ($r->numRows()) {
399 $asso_id = $r->fetchOneCell();
400 XDB::execute('INSERT IGNORE INTO group_members (uid, asso_id)
401 VALUES ({?}, {?})',
402 $uid, $asso_id);
403 try {
404 $mmlist = new MMList($user);
405 $mmlist->subscribe("promo" . $yearpromo);
406 } catch (Exception $e) {
407 PlErrorReport::report($e);
408 $page->trigError("L'inscription à la liste promo" . $yearpromo . " a échouée.");
409 }
e78be37f 410 }
3546b253
VZ
411 }
412 break;
3546b253
VZ
413 }
414 }
415
97a82cd2 416 // Log the registration in the user session.
03c0a3a7 417 S::logger($uid)->log('inscription', $email);
97a82cd2
VZ
418 XDB::execute("UPDATE register_pending
419 SET hash = 'INSCRIT'
420 WHERE uid = {?}", $uid);
f59bc2fb 421
97a82cd2 422 // Congratulate our newly registered user by email.
94590511 423 $mymail = new PlMailer('register/success.mail.tpl');
4b1a8575 424 $mymail->addTo("\"{$user->fullName()}\" <{$user->forlifeEmail()}>");
96700179 425 if ($isX) {
96700179
SJ
426 $mymail->setSubject('Bienvenue parmi les X sur le web !');
427 } else {
96700179
SJ
428 $mymail->setSubject('Bienvenue sur Polytechnique.org !');
429 }
f59bc2fb 430 $mymail->assign('forlife', $forlife);
94590511 431 $mymail->assign('firstname', $firstname);
f59bc2fb 432 $mymail->send();
433
97a82cd2 434 // Index the user, to allow her to appear in searches.
bbdfd693 435 Profile::rebuildSearchTokens($pid);
2a54eb4d 436
97a82cd2 437 // Notify other users which were watching for her arrival.
00ba8a74
SJ
438 XDB::execute('INSERT INTO contacts (uid, contact)
439 SELECT uid, ni_id
440 FROM watch_nonins
441 WHERE ni_id = {?}', $uid);
94590511
SJ
442 XDB::execute('DELETE FROM watch_nonins
443 WHERE ni_id = {?}', $uid);
444 Platal::session()->updateNbNotifs();
03c0a3a7 445
97a82cd2 446 // Forcibly register the new user on default forums.
2bf73be5 447 $registeredForums = array('xorg.general', 'xorg.pa.divers', 'xorg.pa.logements');
97a82cd2 448
2bf73be5
SJ
449 if ($isX) {
450 $promoForum = 'xorg.promo.' . strtolower($promo);
451 $exists = XDB::fetchOneCell('SELECT COUNT(*)
452 FROM forums
453 WHERE name = {?}',
454 $promoForum);
455
456 if ($exists == 0) {
457 // Notify the newsgroup admin of the promotion forum needs be created.
94590511
SJ
458 $promoFull = new UserFilter(new UFC_Promo('=', UserFilter::DISPLAY, $promo));
459 $promoRegistered = new UserFilter(new PFC_And(
460 new UFC_Promo('=', UserFilter::DISPLAY, $promo),
461 new UFC_Registered(true),
462 new PFC_Not(new UFC_Dead())
463 ));
464 if ($promoRegistered->getTotalCount() > 0.2 * $promoFull->getTotalCount()) {
03c0a3a7
FB
465 $mymail = new PlMailer('admin/forums-promo.mail.tpl');
466 $mymail->assign('promo', $promo);
467 $mymail->send();
468 }
2bf73be5
SJ
469 } else {
470 $registeredForums[] = $promoForum;
03c0a3a7
FB
471 }
472 }
473
2bf73be5
SJ
474 foreach ($registeredForums as $forum) {
475 XDB::execute("INSERT INTO forum_subs (fid, uid)
476 SELECT fid, {?}
477 FROM forums
478 WHERE name = {?}",
479 $uid, $val);
480 }
481
97a82cd2 482 // Update the global registration count stats.
ebfdf077 483 $globals->updateNbIns();
b5dd6f2f 484
97a82cd2
VZ
485 //
486 // Update collateral data sources, and inform watchers by email.
487 //
f59bc2fb 488
97a82cd2 489 // Email the referrer(s) of this new user.
94590511
SJ
490 $res = XDB::iterRow("SELECT sender, GROUP_CONCAT(email SEPARATOR ', ') AS mails, MAX(last) AS lastDate
491 FROM register_marketing
492 WHERE uid = {?}
493 GROUP BY sender
494 ORDER BY lastDate DESC", $uid);
97a82cd2
VZ
495 XDB::execute("UPDATE register_mstats
496 SET success = NOW()
497 WHERE uid = {?}", $uid);
f59bc2fb 498
d3447a09 499 $market = array();
94590511
SJ
500 while (list($senderid, $maketingEmails, $lastDate) = $res->next()) {
501 $sender = User::getWithUID($senderid);
07f1f729 502 $market[] = " - par {$sender->fullName()} sur $maketingEmails (le plus récemment le $lastDate)";
94590511
SJ
503 $mymail = new PlMailer('register/marketer.mail.tpl');
504 $mymail->setSubject("$firstname $lastname s'est inscrit à Polytechnique.org !");
330888b0 505 $mymail->addTo($sender);
94590511
SJ
506 $mymail->assign('sender', $sender);
507 $mymail->assign('firstname', $firstname);
508 $mymail->assign('lastname', $lastname);
509 $mymail->assign('promo', $promo);
510 $mymail->assign('sex', $sex);
f59bc2fb 511 $mymail->setTxtBody(wordwrap($msg, 72));
512 $mymail->send();
513 }
5f5f0eb5 514
97a82cd2 515 // Email the plat/al administrators about the registration.
9812efa0 516 if ($globals->register->notif) {
94590511
SJ
517 $mymail = new PlMailer('register/registration.mail.tpl');
518 $mymail->setSubject("Inscription de $firstname $lastname ($promo)");
519 $mymail->assign('firstname', $firstname);
520 $mymail->assign('lastname', $lastname);
521 $mymail->assign('promo', $promo);
522 $mymail->assign('sex', $sex);
523 $mymail->assign('birthdate', $birthdate);
524 $mymail->assign('birthdate_ref', $birthdate_ref);
525 $mymail->assign('forlife', $forlife);
526 $mymail->assign('email', $email);
4b0cf4e4 527 $mymail->assign('logger', S::logger());
defff1aa 528 if (count($market) > 0) {
94590511 529 $mymail->assign('market', implode("\n", $market));
defff1aa 530 }
9812efa0 531 $mymail->setTxtBody($msg);
eaf30d86 532 $mymail->send();
9812efa0 533 }
f59bc2fb 534
97a82cd2 535 // Remove old pending marketing requests for the new user.
e654517d 536 Marketing::clear($uid);
f59bc2fb 537
97a0a459
FB
538 pl_redirect('profile/edit');
539 }
f59bc2fb 540}
541
a7de4ef7 542// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
f59bc2fb 543?>