f59bc2fb |
1 | <?php |
2 | /*************************************************************************** |
3 | * Copyright (C) 2003-2006 Polytechnique.org * |
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( |
20d90835 |
27 | 'register' => $this->make_hook('register', AUTH_PUBLIC), |
28 | 'register/end' => $this->make_hook('end', AUTH_PUBLIC), |
2b6d403c |
29 | 'register/end.php' => $this->make_hook('end_old', AUTH_PUBLIC), |
f59bc2fb |
30 | 'register/success' => $this->make_hook('success', AUTH_MDP), |
31 | ); |
32 | } |
33 | |
20d90835 |
34 | function handler_register(&$page, $hash = null) |
f59bc2fb |
35 | { |
36 | global $globals; |
37 | |
38 | $sub_state = Session::getMixed('sub_state', Array()); |
39 | if (!isset($sub_state['step'])) { |
40 | $sub_state['step'] = 0; |
41 | } |
42 | if (Get::has('back') && Get::getInt('back') < $sub_state['step']) { |
43 | $sub_state['step'] = max(0,Get::getInt('back')); |
44 | } |
45 | |
2b6d403c |
46 | // Compatibility with old sources, keep it atm |
47 | if (!$hash && Env::has('hash')) { |
48 | $hash = Env::get('hash'); |
49 | } |
50 | |
20d90835 |
51 | if ($hash) { |
08cce2ff |
52 | $res = XDB::query( |
f59bc2fb |
53 | "SELECT m.uid, u.promo, u.nom, u.prenom, u.matricule |
54 | FROM register_marketing AS m |
55 | INNER JOIN auth_user_md5 AS u ON u.user_id = m.uid |
20d90835 |
56 | WHERE m.hash={?}", $hash); |
f59bc2fb |
57 | if (list($uid, $promo, $nom, $prenom, $ourmat) = $res->fetchOneRow()) { |
58 | $sub_state['uid'] = $uid; |
20d90835 |
59 | $sub_state['hash'] = $hash; |
f59bc2fb |
60 | $sub_state['promo'] = $promo; |
61 | $sub_state['nom'] = $nom; |
62 | $sub_state['prenom'] = $prenom; |
63 | $sub_state['ourmat'] = $ourmat; |
64 | |
08cce2ff |
65 | XDB::execute( |
f59bc2fb |
66 | "REPLACE INTO register_mstats (uid,sender,success) |
67 | SELECT m.uid, m.sender, 0 |
68 | FROM register_marketing AS m |
69 | WHERE m.hash", $sub_state['hash']); |
70 | } |
71 | } |
72 | |
73 | switch ($sub_state['step']) { |
74 | case 0: |
75 | if (Post::has('step1')) { |
76 | $sub_state['step'] = 1; |
77 | if (isset($sub_state['hash'])) { |
78 | $sub_state['step'] = 3; |
79 | require_once('register.inc.php'); |
80 | create_aliases($sub_state); |
81 | } |
82 | } |
83 | break; |
84 | |
85 | case 1: |
86 | if (Post::has('promo')) { |
87 | $promo = Post::getInt('promo'); |
88 | if ($promo < 1900 || $promo > date('Y')) { |
89 | $err = "La promotion saisie est incorrecte !"; |
90 | } else { |
91 | $sub_state['step'] = 2; |
92 | $sub_state['promo'] = $promo; |
93 | if ($promo >= 1996 && $promo<2000) { |
94 | $sub_state['mat'] = ($promo % 100)*10 . '???'; |
95 | } elseif($promo >= 2000) { |
96 | $sub_state['mat'] = 100 + ($promo % 100) . '???'; |
97 | } |
98 | } |
99 | } |
100 | break; |
101 | |
102 | case 2: |
103 | if (count($_POST)) { |
104 | require_once('register.inc.php'); |
105 | $sub_state['prenom'] = Post::get('prenom'); |
106 | $sub_state['nom'] = Post::get('nom'); |
107 | $sub_state['mat'] = Post::get('mat'); |
108 | $err = check_new_user($sub_state); |
109 | |
110 | if ($err !== true) { break; } |
111 | $err = create_aliases($sub_state); |
112 | if ($err === true) { |
113 | unset($err); |
114 | $sub_state['step'] = 3; |
115 | } |
116 | } |
117 | break; |
118 | |
119 | case 3: |
120 | if (count($_POST)) { |
121 | require_once('register.inc.php'); |
122 | if (!isvalid_email(Post::get('email'))) { |
123 | $err[] = "Le champ 'E-mail' n'est pas valide."; |
124 | } elseif (!isvalid_email_redirection(Post::get('email'))) { |
125 | $err[] = $sub_state['forlife']." doit renvoyer vers un email existant ". |
20d90835 |
126 | "valide, en particulier, il ne peut pas être renvoyé vers lui-même."; |
f59bc2fb |
127 | } |
128 | if (!preg_match('/^[0-3][0-9][01][0-9][12][90][0-9][0-9]$/', |
129 | Post::get('naissance'))) |
130 | { |
131 | $err[] = "La 'Date de naissance' n'est pas correcte."; |
132 | } |
133 | |
134 | if (isset($err)) { |
135 | $err = join('<br />', $err); |
136 | } else { |
137 | $birth = Env::get('naissance'); |
138 | $sub_state['naissance'] = sprintf("%s-%s-%s", |
139 | substr($birth,4,4), |
140 | substr($birth,2,2), |
141 | substr($birth,0,2)); |
142 | $sub_state['email'] = Post::get('email'); |
143 | $sub_state['step'] = 4; |
144 | finish_ins($sub_state); |
145 | } |
146 | } |
147 | break; |
148 | } |
149 | |
150 | $_SESSION['sub_state'] = $sub_state; |
151 | $page->changeTpl('register/step'.intval($sub_state['step']).'.tpl'); |
20d90835 |
152 | $page->assign('simple', true); |
f59bc2fb |
153 | if (isset($err)) { |
154 | $page->trig($err); |
155 | } |
f59bc2fb |
156 | } |
157 | |
2b6d403c |
158 | function handler_end_old(&$page) |
159 | { |
160 | return $this->handler_end($page, Env::get('hash')); |
161 | } |
162 | |
f59bc2fb |
163 | function handler_end(&$page, $hash = null) |
164 | { |
165 | global $globals; |
166 | |
167 | $page->changeTpl('register/end.tpl'); |
168 | |
169 | require_once('user.func.inc.php'); |
170 | |
171 | if ($hash) { |
08cce2ff |
172 | $res = XDB::query( |
f59bc2fb |
173 | "SELECT r.uid, r.forlife, r.bestalias, r.mailorg2, |
174 | r.password, r.email, r.naissance, u.nom, u.prenom, |
175 | u.promo, u.flags |
176 | FROM register_pending AS r |
177 | INNER JOIN auth_user_md5 AS u ON r.uid = u.user_id |
20d90835 |
178 | WHERE hash={?} AND hash!='INSCRIT'", $hash); |
f59bc2fb |
179 | } |
180 | |
181 | if (!$hash || !list($uid, $forlife, $bestalias, $mailorg2, $password, $email, |
182 | $naissance, $nom, $prenom, $promo, $femme) = $res->fetchOneRow()) |
183 | { |
184 | $page->kill("<p>Cette adresse n'existe pas, ou plus, sur le serveur.</p> |
185 | <p>Causes probables :</p> |
186 | <ol> |
20d90835 |
187 | <li>Vérifie que tu visites l'adresse du dernier |
188 | e-mail reçu s'il y en a eu plusieurs.</li> |
189 | <li>Tu as peut-être mal copié l'adresse reçue par |
190 | mail, vérifie-la à la main.</li> |
191 | <li>Tu as peut-être attendu trop longtemps pour |
192 | confirmer. Les pré-inscriptions sont annulées |
f59bc2fb |
193 | tous les 30 jours.</li> |
20d90835 |
194 | <li>Tu es en fait déjà inscrit.</li> |
f59bc2fb |
195 | </ol>"); |
196 | } |
197 | |
198 | |
199 | |
200 | /***********************************************************/ |
201 | /****************** REALLY CREATE ACCOUNT ******************/ |
202 | /***********************************************************/ |
203 | |
08cce2ff |
204 | XDB::execute('UPDATE auth_user_md5 |
f59bc2fb |
205 | SET password={?}, perms="user", |
206 | date=NOW(), naissance={?}, date_ins = NOW() |
207 | WHERE user_id={?}', $password, $naissance, $uid); |
08cce2ff |
208 | XDB::execute('REPLACE INTO auth_user_quick (user_id) VALUES ({?})', $uid); |
209 | XDB::execute('INSERT INTO aliases (id,alias,type) |
f59bc2fb |
210 | VALUES ({?}, {?}, "a_vie")', $uid, |
211 | $forlife); |
08cce2ff |
212 | XDB::execute('INSERT INTO aliases (id,alias,type,flags) |
f59bc2fb |
213 | VALUES ({?}, {?}, "alias", "bestalias")', |
214 | $uid, $bestalias); |
215 | if ($mailorg2) { |
08cce2ff |
216 | XDB::execute('INSERT INTO aliases (id,alias,type) |
f59bc2fb |
217 | VALUES ({?}, {?}, "alias")', $uid, |
218 | $mailorg2); |
219 | } |
220 | |
221 | require_once('emails.inc.php'); |
222 | $redirect = new Redirect($uid); |
223 | $redirect->add_email($email); |
224 | |
225 | // on cree un objet logger et on log l'inscription |
226 | $logger = new DiogenesCoreLogger($uid); |
227 | $logger->log('inscription', $email); |
228 | |
08cce2ff |
229 | XDB::execute('UPDATE register_pending SET hash="INSCRIT" WHERE uid={?}', $uid); |
f59bc2fb |
230 | |
231 | $globals->hook->subscribe($forlife, $uid, $promo, $password); |
232 | |
233 | require_once('xorg.mailer.inc.php'); |
234 | $mymail = new XOrgMailer('register/inscription.reussie.tpl'); |
235 | $mymail->assign('forlife', $forlife); |
236 | $mymail->assign('prenom', $prenom); |
237 | $mymail->send(); |
238 | |
239 | start_connexion($uid,false); |
240 | $_SESSION['auth'] = AUTH_MDP; |
241 | |
242 | /***********************************************************/ |
20d90835 |
243 | /************* envoi d'un mail au démarcheur ***************/ |
f59bc2fb |
244 | /***********************************************************/ |
08cce2ff |
245 | $res = XDB::iterRow( |
f59bc2fb |
246 | "SELECT DISTINCT sa.alias, IF(s.nom_usage,s.nom_usage,s.nom) AS nom, |
247 | s.prenom, s.flags AS femme |
248 | FROM register_marketing AS m |
249 | INNER JOIN auth_user_md5 AS s ON ( m.sender = s.user_id ) |
250 | INNER JOIN aliases AS sa ON ( sa.id = m.sender |
251 | AND FIND_IN_SET('bestalias', sa.flags) ) |
252 | WHERE m.uid = {?}", $uid); |
08cce2ff |
253 | XDB::execute("UPDATE register_mstats SET success=NOW() WHERE uid={?}", $uid); |
f59bc2fb |
254 | |
255 | while (list($salias, $snom, $sprenom, $sfemme) = $res->next()) { |
256 | require_once('diogenes/diogenes.hermes.inc.php'); |
257 | $mymail = new HermesMailer(); |
20d90835 |
258 | $mymail->setSubject("$prenom $nom s'est inscrit à Polytechnique.org !"); |
f59bc2fb |
259 | $mymail->setFrom('"Marketing Polytechnique.org" <register@polytechnique.org>'); |
260 | $mymail->addTo("\"$sprenom $snom\" <$salias@{$globals->mail->domain}>"); |
20d90835 |
261 | $msg = ($sfemme?'Cher':'Chère')." $sprenom,\n\n" |
262 | . "Nous t'écrivons pour t'informer que {$prenom} {$nom} (X{$promo}), " |
263 | . "que tu avais incité".($femme?'e':'')." à s'inscrire à Polytechnique.org, " |
264 | . "vient à l'instant de terminer son inscription.\n\n" |
265 | . "Merci de ta participation active à la reconnaissance de ce site !!!\n\n" |
f59bc2fb |
266 | . "Bien cordialement,\n" |
20d90835 |
267 | . "L'équipe Polytechnique.org"; |
f59bc2fb |
268 | $mymail->setTxtBody(wordwrap($msg, 72)); |
269 | $mymail->send(); |
270 | } |
271 | |
08cce2ff |
272 | XDB::execute("DELETE FROM register_marketing WHERE uid = {?}", $uid); |
f59bc2fb |
273 | |
20d90835 |
274 | redirect($globals->baseurl.'/register/success'); |
f59bc2fb |
275 | $page->assign('uid', $uid); |
f59bc2fb |
276 | } |
277 | |
278 | function handler_success(&$page) |
279 | { |
280 | global $globals; |
281 | |
282 | $page->changeTpl('register/success.tpl'); |
283 | |
284 | if (Env::has('response2')) { |
285 | $_SESSION['password'] = $password = Post::get('response2'); |
286 | |
08cce2ff |
287 | XDB::execute('UPDATE auth_user_md5 SET password={?} |
f59bc2fb |
288 | WHERE user_id={?}', $password, |
289 | Session::getInt('uid')); |
290 | |
291 | $log =& Session::getMixed('log'); |
292 | $log->log('passwd', ''); |
293 | |
294 | if (Cookie::get('ORGaccess')) { |
295 | require_once('secure_hash.inc.php'); |
296 | setcookie('ORGaccess', hash_encrypt($password), (time()+25920000), '/', '' ,0); |
297 | } |
298 | |
299 | $page->assign('mdpok', true); |
300 | } |
301 | |
302 | $page->addJsLink('javascript/motdepasse.js'); |
f59bc2fb |
303 | } |
304 | } |
305 | |
306 | ?> |