Publicity restriction should be the other way around here.
[platal.git] / modules / xnetgrp.php
CommitLineData
ae7bb180 1<?php
2/***************************************************************************
5e1513f6 3 * Copyright (C) 2003-2011 Polytechnique.org *
ae7bb180 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
ef7c8560 22
ae7bb180 23class XnetGrpModule extends PLModule
24{
25 function handlers()
26 {
27 return array(
020c8ed0
SJ
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),
5ae3e9a9
SJ
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'),
50a35e87 35 '%grp/former_users' => $this->make_hook('former_users', AUTH_MDP, 'admin'),
5ae3e9a9
SJ
36 '%grp/annuaire' => $this->make_hook('annuaire', AUTH_MDP, 'groupannu'),
37 '%grp/annuaire/vcard' => $this->make_hook('vcard', AUTH_MDP, 'groupmember:groupannu'),
38 '%grp/annuaire/csv' => $this->make_hook('csv', AUTH_MDP, 'groupmember:groupannu'),
52366335 39 '%grp/directory/sync' => $this->make_hook('directory_sync', AUTH_MDP, 'groupadmin'),
c329751f 40 '%grp/directory/unact' => $this->make_hook('non_active', AUTH_MDP, 'groupadmin'),
5ae3e9a9
SJ
41 '%grp/trombi' => $this->make_hook('trombi', AUTH_MDP, 'groupannu'),
42 '%grp/geoloc' => $this->make_hook('geoloc', AUTH_MDP, 'groupannu'),
c92e5c6c 43 '%grp/subscribe' => $this->make_hook('subscribe', AUTH_MDP, 'groups'),
5ae3e9a9
SJ
44 '%grp/subscribe/valid' => $this->make_hook('subscribe_valid', AUTH_MDP, 'groupadmin'),
45 '%grp/unsubscribe' => $this->make_hook('unsubscribe', AUTH_MDP, 'groupmember'),
4e310c61 46
c92e5c6c 47 '%grp/change_rights' => $this->make_hook('change_rights', AUTH_MDP, 'groups'),
5ae3e9a9
SJ
48 '%grp/admin/annuaire' => $this->make_hook('admin_annuaire', AUTH_MDP, 'groupadmin'),
49 '%grp/member' => $this->make_hook('admin_member', AUTH_MDP, 'groupadmin'),
50 '%grp/member/new' => $this->make_hook('admin_member_new', AUTH_MDP, 'groupadmin'),
c92e5c6c 51 '%grp/member/new/ajax' => $this->make_hook('admin_member_new_ajax', AUTH_MDP, 'groups', NO_AUTH),
5ae3e9a9
SJ
52 '%grp/member/del' => $this->make_hook('admin_member_del', AUTH_MDP, 'groupadmin'),
53 '%grp/member/suggest' => $this->make_hook('admin_member_suggest', AUTH_MDP, 'groupadmin'),
b8e265bf 54
190efb3a 55 '%grp/rss' => $this->make_token_hook('rss', AUTH_PUBLIC),
5ae3e9a9
SJ
56 '%grp/announce/new' => $this->make_hook('edit_announce', AUTH_MDP, 'groupadmin'),
57 '%grp/announce/edit' => $this->make_hook('edit_announce', AUTH_MDP, 'groupadmin'),
020c8ed0 58 '%grp/announce/photo' => $this->make_hook('photo_announce', AUTH_PUBLIC),
5ae3e9a9 59 '%grp/admin/announces' => $this->make_hook('admin_announce', AUTH_MDP, 'groupadmin'),
ae7bb180 60 );
61 }
62
26ba053e 63 function handler_index($page, $arg = null)
ae7bb180 64 {
24bcf50c 65 global $globals, $platal;
2e94d2b8 66 if (!is_null($arg)) {
ae7bb180 67 return PL_NOT_FOUND;
68 }
1490093c 69 $page->changeTpl('xnetgrp/asso.tpl');
ae7bb180 70
24bcf50c 71 if (S::logged()) {
72 if (Env::has('read')) {
14bc135e
SJ
73 XDB::query('DELETE r.*
74 FROM group_announces_read AS r
75 INNER JOIN group_announces AS a ON (a.id = r.announce_id)
b58e5ac2 76 WHERE expiration < CURRENT_DATE()');
14bc135e
SJ
77 XDB::query('INSERT INTO group_announces_read
78 VALUES ({?}, {?})',
24bcf50c 79 Env::i('read'), S::i('uid'));
80 pl_redirect("");
81 }
82 if (Env::has('unread')) {
14bc135e
SJ
83 XDB::query('DELETE FROM group_announces_read
84 WHERE announce_id = {?} AND uid = {?}',
24bcf50c 85 Env::i('unread'), S::i('uid'));
86 pl_redirect("#art" . Env::i('unread'));
87 }
5a9ad4b0
SJ
88
89 /* TODO: refines this filter on promotions by using userfilter. */
90 $user = S::user();
91 if ($user->hasProfile()) {
92 $promo = XDB::format('{?}', $user->profile()->entry_year);
93 $minCondition = ' OR promo_min <= ' . $promo;
94 $maxCondition = ' OR promo_max >= ' . $promo;
95 } else {
96 $minCondition = '';
97 $maxCondition = '';
98 }
99 $arts = XDB::iterator('SELECT a.*, FIND_IN_SET(\'photo\', a.flags) AS photo
14bc135e
SJ
100 FROM group_announces AS a
101 LEFT JOIN group_announces_read AS r ON (r.uid = {?} AND r.announce_id = a.id)
b58e5ac2 102 WHERE asso_id = {?} AND expiration >= CURRENT_DATE()
5a9ad4b0
SJ
103 AND (promo_min = 0' . $minCondition . ')
104 AND (promo_max = 0' . $maxCondition . ')
5660032a 105 AND r.announce_id IS NULL
5a9ad4b0
SJ
106 ORDER BY a.expiration',
107 S::i('uid'), $globals->asso('id'));
108 $index = XDB::iterator('SELECT a.id, a.titre, r.uid IS NULL AS nonlu
14bc135e
SJ
109 FROM group_announces AS a
110 LEFT JOIN group_announces_read AS r ON (a.id = r.announce_id AND r.uid = {?})
b58e5ac2 111 WHERE asso_id = {?} AND expiration >= CURRENT_DATE()
5a9ad4b0
SJ
112 AND (promo_min = 0' . $minCondition . ')
113 AND (promo_max = 0' . $maxCondition . ')
114 ORDER BY a.expiration',
115 S::i('uid'), $globals->asso('id'));
24bcf50c 116 $page->assign('article_index', $index);
117 } else {
14bc135e
SJ
118 $arts = XDB::iterator("SELECT *, FIND_IN_SET('photo', flags) AS photo
119 FROM group_announces
b58e5ac2 120 WHERE asso_id = {?} AND expiration >= CURRENT_DATE()
14bc135e 121 AND FIND_IN_SET('public', flags)",
24bcf50c 122 $globals->asso('id'));
123 }
4af7fd22
FB
124 if (may_update()) {
125 $subs_valid = XDB::query("SELECT uid
eb41eda9 126 FROM group_member_sub_requests
4af7fd22
FB
127 WHERE asso_id = {?}",
128 $globals->asso('id'));
129 $page->assign('requests', $subs_valid->numRows());
130 }
24bcf50c 131
84fc72ff 132 if (!S::hasAuthToken()) {
24bcf50c 133 $page->setRssLink("Polytechnique.net :: {$globals->asso("nom")} :: News publiques",
5700a250 134 $platal->ns . "rss/rss.xml");
24bcf50c 135 } else {
136 $page->setRssLink("Polytechnique.net :: {$globals->asso("nom")} :: News",
2ab3486b 137 $platal->ns . 'rss/' . S::v('hruid') . '/' . S::user()->token . '/rss.xml');
24bcf50c 138 }
eaf30d86 139
24bcf50c 140 $page->assign('articles', $arts);
ae7bb180 141 }
dd798f38 142
26ba053e 143 function handler_logo($page)
dd798f38 144 {
145 global $globals;
833a6e86 146 $globals->asso()->getLogo()->send();
dd798f38 147 }
2e94d2b8 148
26ba053e 149 function handler_site($page)
d430f4d8 150 {
151 global $globals;
152 $site = $globals->asso('site');
153 if (!$site) {
a7d35093 154 $page->trigError('Le groupe n\'a pas de site web.');
d430f4d8 155 return $this->handler_index($page);
156 }
02838718 157 http_redirect($site);
d430f4d8 158 exit;
159 }
160
26ba053e 161 function handler_edit($page)
2e94d2b8 162 {
163 global $globals;
1490093c 164 $page->changeTpl('xnetgrp/edit.tpl');
2e94d2b8 165
40d428d8
VZ
166 if (Post::has('submit')) {
167 S::assert_xsrf_token();
168
113f6de8 169 $flags = new PlFlagSet('wiki_desc');
a6761ca9
FB
170 $flags->addFlag('notif_unsub', Post::i('notif_unsub') == 1);
171 $site = Post::t('site');
ffe73cf7
SJ
172 if ($site && ($site != "http://")) {
173 $scheme = parse_url($site, PHP_URL_SCHEME);
174 if (!$scheme) {
175 $site = "http://" . $site;
176 }
177 } else {
178 $site = "";
179 }
23ff6dd6 180 if (S::admin()) {
c3d959ce
SJ
181 $page->assign('super', true);
182
5e2307dc 183 if (Post::v('mail_domain') && (strstr(Post::v('mail_domain'), '.') === false)) {
6bb2f79a 184 $page->trigError('Le domaine doit être un FQDN (aucune modification effectuée)&nbsp;!!!');
c9110c6c 185 return;
2e94d2b8 186 }
c3d959ce
SJ
187 if (Post::t('nom') == '' || Post::t('diminutif') == '') {
188 $page->trigError('Ni le nom ni le diminutif du groupe ne peuvent être vide.');
189 return;
190 }
004ff79e
SJ
191 $axDate = make_datetime(Post::v('axDate'));
192 if (Post::t('axDate') != '') {
193 $axDate = make_datetime(Post::v('axDate'))->format('Y-m-d');
194 } else {
195 $axDate = null;
196 }
08cce2ff 197 XDB::execute(
eb41eda9 198 "UPDATE groups
2e94d2b8 199 SET nom={?}, diminutif={?}, cat={?}, dom={?},
200 descr={?}, site={?}, mail={?}, resp={?},
004ff79e 201 forum={?}, mail_domain={?}, ax={?}, axDate = {?}, pub={?},
794feea7 202 sub_url={?}, inscriptible={?}, unsub_url={?},
73ac0916 203 flags = {?}, welcome_msg = {?}
2e94d2b8 204 WHERE id={?}",
5e2307dc 205 Post::v('nom'), Post::v('diminutif'),
ca46cc12 206 Post::v('cat'), (Post::i('dom') == 0) ? null : Post::i('dom'),
ffe73cf7 207 Post::v('descr'), $site,
5e2307dc 208 Post::v('mail'), Post::v('resp'),
209 Post::v('forum'), Post::v('mail_domain'),
004ff79e 210 Post::has('ax'), $axDate, Post::v('pub'),
5e2307dc 211 Post::v('sub_url'), Post::v('inscriptible'),
73ac0916
SJ
212 Post::v('unsub_url'), $flags, Post::t('welcome_msg'),
213 $globals->asso('id'));
5e2307dc 214 if (Post::v('mail_domain')) {
831aa467
SJ
215 XDB::execute('INSERT IGNORE INTO email_virtual_domains (name)
216 VALUES ({?})',
217 Post::t('mail_domain'));
218 XDB::execute('UPDATE email_virtual_domains
219 SET aliasing = id
220 WHERE name = {?}',
221 Post::t('mail_domain'));
2e94d2b8 222 }
223 } else {
08cce2ff 224 XDB::execute(
eb41eda9 225 "UPDATE groups
2e94d2b8 226 SET descr={?}, site={?}, mail={?}, resp={?},
c2f19630 227 forum={?}, pub= {?}, sub_url={?},
73ac0916 228 unsub_url = {?}, flags = {?}, welcome_msg = {?}
2e94d2b8 229 WHERE id={?}",
ffe73cf7 230 Post::v('descr'), $site,
5e2307dc 231 Post::v('mail'), Post::v('resp'),
c2f19630 232 Post::v('forum'), Post::v('pub'),
30032578 233 Post::v('sub_url'), Post::v('unsub_url'),
73ac0916
SJ
234 $flags, Post::t('welcome_msg'),
235 $globals->asso('id'));
2e94d2b8 236 }
237
a174a707
SJ
238 Phone::deletePhones(0, Phone::LINK_GROUP, $globals->asso('id'));
239 $phone = new Phone(array('link_type' => 'group', 'link_id' => $globals->asso('id'), 'id' => 0,
240 'type' => 'fixed', 'display' => Post::v('phone'), 'pub' => 'public'));
241 $fax = new Phone(array('link_type' => 'group', 'link_id' => $globals->asso('id'), 'id' => 1,
242 'type' => 'fax', 'display' => Post::v('fax'), 'pub' => 'public'));
243 $phone->save();
244 $fax->save();
baab50c7
SJ
245 Address::deleteAddresses(null, Address::LINK_GROUP, null, $globals->asso('id'));
246 $address = new Address(array('groupid' => $globals->asso('id'), 'type' => Address::LINK_GROUP, 'text' => Post::v('address')));
247 $address->save();
a6761ca9 248
2e94d2b8 249 if ($_FILES['logo']['name']) {
a6761ca9
FB
250 $upload = PlUpload::get($_FILES['logo'], $globals->asso('id'), 'asso.logo', true);
251 if (!$upload) {
5660032a 252 $page->trigError("Impossible de télécharger le logo.");
a6761ca9 253 } else {
eb41eda9 254 XDB::execute('UPDATE groups
5660032a
SJ
255 SET logo = {?}, logo_mime = {?}
256 WHERE id = {?}', $upload->getContents(), $upload->contentType(),
a6761ca9
FB
257 $globals->asso('id'));
258 $upload->rm();
259 }
2e94d2b8 260 }
261
fc4714d6
SJ
262 pl_redirect('../' . Post::v('diminutif', $globals->asso('diminutif')) . '/edit');
263 }
264
265 if (S::admin()) {
266 $dom = XDB::iterator('SELECT *
267 FROM group_dom
268 ORDER BY nom');
269 $page->assign('dom', $dom);
270 $page->assign('super', true);
2e94d2b8 271 }
2e94d2b8 272 }
273
26ba053e 274 function handler_mail($page)
479d2787 275 {
276 global $globals;
277
1490093c 278 $page->changeTpl('xnetgrp/mail.tpl');
5c36f345 279 $mmlist = new MMList(S::user(), $globals->asso('mail_domain'));
9bb8bf21 280 $page->assign('listes', $mmlist->get_lists());
7912097e 281 $page->assign('user', S::user());
479d2787 282
283 if (Post::has('send')) {
e7fdf9dd 284 S::assert_xsrf_token();
5e2307dc 285 $from = Post::v('from');
286 $sujet = Post::v('sujet');
287 $body = Post::v('body');
479d2787 288
5e2307dc 289 $mls = array_keys(Env::v('ml', array()));
06db561e 290 $mbr = array_keys(Env::v('membres', array()));
479d2787 291
460d8f55 292 $this->load('mail.inc.php');
c974e61c 293 set_time_limit(120);
06db561e 294 $tos = get_all_redirects($mbr, $mls, $mmlist);
eab2f6f5 295
f3df6d38 296 $upload = PlUpload::get($_FILES['uploaded'], S::user()->login(), 'xnet.emails', true);
eab2f6f5
VZ
297 if (!$upload && @$_FILES['uploaded']['name'] && PlUpload::$lastError != null) {
298 $page->trigError(PlUpload::$lastError);
299 return;
300 }
301
5b21237d 302 send_xnet_mails($from, $sujet, $body, Env::v('wiki'), $tos, Post::v('replyto'), $upload, @$_FILES['uploaded']['name']);
13627bef 303 if ($upload) {
304 $upload->rm();
305 }
6bb2f79a 306 $page->killSuccess("Email envoyé&nbsp;!");
479d2787 307 $page->assign('sent', true);
308 }
309 }
310
26ba053e 311 function handler_forum($page, $group = null, $artid = null)
4f355064 312 {
313 global $globals;
1490093c 314 $page->changeTpl('xnetgrp/forum.tpl');
4f355064 315 if (!$globals->asso('forum')) {
316 return PL_NOT_FOUND;
317 }
318 require_once 'banana/forum.inc.php';
319 $get = array();
320 get_banana_params($get, $globals->asso('forum'), $group, $artid);
321 run_banana($page, 'ForumsBanana', $get);
322 }
323
26ba053e 324 function handler_annuaire($page, $action = null, $subaction = null)
2e94d2b8 325 {
326 global $globals;
a91fb584 327
4b866888
RB
328 __autoload('userset');
329 $admins = false;
027b16e3
RB
330 if ($action == 'admins') {
331 $admins = true;
332 $action = $subaction;
a91fb584 333 }
027b16e3
RB
334 $view = new UserSet(new UFC_Group($globals->asso('id'), $admins));
335 $view->addMod('groupmember', 'Annuaire');
4b866888
RB
336 $view->addMod('trombi', 'Trombinoscope');
337 $view->apply('annuaire', $page, $action);
338 $page->assign('only_admin', $admins);
316120eb 339 $page->changeTpl('xnetgrp/annuaire.tpl');
2e94d2b8 340 }
4e310c61 341
486bc076
SJ
342 function handler_former_users($page)
343 {
344 global $globals;
345 require_once 'userset.inc.php';
346
347 $view = new UserSet(new UFC_GroupFormerMember($globals->asso('id')));
348 $view->addMod('groupmember', 'Anciens membres', true, array('noadmin' => true));
349 $view->apply('former_users', $page);
350 $page->changeTpl('xnetgrp/former_users.tpl');
351 }
352
26ba053e 353 function handler_trombi($page)
a91fb584 354 {
355 pl_redirect('annuaire/trombi');
356 }
357
26ba053e 358 function handler_geoloc($page)
28929cf0 359 {
a91fb584 360 pl_redirect('annuaire/geoloc');
28929cf0 361 }
eaf30d86 362
26ba053e 363 function handler_vcard($page, $photos = null)
5e193297 364 {
365 global $globals;
5d42c993 366 $vcard = new VCard($photos == 'photos', 'Membre du groupe ' . $globals->asso('nom'));
801adeec 367 $vcard->addProfiles($globals->asso()->getMembersFilter()->getProfiles(null, Profile::FETCH_ALL));
5d42c993 368 $vcard->show();
5e193297 369 }
370
26ba053e 371 function handler_csv($page, $filename = null)
102f4e64
FB
372 {
373 global $globals;
374 if (is_null($filename)) {
375 $filename = $globals->asso('diminutif') . '.csv';
376 }
1a074f45 377 $users = $globals->asso()->getMembersFilter(null, new UFO_Name())->getUsers();
023c46fb 378 pl_cached_content_headers('text/x-csv', 1);
102f4e64 379 $page->changeTpl('xnetgrp/annuaire-csv.tpl', NO_SKIN);
a6761ca9 380 $page->assign('users', $users);
102f4e64
FB
381 }
382
52366335
SJ
383 function handler_directory_sync($page)
384 {
385 global $globals;
386 require_once 'emails.inc.php';
387
388 $page->changeTpl('xnetgrp/sync.tpl');
389 Platal::load('lists', 'lists.inc.php');
390
391 if (Env::has('add_users')) {
392 S::assert_xsrf_token();
393
394 $users = array_keys(Env::v('add_users'));
a208363f
SJ
395 $former_users = XDB::fetchColumn('SELECT uid
396 FROM group_former_members
397 WHERE remember = TRUE AND uid IN {?}',
398 $users);
399 $new_users = array_diff($users, $former_users);
400
401 foreach ($former_users as $uid) {
402 $user = User::getSilentWithUID($uid);
403 $page->trigWarning($user->fullName() . ' est un ancien membre du groupe qui ne souhaite pas y revenir.');
404 }
405 if (count($former_users) > 1) {
406 $page->trigWarning('S\'ils souhaitent revenir dans le groupe, il faut qu\'ils en fassent la demande sur la page d\'accueil du groupe.');
407 } elseif (count($former_users)) {
408 $page->trigWarning('S\'il souhaite revenir dans le groupe, il faut qu\'il en fasse la demande sur la page d\'accueil du groupe.');
409 }
410
52366335 411 $data = array();
a208363f 412 foreach ($new_users as $uid) {
52366335
SJ
413 $data[] = XDB::format('({?}, {?})', $globals->asso('id'), $uid);
414 }
415 XDB::rawExecute('INSERT INTO group_members (asso_id, uid)
416 VALUES ' . implode(',', $data));
417 }
418
419 if (Env::has('add_nonusers')) {
420 S::assert_xsrf_token();
421
422 $nonusers = array_keys(Env::v('add_nonusers'));
423 foreach ($nonusers as $email) {
424 if ($user = User::getSilent($email) || !isvalid_email($email)) {
425 continue;
426 }
427
428 list($local_part, $domain) = explode('@', strtolower($email));
429 $hruid = User::makeHrid($local_part, $domain, 'ext');
430 if ($user = User::getSilent($hruid)) {
431 continue;
432 }
433
434 $parts = explode('.', $local_part);
435 if (count($parts) == 1) {
436 $lastname = $display_name = $full_name = $directory_name = ucfirst($local_part);
437 $firstname = '';
438 } else {
439 $firstname = ucfirst($parts[0]);
440 $lastname = ucwords(implode(' ', array_slice($parts, 1)));
441 $display_name = $firstname;
442 $full_name = $firstname . ' ' . $lastname;
443 $directory_name = strtoupper($lastname) . ' ' . $firstname;
444 }
445 XDB::execute('INSERT INTO accounts (hruid, display_name, full_name, directory_name, firstname, lastname, email, type, state)
446 VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, \'xnet\', \'disabled\')',
447 $hruid, $display_name, $full_name, $directory_name, $firstname, $lastname, $email);
448 $uid = XDB::insertId();
449 XDB::execute('INSERT INTO group_members (asso_id, uid)
450 VALUES ({?}, {?})',
451 $globals->asso('id'), $uid);
452 }
453 }
454
455 if (Env::has('add_users') || Env::has('add_nonusers')) {
456 $page->trigSuccess('Ajouts réalisés avec succès.');
457 }
458
459 $user = S::user();
460 $client = new MMList($user, $globals->asso('mail_domain'));
461 $lists = $client->get_lists();
462 $members = array();
463 foreach ($lists as $list) {
464 $details = $client->get_members($list['list']);
465 $members = array_merge($members, list_extract_members($details[1]));
466 }
467 $members = array_unique($members);
468 $uids = array();
469 $users = array();
470 $nonusers = array();
471 foreach ($members as $email) {
472 if ($user = User::getSilent($email)) {
473 $uids[] = $user->id();
474 } else {
475 $nonusers[] = $email;
476 }
477 }
478
479 $aliases = iterate_list_alias($globals->asso('mail_domain'));
480 foreach ($aliases as $alias) {
481 list($local_part, $domain) = explode('@', $alias);
482 $aliases_members = list_alias_members($local_part, $domain);
483 $users = array_merge($users, $aliases_members['users']);
484 $nonusers = array_merge($nonusers, $aliases_members['nonusers']);
485 }
486 foreach ($users as $user) {
487 $uids[] = $user->id();
488 }
489 $nonusers = array_unique($nonusers);
490 $uids = array_unique($uids);
d522f92b
SJ
491 if (count($uids)) {
492 $uids = XDB::fetchColumn('SELECT a.uid
493 FROM accounts AS a
494 WHERE a.uid IN {?} AND NOT EXISTS (SELECT *
495 FROM group_members AS g
496 WHERE a.uid = g.uid AND g.asso_id = {?})',
497 $uids, $globals->asso('id'));
498
499 $users = User::getBulkUsersWithUIDs($uids);
500 usort($users, 'User::compareDirectoryName');
501 } else {
502 $users = array();
503 }
52366335
SJ
504 sort($nonusers);
505
506 $page->assign('users', $users);
507 $page->assign('nonusers', $nonusers);
508 }
509
c329751f
SJ
510 function handler_non_active($page)
511 {
512 global $globals;
513 $page->changeTpl('xnetgrp/non_active.tpl');
514
515 $uids = XDB::fetchColumn('SELECT g.uid
516 FROM group_members AS g
517 INNER JOIN accounts AS a ON (a.uid = g.uid)
518 LEFT JOIN register_pending_xnet AS p ON (p.uid = g.uid)
519 WHERE a.uid = g.uid AND g.asso_id = {?} AND a.type = \'xnet\' AND a.state = \'disabled\' AND p.uid IS NULL',
520 $globals->asso('id'));
521 foreach ($uids as $key => $uid) {
522 if (AccountReq::isPending($uid) || BulkAccountsReq::isPending($uid)) {
523 unset($uids[$key]);
524 }
525 }
526
527 if (Post::has('enable_accounts')) {
528 S::assert_xsrf_token();
529
530 $uids_to_enable = array_intersect(array_keys(Post::v('enable_accounts')), $uids);
531
532 $user = S::user();
533 $group = Platal::globals()->asso('nom');
534 $request = new BulkAccountsReq($user, $uids_to_enable, $group);
535 $request->submit();
536 $page->trigSuccess('Un email va bientôt être envoyé aux personnes sélectionnées pour l\'activation de leur compte.');
537
538 foreach ($uids as $key => $uid) {
539 if (in_array($uid, $uids_to_enable)) {
540 unset($uids[$key]);
541 }
542 }
543 }
544
545 $users = User::getBulkUsersWithUIDs($uids);
546 $page->assign('users', $users);
547 }
548
4af7fd22
FB
549 private function removeSubscriptionRequest($uid)
550 {
551 global $globals;
eb41eda9 552 XDB::execute("DELETE FROM group_member_sub_requests
4af7fd22
FB
553 WHERE asso_id = {?} AND uid = {?}",
554 $globals->asso('id'), $uid);
555 }
556
26ba053e 557 private function validSubscription(User $user)
4af7fd22
FB
558 {
559 global $globals;
0fab5209 560 $this->removeSubscriptionRequest($user->id());
3a299a1a
SJ
561 Group::subscribe($globals->asso('id'), $user->id());
562
cac7dc37
FB
563 if (XDB::affectedRows() == 1) {
564 $mailer = new PlMailer();
565 $mailer->addTo($user->forlifeEmail());
566 $mailer->setFrom('"' . S::user()->fullName() . '" <' . S::user()->forlifeEmail() . '>');
567 $mailer->setSubject('[' . $globals->asso('nom') . '] Demande d\'inscription');
568 $message = ($user->isFemale() ? 'Chère' : 'Cher') . " Camarade,\n"
569 . "\n"
f41e70e9
SJ
570 . " Suite à ta demande d'adhésion à " . $globals->asso('nom')
571 . ", j'ai le plaisir de t'annoncer que ton inscription a été validée !\n"
73ac0916 572 . (is_null($globals->asso('welcome_msg')) ? '' : "\n" . $globals->asso('welcome_msg') . "\n")
cac7dc37
FB
573 . "\n"
574 . "Bien cordialement,\n"
575 . "-- \n"
576 . S::user()->fullName() . '.';
f41e70e9 577 $mailer->setTxtBody(wordwrap($message, 72));
cac7dc37
FB
578 $mailer->send();
579 }
4af7fd22
FB
580 }
581
26ba053e 582 function handler_subscribe($page, $u = null)
fdf0200a 583 {
c8faf82a 584 global $globals;
1490093c 585 $page->changeTpl('xnetgrp/inscrire.tpl');
fdf0200a 586
587 if (!$globals->asso('inscriptible'))
a7de4ef7 588 $page->kill("Il n'est pas possible de s'inscire en ligne à ce "
589 ."groupe. Essaie de joindre le contact indiqué "
590 ."sur la page de présentation.");
fdf0200a 591
592 if (!is_null($u) && may_update()) {
0fab5209
VZ
593 $user = User::get($u);
594 if (!$user) {
595 return PL_NOT_FOUND;
596 } else {
597 $page->assign('user', $user);
fdf0200a 598 }
0fab5209
VZ
599
600 // Retrieves the subscription status, and the reason.
601 $res = XDB::query("SELECT reason
eb41eda9 602 FROM group_member_sub_requests
0fab5209
VZ
603 WHERE asso_id = {?} AND uid = {?}",
604 $globals->asso('id'), $user->id());
605 $reason = ($res->numRows() ? $res->fetchOneCell() : null);
606
607 $res = XDB::query("SELECT COUNT(*)
eb41eda9 608 FROM group_members
0fab5209
VZ
609 WHERE asso_id = {?} AND uid = {?}",
610 $globals->asso('id'), $user->id());
611 $already_member = ($res->fetchOneCell() > 0);
612
613 // Handles the membership request.
614 if ($already_member) {
615 $this->removeSubscriptionRequest($user->id());
6bb2f79a 616 $page->kill($user->fullName() . ' est déjà membre du groupe&nbsp;!');
0fab5209
VZ
617 } elseif (Env::has('accept')) {
618 S::assert_xsrf_token();
619
620 $this->validSubscription($user);
621 pl_redirect("member/" . $user->login());
622 } elseif (Env::has('refuse')) {
623 S::assert_xsrf_token();
624
625 $this->removeSubscriptionRequest($user->id());
626 $mailer = new PlMailer();
627 $mailer->addTo($user->forlifeEmail());
628 $mailer->setFrom('"' . S::user()->fullName() . '" <' . S::user()->forlifeEmail() . '>');
629 $mailer->setSubject('['.$globals->asso('nom').'] Demande d\'inscription annulée');
630 $mailer->setTxtBody(Env::v('motif'));
631 $mailer->send();
354adb18 632 $page->killSuccess("La demande de {$user->fullName()} a bien été refusée.");
0fab5209
VZ
633 } else {
634 $page->assign('show_form', true);
635 $page->assign('reason', $reason);
636 }
637 return;
fdf0200a 638 }
639
640 if (is_member()) {
6bb2f79a 641 $page->kill("Tu es déjà membre&nbsp;!");
fdf0200a 642 return;
643 }
644
4af7fd22 645 $res = XDB::query("SELECT uid
eb41eda9 646 FROM group_member_sub_requests
4af7fd22
FB
647 WHERE uid = {?} AND asso_id = {?}",
648 S::i('uid'), $globals->asso('id'));
649 if ($res->numRows() != 0) {
650 $page->kill("Tu as déjà demandé ton inscription à ce groupe. Cette demande est actuellement en attente de validation.");
651 return;
652 }
653
fdf0200a 654 if (Post::has('inscrire')) {
e7fdf9dd
VZ
655 S::assert_xsrf_token();
656
eb41eda9 657 XDB::execute("INSERT INTO group_member_sub_requests (asso_id, uid, ts, reason)
4af7fd22
FB
658 VALUES ({?}, {?}, NOW(), {?})",
659 $globals->asso('id'), S::i('uid'), Post::v('message'));
a208363f
SJ
660 XDB::execute('DELETE FROM group_former_members
661 WHERE uid = {?} AND asso_id = {?}',
662 S::i('uid'), $globals->asso('id'));
ae775de9
SJ
663 $uf = New UserFilter(New UFC_Group($globals->asso('id'), true));
664 $admins = $uf->iterUsers();
665 $admin = $admins->next();
11d8c704 666 $to = $admin->bestEmail();
ae775de9 667 while ($admin = $admins->next()) {
11d8c704 668 $to .= ', ' . $admin->bestEmail();
ae775de9 669 }
fdf0200a 670
671 $append = "\n"
672 . "-- \n"
a7de4ef7 673 . "Ce message a été envoyé suite à la demande d'inscription de\n"
8d2853fa 674 . S::user()->fullName(true) . "\n"
fdf0200a 675 . "Via le site www.polytechnique.net. Tu peux choisir de valider ou\n"
676 . "de refuser sa demande d'inscription depuis la page :\n"
0fab5209 677 . "http://www.polytechnique.net/" . $globals->asso("diminutif") . "/subscribe/" . S::user()->login() . "\n"
fdf0200a 678 . "\n"
a7de4ef7 679 . "En cas de problème, contacter l'équipe de Polytechnique.org\n"
680 . "à l'adresse : support@polytechnique.org\n";
fdf0200a 681
682 if (!$to) {
6f2b23a4
SJ
683 $to = ($globals->asso('mail') != '') ? $globals->asso('mail') . ', ' : '';
684 $to .= 'support@polytechnique.org';
fdf0200a 685 $append = "\n-- \nLe groupe ".$globals->asso("nom")
a7de4ef7 686 ." n'a pas d'administrateur, l'équipe de"
687 ." Polytechnique.org a été prévenue et va rapidement"
688 ." résoudre ce problème.\n";
fdf0200a 689 }
690
1e33266a 691 $mailer = new PlMailer();
fdf0200a 692 $mailer->addTo($to);
0fab5209 693 $mailer->setFrom('"' . S::user()->fullName() . '" <' . S::user()->forlifeEmail() . '>');
fdf0200a 694 $mailer->setSubject('['.$globals->asso('nom').'] Demande d\'inscription');
5e2307dc 695 $mailer->setTxtBody(Post::v('message').$append);
fdf0200a 696 $mailer->send();
697 }
698 }
699
26ba053e 700 function handler_subscribe_valid($page)
4af7fd22
FB
701 {
702 global $globals;
703
704 if (Post::has('valid')) {
705 S::assert_xsrf_token();
706 $subs = Post::v('subs');
707 if (is_array($subs)) {
708 $users = array();
0fab5209 709 foreach ($subs as $hruid => $val) {
4af7fd22 710 if ($val == '1') {
0fab5209
VZ
711 $user = User::get($hruid);
712 if ($user) {
713 $this->validSubscription($user);
4af7fd22
FB
714 }
715 }
716 }
717 }
718 }
719
aa21c568 720 $it = XDB::iterator('SELECT s.uid, a.hruid, s.ts AS date
eb41eda9 721 FROM group_member_sub_requests AS s
c8d75c58 722 INNER JOIN accounts AS a ON(s.uid = a.uid)
aa21c568
FB
723 WHERE s.asso_id = {?}
724 ORDER BY s.ts', $globals->asso('id'));
4af7fd22
FB
725 $page->changeTpl('xnetgrp/subscribe-valid.tpl');
726 $page->assign('valid', $it);
727 }
728
26ba053e 729 function handler_change_rights($page)
b8e265bf 730 {
0c02607e 731 if (Env::has('right') && (may_update() || S::suid())) {
b8e265bf 732 switch (Env::v('right')) {
eaf30d86 733 case 'admin':
ab694eb5 734 Platal::session()->stopSUID();
b8e265bf 735 break;
736 case 'anim':
ab694eb5 737 Platal::session()->doSelfSuid();
b8e265bf 738 may_update(true);
739 is_member(true);
740 break;
741 case 'member':
ab694eb5 742 Platal::session()->doSelfSuid();
b8e265bf 743 may_update(false, true);
744 is_member(true);
745 break;
746 case 'logged':
ab694eb5 747 Platal::session()->doSelfSuid();
b8e265bf 748 may_update(false, true);
749 is_member(false, true);
750 break;
751 }
752 }
5603d2ce 753 http_redirect($_SERVER['HTTP_REFERER']);
b8e265bf 754 }
755
26ba053e 756 function handler_admin_annuaire($page)
4e310c61 757 {
758 global $globals;
759
460d8f55 760 $this->load('mail.inc.php');
1490093c 761 $page->changeTpl('xnetgrp/annuaire-admin.tpl');
aa21c568
FB
762 $user = S::user();
763 $mmlist = new MMList($user, $globals->asso('mail_domain'));
9bb8bf21 764 $lists = $mmlist->get_lists();
4e310c61 765 if (!$lists) $lists = array();
766 $listes = array_map(create_function('$arr', 'return $arr["list"];'), $lists);
767
768 $subscribers = array();
769
770 foreach ($listes as $list) {
9bb8bf21 771 list(,$members) = $mmlist->get_members($list);
4e310c61 772 $mails = array_map(create_function('$arr', 'return $arr[1];'), $members);
773 $subscribers = array_unique(array_merge($subscribers, $mails));
774 }
775
776 $not_in_group_x = array();
777 $not_in_group_ext = array();
778
779 foreach ($subscribers as $mail) {
c8763ca3 780 $uf = new UserFilter(new PFC_And(new UFC_Group($globals->asso('id')),
aa21c568
FB
781 new UFC_Email($mail)));
782 if ($uf->getTotalCount() == 0) {
783 if (User::isForeignEmailAddress($mail)) {
4e310c61 784 $not_in_group_ext[] = $mail;
785 } else {
786 $not_in_group_x[] = $mail;
787 }
788 }
789 }
790
791 $page->assign('not_in_group_ext', $not_in_group_ext);
792 $page->assign('not_in_group_x', $not_in_group_x);
793 $page->assign('lists', $lists);
794 }
ef7c8560 795
26ba053e 796 function handler_admin_member_new($page, $email = null)
ef7c8560 797 {
798 global $globals;
799
1490093c 800 $page->changeTpl('xnetgrp/membres-add.tpl');
ef7c8560 801
802 if (is_null($email)) {
803 return;
804 }
805
bb88d138 806 S::assert_xsrf_token();
bc6e8005 807 $suggest_account_activation = false;
bb88d138 808
41905adf
RB
809 // FS#703 : $_GET is urldecoded twice, hence
810 // + (the data) => %2B (in the url) => + (first decoding) => ' ' (second decoding)
811 // Since there can be no spaces in emails, we can fix this with :
812 $email = str_replace(' ', '+', $email);
813
33a4f3f9 814 // Finds or creates account: first cases are for users with an account.
a1642859 815 if (!User::isForeignEmailAddress($email)) {
33a4f3f9 816 // Standard account
5142a832 817 $user = User::getSilent($email);
bb88d138
PC
818 } else if (!isvalid_email($email)) {
819 // email might not be a regular email but an alias or a hruid
5142a832 820 $user = User::getSilent($email);
bb88d138
PC
821 if (!$user) {
822 // need a valid email address
33a4f3f9 823 $page->trigError('«&nbsp;<strong>' . $email . '</strong>&nbsp;» n\'est pas une adresse email valide.');
bb88d138 824 return;
ef7c8560 825 }
bb88d138 826 } else if (Env::v('x') && Env::i('userid')) {
5142a832 827 $user = User::getSilentWithUID(Env::i('userid'));
bb88d138 828 if (!$user) {
33a4f3f9 829 $page->trigError('Utilisateur invalide.');
bb88d138
PC
830 return;
831 }
33a4f3f9
SJ
832
833 // User has an account but is not yet registered.
834 if ($user->state == 'pending') {
835 // Add email in account table.
836 XDB::query('UPDATE accounts
837 SET email = {?}
838 WHERE uid = {?} AND email IS NULL',
839 Post::t('email'), $user->id());
840 // Add email for marketing if required.
841 if (Env::v('market')) {
842 $market = Marketing::get($user->uid, $email);
843 if (!$market) {
844 $market = new Marketing($user->uid, $email, 'group', $globals->asso('nom'),
845 Env::v('market_from'), S::v('uid'));
846 $market->add();
847 }
dc2073c3 848 }
bb88d138
PC
849 }
850 } else {
bc6e8005
SJ
851 // User is of type xnet. There are 3 possible cases:
852 // * the email is not known yet: we create a new account and
853 // propose to send an email to the user so he can activate
854 // his account,
855 // * the email is known but the user was not contacted in order to
856 // activate yet: we propose to send an email to the user so he
857 // can activate his account,
858 // * the email is known and the user was already contacted or has
859 // an active account: nothing to be done.
445d244c
RB
860 list($mbox, $domain) = explode('@', strtolower($email));
861 $hruid = User::makeHrid($mbox, $domain, 'ext');
33a4f3f9 862 // User might already have an account (in another group for example).
5142a832 863 $user = User::getSilent($hruid);
33a4f3f9
SJ
864
865 // If the user has no account yet, creates new account: build names from email address.
bb88d138 866 if (empty($user)) {
445d244c
RB
867 $parts = explode('.', $mbox);
868 if (count($parts) == 1) {
b7753795
SJ
869 $lastname = $display_name = $full_name = $directory_name = ucfirst($mbox);
870 $firstname = '';
445d244c
RB
871 } else {
872 $firstname = ucfirst($parts[0]);
873 $lastname = ucwords(implode(' ', array_slice($parts, 1)));
874 $display_name = $firstname;
875 $full_name = "$firstname $lastname";
876 $directory_name = strtoupper($lastname) . " " . $firstname;
877 }
b7753795 878 XDB::execute('INSERT INTO accounts (hruid, display_name, full_name, directory_name, firstname, lastname, email, type, state)
5142a832 879 VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, \'xnet\', \'disabled\')',
b7753795 880 $hruid, $display_name, $full_name, $directory_name, $firstname, $lastname, $email);
5142a832 881 $user = User::getSilent($hruid);
ef7c8560 882 }
bc6e8005 883
fb422cab 884 $suggest_account_activation = $this->suggest($user);
ef7c8560 885 }
33a4f3f9 886
bb88d138 887 if ($user) {
a208363f
SJ
888 // First check if the user used to be in this group.
889 XDB::rawExecute('DELETE FROM group_former_members
890 WHERE remember AND DATE_SUB(NOW(), INTERVAL 1 YEAR) > unsubsciption_date');
891 $former_member = XDB::fetchOneCell('SELECT remember
892 FROM group_former_members
893 WHERE uid = {?} AND asso_id = {?}',
894 $user->id(), $globals->asso('id'));
895 if ($former_member === 1) {
896 $page->trigError($user->fullName() . ' est un ancien membre du groupe qui ne souhaite pas y revenir. S\'il souhaite revenir dans le groupe, il faut qu\'il en fasse la demande sur la page d\'accueil du groupe.');
897 return;
898 } elseif (!is_null($former_member) && Post::i('force_continue') == 0) {
899 $page->trigWarning($user->fullName() . ' est un ancien membre du groupe qui s\'est récemment désinscrit. Malgré cela, si tu penses qu\'il souhaite revenir, cliquer sur « Ajouter » l\'ajoutera bien au groupe cette fois.');
900 $page->assign('force_continue', 1);
901 return;
902 }
903
904 Group::subscribe($globals->asso('id'), $user->id());
bb88d138 905 $this->removeSubscriptionRequest($user->id());
bc6e8005
SJ
906 if ($suggest_account_activation) {
907 pl_redirect('member/suggest/' . $user->login() . '/' . $email . '/' . $globals->asso('nom'));
908 } else {
909 pl_redirect('member/' . $user->login());
910 }
911 }
912 }
913
fb422cab
SJ
914 // Check if the user has a pending or active account, and thus if we should her account's activation.
915 private function suggest(PlUser $user)
916 {
917 $active = XDB::fetchOneCell('SELECT state = \'active\'
918 FROM accounts
919 WHERE uid = {?}',
920 $user->id());
921 $pending = XDB::fetchOneCell('SELECT uid
922 FROM register_pending_xnet
923 WHERE uid = {?}',
924 $user->id());
c329751f 925 $requested = AccountReq::isPending($user->id()) || BulkAccountsReq::isPending($user->id());
fb422cab
SJ
926
927 if ($active || $pending || $requested) {
928 return false;
929 }
930 return true;
931 }
932
bc6e8005
SJ
933 function handler_admin_member_suggest($page, $hruid, $email)
934 {
935 $page->changeTpl('xnetgrp/membres-suggest.tpl');
41905adf
RB
936
937 // FS#703 : $_GET is urldecoded twice, hence
938 // + (the data) => %2B (in the url) => + (first decoding) => ' ' (second decoding)
939 // Since there can be no spaces in emails, we can fix this with :
940 $email = str_replace(' ', '+', $email);
bc6e8005
SJ
941
942 if (Post::has('suggest')) {
943 if (Post::t('suggest') == 'yes') {
944 $user = S::user();
98d858e5 945 $request = new AccountReq($user, $hruid, $email, Platal::globals()->asso('nom'));
bc6e8005
SJ
946 $request->submit();
947 $page->trigSuccessRedirect('Un email va bien être envoyé à ' . $email . ' pour l\'activation de son compte.',
98d858e5 948 Platal::globals()->asso('diminutif') . '/member/' . $hruid);
bc6e8005
SJ
949 } else {
950 pl_redirect('member/' . $hruid);
951 }
bb88d138 952 }
bc6e8005
SJ
953 $page->assign('email', $email);
954 $page->assign('hruid', $hruid);
ef7c8560 955 }
956
26ba053e 957 function handler_admin_member_new_ajax($page)
dc2073c3 958 {
3cb500d5 959 pl_content_headers("text/html");
8b1f8e12 960 $page->changeTpl('xnetgrp/membres-new-search.tpl', NO_SKIN);
aa21c568 961 $users = array();
0baf0741 962 if (Env::has('login')) {
aa21c568
FB
963 $user = User::getSilent(Env::t('login'));
964 if ($user && $user->state != 'pending') {
965 $users = array($user);
966 }
e2b0a45c 967 }
aa21c568 968 if (empty($users)) {
33a4f3f9 969 list($lastname, $firstname) = str_replace(array('-', ' ', "'"), '%', array(Env::t('nom'), Env::t('prenom')));
c8763ca3 970 $cond = new PFC_And(new PFC_Not(new UFC_Registered()));
33a4f3f9 971 if (!empty($lastname)) {
3731beb2 972 $cond->addChild(new UFC_NameTokens($lastname, array(), false, false, Profile::LASTNAME));
0baf0741 973 }
33a4f3f9 974 if (!empty($firstname)) {
3731beb2 975 $cond->addChild(new UFC_NameTokens($firstname, array(), false, false, Profile::FIRSTNAME));
0baf0741 976 }
33a4f3f9
SJ
977 if (Env::t('promo')) {
978 $cond->addChild(new UFC_Promo('=', UserFilter::DISPLAY, Env::t('promo')));
aa21c568
FB
979 }
980 $uf = new UserFilter($cond);
e1406965 981 $users = $uf->getUsers(new PlLimit(30));
aa21c568
FB
982 if ($uf->getTotalCount() > 30) {
983 $page->assign('too_many', true);
984 $users = array();
0baf0741 985 }
dc2073c3 986 }
aa21c568 987 $page->assign('users', $users);
dc2073c3 988 }
989
49056fe2 990 function unsubscribe(PlUser $user, $remember = false)
ef7c8560 991 {
d7610c35 992 global $globals;
49056fe2 993 Group::unsubscribe($globals->asso('id'), $user->id(), $remember);
ef7c8560 994
fa9493fe
FB
995 if ($globals->asso('notif_unsub')) {
996 $mailer = new PlMailer('xnetgrp/unsubscription-notif.mail.tpl');
57c1f1d7
SJ
997 $admins = $globals->asso()->iterAdmins();
998 while ($admin = $admins->next()) {
999 $mailer->addTo($admin);
fa9493fe
FB
1000 }
1001 $mailer->assign('group', $globals->asso('nom'));
45dcd6dd
FB
1002 $mailer->assign('user', $user);
1003 $mailer->assign('selfdone', $user->id() == S::i('uid'));
fa9493fe
FB
1004 $mailer->send();
1005 }
eca5d69f 1006
30032578 1007 $domain = $globals->asso('mail_domain');
45dcd6dd 1008 if (!$domain) {
30032578 1009 return true;
1010 }
ef7c8560 1011
dc81a0b2 1012 $mmlist = new MMList(S::user(), $domain);
45dcd6dd 1013 $listes = $mmlist->get_lists($user->forlifeEmail());
ef7c8560 1014
30032578 1015 $may_update = may_update();
1016 $warning = false;
23ba40c4
PC
1017 if (is_array($listes)) {
1018 foreach ($listes as $liste) {
1019 if ($liste['sub'] == 2) {
1020 if ($may_update) {
1021 $mmlist->mass_unsubscribe($liste['list'], Array($user->forlifeEmail()));
1022 } else {
1023 $mmlist->unsubscribe($liste['list']);
1024 }
1025 } elseif ($liste['sub']) {
1026 Platal::page()->trigWarning($user->fullName() . " a une"
1027 ." demande d'inscription en cours sur la"
1028 ." liste {$liste['list']}@ !");
1029 $warning = true;
ef7c8560 1030 }
1031 }
30032578 1032 }
ef7c8560 1033
831aa467
SJ
1034 XDB::execute('DELETE v
1035 FROM email_virtual AS v
1036 INNER JOIN email_virtual_domains AS d ON (v.domain = d.id)
1037 WHERE v.redirect = {?} AND d.name = {?}',
1038 $user->forlifeEmail(), $domain);
30032578 1039 return !$warning;
1040 }
1041
26ba053e 1042 function handler_unsubscribe($page)
30032578 1043 {
1490093c 1044 $page->changeTpl('xnetgrp/membres-del.tpl');
035de9c1 1045 $user = S::user();
cb1f5408 1046 if (empty($user)) {
30032578 1047 return PL_NOT_FOUND;
ef7c8560 1048 }
30032578 1049 $page->assign('self', true);
cb1f5408 1050 $page->assign('user', $user);
ef7c8560 1051
30032578 1052 if (!Post::has('confirm')) {
1053 return;
e7fdf9dd
VZ
1054 } else {
1055 S::assert_xsrf_token();
30032578 1056 }
1057
9a7f3d8e 1058 $hasSingleGroup = ($user->groupCount() == 1);
cb1f5408 1059
49056fe2 1060 if ($this->unsubscribe($user, Post::b('remember'))) {
cb1f5408 1061 $page->trigSuccess('Tu as été désinscrit du groupe avec succès.');
30032578 1062 } else {
cb1f5408
SJ
1063 $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.');
1064 }
8d014576
SJ
1065
1066 // If user is of type xnet account and this was her last group, disable the account.
1067 if ($user->type == 'xnet' && $hasSingleGroup) {
1068 $user->clear(true);
30032578 1069 }
c1863ee9 1070 $page->assign('is_member', is_member(true));
30032578 1071 }
1072
26ba053e 1073 function handler_admin_member_del($page, $user = null)
30032578 1074 {
1490093c 1075 $page->changeTpl('xnetgrp/membres-del.tpl');
45dcd6dd 1076 $user = User::getSilent($user);
30032578 1077 if (empty($user)) {
1078 return PL_NOT_FOUND;
1079 }
4a648e80
SJ
1080
1081 global $globals;
1082
1083 if (!$user->inGroup($globals->asso('id'))) {
1084 pl_redirect('annuaire');
1085 }
1086
cb1f5408 1087 $page->assign('self', false);
30032578 1088 $page->assign('user', $user);
1089
1090 if (!Post::has('confirm')) {
1091 return;
e7fdf9dd
VZ
1092 } else {
1093 S::assert_xsrf_token();
30032578 1094 }
1095
9a7f3d8e 1096 $hasSingleGroup = ($user->groupCount() == 1);
91d2135c 1097
30032578 1098 if ($this->unsubscribe($user)) {
e46cf8c4 1099 $page->trigSuccess("{$user->fullName()} a été désinscrit du groupe&nbsp;!");
30032578 1100 } else {
e46cf8c4 1101 $page->trigWarning("{$user->fullName()} a été désinscrit du groupe, mais des erreurs subsistent&nbsp;!");
30032578 1102 }
91d2135c 1103
8d014576 1104 // If user is of type xnet account and this was her last group, disable the account.
91d2135c 1105 if ($user->type == 'xnet' && $hasSingleGroup) {
8d014576 1106 $user->clear(true);
91d2135c 1107 }
ef7c8560 1108 }
1109
2a1cd4ab 1110 private function changeLogin(PlPage $page, PlUser $user, $login)
631565e1 1111 {
33a4f3f9 1112 // Search the user's uid.
bb88d138
PC
1113 $xuser = User::getSilent($login);
1114 if (!$xuser) {
61a7d279
SJ
1115 $accounts = User::getPendingAccounts($login);
1116 if (!$accounts) {
1117 $page->trigError("L'identifiant $login ne correspond à aucun X.");
631565e1 1118 return false;
61a7d279
SJ
1119 } else if (count($accounts) > 1) {
1120 $page->trigError("L'identifiant $login correspond à plusieurs camarades.");
631565e1
FB
1121 return false;
1122 }
bb88d138 1123 $xuser = User::getSilent($accounts[0]['uid']);
631565e1
FB
1124 }
1125
bb88d138
PC
1126 if (!$xuser) {
1127 return false;
631565e1
FB
1128 }
1129
33a4f3f9
SJ
1130 if ($user->mergeIn($xuser)) {
1131 return $xuser->login();
1132 }
1133 return $user->login();
631565e1
FB
1134 }
1135
26ba053e 1136 function handler_admin_member($page, $user)
ef7c8560 1137 {
1138 global $globals;
1139
45dcd6dd 1140 $user = User::getSilent($user);
ef7c8560 1141 if (empty($user)) {
1142 return PL_NOT_FOUND;
1143 }
1144
7ae5c545
SJ
1145 if (!$user->inGroup($globals->asso('id'))) {
1146 pl_redirect('annuaire');
1147 }
1148
1149 $page->changeTpl('xnetgrp/membres-edit.tpl');
1150
dc81a0b2 1151 $mmlist = new MMList(S::user(), $globals->asso('mail_domain'));
ef7c8560 1152
1153 if (Post::has('change')) {
ca6980dc 1154 require_once 'emails.inc.php';
e7fdf9dd
VZ
1155 S::assert_xsrf_token();
1156
631565e1 1157 // Convert user status to X
bb88d138 1158 if (!Post::blank('login_X')) {
bb94f7b6 1159 $forlife = $this->changeLogin($page, $user, Post::t('login_X'));
631565e1
FB
1160 if ($forlife) {
1161 pl_redirect('member/' . $forlife);
1162 }
1163 }
1164
1165 // Update user info
1d6870e1 1166 if ($user->type == 'virtual' || ($user->type == 'xnet' && !$user->perms)) {
b7753795
SJ
1167 $lastname = Post::s('lastname');
1168 if (Post::s('type') != 'virtual') {
1169 $firstname = Post::s('firstname');
1170 $full_name = $firstname . ' ' . $lastname;
1171 $directory_name = mb_strtoupper($lastname) . ' ' . $firstname;
1172 } else {
1173 $firstname = '';
1174 $full_name = $lastname;
1175 $directory_name = mb_strtoupper($lastname);
1176 }
bb88d138 1177 XDB::query('UPDATE accounts
33a4f3f9 1178 SET full_name = {?}, directory_name = {?}, display_name = {?},
b7753795 1179 firstname = {?}, lastname = {?}, sex = {?}, email = {?}, type = {?}
bb88d138 1180 WHERE uid = {?}',
b7753795 1181 $full_name, $directory_name, Post::t('display_name'), $firstname, $lastname,
33a4f3f9
SJ
1182 (Post::t('sex') == 'male') ? 'male' : 'female', Post::t('email'),
1183 (Post::t('type') == 'xnet') ? 'xnet' : 'virtual', $user->id());
b3b00d58 1184 } else if (!$user->perms && Post::has('email') && require_email_update($user, Post::t('email'))) {
33a4f3f9
SJ
1185 XDB::query('UPDATE accounts
1186 SET email = {?}
1187 WHERE uid = {?}',
1188 Post::t('email'), $user->id());
b3b00d58
SJ
1189 $listClient = new MMList(S::user());
1190 $listClient->change_user_email($user->forlifeEmail(), Post::t('email'));
1191 update_alias_user($user->forlifeEmail(), Post::t('email'));
ca6980dc 1192 }
33a4f3f9 1193 if (XDB::affectedRows()) {
94bf736e 1194 $page->trigSuccess('Données de l\'utilisateur mises à jour.');
ef7c8560 1195 }
1196
fb422cab
SJ
1197 if (($user->type == 'xnet' && !$user->perms) && Post::b('suggest')) {
1198 $request = new AccountReq(S::user(), $user->hruid, Post::t('email'), $globals->asso('nom'));
1199 $request->submit();
1200 $page->trigSuccess('Le compte va bientôt être activé.');
1201 }
1202
bb88d138
PC
1203 // Update group params for user
1204 $perms = Post::v('group_perms');
a6761ca9 1205 $comm = Post::t('comm');
33fcb12c
SJ
1206 $position = (Post::t('group_position') == '') ? null : Post::v('group_position');
1207 if ($user->group_perms != $perms || $user->group_comm != $comm || $user->group_position != $position) {
eb41eda9 1208 XDB::query('UPDATE group_members
33fcb12c 1209 SET perms = {?}, comm = {?}, position = {?}
00112b2e 1210 WHERE uid = {?} AND asso_id = {?}',
33fcb12c 1211 ($perms == 'admin') ? 'admin' : 'membre', $comm, $position,
bb88d138 1212 $user->id(), $globals->asso('id'));
33a4f3f9
SJ
1213 if (XDB::affectedRows()) {
1214 if ($perms != $user->group_perms) {
1215 $page->trigSuccess('Permissions modifiées&nbsp;!');
1216 }
1217 if ($comm != $user->group_comm) {
1218 $page->trigSuccess('Commentaire mis à jour.');
1219 }
58149849
SJ
1220 if ($position != $user->group_position) {
1221 $page->trigSuccess('Poste mis à jour.');
1222 }
54b24ba2 1223 }
ef7c8560 1224 }
1225
bb88d138
PC
1226 // Gets user info again as they might have change
1227 $user = User::getSilent($user->id());
1228
631565e1 1229 // Update ML subscriptions
5e2307dc 1230 foreach (Env::v('ml1', array()) as $ml => $state) {
ef7c8560 1231 $ask = empty($_REQUEST['ml2'][$ml]) ? 0 : 2;
c4d57bd8 1232 if ($ask == $state) {
c4d57bd8 1233 continue;
1234 }
ef7c8560 1235 if ($state == '1') {
bb88d138 1236 $page->trigWarning("{$user->fullName()} a "
ef7c8560 1237 ."actuellement une demande d'inscription en "
1238 ."cours sur <strong>$ml@</strong> !!!");
1239 } elseif ($ask) {
bb88d138
PC
1240 $mmlist->mass_subscribe($ml, Array($user->forlifeEmail()));
1241 $page->trigSuccess("{$user->fullName()} a été abonné à $ml@.");
ef7c8560 1242 } else {
65fae027 1243 $mmlist->mass_unsubscribe($ml, Array($user->forlifeEmail()));
bb88d138 1244 $page->trigSuccess("{$user->fullName()} a été désabonné de $ml@.");
ef7c8560 1245 }
1246 }
1247
631565e1 1248 // Change subscriptioin to aliases
5e2307dc 1249 foreach (Env::v('ml3', array()) as $ml => $state) {
831aa467 1250 require_once 'emails.inc.php';
ef7c8560 1251 $ask = !empty($_REQUEST['ml4'][$ml]);
7e82b545 1252 list($local_part, ) = explode('@', $ml);
65fae027
SJ
1253 if ($ask == $state) {
1254 continue;
1255 }
1256 if ($ask) {
7e82b545 1257 add_to_list_alias($user->id(), $local_part, $globals->asso('mail_domain'));
bb88d138 1258 $page->trigSuccess("{$user->fullName()} a été abonné à $ml.");
ef7c8560 1259 } else {
7e82b545 1260 delete_from_list_alias($user->id(), $local_part, $globals->asso('mail_domain'));
bb88d138 1261 $page->trigSuccess("{$user->fullName()} a été désabonné de $ml.");
ef7c8560 1262 }
1263 }
bf26b317
SJ
1264
1265 if ($globals->asso('has_nl')) {
20d37dc0 1266 $nl = NewsLetter::forGroup($globals->asso('shortname'));
bf26b317
SJ
1267 // Updates group's newsletter subscription.
1268 if (Post::i('newsletter') == 1) {
e4b8520c 1269 $nl->subscribe($user);
bf26b317 1270 } else {
e4b8520c 1271 $nl->unsubscribe(null, $user->id);
bf26b317
SJ
1272 }
1273 }
ef7c8560 1274 }
1275
33fcb12c
SJ
1276 $res = XDB::rawFetchAllAssoc('SHOW COLUMNS FROM group_members LIKE \'position\'');
1277 $positions = str_replace(array('enum(', ')', '\''), '', $res[0]['Type']);
e4b8520c
RB
1278 if ($globals->asso('has_nl')) {
1279 $nl = NewsLetter::forGroup($globals->asso('shortname'));
1280 $nl_registered = $nl->subscriptionState($user);
1281 } else {
1282 $nl_registered = false;
1283 }
33fcb12c 1284
ef7c8560 1285 $page->assign('user', $user);
fb422cab 1286 $page->assign('suggest', $this->suggest($user));
a6761ca9 1287 $page->assign('listes', $mmlist->get_lists($user->forlifeEmail()));
06a548e5 1288 $page->assign('alias', $user->emailGroupAliases($globals->asso('mail_domain')));
33fcb12c 1289 $page->assign('positions', explode(',', $positions));
bf26b317 1290 $page->assign('nl_registered', $nl_registered);
ef7c8560 1291 }
24bcf50c 1292
82af3fc3 1293 function handler_rss(PlPage $page, PlUser $user)
24bcf50c 1294 {
1295 global $globals;
24bcf50c 1296 $page->assign('asso', $globals->asso());
4f18bb11 1297
460d8f55 1298 $this->load('feed.inc.php');
4f18bb11 1299 $feed = new XnetGrpEventFeed();
190efb3a 1300 return $feed->run($page, $user, false);
24bcf50c 1301 }
1302
26ba053e 1303 private function upload_image(PlPage $page, PlUpload $upload)
ff95a302
FB
1304 {
1305 if (@!$_FILES['image']['tmp_name'] && !Env::v('image_url')) {
1306 return true;
1307 }
1308 if (!$upload->upload($_FILES['image']) && !$upload->download(Env::v('image_url'))) {
a7d35093 1309 $page->trigError('Impossible de télécharger l\'image');
ff95a302
FB
1310 return false;
1311 } elseif (!$upload->isType('image')) {
a7d35093 1312 $page->trigError('Le fichier n\'est pas une image valide au format JPEG, GIF ou PNG.');
ff95a302
FB
1313 $upload->rm();
1314 return false;
a6f76d68 1315 } elseif (!$upload->resizeImage(80, 100, 100, 100, 32284)) {
a7d35093 1316 $page->trigError('Impossible de retraiter l\'image');
ff95a302
FB
1317 return false;
1318 }
1319 return true;
1320 }
1321
26ba053e 1322 function handler_photo_announce($page, $eid = null) {
ff95a302 1323 if ($eid) {
14bc135e
SJ
1324 $res = XDB::query('SELECT *
1325 FROM group_announces_photo
1326 WHERE eid = {?}', $eid);
ff95a302
FB
1327 if ($res->numRows()) {
1328 $photo = $res->fetchOneAssoc();
3cb500d5 1329 pl_cached_dynamic_content_headers("image/" . $photo['attachmime']);
ff95a302
FB
1330 echo $photo['attach'];
1331 exit;
1332 }
1333 } else {
f3df6d38 1334 $upload = new PlUpload(S::user()->login(), 'xnetannounce');
ff95a302 1335 if ($upload->exists() && $upload->isType('image')) {
3cb500d5 1336 pl_cached_dynamic_content_headers($upload->contentType());
ff95a302
FB
1337 echo $upload->getContents();
1338 exit;
1339 }
1340 }
1341 global $globals;
3cb500d5 1342 pl_cached_dynamic_content_headers("image/png");
ff95a302
FB
1343 echo file_get_contents($globals->spoolroot . '/htdocs/images/logo.png');
1344 exit;
1345 }
1346
26ba053e 1347 function handler_edit_announce($page, $aid = null)
24bcf50c 1348 {
1349 global $globals, $platal;
1490093c 1350 $page->changeTpl('xnetgrp/announce-edit.tpl');
24bcf50c 1351 $page->assign('new', is_null($aid));
1352 $art = array();
1353
ff95a302 1354 if (Post::v('valid') == 'Visualiser' || Post::v('valid') == 'Enregistrer'
2f8677c2 1355 || Post::v('valid') == 'Supprimer l\'image' || Post::v('valid') == 'Pas d\'image') {
e7fdf9dd
VZ
1356 S::assert_xsrf_token();
1357
24bcf50c 1358 if (!is_null($aid)) {
1359 $art['id'] = $aid;
1360 }
1361 $art['titre'] = Post::v('titre');
1362 $art['texte'] = Post::v('texte');
1363 $art['contacts'] = Post::v('contacts');
1364 $art['promo_min'] = Post::i('promo_min');
1365 $art['promo_max'] = Post::i('promo_max');
1366 $art['nom'] = S::v('nom');
1367 $art['prenom'] = S::v('prenom');
1368 $art['promo'] = S::v('promo');
0fab5209 1369 $art['hruid'] = S::user()->login();
79e610a9 1370 $art['uid'] = S::user()->id();
b58e5ac2 1371 $art['expiration'] = Post::v('expiration');
24bcf50c 1372 $art['public'] = Post::has('public');
1373 $art['xorg'] = Post::has('xorg');
1374 $art['nl'] = Post::has('nl');
1375 $art['event'] = Post::v('event');
f3df6d38 1376 $upload = new PlUpload(S::user()->login(), 'xnetannounce');
ff95a302 1377 $this->upload_image($page, $upload);
24bcf50c 1378
1379 $art['contact_html'] = $art['contacts'];
b9a1ba64 1380 if ($art['event']) {
1381 $art['contact_html'] .= "\n{$globals->baseurl}/{$platal->ns}events/sub/{$art['event']}";
24bcf50c 1382 }
2a557a09 1383
1384 if (!$art['public'] &&
d1c97e42 1385 (($art['promo_min'] > $art['promo_max'] && $art['promo_max'] != 0) ||
2a557a09 1386 ($art['promo_min'] != 0 && ($art['promo_min'] <= 1900 || $art['promo_min'] >= 2020)) ||
1387 ($art['promo_max'] != 0 && ($art['promo_max'] <= 1900 || $art['promo_max'] >= 2020))))
1388 {
a7d35093 1389 $page->trigError("L'intervalle de promotions est invalide.");
2a557a09 1390 Post::kill('valid');
1391 }
1970c12b 1392
1393 if (!trim($art['titre']) || !trim($art['texte'])) {
a7d35093 1394 $page->trigError("L'article doit avoir un titre et un contenu.");
1970c12b 1395 Post::kill('valid');
1396 }
ff95a302
FB
1397
1398 if (Post::v('valid') == 'Supprimer l\'image') {
1399 $upload->rm();
1400 Post::kill('valid');
1401 }
2f8677c2
FB
1402 $art['photo'] = $upload->exists() || Post::i('photo');
1403 if (Post::v('valid') == 'Pas d\'image' && !is_null($aid)) {
14bc135e
SJ
1404 XDB::query('DELETE FROM group_announces_photo
1405 WHERE eid = {?}', $aid);
2f8677c2
FB
1406 $upload->rm();
1407 Post::kill('valid');
1408 $art['photo'] = false;
1409 }
24bcf50c 1410 }
1411
1412 if (Post::v('valid') == 'Enregistrer') {
2a557a09 1413 $promo_min = ($art['public'] ? 0 : $art['promo_min']);
1414 $promo_max = ($art['public'] ? 0 : $art['promo_max']);
113f6de8 1415 $flags = new PlFlagSet();
ff95a302 1416 if ($art['public']) {
77e786e1 1417 $flags->addFlag('public');
ff95a302
FB
1418 }
1419 if ($art['photo']) {
77e786e1 1420 $flags->addFlag('photo');
ff95a302 1421 }
24bcf50c 1422 if (is_null($aid)) {
eaf30d86
PH
1423 $fulltext = $art['texte'];
1424 if (!empty($art['contact_html'])) {
1425 $fulltext .= "\n\n'''Contacts :'''\\\\\n" . $art['contact_html'];
e219710a 1426 }
91cf1bdb 1427 $post = null;
e219710a 1428 if ($globals->asso('forum')) {
1429 require_once 'banana/forum.inc.php';
e3a55098 1430 $banana = new ForumsBanana(S::user());
e219710a 1431 $post = $banana->post($globals->asso('forum'), null,
1432 $art['titre'], MiniWiki::wikiToText($fulltext, false, 0, 80));
91cf1bdb 1433 }
14bc135e 1434 XDB::query('INSERT INTO group_announces (uid, asso_id, create_date, titre, texte, contacts,
b58e5ac2 1435 expiration, promo_min, promo_max, flags, post_id)
14bc135e 1436 VALUES ({?}, {?}, NOW(), {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})',
24bcf50c 1437 S::i('uid'), $globals->asso('id'), $art['titre'], $art['texte'], $art['contact_html'],
b58e5ac2 1438 $art['expiration'], $promo_min, $promo_max, $flags, $post);
8b83a166 1439 $aid = XDB::insertId();
ff95a302
FB
1440 if ($art['photo']) {
1441 list($imgx, $imgy, $imgtype) = $upload->imageInfo();
14bc135e
SJ
1442 XDB::execute('INSERT INTO group_announces_photo
1443 SET eid = {?}, attachmime = {?}, x = {?}, y = {?}, attach = {?}',
ff95a302
FB
1444 $aid, $imgtype, $imgx, $imgy, $upload->getContents());
1445 }
24bcf50c 1446 if ($art['xorg']) {
794feea7 1447 $article = new EvtReq("[{$globals->asso('nom')}] " . $art['titre'], $fulltext,
b58e5ac2 1448 $art['promo_min'], $art['promo_max'], $art['expiration'], "", S::user(),
ff95a302 1449 $upload);
24bcf50c 1450 $article->submit();
a7d35093 1451 $page->trigWarning("L'affichage sur la page d'accueil de Polytechnique.org est en attente de validation.");
ff95a302
FB
1452 } else if ($upload && $upload->exists()) {
1453 $upload->rm();
24bcf50c 1454 }
1455 if ($art['nl']) {
5daf68f6 1456 $article = new NLReq(S::user(), $globals->asso('nom') . " : " .$art['titre'],
2a557a09 1457 $art['texte'], $art['contact_html']);
24bcf50c 1458 $article->submit();
a7d35093 1459 $page->trigWarning("La parution dans la Lettre Mensuelle est en attente de validation.");
24bcf50c 1460 }
1461 } else {
14bc135e 1462 XDB::query('UPDATE group_announces
b58e5ac2 1463 SET titre = {?}, texte = {?}, contacts = {?}, expiration = {?},
14bc135e
SJ
1464 promo_min = {?}, promo_max = {?}, flags = {?}
1465 WHERE id = {?} AND asso_id = {?}',
b58e5ac2 1466 $art['titre'], $art['texte'], $art['contacts'], $art['expiration'],
ff95a302 1467 $promo_min, $promo_max, $flags,
24bcf50c 1468 $art['id'], $globals->asso('id'));
2f8677c2
FB
1469 if ($art['photo'] && $upload->exists()) {
1470 list($imgx, $imgy, $imgtype) = $upload->imageInfo();
00ba8a74
SJ
1471 XDB::execute('INSERT INTO group_announces_photo (eid, attachmime, attach, x, y)
1472 VALUES ({?}, {?}, {?}, {?}, {?})
1473 ON DUPLICATE KEY UPDATE attachmime = VALUES(attachmime), attach = VALUES(attach), x = VALUES(x), y = VALUES(y)',
1474 $aid, $imgtype, $upload->getContents(), $imgx, $imgy);
2f8677c2
FB
1475 $upload->rm();
1476 }
24bcf50c 1477 }
2a557a09 1478 }
1479 if (Post::v('valid') == 'Enregistrer' || Post::v('valid') == 'Annuler') {
24bcf50c 1480 pl_redirect("");
eaf30d86 1481 }
24bcf50c 1482
1483 if (empty($art) && !is_null($aid)) {
14bc135e
SJ
1484 $res = XDB::query("SELECT *, FIND_IN_SET('public', flags) AS public,
1485 FIND_IN_SET('photo', flags) AS photo
1486 FROM group_announces
1487 WHERE asso_id = {?} AND id = {?}",
24bcf50c 1488 $globals->asso('id'), $aid);
1489 if ($res->numRows()) {
1490 $art = $res->fetchOneAssoc();
1491 $art['contact_html'] = $art['contacts'];
1492 } else {
567553ac 1493 $page->kill("Aucun article correspond à l'identifiant indiqué.");
24bcf50c 1494 }
1495 }
1496
24bcf50c 1497 if (is_null($aid)) {
1498 $events = XDB::iterator("SELECT *
eb41eda9 1499 FROM group_events
24bcf50c 1500 WHERE asso_id = {?} AND archive = 0",
1501 $globals->asso('id'));
1502 if ($events->total()) {
1503 $page->assign('events', $events);
1504 }
eaf30d86 1505 }
24bcf50c 1506
72b2f8bb 1507 $art['contact_html'] = @MiniWiki::WikiToHTML($art['contact_html']);
24bcf50c 1508 $page->assign('art', $art);
ff95a302 1509 $page->assign_by_ref('upload', $upload);
24bcf50c 1510 }
1511
26ba053e 1512 function handler_admin_announce($page)
24bcf50c 1513 {
1514 global $globals;
1490093c 1515 $page->changeTpl('xnetgrp/announce-admin.tpl');
24bcf50c 1516
1517 if (Env::has('del')) {
e7fdf9dd 1518 S::assert_xsrf_token();
14bc135e
SJ
1519 XDB::execute('DELETE FROM group_announces
1520 WHERE id = {?} AND asso_id = {?}',
24bcf50c 1521 Env::i('del'), $globals->asso('id'));
1522 }
b58e5ac2 1523 $res = XDB::iterator('SELECT id, titre, expiration, expiration < CURRENT_DATE() AS perime
14bc135e
SJ
1524 FROM group_announces
1525 WHERE asso_id = {?}
b58e5ac2 1526 ORDER BY expiration DESC',
24bcf50c 1527 $globals->asso('id'));
1528 $page->assign('articles', $res);
1529 }
ae7bb180 1530}
1531
a7de4ef7 1532// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
ae7bb180 1533?>