Commit | Line | Data |
---|---|---|
bd4be95d | 1 | <?php |
2 | /*************************************************************************** | |
9f5bd98e | 3 | * Copyright (C) 2003-2010 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 | ||
deb09f59 | 41 | function handler_photo(&$page, $x = null) |
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 | |
bd4be95d | 54 | function handler_index(&$page) |
55 | { | |
d83a1b04 | 56 | $page->nomenu = true; |
bd4be95d | 57 | $page->changeTpl('xnet/index.tpl'); |
bd4be95d | 58 | } |
badfc7ee | 59 | |
71fe935c | 60 | function handler_exit(&$page) |
61 | { | |
ab694eb5 FB |
62 | Platal::session()->stopSUID(); |
63 | Platal::session()->destroy(); | |
b8e265bf | 64 | $page->changeTpl('xnet/deconnexion.tpl'); |
71fe935c | 65 | } |
66 | ||
d55888e6 | 67 | function handler_admin(&$page) |
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) { | |
08cce2ff | 84 | XDB::query('DELETE FROM virtual_domains WHERE domain={?}', $domain); |
85 | XDB::query('DELETE FROM virtual, virtual_redirect | |
d55888e6 | 86 | USING virtual INNER JOIN virtual_redirect USING (vid) |
87 | WHERE alias LIKE {?}', '%@'.$domain); | |
a7d35093 | 88 | $page->trigSuccess('suppression des alias mails'); |
d55888e6 | 89 | |
9bb8bf21 | 90 | $mmlist = new MMList(S::v('uid'), S::v('password'), $domain); |
91 | if ($listes = $mmlist->get_lists()) { | |
d55888e6 | 92 | foreach ($listes as $l) { |
9bb8bf21 | 93 | $mmlist->delete_list($l['list'], true); |
d55888e6 | 94 | } |
a7d35093 | 95 | $page->trigSuccess('mail lists surpprimées'); |
d55888e6 | 96 | } |
97 | } | |
98 | ||
eb41eda9 | 99 | XDB::query('DELETE FROM groups WHERE id={?}', $id); |
a7d35093 | 100 | $page->trigSuccess("Groupe $nom supprimé"); |
d55888e6 | 101 | Get::kill('del'); |
102 | } | |
103 | if (!$id) { | |
104 | Get::kill('del'); | |
105 | } | |
106 | } | |
107 | ||
8d11b755 | 108 | if (Post::has('diminutif') && Post::v('diminutif') != "") { |
40d428d8 VZ |
109 | S::assert_xsrf_token(); |
110 | ||
3af5a31e | 111 | $res = XDB::query('SELECT COUNT(*) |
eb41eda9 | 112 | FROM groups |
3af5a31e SJ |
113 | WHERE diminutif = {?}', |
114 | Post::v('diminutif')); | |
115 | ||
116 | if ($res->fetchOneCell() == 0) { | |
eb41eda9 | 117 | XDB::execute('INSERT INTO groups (id, diminutif) |
3af5a31e SJ |
118 | VALUES (NULL, {?})', |
119 | Post::v('diminutif')); | |
fc4714d6 | 120 | pl_redirect(Post::v('diminutif') . '/edit'); |
3af5a31e SJ |
121 | } else { |
122 | $page->trigError('Le diminutif demandé est déjà pris.'); | |
123 | } | |
d55888e6 | 124 | } |
125 | ||
3af5a31e | 126 | $res = XDB::query('SELECT nom, diminutif |
eb41eda9 | 127 | FROM groups |
3af5a31e | 128 | ORDER BY nom'); |
d55888e6 | 129 | $page->assign('assos', $res->fetchAllAssoc()); |
130 | } | |
131 | ||
71fe935c | 132 | function handler_plan(&$page) |
133 | { | |
71fe935c | 134 | $page->changeTpl('xnet/plan.tpl'); |
135 | ||
136 | $page->setType('plan'); | |
137 | ||
08cce2ff | 138 | $res = XDB::iterator( |
e1406965 FB |
139 | 'SELECT dom.id, dom.nom as domnom, groups.diminutif, groups.nom |
140 | FROM group_dom AS dom | |
141 | INNER JOIN groups ON dom.id = groups.dom | |
142 | WHERE FIND_IN_SET("GroupesX", dom.cat) AND FIND_IN_SET("GroupesX", groups.cat) | |
143 | ORDER BY dom.nom, groups.nom'); | |
71fe935c | 144 | $groupesx = array(); |
145 | while ($tmp = $res->next()) { $groupesx[$tmp['id']][] = $tmp; } | |
146 | $page->assign('groupesx', $groupesx); | |
147 | ||
08cce2ff | 148 | $res = XDB::iterator( |
e1406965 FB |
149 | 'SELECT dom.id, dom.nom as domnom, groups.diminutif, groups.nom |
150 | FROM group_dom AS dom | |
151 | INNER JOIN groups ON dom.id = groups.dom | |
152 | WHERE FIND_IN_SET("Binets", dom.cat) AND FIND_IN_SET("Binets", groups.cat) | |
153 | ORDER BY dom.nom, groups.nom'); | |
71fe935c | 154 | $binets = array(); |
155 | while ($tmp = $res->next()) { $binets[$tmp['id']][] = $tmp; } | |
156 | $page->assign('binets', $binets); | |
157 | ||
08cce2ff | 158 | $res = XDB::iterator( |
e1406965 | 159 | 'SELECT diminutif, nom |
eb41eda9 | 160 | FROM groups |
71fe935c | 161 | WHERE cat LIKE "%Promotions%" |
162 | ORDER BY diminutif'); | |
163 | $page->assign('promos', $res); | |
164 | ||
08cce2ff | 165 | $res = XDB::iterator( |
e1406965 | 166 | 'SELECT diminutif, nom |
eb41eda9 | 167 | FROM groups |
71fe935c | 168 | WHERE FIND_IN_SET("Institutions", cat) |
169 | ORDER BY diminutif'); | |
170 | $page->assign('inst', $res); | |
045a1522 | 171 | } |
0e02493e | 172 | |
173 | function handler_groups2(&$page) | |
174 | { | |
5e2307dc | 175 | $this->handler_groups(&$page, Get::v('cat'), Get::v('dom')); |
0e02493e | 176 | } |
177 | ||
178 | function handler_groups(&$page, $cat = null, $dom = null) | |
179 | { | |
0e02493e | 180 | if (!$cat) { |
181 | $this->handler_index(&$page); | |
182 | } | |
183 | ||
a953f7e7 | 184 | $cat = mb_strtolower($cat); |
0e02493e | 185 | |
186 | $page->changeTpl('xnet/groupes.tpl'); | |
187 | $page->assign('cat', $cat); | |
188 | $page->assign('dom', $dom); | |
189 | ||
00112b2e | 190 | $res = XDB::query("SELECT id,nom |
eb41eda9 | 191 | FROM group_dom |
00112b2e VZ |
192 | WHERE FIND_IN_SET({?}, cat) |
193 | ORDER BY nom", $cat); | |
0e02493e | 194 | $doms = $res->fetchAllAssoc(); |
195 | $page->assign('doms', $doms); | |
196 | ||
197 | if (empty($doms)) { | |
00112b2e | 198 | $res = XDB::query("SELECT diminutif, nom, site |
eb41eda9 | 199 | FROM groups |
00112b2e VZ |
200 | WHERE FIND_IN_SET({?}, cat) |
201 | ORDER BY nom", $cat); | |
f0430dc7 | 202 | $page->assign('gps', $res->fetchAllAssoc()); |
0e02493e | 203 | } elseif (!is_null($dom)) { |
00112b2e | 204 | $res = XDB::query("SELECT diminutif, nom, site |
eb41eda9 | 205 | FROM groups |
00112b2e VZ |
206 | WHERE FIND_IN_SET({?}, cat) AND dom={?} |
207 | ORDER BY nom", $cat, $dom); | |
f0430dc7 | 208 | $page->assign('gps', $res->fetchAllAssoc()); |
0e02493e | 209 | } |
0e02493e | 210 | |
0e02493e | 211 | $page->setType($cat); |
212 | } | |
eaf30d86 | 213 | |
4a8a1e0a | 214 | function handler_autologin(&$page) |
215 | { | |
8c5c6d64 | 216 | $allkeys = func_get_args(); |
217 | unset($allkeys[0]); | |
218 | $url = join('/',$allkeys); | |
3cb500d5 | 219 | pl_content_headers("text/javascript"); |
8c5c6d64 | 220 | echo '$.ajax({ url: "'.$url.'?forceXml=1", dataType: "xml", success: function(xml) { $("body",xml).insertBefore("body"); $("body:eq(1)").remove(); }});'; |
4a8a1e0a | 221 | exit; |
222 | } | |
bd4be95d | 223 | } |
224 | ||
a7de4ef7 | 225 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
bd4be95d | 226 | ?> |