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