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