Move pages Services, About, Article12, Article16 and CreateGPX to the wiki
[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 '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 );
35 }
36
37 function handler_index(&$page)
38 {
39 $page->changeTpl('xnet/index.tpl');
40 }
41
42 function handler_exit(&$page)
43 {
44 XnetSession::destroy();
45 $page->changeTpl('xnet/deconnexion.tpl');
46 $page->useMenu();
47 }
48
49 function handler_admin(&$page)
50 {
51 new_admin_page('xnet/admin.tpl');
52 $page->useMenu();
53
54 if (Get::has('del')) {
55 $res = XDB::query('SELECT id, nom, mail_domain
56 FROM groupex.asso WHERE diminutif={?}',
57 Get::v('del'));
58 list($id, $nom, $domain) = $res->fetchOneRow();
59 $page->assign('nom', $nom);
60 if ($id && Post::has('del')) {
61 XDB::query('DELETE FROM groupex.membres WHERE asso_id={?}', $id);
62 $page->trig('membres supprimés');
63
64 if ($domain) {
65 XDB::query('DELETE FROM virtual_domains WHERE domain={?}', $domain);
66 XDB::query('DELETE FROM virtual, virtual_redirect
67 USING virtual INNER JOIN virtual_redirect USING (vid)
68 WHERE alias LIKE {?}', '%@'.$domain);
69 $page->trig('suppression des alias mails');
70
71 require_once('lists.inc.php');
72 $client =& lists_xmlrpc(S::v('uid'), S::v('password'), $domain);
73 if ($listes = $client->get_lists()) {
74 foreach ($listes as $l) {
75 $client->delete_list($l['list'], true);
76 }
77 $page->trig('mail lists surpprimées');
78 }
79 }
80
81 XDB::query('DELETE FROM groupex.asso WHERE id={?}', $id);
82 $page->trig("Groupe $nom supprimé");
83 Get::kill('del');
84 }
85 if (!$id) {
86 Get::kill('del');
87 }
88 }
89
90 if (Post::has('diminutif')) {
91 XDB::query('INSERT INTO groupex.asso (id,diminutif)
92 VALUES(NULL,{?})', Post::v('diminutif'));
93 pl_redirect('../'.Post::v('diminutif').'/edit');
94 }
95
96 $res = XDB::query('SELECT nom,diminutif FROM groupex.asso ORDER by NOM');
97 $page->assign('assos', $res->fetchAllAssoc());
98 }
99
100 function handler_plan(&$page)
101 {
102 $page->changeTpl('xnet/plan.tpl');
103
104 $page->setType('plan');
105
106 $res = XDB::iterator(
107 'SELECT dom.id, dom.nom as domnom, asso.diminutif, asso.nom
108 FROM groupex.dom
109 INNER JOIN groupex.asso ON dom.id = asso.dom
110 WHERE FIND_IN_SET("GroupesX", dom.cat) AND FIND_IN_SET("GroupesX", asso.cat)
111 ORDER BY dom.nom, asso.nom');
112 $groupesx = array();
113 while ($tmp = $res->next()) { $groupesx[$tmp['id']][] = $tmp; }
114 $page->assign('groupesx', $groupesx);
115
116 $res = XDB::iterator(
117 'SELECT dom.id, dom.nom as domnom, asso.diminutif, asso.nom
118 FROM groupex.dom
119 INNER JOIN groupex.asso ON dom.id = asso.dom
120 WHERE FIND_IN_SET("Binets", dom.cat) AND FIND_IN_SET("Binets", asso.cat)
121 ORDER BY dom.nom, asso.nom');
122 $binets = array();
123 while ($tmp = $res->next()) { $binets[$tmp['id']][] = $tmp; }
124 $page->assign('binets', $binets);
125
126 $res = XDB::iterator(
127 'SELECT asso.diminutif, asso.nom
128 FROM groupex.asso
129 WHERE cat LIKE "%Promotions%"
130 ORDER BY diminutif');
131 $page->assign('promos', $res);
132
133 $res = XDB::iterator(
134 'SELECT asso.diminutif, asso.nom
135 FROM groupex.asso
136 WHERE FIND_IN_SET("Institutions", cat)
137 ORDER BY diminutif');
138 $page->assign('inst', $res);
139 $page->useMenu();
140 }
141
142 function handler_groups2(&$page)
143 {
144 $this->handler_groups(&$page, Get::v('cat'), Get::v('dom'));
145 }
146
147 function handler_groups(&$page, $cat = null, $dom = null)
148 {
149 if (!$cat) {
150 $this->handler_index(&$page);
151 }
152
153 $cat = strtolower($cat);
154
155 $page->changeTpl('xnet/groupes.tpl');
156 $page->assign('cat', $cat);
157 $page->assign('dom', $dom);
158
159 $res = XDB::query("SELECT id,nom FROM groupex.dom
160 WHERE FIND_IN_SET({?}, cat)
161 ORDER BY nom", $cat);
162 $doms = $res->fetchAllAssoc();
163 $page->assign('doms', $doms);
164
165 if (empty($doms)) {
166 $res = XDB::query("SELECT diminutif, nom FROM groupex.asso
167 WHERE FIND_IN_SET({?}, cat)
168 ORDER BY nom", $cat);
169 $page->assign('gps', $res->fetchAllAssoc());
170 } elseif (!is_null($dom)) {
171 $res = XDB::query("SELECT diminutif, nom FROM groupex.asso
172 WHERE FIND_IN_SET({?}, cat) AND dom={?}
173 ORDER BY nom", $cat, $dom);
174 $page->assign('gps', $res->fetchAllAssoc());
175 }
176
177 $page->useMenu();
178 $page->setType($cat);
179 }
180 }
181
182 ?>