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