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