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