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