Drops former profile_name* tables.
[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'),
020c8ed0 43 '%grp/subscribe' => $this->make_hook('subscribe', AUTH_MDP),
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
020c8ed0 47 '%grp/change_rights' => $this->make_hook('change_rights', AUTH_MDP),
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'),
51 '%grp/member/new/ajax' => $this->make_hook('admin_member_new_ajax', AUTH_MDP, 'user', NO_AUTH),
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 }
184b012d 377 $users = $globals->asso()->getMembersFilter(null, new UFO_Name('directory_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"
0fab5209 674 . S::user()->fullName() . ' (X' . S::v('promo') . ")\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();
945 $group = Platal::globals()->asso('nom');
946 $request = new AccountReq($user, $hruid, $email, $group);
947 $request->submit();
948 $page->trigSuccessRedirect('Un email va bien être envoyé à ' . $email . ' pour l\'activation de son compte.',
949 $group . '/member/' . $hruid);
950 } else {
951 pl_redirect('member/' . $hruid);
952 }
bb88d138 953 }
bc6e8005
SJ
954 $page->assign('email', $email);
955 $page->assign('hruid', $hruid);
ef7c8560 956 }
957
26ba053e 958 function handler_admin_member_new_ajax($page)
dc2073c3 959 {
3cb500d5 960 pl_content_headers("text/html");
8b1f8e12 961 $page->changeTpl('xnetgrp/membres-new-search.tpl', NO_SKIN);
aa21c568 962 $users = array();
0baf0741 963 if (Env::has('login')) {
aa21c568
FB
964 $user = User::getSilent(Env::t('login'));
965 if ($user && $user->state != 'pending') {
966 $users = array($user);
967 }
e2b0a45c 968 }
aa21c568 969 if (empty($users)) {
33a4f3f9 970 list($lastname, $firstname) = str_replace(array('-', ' ', "'"), '%', array(Env::t('nom'), Env::t('prenom')));
c8763ca3 971 $cond = new PFC_And(new PFC_Not(new UFC_Registered()));
33a4f3f9
SJ
972 if (!empty($lastname)) {
973 $cond->addChild(new UFC_Name(Profile::LASTNAME, $lastname, UFC_Name::CONTAINS));
0baf0741 974 }
33a4f3f9
SJ
975 if (!empty($firstname)) {
976 $cond->addChild(new UFC_Name(Profile::FIRSTNAME, $firstname, UFC_Name::CONTAINS));
0baf0741 977 }
33a4f3f9
SJ
978 if (Env::t('promo')) {
979 $cond->addChild(new UFC_Promo('=', UserFilter::DISPLAY, Env::t('promo')));
aa21c568
FB
980 }
981 $uf = new UserFilter($cond);
e1406965 982 $users = $uf->getUsers(new PlLimit(30));
aa21c568
FB
983 if ($uf->getTotalCount() > 30) {
984 $page->assign('too_many', true);
985 $users = array();
0baf0741 986 }
dc2073c3 987 }
aa21c568 988 $page->assign('users', $users);
dc2073c3 989 }
990
49056fe2 991 function unsubscribe(PlUser $user, $remember = false)
ef7c8560 992 {
d7610c35 993 global $globals;
49056fe2 994 Group::unsubscribe($globals->asso('id'), $user->id(), $remember);
ef7c8560 995
fa9493fe
FB
996 if ($globals->asso('notif_unsub')) {
997 $mailer = new PlMailer('xnetgrp/unsubscription-notif.mail.tpl');
57c1f1d7
SJ
998 $admins = $globals->asso()->iterAdmins();
999 while ($admin = $admins->next()) {
1000 $mailer->addTo($admin);
fa9493fe
FB
1001 }
1002 $mailer->assign('group', $globals->asso('nom'));
45dcd6dd
FB
1003 $mailer->assign('user', $user);
1004 $mailer->assign('selfdone', $user->id() == S::i('uid'));
fa9493fe
FB
1005 $mailer->send();
1006 }
eca5d69f 1007
30032578 1008 $domain = $globals->asso('mail_domain');
45dcd6dd 1009 if (!$domain) {
30032578 1010 return true;
1011 }
ef7c8560 1012
dc81a0b2 1013 $mmlist = new MMList(S::user(), $domain);
45dcd6dd 1014 $listes = $mmlist->get_lists($user->forlifeEmail());
ef7c8560 1015
30032578 1016 $may_update = may_update();
1017 $warning = false;
23ba40c4
PC
1018 if (is_array($listes)) {
1019 foreach ($listes as $liste) {
1020 if ($liste['sub'] == 2) {
1021 if ($may_update) {
1022 $mmlist->mass_unsubscribe($liste['list'], Array($user->forlifeEmail()));
1023 } else {
1024 $mmlist->unsubscribe($liste['list']);
1025 }
1026 } elseif ($liste['sub']) {
1027 Platal::page()->trigWarning($user->fullName() . " a une"
1028 ." demande d'inscription en cours sur la"
1029 ." liste {$liste['list']}@ !");
1030 $warning = true;
ef7c8560 1031 }
1032 }
30032578 1033 }
ef7c8560 1034
831aa467
SJ
1035 XDB::execute('DELETE v
1036 FROM email_virtual AS v
1037 INNER JOIN email_virtual_domains AS d ON (v.domain = d.id)
1038 WHERE v.redirect = {?} AND d.name = {?}',
1039 $user->forlifeEmail(), $domain);
30032578 1040 return !$warning;
1041 }
1042
26ba053e 1043 function handler_unsubscribe($page)
30032578 1044 {
1490093c 1045 $page->changeTpl('xnetgrp/membres-del.tpl');
035de9c1 1046 $user = S::user();
cb1f5408 1047 if (empty($user)) {
30032578 1048 return PL_NOT_FOUND;
ef7c8560 1049 }
30032578 1050 $page->assign('self', true);
cb1f5408 1051 $page->assign('user', $user);
ef7c8560 1052
30032578 1053 if (!Post::has('confirm')) {
1054 return;
e7fdf9dd
VZ
1055 } else {
1056 S::assert_xsrf_token();
30032578 1057 }
1058
9a7f3d8e 1059 $hasSingleGroup = ($user->groupCount() == 1);
cb1f5408 1060
49056fe2 1061 if ($this->unsubscribe($user, Post::b('remember'))) {
cb1f5408 1062 $page->trigSuccess('Tu as été désinscrit du groupe avec succès.');
30032578 1063 } else {
cb1f5408
SJ
1064 $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.');
1065 }
8d014576
SJ
1066
1067 // If user is of type xnet account and this was her last group, disable the account.
1068 if ($user->type == 'xnet' && $hasSingleGroup) {
1069 $user->clear(true);
30032578 1070 }
c1863ee9 1071 $page->assign('is_member', is_member(true));
30032578 1072 }
1073
26ba053e 1074 function handler_admin_member_del($page, $user = null)
30032578 1075 {
1490093c 1076 $page->changeTpl('xnetgrp/membres-del.tpl');
45dcd6dd 1077 $user = User::getSilent($user);
30032578 1078 if (empty($user)) {
1079 return PL_NOT_FOUND;
1080 }
4a648e80
SJ
1081
1082 global $globals;
1083
1084 if (!$user->inGroup($globals->asso('id'))) {
1085 pl_redirect('annuaire');
1086 }
1087
cb1f5408 1088 $page->assign('self', false);
30032578 1089 $page->assign('user', $user);
1090
1091 if (!Post::has('confirm')) {
1092 return;
e7fdf9dd
VZ
1093 } else {
1094 S::assert_xsrf_token();
30032578 1095 }
1096
9a7f3d8e 1097 $hasSingleGroup = ($user->groupCount() == 1);
91d2135c 1098
30032578 1099 if ($this->unsubscribe($user)) {
e46cf8c4 1100 $page->trigSuccess("{$user->fullName()} a été désinscrit du groupe&nbsp;!");
30032578 1101 } else {
e46cf8c4 1102 $page->trigWarning("{$user->fullName()} a été désinscrit du groupe, mais des erreurs subsistent&nbsp;!");
30032578 1103 }
91d2135c 1104
8d014576 1105 // If user is of type xnet account and this was her last group, disable the account.
91d2135c 1106 if ($user->type == 'xnet' && $hasSingleGroup) {
8d014576 1107 $user->clear(true);
91d2135c 1108 }
ef7c8560 1109 }
1110
2a1cd4ab 1111 private function changeLogin(PlPage $page, PlUser $user, $login)
631565e1 1112 {
33a4f3f9 1113 // Search the user's uid.
bb88d138
PC
1114 $xuser = User::getSilent($login);
1115 if (!$xuser) {
61a7d279
SJ
1116 $accounts = User::getPendingAccounts($login);
1117 if (!$accounts) {
1118 $page->trigError("L'identifiant $login ne correspond à aucun X.");
631565e1 1119 return false;
61a7d279
SJ
1120 } else if (count($accounts) > 1) {
1121 $page->trigError("L'identifiant $login correspond à plusieurs camarades.");
631565e1
FB
1122 return false;
1123 }
bb88d138 1124 $xuser = User::getSilent($accounts[0]['uid']);
631565e1
FB
1125 }
1126
bb88d138
PC
1127 if (!$xuser) {
1128 return false;
631565e1
FB
1129 }
1130
33a4f3f9
SJ
1131 if ($user->mergeIn($xuser)) {
1132 return $xuser->login();
1133 }
1134 return $user->login();
631565e1
FB
1135 }
1136
26ba053e 1137 function handler_admin_member($page, $user)
ef7c8560 1138 {
1139 global $globals;
1140
45dcd6dd 1141 $user = User::getSilent($user);
ef7c8560 1142 if (empty($user)) {
1143 return PL_NOT_FOUND;
1144 }
1145
7ae5c545
SJ
1146 if (!$user->inGroup($globals->asso('id'))) {
1147 pl_redirect('annuaire');
1148 }
1149
1150 $page->changeTpl('xnetgrp/membres-edit.tpl');
1151
dc81a0b2 1152 $mmlist = new MMList(S::user(), $globals->asso('mail_domain'));
ef7c8560 1153
1154 if (Post::has('change')) {
ca6980dc 1155 require_once 'emails.inc.php';
e7fdf9dd
VZ
1156 S::assert_xsrf_token();
1157
631565e1 1158 // Convert user status to X
bb88d138 1159 if (!Post::blank('login_X')) {
bb94f7b6 1160 $forlife = $this->changeLogin($page, $user, Post::t('login_X'));
631565e1
FB
1161 if ($forlife) {
1162 pl_redirect('member/' . $forlife);
1163 }
1164 }
1165
1166 // Update user info
bb88d138
PC
1167 $email_changed = (!$user->profile() && strtolower($user->forlifeEmail()) != strtolower(Post::v('email')));
1168 $from_email = $user->forlifeEmail();
1d6870e1 1169 if ($user->type == 'virtual' || ($user->type == 'xnet' && !$user->perms)) {
b7753795
SJ
1170 $lastname = Post::s('lastname');
1171 if (Post::s('type') != 'virtual') {
1172 $firstname = Post::s('firstname');
1173 $full_name = $firstname . ' ' . $lastname;
1174 $directory_name = mb_strtoupper($lastname) . ' ' . $firstname;
1175 } else {
1176 $firstname = '';
1177 $full_name = $lastname;
1178 $directory_name = mb_strtoupper($lastname);
1179 }
bb88d138 1180 XDB::query('UPDATE accounts
33a4f3f9 1181 SET full_name = {?}, directory_name = {?}, display_name = {?},
b7753795 1182 firstname = {?}, lastname = {?}, sex = {?}, email = {?}, type = {?}
bb88d138 1183 WHERE uid = {?}',
b7753795 1184 $full_name, $directory_name, Post::t('display_name'), $firstname, $lastname,
33a4f3f9
SJ
1185 (Post::t('sex') == 'male') ? 'male' : 'female', Post::t('email'),
1186 (Post::t('type') == 'xnet') ? 'xnet' : 'virtual', $user->id());
1187 } else if (!$user->perms) {
1188 XDB::query('UPDATE accounts
1189 SET email = {?}
1190 WHERE uid = {?}',
1191 Post::t('email'), $user->id());
1192 }
ca6980dc
SJ
1193 if (require_email_update($user, Post::t('email'))) {
1194 $listClient = new MMList(S::user());
1195 $listClient->change_user_email($user->forlifeEmail(), Post::t('email'));
1196 update_alias_user($user->forlifeEmail(), Post::t('email'));
1197 }
33a4f3f9 1198 if (XDB::affectedRows()) {
94bf736e 1199 $page->trigSuccess('Données de l\'utilisateur mises à jour.');
ef7c8560 1200 }
1201
fb422cab
SJ
1202 if (($user->type == 'xnet' && !$user->perms) && Post::b('suggest')) {
1203 $request = new AccountReq(S::user(), $user->hruid, Post::t('email'), $globals->asso('nom'));
1204 $request->submit();
1205 $page->trigSuccess('Le compte va bientôt être activé.');
1206 }
1207
bb88d138
PC
1208 // Update group params for user
1209 $perms = Post::v('group_perms');
a6761ca9 1210 $comm = Post::t('comm');
33fcb12c
SJ
1211 $position = (Post::t('group_position') == '') ? null : Post::v('group_position');
1212 if ($user->group_perms != $perms || $user->group_comm != $comm || $user->group_position != $position) {
eb41eda9 1213 XDB::query('UPDATE group_members
33fcb12c 1214 SET perms = {?}, comm = {?}, position = {?}
00112b2e 1215 WHERE uid = {?} AND asso_id = {?}',
33fcb12c 1216 ($perms == 'admin') ? 'admin' : 'membre', $comm, $position,
bb88d138 1217 $user->id(), $globals->asso('id'));
33a4f3f9
SJ
1218 if (XDB::affectedRows()) {
1219 if ($perms != $user->group_perms) {
1220 $page->trigSuccess('Permissions modifiées&nbsp;!');
1221 }
1222 if ($comm != $user->group_comm) {
1223 $page->trigSuccess('Commentaire mis à jour.');
1224 }
58149849
SJ
1225 if ($position != $user->group_position) {
1226 $page->trigSuccess('Poste mis à jour.');
1227 }
54b24ba2 1228 }
ef7c8560 1229 }
1230
bb88d138
PC
1231 // Gets user info again as they might have change
1232 $user = User::getSilent($user->id());
1233
631565e1 1234 // Update ML subscriptions
5e2307dc 1235 foreach (Env::v('ml1', array()) as $ml => $state) {
ef7c8560 1236 $ask = empty($_REQUEST['ml2'][$ml]) ? 0 : 2;
c4d57bd8 1237 if ($ask == $state) {
06db561e 1238 if ($state && $email_changed) {
bb88d138
PC
1239 $mmlist->replace_email($ml, $from_email, $user->forlifeEmail());
1240 $page->trigSuccess("L'abonnement de {$user->fullName()} à $ml@ a été mis à jour.");
c4d57bd8 1241 }
1242 continue;
1243 }
ef7c8560 1244 if ($state == '1') {
bb88d138 1245 $page->trigWarning("{$user->fullName()} a "
ef7c8560 1246 ."actuellement une demande d'inscription en "
1247 ."cours sur <strong>$ml@</strong> !!!");
1248 } elseif ($ask) {
bb88d138
PC
1249 $mmlist->mass_subscribe($ml, Array($user->forlifeEmail()));
1250 $page->trigSuccess("{$user->fullName()} a été abonné à $ml@.");
ef7c8560 1251 } else {
c4d57bd8 1252 if ($email_changed) {
1253 $mmlist->mass_unsubscribe($ml, Array($from_email));
1254 } else {
bb88d138 1255 $mmlist->mass_unsubscribe($ml, Array($user->forlifeEmail()));
c4d57bd8 1256 }
bb88d138 1257 $page->trigSuccess("{$user->fullName()} a été désabonné de $ml@.");
ef7c8560 1258 }
1259 }
1260
631565e1 1261 // Change subscriptioin to aliases
5e2307dc 1262 foreach (Env::v('ml3', array()) as $ml => $state) {
831aa467 1263 require_once 'emails.inc.php';
ef7c8560 1264 $ask = !empty($_REQUEST['ml4'][$ml]);
7e82b545 1265 list($local_part, ) = explode('@', $ml);
bb88d138
PC
1266 if($state == $ask) {
1267 if ($state && $email_changed) {
7e82b545 1268 update_list_alias($user->id(), $from_email, $local_part, $globals->asso('mail_domain'));
bb88d138
PC
1269 $page->trigSuccess("L'abonnement de {$user->fullName()} à $ml a été mis à jour.");
1270 }
1271 } else if($ask) {
7e82b545 1272 add_to_list_alias($user->id(), $local_part, $globals->asso('mail_domain'));
bb88d138 1273 $page->trigSuccess("{$user->fullName()} a été abonné à $ml.");
ef7c8560 1274 } else {
7e82b545 1275 delete_from_list_alias($user->id(), $local_part, $globals->asso('mail_domain'));
bb88d138 1276 $page->trigSuccess("{$user->fullName()} a été désabonné de $ml.");
ef7c8560 1277 }
1278 }
bf26b317
SJ
1279
1280 if ($globals->asso('has_nl')) {
1281 // Updates group's newsletter subscription.
1282 if (Post::i('newsletter') == 1) {
1283 XDB::execute('INSERT IGNORE INTO newsletter_ins (uid, nlid)
1284 SELECT {?}, id
1285 FROM newsletters
1286 WHERE group_id = {?}',
1287 $user->id(), $globals->asso('id'));
1288 } else {
1289 XDB::execute('DELETE ni
1290 FROM newsletter_ins AS ni
1291 INNER JOIN newsletters AS n ON (n.id = ni.nlid)
1292 WHERE ni.uid = {?} AND n.group_id = {?}',
1293 $user->id(), $globals->asso('id'));
1294 }
1295 }
ef7c8560 1296 }
1297
33fcb12c
SJ
1298 $res = XDB::rawFetchAllAssoc('SHOW COLUMNS FROM group_members LIKE \'position\'');
1299 $positions = str_replace(array('enum(', ')', '\''), '', $res[0]['Type']);
bf26b317
SJ
1300 $nl_registered = XDB::fetchOneCell('SELECT COUNT(ni.uid)
1301 FROM newsletter_ins AS ni
1302 INNER JOIN newsletters AS n ON (n.id = ni.nlid)
1303 WHERE ni.uid = {?} AND n.group_id = {?}',
1304 $user->id(), $globals->asso('id'));
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?>