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