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