2 /***************************************************************************
3 * Copyright (C) 2003-2011 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 XnetModule
extends PLModule
27 'index' => $this->make_hook('index', AUTH_PUBLIC
),
28 'exit' => $this->make_hook('exit', AUTH_PUBLIC
),
30 'admin' => $this->make_hook('admin', AUTH_MDP
, 'admin'),
31 'groups' => $this->make_hook('groups', AUTH_PUBLIC
),
32 'groupes.php' => $this->make_hook('groups2', AUTH_PUBLIC
),
33 'plan' => $this->make_hook('plan', AUTH_PUBLIC
),
34 'photo' => $this->make_hook('photo', AUTH_MDP
),
35 'autologin' => $this->make_hook('autologin', AUTH_MDP
),
36 'login/ext' => $this->make_hook('login_ext', AUTH_PUBLIC
),
37 'register/ext' => $this->make_hook('register_ext', AUTH_PUBLIC
),
38 'edit' => $this->make_hook('edit', AUTH_MDP
, 'user'),
40 'Xnet' => $this->make_wiki_hook(),
44 function handler_photo($page, $x = null
)
46 if (!$x ||
!($profile = Profile
::get($x))) {
50 // Retrieve the photo and its mime type.
51 $photo = $profile->getPhoto(true
, true
);
53 // Display the photo, or a default one when not available.
57 function handler_index($page)
60 $page->changeTpl('xnet/index.tpl');
63 function handler_exit($page)
65 Platal
::session()->stopSUID();
66 Platal
::session()->destroy();
67 $page->changeTpl('xnet/deconnexion.tpl');
70 function handler_admin($page)
72 $page->changeTpl('xnet/admin.tpl');
74 if (Get
::has('del')) {
75 $res = XDB
::query('SELECT id, nom, mail_domain
76 FROM groups WHERE diminutif={?}',
78 list($id, $nom, $domain) = $res->fetchOneRow();
79 $page->assign('nom', $nom);
80 if ($id && Post
::has('del')) {
81 S
::assert_xsrf_token();
83 XDB
::query('DELETE FROM group_members WHERE asso_id={?}', $id);
84 $page->trigSuccess('membres supprimés');
87 XDB
::execute('DELETE v
88 FROM email_virtual AS v
89 INNER JOIN email_virtual_domains AS d ON (v.domain = d.id)
92 XDB
::execute('DELETE FROM email_virtual_domains
93 WHERE name = {?}', $domain);
94 $page->trigSuccess('suppression des alias mails');
96 $mmlist = new MMList(S
::v('uid'), S
::v('password'), $domain);
97 if ($listes = $mmlist->get_lists()) {
98 foreach ($listes as $l) {
99 $mmlist->delete_list($l['list'], true
);
101 $page->trigSuccess('mail lists surpprimées');
105 XDB
::query('DELETE FROM groups WHERE id={?}', $id);
106 $page->trigSuccess("Groupe $nom supprimé");
114 if (Post
::has('diminutif') && Post
::v('diminutif') != "") {
115 S
::assert_xsrf_token();
117 $res = XDB
::query('SELECT COUNT(*)
119 WHERE diminutif = {?}',
120 Post
::v('diminutif'));
122 if ($res->fetchOneCell() == 0) {
123 XDB
::execute('INSERT INTO groups (id, diminutif)
125 Post
::v('diminutif'));
126 pl_redirect(Post
::v('diminutif') . '/edit');
128 $page->trigError('Le diminutif demandé est déjà pris.');
132 $res = XDB
::query('SELECT nom, diminutif
135 $page->assign('assos', $res->fetchAllAssoc());
138 function handler_plan($page)
140 $page->changeTpl('xnet/plan.tpl');
142 $page->setType('plan');
144 $res = XDB
::iterator(
145 'SELECT dom.id, dom.nom as domnom, groups.diminutif, groups.nom
146 FROM group_dom AS dom
147 INNER JOIN groups ON dom.id = groups.dom
148 WHERE FIND_IN_SET("GroupesX", dom.cat) AND FIND_IN_SET("GroupesX", groups.cat)
149 ORDER BY dom.nom, groups.nom');
151 while ($tmp = $res->next()) { $groupesx[$tmp['id']][] = $tmp; }
152 $page->assign('groupesx', $groupesx);
154 $res = XDB
::iterator(
155 'SELECT dom.id, dom.nom as domnom, groups.diminutif, groups.nom
156 FROM group_dom AS dom
157 INNER JOIN groups ON dom.id = groups.dom
158 WHERE FIND_IN_SET("Binets", dom.cat) AND FIND_IN_SET("Binets", groups.cat)
159 ORDER BY dom.nom, groups.nom');
161 while ($tmp = $res->next()) { $binets[$tmp['id']][] = $tmp; }
162 $page->assign('binets', $binets);
164 $res = XDB
::iterator(
165 'SELECT diminutif, nom
167 WHERE cat LIKE "%Promotions%"
168 ORDER BY diminutif');
169 $page->assign('promos', $res);
171 $res = XDB
::iterator(
172 'SELECT diminutif, nom
174 WHERE FIND_IN_SET("Institutions", cat)
175 ORDER BY diminutif');
176 $page->assign('inst', $res);
179 function handler_groups2($page)
181 $this->handler_groups($page, Get
::v('cat'), Get
::v('dom'));
184 function handler_groups($page, $cat = null
, $dom = null
)
187 $this->handler_index($page);
190 $cat = mb_strtolower($cat);
192 $page->changeTpl('xnet/groupes.tpl');
193 $page->assign('cat', $cat);
194 $page->assign('dom', $dom);
196 $res = XDB
::query("SELECT id,nom
198 WHERE FIND_IN_SET({?}, cat)
199 ORDER BY nom", $cat);
200 $doms = $res->fetchAllAssoc();
201 $page->assign('doms', $doms);
204 $res = XDB
::query("SELECT diminutif, nom, site
206 WHERE FIND_IN_SET({?}, cat)
207 ORDER BY nom", $cat);
208 $page->assign('gps', $res->fetchAllAssoc());
209 } elseif (!is_null($dom)) {
210 $res = XDB
::query("SELECT diminutif, nom, site
212 WHERE FIND_IN_SET({?}, cat) AND dom={?}
213 ORDER BY nom", $cat, $dom);
214 $page->assign('gps', $res->fetchAllAssoc());
217 $page->setType($cat);
220 function handler_autologin($page)
222 $allkeys = func_get_args();
224 $url = join('/',$allkeys);
225 pl_content_headers("text/javascript");
226 echo '$.ajax({ url: "'.$url.'?forceXml=1", dataType: "xml", success: function(xml) { $("body",xml).insertBefore("body"); $("body:eq(1)").remove(); }});';
230 function handler_login_ext($page)
233 $page->changeTpl('xnet/login.tpl');
239 function handler_register_ext($page, $hash = null
)
241 XDB
::execute('DELETE FROM register_pending_xnet
242 WHERE DATE_SUB(NOW(), INTERVAL 1 MONTH) > date');
243 $res = XDB
::fetchOneAssoc('SELECT uid, hruid
244 FROM register_pending_xnet
248 if (is_null($hash) ||
is_null($res)) {
249 $page->trigErrorRedirect('Cette adresse n\'existe pas ou n\'existe plus sur le serveur.', '');
252 if (Post
::has('pwhash') && Post
::t('pwhash')) {
253 XDB
::query('UPDATE accounts
254 SET password = {?}, state = \'active\'
255 WHERE uid = {?} AND state = \'pending\' AND type = \'xnet\'',
256 Post
::t('pwhash'), $res['uid']);
257 XDB
::query('DELETE FROM register_pending_xnet
261 S
::logger($res['uid'])->log('passwd', '');
263 // Try to start a session (so the user don't have to log in); we will use
264 // the password available in Post:: to authenticate the user.
266 Platal
::session()->startAvailableAuth();
268 $page->changeTpl('xnet/register.success.tpl');
269 $page->assign('hruid', $res['hruid']);
271 $page->changeTpl('platal/password.tpl');
272 $page->assign('xnet', true
);
273 $page->assign('hruid', $res['hruid']);
277 function handler_edit(&$page)
285 if ($user->type
!= 'xnet') {
286 pl_redirect('index');
289 $page->changeTpl('xnet/edit.tpl');
290 if (Post
::has('change')) {
291 S
::assert_xsrf_token();
293 if ($user->groupCount() == 0 && Post
::t('delete') == 'OUI') {
294 XDB
::execute('DELETE FROM accounts
297 pl_redirect('index');
300 // Convert user status to X
301 if (!Post
::blank('login_X')) {
302 $forlife = $this->changeLogin($page, $user, Post
::t('login_X'));
304 pl_redirect('index');
309 XDB
::query('UPDATE accounts
310 SET full_name = {?}, directory_name = {?}, display_name = {?},
311 sex = {?}, email = {?}
313 Post
::t('full_name'), Post
::t('directory_name'), Post
::t('display_name'),
314 (Post
::t('sex') == 'male') ?
'male' : 'female', Post
::t('email'), $user->id());
315 // If user is of type xnet and new password is given.
316 if (!Post
::blank('pwhash')) {
317 XDB
::query('UPDATE accounts
320 Post
::t('pwhash'), $user->id());
322 if (XDB
::affectedRows()) {
323 $page->trigSuccess('Données mises à jour.');
327 $page->addJsLink('password.js');
328 $page->assign('user', $user);
332 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: