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
),
37 'Xnet' => $this->make_wiki_hook(),
41 function handler_photo($page, $x = null
)
43 if (!$x ||
!($profile = Profile
::get($x))) {
47 // Retrieve the photo and its mime type.
48 $photo = $profile->getPhoto(true
, true
);
50 // Display the photo, or a default one when not available.
54 function handler_index($page)
57 $page->changeTpl('xnet/index.tpl');
60 function handler_exit($page)
62 Platal
::session()->stopSUID();
63 Platal
::session()->destroy();
64 $page->changeTpl('xnet/deconnexion.tpl');
67 function handler_admin($page)
69 $page->changeTpl('xnet/admin.tpl');
71 if (Get
::has('del')) {
72 $res = XDB
::query('SELECT id, nom, mail_domain
73 FROM groups WHERE diminutif={?}',
75 list($id, $nom, $domain) = $res->fetchOneRow();
76 $page->assign('nom', $nom);
77 if ($id && Post
::has('del')) {
78 S
::assert_xsrf_token();
80 XDB
::query('DELETE FROM group_members WHERE asso_id={?}', $id);
81 $page->trigSuccess('membres supprimés');
84 XDB
::execute('DELETE v
85 FROM email_virtual AS v
86 INNER JOIN email_virtual_domains AS d ON (v.domain = d.id)
89 XDB
::execute('DELETE FROM email_virtual_domains
90 WHERE name = {?}', $domain);
91 $page->trigSuccess('suppression des alias mails');
93 $mmlist = new MMList(S
::v('uid'), S
::v('password'), $domain);
94 if ($listes = $mmlist->get_lists()) {
95 foreach ($listes as $l) {
96 $mmlist->delete_list($l['list'], true
);
98 $page->trigSuccess('mail lists surpprimées');
102 XDB
::query('DELETE FROM groups WHERE id={?}', $id);
103 $page->trigSuccess("Groupe $nom supprimé");
111 if (Post
::has('diminutif') && Post
::v('diminutif') != "") {
112 S
::assert_xsrf_token();
114 $res = XDB
::query('SELECT COUNT(*)
116 WHERE diminutif = {?}',
117 Post
::v('diminutif'));
119 if ($res->fetchOneCell() == 0) {
120 XDB
::execute('INSERT INTO groups (id, diminutif)
122 Post
::v('diminutif'));
123 pl_redirect(Post
::v('diminutif') . '/edit');
125 $page->trigError('Le diminutif demandé est déjà pris.');
129 $res = XDB
::query('SELECT nom, diminutif
132 $page->assign('assos', $res->fetchAllAssoc());
135 function handler_plan($page)
137 $page->changeTpl('xnet/plan.tpl');
139 $page->setType('plan');
141 $res = XDB
::iterator(
142 'SELECT dom.id, dom.nom as domnom, groups.diminutif, groups.nom
143 FROM group_dom AS dom
144 INNER JOIN groups ON dom.id = groups.dom
145 WHERE FIND_IN_SET("GroupesX", dom.cat) AND FIND_IN_SET("GroupesX", groups.cat)
146 ORDER BY dom.nom, groups.nom');
148 while ($tmp = $res->next()) { $groupesx[$tmp['id']][] = $tmp; }
149 $page->assign('groupesx', $groupesx);
151 $res = XDB
::iterator(
152 'SELECT dom.id, dom.nom as domnom, groups.diminutif, groups.nom
153 FROM group_dom AS dom
154 INNER JOIN groups ON dom.id = groups.dom
155 WHERE FIND_IN_SET("Binets", dom.cat) AND FIND_IN_SET("Binets", groups.cat)
156 ORDER BY dom.nom, groups.nom');
158 while ($tmp = $res->next()) { $binets[$tmp['id']][] = $tmp; }
159 $page->assign('binets', $binets);
161 $res = XDB
::iterator(
162 'SELECT diminutif, nom
164 WHERE cat LIKE "%Promotions%"
165 ORDER BY diminutif');
166 $page->assign('promos', $res);
168 $res = XDB
::iterator(
169 'SELECT diminutif, nom
171 WHERE FIND_IN_SET("Institutions", cat)
172 ORDER BY diminutif');
173 $page->assign('inst', $res);
176 function handler_groups2($page)
178 $this->handler_groups($page, Get
::v('cat'), Get
::v('dom'));
181 function handler_groups($page, $cat = null
, $dom = null
)
184 $this->handler_index($page);
187 $cat = mb_strtolower($cat);
189 $page->changeTpl('xnet/groupes.tpl');
190 $page->assign('cat', $cat);
191 $page->assign('dom', $dom);
193 $res = XDB
::query("SELECT id,nom
195 WHERE FIND_IN_SET({?}, cat)
196 ORDER BY nom", $cat);
197 $doms = $res->fetchAllAssoc();
198 $page->assign('doms', $doms);
201 $res = XDB
::query("SELECT diminutif, nom, site
203 WHERE FIND_IN_SET({?}, cat)
204 ORDER BY nom", $cat);
205 $page->assign('gps', $res->fetchAllAssoc());
206 } elseif (!is_null($dom)) {
207 $res = XDB
::query("SELECT diminutif, nom, site
209 WHERE FIND_IN_SET({?}, cat) AND dom={?}
210 ORDER BY nom", $cat, $dom);
211 $page->assign('gps', $res->fetchAllAssoc());
214 $page->setType($cat);
217 function handler_autologin($page)
219 $allkeys = func_get_args();
221 $url = join('/',$allkeys);
222 pl_content_headers("text/javascript");
223 echo '$.ajax({ url: "'.$url.'?forceXml=1", dataType: "xml", success: function(xml) { $("body",xml).insertBefore("body"); $("body:eq(1)").remove(); }});';
228 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: