2 /***************************************************************************
3 * Copyright (C) 2003-2006 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
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. *
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. *
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 *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
22 class RegisterModule
extends PLModule
27 'register' => $this->make_hook('register', AUTH_PUBLIC
),
28 'register/end' => $this->make_hook('end', AUTH_PUBLIC
),
29 'register/success' => $this->make_hook('success', AUTH_MDP
),
33 function handler_register(&$page, $hash = null
)
37 $sub_state = Session
::getMixed('sub_state', Array());
38 if (!isset($sub_state['step'])) {
39 $sub_state['step'] = 0;
41 if (Get
::has('back') && Get
::getInt('back') < $sub_state['step']) {
42 $sub_state['step'] = max(0,Get
::getInt('back'));
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
50 WHERE m.hash={?}", $hash);
51 if (list($uid, $promo, $nom, $prenom, $ourmat) = $res->fetchOneRow()) {
52 $sub_state['uid'] = $uid;
53 $sub_state['hash'] = $hash;
54 $sub_state['promo'] = $promo;
55 $sub_state['nom'] = $nom;
56 $sub_state['prenom'] = $prenom;
57 $sub_state['ourmat'] = $ourmat;
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']);
67 switch ($sub_state['step']) {
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);
80 if (Post
::has('promo')) {
81 $promo = Post
::getInt('promo');
82 if ($promo < 1900 ||
$promo > date('Y')) {
83 $err = "La promotion saisie est incorrecte !";
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) . '???';
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);
104 if ($err !== true
) { break; }
105 $err = create_aliases($sub_state);
108 $sub_state['step'] = 3;
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 ".
120 "valide, en particulier, il ne peut pas être renvoyé vers lui-même.";
122 if (!preg_match('/^[0-3][0-9][01][0-9][12][90][0-9][0-9]$/',
123 Post
::get('naissance')))
125 $err[] = "La 'Date de naissance' n'est pas correcte.";
129 $err = join('<br />', $err);
131 $birth = Env
::get('naissance');
132 $sub_state['naissance'] = sprintf("%s-%s-%s",
136 $sub_state['email'] = Post
::get('email');
137 $sub_state['step'] = 4;
138 finish_ins($sub_state);
144 $_SESSION['sub_state'] = $sub_state;
145 $page->changeTpl('register/step'.intval($sub_state['step']).'.tpl');
146 $page->assign('simple', true
);
154 function handler_end(&$page, $hash = null
)
158 $page->changeTpl('register/end.tpl');
160 require_once('user.func.inc.php');
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,
167 FROM register_pending AS r
168 INNER JOIN auth_user_md5 AS u ON r.uid = u.user_id
169 WHERE hash={?} AND hash!='INSCRIT'", $hash);
172 if (!$hash ||
!list($uid, $forlife, $bestalias, $mailorg2, $password, $email,
173 $naissance, $nom, $prenom, $promo, $femme) = $res->fetchOneRow())
175 $page->kill("<p>Cette adresse n'existe pas, ou plus, sur le serveur.</p>
176 <p>Causes probables :</p>
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
184 tous les 30 jours.</li>
185 <li>Tu es en fait déjà inscrit.</li>
191 /***********************************************************/
192 /****************** REALLY CREATE ACCOUNT ******************/
193 /***********************************************************/
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,
203 $globals->xdb
->execute('INSERT INTO aliases (id,alias,type,flags)
204 VALUES ({?}, {?}, "alias", "bestalias")',
207 $globals->xdb
->execute('INSERT INTO aliases (id,alias,type)
208 VALUES ({?}, {?}, "alias")', $uid,
212 require_once('emails.inc.php');
213 $redirect = new Redirect($uid);
214 $redirect->add_email($email);
216 // on cree un objet logger et on log l'inscription
217 $logger = new DiogenesCoreLogger($uid);
218 $logger->log('inscription', $email);
220 $globals->xdb
->execute('UPDATE register_pending SET hash="INSCRIT" WHERE uid={?}', $uid);
222 $globals->hook
->subscribe($forlife, $uid, $promo, $password);
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);
230 start_connexion($uid,false
);
231 $_SESSION['auth'] = AUTH_MDP
;
233 /***********************************************************/
234 /************* envoi d'un mail au démarcheur ***************/
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);
246 while (list($salias, $snom, $sprenom, $sfemme) = $res->next()) {
247 require_once('diogenes/diogenes.hermes.inc.php');
248 $mymail = new HermesMailer();
249 $mymail->setSubject("$prenom $nom s'est inscrit à Polytechnique.org !");
250 $mymail->setFrom('"Marketing Polytechnique.org" <register@polytechnique.org>');
251 $mymail->addTo("\"$sprenom $snom\" <$salias@{$globals->mail->domain}>");
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"
257 . "Bien cordialement,\n"
258 . "L'équipe Polytechnique.org";
259 $mymail->setTxtBody(wordwrap($msg, 72));
263 $globals->xdb
->execute("DELETE FROM register_marketing WHERE uid = {?}", $uid);
265 redirect($globals->baseurl
.'/register/success');
266 $page->assign('uid', $uid);
271 function handler_success(&$page)
275 $page->changeTpl('register/success.tpl');
277 if (Env
::has('response2')) {
278 $_SESSION['password'] = $password = Post
::get('response2');
280 $globals->xdb
->execute('UPDATE auth_user_md5 SET password={?}
281 WHERE user_id={?}', $password,
282 Session
::getInt('uid'));
284 $log =& Session
::getMixed('log');
285 $log->log('passwd', '');
287 if (Cookie
::get('ORGaccess')) {
288 require_once('secure_hash.inc.php');
289 setcookie('ORGaccess', hash_encrypt($password), (time()+
25920000), '/', '' ,0);
292 $page->assign('mdpok', true
);
295 $page->addJsLink('javascript/motdepasse.js');