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