2a03c39b6f2a40cdf9252c72aff3fb8c9b948a7a
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
)
45 $res = XDB
::query("SELECT pp.attachmime, pp.attach
47 INNER JOIN account_profiles AS ap ON (ap.uid = a.uid AND FIND_IN_SET('owner', ap.flags))
48 INNER JOIN profile_photos AS pp ON (ap.pid = pp.pid)
49 WHERE a.alias = {?}", $x);
51 if ((list($type, $data) = $res->fetchOneRow())) {
52 pl_cached_dynamic_content_headers("image/$type");
55 pl_cached_dynamic_content_headers("image/png");
56 echo file_get_contents(dirname(__FILE__
).'/../htdocs/images/none.png');
61 function handler_index(&$page)
64 $page->changeTpl('xnet/index.tpl');
67 function handler_exit(&$page)
69 Platal
::session()->stopSUID();
70 Platal
::session()->destroy();
71 $page->changeTpl('xnet/deconnexion.tpl');
74 function handler_admin(&$page)
76 $page->changeTpl('xnet/admin.tpl');
78 if (Get
::has('del')) {
79 $res = XDB
::query('SELECT id, nom, mail_domain
80 FROM groups WHERE diminutif={?}',
82 list($id, $nom, $domain) = $res->fetchOneRow();
83 $page->assign('nom', $nom);
84 if ($id && Post
::has('del')) {
85 S
::assert_xsrf_token();
87 XDB
::query('DELETE FROM group_members WHERE asso_id={?}', $id);
88 $page->trigSuccess('membres supprimés');
91 XDB
::query('DELETE FROM virtual_domains WHERE domain={?}', $domain);
92 XDB
::query('DELETE FROM virtual, virtual_redirect
93 USING virtual INNER JOIN virtual_redirect USING (vid)
94 WHERE alias LIKE {?}', '%@'.$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(); }});';
232 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: