Commit | Line | Data |
---|---|---|
bd4be95d | 1 | <?php |
2 | /*************************************************************************** | |
12262f13 | 3 | * Copyright (C) 2003-2011 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), | |
6d69b527 FB |
36 | |
37 | 'Xnet' => $this->make_wiki_hook(), | |
bd4be95d | 38 | ); |
39 | } | |
40 | ||
26ba053e | 41 | function handler_photo($page, $x = null) |
deb09f59 | 42 | { |
706f830d | 43 | if (!$x || !($profile = Profile::get($x))) { |
deb09f59 | 44 | return PL_NOT_FOUND; |
45 | } | |
46 | ||
706f830d | 47 | // Retrieve the photo and its mime type. |
470d14f6 | 48 | $photo = $profile->getPhoto(true, true); |
deb09f59 | 49 | |
706f830d FB |
50 | // Display the photo, or a default one when not available. |
51 | $photo->send(); | |
deb09f59 | 52 | } |
eaf30d86 | 53 | |
26ba053e | 54 | function handler_index($page) |
bd4be95d | 55 | { |
d83a1b04 | 56 | $page->nomenu = true; |
bd4be95d | 57 | $page->changeTpl('xnet/index.tpl'); |
bd4be95d | 58 | } |
badfc7ee | 59 | |
26ba053e | 60 | function handler_exit($page) |
71fe935c | 61 | { |
ab694eb5 FB |
62 | Platal::session()->stopSUID(); |
63 | Platal::session()->destroy(); | |
b8e265bf | 64 | $page->changeTpl('xnet/deconnexion.tpl'); |
71fe935c | 65 | } |
66 | ||
26ba053e | 67 | function handler_admin($page) |
d55888e6 | 68 | { |
1490093c | 69 | $page->changeTpl('xnet/admin.tpl'); |
d55888e6 | 70 | |
71 | if (Get::has('del')) { | |
08cce2ff | 72 | $res = XDB::query('SELECT id, nom, mail_domain |
eb41eda9 | 73 | FROM groups WHERE diminutif={?}', |
5e2307dc | 74 | Get::v('del')); |
d55888e6 | 75 | list($id, $nom, $domain) = $res->fetchOneRow(); |
76 | $page->assign('nom', $nom); | |
40d428d8 VZ |
77 | if ($id && Post::has('del')) { |
78 | S::assert_xsrf_token(); | |
79 | ||
eb41eda9 | 80 | XDB::query('DELETE FROM group_members WHERE asso_id={?}', $id); |
a7d35093 | 81 | $page->trigSuccess('membres supprimés'); |
d55888e6 | 82 | |
83 | if ($domain) { | |
831aa467 SJ |
84 | XDB::execute('DELETE v |
85 | FROM email_virtual AS v | |
86 | INNER JOIN email_virtual_domains AS d ON (v.domain = d.id) | |
87 | WHERE d.name = {?}', | |
88 | $domain); | |
89 | XDB::execute('DELETE FROM email_virtual_domains | |
90 | WHERE name = {?}', $domain); | |
a7d35093 | 91 | $page->trigSuccess('suppression des alias mails'); |
d55888e6 | 92 | |
9bb8bf21 | 93 | $mmlist = new MMList(S::v('uid'), S::v('password'), $domain); |
94 | if ($listes = $mmlist->get_lists()) { | |
d55888e6 | 95 | foreach ($listes as $l) { |
9bb8bf21 | 96 | $mmlist->delete_list($l['list'], true); |
d55888e6 | 97 | } |
a7d35093 | 98 | $page->trigSuccess('mail lists surpprimées'); |
d55888e6 | 99 | } |
100 | } | |
101 | ||
eb41eda9 | 102 | XDB::query('DELETE FROM groups WHERE id={?}', $id); |
a7d35093 | 103 | $page->trigSuccess("Groupe $nom supprimé"); |
d55888e6 | 104 | Get::kill('del'); |
105 | } | |
106 | if (!$id) { | |
107 | Get::kill('del'); | |
108 | } | |
109 | } | |
110 | ||
8d11b755 | 111 | if (Post::has('diminutif') && Post::v('diminutif') != "") { |
40d428d8 VZ |
112 | S::assert_xsrf_token(); |
113 | ||
3af5a31e | 114 | $res = XDB::query('SELECT COUNT(*) |
eb41eda9 | 115 | FROM groups |
3af5a31e SJ |
116 | WHERE diminutif = {?}', |
117 | Post::v('diminutif')); | |
118 | ||
119 | if ($res->fetchOneCell() == 0) { | |
eb41eda9 | 120 | XDB::execute('INSERT INTO groups (id, diminutif) |
3af5a31e SJ |
121 | VALUES (NULL, {?})', |
122 | Post::v('diminutif')); | |
fc4714d6 | 123 | pl_redirect(Post::v('diminutif') . '/edit'); |
3af5a31e SJ |
124 | } else { |
125 | $page->trigError('Le diminutif demandé est déjà pris.'); | |
126 | } | |
d55888e6 | 127 | } |
128 | ||
3af5a31e | 129 | $res = XDB::query('SELECT nom, diminutif |
eb41eda9 | 130 | FROM groups |
3af5a31e | 131 | ORDER BY nom'); |
d55888e6 | 132 | $page->assign('assos', $res->fetchAllAssoc()); |
133 | } | |
134 | ||
26ba053e | 135 | function handler_plan($page) |
71fe935c | 136 | { |
71fe935c | 137 | $page->changeTpl('xnet/plan.tpl'); |
138 | ||
139 | $page->setType('plan'); | |
140 | ||
08cce2ff | 141 | $res = XDB::iterator( |
e1406965 FB |
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'); | |
71fe935c | 147 | $groupesx = array(); |
148 | while ($tmp = $res->next()) { $groupesx[$tmp['id']][] = $tmp; } | |
149 | $page->assign('groupesx', $groupesx); | |
150 | ||
08cce2ff | 151 | $res = XDB::iterator( |
e1406965 FB |
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'); | |
71fe935c | 157 | $binets = array(); |
158 | while ($tmp = $res->next()) { $binets[$tmp['id']][] = $tmp; } | |
159 | $page->assign('binets', $binets); | |
160 | ||
08cce2ff | 161 | $res = XDB::iterator( |
e1406965 | 162 | 'SELECT diminutif, nom |
eb41eda9 | 163 | FROM groups |
71fe935c | 164 | WHERE cat LIKE "%Promotions%" |
165 | ORDER BY diminutif'); | |
166 | $page->assign('promos', $res); | |
167 | ||
08cce2ff | 168 | $res = XDB::iterator( |
e1406965 | 169 | 'SELECT diminutif, nom |
eb41eda9 | 170 | FROM groups |
71fe935c | 171 | WHERE FIND_IN_SET("Institutions", cat) |
172 | ORDER BY diminutif'); | |
173 | $page->assign('inst', $res); | |
045a1522 | 174 | } |
0e02493e | 175 | |
26ba053e | 176 | function handler_groups2($page) |
0e02493e | 177 | { |
26ba053e | 178 | $this->handler_groups($page, Get::v('cat'), Get::v('dom')); |
0e02493e | 179 | } |
180 | ||
26ba053e | 181 | function handler_groups($page, $cat = null, $dom = null) |
0e02493e | 182 | { |
0e02493e | 183 | if (!$cat) { |
26ba053e | 184 | $this->handler_index($page); |
0e02493e | 185 | } |
186 | ||
a953f7e7 | 187 | $cat = mb_strtolower($cat); |
0e02493e | 188 | |
189 | $page->changeTpl('xnet/groupes.tpl'); | |
190 | $page->assign('cat', $cat); | |
191 | $page->assign('dom', $dom); | |
192 | ||
aab2ffdd | 193 | $res = XDB::query("SELECT id,nom |
eb41eda9 | 194 | FROM group_dom |
00112b2e VZ |
195 | WHERE FIND_IN_SET({?}, cat) |
196 | ORDER BY nom", $cat); | |
0e02493e | 197 | $doms = $res->fetchAllAssoc(); |
198 | $page->assign('doms', $doms); | |
199 | ||
200 | if (empty($doms)) { | |
00112b2e | 201 | $res = XDB::query("SELECT diminutif, nom, site |
eb41eda9 | 202 | FROM groups |
00112b2e VZ |
203 | WHERE FIND_IN_SET({?}, cat) |
204 | ORDER BY nom", $cat); | |
f0430dc7 | 205 | $page->assign('gps', $res->fetchAllAssoc()); |
0e02493e | 206 | } elseif (!is_null($dom)) { |
00112b2e | 207 | $res = XDB::query("SELECT diminutif, nom, site |
eb41eda9 | 208 | FROM groups |
00112b2e VZ |
209 | WHERE FIND_IN_SET({?}, cat) AND dom={?} |
210 | ORDER BY nom", $cat, $dom); | |
f0430dc7 | 211 | $page->assign('gps', $res->fetchAllAssoc()); |
0e02493e | 212 | } |
0e02493e | 213 | |
0e02493e | 214 | $page->setType($cat); |
215 | } | |
eaf30d86 | 216 | |
26ba053e | 217 | function handler_autologin($page) |
4a8a1e0a | 218 | { |
8c5c6d64 | 219 | $allkeys = func_get_args(); |
220 | unset($allkeys[0]); | |
221 | $url = join('/',$allkeys); | |
3cb500d5 | 222 | pl_content_headers("text/javascript"); |
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 | ?> |