2 /***************************************************************************
3 * Copyright (C) 2003-2010 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 // {{{ function checkId
24 function checkId(&$subState)
26 $subState->set('xorgid', Profile
::getXorgId($subState->i('schoolid')));
27 if (!$subState->v('xorgid')) {
28 return 'Le matricule est incorrect.';
31 $uf = new UserFilter(new PFC_And(
32 new UFC_UID($subState->i('xorg_id')),
33 new PFC_Not(new UFC_Dead())
35 $profile = $uf->getProfile();
37 if ($profile->__get('state') == 'active') {
38 return "Tu es déjà inscrit ou ton matricule est incorrect !";
40 if ($profile->promo() != $subState->s('promo')) {
41 return 'Le matricule est incorrect.';
44 if (!$profile->compareNames($subState->s('firstname'), $subState->s('lastname'))) {
45 return "Erreur dans l'identification. Réessaie, il y a une erreur quelque part !";
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'));
57 // {{{ function checkOldId
59 function checkOldId(&$subState)
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
))
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());
72 $subState->set('watch', $profile->owner()->watch
);
73 $subState->set('birthdateRef', $profile->__get('birthdate_ref'));
74 $subState->set('xorgid', $profile->__get('xorg_id'));
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
)
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());
88 $subState->set('watch', $profile->owner()->watch
);
89 $subState->set('birthdateRef', $profile->__get('birthdate_ref'));
90 $subState->set('xorgid', $profile->__get('xorg_id'));
91 return 'Tu es vraisemblablement déjà inscrit !';
94 return 'Erreur : vérifie que tu as bien orthographié ton nom !';
98 // {{{ function checkNewUser
100 function checkNewUser(&$subState)
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));
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));
112 if ($subState->i('yearpromo') >= 1996) {
113 $res = checkId($subState);
115 $res = checkOldId($subState);
125 // {{{ function createAliases
127 function createAliases(&$subState)
131 $emailXorg = PlUser
::makeUserName($subState->t('firstname'), $subState->t('lastname'));
132 $emailXorg2 = $emailXorg . sprintf(".%02u", ($subState->i('yearpromo') %
100));
134 $res = XDB
::query("SELECT hruid
136 WHERE uid = {?} AND hruid != ''", $subState->i('uid'));
137 if ($res->numRows() == 0) {
138 return "Tu n'as pas d'adresse à vie pré-attribuée.<br />"
139 . "Envoie un mail à <a href=\"mailto:support@{$globals->mail->domain}</a>\">"
140 . "support@{$globals->mail->domain}</a> en expliquant ta situation.";
142 $forlife = $res->fetchOneCell();
145 $res = XDB
::query('SELECT uid, type, expire
147 WHERE alias = {?}', $emailXorg);
148 if ($res->numRows()) {
149 list($h_id, $h_type, $expire) = $res->fetchOneRow();
150 if ($h_type != 'homonyme' and empty($expire)) {
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)
155 VALUES ({?}, {?})', $h_id, $h_id);
156 XDB
::execute('REPLACE INTO homonyms (homonyme_id, uid)
157 VALUES ({?}, {?})', $h_id, $uid);
158 $res = XDB
::query('SELECT alias
160 WHERE uid = {?} AND expire IS NULL', $h_id);
161 $als = $res->fetchColumn();
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));
168 $mailer->SetTxtBody(wordwrap($msg,72));
172 $subState->set('forlife', $forlife);
173 $subState->set('bestalias', $emailXorg2);
174 $subState->set('emailXorg2', null
);
176 $subState->set('forlife', $forlife);
177 $subState->set('bestalias', $emailXorg);
178 $subState->set('emailXorg2', $emailXorg2);
185 // {{{ function finishRegistration
187 function finishRegistration($subState)
191 $hash = rand_url_id(12);
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')));
199 $mymail = new PlMailer('register/end.mail.tpl');
200 $mymail->assign('emailXorg', $subState->s('bestalias'));
201 $mymail->assign('to', $subState->s('email'));
202 $mymail->assign('baseurl', $globals->baseurl
);
203 $mymail->assign('hash', $hash);
204 $mymail->assign('subject', $subState->s('bestalias') . '@' . $globals->mail
->domain
);
209 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: