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