migrate annuaire
[platal.git] / modules / xnetgrp.php
CommitLineData
ae7bb180 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 XnetGrpModule extends PLModule
23{
24 function handlers()
25 {
26 return array(
2e94d2b8 27 'grp' => $this->make_hook('index', AUTH_PUBLIC),
28 'grp/asso.php' => $this->make_hook('index', AUTH_PUBLIC),
29 'grp/logo' => $this->make_hook('logo', AUTH_PUBLIC),
30 'grp/edit' => $this->make_hook('edit', AUTH_MDP),
31 'grp/annuaire' => $this->make_hook('annuaire', AUTH_MDP),
ae7bb180 32 );
33 }
34
2e94d2b8 35 function handler_index(&$page, $arg = null)
ae7bb180 36 {
37 global $globals;
38
2e94d2b8 39 if (!is_null($arg)) {
ae7bb180 40 return PL_NOT_FOUND;
41 }
42
43 $page->changeTpl('xnet/groupe/asso.tpl');
44 $page->useMenu();
45 $page->setType($globals->asso('cat'));
46 $page->assign('is_member', is_member());
47 $page->assign('logged', logged());
48
49 $page->assign('asso', $globals->asso());
50 }
dd798f38 51
52 function handler_logo(&$page)
53 {
54 global $globals;
55
56 $res = $globals->xdb->query("SELECT logo, logo_mime
57 FROM groupex.asso WHERE id = {?}",
58 $globals->asso('id'));
59 list($logo, $logo_mime) = $res->fetchOneRow();
60
61 if (!empty($logo)) {
62 header("Content-type: $mime");
63 header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
64 header('Last-Modified:' . gmdate('D, d M Y H:i:s') . ' GMT');
65 header('Cache-Control: no-cache, must-revalidate');
66 header('Pragma: no-cache');
67 echo $logo;
68 } else {
69 header('Content-type: image/jpeg');
70 header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
71 header('Last-Modified:' . gmdate('D, d M Y H:i:s') . ' GMT');
72 header('Cache-Control: no-cache, must-revalidate');
73 header('Pragma: no-cache');
74 readfile(dirname(__FILE__).'/../htdocs.net/images/dflt_carre.jpg');
75 }
76
77 exit;
78 }
2e94d2b8 79
80 function handler_edit(&$page)
81 {
82 global $globals;
83
84 new_groupadmin_page('xnet/groupe/edit.tpl');
85
86 if (Post::has('submit')) {
87 if (has_perms()) {
88 if (Post::get('mail_domain') && (strstr(Post::get('mail_domain'), '.') === false)) {
89 $page->trig_run("le domaine doit être un FQDN (aucune modif effectuée) !!!");
90 }
91 $globals->xdb->execute(
92 "UPDATE groupex.asso
93 SET nom={?}, diminutif={?}, cat={?}, dom={?},
94 descr={?}, site={?}, mail={?}, resp={?},
95 forum={?}, mail_domain={?}, ax={?}, pub={?},
96 sub_url={?}, inscriptible={?}
97 WHERE id={?}",
98 Post::get('nom'), Post::get('diminutif'),
99 Post::get('cat'), Post::getInt('dom'),
100 Post::get('descr'), Post::get('site'),
101 Post::get('mail'), Post::get('resp'),
102 Post::get('forum'), Post::get('mail_domain'),
103 Post::has('ax'), Post::has('pub')?'private':'public',
104 Post::get('sub_url'), Post::get('inscriptible'),
105 $globals->asso('id'));
106 if (Post::get('mail_domain')) {
107 $globals->xdb->execute('INSERT INTO virtual_domains (domain) VALUES({?})',
108 Post::get('mail_domain'));
109 }
110 } else {
111 $globals->xdb->execute(
112 "UPDATE groupex.asso
113 SET descr={?}, site={?}, mail={?}, resp={?},
114 forum={?}, ax={?}, pub= {?}, sub_url={?}
115 WHERE id={?}",
116 Post::get('descr'), Post::get('site'),
117 Post::get('mail'), Post::get('resp'),
118 Post::get('forum'), Post::has('ax'),
119 Post::has('pub')?'private':'public',
120 Post::get('sub_url'), $globals->asso('id'));
121 }
122
123 if ($_FILES['logo']['name']) {
124 $logo = file_get_contents($_FILES['logo']['tmp_name']);
125 $mime = $_FILES['logo']['type'];
126 $globals->xdb->execute('UPDATE groupex.asso
127 SET logo={?}, logo_mime={?}
128 WHERE id={?}', $logo, $mime,
129 $globals->asso('id'));
130 }
131
132 redirect('../'.Post::get('diminutif', $globals->asso('diminutif')).'/edit');
133 }
134
135 if (has_perms()) {
136 $dom = $globals->xdb->iterator('SELECT * FROM groupex.dom ORDER BY nom');
137 $page->assign('dom', $dom);
138 $page->assign('super', true);
139 }
140 }
141
142 function handler_annuaire(&$page)
143 {
144 global $globals;
145
146 define('NB_PER_PAGE', 25);
147
148 if ($globals->asso('pub') == 'public') {
149 new_group_page('xnet/groupe/annuaire.tpl');
150 } else {
151 new_groupadmin_page('xnet/groupe/annuaire.tpl');
152 }
153
154 $page->assign('admin', may_update());
155
156 switch (Env::get('order')) {
157 case 'promo' : $group = 'promo'; $tri = 'promo_o DESC, nom, prenom'; break;
158 case 'promo_inv': $group = 'promo'; $tri = 'promo_o, nom, prenom'; break;
159 case 'alpha_inv': $group = 'initiale'; $tri = 'nom DESC, prenom DESC, promo'; break;
160 default : $group = 'initiale'; $tri = 'nom, prenom, promo';
161 }
162
163 if ($group == 'initiale')
164 $res = $globals->xdb->iterRow(
165 'SELECT UPPER(SUBSTRING(
166 IF(m.origine="X", IF(u.nom_usage<>"", u.nom_usage, u.nom),m.nom),
167 1, 1)) as letter, COUNT(*)
168 FROM groupex.membres AS m
169 LEFT JOIN auth_user_md5 AS u ON ( u.user_id = m.uid )
170 WHERE asso_id = {?}
171 GROUP BY letter
172 ORDER BY letter', $globals->asso('id'));
173 else
174 $res = $globals->xdb->iterRow(
175 'SELECT IF(m.origine="X",u.promo,"extérieur") AS promo,
176 COUNT(*), IF(m.origine="X",u.promo,"") AS promo_o
177 FROM groupex.membres AS m
178 LEFT JOIN auth_user_md5 AS u ON ( u.user_id = m.uid )
179 WHERE asso_id = {?}
180 GROUP BY promo
181 ORDER BY promo_o DESC', $globals->asso('id'));
182
183 $alphabet = array();
184 $nb_tot = 0;
185 while (list($char, $nb) = $res->next()) {
186 $alphabet[] = $char;
187 $nb_tot += $nb;
188 if (Env::has($group) && $char == strtoupper(Env::get($group))) {
189 $tot = $nb;
190 }
191 }
192 $page->assign('group', $group);
193 $page->assign('request_group', Env::get($group));
194 $page->assign('alphabet', $alphabet);
195 $page->assign('nb_tot', $nb_tot);
196
197 $ofs = Env::getInt('offset');
198 $tot = Env::get($group) ? $tot : $nb_tot;
199 $nbp = intval(($tot-1)/NB_PER_PAGE);
200 $links = array();
201 if ($ofs) {
202 $links['précédent'] = $ofs-1;
203 }
204 for ($i = 0; $i <= $nbp; $i++) {
205 $links[(string)($i+1)] = $i;
206 }
207 if ($ofs < $nbp) {
208 $links['suivant'] = $ofs+1;
209 }
210 if (count($links)>1) {
211 $page->assign('links', $links);
212 }
213
214 $ini = '';
215 if (Env::has('initiale')) {
216 $ini = 'AND IF(m.origine="X",
217 IF(u.nom_usage<>"", u.nom_usage, u.nom),
218 m.nom) LIKE "'.addslashes(Env::get('initiale')).'%"';
219 } elseif (Env::has('promo')) {
220 $ini = 'AND IF(m.origine="X", u.promo, "extérieur") = "'
221 .addslashes(Env::get('promo')).'"';
222 }
223
224 $ann = $globals->xdb->iterator(
225 "SELECT IF(m.origine='X',IF(u.nom_usage<>'', u.nom_usage, u.nom) ,m.nom) AS nom,
226 IF(m.origine='X',u.prenom,m.prenom) AS prenom,
227 IF(m.origine='X',u.promo,'extérieur') AS promo,
228 IF(m.origine='X',u.promo,'') AS promo_o,
229 IF(m.origine='X',a.alias,m.email) AS email,
230 IF(m.origine='X',FIND_IN_SET('femme', u.flags),0) AS femme,
231 m.perms='admin' AS admin,
232 m.origine='X' AS x,
233 m.uid
234 FROM groupex.membres AS m
235 LEFT JOIN auth_user_md5 AS u ON ( u.user_id = m.uid )
236 LEFT JOIN aliases AS a ON ( a.id = m.uid AND a.type='a_vie' )
237 WHERE m.asso_id = {?} $ini
238 ORDER BY $tri
239 LIMIT {?},{?}", $globals->asso('id'), $ofs*NB_PER_PAGE, NB_PER_PAGE);
240
241 $page->assign('ann', $ann);
242 }
ae7bb180 243}
244
245?>