Mailman don't understand UTF8 (Closes #761)
[platal.git] / modules / xnet.php
1 <?php
2 /***************************************************************************
3 * Copyright (C) 2003-2008 Polytechnique.org *
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(
27 'index' => $this->make_hook('index', AUTH_PUBLIC),
28 'exit' => $this->make_hook('exit', AUTH_PUBLIC),
29
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),
36 );
37 }
38
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 }
59
60 function handler_index(&$page)
61 {
62 $page->nomenu = true;
63 $page->changeTpl('xnet/index.tpl');
64 }
65
66 function handler_exit(&$page)
67 {
68 XnetSession::killSuid();
69 XnetSession::destroy();
70 $page->changeTpl('xnet/deconnexion.tpl');
71 }
72
73 function handler_admin(&$page)
74 {
75 $page->changeTpl('xnet/admin.tpl');
76
77 if (Get::has('del')) {
78 $res = XDB::query('SELECT id, nom, mail_domain
79 FROM groupex.asso WHERE diminutif={?}',
80 Get::v('del'));
81 list($id, $nom, $domain) = $res->fetchOneRow();
82 $page->assign('nom', $nom);
83 if ($id && Post::has('del')) {
84 S::assert_xsrf_token();
85
86 XDB::query('DELETE FROM groupex.membres WHERE asso_id={?}', $id);
87 $page->trig('membres supprimés');
88
89 if ($domain) {
90 XDB::query('DELETE FROM virtual_domains WHERE domain={?}', $domain);
91 XDB::query('DELETE FROM virtual, virtual_redirect
92 USING virtual INNER JOIN virtual_redirect USING (vid)
93 WHERE alias LIKE {?}', '%@'.$domain);
94 $page->trig('suppression des alias mails');
95
96 $mmlist = new MMList(S::v('uid'), S::v('password'), $domain);
97 if ($listes = $mmlist->get_lists()) {
98 foreach ($listes as $l) {
99 $mmlist->delete_list($l['list'], true);
100 }
101 $page->trig('mail lists surpprimées');
102 }
103 }
104
105 XDB::query('DELETE FROM groupex.asso WHERE id={?}', $id);
106 $page->trig("Groupe $nom supprimé");
107 Get::kill('del');
108 }
109 if (!$id) {
110 Get::kill('del');
111 }
112 }
113
114 if (Post::has('diminutif')) {
115 S::assert_xsrf_token();
116
117 XDB::query('INSERT INTO groupex.asso (id,diminutif)
118 VALUES(NULL,{?})', Post::v('diminutif'));
119 pl_redirect('../'.Post::v('diminutif').'/edit');
120 }
121
122 $res = XDB::query('SELECT nom,diminutif FROM groupex.asso ORDER by NOM');
123 $page->assign('assos', $res->fetchAllAssoc());
124 }
125
126 function handler_plan(&$page)
127 {
128 $page->changeTpl('xnet/plan.tpl');
129
130 $page->setType('plan');
131
132 $res = XDB::iterator(
133 'SELECT dom.id, dom.nom as domnom, asso.diminutif, asso.nom
134 FROM groupex.dom
135 INNER JOIN groupex.asso ON dom.id = asso.dom
136 WHERE FIND_IN_SET("GroupesX", dom.cat) AND FIND_IN_SET("GroupesX", asso.cat)
137 ORDER BY dom.nom, asso.nom');
138 $groupesx = array();
139 while ($tmp = $res->next()) { $groupesx[$tmp['id']][] = $tmp; }
140 $page->assign('groupesx', $groupesx);
141
142 $res = XDB::iterator(
143 'SELECT dom.id, dom.nom as domnom, asso.diminutif, asso.nom
144 FROM groupex.dom
145 INNER JOIN groupex.asso ON dom.id = asso.dom
146 WHERE FIND_IN_SET("Binets", dom.cat) AND FIND_IN_SET("Binets", asso.cat)
147 ORDER BY dom.nom, asso.nom');
148 $binets = array();
149 while ($tmp = $res->next()) { $binets[$tmp['id']][] = $tmp; }
150 $page->assign('binets', $binets);
151
152 $res = XDB::iterator(
153 'SELECT asso.diminutif, asso.nom
154 FROM groupex.asso
155 WHERE cat LIKE "%Promotions%"
156 ORDER BY diminutif');
157 $page->assign('promos', $res);
158
159 $res = XDB::iterator(
160 'SELECT asso.diminutif, asso.nom
161 FROM groupex.asso
162 WHERE FIND_IN_SET("Institutions", cat)
163 ORDER BY diminutif');
164 $page->assign('inst', $res);
165 }
166
167 function handler_groups2(&$page)
168 {
169 $this->handler_groups(&$page, Get::v('cat'), Get::v('dom'));
170 }
171
172 function handler_groups(&$page, $cat = null, $dom = null)
173 {
174 if (!$cat) {
175 $this->handler_index(&$page);
176 }
177
178 $cat = strtolower($cat);
179
180 $page->changeTpl('xnet/groupes.tpl');
181 $page->assign('cat', $cat);
182 $page->assign('dom', $dom);
183
184 $res = XDB::query("SELECT id,nom FROM groupex.dom
185 WHERE FIND_IN_SET({?}, cat)
186 ORDER BY nom", $cat);
187 $doms = $res->fetchAllAssoc();
188 $page->assign('doms', $doms);
189
190 if (empty($doms)) {
191 $res = XDB::query("SELECT diminutif, nom, site FROM groupex.asso
192 WHERE FIND_IN_SET({?}, cat)
193 ORDER BY nom", $cat);
194 $page->assign('gps', $res->fetchAllAssoc());
195 } elseif (!is_null($dom)) {
196 $res = XDB::query("SELECT diminutif, nom, site FROM groupex.asso
197 WHERE FIND_IN_SET({?}, cat) AND dom={?}
198 ORDER BY nom", $cat, $dom);
199 $page->assign('gps', $res->fetchAllAssoc());
200 }
201
202 $page->setType($cat);
203 }
204
205 function handler_autologin(&$page)
206 {
207 $allkeys = func_get_args();
208 unset($allkeys[0]);
209 $url = join('/',$allkeys);
210 header("Content-type: text/javascript; charset=utf-8");
211 echo '$.ajax({ url: "'.$url.'?forceXml=1", dataType: "xml", success: function(xml) { $("body",xml).insertBefore("body"); $("body:eq(1)").remove(); }});';
212 exit;
213 }
214 }
215
216 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
217 ?>