Commit | Line | Data |
---|---|---|
bd4be95d | 1 | <?php |
2 | /*************************************************************************** | |
8d84c630 | 3 | * Copyright (C) 2003-2009 Polytechnique.org * |
bd4be95d | 4 | * http://opensource.polytechnique.org/ * |
5 | * * | |
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. * | |
10 | * * | |
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. * | |
15 | * * | |
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 * | |
18 | * Foundation, Inc., * | |
19 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * | |
20 | ***************************************************************************/ | |
21 | ||
22 | class XnetModule extends PLModule | |
23 | { | |
24 | function handlers() | |
25 | { | |
26 | return array( | |
020c8ed0 SJ |
27 | 'index' => $this->make_hook('index', AUTH_PUBLIC), |
28 | 'exit' => $this->make_hook('exit', AUTH_PUBLIC), | |
71fe935c | 29 | |
020c8ed0 SJ |
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), | |
bd4be95d | 36 | ); |
37 | } | |
38 | ||
deb09f59 | 39 | function handler_photo(&$page, $x = null) |
40 | { | |
41 | if (is_null($x)) { | |
42 | return PL_NOT_FOUND; | |
43 | } | |
44 | ||
45 | $res = XDB::query("SELECT attachmime, attach | |
46 | FROM aliases | |
47 | INNER JOIN photo ON(id = uid) | |
48 | WHERE alias = {?}", $x); | |
49 | ||
50 | if ((list($type, $data) = $res->fetchOneRow())) { | |
51 | Header("Content-type: image/$type"); | |
52 | echo $data; | |
53 | } else { | |
54 | Header('Content-type: image/png'); | |
55 | echo file_get_contents(dirname(__FILE__).'/../htdocs/images/none.png'); | |
56 | } | |
57 | exit; | |
58 | } | |
eaf30d86 | 59 | |
bd4be95d | 60 | function handler_index(&$page) |
61 | { | |
d83a1b04 | 62 | $page->nomenu = true; |
bd4be95d | 63 | $page->changeTpl('xnet/index.tpl'); |
bd4be95d | 64 | } |
badfc7ee | 65 | |
71fe935c | 66 | function handler_exit(&$page) |
67 | { | |
ab694eb5 FB |
68 | Platal::session()->stopSUID(); |
69 | Platal::session()->destroy(); | |
b8e265bf | 70 | $page->changeTpl('xnet/deconnexion.tpl'); |
71fe935c | 71 | } |
72 | ||
d55888e6 | 73 | function handler_admin(&$page) |
74 | { | |
1490093c | 75 | $page->changeTpl('xnet/admin.tpl'); |
d55888e6 | 76 | |
77 | if (Get::has('del')) { | |
08cce2ff | 78 | $res = XDB::query('SELECT id, nom, mail_domain |
d55888e6 | 79 | FROM groupex.asso WHERE diminutif={?}', |
5e2307dc | 80 | Get::v('del')); |
d55888e6 | 81 | list($id, $nom, $domain) = $res->fetchOneRow(); |
82 | $page->assign('nom', $nom); | |
40d428d8 VZ |
83 | if ($id && Post::has('del')) { |
84 | S::assert_xsrf_token(); | |
85 | ||
08cce2ff | 86 | XDB::query('DELETE FROM groupex.membres WHERE asso_id={?}', $id); |
a7d35093 | 87 | $page->trigSuccess('membres supprimés'); |
d55888e6 | 88 | |
89 | if ($domain) { | |
08cce2ff | 90 | XDB::query('DELETE FROM virtual_domains WHERE domain={?}', $domain); |
91 | XDB::query('DELETE FROM virtual, virtual_redirect | |
d55888e6 | 92 | USING virtual INNER JOIN virtual_redirect USING (vid) |
93 | WHERE alias LIKE {?}', '%@'.$domain); | |
a7d35093 | 94 | $page->trigSuccess('suppression des alias mails'); |
d55888e6 | 95 | |
9bb8bf21 | 96 | $mmlist = new MMList(S::v('uid'), S::v('password'), $domain); |
97 | if ($listes = $mmlist->get_lists()) { | |
d55888e6 | 98 | foreach ($listes as $l) { |
9bb8bf21 | 99 | $mmlist->delete_list($l['list'], true); |
d55888e6 | 100 | } |
a7d35093 | 101 | $page->trigSuccess('mail lists surpprimées'); |
d55888e6 | 102 | } |
103 | } | |
104 | ||
08cce2ff | 105 | XDB::query('DELETE FROM groupex.asso WHERE id={?}', $id); |
a7d35093 | 106 | $page->trigSuccess("Groupe $nom supprimé"); |
d55888e6 | 107 | Get::kill('del'); |
108 | } | |
109 | if (!$id) { | |
110 | Get::kill('del'); | |
111 | } | |
112 | } | |
113 | ||
8d11b755 | 114 | if (Post::has('diminutif') && Post::v('diminutif') != "") { |
40d428d8 VZ |
115 | S::assert_xsrf_token(); |
116 | ||
3af5a31e SJ |
117 | $res = XDB::query('SELECT COUNT(*) |
118 | FROM groupex.asso | |
119 | WHERE diminutif = {?}', | |
120 | Post::v('diminutif')); | |
121 | ||
122 | if ($res->fetchOneCell() == 0) { | |
123 | XDB::execute('INSERT INTO groupex.asso (id, diminutif) | |
124 | VALUES (NULL, {?})', | |
125 | Post::v('diminutif')); | |
126 | pl_redirect('../' . Post::v('diminutif') . '/edit'); | |
127 | } else { | |
128 | $page->trigError('Le diminutif demandé est déjà pris.'); | |
129 | } | |
d55888e6 | 130 | } |
131 | ||
3af5a31e SJ |
132 | $res = XDB::query('SELECT nom, diminutif |
133 | FROM groupex.asso | |
134 | ORDER BY nom'); | |
d55888e6 | 135 | $page->assign('assos', $res->fetchAllAssoc()); |
136 | } | |
137 | ||
71fe935c | 138 | function handler_plan(&$page) |
139 | { | |
71fe935c | 140 | $page->changeTpl('xnet/plan.tpl'); |
141 | ||
142 | $page->setType('plan'); | |
143 | ||
08cce2ff | 144 | $res = XDB::iterator( |
71fe935c | 145 | 'SELECT dom.id, dom.nom as domnom, asso.diminutif, asso.nom |
146 | FROM groupex.dom | |
147 | INNER JOIN groupex.asso ON dom.id = asso.dom | |
148 | WHERE FIND_IN_SET("GroupesX", dom.cat) AND FIND_IN_SET("GroupesX", asso.cat) | |
149 | ORDER BY dom.nom, asso.nom'); | |
150 | $groupesx = array(); | |
151 | while ($tmp = $res->next()) { $groupesx[$tmp['id']][] = $tmp; } | |
152 | $page->assign('groupesx', $groupesx); | |
153 | ||
08cce2ff | 154 | $res = XDB::iterator( |
71fe935c | 155 | 'SELECT dom.id, dom.nom as domnom, asso.diminutif, asso.nom |
156 | FROM groupex.dom | |
157 | INNER JOIN groupex.asso ON dom.id = asso.dom | |
158 | WHERE FIND_IN_SET("Binets", dom.cat) AND FIND_IN_SET("Binets", asso.cat) | |
159 | ORDER BY dom.nom, asso.nom'); | |
160 | $binets = array(); | |
161 | while ($tmp = $res->next()) { $binets[$tmp['id']][] = $tmp; } | |
162 | $page->assign('binets', $binets); | |
163 | ||
08cce2ff | 164 | $res = XDB::iterator( |
71fe935c | 165 | 'SELECT asso.diminutif, asso.nom |
166 | FROM groupex.asso | |
167 | WHERE cat LIKE "%Promotions%" | |
168 | ORDER BY diminutif'); | |
169 | $page->assign('promos', $res); | |
170 | ||
08cce2ff | 171 | $res = XDB::iterator( |
71fe935c | 172 | 'SELECT asso.diminutif, asso.nom |
173 | FROM groupex.asso | |
174 | WHERE FIND_IN_SET("Institutions", cat) | |
175 | ORDER BY diminutif'); | |
176 | $page->assign('inst', $res); | |
045a1522 | 177 | } |
0e02493e | 178 | |
179 | function handler_groups2(&$page) | |
180 | { | |
5e2307dc | 181 | $this->handler_groups(&$page, Get::v('cat'), Get::v('dom')); |
0e02493e | 182 | } |
183 | ||
184 | function handler_groups(&$page, $cat = null, $dom = null) | |
185 | { | |
0e02493e | 186 | if (!$cat) { |
187 | $this->handler_index(&$page); | |
188 | } | |
189 | ||
a953f7e7 | 190 | $cat = mb_strtolower($cat); |
0e02493e | 191 | |
192 | $page->changeTpl('xnet/groupes.tpl'); | |
193 | $page->assign('cat', $cat); | |
194 | $page->assign('dom', $dom); | |
195 | ||
08cce2ff | 196 | $res = XDB::query("SELECT id,nom FROM groupex.dom |
f0430dc7 | 197 | WHERE FIND_IN_SET({?}, cat) |
198 | ORDER BY nom", $cat); | |
0e02493e | 199 | $doms = $res->fetchAllAssoc(); |
200 | $page->assign('doms', $doms); | |
201 | ||
202 | if (empty($doms)) { | |
0d696b52 | 203 | $res = XDB::query("SELECT diminutif, nom, site FROM groupex.asso |
f0430dc7 | 204 | WHERE FIND_IN_SET({?}, cat) |
205 | ORDER BY nom", $cat); | |
206 | $page->assign('gps', $res->fetchAllAssoc()); | |
0e02493e | 207 | } elseif (!is_null($dom)) { |
0d696b52 | 208 | $res = XDB::query("SELECT diminutif, nom, site FROM groupex.asso |
f0430dc7 | 209 | WHERE FIND_IN_SET({?}, cat) AND dom={?} |
210 | ORDER BY nom", $cat, $dom); | |
211 | $page->assign('gps', $res->fetchAllAssoc()); | |
0e02493e | 212 | } |
0e02493e | 213 | |
0e02493e | 214 | $page->setType($cat); |
215 | } | |
eaf30d86 | 216 | |
4a8a1e0a | 217 | function handler_autologin(&$page) |
218 | { | |
8c5c6d64 | 219 | $allkeys = func_get_args(); |
220 | unset($allkeys[0]); | |
221 | $url = join('/',$allkeys); | |
4a8a1e0a | 222 | header("Content-type: text/javascript; charset=utf-8"); |
8c5c6d64 | 223 | echo '$.ajax({ url: "'.$url.'?forceXml=1", dataType: "xml", success: function(xml) { $("body",xml).insertBefore("body"); $("body:eq(1)").remove(); }});'; |
4a8a1e0a | 224 | exit; |
225 | } | |
bd4be95d | 226 | } |
227 | ||
a7de4ef7 | 228 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
bd4be95d | 229 | ?> |