Table editor fills the new entry form with the default values of the fields
[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 'login' => $this->make_hook('login', AUTH_MDP),
29 'exit' => $this->make_hook('exit', AUTH_PUBLIC),
30
31 'admin' => $this->make_hook('admin', AUTH_MDP, 'admin'),
32 'groups' => $this->make_hook('groups', AUTH_PUBLIC),
33 'groupes.php' => $this->make_hook('groups2', AUTH_PUBLIC),
34 'plan' => $this->make_hook('plan', AUTH_PUBLIC),
35 'send_bug' => $this->make_hook('bug', AUTH_MDP),
36 );
37 }
38
39 function handler_bug(&$page)
40 {
41 $this->handler_index(&$page);
42 $page->assign('bug', 1);
43 }
44
45 function handler_index(&$page)
46 {
47 $page->nomenu = true;
48 $page->changeTpl('xnet/index.tpl');
49 }
50
51 function handler_login(&$page)
52 {
53 $allkeys = func_get_args();
54 unset($allkeys[0]);
55 $url = join('/',$allkeys);
56 pl_redirect($url);
57 }
58
59 function handler_exit(&$page)
60 {
61 XnetSession::destroy();
62 $page->changeTpl('xnet/deconnexion.tpl');
63 }
64
65 function handler_admin(&$page)
66 {
67 new_admin_page('xnet/admin.tpl');
68
69 if (Get::has('del')) {
70 $res = XDB::query('SELECT id, nom, mail_domain
71 FROM groupex.asso WHERE diminutif={?}',
72 Get::v('del'));
73 list($id, $nom, $domain) = $res->fetchOneRow();
74 $page->assign('nom', $nom);
75 if ($id && Post::has('del')) {
76 XDB::query('DELETE FROM groupex.membres WHERE asso_id={?}', $id);
77 $page->trig('membres supprimés');
78
79 if ($domain) {
80 XDB::query('DELETE FROM virtual_domains WHERE domain={?}', $domain);
81 XDB::query('DELETE FROM virtual, virtual_redirect
82 USING virtual INNER JOIN virtual_redirect USING (vid)
83 WHERE alias LIKE {?}', '%@'.$domain);
84 $page->trig('suppression des alias mails');
85
86 $mmlist = new MMList(S::v('uid'), S::v('password'), $domain);
87 if ($listes = $mmlist->get_lists()) {
88 foreach ($listes as $l) {
89 $mmlist->delete_list($l['list'], true);
90 }
91 $page->trig('mail lists surpprimées');
92 }
93 }
94
95 XDB::query('DELETE FROM groupex.asso WHERE id={?}', $id);
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')) {
105 XDB::query('INSERT INTO groupex.asso (id,diminutif)
106 VALUES(NULL,{?})', Post::v('diminutif'));
107 pl_redirect('../'.Post::v('diminutif').'/edit');
108 }
109
110 $res = XDB::query('SELECT nom,diminutif FROM groupex.asso ORDER by NOM');
111 $page->assign('assos', $res->fetchAllAssoc());
112 }
113
114 function handler_plan(&$page)
115 {
116 $page->changeTpl('xnet/plan.tpl');
117
118 $page->setType('plan');
119
120 $res = XDB::iterator(
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
130 $res = XDB::iterator(
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
140 $res = XDB::iterator(
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
147 $res = XDB::iterator(
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);
153 }
154
155 function handler_groups2(&$page)
156 {
157 $this->handler_groups(&$page, Get::v('cat'), Get::v('dom'));
158 }
159
160 function handler_groups(&$page, $cat = null, $dom = null)
161 {
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
172 $res = XDB::query("SELECT id,nom FROM groupex.dom
173 WHERE FIND_IN_SET({?}, cat)
174 ORDER BY nom", $cat);
175 $doms = $res->fetchAllAssoc();
176 $page->assign('doms', $doms);
177
178 if (empty($doms)) {
179 $res = XDB::query("SELECT diminutif, nom, site FROM groupex.asso
180 WHERE FIND_IN_SET({?}, cat)
181 ORDER BY nom", $cat);
182 $page->assign('gps', $res->fetchAllAssoc());
183 } elseif (!is_null($dom)) {
184 $res = XDB::query("SELECT diminutif, nom, site FROM groupex.asso
185 WHERE FIND_IN_SET({?}, cat) AND dom={?}
186 ORDER BY nom", $cat, $dom);
187 $page->assign('gps', $res->fetchAllAssoc());
188 }
189
190 $page->setType($cat);
191 }
192 }
193
194 ?>