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