M/D do not have promotion groups and ML yet.
[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);
599e4774 54 $res = XDB::query("SELECT a.uid, a.hruid, pnl.name AS lastname, pnf.name AS firstname, p.xorg_id AS xorgid,
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)
94660e07
SJ
60 INNER JOIN profile_name AS pnl ON (p.pid = pnl.pid AND pnl.typeid = {?})
61 INNER JOIN profile_name AS pnf ON (p.pid = pnf.pid AND pnf.typeid = {?})
4c5a5921 62 WHERE m.hash = {?} AND a.state = 'pending'",
94660e07
SJ
63 $nameTypes['name_ini'], $nameTypes['firstname_ini'], $hash);
64
94590511
SJ
65 if ($res->numRows() == 1) {
66 $subState->merge($res->fetchOneRow());
f036c896 67 $subState->set('main_mail_domain', User::$sub_mail_domains[$subState->v('type')]);
599e4774 68 $subState->set('yearpromo', substr($subState->s('hruid'), -4));
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');
f0a52f1b 97 $promo = $edu_type . $yearpromo;
599e4774 98 $year = ($edu_type == 'X') ? 'entry_year' : 'grad_year';
94660e07 99 $res = XDB::query("SELECT COUNT(*)
94590511
SJ
100 FROM accounts AS a
101 INNER JOIN account_profiles AS ap ON (a.uid = ap.uid AND FIND_IN_SET('owner', ap.perms))
102 INNER JOIN profiles AS p ON (p.pid = ap.pid)
599e4774
SJ
103 INNER JOIN profile_education AS pe ON (pe.pid = p.pid AND FIND_IN_SET('primary', pe.flags))
104 WHERE a.state = 'pending' AND p.deathdate IS NULL AND pe.$year = {?}",
105 $yearpromo);
94660e07 106
a41bf2f8 107 if (!$res->fetchOneCell()) {
94660e07 108 $error = 'La promotion saisie est incorrecte ou tous les camarades de cette promotion sont inscrits !';
f59bc2fb 109 } else {
94590511
SJ
110 $subState->set('step', 2);
111 $subState->set('promo', $promo);
112 $subState->set('yearpromo', $yearpromo);
f0a52f1b
SJ
113 $subState->set('edu_type', $edu_type);
114 if ($edu_type == 'X') {
115 if ($yearpromo >= 1996 && $yearpromo < 2000) {
116 $subState->set('schoolid', ($yearpromo % 100) * 10 . '???');
117 } elseif($yearpromo >= 2000) {
118 $subState->set('schoolid', 100 + ($yearpromo % 100) . '???');
119 }
120 } else {
121 $subState->set('schoolid', '');
f59bc2fb 122 }
123 }
124 }
125 break;
126
127 case 2:
128 if (count($_POST)) {
460d8f55 129 $this->load('register.inc.php');
94590511
SJ
130 $subState->set('firstname', Post::t('firstname'));
131 $subState->set('lastname', Post::t('lastname'));
132 $subState->set('schoolid', Post::i('schoolid'));
133 $error = checkNewUser($subState);
f59bc2fb 134
94660e07
SJ
135 if ($error !== true) {
136 break;
137 }
94590511 138 $error = createAliases($subState);
94660e07
SJ
139 if ($error === true) {
140 unset($error);
94590511 141 $subState->set('step', 3);
f59bc2fb 142 }
143 }
144 break;
145
146 case 3:
147 if (count($_POST)) {
460d8f55 148 $this->load('register.inc.php');
97a82cd2
VZ
149
150 // Validate the email address format and domain.
c6310567 151 require_once 'emails.inc.php';
94660e07 152
5e2307dc 153 if (!isvalid_email(Post::v('email'))) {
94660e07 154 $error[] = "Le champ 'Email' n'est pas valide.";
5e2307dc 155 } elseif (!isvalid_email_redirection(Post::v('email'))) {
94590511 156 $error[] = $subState->s('forlife') . ' doit renvoyer vers un email existant '
94660e07 157 . 'valide, en particulier, il ne peut pas être renvoyé vers lui-même.';
f59bc2fb 158 }
97a82cd2
VZ
159
160 // Validate the birthday format and range.
94590511 161 $birth = Post::t('birthdate');
12e5d7a6 162 if (!preg_match('@^[0-3]?\d/[01]?\d/(19|20)?\d{2}$@', $birth)) {
94660e07 163 $error[] = "La 'Date de naissance' n'est pas correcte.";
35cd1be1 164 } else {
12e5d7a6 165 $birth = explode('/', $birth, 3);
94660e07 166 for ($i = 0; $i < 3; ++$i)
7caaaf6d 167 $birth[$i] = intval($birth[$i]);
94660e07
SJ
168 if ($birth[2] < 100) {
169 $birth[2] += 1900;
170 }
7caaaf6d 171 $year = $birth[2];
94590511 172 $promo = $subState->i('yearpromo');
35cd1be1 173 if ($year > $promo - 15 || $year < $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,
285 pnl.name AS lastname, pnf.name AS firstname,
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)
4c5a5921 294 WHERE hash = {?} AND hash != 'INSCRIT' AND a.state = 'pending'",
94590511 295 $nameTypes['name_ini'], $nameTypes['firstname_ini'], $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,
96700179
SJ
312 $birthdate, $lastname, $firstname, $promo, $sex, $birthdate_ref, $eduType) = $res->fetchOneRow();
313 $isX = ($eduType == 'x');
599e4774
SJ
314 $yearpromo = substr($forlife, -4);
315 $promo = str_replace(' (en cours)', $yearpromo, $promo);
f0a52f1b 316 $mail_domain = User::$sub_mail_domains[$eduType] . $globals->mail->domain;
f59bc2fb 317
97a82cd2
VZ
318 // Prepare the template for display.
319 $page->changeTpl('register/end.tpl');
97a82cd2 320 $page->assign('forlife', $forlife);
94590511 321 $page->assign('firstname', $firstname);
97a82cd2
VZ
322
323 // Check if the user did enter a valid password; if not (or if none is found),
324 // get her an information page.
94590511
SJ
325 if (Post::has('response')) {
326 $expected_response = sha1("$forlife:$password:" . S::v('challenge'));
327 if (Post::v('response') != $expected_response) {
97a82cd2
VZ
328 $page->trigError("Mot de passe invalide.");
329 S::logger($uid)->log('auth_fail', 'bad password (register/end)');
330 return;
331 }
332 } else {
333 return;
334 }
f59bc2fb 335
97a82cd2
VZ
336 //
337 // Create the user account.
338 //
dd9b3613 339 XDB::startTransaction();
94590511
SJ
340 XDB::execute("UPDATE accounts
341 SET password = {?}, state = 'active',
33a4f3f9 342 registration_date = NOW(), email = NULL
94590511
SJ
343 WHERE uid = {?}", $password, $uid);
344 XDB::execute("UPDATE profiles
345 SET birthdate = {?}, last_change = NOW()
346 WHERE pid = {?}", $birthdate, $pid);
c0436d0b
SJ
347 XDB::execute('INSERT INTO email_source_account (email, uid, type, flags, domain)
348 SELECT {?}, {?}, \'forlife\', \'\', id
349 FROM email_virtual_domains
350 WHERE name = {?}',
f036c896 351 $forlife, $uid, $mail_domain);
c0436d0b
SJ
352 XDB::execute('INSERT INTO email_source_account (email, uid, type, flags, domain)
353 SELECT {?}, {?}, \'alias\', \'bestalias\', id
354 FROM email_virtual_domains
355 WHERE name = {?}',
f036c896 356 $bestalias, $uid, $mail_domain);
94590511 357 if ($emailXorg2) {
c0436d0b
SJ
358 XDB::execute('INSERT INTO email_source_account (email, uid, type, flags, domain)
359 SELECT {?}, {?}, \'alias\', \'\', id
360 FROM email_virtual_domains
361 WHERE name = {?}',
f036c896 362 $emailXorg2, $uid, $mail_domain);
f59bc2fb 363 }
dd9b3613 364 XDB::commit();
f59bc2fb 365
97a82cd2 366 // Add the registration email address as first and only redirection.
726eaf7a 367 require_once 'emails.inc.php';
f0a52f1b 368 $user = User::getSilentWithUID($uid);
4b1a8575
SJ
369 $redirect = new Redirect($user);
370 $redirect->add_email($email);
f59bc2fb 371
3546b253
VZ
372 // Try to start a session (so the user don't have to log in); we will use
373 // the password available in Post:: to authenticate the user.
f0a52f1b 374 Platal::session()->start(AUTH_MDP);
3546b253
VZ
375
376 // Subscribe the user to the services she did request at registration time.
377 foreach (explode(',', $services) as $service) {
6ae6840d 378 require_once 'newsletter.inc.php';
3546b253
VZ
379 switch ($service) {
380 case 'ax_letter':
6ae6840d
RB
381 NewsLetter::forGroup(NewsLetter::GROUP_AX)->subscribe($user);
382 break;
383 case 'nl':
384 NewsLetter::forGroup(NewsLetter::GROUP_XORG)->subscribe($user);
3546b253
VZ
385 break;
386 case 'imap':
b4503762 387 Email::activate_storage($user, 'imap');
3546b253
VZ
388 break;
389 case 'ml_promo':
d1d7fe34
SJ
390 if ($isX) {
391 $r = XDB::query('SELECT id FROM groups WHERE diminutif = {?}', $yearpromo);
392 if ($r->numRows()) {
393 $asso_id = $r->fetchOneCell();
394 XDB::execute('INSERT IGNORE INTO group_members (uid, asso_id)
395 VALUES ({?}, {?})',
396 $uid, $asso_id);
397 try {
398 $mmlist = new MMList($user);
399 $mmlist->subscribe("promo" . $yearpromo);
400 } catch (Exception $e) {
401 PlErrorReport::report($e);
402 $page->trigError("L'inscription à la liste promo" . $yearpromo . " a échouée.");
403 }
e78be37f 404 }
3546b253
VZ
405 }
406 break;
3546b253
VZ
407 }
408 }
409
97a82cd2 410 // Log the registration in the user session.
03c0a3a7 411 S::logger($uid)->log('inscription', $email);
97a82cd2
VZ
412 XDB::execute("UPDATE register_pending
413 SET hash = 'INSCRIT'
414 WHERE uid = {?}", $uid);
f59bc2fb 415
97a82cd2 416 // Congratulate our newly registered user by email.
94590511 417 $mymail = new PlMailer('register/success.mail.tpl');
4b1a8575 418 $mymail->addTo("\"{$user->fullName()}\" <{$user->forlifeEmail()}>");
96700179 419 if ($isX) {
96700179
SJ
420 $mymail->setSubject('Bienvenue parmi les X sur le web !');
421 } else {
96700179
SJ
422 $mymail->setSubject('Bienvenue sur Polytechnique.org !');
423 }
f59bc2fb 424 $mymail->assign('forlife', $forlife);
94590511 425 $mymail->assign('firstname', $firstname);
f59bc2fb 426 $mymail->send();
427
97a82cd2 428 // Index the user, to allow her to appear in searches.
bbdfd693 429 Profile::rebuildSearchTokens($pid);
2a54eb4d 430
97a82cd2 431 // Notify other users which were watching for her arrival.
00ba8a74
SJ
432 XDB::execute('INSERT INTO contacts (uid, contact)
433 SELECT uid, ni_id
434 FROM watch_nonins
435 WHERE ni_id = {?}', $uid);
94590511
SJ
436 XDB::execute('DELETE FROM watch_nonins
437 WHERE ni_id = {?}', $uid);
438 Platal::session()->updateNbNotifs();
03c0a3a7 439
97a82cd2 440 // Forcibly register the new user on default forums.
94590511
SJ
441 $promoForum = 'xorg.promo.' . strtolower($promo);
442 $registeredForums = array('xorg.general', 'xorg.pa.divers', 'xorg.pa.logements', $promoForum);
443 foreach ($registeredForums as $forum) {
444 XDB::execute("INSERT INTO forum_subs (fid, uid)
97a82cd2 445 SELECT fid, {?}
94590511
SJ
446 FROM forums
447 WHERE name = {?}",
448 $uid, $val);
97a82cd2
VZ
449
450 // Notify the newsgroup admin of the promotion forum needs be created.
94590511
SJ
451 if (XDB::affectedRows() == 0 && $forum == $promoForum) {
452 $promoFull = new UserFilter(new UFC_Promo('=', UserFilter::DISPLAY, $promo));
453 $promoRegistered = new UserFilter(new PFC_And(
454 new UFC_Promo('=', UserFilter::DISPLAY, $promo),
455 new UFC_Registered(true),
456 new PFC_Not(new UFC_Dead())
457 ));
458 if ($promoRegistered->getTotalCount() > 0.2 * $promoFull->getTotalCount()) {
03c0a3a7
FB
459 $mymail = new PlMailer('admin/forums-promo.mail.tpl');
460 $mymail->assign('promo', $promo);
461 $mymail->send();
462 }
463 }
464 }
465
97a82cd2 466 // Update the global registration count stats.
ebfdf077 467 $globals->updateNbIns();
b5dd6f2f 468
97a82cd2
VZ
469 //
470 // Update collateral data sources, and inform watchers by email.
471 //
f59bc2fb 472
97a82cd2 473 // Email the referrer(s) of this new user.
94590511
SJ
474 $res = XDB::iterRow("SELECT sender, GROUP_CONCAT(email SEPARATOR ', ') AS mails, MAX(last) AS lastDate
475 FROM register_marketing
476 WHERE uid = {?}
477 GROUP BY sender
478 ORDER BY lastDate DESC", $uid);
97a82cd2
VZ
479 XDB::execute("UPDATE register_mstats
480 SET success = NOW()
481 WHERE uid = {?}", $uid);
f59bc2fb 482
d3447a09 483 $market = array();
94590511
SJ
484 while (list($senderid, $maketingEmails, $lastDate) = $res->next()) {
485 $sender = User::getWithUID($senderid);
07f1f729 486 $market[] = " - par {$sender->fullName()} sur $maketingEmails (le plus récemment le $lastDate)";
94590511
SJ
487 $mymail = new PlMailer('register/marketer.mail.tpl');
488 $mymail->setSubject("$firstname $lastname s'est inscrit à Polytechnique.org !");
330888b0 489 $mymail->addTo($sender);
94590511
SJ
490 $mymail->assign('sender', $sender);
491 $mymail->assign('firstname', $firstname);
492 $mymail->assign('lastname', $lastname);
493 $mymail->assign('promo', $promo);
494 $mymail->assign('sex', $sex);
f59bc2fb 495 $mymail->setTxtBody(wordwrap($msg, 72));
496 $mymail->send();
497 }
5f5f0eb5 498
97a82cd2 499 // Email the plat/al administrators about the registration.
9812efa0 500 if ($globals->register->notif) {
94590511
SJ
501 $mymail = new PlMailer('register/registration.mail.tpl');
502 $mymail->setSubject("Inscription de $firstname $lastname ($promo)");
503 $mymail->assign('firstname', $firstname);
504 $mymail->assign('lastname', $lastname);
505 $mymail->assign('promo', $promo);
506 $mymail->assign('sex', $sex);
507 $mymail->assign('birthdate', $birthdate);
508 $mymail->assign('birthdate_ref', $birthdate_ref);
509 $mymail->assign('forlife', $forlife);
510 $mymail->assign('email', $email);
4b0cf4e4 511 $mymail->assign('logger', S::logger());
defff1aa 512 if (count($market) > 0) {
94590511 513 $mymail->assign('market', implode("\n", $market));
defff1aa 514 }
9812efa0 515 $mymail->setTxtBody($msg);
eaf30d86 516 $mymail->send();
9812efa0 517 }
f59bc2fb 518
97a82cd2 519 // Remove old pending marketing requests for the new user.
e654517d 520 Marketing::clear($uid);
f59bc2fb 521
97a0a459
FB
522 pl_redirect('profile/edit');
523 }
f59bc2fb 524}
525
a7de4ef7 526// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
f59bc2fb 527?>