6e54d385bda040e2657b94fdce9236c6be4f5d69
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'),
39 'password' => $this->make_hook('password', AUTH_MDP
, 'user'),
41 'Xnet' => $this->make_wiki_hook(),
45 function handler_photo($page, $x = null
)
47 if (!$x ||
!($profile = Profile
::get($x))) {
51 // Retrieve the photo and its mime type.
52 $photo = $profile->getPhoto(true
, true
);
54 // Display the photo, or a default one when not available.
58 function handler_index($page)
61 $page->changeTpl('xnet/index.tpl');
64 function handler_exit($page)
66 Platal
::session()->stopSUID();
67 Platal
::session()->destroy();
68 $page->changeTpl('xnet/deconnexion.tpl');
71 function handler_admin($page)
73 $page->changeTpl('xnet/admin.tpl');
75 if (Get
::has('del')) {
76 $res = XDB
::query('SELECT id, nom, mail_domain
77 FROM groups WHERE diminutif={?}',
79 list($id, $nom, $domain) = $res->fetchOneRow();
80 $page->assign('nom', $nom);
81 if ($id && Post
::has('del')) {
82 S
::assert_xsrf_token();
84 XDB
::query('DELETE FROM group_members WHERE asso_id={?}', $id);
85 $page->trigSuccess('membres supprimés');
88 XDB
::execute('DELETE v
89 FROM email_virtual AS v
90 INNER JOIN email_virtual_domains AS d ON (v.domain = d.id)
93 XDB
::execute('DELETE FROM email_virtual_domains
94 WHERE name = {?}', $domain);
95 $page->trigSuccess('suppression des alias mails');
97 $mmlist = new MMList(S
::v('uid'), S
::v('password'), $domain);
98 if ($listes = $mmlist->get_lists()) {
99 foreach ($listes as $l) {
100 $mmlist->delete_list($l['list'], true
);
102 $page->trigSuccess('mail lists surpprimées');
106 XDB
::query('DELETE FROM groups WHERE id={?}', $id);
107 $page->trigSuccess("Groupe $nom supprimé");
115 if (Post
::has('diminutif') && Post
::v('diminutif') != "") {
116 S
::assert_xsrf_token();
118 $res = XDB
::query('SELECT COUNT(*)
120 WHERE diminutif = {?}',
121 Post
::v('diminutif'));
123 if ($res->fetchOneCell() == 0) {
124 XDB
::execute('INSERT INTO groups (id, diminutif)
126 Post
::v('diminutif'));
127 pl_redirect(Post
::v('diminutif') . '/edit');
129 $page->trigError('Le diminutif demandé est déjà pris.');
133 $res = XDB
::query('SELECT nom, diminutif
136 $page->assign('assos', $res->fetchAllAssoc());
139 function handler_plan($page)
141 $page->changeTpl('xnet/plan.tpl');
143 $page->setType('plan');
145 $res = XDB
::iterator(
146 'SELECT dom.id, dom.nom as domnom, groups.diminutif, groups.nom
147 FROM group_dom AS dom
148 INNER JOIN groups ON dom.id = groups.dom
149 WHERE FIND_IN_SET("GroupesX", dom.cat) AND FIND_IN_SET("GroupesX", groups.cat)
150 ORDER BY dom.nom, groups.nom');
152 while ($tmp = $res->next()) { $groupesx[$tmp['id']][] = $tmp; }
153 $page->assign('groupesx', $groupesx);
155 $res = XDB
::iterator(
156 'SELECT dom.id, dom.nom as domnom, groups.diminutif, groups.nom
157 FROM group_dom AS dom
158 INNER JOIN groups ON dom.id = groups.dom
159 WHERE FIND_IN_SET("Binets", dom.cat) AND FIND_IN_SET("Binets", groups.cat)
160 ORDER BY dom.nom, groups.nom');
162 while ($tmp = $res->next()) { $binets[$tmp['id']][] = $tmp; }
163 $page->assign('binets', $binets);
165 $res = XDB
::iterator(
166 'SELECT diminutif, nom
168 WHERE cat LIKE "%Promotions%"
169 ORDER BY diminutif');
170 $page->assign('promos', $res);
172 $res = XDB
::iterator(
173 'SELECT diminutif, nom
175 WHERE FIND_IN_SET("Institutions", cat)
176 ORDER BY diminutif');
177 $page->assign('inst', $res);
180 function handler_groups2($page)
182 $this->handler_groups($page, Get
::v('cat'), Get
::v('dom'));
185 function handler_groups($page, $cat = null
, $dom = null
)
188 $this->handler_index($page);
191 $cat = mb_strtolower($cat);
193 $page->changeTpl('xnet/groupes.tpl');
194 $page->assign('cat', $cat);
195 $page->assign('dom', $dom);
197 $res = XDB
::query("SELECT id,nom
199 WHERE FIND_IN_SET({?}, cat)
200 ORDER BY nom", $cat);
201 $doms = $res->fetchAllAssoc();
202 $page->assign('doms', $doms);
205 $res = XDB
::query("SELECT diminutif, nom, site
207 WHERE FIND_IN_SET({?}, cat)
208 ORDER BY nom", $cat);
209 $page->assign('gps', $res->fetchAllAssoc());
210 } elseif (!is_null($dom)) {
211 $res = XDB
::query("SELECT diminutif, nom, site
213 WHERE FIND_IN_SET({?}, cat) AND dom={?}
214 ORDER BY nom", $cat, $dom);
215 $page->assign('gps', $res->fetchAllAssoc());
218 $page->setType($cat);
221 function handler_autologin($page)
223 $allkeys = func_get_args();
225 $url = join('/',$allkeys);
226 pl_content_headers("text/javascript");
227 echo '$.ajax({ url: "'.$url.'?forceXml=1", dataType: "xml", success: function(xml) { $("body",xml).insertBefore("body"); $("body:eq(1)").remove(); }});';
231 function handler_login_ext($page)
234 $page->changeTpl('xnet/login.tpl');
240 function handler_register_ext($page, $hash = null
)
242 XDB
::execute('DELETE FROM register_pending_xnet
243 WHERE DATE_SUB(NOW(), INTERVAL 1 MONTH) > date');
244 $res = XDB
::fetchOneAssoc('SELECT uid, hruid
245 FROM register_pending_xnet
249 if (is_null($hash) ||
is_null($res)) {
250 $page->trigErrorRedirect('Cette adresse n\'existe pas ou n\'existe plus sur le serveur.', '');
253 if (Post
::has('pwhash') && Post
::t('pwhash')) {
254 XDB
::query('UPDATE accounts
255 SET password = {?}, state = \'active\'
256 WHERE uid = {?} AND state = \'pending\' AND type = \'xnet\'',
257 Post
::t('pwhash'), $res['uid']);
258 XDB
::query('DELETE FROM register_pending_xnet
262 S
::logger($res['uid'])->log('passwd', '');
264 // Try to start a session (so the user don't have to log in); we will use
265 // the password available in Post:: to authenticate the user.
267 Platal
::session()->startAvailableAuth();
269 $page->changeTpl('xnet/register.success.tpl');
270 $page->assign('hruid', $res['hruid']);
272 $page->changeTpl('platal/password.tpl');
273 $page->assign('xnet', true
);
274 $page->assign('hruid', $res['hruid']);
275 $page->assign('do_auth', true
);
279 function handler_edit($page)
287 if ($user->type
!= 'xnet') {
288 pl_redirect('index');
291 $page->changeTpl('xnet/edit.tpl');
292 if (Post
::has('change')) {
293 S
::assert_xsrf_token();
295 // Convert user status to X
296 if (!Post
::blank('login_X')) {
297 $forlife = $this->changeLogin($page, $user, Post
::t('login_X'));
299 pl_redirect('index');
304 XDB
::query('UPDATE accounts
305 SET full_name = {?}, directory_name = {?}, display_name = {?},
306 sex = {?}, email = {?}
308 Post
::t('full_name'), Post
::t('directory_name'), Post
::t('display_name'),
309 (Post
::t('sex') == 'male') ?
'male' : 'female', Post
::t('email'), $user->id());
310 if (XDB
::affectedRows()) {
311 $page->trigSuccess('Données mises à jour.');
315 $page->addJsLink('password.js');
316 $page->assign('user', $user);
319 function handler_password ($page)
321 if (Post
::has('pwhash') && Post
::t('pwhash')) {
322 S
::assert_xsrf_token();
324 S
::set('password', $password = Post
::t('pwhash'));
325 XDB
::execute('UPDATE accounts
327 WHERE uid={?}', $password,
329 S
::logger()->log('passwd');
330 Platal
::session()->setAccessCookie(true
);
331 $page->changeTpl('platal/password.success.tpl');
335 $page->changeTpl('platal/password.tpl');
336 $page->assign('xnet_reset', true
);
337 $page->assign('do_auth', false
);
341 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: