Commit | Line | Data |
---|---|---|
0337d704 | 1 | <?php |
2 | /*************************************************************************** | |
9f5bd98e | 3 | * Copyright (C) 2003-2010 Polytechnique.org * |
0337d704 | 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 | ||
94590511 | 22 | // {{{ function checkId |
0337d704 | 23 | |
94590511 | 24 | function checkId(&$subState) |
0337d704 | 25 | { |
94590511 SJ |
26 | $subState->set('xorgid', Profile::getXorgId($subState->i('schoolid'))); |
27 | if (!$subState->v('xorgid')) { | |
28 | return 'Le matricule est incorrect.'; | |
0337d704 | 29 | } |
30 | ||
94590511 | 31 | $uf = new UserFilter(new PFC_And( |
16c709a0 | 32 | new UFC_SchoolId('xorg', $subState->i('xorgid')), |
94590511 SJ |
33 | new PFC_Not(new UFC_Dead()) |
34 | )); | |
4b0cf4e4 | 35 | $profile = $uf->getProfile(); |
0337d704 | 36 | |
4b0cf4e4 | 37 | if ($profile->__get('state') == 'active') { |
94590511 SJ |
38 | return "Tu es déjà inscrit ou ton matricule est incorrect !"; |
39 | } | |
4b0cf4e4 | 40 | if ($profile->promo() != $subState->s('promo')) { |
94590511 SJ |
41 | return 'Le matricule est incorrect.'; |
42 | } | |
0337d704 | 43 | |
4b0cf4e4 | 44 | if (!$profile->compareNames($subState->s('firstname'), $subState->s('lastname'))) { |
94590511 | 45 | return "Erreur dans l'identification. Réessaie, il y a une erreur quelque part !"; |
0337d704 | 46 | } |
47 | ||
4b0cf4e4 SJ |
48 | $subState->set('lastname', $profile->lastName()); |
49 | $subState->set('firstname', $profile->firstName()); | |
50 | $subState->set('uid', $profile->owner()->id()); | |
51 | $subState->set('watch', $profile->owner()->watch); | |
52 | $subState->set('birthdateRef', $profile->__get('birthdate_ref')); | |
0337d704 | 53 | return true; |
54 | } | |
55 | ||
56 | // }}} | |
94590511 | 57 | // {{{ function checkOldId |
0337d704 | 58 | |
94590511 | 59 | function checkOldId(&$subState) |
0337d704 | 60 | { |
94590511 SJ |
61 | $uf = new UserFilter(new PFC_And( |
62 | new PFC_Not(new UFC_Dead()), | |
63 | new UFC_Promo('=', UserFilter::DISPLAY, $subState->s('promo')), | |
64 | new PFC_Not(new UFC_Registered(true)) | |
65 | )); | |
66 | $it = $uf->iterProfiles(); | |
67 | while ($profile = $it->next()) { | |
68 | if ($profile->compareNames($subState->s('firstname'), $subState->s('lastname'))) { | |
69 | $subState->set('lastname', $profile->lastName()); | |
70 | $subState->set('firstname', $profile->firstName()); | |
71 | $subState->set('uid', $profile->owner()->id()); | |
4b0cf4e4 | 72 | $subState->set('watch', $profile->owner()->watch); |
94590511 SJ |
73 | $subState->set('birthdateRef', $profile->__get('birthdate_ref')); |
74 | $subState->set('xorgid', $profile->__get('xorg_id')); | |
0337d704 | 75 | return true; |
76 | } | |
77 | } | |
78 | ||
94590511 SJ |
79 | $uf = new UserFilter(new PFC_And( |
80 | new PFC_Not(new UFC_Dead()), | |
81 | new UFC_Promo('=', UserFilter::DISPLAY, $subState->s('promo')), | |
82 | new UFC_Registered(true) | |
83 | )); | |
84 | $it = $uf->iterProfiles(); | |
85 | while ($profile = $it->next()) { | |
86 | if ($profile->compareNames($subState->s('firstname'), $subState->s('lastname'))) { | |
87 | $subState->set('uid', $profile->owner()->id()); | |
4b0cf4e4 | 88 | $subState->set('watch', $profile->owner()->watch); |
94590511 SJ |
89 | $subState->set('birthdateRef', $profile->__get('birthdate_ref')); |
90 | $subState->set('xorgid', $profile->__get('xorg_id')); | |
91 | return 'Tu es vraisemblablement déjà inscrit !'; | |
0337d704 | 92 | } |
93 | } | |
94590511 | 94 | return 'Erreur : vérifie que tu as bien orthographié ton nom !'; |
0337d704 | 95 | } |
96 | ||
97 | // }}} | |
94590511 | 98 | // {{{ function checkNewUser |
0337d704 | 99 | |
94590511 | 100 | function checkNewUser(&$subState) |
0337d704 | 101 | { |
94590511 SJ |
102 | $firstname = preg_replace("/[ \t]+/", ' ', $subState->t('firstname')); |
103 | $firstname = preg_replace("/--+/", '-', $firstname); | |
104 | $firstname = preg_replace("/''+/", '\'', $firstname); | |
105 | $subState->set('firstname', PlUser::fixFirstnameCase($firstname)); | |
106 | ||
107 | $lastname = preg_replace("/[ \t]+/", ' ', $subState->t('lastname')); | |
108 | $lastname = preg_replace("/--+/", '-', $lastname); | |
109 | $lastname = preg_replace("/''+/", '\'', $lastname); | |
110 | $subState->set('lastname', mb_strtoupper($lastname)); | |
111 | ||
112 | if ($subState->i('yearpromo') >= 1996) { | |
113 | $res = checkId($subState); | |
0337d704 | 114 | } else { |
94590511 SJ |
115 | $res = checkOldId($subState); |
116 | } | |
117 | if ($res !== true) { | |
118 | return $res; | |
0337d704 | 119 | } |
0337d704 | 120 | |
121 | return true; | |
122 | } | |
123 | ||
124 | // }}} | |
94590511 | 125 | // {{{ function createAliases |
0337d704 | 126 | |
94590511 | 127 | function createAliases(&$subState) |
0337d704 | 128 | { |
115c90db | 129 | global $globals; |
0337d704 | 130 | |
94590511 SJ |
131 | $emailXorg = PlUser::makeUserName($subState->t('firstname'), $subState->t('lastname')); |
132 | $emailXorg2 = $emailXorg . sprintf(".%02u", ($subState->i('yearpromo') % 100)); | |
0337d704 | 133 | |
94590511 SJ |
134 | $res = XDB::query("SELECT hruid |
135 | FROM accounts | |
136 | WHERE uid = {?} AND hruid != ''", $subState->i('uid')); | |
56081a9c VZ |
137 | if ($res->numRows() == 0) { |
138 | return "Tu n'as pas d'adresse à vie pré-attribuée.<br />" | |
4ce2a30a | 139 | . "Envoie un mail à <a href=\"mailto:support@{$globals->mail->domain}</a>\">" |
56081a9c VZ |
140 | . "support@{$globals->mail->domain}</a> en expliquant ta situation."; |
141 | } else { | |
56081a9c | 142 | $forlife = $res->fetchOneCell(); |
0337d704 | 143 | } |
eaf30d86 | 144 | |
94590511 SJ |
145 | $res = XDB::query('SELECT uid, type, expire |
146 | FROM aliases | |
147 | WHERE alias = {?}', $emailXorg); | |
56081a9c | 148 | if ($res->numRows()) { |
0337d704 | 149 | list($h_id, $h_type, $expire) = $res->fetchOneRow(); |
56081a9c | 150 | if ($h_type != 'homonyme' and empty($expire)) { |
94590511 SJ |
151 | XDB::execute('UPDATE aliases |
152 | SET expire = ADDDATE(NOW(), INTERVAL 1 MONTH) | |
153 | WHERE alias = {?}', $emailXorg); | |
154 | XDB::execute('REPLACE INTO homonyms (homonyme_id, uid) | |
edf5e979 | 155 | VALUES ({?}, {?})', $subState->i('uid'), $h_id); |
94590511 | 156 | XDB::execute('REPLACE INTO homonyms (homonyme_id, uid) |
edf5e979 | 157 | VALUES ({?}, {?})', $h_id, $subState->i('uid')); |
94590511 SJ |
158 | $res = XDB::query('SELECT alias |
159 | FROM aliases | |
160 | WHERE uid = {?} AND expire IS NULL', $h_id); | |
0337d704 | 161 | $als = $res->fetchColumn(); |
162 | ||
94590511 SJ |
163 | $mailer = new PlMailer('register/lostalias.mail.tpl'); |
164 | $mailer->addTo($emailXorg . '@' . $globals->mail->domain); | |
165 | $mailer->setSubject("Perte de ton alias $emailXorg dans un mois !"); | |
166 | $mailer->assign('emailXorg', $emailXorg); | |
167 | $mailer->assign('als', join(', ', $als)); | |
0337d704 | 168 | $mailer->SetTxtBody(wordwrap($msg,72)); |
169 | $mailer->send(); | |
170 | } | |
171 | ||
94590511 SJ |
172 | $subState->set('forlife', $forlife); |
173 | $subState->set('bestalias', $emailXorg2); | |
174 | $subState->set('emailXorg2', null); | |
0337d704 | 175 | } else { |
94590511 SJ |
176 | $subState->set('forlife', $forlife); |
177 | $subState->set('bestalias', $emailXorg); | |
178 | $subState->set('emailXorg2', $emailXorg2); | |
0337d704 | 179 | } |
180 | ||
181 | return true; | |
182 | } | |
183 | ||
184 | // }}} | |
94590511 | 185 | // {{{ function finishRegistration |
0337d704 | 186 | |
94590511 | 187 | function finishRegistration($subState) |
0337d704 | 188 | { |
189 | global $globals; | |
0337d704 | 190 | |
97a82cd2 | 191 | $hash = rand_url_id(12); |
94590511 SJ |
192 | XDB::execute('REPLACE INTO register_pending (uid, forlife, bestalias, mailorg2, password, |
193 | email, date, relance, naissance, hash, services) | |
194 | VALUES ({?}, {?}, {?}, {?}, {?}, {?}, NOW(), 0, {?}, {?}, {?})', | |
195 | $subState->i('uid'), $subState->s('forlife'), $subState->s('bestalias'), | |
196 | $subState->s('emailXorg2'), $subState->s('password'), $subState->s('email'), | |
197 | $subState->s('birthdate'), $hash, implode(',', $subState->v('services'))); | |
198 | ||
199 | $mymail = new PlMailer('register/end.mail.tpl'); | |
200 | $mymail->assign('emailXorg', $subState->s('bestalias')); | |
4b0cf4e4 | 201 | $mymail->assign('to', $subState->s('email')); |
0337d704 | 202 | $mymail->assign('baseurl', $globals->baseurl); |
94590511 | 203 | $mymail->assign('hash', $hash); |
4b0cf4e4 | 204 | $mymail->assign('subject', $subState->s('bestalias') . '@' . $globals->mail->domain); |
0337d704 | 205 | $mymail->send(); |
206 | } | |
207 | ||
208 | // }}} | |
a7de4ef7 | 209 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
0337d704 | 210 | ?> |