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
),
39 function handler_photo(&$page, $x = null
)
41 if (!$x ||
!($profile = Profile
::get($x))) {
45 // Retrieve the photo and its mime type.
46 $photo = $profile->getPhoto(true
);
48 // Display the photo, or a default one when not available.
52 function handler_index(&$page)
55 $page->changeTpl('xnet/index.tpl');
58 function handler_exit(&$page)
60 Platal
::session()->stopSUID();
61 Platal
::session()->destroy();
62 $page->changeTpl('xnet/deconnexion.tpl');
65 function handler_admin(&$page)
67 $page->changeTpl('xnet/admin.tpl');
69 if (Get
::has('del')) {
70 $res = XDB
::query('SELECT id, nom, mail_domain
71 FROM groups WHERE diminutif={?}',
73 list($id, $nom, $domain) = $res->fetchOneRow();
74 $page->assign('nom', $nom);
75 if ($id && Post
::has('del')) {
76 S
::assert_xsrf_token();
78 XDB
::query('DELETE FROM group_members WHERE asso_id={?}', $id);
79 $page->trigSuccess('membres supprimés');
82 XDB
::query('DELETE FROM virtual_domains WHERE domain={?}', $domain);
83 XDB
::query('DELETE FROM virtual, virtual_redirect
84 USING virtual INNER JOIN virtual_redirect USING (vid)
85 WHERE alias LIKE {?}', '%@'.$domain);
86 $page->trigSuccess('suppression des alias mails');
88 $mmlist = new MMList(S
::v('uid'), S
::v('password'), $domain);
89 if ($listes = $mmlist->get_lists()) {
90 foreach ($listes as $l) {
91 $mmlist->delete_list($l['list'], true
);
93 $page->trigSuccess('mail lists surpprimées');
97 XDB
::query('DELETE FROM groups WHERE id={?}', $id);
98 $page->trigSuccess("Groupe $nom supprimé");
106 if (Post
::has('diminutif') && Post
::v('diminutif') != "") {
107 S
::assert_xsrf_token();
109 $res = XDB
::query('SELECT COUNT(*)
111 WHERE diminutif = {?}',
112 Post
::v('diminutif'));
114 if ($res->fetchOneCell() == 0) {
115 XDB
::execute('INSERT INTO groups (id, diminutif)
117 Post
::v('diminutif'));
118 pl_redirect('../' . Post
::v('diminutif') . '/edit');
120 $page->trigError('Le diminutif demandé est déjà pris.');
124 $res = XDB
::query('SELECT nom, diminutif
127 $page->assign('assos', $res->fetchAllAssoc());
130 function handler_plan(&$page)
132 $page->changeTpl('xnet/plan.tpl');
134 $page->setType('plan');
136 $res = XDB
::iterator(
137 'SELECT dom.id, dom.nom as domnom, groups.diminutif, groups.nom
138 FROM group_dom AS dom
139 INNER JOIN groups ON dom.id = groups.dom
140 WHERE FIND_IN_SET("GroupesX", dom.cat) AND FIND_IN_SET("GroupesX", groups.cat)
141 ORDER BY dom.nom, groups.nom');
143 while ($tmp = $res->next()) { $groupesx[$tmp['id']][] = $tmp; }
144 $page->assign('groupesx', $groupesx);
146 $res = XDB
::iterator(
147 'SELECT dom.id, dom.nom as domnom, groups.diminutif, groups.nom
148 FROM group_dom AS dom
149 INNER JOIN groups ON dom.id = groups.dom
150 WHERE FIND_IN_SET("Binets", dom.cat) AND FIND_IN_SET("Binets", groups.cat)
151 ORDER BY dom.nom, groups.nom');
153 while ($tmp = $res->next()) { $binets[$tmp['id']][] = $tmp; }
154 $page->assign('binets', $binets);
156 $res = XDB
::iterator(
157 'SELECT diminutif, nom
159 WHERE cat LIKE "%Promotions%"
160 ORDER BY diminutif');
161 $page->assign('promos', $res);
163 $res = XDB
::iterator(
164 'SELECT diminutif, nom
166 WHERE FIND_IN_SET("Institutions", cat)
167 ORDER BY diminutif');
168 $page->assign('inst', $res);
171 function handler_groups2(&$page)
173 $this->handler_groups(&$page, Get
::v('cat'), Get
::v('dom'));
176 function handler_groups(&$page, $cat = null
, $dom = null
)
179 $this->handler_index(&$page);
182 $cat = mb_strtolower($cat);
184 $page->changeTpl('xnet/groupes.tpl');
185 $page->assign('cat', $cat);
186 $page->assign('dom', $dom);
188 $res = XDB
::query("SELECT id,nom
190 WHERE FIND_IN_SET({?}, cat)
191 ORDER BY nom", $cat);
192 $doms = $res->fetchAllAssoc();
193 $page->assign('doms', $doms);
196 $res = XDB
::query("SELECT diminutif, nom, site
198 WHERE FIND_IN_SET({?}, cat)
199 ORDER BY nom", $cat);
200 $page->assign('gps', $res->fetchAllAssoc());
201 } elseif (!is_null($dom)) {
202 $res = XDB
::query("SELECT diminutif, nom, site
204 WHERE FIND_IN_SET({?}, cat) AND dom={?}
205 ORDER BY nom", $cat, $dom);
206 $page->assign('gps', $res->fetchAllAssoc());
209 $page->setType($cat);
212 function handler_autologin(&$page)
214 $allkeys = func_get_args();
216 $url = join('/',$allkeys);
217 pl_content_headers("text/javascript");
218 echo '$.ajax({ url: "'.$url.'?forceXml=1", dataType: "xml", success: function(xml) { $("body",xml).insertBefore("body"); $("body:eq(1)").remove(); }});';
223 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: