Table editor fills the new entry form with the default values of the fields
[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),
badfc7ee 28 'login' => $this->make_hook('login', AUTH_MDP),
71fe935c 29 'exit' => $this->make_hook('exit', AUTH_PUBLIC),
30
d55888e6 31 'admin' => $this->make_hook('admin', AUTH_MDP, 'admin'),
0e02493e 32 'groups' => $this->make_hook('groups', AUTH_PUBLIC),
33 'groupes.php' => $this->make_hook('groups2', AUTH_PUBLIC),
71fe935c 34 'plan' => $this->make_hook('plan', AUTH_PUBLIC),
92169c1d 35 'send_bug' => $this->make_hook('bug', AUTH_MDP),
bd4be95d 36 );
37 }
38
92169c1d 39 function handler_bug(&$page)
40 {
41 $this->handler_index(&$page);
42 $page->assign('bug', 1);
43 }
44
bd4be95d 45 function handler_index(&$page)
46 {
d83a1b04 47 $page->nomenu = true;
bd4be95d 48 $page->changeTpl('xnet/index.tpl');
bd4be95d 49 }
045a1522 50
badfc7ee 51 function handler_login(&$page)
52 {
a1d79217 53 $allkeys = func_get_args();
54 unset($allkeys[0]);
55 $url = join('/',$allkeys);
56 pl_redirect($url);
badfc7ee 57 }
58
71fe935c 59 function handler_exit(&$page)
60 {
61 XnetSession::destroy();
62 $page->changeTpl('xnet/deconnexion.tpl');
71fe935c 63 }
64
d55888e6 65 function handler_admin(&$page)
66 {
d55888e6 67 new_admin_page('xnet/admin.tpl');
d55888e6 68
69 if (Get::has('del')) {
08cce2ff 70 $res = XDB::query('SELECT id, nom, mail_domain
d55888e6 71 FROM groupex.asso WHERE diminutif={?}',
5e2307dc 72 Get::v('del'));
d55888e6 73 list($id, $nom, $domain) = $res->fetchOneRow();
74 $page->assign('nom', $nom);
75 if ($id && Post::has('del')) {
08cce2ff 76 XDB::query('DELETE FROM groupex.membres WHERE asso_id={?}', $id);
d55888e6 77 $page->trig('membres supprimés');
78
79 if ($domain) {
08cce2ff 80 XDB::query('DELETE FROM virtual_domains WHERE domain={?}', $domain);
81 XDB::query('DELETE FROM virtual, virtual_redirect
d55888e6 82 USING virtual INNER JOIN virtual_redirect USING (vid)
83 WHERE alias LIKE {?}', '%@'.$domain);
84 $page->trig('suppression des alias mails');
85
9bb8bf21 86 $mmlist = new MMList(S::v('uid'), S::v('password'), $domain);
87 if ($listes = $mmlist->get_lists()) {
d55888e6 88 foreach ($listes as $l) {
9bb8bf21 89 $mmlist->delete_list($l['list'], true);
d55888e6 90 }
91 $page->trig('mail lists surpprimées');
92 }
93 }
94
08cce2ff 95 XDB::query('DELETE FROM groupex.asso WHERE id={?}', $id);
d55888e6 96 $page->trig("Groupe $nom supprimé");
97 Get::kill('del');
98 }
99 if (!$id) {
100 Get::kill('del');
101 }
102 }
103
104 if (Post::has('diminutif')) {
08cce2ff 105 XDB::query('INSERT INTO groupex.asso (id,diminutif)
5e2307dc 106 VALUES(NULL,{?})', Post::v('diminutif'));
107 pl_redirect('../'.Post::v('diminutif').'/edit');
d55888e6 108 }
109
08cce2ff 110 $res = XDB::query('SELECT nom,diminutif FROM groupex.asso ORDER by NOM');
d55888e6 111 $page->assign('assos', $res->fetchAllAssoc());
112 }
113
71fe935c 114 function handler_plan(&$page)
115 {
71fe935c 116 $page->changeTpl('xnet/plan.tpl');
117
118 $page->setType('plan');
119
08cce2ff 120 $res = XDB::iterator(
71fe935c 121 'SELECT dom.id, dom.nom as domnom, asso.diminutif, asso.nom
122 FROM groupex.dom
123 INNER JOIN groupex.asso ON dom.id = asso.dom
124 WHERE FIND_IN_SET("GroupesX", dom.cat) AND FIND_IN_SET("GroupesX", asso.cat)
125 ORDER BY dom.nom, asso.nom');
126 $groupesx = array();
127 while ($tmp = $res->next()) { $groupesx[$tmp['id']][] = $tmp; }
128 $page->assign('groupesx', $groupesx);
129
08cce2ff 130 $res = XDB::iterator(
71fe935c 131 'SELECT dom.id, dom.nom as domnom, asso.diminutif, asso.nom
132 FROM groupex.dom
133 INNER JOIN groupex.asso ON dom.id = asso.dom
134 WHERE FIND_IN_SET("Binets", dom.cat) AND FIND_IN_SET("Binets", asso.cat)
135 ORDER BY dom.nom, asso.nom');
136 $binets = array();
137 while ($tmp = $res->next()) { $binets[$tmp['id']][] = $tmp; }
138 $page->assign('binets', $binets);
139
08cce2ff 140 $res = XDB::iterator(
71fe935c 141 'SELECT asso.diminutif, asso.nom
142 FROM groupex.asso
143 WHERE cat LIKE "%Promotions%"
144 ORDER BY diminutif');
145 $page->assign('promos', $res);
146
08cce2ff 147 $res = XDB::iterator(
71fe935c 148 'SELECT asso.diminutif, asso.nom
149 FROM groupex.asso
150 WHERE FIND_IN_SET("Institutions", cat)
151 ORDER BY diminutif');
152 $page->assign('inst', $res);
045a1522 153 }
0e02493e 154
155 function handler_groups2(&$page)
156 {
5e2307dc 157 $this->handler_groups(&$page, Get::v('cat'), Get::v('dom'));
0e02493e 158 }
159
160 function handler_groups(&$page, $cat = null, $dom = null)
161 {
0e02493e 162 if (!$cat) {
163 $this->handler_index(&$page);
164 }
165
166 $cat = strtolower($cat);
167
168 $page->changeTpl('xnet/groupes.tpl');
169 $page->assign('cat', $cat);
170 $page->assign('dom', $dom);
171
08cce2ff 172 $res = XDB::query("SELECT id,nom FROM groupex.dom
f0430dc7 173 WHERE FIND_IN_SET({?}, cat)
174 ORDER BY nom", $cat);
0e02493e 175 $doms = $res->fetchAllAssoc();
176 $page->assign('doms', $doms);
177
178 if (empty($doms)) {
0d696b52 179 $res = XDB::query("SELECT diminutif, nom, site FROM groupex.asso
f0430dc7 180 WHERE FIND_IN_SET({?}, cat)
181 ORDER BY nom", $cat);
182 $page->assign('gps', $res->fetchAllAssoc());
0e02493e 183 } elseif (!is_null($dom)) {
0d696b52 184 $res = XDB::query("SELECT diminutif, nom, site FROM groupex.asso
f0430dc7 185 WHERE FIND_IN_SET({?}, cat) AND dom={?}
186 ORDER BY nom", $cat, $dom);
187 $page->assign('gps', $res->fetchAllAssoc());
0e02493e 188 }
0e02493e 189
0e02493e 190 $page->setType($cat);
191 }
bd4be95d 192}
193
194?>