1f6dbf946f526dc456fb3b69976c9f3689b3cdcb
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 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 'edit' => $this->make_hook('edit', AUTH_MDP
, 'user'),
38 'Xnet' => $this->make_wiki_hook(),
42 function handler_photo(&$page, $x = null
)
44 if (!$x ||
!($profile = Profile
::get($x))) {
48 // Retrieve the photo and its mime type.
49 $photo = $profile->getPhoto(true
, true
);
51 // Display the photo, or a default one when not available.
55 function handler_index(&$page)
58 $page->changeTpl('xnet/index.tpl');
61 function handler_exit(&$page)
63 Platal
::session()->stopSUID();
64 Platal
::session()->destroy();
65 $page->changeTpl('xnet/deconnexion.tpl');
68 function handler_admin(&$page)
70 $page->changeTpl('xnet/admin.tpl');
72 if (Get
::has('del')) {
73 $res = XDB
::query('SELECT id, nom, mail_domain
74 FROM groups WHERE diminutif={?}',
76 list($id, $nom, $domain) = $res->fetchOneRow();
77 $page->assign('nom', $nom);
78 if ($id && Post
::has('del')) {
79 S
::assert_xsrf_token();
81 XDB
::query('DELETE FROM group_members WHERE asso_id={?}', $id);
82 $page->trigSuccess('membres supprimés');
85 XDB
::query('DELETE FROM virtual_domains WHERE domain={?}', $domain);
86 XDB
::query('DELETE FROM virtual, virtual_redirect
87 USING virtual INNER JOIN virtual_redirect USING (vid)
88 WHERE alias LIKE {?}', '%@'.$domain);
89 $page->trigSuccess('suppression des alias mails');
91 $mmlist = new MMList(S
::v('uid'), S
::v('password'), $domain);
92 if ($listes = $mmlist->get_lists()) {
93 foreach ($listes as $l) {
94 $mmlist->delete_list($l['list'], true
);
96 $page->trigSuccess('mail lists surpprimées');
100 XDB
::query('DELETE FROM groups WHERE id={?}', $id);
101 $page->trigSuccess("Groupe $nom supprimé");
109 if (Post
::has('diminutif') && Post
::v('diminutif') != "") {
110 S
::assert_xsrf_token();
112 $res = XDB
::query('SELECT COUNT(*)
114 WHERE diminutif = {?}',
115 Post
::v('diminutif'));
117 if ($res->fetchOneCell() == 0) {
118 XDB
::execute('INSERT INTO groups (id, diminutif)
120 Post
::v('diminutif'));
121 pl_redirect(Post
::v('diminutif') . '/edit');
123 $page->trigError('Le diminutif demandé est déjà pris.');
127 $res = XDB
::query('SELECT nom, diminutif
130 $page->assign('assos', $res->fetchAllAssoc());
133 function handler_plan(&$page)
135 $page->changeTpl('xnet/plan.tpl');
137 $page->setType('plan');
139 $res = XDB
::iterator(
140 'SELECT dom.id, dom.nom as domnom, groups.diminutif, groups.nom
141 FROM group_dom AS dom
142 INNER JOIN groups ON dom.id = groups.dom
143 WHERE FIND_IN_SET("GroupesX", dom.cat) AND FIND_IN_SET("GroupesX", groups.cat)
144 ORDER BY dom.nom, groups.nom');
146 while ($tmp = $res->next()) { $groupesx[$tmp['id']][] = $tmp; }
147 $page->assign('groupesx', $groupesx);
149 $res = XDB
::iterator(
150 'SELECT dom.id, dom.nom as domnom, groups.diminutif, groups.nom
151 FROM group_dom AS dom
152 INNER JOIN groups ON dom.id = groups.dom
153 WHERE FIND_IN_SET("Binets", dom.cat) AND FIND_IN_SET("Binets", groups.cat)
154 ORDER BY dom.nom, groups.nom');
156 while ($tmp = $res->next()) { $binets[$tmp['id']][] = $tmp; }
157 $page->assign('binets', $binets);
159 $res = XDB
::iterator(
160 'SELECT diminutif, nom
162 WHERE cat LIKE "%Promotions%"
163 ORDER BY diminutif');
164 $page->assign('promos', $res);
166 $res = XDB
::iterator(
167 'SELECT diminutif, nom
169 WHERE FIND_IN_SET("Institutions", cat)
170 ORDER BY diminutif');
171 $page->assign('inst', $res);
174 function handler_groups2(&$page)
176 $this->handler_groups(&$page, Get
::v('cat'), Get
::v('dom'));
179 function handler_groups(&$page, $cat = null
, $dom = null
)
182 $this->handler_index(&$page);
185 $cat = mb_strtolower($cat);
187 $page->changeTpl('xnet/groupes.tpl');
188 $page->assign('cat', $cat);
189 $page->assign('dom', $dom);
191 $res = XDB
::query("SELECT id,nom
193 WHERE FIND_IN_SET({?}, cat)
194 ORDER BY nom", $cat);
195 $doms = $res->fetchAllAssoc();
196 $page->assign('doms', $doms);
199 $res = XDB
::query("SELECT diminutif, nom, site
201 WHERE FIND_IN_SET({?}, cat)
202 ORDER BY nom", $cat);
203 $page->assign('gps', $res->fetchAllAssoc());
204 } elseif (!is_null($dom)) {
205 $res = XDB
::query("SELECT diminutif, nom, site
207 WHERE FIND_IN_SET({?}, cat) AND dom={?}
208 ORDER BY nom", $cat, $dom);
209 $page->assign('gps', $res->fetchAllAssoc());
212 $page->setType($cat);
215 function handler_autologin(&$page)
217 $allkeys = func_get_args();
219 $url = join('/',$allkeys);
220 pl_content_headers("text/javascript");
221 echo '$.ajax({ url: "'.$url.'?forceXml=1", dataType: "xml", success: function(xml) { $("body",xml).insertBefore("body"); $("body:eq(1)").remove(); }});';
225 function handler_edit(&$page)
233 if ($user->type
!= 'xnet') {
234 pl_redirect('index');
237 $page->changeTpl('xnet/edit.tpl');
238 if (Post
::has('change')) {
239 S
::assert_xsrf_token();
241 if ($user->groupCount() == 0 && Post
::t('delete') == 'OUI') {
242 XDB
::execute('DELETE FROM accounts
245 pl_redirect('index');
248 // Convert user status to X
249 if (!Post
::blank('login_X')) {
250 $forlife = $this->changeLogin($page, $user, Post
::t('login_X'));
252 pl_redirect('index');
257 XDB
::query('UPDATE accounts
258 SET full_name = {?}, directory_name = {?}, display_name = {?},
259 sex = {?}, email = {?}
261 Post
::t('full_name'), Post
::t('directory_name'), Post
::t('display_name'),
262 (Post
::t('sex') == 'male') ?
'male' : 'female', Post
::t('email'), $user->id());
263 // If user is of type xnet and new password is given.
264 if (!Post
::blank('pwhash')) {
265 XDB
::query('UPDATE accounts
268 Post
::t('pwhash'), $user->id());
270 if (XDB
::affectedRows()) {
271 $page->trigSuccess('Données mises à jour.');
275 $page->addJsLink('password.js');
276 $page->assign('user', $user);
280 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: