Typo.
[platal.git] / modules / xnetgrp.php
1 <?php
2 /***************************************************************************
3 * Copyright (C) 2003-2010 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
23 class XnetGrpModule extends PLModule
24 {
25 function handlers()
26 {
27 return array(
28 '%grp' => $this->make_hook('index', AUTH_PUBLIC),
29 '%grp/asso.php' => $this->make_hook('index', AUTH_PUBLIC),
30 '%grp/logo' => $this->make_hook('logo', AUTH_PUBLIC),
31 '%grp/site' => $this->make_hook('site', AUTH_PUBLIC),
32 '%grp/edit' => $this->make_hook('edit', AUTH_MDP, 'groupadmin'),
33 '%grp/mail' => $this->make_hook('mail', AUTH_MDP, 'groupadmin'),
34 '%grp/forum' => $this->make_hook('forum', AUTH_MDP, 'groupmember'),
35 '%grp/annuaire' => $this->make_hook('annuaire', AUTH_MDP, 'groupannu'),
36 '%grp/annuaire/vcard' => $this->make_hook('vcard', AUTH_MDP, 'groupmember:groupannu'),
37 '%grp/annuaire/csv' => $this->make_hook('csv', AUTH_MDP, 'groupmember:groupannu'),
38 '%grp/trombi' => $this->make_hook('trombi', AUTH_MDP, 'groupannu'),
39 '%grp/geoloc' => $this->make_hook('geoloc', AUTH_MDP, 'groupannu'),
40 '%grp/subscribe' => $this->make_hook('subscribe', AUTH_MDP),
41 '%grp/subscribe/valid' => $this->make_hook('subscribe_valid', AUTH_MDP, 'groupadmin'),
42 '%grp/unsubscribe' => $this->make_hook('unsubscribe', AUTH_MDP, 'groupmember'),
43
44 '%grp/change_rights' => $this->make_hook('change_rights', AUTH_MDP),
45 '%grp/admin/annuaire' => $this->make_hook('admin_annuaire', AUTH_MDP, 'groupadmin'),
46 '%grp/member' => $this->make_hook('admin_member', AUTH_MDP, 'groupadmin'),
47 '%grp/member/new' => $this->make_hook('admin_member_new', AUTH_MDP, 'groupadmin'),
48 '%grp/member/new/ajax' => $this->make_hook('admin_member_new_ajax', AUTH_MDP, 'user', NO_AUTH),
49 '%grp/member/del' => $this->make_hook('admin_member_del', AUTH_MDP, 'groupadmin'),
50
51 '%grp/rss' => $this->make_hook('rss', AUTH_PUBLIC, 'user', NO_HTTPS),
52 '%grp/announce/new' => $this->make_hook('edit_announce', AUTH_MDP, 'groupadmin'),
53 '%grp/announce/edit' => $this->make_hook('edit_announce', AUTH_MDP, 'groupadmin'),
54 '%grp/announce/photo' => $this->make_hook('photo_announce', AUTH_PUBLIC),
55 '%grp/admin/announces' => $this->make_hook('admin_announce', AUTH_MDP, 'groupadmin'),
56 );
57 }
58
59 function handler_index(&$page, $arg = null)
60 {
61 global $globals, $platal;
62 if (!is_null($arg)) {
63 return PL_NOT_FOUND;
64 }
65 $page->changeTpl('xnetgrp/asso.tpl');
66
67 if (S::logged()) {
68 if (Env::has('read')) {
69 XDB::query('DELETE r.*
70 FROM group_announces_read AS r
71 INNER JOIN group_announces AS a ON (a.id = r.announce_id)
72 WHERE expiration < CURRENT_DATE()');
73 XDB::query('INSERT INTO group_announces_read
74 VALUES ({?}, {?})',
75 Env::i('read'), S::i('uid'));
76 pl_redirect("");
77 }
78 if (Env::has('unread')) {
79 XDB::query('DELETE FROM group_announces_read
80 WHERE announce_id = {?} AND uid = {?}',
81 Env::i('unread'), S::i('uid'));
82 pl_redirect("#art" . Env::i('unread'));
83 }
84
85 /* TODO: refines this filter on promotions by using userfilter. */
86 $user = S::user();
87 if ($user->hasProfile()) {
88 $promo = XDB::format('{?}', $user->profile()->entry_year);
89 $minCondition = ' OR promo_min <= ' . $promo;
90 $maxCondition = ' OR promo_max >= ' . $promo;
91 } else {
92 $minCondition = '';
93 $maxCondition = '';
94 }
95 $arts = XDB::iterator('SELECT a.*, FIND_IN_SET(\'photo\', a.flags) AS photo
96 FROM group_announces AS a
97 LEFT JOIN group_announces_read AS r ON (r.uid = {?} AND r.announce_id = a.id)
98 WHERE asso_id = {?} AND expiration >= CURRENT_DATE()
99 AND (promo_min = 0' . $minCondition . ')
100 AND (promo_max = 0' . $maxCondition . ')
101 AND r.announce_id IS NULL
102 ORDER BY a.expiration',
103 S::i('uid'), $globals->asso('id'));
104 $index = XDB::iterator('SELECT a.id, a.titre, r.uid IS NULL AS nonlu
105 FROM group_announces AS a
106 LEFT JOIN group_announces_read AS r ON (a.id = r.announce_id AND r.uid = {?})
107 WHERE asso_id = {?} AND expiration >= CURRENT_DATE()
108 AND (promo_min = 0' . $minCondition . ')
109 AND (promo_max = 0' . $maxCondition . ')
110 ORDER BY a.expiration',
111 S::i('uid'), $globals->asso('id'));
112 $page->assign('article_index', $index);
113 } else {
114 $arts = XDB::iterator("SELECT *, FIND_IN_SET('photo', flags) AS photo
115 FROM group_announces
116 WHERE asso_id = {?} AND expiration >= CURRENT_DATE()
117 AND FIND_IN_SET('public', flags)",
118 $globals->asso('id'));
119 }
120 if (may_update()) {
121 $subs_valid = XDB::query("SELECT uid
122 FROM group_member_sub_requests
123 WHERE asso_id = {?}",
124 $globals->asso('id'));
125 $page->assign('requests', $subs_valid->numRows());
126 }
127
128 if (!S::hasAuthToken()) {
129 $page->setRssLink("Polytechnique.net :: {$globals->asso("nom")} :: News publiques",
130 $platal->ns . "rss/rss.xml");
131 } else {
132 $page->setRssLink("Polytechnique.net :: {$globals->asso("nom")} :: News",
133 $platal->ns . 'rss/' . S::v('hruid') . '/' . S::user()->token . '/rss.xml');
134 }
135
136 $page->assign('articles', $arts);
137 }
138
139 function handler_logo(&$page)
140 {
141 global $globals;
142 $globals->asso()->getLogo()->send();
143 }
144
145 function handler_site(&$page)
146 {
147 global $globals;
148 $site = $globals->asso('site');
149 if (!$site) {
150 $page->trigError('Le groupe n\'a pas de site web.');
151 return $this->handler_index($page);
152 }
153 http_redirect($site);
154 exit;
155 }
156
157 function handler_edit(&$page)
158 {
159 global $globals;
160 $page->changeTpl('xnetgrp/edit.tpl');
161
162 if (Post::has('submit')) {
163 S::assert_xsrf_token();
164
165 $flags = new PlFlagSet('wiki_desc');
166 $flags->addFlag('notif_unsub', Post::i('notif_unsub') == 1);
167 $site = Post::t('site');
168 if ($site && ($site != "http://")) {
169 $scheme = parse_url($site, PHP_URL_SCHEME);
170 if (!$scheme) {
171 $site = "http://" . $site;
172 }
173 } else {
174 $site = "";
175 }
176 if (S::admin()) {
177 $page->assign('super', true);
178
179 if (Post::v('mail_domain') && (strstr(Post::v('mail_domain'), '.') === false)) {
180 $page->trigError('Le domaine doit être un FQDN (aucune modification effectuée)&nbsp;!!!');
181 return;
182 }
183 if (Post::t('nom') == '' || Post::t('diminutif') == '') {
184 $page->trigError('Ni le nom ni le diminutif du groupe ne peuvent être vide.');
185 return;
186 }
187 XDB::execute(
188 "UPDATE groups
189 SET nom={?}, diminutif={?}, cat={?}, dom={?},
190 descr={?}, site={?}, mail={?}, resp={?},
191 forum={?}, mail_domain={?}, ax={?}, pub={?},
192 sub_url={?}, inscriptible={?}, unsub_url={?},
193 flags={?}
194 WHERE id={?}",
195 Post::v('nom'), Post::v('diminutif'),
196 Post::v('cat'), Post::i('dom'),
197 Post::v('descr'), $site,
198 Post::v('mail'), Post::v('resp'),
199 Post::v('forum'), Post::v('mail_domain'),
200 Post::has('ax'), Post::v('pub'),
201 Post::v('sub_url'), Post::v('inscriptible'),
202 Post::v('unsub_url'), $flags, $globals->asso('id'));
203 if (Post::v('mail_domain')) {
204 XDB::execute('INSERT IGNORE INTO virtual_domains (domain) VALUES({?})',
205 Post::v('mail_domain'));
206 }
207 } else {
208 XDB::execute(
209 "UPDATE groups
210 SET descr={?}, site={?}, mail={?}, resp={?},
211 forum={?}, pub= {?}, sub_url={?},
212 unsub_url={?},flags={?}
213 WHERE id={?}",
214 Post::v('descr'), $site,
215 Post::v('mail'), Post::v('resp'),
216 Post::v('forum'), Post::v('pub'),
217 Post::v('sub_url'), Post::v('unsub_url'),
218 $flags, $globals->asso('id'));
219 }
220
221
222 if ($_FILES['logo']['name']) {
223 $upload = PlUpload::get($_FILES['logo'], $globals->asso('id'), 'asso.logo', true);
224 if (!$upload) {
225 $page->trigError("Impossible de télécharger le logo.");
226 } else {
227 XDB::execute('UPDATE groups
228 SET logo = {?}, logo_mime = {?}
229 WHERE id = {?}', $upload->getContents(), $upload->contentType(),
230 $globals->asso('id'));
231 $upload->rm();
232 }
233 }
234
235 pl_redirect('../' . Post::v('diminutif', $globals->asso('diminutif')) . '/edit');
236 }
237
238 if (S::admin()) {
239 $dom = XDB::iterator('SELECT *
240 FROM group_dom
241 ORDER BY nom');
242 $page->assign('dom', $dom);
243 $page->assign('super', true);
244 }
245 }
246
247 function handler_mail(&$page)
248 {
249 global $globals;
250
251 $page->changeTpl('xnetgrp/mail.tpl');
252 $mmlist = new MMList(S::v('uid'), S::v('password'),
253 $globals->asso('mail_domain'));
254 $page->assign('listes', $mmlist->get_lists());
255 $page->assign('user', S::user());
256 $page->addJsLink('ajax.js');
257
258 if (Post::has('send')) {
259 S::assert_xsrf_token();
260 $from = Post::v('from');
261 $sujet = Post::v('sujet');
262 $body = Post::v('body');
263
264 $mls = array_keys(Env::v('ml', array()));
265 $mbr = array_keys(Env::v('membres', array()));
266
267 $this->load('mail.inc.php');
268 set_time_limit(120);
269 $tos = get_all_redirects($mbr, $mls, $mmlist);
270
271 $upload = PlUpload::get($_FILES['uploaded'], S::user()->login(), 'xnet.emails', true);
272 if (!$upload && @$_FILES['uploaded']['name'] && PlUpload::$lastError != null) {
273 $page->trigError(PlUpload::$lastError);
274 return;
275 }
276
277 send_xnet_mails($from, $sujet, $body, Env::v('wiki'), $tos, Post::v('replyto'), $upload, @$_FILES['uploaded']['name']);
278 if ($upload) {
279 $upload->rm();
280 }
281 $page->killSuccess("Email envoyé&nbsp;!");
282 $page->assign('sent', true);
283 }
284 }
285
286 function handler_forum(&$page, $group = null, $artid = null)
287 {
288 global $globals;
289 $page->changeTpl('xnetgrp/forum.tpl');
290 if (!$globals->asso('forum')) {
291 return PL_NOT_FOUND;
292 }
293 require_once 'banana/forum.inc.php';
294 $get = array();
295 get_banana_params($get, $globals->asso('forum'), $group, $artid);
296 run_banana($page, 'ForumsBanana', $get);
297 }
298
299 function handler_annuaire(&$page, $action = null, $subaction = null)
300 {
301 global $globals;
302
303 if ($action == 'trombi') {
304 __autoload('userset');
305 if ($action == 'trombi') {
306 $view = new ProfileSet(new UFC_Group($globals->asso('id')));
307 } else {
308 $view = new UserSet(new UFC_Group($globals->asso('id')));
309 }
310 $view->addMod('trombi', 'Trombinoscope');
311 $view->apply('annuaire', $page, $action, $subaction);
312 $page->changeTpl('xnetgrp/annuaire.tpl');
313 $count = XDB::fetchOneCell('SELECT COUNT(*)
314 FROM group_members
315 WHERE asso_id = {?}',
316 $globals->asso('id'));
317 $page->assign('nb_tot', $count);
318 return;
319 }
320
321 $page->changeTpl('xnetgrp/annuaire.tpl');
322 $sort = Env::s('order', 'directory_name');
323 $ofs = Env::i('offset');
324 if ($ofs < 0) {
325 $ofs = 0;
326 }
327
328 $sdesc = $sort{0} == '-';
329 $sf = $sdesc ? substr($sort, 1) : $sort;
330 if ($sf == 'promo') {
331 $se = new UFO_Promo(null, $sdesc);
332 } else {
333 $se = new UFO_Name($sf, null, null, $sdesc);
334 }
335
336 if (Env::b('admin')) {
337 $uf = $globals->asso()->getAdminsFilter(null, $se);
338 } else {
339 $uf = $globals->asso()->getMembersFilter(null, $se);
340 }
341 $users = $uf->getUsers(new PlLimit(NB_PER_PAGE, $ofs * NB_PER_PAGE));
342 $count = $uf->getTotalCount();
343
344 $page->assign('nb_tot', $count);
345 $page->assign('pages', floor(($count + NB_PER_PAGE - 1) / NB_PER_PAGE));
346 $page->assign('current', $ofs);
347 $page->assign('order', $sort);
348 $page->assign('users', $users);
349 $page->assign('only_admin', Env::b('admin'));
350 }
351
352 function handler_trombi(&$page)
353 {
354 pl_redirect('annuaire/trombi');
355 }
356
357 function handler_geoloc(&$page)
358 {
359 pl_redirect('annuaire/geoloc');
360 }
361
362 function handler_vcard(&$page, $photos = null)
363 {
364 global $globals;
365 $vcard = new VCard($photos == 'photos', 'Membre du groupe ' . $globals->asso('nom'));
366 $vcard->addProfiles($globals->asso()->getMembersFilter()->getProfiles());
367 $vcard->show();
368 }
369
370 function handler_csv(&$page, $filename = null)
371 {
372 global $globals;
373 if (is_null($filename)) {
374 $filename = $globals->asso('diminutif') . '.csv';
375 }
376 $users = $globals->asso()->getMembersFilter(null, new UFO_Name('directory_name'))->getUsers();
377 pl_content_headers("text/x-csv");
378 $page->changeTpl('xnetgrp/annuaire-csv.tpl', NO_SKIN);
379 $page->assign('users', $users);
380 }
381
382 private function removeSubscriptionRequest($uid)
383 {
384 global $globals;
385 XDB::execute("DELETE FROM group_member_sub_requests
386 WHERE asso_id = {?} AND uid = {?}",
387 $globals->asso('id'), $uid);
388 }
389
390 private function validSubscription(User &$user)
391 {
392 global $globals;
393 $this->removeSubscriptionRequest($user->id());
394 XDB::execute("INSERT IGNORE INTO group_members (asso_id, uid)
395 VALUES ({?}, {?})",
396 $globals->asso('id'), $user->id());
397 if (XDB::affectedRows() == 1) {
398 $mailer = new PlMailer();
399 $mailer->addTo($user->forlifeEmail());
400 $mailer->setFrom('"' . S::user()->fullName() . '" <' . S::user()->forlifeEmail() . '>');
401 $mailer->setSubject('[' . $globals->asso('nom') . '] Demande d\'inscription');
402 $message = ($user->isFemale() ? 'Chère' : 'Cher') . " Camarade,\n"
403 . "\n"
404 . " Suite à ta demande d'adhésion à " . $globals->asso('nom') . ",\n"
405 . "j'ai le plaisir de t'annoncer que ton inscription a été validée !\n"
406 . "\n"
407 . "Bien cordialement,\n"
408 . "-- \n"
409 . S::user()->fullName() . '.';
410 $mailer->setTxtBody($message);
411 $mailer->send();
412 }
413 }
414
415 function handler_subscribe(&$page, $u = null)
416 {
417 global $globals;
418 $page->changeTpl('xnetgrp/inscrire.tpl');
419
420 if (!$globals->asso('inscriptible'))
421 $page->kill("Il n'est pas possible de s'inscire en ligne à ce "
422 ."groupe. Essaie de joindre le contact indiqué "
423 ."sur la page de présentation.");
424
425 if (!is_null($u) && may_update()) {
426 $user = User::get($u);
427 if (!$user) {
428 return PL_NOT_FOUND;
429 } else {
430 $page->assign('user', $user);
431 }
432
433 // Retrieves the subscription status, and the reason.
434 $res = XDB::query("SELECT reason
435 FROM group_member_sub_requests
436 WHERE asso_id = {?} AND uid = {?}",
437 $globals->asso('id'), $user->id());
438 $reason = ($res->numRows() ? $res->fetchOneCell() : null);
439
440 $res = XDB::query("SELECT COUNT(*)
441 FROM group_members
442 WHERE asso_id = {?} AND uid = {?}",
443 $globals->asso('id'), $user->id());
444 $already_member = ($res->fetchOneCell() > 0);
445
446 // Handles the membership request.
447 if ($already_member) {
448 $this->removeSubscriptionRequest($user->id());
449 $page->kill($user->fullName() . ' est déjà membre du groupe&nbsp;!');
450 } elseif (Env::has('accept')) {
451 S::assert_xsrf_token();
452
453 $this->validSubscription($user);
454 pl_redirect("member/" . $user->login());
455 } elseif (Env::has('refuse')) {
456 S::assert_xsrf_token();
457
458 $this->removeSubscriptionRequest($user->id());
459 $mailer = new PlMailer();
460 $mailer->addTo($user->forlifeEmail());
461 $mailer->setFrom('"' . S::user()->fullName() . '" <' . S::user()->forlifeEmail() . '>');
462 $mailer->setSubject('['.$globals->asso('nom').'] Demande d\'inscription annulée');
463 $mailer->setTxtBody(Env::v('motif'));
464 $mailer->send();
465 $page->killSuccess("La demande de {$user->fullName()} a bien été refusée.");
466 } else {
467 $page->assign('show_form', true);
468 $page->assign('reason', $reason);
469 }
470 return;
471 }
472
473 if (is_member()) {
474 $page->kill("Tu es déjà membre&nbsp;!");
475 return;
476 }
477
478 $res = XDB::query("SELECT uid
479 FROM group_member_sub_requests
480 WHERE uid = {?} AND asso_id = {?}",
481 S::i('uid'), $globals->asso('id'));
482 if ($res->numRows() != 0) {
483 $page->kill("Tu as déjà demandé ton inscription à ce groupe. Cette demande est actuellement en attente de validation.");
484 return;
485 }
486
487 if (Post::has('inscrire')) {
488 S::assert_xsrf_token();
489
490 XDB::execute("INSERT INTO group_member_sub_requests (asso_id, uid, ts, reason)
491 VALUES ({?}, {?}, NOW(), {?})",
492 $globals->asso('id'), S::i('uid'), Post::v('message'));
493 $uf = New UserFilter(New UFC_Group($globals->asso('id'), true));
494 $admins = $uf->iterUsers();
495 $admin = $admins->next();
496 $to = $admin->bestalias;
497 while ($admin = $admins->next()) {
498 $to .= ', ' . $admin->bestalias;
499 }
500
501 $append = "\n"
502 . "-- \n"
503 . "Ce message a été envoyé suite à la demande d'inscription de\n"
504 . S::user()->fullName() . ' (X' . S::v('promo') . ")\n"
505 . "Via le site www.polytechnique.net. Tu peux choisir de valider ou\n"
506 . "de refuser sa demande d'inscription depuis la page :\n"
507 . "http://www.polytechnique.net/" . $globals->asso("diminutif") . "/subscribe/" . S::user()->login() . "\n"
508 . "\n"
509 . "En cas de problème, contacter l'équipe de Polytechnique.org\n"
510 . "à l'adresse : support@polytechnique.org\n";
511
512 if (!$to) {
513 $to = ($globals->asso('mail') != '') ? $globals->asso('mail') . ', ' : '';
514 $to .= 'support@polytechnique.org';
515 $append = "\n-- \nLe groupe ".$globals->asso("nom")
516 ." n'a pas d'administrateur, l'équipe de"
517 ." Polytechnique.org a été prévenue et va rapidement"
518 ." résoudre ce problème.\n";
519 }
520
521 $mailer = new PlMailer();
522 $mailer->addTo($to);
523 $mailer->setFrom('"' . S::user()->fullName() . '" <' . S::user()->forlifeEmail() . '>');
524 $mailer->setSubject('['.$globals->asso('nom').'] Demande d\'inscription');
525 $mailer->setTxtBody(Post::v('message').$append);
526 $mailer->send();
527 }
528 }
529
530 function handler_subscribe_valid(&$page)
531 {
532 global $globals;
533
534 if (Post::has('valid')) {
535 S::assert_xsrf_token();
536 $subs = Post::v('subs');
537 if (is_array($subs)) {
538 $users = array();
539 foreach ($subs as $hruid => $val) {
540 if ($val == '1') {
541 $user = User::get($hruid);
542 if ($user) {
543 $this->validSubscription($user);
544 }
545 }
546 }
547 }
548 }
549
550 $it = XDB::iterator('SELECT s.uid, a.hruid, s.ts AS date
551 FROM group_member_sub_requests AS s
552 INNER JOIN accounts AS a ON(s.uid = a.uid)
553 WHERE s.asso_id = {?}
554 ORDER BY s.ts', $globals->asso('id'));
555 $page->changeTpl('xnetgrp/subscribe-valid.tpl');
556 $page->assign('valid', $it);
557 }
558
559 function handler_change_rights(&$page)
560 {
561 if (Env::has('right') && (may_update() || S::suid())) {
562 switch (Env::v('right')) {
563 case 'admin':
564 Platal::session()->stopSUID();
565 break;
566 case 'anim':
567 Platal::session()->doSelfSuid();
568 may_update(true);
569 is_member(true);
570 break;
571 case 'member':
572 Platal::session()->doSelfSuid();
573 may_update(false, true);
574 is_member(true);
575 break;
576 case 'logged':
577 Platal::session()->doSelfSuid();
578 may_update(false, true);
579 is_member(false, true);
580 break;
581 }
582 }
583 http_redirect($_SERVER['HTTP_REFERER']);
584 }
585
586 function handler_admin_annuaire(&$page)
587 {
588 global $globals;
589
590 $this->load('mail.inc.php');
591 $page->changeTpl('xnetgrp/annuaire-admin.tpl');
592 $user = S::user();
593 $mmlist = new MMList($user, $globals->asso('mail_domain'));
594 $lists = $mmlist->get_lists();
595 if (!$lists) $lists = array();
596 $listes = array_map(create_function('$arr', 'return $arr["list"];'), $lists);
597
598 $subscribers = array();
599
600 foreach ($listes as $list) {
601 list(,$members) = $mmlist->get_members($list);
602 $mails = array_map(create_function('$arr', 'return $arr[1];'), $members);
603 $subscribers = array_unique(array_merge($subscribers, $mails));
604 }
605
606 $not_in_group_x = array();
607 $not_in_group_ext = array();
608
609 foreach ($subscribers as $mail) {
610 $uf = new UserFilter(new PFC_And(new UFC_Group($globals->asso('id')),
611 new UFC_Email($mail)));
612 if ($uf->getTotalCount() == 0) {
613 if (User::isForeignEmailAddress($mail)) {
614 $not_in_group_ext[] = $mail;
615 } else {
616 $not_in_group_x[] = $mail;
617 }
618 }
619 }
620
621 $page->assign('not_in_group_ext', $not_in_group_ext);
622 $page->assign('not_in_group_x', $not_in_group_x);
623 $page->assign('lists', $lists);
624 }
625
626 function handler_admin_member_new(&$page, $email = null)
627 {
628 global $globals;
629
630 $page->changeTpl('xnetgrp/membres-add.tpl');
631 $page->addJsLink('ajax.js');
632
633 if (is_null($email)) {
634 return;
635 }
636
637 S::assert_xsrf_token();
638
639 // Finds or creates account: first cases are for users with an account.
640 if (!User::isForeignEmailAddress($email)) {
641 // Standard account
642 $user = User::get($email);
643 } else if (!isvalid_email($email)) {
644 // email might not be a regular email but an alias or a hruid
645 $user = User::get($email);
646 if (!$user) {
647 // need a valid email address
648 $page->trigError('«&nbsp;<strong>' . $email . '</strong>&nbsp;» n\'est pas une adresse email valide.');
649 return;
650 }
651 } else if (Env::v('x') && Env::i('userid')) {
652 $user = User::getWithUID(Env::i('userid'));
653 if (!$user) {
654 $page->trigError('Utilisateur invalide.');
655 return;
656 }
657
658 // User has an account but is not yet registered.
659 if ($user->state == 'pending') {
660 // Add email in account table.
661 XDB::query('UPDATE accounts
662 SET email = {?}
663 WHERE uid = {?} AND email IS NULL',
664 Post::t('email'), $user->id());
665 // Add email for marketing if required.
666 if (Env::v('market')) {
667 $market = Marketing::get($user->uid, $email);
668 if (!$market) {
669 $market = new Marketing($user->uid, $email, 'group', $globals->asso('nom'),
670 Env::v('market_from'), S::v('uid'));
671 $market->add();
672 }
673 }
674 }
675 } else {
676 // User is of type xnet.
677 list($firstname, $lastname) = explode('@', $email);
678 $hruid = User::makeHrid($firstname, $lastname, 'ext');
679 // User might already have an account (in another group for example).
680 $user = User::get($hruid);
681
682 // If the user has no account yet, creates new account: build names from email address.
683 if (empty($user)) {
684 $display_name = ucwords(strtolower(substr($hruid, strpos('.', $hruid))));
685 $full_name = ucwords(strtolower(str_replace('.', ' ', substr($email, strpos('@', $email)))));
686 XDB::execute('INSERT INTO accounts (hruid, display_name, full_name, email, type)
687 VALUES ({?}, {?}, {?}, {?}, \'xnet\')',
688 $hruid, $display_name, $full_name, $email);
689 $user = User::get($hruid);
690 }
691 }
692
693 if ($user) {
694 XDB::execute('REPLACE INTO group_members (uid, asso_id)
695 VALUES ({?}, {?})',
696 $user->id(), $globals->asso('id'));
697 $this->removeSubscriptionRequest($user->id());
698 pl_redirect('member/' . $user->login());
699 }
700 }
701
702 function handler_admin_member_new_ajax(&$page)
703 {
704 pl_content_headers("text/html");
705 $page->changeTpl('xnetgrp/membres-new-search.tpl', NO_SKIN);
706 $users = array();
707 if (Env::has('login')) {
708 $user = User::getSilent(Env::t('login'));
709 if ($user && $user->state != 'pending') {
710 $users = array($user);
711 }
712 }
713 if (empty($users)) {
714 list($lastname, $firstname) = str_replace(array('-', ' ', "'"), '%', array(Env::t('nom'), Env::t('prenom')));
715 $cond = new PFC_And(new PFC_Not(new UFC_Registered()));
716 if (!empty($lastname)) {
717 $cond->addChild(new UFC_Name(Profile::LASTNAME, $lastname, UFC_Name::CONTAINS));
718 }
719 if (!empty($firstname)) {
720 $cond->addChild(new UFC_Name(Profile::FIRSTNAME, $firstname, UFC_Name::CONTAINS));
721 }
722 if (Env::t('promo')) {
723 $cond->addChild(new UFC_Promo('=', UserFilter::DISPLAY, Env::t('promo')));
724 }
725 $uf = new UserFilter($cond);
726 $users = $uf->getUsers(new PlLimit(30));
727 if ($uf->getTotalCount() > 30) {
728 $page->assign('too_many', true);
729 $users = array();
730 }
731 }
732 $page->assign('users', $users);
733 }
734
735 function unsubscribe(PlUser &$user)
736 {
737 global $globals;
738 XDB::execute("DELETE FROM group_members
739 WHERE uid = {?} AND asso_id = {?}",
740 $user->id(), $globals->asso('id'));
741
742 if ($globals->asso('notif_unsub')) {
743 $mailer = new PlMailer('xnetgrp/unsubscription-notif.mail.tpl');
744 $admins = $globals->asso()->iterAdmins();
745 while ($admin = $admins->next()) {
746 $mailer->addTo($admin);
747 }
748 $mailer->assign('group', $globals->asso('nom'));
749 $mailer->assign('user', $user);
750 $mailer->assign('selfdone', $user->id() == S::i('uid'));
751 $mailer->send();
752 }
753
754 $domain = $globals->asso('mail_domain');
755 if (!$domain) {
756 return true;
757 }
758
759 $mmlist = new MMList($user, $domain);
760 $listes = $mmlist->get_lists($user->forlifeEmail());
761
762 $may_update = may_update();
763 $warning = false;
764 if (is_array($listes)) {
765 foreach ($listes as $liste) {
766 if ($liste['sub'] == 2) {
767 if ($may_update) {
768 $mmlist->mass_unsubscribe($liste['list'], Array($user->forlifeEmail()));
769 } else {
770 $mmlist->unsubscribe($liste['list']);
771 }
772 } elseif ($liste['sub']) {
773 Platal::page()->trigWarning($user->fullName() . " a une"
774 ." demande d'inscription en cours sur la"
775 ." liste {$liste['list']}@ !");
776 $warning = true;
777 }
778 }
779 }
780
781 XDB::execute("DELETE FROM virtual_redirect
782 USING virtual_redirect
783 INNER JOIN virtual USING(vid)
784 WHERE redirect={?} AND alias LIKE {?}",
785 $user->forlifeEmail(), '%@'.$domain);
786 return !$warning;
787 }
788
789 function handler_unsubscribe(&$page)
790 {
791 $page->changeTpl('xnetgrp/membres-del.tpl');
792 $user = S::user();
793 if (empty($user)) {
794 return PL_NOT_FOUND;
795 }
796 $page->assign('self', true);
797 $page->assign('user', $user);
798
799 if (!Post::has('confirm')) {
800 return;
801 } else {
802 S::assert_xsrf_token();
803 }
804
805 $hasSingleGroup = $user->hasSingleGroup();
806
807 if ($this->unsubscribe($user)) {
808 $page->trigSuccess('Tu as été désinscrit du groupe avec succès.');
809 } else {
810 $page->trigWarning('Tu as été désinscrit du groupe, mais des erreurs se sont produites lors des désinscriptions des alias et des listes de diffusion.');
811 }
812 if ($user->type == 'xnet' && $hasSingleGroup && Post::has('accountDeletion')) {
813 XDB::execute('DELETE FROM acounts
814 WHERE uid = {?}',
815 $user->id());
816 $page->trigSuccess('Ton compte a bien été supprimé.');
817 }
818 $page->assign('is_member', is_member(true));
819 }
820
821 function handler_admin_member_del(&$page, $user = null)
822 {
823 $page->changeTpl('xnetgrp/membres-del.tpl');
824 $user = User::getSilent($user);
825 if (empty($user)) {
826 return PL_NOT_FOUND;
827 }
828
829 global $globals;
830
831 if (!$user->inGroup($globals->asso('id'))) {
832 pl_redirect('annuaire');
833 }
834
835 $page->assign('self', false);
836 $page->assign('user', $user);
837
838 if (!Post::has('confirm')) {
839 return;
840 } else {
841 S::assert_xsrf_token();
842 }
843
844 $hasSingleGroup = $user->hasSingleGroup();
845
846 if ($this->unsubscribe($user)) {
847 $page->trigSuccess("{$user->fullName()} a été désinscrit du groupe&nbsp;!");
848 } else {
849 $page->trigWarning("{$user->fullName()} a été désinscrit du groupe, mais des erreurs subsistent&nbsp;!");
850 }
851
852 // Either deletes or notifies site administrators if it was the last group
853 // of a xnet account.
854 if ($user->type == 'xnet' && $hasSingleGroup) {
855 if ($user->state == 'pending') {
856 // If the user has never logged in the site, we delete her account.
857 XDB::execute('DELETE FROM acounts
858 WHERE uid = {?}',
859 $user->id());
860 } else {
861 // It the user has already logged in the site, we notify site
862 // administrators that there is a new xnet account without any
863 // group.
864 $mailer = new PlMailer('xnetgrp/unsubscription.mail.tpl');
865 $mailer->assign('user', $user);
866 $mailer->assign('groupId', $globals->asso('id'));
867 $mailer->assign('groupName', $globals->asso('nom'));
868 $mailer->send();
869 }
870 }
871 }
872
873 private function changeLogin(PlPage &$page, PlUser &$user, $login)
874 {
875 // Search the user's uid.
876 $xuser = User::getSilent($login);
877 if (!$xuser) {
878 $accounts = User::getPendingAccounts($login);
879 if (!$accounts) {
880 $page->trigError("L'identifiant $login ne correspond à aucun X.");
881 return false;
882 } else if (count($accounts) > 1) {
883 $page->trigError("L'identifiant $login correspond à plusieurs camarades.");
884 return false;
885 }
886 $xuser = User::getSilent($accounts[0]['uid']);
887 }
888
889 if (!$xuser) {
890 return false;
891 }
892
893 if ($user->mergeIn($xuser)) {
894 return $xuser->login();
895 }
896 return $user->login();
897 }
898
899 function handler_admin_member(&$page, $user)
900 {
901 global $globals;
902
903 $user = User::getSilent($user);
904 if (empty($user)) {
905 return PL_NOT_FOUND;
906 }
907
908 if (!$user->inGroup($globals->asso('id'))) {
909 pl_redirect('annuaire');
910 }
911
912 $page->changeTpl('xnetgrp/membres-edit.tpl');
913
914 $mmlist = new MMList($user, $globals->asso('mail_domain'));
915
916 if (Post::has('change')) {
917 S::assert_xsrf_token();
918
919 // Convert user status to X
920 if (!Post::blank('login_X')) {
921 $forlife = $this->changeLogin($page, $user, Post::t('login_X'));
922 if ($forlife) {
923 pl_redirect('member/' . $forlife);
924 }
925 }
926
927 // Update user info
928 $email_changed = (!$user->profile() && strtolower($user->forlifeEmail()) != strtolower(Post::v('email')));
929 $from_email = $user->forlifeEmail();
930 if (!$user->profile()) {
931 XDB::query('UPDATE accounts
932 SET full_name = {?}, directory_name = {?}, display_name = {?},
933 sex = {?}, email = {?}, type = {?}
934 WHERE uid = {?}',
935 Post::t('full_name'), Post::t('directory_name'), Post::t('display_name'),
936 (Post::t('sex') == 'male') ? 'male' : 'female', Post::t('email'),
937 (Post::t('type') == 'xnet') ? 'xnet' : 'virtual', $user->id());
938 // If user is of type xnet and new password is given.
939 if (!Post::blank('pwhash') && Post::t('type') == 'xnet') {
940 XDB::query('UPDATE accounts
941 SET password = {?}
942 WHERE uid = {?}',
943 Post::t('pwhash'), $user->id());
944 }
945 } else if (!$user->perms) {
946 XDB::query('UPDATE accounts
947 SET email = {?}
948 WHERE uid = {?}',
949 Post::t('email'), $user->id());
950 }
951 if (XDB::affectedRows()) {
952 $page->trigSuccess('Données de l\'utilisateur mises à jour.');
953 }
954
955 // Update group params for user
956 $perms = Post::v('group_perms');
957 $comm = Post::t('comm');
958 if ($user->group_perms != $perms || $user->group_comm != $comm) {
959 XDB::query('UPDATE group_members
960 SET perms = {?}, comm = {?}
961 WHERE uid = {?} AND asso_id = {?}',
962 ($perms == 'admin') ? 'admin' : 'membre', $comm,
963 $user->id(), $globals->asso('id'));
964 if (XDB::affectedRows()) {
965 if ($perms != $user->group_perms) {
966 $page->trigSuccess('Permissions modifiées&nbsp;!');
967 }
968 if ($comm != $user->group_comm) {
969 $page->trigSuccess('Commentaire mis à jour.');
970 }
971 }
972 }
973
974 // Gets user info again as they might have change
975 $user = User::getSilent($user->id());
976
977 // Update ML subscriptions
978 foreach (Env::v('ml1', array()) as $ml => $state) {
979 $ask = empty($_REQUEST['ml2'][$ml]) ? 0 : 2;
980 if ($ask == $state) {
981 if ($state && $email_changed) {
982 $mmlist->replace_email($ml, $from_email, $user->forlifeEmail());
983 $page->trigSuccess("L'abonnement de {$user->fullName()} à $ml@ a été mis à jour.");
984 }
985 continue;
986 }
987 if ($state == '1') {
988 $page->trigWarning("{$user->fullName()} a "
989 ."actuellement une demande d'inscription en "
990 ."cours sur <strong>$ml@</strong> !!!");
991 } elseif ($ask) {
992 $mmlist->mass_subscribe($ml, Array($user->forlifeEmail()));
993 $page->trigSuccess("{$user->fullName()} a été abonné à $ml@.");
994 } else {
995 if ($email_changed) {
996 $mmlist->mass_unsubscribe($ml, Array($from_email));
997 } else {
998 $mmlist->mass_unsubscribe($ml, Array($user->forlifeEmail()));
999 }
1000 $page->trigSuccess("{$user->fullName()} a été désabonné de $ml@.");
1001 }
1002 }
1003
1004 // Change subscriptioin to aliases
1005 foreach (Env::v('ml3', array()) as $ml => $state) {
1006 $ask = !empty($_REQUEST['ml4'][$ml]);
1007 if($state == $ask) {
1008 if ($state && $email_changed) {
1009 XDB::query("UPDATE virtual_redirect AS vr, virtual AS v
1010 SET vr.redirect = {?}
1011 WHERE vr.vid = v.vid AND v.alias = {?} AND vr.redirect = {?}",
1012 $user->forlifeEmail(), $ml, $from_email);
1013 $page->trigSuccess("L'abonnement de {$user->fullName()} à $ml a été mis à jour.");
1014 }
1015 } else if($ask) {
1016 XDB::query("INSERT INTO virtual_redirect (vid,redirect)
1017 SELECT vid,{?} FROM virtual WHERE alias={?}",
1018 $user->forlifeEmail(), $ml);
1019 $page->trigSuccess("{$user->fullName()} a été abonné à $ml.");
1020 } else {
1021 XDB::query("DELETE FROM virtual_redirect
1022 USING virtual_redirect
1023 INNER JOIN virtual USING(vid)
1024 WHERE redirect={?} AND alias={?}",
1025 $from_email, $ml);
1026 $page->trigSuccess("{$user->fullName()} a été désabonné de $ml.");
1027 }
1028 }
1029 }
1030
1031 $page->addJsLink('password.js');
1032 $page->assign('onlyGroup', $user->hasSingleGroup());
1033 $page->assign('user', $user);
1034 $page->assign('listes', $mmlist->get_lists($user->forlifeEmail()));
1035 $page->assign('alias', $user->emailAliases($globals->asso('mail_domain'), 'user', true));
1036 }
1037
1038 function handler_rss(&$page, $user = null, $hash = null)
1039 {
1040 global $globals;
1041 $page->assign('asso', $globals->asso());
1042
1043 $this->load('feed.inc.php');
1044 $feed = new XnetGrpEventFeed();
1045 return $feed->run($page, $user, $hash, false);
1046 }
1047
1048 private function upload_image(PlPage &$page, PlUpload &$upload)
1049 {
1050 if (@!$_FILES['image']['tmp_name'] && !Env::v('image_url')) {
1051 return true;
1052 }
1053 if (!$upload->upload($_FILES['image']) && !$upload->download(Env::v('image_url'))) {
1054 $page->trigError('Impossible de télécharger l\'image');
1055 return false;
1056 } elseif (!$upload->isType('image')) {
1057 $page->trigError('Le fichier n\'est pas une image valide au format JPEG, GIF ou PNG.');
1058 $upload->rm();
1059 return false;
1060 } elseif (!$upload->resizeImage(200, 300, 100, 100, 32284)) {
1061 $page->trigError('Impossible de retraiter l\'image');
1062 return false;
1063 }
1064 return true;
1065 }
1066
1067 function handler_photo_announce(&$page, $eid = null) {
1068 if ($eid) {
1069 $res = XDB::query('SELECT *
1070 FROM group_announces_photo
1071 WHERE eid = {?}', $eid);
1072 if ($res->numRows()) {
1073 $photo = $res->fetchOneAssoc();
1074 pl_cached_dynamic_content_headers("image/" . $photo['attachmime']);
1075 echo $photo['attach'];
1076 exit;
1077 }
1078 } else {
1079 $upload = new PlUpload(S::user()->login(), 'xnetannounce');
1080 if ($upload->exists() && $upload->isType('image')) {
1081 pl_cached_dynamic_content_headers($upload->contentType());
1082 echo $upload->getContents();
1083 exit;
1084 }
1085 }
1086 global $globals;
1087 pl_cached_dynamic_content_headers("image/png");
1088 echo file_get_contents($globals->spoolroot . '/htdocs/images/logo.png');
1089 exit;
1090 }
1091
1092 function handler_edit_announce(&$page, $aid = null)
1093 {
1094 global $globals, $platal;
1095 $page->changeTpl('xnetgrp/announce-edit.tpl');
1096 $page->assign('new', is_null($aid));
1097 $art = array();
1098
1099 if (Post::v('valid') == 'Visualiser' || Post::v('valid') == 'Enregistrer'
1100 || Post::v('valid') == 'Supprimer l\'image' || Post::v('valid') == 'Pas d\'image') {
1101 S::assert_xsrf_token();
1102
1103 if (!is_null($aid)) {
1104 $art['id'] = $aid;
1105 }
1106 $art['titre'] = Post::v('titre');
1107 $art['texte'] = Post::v('texte');
1108 $art['contacts'] = Post::v('contacts');
1109 $art['promo_min'] = Post::i('promo_min');
1110 $art['promo_max'] = Post::i('promo_max');
1111 $art['nom'] = S::v('nom');
1112 $art['prenom'] = S::v('prenom');
1113 $art['promo'] = S::v('promo');
1114 $art['hruid'] = S::user()->login();
1115 $art['uid'] = S::user()->id();
1116 $art['expiration'] = Post::v('expiration');
1117 $art['public'] = Post::has('public');
1118 $art['xorg'] = Post::has('xorg');
1119 $art['nl'] = Post::has('nl');
1120 $art['event'] = Post::v('event');
1121 $upload = new PlUpload(S::user()->login(), 'xnetannounce');
1122 $this->upload_image($page, $upload);
1123
1124 $art['contact_html'] = $art['contacts'];
1125 if ($art['event']) {
1126 $art['contact_html'] .= "\n{$globals->baseurl}/{$platal->ns}events/sub/{$art['event']}";
1127 }
1128
1129 if (!$art['public'] &&
1130 (($art['promo_min'] > $art['promo_max'] && $art['promo_max'] != 0) ||
1131 ($art['promo_min'] != 0 && ($art['promo_min'] <= 1900 || $art['promo_min'] >= 2020)) ||
1132 ($art['promo_max'] != 0 && ($art['promo_max'] <= 1900 || $art['promo_max'] >= 2020))))
1133 {
1134 $page->trigError("L'intervalle de promotions est invalide.");
1135 Post::kill('valid');
1136 }
1137
1138 if (!trim($art['titre']) || !trim($art['texte'])) {
1139 $page->trigError("L'article doit avoir un titre et un contenu.");
1140 Post::kill('valid');
1141 }
1142
1143 if (Post::v('valid') == 'Supprimer l\'image') {
1144 $upload->rm();
1145 Post::kill('valid');
1146 }
1147 $art['photo'] = $upload->exists() || Post::i('photo');
1148 if (Post::v('valid') == 'Pas d\'image' && !is_null($aid)) {
1149 XDB::query('DELETE FROM group_announces_photo
1150 WHERE eid = {?}', $aid);
1151 $upload->rm();
1152 Post::kill('valid');
1153 $art['photo'] = false;
1154 }
1155 }
1156
1157 if (Post::v('valid') == 'Enregistrer') {
1158 $promo_min = ($art['public'] ? 0 : $art['promo_min']);
1159 $promo_max = ($art['public'] ? 0 : $art['promo_max']);
1160 $flags = new PlFlagSet();
1161 if ($art['public']) {
1162 $flags->addFlag('public');
1163 }
1164 if ($art['photo']) {
1165 $flags->addFlag('photo');
1166 }
1167 if (is_null($aid)) {
1168 $fulltext = $art['texte'];
1169 if (!empty($art['contact_html'])) {
1170 $fulltext .= "\n\n'''Contacts :'''\\\\\n" . $art['contact_html'];
1171 }
1172 $post = null;/*
1173 if ($globals->asso('forum')) {
1174 require_once 'banana/forum.inc.php';
1175 $banana = new ForumsBanana(S::user());
1176 $post = $banana->post($globals->asso('forum'), null,
1177 $art['titre'], MiniWiki::wikiToText($fulltext, false, 0, 80));
1178 }*/
1179 XDB::query('INSERT INTO group_announces (uid, asso_id, create_date, titre, texte, contacts,
1180 expiration, promo_min, promo_max, flags, post_id)
1181 VALUES ({?}, {?}, NOW(), {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})',
1182 S::i('uid'), $globals->asso('id'), $art['titre'], $art['texte'], $art['contact_html'],
1183 $art['expiration'], $promo_min, $promo_max, $flags, $post);
1184 $aid = XDB::insertId();
1185 if ($art['photo']) {
1186 list($imgx, $imgy, $imgtype) = $upload->imageInfo();
1187 XDB::execute('INSERT INTO group_announces_photo
1188 SET eid = {?}, attachmime = {?}, x = {?}, y = {?}, attach = {?}',
1189 $aid, $imgtype, $imgx, $imgy, $upload->getContents());
1190 }
1191 if ($art['xorg']) {
1192 require_once('validations.inc.php');
1193 $article = new EvtReq("[{$globals->asso('nom')}] " . $art['titre'], $fulltext,
1194 $art['promo_min'], $art['promo_max'], $art['expiration'], "", S::user(),
1195 $upload);
1196 $article->submit();
1197 $page->trigWarning("L'affichage sur la page d'accueil de Polytechnique.org est en attente de validation.");
1198 } else if ($upload && $upload->exists()) {
1199 $upload->rm();
1200 }
1201 if ($art['nl']) {
1202 require_once('validations.inc.php');
1203 $article = new NLReq(S::user(), $globals->asso('nom') . " : " .$art['titre'],
1204 $art['texte'], $art['contact_html']);
1205 $article->submit();
1206 $page->trigWarning("La parution dans la Lettre Mensuelle est en attente de validation.");
1207 }
1208 } else {
1209 XDB::query('UPDATE group_announces
1210 SET titre = {?}, texte = {?}, contacts = {?}, expiration = {?},
1211 promo_min = {?}, promo_max = {?}, flags = {?}
1212 WHERE id = {?} AND asso_id = {?}',
1213 $art['titre'], $art['texte'], $art['contacts'], $art['expiration'],
1214 $promo_min, $promo_max, $flags,
1215 $art['id'], $globals->asso('id'));
1216 if ($art['photo'] && $upload->exists()) {
1217 list($imgx, $imgy, $imgtype) = $upload->imageInfo();
1218 XDB::execute("REPLACE INTO group_announces_photo
1219 SET eid = {?}, attachmime = {?}, x = {?}, y = {?}, attach = {?}",
1220 $aid, $imgtype, $imgx, $imgy, $upload->getContents());
1221 $upload->rm();
1222 }
1223 }
1224 }
1225 if (Post::v('valid') == 'Enregistrer' || Post::v('valid') == 'Annuler') {
1226 pl_redirect("");
1227 }
1228
1229 if (empty($art) && !is_null($aid)) {
1230 $res = XDB::query("SELECT *, FIND_IN_SET('public', flags) AS public,
1231 FIND_IN_SET('photo', flags) AS photo
1232 FROM group_announces
1233 WHERE asso_id = {?} AND id = {?}",
1234 $globals->asso('id'), $aid);
1235 if ($res->numRows()) {
1236 $art = $res->fetchOneAssoc();
1237 $art['contact_html'] = $art['contacts'];
1238 } else {
1239 $page->kill("Aucun article correspond à l'identifiant indiqué.");
1240 }
1241 }
1242
1243 if (is_null($aid)) {
1244 $events = XDB::iterator("SELECT *
1245 FROM group_events
1246 WHERE asso_id = {?} AND archive = 0",
1247 $globals->asso('id'));
1248 if ($events->total()) {
1249 $page->assign('events', $events);
1250 }
1251 }
1252
1253 $art['contact_html'] = @MiniWiki::WikiToHTML($art['contact_html']);
1254 $page->assign('art', $art);
1255 $page->assign_by_ref('upload', $upload);
1256 }
1257
1258 function handler_admin_announce(&$page)
1259 {
1260 global $globals;
1261 $page->changeTpl('xnetgrp/announce-admin.tpl');
1262
1263 if (Env::has('del')) {
1264 S::assert_xsrf_token();
1265 XDB::execute('DELETE FROM group_announces
1266 WHERE id = {?} AND asso_id = {?}',
1267 Env::i('del'), $globals->asso('id'));
1268 }
1269 $res = XDB::iterator('SELECT id, titre, expiration, expiration < CURRENT_DATE() AS perime
1270 FROM group_announces
1271 WHERE asso_id = {?}
1272 ORDER BY expiration DESC',
1273 $globals->asso('id'));
1274 $page->assign('articles', $res);
1275 }
1276 }
1277
1278 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
1279 ?>