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( |
fdf0200a |
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/mail' => $this->make_hook('mail', AUTH_MDP), |
32 | 'grp/annuaire' => $this->make_hook('annuaire', AUTH_MDP), |
33 | 'grp/subscribe' => $this->make_hook('subscribe', AUTH_MDP), |
4e310c61 |
34 | |
35 | 'grp/admin/annuaire' |
36 | => $this->make_hook('admin_annuaire', AUTH_MDP), |
ae7bb180 |
37 | ); |
38 | } |
39 | |
2e94d2b8 |
40 | function handler_index(&$page, $arg = null) |
ae7bb180 |
41 | { |
42 | global $globals; |
43 | |
2e94d2b8 |
44 | if (!is_null($arg)) { |
ae7bb180 |
45 | return PL_NOT_FOUND; |
46 | } |
47 | |
48 | $page->changeTpl('xnet/groupe/asso.tpl'); |
49 | $page->useMenu(); |
50 | $page->setType($globals->asso('cat')); |
51 | $page->assign('is_member', is_member()); |
52 | $page->assign('logged', logged()); |
53 | |
54 | $page->assign('asso', $globals->asso()); |
55 | } |
dd798f38 |
56 | |
57 | function handler_logo(&$page) |
58 | { |
59 | global $globals; |
60 | |
61 | $res = $globals->xdb->query("SELECT logo, logo_mime |
62 | FROM groupex.asso WHERE id = {?}", |
63 | $globals->asso('id')); |
64 | list($logo, $logo_mime) = $res->fetchOneRow(); |
65 | |
66 | if (!empty($logo)) { |
67 | header("Content-type: $mime"); |
68 | header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); |
69 | header('Last-Modified:' . gmdate('D, d M Y H:i:s') . ' GMT'); |
70 | header('Cache-Control: no-cache, must-revalidate'); |
71 | header('Pragma: no-cache'); |
72 | echo $logo; |
73 | } else { |
74 | header('Content-type: image/jpeg'); |
75 | header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); |
76 | header('Last-Modified:' . gmdate('D, d M Y H:i:s') . ' GMT'); |
77 | header('Cache-Control: no-cache, must-revalidate'); |
78 | header('Pragma: no-cache'); |
79 | readfile(dirname(__FILE__).'/../htdocs.net/images/dflt_carre.jpg'); |
80 | } |
81 | |
82 | exit; |
83 | } |
2e94d2b8 |
84 | |
85 | function handler_edit(&$page) |
86 | { |
87 | global $globals; |
88 | |
89 | new_groupadmin_page('xnet/groupe/edit.tpl'); |
90 | |
91 | if (Post::has('submit')) { |
92 | if (has_perms()) { |
93 | if (Post::get('mail_domain') && (strstr(Post::get('mail_domain'), '.') === false)) { |
94 | $page->trig_run("le domaine doit être un FQDN (aucune modif effectuée) !!!"); |
95 | } |
96 | $globals->xdb->execute( |
97 | "UPDATE groupex.asso |
98 | SET nom={?}, diminutif={?}, cat={?}, dom={?}, |
99 | descr={?}, site={?}, mail={?}, resp={?}, |
100 | forum={?}, mail_domain={?}, ax={?}, pub={?}, |
101 | sub_url={?}, inscriptible={?} |
102 | WHERE id={?}", |
103 | Post::get('nom'), Post::get('diminutif'), |
104 | Post::get('cat'), Post::getInt('dom'), |
105 | Post::get('descr'), Post::get('site'), |
106 | Post::get('mail'), Post::get('resp'), |
107 | Post::get('forum'), Post::get('mail_domain'), |
108 | Post::has('ax'), Post::has('pub')?'private':'public', |
109 | Post::get('sub_url'), Post::get('inscriptible'), |
110 | $globals->asso('id')); |
111 | if (Post::get('mail_domain')) { |
112 | $globals->xdb->execute('INSERT INTO virtual_domains (domain) VALUES({?})', |
113 | Post::get('mail_domain')); |
114 | } |
115 | } else { |
116 | $globals->xdb->execute( |
117 | "UPDATE groupex.asso |
118 | SET descr={?}, site={?}, mail={?}, resp={?}, |
119 | forum={?}, ax={?}, pub= {?}, sub_url={?} |
120 | WHERE id={?}", |
121 | Post::get('descr'), Post::get('site'), |
122 | Post::get('mail'), Post::get('resp'), |
123 | Post::get('forum'), Post::has('ax'), |
124 | Post::has('pub')?'private':'public', |
125 | Post::get('sub_url'), $globals->asso('id')); |
126 | } |
127 | |
128 | if ($_FILES['logo']['name']) { |
129 | $logo = file_get_contents($_FILES['logo']['tmp_name']); |
130 | $mime = $_FILES['logo']['type']; |
131 | $globals->xdb->execute('UPDATE groupex.asso |
132 | SET logo={?}, logo_mime={?} |
133 | WHERE id={?}', $logo, $mime, |
134 | $globals->asso('id')); |
135 | } |
136 | |
137 | redirect('../'.Post::get('diminutif', $globals->asso('diminutif')).'/edit'); |
138 | } |
139 | |
140 | if (has_perms()) { |
141 | $dom = $globals->xdb->iterator('SELECT * FROM groupex.dom ORDER BY nom'); |
142 | $page->assign('dom', $dom); |
143 | $page->assign('super', true); |
144 | } |
145 | } |
146 | |
479d2787 |
147 | function handler_mail(&$page) |
148 | { |
149 | global $globals; |
150 | |
151 | require_once 'lists.inc.php'; |
152 | |
153 | new_groupadmin_page('xnet/groupe/mail.tpl'); |
154 | $client =& lists_xmlrpc(Session::getInt('uid'), |
155 | Session::get('password'), |
156 | $globals->asso('mail_domain')); |
157 | $page->assign('listes', $client->get_lists()); |
158 | |
159 | if (Post::has('send')) { |
160 | $from = Post::get('from'); |
161 | $sujet = Post::get('sujet'); |
162 | $body = Post::get('body'); |
163 | |
164 | $mls = array_keys(Env::getMixed('ml', array())); |
165 | |
166 | require_once 'xnet/mail.inc.php'; |
167 | $tos = get_all_redirects(Post::has('membres'), $mls, $client); |
168 | send_xnet_mails($from, $sujet, $body, $tos, Post::get('replyto')); |
169 | $page->kill("Mail envoyé !"); |
170 | $page->assign('sent', true); |
171 | } |
172 | } |
173 | |
2e94d2b8 |
174 | function handler_annuaire(&$page) |
175 | { |
176 | global $globals; |
177 | |
178 | define('NB_PER_PAGE', 25); |
179 | |
180 | if ($globals->asso('pub') == 'public') { |
181 | new_group_page('xnet/groupe/annuaire.tpl'); |
182 | } else { |
183 | new_groupadmin_page('xnet/groupe/annuaire.tpl'); |
184 | } |
185 | |
186 | $page->assign('admin', may_update()); |
187 | |
188 | switch (Env::get('order')) { |
189 | case 'promo' : $group = 'promo'; $tri = 'promo_o DESC, nom, prenom'; break; |
190 | case 'promo_inv': $group = 'promo'; $tri = 'promo_o, nom, prenom'; break; |
191 | case 'alpha_inv': $group = 'initiale'; $tri = 'nom DESC, prenom DESC, promo'; break; |
192 | default : $group = 'initiale'; $tri = 'nom, prenom, promo'; |
193 | } |
194 | |
195 | if ($group == 'initiale') |
196 | $res = $globals->xdb->iterRow( |
197 | 'SELECT UPPER(SUBSTRING( |
198 | IF(m.origine="X", IF(u.nom_usage<>"", u.nom_usage, u.nom),m.nom), |
199 | 1, 1)) as letter, COUNT(*) |
200 | FROM groupex.membres AS m |
201 | LEFT JOIN auth_user_md5 AS u ON ( u.user_id = m.uid ) |
202 | WHERE asso_id = {?} |
203 | GROUP BY letter |
204 | ORDER BY letter', $globals->asso('id')); |
205 | else |
206 | $res = $globals->xdb->iterRow( |
207 | 'SELECT IF(m.origine="X",u.promo,"extérieur") AS promo, |
208 | COUNT(*), IF(m.origine="X",u.promo,"") AS promo_o |
209 | FROM groupex.membres AS m |
210 | LEFT JOIN auth_user_md5 AS u ON ( u.user_id = m.uid ) |
211 | WHERE asso_id = {?} |
212 | GROUP BY promo |
213 | ORDER BY promo_o DESC', $globals->asso('id')); |
214 | |
215 | $alphabet = array(); |
216 | $nb_tot = 0; |
217 | while (list($char, $nb) = $res->next()) { |
218 | $alphabet[] = $char; |
219 | $nb_tot += $nb; |
220 | if (Env::has($group) && $char == strtoupper(Env::get($group))) { |
221 | $tot = $nb; |
222 | } |
223 | } |
224 | $page->assign('group', $group); |
225 | $page->assign('request_group', Env::get($group)); |
226 | $page->assign('alphabet', $alphabet); |
227 | $page->assign('nb_tot', $nb_tot); |
228 | |
229 | $ofs = Env::getInt('offset'); |
230 | $tot = Env::get($group) ? $tot : $nb_tot; |
231 | $nbp = intval(($tot-1)/NB_PER_PAGE); |
232 | $links = array(); |
233 | if ($ofs) { |
234 | $links['précédent'] = $ofs-1; |
235 | } |
236 | for ($i = 0; $i <= $nbp; $i++) { |
237 | $links[(string)($i+1)] = $i; |
238 | } |
239 | if ($ofs < $nbp) { |
240 | $links['suivant'] = $ofs+1; |
241 | } |
242 | if (count($links)>1) { |
243 | $page->assign('links', $links); |
244 | } |
245 | |
246 | $ini = ''; |
247 | if (Env::has('initiale')) { |
248 | $ini = 'AND IF(m.origine="X", |
249 | IF(u.nom_usage<>"", u.nom_usage, u.nom), |
250 | m.nom) LIKE "'.addslashes(Env::get('initiale')).'%"'; |
251 | } elseif (Env::has('promo')) { |
252 | $ini = 'AND IF(m.origine="X", u.promo, "extérieur") = "' |
253 | .addslashes(Env::get('promo')).'"'; |
254 | } |
255 | |
256 | $ann = $globals->xdb->iterator( |
257 | "SELECT IF(m.origine='X',IF(u.nom_usage<>'', u.nom_usage, u.nom) ,m.nom) AS nom, |
258 | IF(m.origine='X',u.prenom,m.prenom) AS prenom, |
259 | IF(m.origine='X',u.promo,'extérieur') AS promo, |
260 | IF(m.origine='X',u.promo,'') AS promo_o, |
261 | IF(m.origine='X',a.alias,m.email) AS email, |
262 | IF(m.origine='X',FIND_IN_SET('femme', u.flags),0) AS femme, |
263 | m.perms='admin' AS admin, |
264 | m.origine='X' AS x, |
265 | m.uid |
266 | FROM groupex.membres AS m |
267 | LEFT JOIN auth_user_md5 AS u ON ( u.user_id = m.uid ) |
268 | LEFT JOIN aliases AS a ON ( a.id = m.uid AND a.type='a_vie' ) |
269 | WHERE m.asso_id = {?} $ini |
270 | ORDER BY $tri |
271 | LIMIT {?},{?}", $globals->asso('id'), $ofs*NB_PER_PAGE, NB_PER_PAGE); |
272 | |
273 | $page->assign('ann', $ann); |
274 | } |
4e310c61 |
275 | |
fdf0200a |
276 | function handler_subscribe(&$page, $u = null) |
277 | { |
278 | $page->changeTpl('xnet/groupe/inscrire.tpl'); |
279 | |
280 | $page->useMenu(); |
281 | $page->setType($globals->asso('cat')); |
282 | $page->assign('asso', $globals->asso()); |
283 | $page->assign('admin', may_update()); |
284 | |
285 | if (!$globals->asso('inscriptible')) |
286 | $page->kill("Il n'est pas possible de s'inscire en ligne à ce " |
287 | ."groupe. Essaie de joindre le contact indiqué " |
288 | ."sur la page de présentation."); |
289 | |
290 | if (!is_null($u) && may_update()) { |
291 | $page->assign('u', $u); |
292 | $res = $globals->xdb->query("SELECT nom, prenom, promo, user_id |
293 | FROM auth_user_md5 AS u |
294 | INNER JOIN aliases AS al ON (al.id = u.user_id |
295 | AND al.type != 'liste') |
296 | WHERE al.alias = {?}", $u); |
297 | |
298 | if (list($nom, $prenom, $promo, $uid) = $res->fetchOneRow()) { |
299 | $res = $globals->xdb->query("SELECT COUNT(*) |
300 | FROM groupex.membres AS m |
301 | INNER JOIN aliases AS a ON (m.uid = a.id |
302 | AND a.type != 'homonyme') |
303 | WHERE a.alias = {?} AND m.asso_id = {?}", |
304 | $u, $globals->asso('id')); |
305 | $n = $res->fetchOneCell(); |
306 | if ($n) { |
307 | $page->trig_run("$prenom $nom est déjà membre du groupe !"); |
308 | } |
309 | elseif (Env::has('accept')) |
310 | { |
311 | $globals->xdb->execute("INSERT INTO groupex.membres |
312 | VALUES ({?}, {?}, 'membre', 'X', NULL, NULL, NULL, NULL)", |
313 | $globals->asso('id'), $uid); |
314 | require_once 'diogenes/diogenes.hermes.inc.php'; |
315 | $mailer = new HermesMailer(); |
316 | $mailer->addTo("$u@polytechnique.org"); |
317 | $mailer->setFrom('"'.Session::get('prenom').' '.Session::get('nom') |
318 | .'" <'.Session::get('forlife').'@polytechnique.org>'); |
319 | $mailer->setSubject('['.$globals->asso('nom').'] Demande d\'inscription'); |
320 | $message = "Cher Camarade,\n" |
321 | . "\n" |
322 | . " Suite à ta demande d'adhésion à ".$globals->asso('nom').",\n" |
323 | . "j'ai le plaisir de t'annoncer que ton inscription a été validée !\n" |
324 | . "\n" |
325 | . "Bien cordialement,\n" |
326 | . "{$_SESSION["prenom"]} {$_SESSION["nom"]}."; |
327 | $mailer->setTxtBody($message); |
328 | $mailer->send(); |
329 | $page->kill("$prenom $nom a bien été inscrit"); |
330 | } |
331 | elseif (Env::has('refuse')) |
332 | { |
333 | require_once 'diogenes/diogenes.hermes.inc.php'; |
334 | $mailer = new HermesMailer(); |
335 | $mailer->addTo("$u@polytechnique.org"); |
336 | $mailer->setFrom('"'.Session::get('prenom').' '.Session::get('nom') |
337 | .'" <'.Session::get('forlife').'@polytechnique.org>'); |
338 | $mailer->setSubject('['.$globals->asso('nom').'] Demande d\'inscription annulée'); |
339 | $mailer->setTxtBody(Env::get('motif')); |
340 | $mailer->send(); |
341 | $page->kill("la demande $prenom $nom a bien été refusée"); |
342 | } else { |
343 | $page->assign('show_form', true); |
344 | $page->assign('prenom', $prenom); |
345 | $page->assign('nom', $nom); |
346 | $page->assign('promo', $promo); |
347 | $page->assign('uid', $uid); |
348 | } |
349 | return; |
350 | } |
351 | return PL_NOT_FOUND; |
352 | } |
353 | |
354 | if (is_member()) { |
355 | $page->kill("tu es déjà membre !"); |
356 | return; |
357 | } |
358 | |
359 | if (Post::has('inscrire')) { |
360 | $res = $globals->xdb->query('SELECT IF(m.email IS NULL, |
361 | CONCAT(al.alias,"@polytechnique.org"), |
362 | m.email) |
363 | FROM groupex.membres AS m |
364 | INNER JOIN aliases AS al ON (al.type = "a_vie" |
365 | AND al.id = m.uid) |
366 | WHERE perms="admin" AND m.asso_id = {?}', |
367 | $globals->asso('id')); |
368 | $emails = $res->fetchColumn(); |
369 | $to = implode(',', $emails); |
370 | |
371 | $append = "\n" |
372 | . "-- \n" |
373 | . "Ce message a été envoyé suite à la demande d'inscription de\n" |
374 | . Session::get('prenom').' '.Session::get('nom').' (X'.Session::get('promo').")\n" |
375 | . "Via le site www.polytechnique.net. Tu peux choisir de valider ou\n" |
376 | . "de refuser sa demande d'inscription depuis la page :\n" |
377 | . |
378 | "http://www.polytechnique.net/".$globals->asso("diminutif")."/subscribe/" |
379 | .Session::get('forlife')."\n" |
380 | . "\n" |
381 | . "En cas de problème, contacter l'équipe de Polytechnique.org\n" |
382 | . "à l'adresse : support@polytechnique.org\n"; |
383 | |
384 | if (!$to) { |
385 | $to = $globals->asso("mail").", support@polytechnique.org"; |
386 | $append = "\n-- \nLe groupe ".$globals->asso("nom") |
387 | ." n'a pas d'administrateur, l'équipe de" |
388 | ." Polytechnique.org a été prévenue et va rapidement" |
389 | ." résoudre ce problème.\n"; |
390 | } |
391 | |
392 | require_once 'diogenes/diogenes.hermes.inc.php'; |
393 | $mailer = new HermesMailer(); |
394 | $mailer->addTo($to); |
395 | $mailer->setFrom('"'.Session::get('prenom').' '.Session::get('nom') |
396 | .'" <'.Session::get('forlife').'@polytechnique.org>'); |
397 | $mailer->setSubject('['.$globals->asso('nom').'] Demande d\'inscription'); |
398 | $mailer->setTxtBody(Post::get('message').$append); |
399 | $mailer->send(); |
400 | } |
401 | } |
402 | |
4e310c61 |
403 | function handler_admin_annuaire(&$page) |
404 | { |
405 | global $globals; |
406 | |
407 | require_once 'lists.inc.php'; |
408 | require_once 'xnet/mail.inc.php'; |
409 | |
410 | new_groupadmin_page('xnet/groupe/annuaire-admin.tpl'); |
411 | $client =& lists_xmlrpc(Session::getInt('uid'), |
412 | Session::get('password'), |
413 | $globals->asso('mail_domain')); |
414 | $lists = $client->get_lists(); |
415 | if (!$lists) $lists = array(); |
416 | $listes = array_map(create_function('$arr', 'return $arr["list"];'), $lists); |
417 | |
418 | $subscribers = array(); |
419 | |
420 | foreach ($listes as $list) { |
421 | list(,$members) = $client->get_members($list); |
422 | $mails = array_map(create_function('$arr', 'return $arr[1];'), $members); |
423 | $subscribers = array_unique(array_merge($subscribers, $mails)); |
424 | } |
425 | |
426 | $not_in_group_x = array(); |
427 | $not_in_group_ext = array(); |
428 | |
429 | foreach ($subscribers as $mail) { |
430 | $res = $globals->xdb->query( |
431 | 'SELECT COUNT(*) |
432 | FROM groupex.membres AS m |
433 | LEFT JOIN auth_user_md5 AS u ON (m.uid=u.user_id AND m.uid<50000) |
434 | LEFT JOIN aliases AS a ON (a.id=u.user_id and a.type="a_vie") |
435 | WHERE asso_id = {?} AND |
436 | (m.email = {?} OR CONCAT(a.alias, "@polytechnique.org") = {?})', |
437 | $globals->asso('id'), $mail, $mail); |
438 | if ($res->fetchOneCell() == 0) { |
439 | if (strstr($mail, '@polytechnique.org') === false) { |
440 | $not_in_group_ext[] = $mail; |
441 | } else { |
442 | $not_in_group_x[] = $mail; |
443 | } |
444 | } |
445 | } |
446 | |
447 | $page->assign('not_in_group_ext', $not_in_group_ext); |
448 | $page->assign('not_in_group_x', $not_in_group_x); |
449 | $page->assign('lists', $lists); |
450 | } |
ae7bb180 |
451 | } |
452 | |
453 | ?> |