a1bba73c4324ff23e6c576925a9d272db4366c5e
2 /***************************************************************************
3 * Copyright (C) 2003-2014 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 'login' => $this->make_hook('login', AUTH_COOKIE
, 'groups'),
31 'admin' => $this->make_hook('admin', AUTH_PASSWD
, 'admin'),
32 'groups' => $this->make_hook('groups', AUTH_PUBLIC
),
33 'groupes.php' => $this->make_hook('groups2', AUTH_PUBLIC
),
34 'plan' => $this->make_hook('plan', AUTH_PUBLIC
),
35 // Should be removed in a future release as links will have expired anyway.
36 'register/ext' => $this->make_hook('register_ext', AUTH_PUBLIC
),
37 'photo' => $this->make_hook('photo', AUTH_PASSWD
, 'groups'),
38 'autologin' => $this->make_hook('autologin', AUTH_PASSWD
, 'groups'),
39 'edit' => $this->make_hook('edit', AUTH_PASSWD
, 'groups'),
40 'Xnet' => $this->make_wiki_hook(),
44 function handler_login()
46 // We require different credentials for '/login/' ("groups" instead of "user").
47 // We have to redirect the call to the actual CoreModule->handler_login.
48 $args = func_get_args();
49 return call_user_func_array(array("CoreModule", "handler_login"), $args);
52 function handler_photo($page, $x = null
)
54 if (!$x ||
!($profile = Profile
::get($x))) {
58 // Retrieve the photo and its mime type.
59 $photo = $profile->getPhoto(true
, true
);
61 // Display the photo, or a default one when not available.
65 function handler_index($page)
68 $page->changeTpl('xnet/index.tpl');
71 function handler_exit($page)
73 Platal
::session()->stopSUID();
74 Platal
::session()->destroy();
75 $page->changeTpl('xnet/deconnexion.tpl');
78 function handler_admin($page)
80 $page->changeTpl('xnet/admin.tpl');
82 if (Get
::has('del')) {
83 $res = XDB
::query('SELECT id, nom, mail_domain
84 FROM groups WHERE diminutif={?}',
86 list($id, $nom, $domain) = $res->fetchOneRow();
87 $page->assign('nom', $nom);
88 if ($id && Post
::has('del')) {
89 S
::assert_xsrf_token();
91 XDB
::query('DELETE FROM group_members WHERE asso_id={?}', $id);
92 $page->trigSuccess('membres supprimés');
95 XDB
::execute('DELETE v
96 FROM email_virtual AS v
97 INNER JOIN email_virtual_domains AS d ON (v.domain = d.id)
100 XDB
::execute('DELETE FROM email_virtual_domains
101 WHERE name = {?}', $domain);
102 $page->trigSuccess('suppression des alias mails');
104 $mmlist = new MMList(S
::v('uid'), S
::v('password'), $domain);
105 if ($listes = $mmlist->get_lists()) {
106 foreach ($listes as $l) {
107 $mmlist->delete_list($l['list'], true
);
109 $page->trigSuccess('mail lists surpprimées');
113 XDB
::query('DELETE FROM groups WHERE id={?}', $id);
114 $page->trigSuccess("Groupe $nom supprimé");
122 if (Post
::has('diminutif') && Post
::v('diminutif') != "") {
123 S
::assert_xsrf_token();
125 $res = XDB
::query('SELECT COUNT(*)
127 WHERE diminutif = {?}',
128 Post
::v('diminutif'));
130 if ($res->fetchOneCell() == 0) {
131 XDB
::execute('INSERT INTO groups (id, diminutif)
133 Post
::v('diminutif'));
134 pl_redirect(Post
::v('diminutif') . '/edit');
136 $page->trigError('Le diminutif demandé est déjà pris.');
140 $res = XDB
::query('SELECT nom, diminutif
143 $page->assign('assos', $res->fetchAllAssoc());
146 function handler_plan($page)
148 $page->changeTpl('xnet/plan.tpl');
150 $page->setType('plan');
152 $res = XDB
::iterator(
153 'SELECT dom.id, dom.nom as domnom, groups.diminutif, groups.nom
154 FROM group_dom AS dom
155 INNER JOIN groups ON dom.id = groups.dom
156 WHERE FIND_IN_SET("GroupesX", dom.cat) AND FIND_IN_SET("GroupesX", groups.cat)
157 ORDER BY dom.nom, groups.nom');
159 while ($tmp = $res->next()) { $groupesx[$tmp['id']][] = $tmp; }
160 $page->assign('groupesx', $groupesx);
162 $res = XDB
::iterator(
163 'SELECT dom.id, dom.nom as domnom, groups.diminutif, groups.nom
164 FROM group_dom AS dom
165 INNER JOIN groups ON dom.id = groups.dom
166 WHERE FIND_IN_SET("Binets", dom.cat) AND FIND_IN_SET("Binets", groups.cat)
167 ORDER BY dom.nom, groups.nom');
169 while ($tmp = $res->next()) { $binets[$tmp['id']][] = $tmp; }
170 $page->assign('binets', $binets);
172 $res = XDB
::iterator(
173 'SELECT diminutif, nom
175 WHERE cat LIKE "%Promotions%"
176 ORDER BY diminutif');
177 $page->assign('promos', $res);
179 $res = XDB
::iterator(
180 'SELECT diminutif, nom
182 WHERE FIND_IN_SET("Institutions", cat)
183 ORDER BY diminutif');
184 $page->assign('inst', $res);
187 function handler_groups2($page)
189 $this->handler_groups($page, Get
::v('cat'), Get
::v('dom'));
192 function handler_groups($page, $cat = null
, $dom = null
)
195 $this->handler_index($page);
198 $cat = mb_strtolower($cat);
200 $page->changeTpl('xnet/groupes.tpl');
201 $page->assign('cat', $cat);
202 $page->assign('dom', $dom);
204 $res = XDB
::query("SELECT id,nom
206 WHERE FIND_IN_SET({?}, cat)
207 ORDER BY nom", $cat);
208 $doms = $res->fetchAllAssoc();
209 $page->assign('doms', $doms);
212 $res = XDB
::query("SELECT diminutif, nom, site
214 WHERE FIND_IN_SET({?}, cat)
215 ORDER BY nom", $cat);
216 $page->assign('gps', $res->fetchAllAssoc());
217 } elseif (!is_null($dom)) {
218 $res = XDB
::query("SELECT diminutif, nom, site
220 WHERE FIND_IN_SET({?}, cat) AND dom={?}
221 ORDER BY nom", $cat, $dom);
222 $page->assign('gps', $res->fetchAllAssoc());
225 $page->setType($cat);
228 function handler_autologin($page)
230 $allkeys = func_get_args();
232 $url = join('/',$allkeys);
233 pl_content_headers("text/javascript");
234 echo '$.ajax({ url: "'.$url.'?forceXml=1", dataType: "xml", success: function(xml) { $("body",xml).insertBefore("body"); $("body:eq(1)").remove(); }});';
238 function handler_edit($page)
246 if ($user->type
!= 'xnet') {
247 pl_redirect('index');
250 $page->changeTpl('xnet/edit.tpl');
251 if (Post
::has('change')) {
252 S
::assert_xsrf_token();
254 // Convert user status to X
255 if (!Post
::blank('login_X')) {
256 $forlife = $this->changeLogin($page, $user, Post
::t('login_X'));
258 pl_redirect('index');
262 require_once 'emails.inc.php';
263 require_once 'name.func.inc.php';
266 $lastname = capitalize_name(Post
::t('lastname'));
267 $firstname = capitalize_name(Post
::t('firstname'));
268 $full_name = build_full_name($firstname, $lastname);
269 $directory_name = build_directory_name($firstname, $lastname);
270 $sort_name = build_sort_name($firstname, $lastname);
271 XDB
::query('UPDATE accounts
272 SET full_name = {?}, directory_name = {?}, sort_name = {?}, display_name = {?},
273 firstname = {?}, lastname = {?}, sex = {?}
275 $full_name, $directory_name, $sort_name, Post
::t('display_name'),
276 Post
::t('firstname'), Post
::t('lastname'),
277 (Post
::t('sex') == 'male') ?
'male' : 'female', $user->id());
280 $new_email = strtolower(Post
::t('email'));
281 if (require_email_update($user, $new_email)) {
282 XDB
::query('UPDATE accounts
285 $new_email, $user->id());
286 $listClient = new MMList(S
::user());
287 $listClient->change_user_email($user->forlifeEmail(), $new_email);
288 update_alias_user($user->forlifeEmail(), $new_email);
290 $user = User
::getWithUID($user->id());
291 S
::set('user', $user);
292 $page->trigSuccess('Données mises à jour.');
295 $page->addJsLink('password.js');
296 $page->assign('user', $user);
299 function handler_register_ext($page, $hash = null
)
301 http_redirect(Platal
::globals()->xnet
->xorg_baseurl
. 'register/ext/' . $hash);
305 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker fenc=utf-8: