Only gives number of occurencies in profile_merge_issues when database check is verbo...
[platal.git] / modules / register / register.inc.php
CommitLineData
0337d704 1<?php
2/***************************************************************************
9f5bd98e 3 * Copyright (C) 2003-2010 Polytechnique.org *
0337d704 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
94590511 22// {{{ function checkId
0337d704 23
94590511 24function checkId(&$subState)
0337d704 25{
94590511
SJ
26 $subState->set('xorgid', Profile::getXorgId($subState->i('schoolid')));
27 if (!$subState->v('xorgid')) {
28 return 'Le matricule est incorrect.';
0337d704 29 }
30
94590511 31 $uf = new UserFilter(new PFC_And(
16c709a0 32 new UFC_SchoolId('xorg', $subState->i('xorgid')),
f09bdd3d
FB
33 new PFC_Not(new UFC_Dead()),
34 new PFC_Not(new UFC_Registered(true))
94590511 35 ));
4b0cf4e4 36 $profile = $uf->getProfile();
f09bdd3d 37 if (is_null($profile)) {
94590511
SJ
38 return "Tu es déjà inscrit ou ton matricule est incorrect !";
39 }
f09bdd3d 40
4b0cf4e4 41 if ($profile->promo() != $subState->s('promo')) {
94590511
SJ
42 return 'Le matricule est incorrect.';
43 }
0337d704 44
4b0cf4e4 45 if (!$profile->compareNames($subState->s('firstname'), $subState->s('lastname'))) {
94590511 46 return "Erreur dans l'identification. Réessaie, il y a une erreur quelque part !";
0337d704 47 }
48
4b0cf4e4
SJ
49 $subState->set('lastname', $profile->lastName());
50 $subState->set('firstname', $profile->firstName());
51 $subState->set('uid', $profile->owner()->id());
52 $subState->set('watch', $profile->owner()->watch);
53 $subState->set('birthdateRef', $profile->__get('birthdate_ref'));
0337d704 54 return true;
55}
56
57// }}}
94590511 58// {{{ function checkOldId
0337d704 59
94590511 60function checkOldId(&$subState)
0337d704 61{
94590511
SJ
62 $uf = new UserFilter(new PFC_And(
63 new PFC_Not(new UFC_Dead()),
64 new UFC_Promo('=', UserFilter::DISPLAY, $subState->s('promo')),
65 new PFC_Not(new UFC_Registered(true))
66 ));
67 $it = $uf->iterProfiles();
68 while ($profile = $it->next()) {
69 if ($profile->compareNames($subState->s('firstname'), $subState->s('lastname'))) {
70 $subState->set('lastname', $profile->lastName());
71 $subState->set('firstname', $profile->firstName());
72 $subState->set('uid', $profile->owner()->id());
4b0cf4e4 73 $subState->set('watch', $profile->owner()->watch);
94590511
SJ
74 $subState->set('birthdateRef', $profile->__get('birthdate_ref'));
75 $subState->set('xorgid', $profile->__get('xorg_id'));
0337d704 76 return true;
77 }
78 }
79
94590511
SJ
80 $uf = new UserFilter(new PFC_And(
81 new PFC_Not(new UFC_Dead()),
82 new UFC_Promo('=', UserFilter::DISPLAY, $subState->s('promo')),
83 new UFC_Registered(true)
84 ));
85 $it = $uf->iterProfiles();
86 while ($profile = $it->next()) {
87 if ($profile->compareNames($subState->s('firstname'), $subState->s('lastname'))) {
88 $subState->set('uid', $profile->owner()->id());
4b0cf4e4 89 $subState->set('watch', $profile->owner()->watch);
94590511
SJ
90 $subState->set('birthdateRef', $profile->__get('birthdate_ref'));
91 $subState->set('xorgid', $profile->__get('xorg_id'));
92 return 'Tu es vraisemblablement déjà inscrit !';
0337d704 93 }
94 }
94590511 95 return 'Erreur : vérifie que tu as bien orthographié ton nom !';
0337d704 96}
97
98// }}}
94590511 99// {{{ function checkNewUser
0337d704 100
94590511 101function checkNewUser(&$subState)
0337d704 102{
94590511
SJ
103 $firstname = preg_replace("/[ \t]+/", ' ', $subState->t('firstname'));
104 $firstname = preg_replace("/--+/", '-', $firstname);
105 $firstname = preg_replace("/''+/", '\'', $firstname);
106 $subState->set('firstname', PlUser::fixFirstnameCase($firstname));
107
108 $lastname = preg_replace("/[ \t]+/", ' ', $subState->t('lastname'));
109 $lastname = preg_replace("/--+/", '-', $lastname);
110 $lastname = preg_replace("/''+/", '\'', $lastname);
111 $subState->set('lastname', mb_strtoupper($lastname));
112
113 if ($subState->i('yearpromo') >= 1996) {
114 $res = checkId($subState);
0337d704 115 } else {
94590511
SJ
116 $res = checkOldId($subState);
117 }
118 if ($res !== true) {
119 return $res;
0337d704 120 }
0337d704 121
122 return true;
123}
124
125// }}}
94590511 126// {{{ function createAliases
0337d704 127
94590511 128function createAliases(&$subState)
0337d704 129{
115c90db 130 global $globals;
0337d704 131
94590511
SJ
132 $emailXorg = PlUser::makeUserName($subState->t('firstname'), $subState->t('lastname'));
133 $emailXorg2 = $emailXorg . sprintf(".%02u", ($subState->i('yearpromo') % 100));
0337d704 134
94590511
SJ
135 $res = XDB::query("SELECT hruid
136 FROM accounts
137 WHERE uid = {?} AND hruid != ''", $subState->i('uid'));
56081a9c
VZ
138 if ($res->numRows() == 0) {
139 return "Tu n'as pas d'adresse à vie pré-attribuée.<br />"
4ce2a30a 140 . "Envoie un mail à <a href=\"mailto:support@{$globals->mail->domain}</a>\">"
56081a9c
VZ
141 . "support@{$globals->mail->domain}</a> en expliquant ta situation.";
142 } else {
56081a9c 143 $forlife = $res->fetchOneCell();
0337d704 144 }
eaf30d86 145
94590511
SJ
146 $res = XDB::query('SELECT uid, type, expire
147 FROM aliases
148 WHERE alias = {?}', $emailXorg);
56081a9c 149 if ($res->numRows()) {
0337d704 150 list($h_id, $h_type, $expire) = $res->fetchOneRow();
56081a9c 151 if ($h_type != 'homonyme' and empty($expire)) {
94590511
SJ
152 XDB::execute('UPDATE aliases
153 SET expire = ADDDATE(NOW(), INTERVAL 1 MONTH)
154 WHERE alias = {?}', $emailXorg);
155 XDB::execute('REPLACE INTO homonyms (homonyme_id, uid)
edf5e979 156 VALUES ({?}, {?})', $subState->i('uid'), $h_id);
94590511 157 XDB::execute('REPLACE INTO homonyms (homonyme_id, uid)
edf5e979 158 VALUES ({?}, {?})', $h_id, $subState->i('uid'));
94590511
SJ
159 $res = XDB::query('SELECT alias
160 FROM aliases
161 WHERE uid = {?} AND expire IS NULL', $h_id);
0337d704 162 $als = $res->fetchColumn();
163
94590511
SJ
164 $mailer = new PlMailer('register/lostalias.mail.tpl');
165 $mailer->addTo($emailXorg . '@' . $globals->mail->domain);
166 $mailer->setSubject("Perte de ton alias $emailXorg dans un mois !");
167 $mailer->assign('emailXorg', $emailXorg);
168 $mailer->assign('als', join(', ', $als));
0337d704 169 $mailer->SetTxtBody(wordwrap($msg,72));
170 $mailer->send();
171 }
172
94590511
SJ
173 $subState->set('forlife', $forlife);
174 $subState->set('bestalias', $emailXorg2);
175 $subState->set('emailXorg2', null);
0337d704 176 } else {
94590511
SJ
177 $subState->set('forlife', $forlife);
178 $subState->set('bestalias', $emailXorg);
179 $subState->set('emailXorg2', $emailXorg2);
0337d704 180 }
181
182 return true;
183}
184
185// }}}
94590511 186// {{{ function finishRegistration
0337d704 187
94590511 188function finishRegistration($subState)
0337d704 189{
190 global $globals;
0337d704 191
97a82cd2 192 $hash = rand_url_id(12);
94590511
SJ
193 XDB::execute('REPLACE INTO register_pending (uid, forlife, bestalias, mailorg2, password,
194 email, date, relance, naissance, hash, services)
195 VALUES ({?}, {?}, {?}, {?}, {?}, {?}, NOW(), 0, {?}, {?}, {?})',
196 $subState->i('uid'), $subState->s('forlife'), $subState->s('bestalias'),
197 $subState->s('emailXorg2'), $subState->s('password'), $subState->s('email'),
198 $subState->s('birthdate'), $hash, implode(',', $subState->v('services')));
199
200 $mymail = new PlMailer('register/end.mail.tpl');
201 $mymail->assign('emailXorg', $subState->s('bestalias'));
4b0cf4e4 202 $mymail->assign('to', $subState->s('email'));
0337d704 203 $mymail->assign('baseurl', $globals->baseurl);
94590511 204 $mymail->assign('hash', $hash);
4b0cf4e4 205 $mymail->assign('subject', $subState->s('bestalias') . '@' . $globals->mail->domain);
0337d704 206 $mymail->send();
207}
208
209// }}}
a7de4ef7 210// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
0337d704 211?>