Some fixes
[platal.git] / modules / xnet.php
CommitLineData
bd4be95d 1<?php
2/***************************************************************************
3 * Copyright (C) 2003-2006 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
22class XnetModule extends PLModule
23{
24 function handlers()
25 {
26 return array(
71fe935c 27 'index' => $this->make_hook('index', AUTH_PUBLIC),
28 'exit' => $this->make_hook('exit', AUTH_PUBLIC),
29
30 'about' => $this->make_hook('about', AUTH_PUBLIC),
31 'article12' => $this->make_hook('article12', AUTH_PUBLIC),
32 'article16' => $this->make_hook('article16', AUTH_PUBLIC),
33 'creategpx' => $this->make_hook('creategpx', AUTH_PUBLIC),
34 'services' => $this->make_hook('services', AUTH_PUBLIC),
35 'manuel' => $this->make_hook('manuel', AUTH_PUBLIC),
36
d55888e6 37 'admin' => $this->make_hook('admin', AUTH_MDP, 'admin'),
0e02493e 38 'groups' => $this->make_hook('groups', AUTH_PUBLIC),
39 'groupes.php' => $this->make_hook('groups2', AUTH_PUBLIC),
71fe935c 40 'plan' => $this->make_hook('plan', AUTH_PUBLIC),
bd4be95d 41 );
42 }
43
44 function handler_index(&$page)
45 {
46 $page->changeTpl('xnet/index.tpl');
bd4be95d 47 }
045a1522 48
71fe935c 49 function handler_exit(&$page)
50 {
51 XnetSession::destroy();
52 $page->changeTpl('xnet/deconnexion.tpl');
53 $page->useMenu();
71fe935c 54 }
55
045a1522 56 function handler_about(&$page)
57 {
58 $page->changeTpl('xnet/apropos.tpl');
59 $page->useMenu();
71fe935c 60 }
61
62 function handler_article12(&$page)
63 {
64 $page->changeTpl('xnet/article12.tpl');
65 $page->useMenu();
71fe935c 66 }
67
68 function handler_article16(&$page)
69 {
70 $page->changeTpl('xnet/article16.tpl');
71 $page->useMenu();
71fe935c 72 }
73
74 function handler_creategpx(&$page)
75 {
76 $page->changeTpl('xnet/creation-groupex.tpl');
77 $page->useMenu();
71fe935c 78 }
79
883ae44b 80 function handler_services(&$page)
71fe935c 81 {
82 $page->changeTpl('xnet/services.tpl');
83 $page->useMenu();
71fe935c 84 }
85
7fc42a8b 86 function handler_manuel(&$page, $type = null)
71fe935c 87 {
88 $page->changeTpl('xnet/manuel.tpl');
8354a15c 89 if (!$type) {
90 $page->useMenu();
91 }
7fc42a8b 92 $page->assign('type', $type);
71fe935c 93 }
94
d55888e6 95 function handler_admin(&$page)
96 {
d55888e6 97 new_admin_page('xnet/admin.tpl');
98 $page->useMenu();
99
100 if (Get::has('del')) {
08cce2ff 101 $res = XDB::query('SELECT id, nom, mail_domain
d55888e6 102 FROM groupex.asso WHERE diminutif={?}',
5e2307dc 103 Get::v('del'));
d55888e6 104 list($id, $nom, $domain) = $res->fetchOneRow();
105 $page->assign('nom', $nom);
106 if ($id && Post::has('del')) {
08cce2ff 107 XDB::query('DELETE FROM groupex.membres WHERE asso_id={?}', $id);
d55888e6 108 $page->trig('membres supprimés');
109
110 if ($domain) {
08cce2ff 111 XDB::query('DELETE FROM virtual_domains WHERE domain={?}', $domain);
112 XDB::query('DELETE FROM virtual, virtual_redirect
d55888e6 113 USING virtual INNER JOIN virtual_redirect USING (vid)
114 WHERE alias LIKE {?}', '%@'.$domain);
115 $page->trig('suppression des alias mails');
116
117 require_once('lists.inc.php');
cab08090 118 $client =& lists_xmlrpc(S::v('uid'), S::v('password'), $domain);
d55888e6 119 if ($listes = $client->get_lists()) {
120 foreach ($listes as $l) {
121 $client->delete_list($l['list'], true);
122 }
123 $page->trig('mail lists surpprimées');
124 }
125 }
126
08cce2ff 127 XDB::query('DELETE FROM groupex.asso WHERE id={?}', $id);
d55888e6 128 $page->trig("Groupe $nom supprimé");
129 Get::kill('del');
130 }
131 if (!$id) {
132 Get::kill('del');
133 }
134 }
135
136 if (Post::has('diminutif')) {
08cce2ff 137 XDB::query('INSERT INTO groupex.asso (id,diminutif)
5e2307dc 138 VALUES(NULL,{?})', Post::v('diminutif'));
139 pl_redirect('../'.Post::v('diminutif').'/edit');
d55888e6 140 }
141
08cce2ff 142 $res = XDB::query('SELECT nom,diminutif FROM groupex.asso ORDER by NOM');
d55888e6 143 $page->assign('assos', $res->fetchAllAssoc());
144 }
145
71fe935c 146 function handler_plan(&$page)
147 {
71fe935c 148 $page->changeTpl('xnet/plan.tpl');
149
150 $page->setType('plan');
151
08cce2ff 152 $res = XDB::iterator(
71fe935c 153 'SELECT dom.id, dom.nom as domnom, asso.diminutif, asso.nom
154 FROM groupex.dom
155 INNER JOIN groupex.asso ON dom.id = asso.dom
156 WHERE FIND_IN_SET("GroupesX", dom.cat) AND FIND_IN_SET("GroupesX", asso.cat)
157 ORDER BY dom.nom, asso.nom');
158 $groupesx = array();
159 while ($tmp = $res->next()) { $groupesx[$tmp['id']][] = $tmp; }
160 $page->assign('groupesx', $groupesx);
161
08cce2ff 162 $res = XDB::iterator(
71fe935c 163 'SELECT dom.id, dom.nom as domnom, asso.diminutif, asso.nom
164 FROM groupex.dom
165 INNER JOIN groupex.asso ON dom.id = asso.dom
166 WHERE FIND_IN_SET("Binets", dom.cat) AND FIND_IN_SET("Binets", asso.cat)
167 ORDER BY dom.nom, asso.nom');
168 $binets = array();
169 while ($tmp = $res->next()) { $binets[$tmp['id']][] = $tmp; }
170 $page->assign('binets', $binets);
171
08cce2ff 172 $res = XDB::iterator(
71fe935c 173 'SELECT asso.diminutif, asso.nom
174 FROM groupex.asso
175 WHERE cat LIKE "%Promotions%"
176 ORDER BY diminutif');
177 $page->assign('promos', $res);
178
08cce2ff 179 $res = XDB::iterator(
71fe935c 180 'SELECT asso.diminutif, asso.nom
181 FROM groupex.asso
182 WHERE FIND_IN_SET("Institutions", cat)
183 ORDER BY diminutif');
184 $page->assign('inst', $res);
6fb8424a 185 $page->useMenu();
045a1522 186 }
0e02493e 187
188 function handler_groups2(&$page)
189 {
5e2307dc 190 $this->handler_groups(&$page, Get::v('cat'), Get::v('dom'));
0e02493e 191 }
192
193 function handler_groups(&$page, $cat = null, $dom = null)
194 {
0e02493e 195 if (!$cat) {
196 $this->handler_index(&$page);
197 }
198
199 $cat = strtolower($cat);
200
201 $page->changeTpl('xnet/groupes.tpl');
202 $page->assign('cat', $cat);
203 $page->assign('dom', $dom);
204
08cce2ff 205 $res = XDB::query("SELECT id,nom FROM groupex.dom
0e02493e 206 WHERE FIND_IN_SET({?}, cat) ORDER BY nom", $cat);
207 $doms = $res->fetchAllAssoc();
208 $page->assign('doms', $doms);
209
210 if (empty($doms)) {
08cce2ff 211 $res = XDB::iterator("SELECT diminutif, nom FROM groupex.asso
0e02493e 212 WHERE FIND_IN_SET({?}, cat) ORDER BY nom", $cat);
213 } elseif (!is_null($dom)) {
08cce2ff 214 $res = XDB::iterator("SELECT diminutif, nom FROM groupex.asso
0e02493e 215 WHERE FIND_IN_SET({?}, cat) AND dom={?}
216 ORDER BY nom", $cat, $dom);
217 } else {
218 $res = null;
219 }
220 $page->assign('gps', $res);
221
222 $page->useMenu();
223 $page->setType($cat);
224 }
bd4be95d 225}
226
227?>