Merge branch 'xorg/maint' into xorg/master
[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'));
395 $data = array();
396 foreach ($users as $uid) {
397 $data[] = XDB::format('({?}, {?})', $globals->asso('id'), $uid);
398 }
399 XDB::rawExecute('INSERT INTO group_members (asso_id, uid)
400 VALUES ' . implode(',', $data));
401 }
402
403 if (Env::has('add_nonusers')) {
404 S::assert_xsrf_token();
405
406 $nonusers = array_keys(Env::v('add_nonusers'));
407 foreach ($nonusers as $email) {
408 if ($user = User::getSilent($email) || !isvalid_email($email)) {
409 continue;
410 }
411
412 list($local_part, $domain) = explode('@', strtolower($email));
413 $hruid = User::makeHrid($local_part, $domain, 'ext');
414 if ($user = User::getSilent($hruid)) {
415 continue;
416 }
417
418 $parts = explode('.', $local_part);
419 if (count($parts) == 1) {
420 $lastname = $display_name = $full_name = $directory_name = ucfirst($local_part);
421 $firstname = '';
422 } else {
423 $firstname = ucfirst($parts[0]);
424 $lastname = ucwords(implode(' ', array_slice($parts, 1)));
425 $display_name = $firstname;
426 $full_name = $firstname . ' ' . $lastname;
427 $directory_name = strtoupper($lastname) . ' ' . $firstname;
428 }
429 XDB::execute('INSERT INTO accounts (hruid, display_name, full_name, directory_name, firstname, lastname, email, type, state)
430 VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, \'xnet\', \'disabled\')',
431 $hruid, $display_name, $full_name, $directory_name, $firstname, $lastname, $email);
432 $uid = XDB::insertId();
433 XDB::execute('INSERT INTO group_members (asso_id, uid)
434 VALUES ({?}, {?})',
435 $globals->asso('id'), $uid);
436 }
437 }
438
439 if (Env::has('add_users') || Env::has('add_nonusers')) {
440 $page->trigSuccess('Ajouts réalisés avec succès.');
441 }
442
443 $user = S::user();
444 $client = new MMList($user, $globals->asso('mail_domain'));
445 $lists = $client->get_lists();
446 $members = array();
447 foreach ($lists as $list) {
448 $details = $client->get_members($list['list']);
449 $members = array_merge($members, list_extract_members($details[1]));
450 }
451 $members = array_unique($members);
452 $uids = array();
453 $users = array();
454 $nonusers = array();
455 foreach ($members as $email) {
456 if ($user = User::getSilent($email)) {
457 $uids[] = $user->id();
458 } else {
459 $nonusers[] = $email;
460 }
461 }
462
463 $aliases = iterate_list_alias($globals->asso('mail_domain'));
464 foreach ($aliases as $alias) {
465 list($local_part, $domain) = explode('@', $alias);
466 $aliases_members = list_alias_members($local_part, $domain);
467 $users = array_merge($users, $aliases_members['users']);
468 $nonusers = array_merge($nonusers, $aliases_members['nonusers']);
469 }
470 foreach ($users as $user) {
471 $uids[] = $user->id();
472 }
473 $nonusers = array_unique($nonusers);
474 $uids = array_unique($uids);
d522f92b
SJ
475 if (count($uids)) {
476 $uids = XDB::fetchColumn('SELECT a.uid
477 FROM accounts AS a
478 WHERE a.uid IN {?} AND NOT EXISTS (SELECT *
479 FROM group_members AS g
480 WHERE a.uid = g.uid AND g.asso_id = {?})',
481 $uids, $globals->asso('id'));
482
483 $users = User::getBulkUsersWithUIDs($uids);
484 usort($users, 'User::compareDirectoryName');
485 } else {
486 $users = array();
487 }
52366335
SJ
488 sort($nonusers);
489
490 $page->assign('users', $users);
491 $page->assign('nonusers', $nonusers);
492 }
493
c329751f
SJ
494 function handler_non_active($page)
495 {
496 global $globals;
497 $page->changeTpl('xnetgrp/non_active.tpl');
498
499 $uids = XDB::fetchColumn('SELECT g.uid
500 FROM group_members AS g
501 INNER JOIN accounts AS a ON (a.uid = g.uid)
502 LEFT JOIN register_pending_xnet AS p ON (p.uid = g.uid)
503 WHERE a.uid = g.uid AND g.asso_id = {?} AND a.type = \'xnet\' AND a.state = \'disabled\' AND p.uid IS NULL',
504 $globals->asso('id'));
505 foreach ($uids as $key => $uid) {
506 if (AccountReq::isPending($uid) || BulkAccountsReq::isPending($uid)) {
507 unset($uids[$key]);
508 }
509 }
510
511 if (Post::has('enable_accounts')) {
512 S::assert_xsrf_token();
513
514 $uids_to_enable = array_intersect(array_keys(Post::v('enable_accounts')), $uids);
515
516 $user = S::user();
517 $group = Platal::globals()->asso('nom');
518 $request = new BulkAccountsReq($user, $uids_to_enable, $group);
519 $request->submit();
520 $page->trigSuccess('Un email va bientôt être envoyé aux personnes sélectionnées pour l\'activation de leur compte.');
521
522 foreach ($uids as $key => $uid) {
523 if (in_array($uid, $uids_to_enable)) {
524 unset($uids[$key]);
525 }
526 }
527 }
528
529 $users = User::getBulkUsersWithUIDs($uids);
530 $page->assign('users', $users);
531 }
532
4af7fd22
FB
533 private function removeSubscriptionRequest($uid)
534 {
535 global $globals;
eb41eda9 536 XDB::execute("DELETE FROM group_member_sub_requests
4af7fd22
FB
537 WHERE asso_id = {?} AND uid = {?}",
538 $globals->asso('id'), $uid);
539 }
540
26ba053e 541 private function validSubscription(User $user)
4af7fd22
FB
542 {
543 global $globals;
0fab5209 544 $this->removeSubscriptionRequest($user->id());
3a299a1a
SJ
545 Group::subscribe($globals->asso('id'), $user->id());
546
cac7dc37
FB
547 if (XDB::affectedRows() == 1) {
548 $mailer = new PlMailer();
549 $mailer->addTo($user->forlifeEmail());
550 $mailer->setFrom('"' . S::user()->fullName() . '" <' . S::user()->forlifeEmail() . '>');
551 $mailer->setSubject('[' . $globals->asso('nom') . '] Demande d\'inscription');
552 $message = ($user->isFemale() ? 'Chère' : 'Cher') . " Camarade,\n"
553 . "\n"
f41e70e9
SJ
554 . " Suite à ta demande d'adhésion à " . $globals->asso('nom')
555 . ", j'ai le plaisir de t'annoncer que ton inscription a été validée !\n"
73ac0916 556 . (is_null($globals->asso('welcome_msg')) ? '' : "\n" . $globals->asso('welcome_msg') . "\n")
cac7dc37
FB
557 . "\n"
558 . "Bien cordialement,\n"
559 . "-- \n"
560 . S::user()->fullName() . '.';
f41e70e9 561 $mailer->setTxtBody(wordwrap($message, 72));
cac7dc37
FB
562 $mailer->send();
563 }
4af7fd22
FB
564 }
565
26ba053e 566 function handler_subscribe($page, $u = null)
fdf0200a 567 {
c8faf82a 568 global $globals;
1490093c 569 $page->changeTpl('xnetgrp/inscrire.tpl');
fdf0200a 570
571 if (!$globals->asso('inscriptible'))
a7de4ef7 572 $page->kill("Il n'est pas possible de s'inscire en ligne à ce "
573 ."groupe. Essaie de joindre le contact indiqué "
574 ."sur la page de présentation.");
fdf0200a 575
576 if (!is_null($u) && may_update()) {
0fab5209
VZ
577 $user = User::get($u);
578 if (!$user) {
579 return PL_NOT_FOUND;
580 } else {
581 $page->assign('user', $user);
fdf0200a 582 }
0fab5209
VZ
583
584 // Retrieves the subscription status, and the reason.
585 $res = XDB::query("SELECT reason
eb41eda9 586 FROM group_member_sub_requests
0fab5209
VZ
587 WHERE asso_id = {?} AND uid = {?}",
588 $globals->asso('id'), $user->id());
589 $reason = ($res->numRows() ? $res->fetchOneCell() : null);
590
591 $res = XDB::query("SELECT COUNT(*)
eb41eda9 592 FROM group_members
0fab5209
VZ
593 WHERE asso_id = {?} AND uid = {?}",
594 $globals->asso('id'), $user->id());
595 $already_member = ($res->fetchOneCell() > 0);
596
597 // Handles the membership request.
598 if ($already_member) {
599 $this->removeSubscriptionRequest($user->id());
6bb2f79a 600 $page->kill($user->fullName() . ' est déjà membre du groupe&nbsp;!');
0fab5209
VZ
601 } elseif (Env::has('accept')) {
602 S::assert_xsrf_token();
603
604 $this->validSubscription($user);
605 pl_redirect("member/" . $user->login());
606 } elseif (Env::has('refuse')) {
607 S::assert_xsrf_token();
608
609 $this->removeSubscriptionRequest($user->id());
610 $mailer = new PlMailer();
611 $mailer->addTo($user->forlifeEmail());
612 $mailer->setFrom('"' . S::user()->fullName() . '" <' . S::user()->forlifeEmail() . '>');
613 $mailer->setSubject('['.$globals->asso('nom').'] Demande d\'inscription annulée');
614 $mailer->setTxtBody(Env::v('motif'));
615 $mailer->send();
354adb18 616 $page->killSuccess("La demande de {$user->fullName()} a bien été refusée.");
0fab5209
VZ
617 } else {
618 $page->assign('show_form', true);
619 $page->assign('reason', $reason);
620 }
621 return;
fdf0200a 622 }
623
624 if (is_member()) {
6bb2f79a 625 $page->kill("Tu es déjà membre&nbsp;!");
fdf0200a 626 return;
627 }
628
4af7fd22 629 $res = XDB::query("SELECT uid
eb41eda9 630 FROM group_member_sub_requests
4af7fd22
FB
631 WHERE uid = {?} AND asso_id = {?}",
632 S::i('uid'), $globals->asso('id'));
633 if ($res->numRows() != 0) {
634 $page->kill("Tu as déjà demandé ton inscription à ce groupe. Cette demande est actuellement en attente de validation.");
635 return;
636 }
637
fdf0200a 638 if (Post::has('inscrire')) {
e7fdf9dd
VZ
639 S::assert_xsrf_token();
640
eb41eda9 641 XDB::execute("INSERT INTO group_member_sub_requests (asso_id, uid, ts, reason)
4af7fd22
FB
642 VALUES ({?}, {?}, NOW(), {?})",
643 $globals->asso('id'), S::i('uid'), Post::v('message'));
ae775de9
SJ
644 $uf = New UserFilter(New UFC_Group($globals->asso('id'), true));
645 $admins = $uf->iterUsers();
646 $admin = $admins->next();
11d8c704 647 $to = $admin->bestEmail();
ae775de9 648 while ($admin = $admins->next()) {
11d8c704 649 $to .= ', ' . $admin->bestEmail();
ae775de9 650 }
fdf0200a 651
652 $append = "\n"
653 . "-- \n"
a7de4ef7 654 . "Ce message a été envoyé suite à la demande d'inscription de\n"
0fab5209 655 . S::user()->fullName() . ' (X' . S::v('promo') . ")\n"
fdf0200a 656 . "Via le site www.polytechnique.net. Tu peux choisir de valider ou\n"
657 . "de refuser sa demande d'inscription depuis la page :\n"
0fab5209 658 . "http://www.polytechnique.net/" . $globals->asso("diminutif") . "/subscribe/" . S::user()->login() . "\n"
fdf0200a 659 . "\n"
a7de4ef7 660 . "En cas de problème, contacter l'équipe de Polytechnique.org\n"
661 . "à l'adresse : support@polytechnique.org\n";
fdf0200a 662
663 if (!$to) {
6f2b23a4
SJ
664 $to = ($globals->asso('mail') != '') ? $globals->asso('mail') . ', ' : '';
665 $to .= 'support@polytechnique.org';
fdf0200a 666 $append = "\n-- \nLe groupe ".$globals->asso("nom")
a7de4ef7 667 ." n'a pas d'administrateur, l'équipe de"
668 ." Polytechnique.org a été prévenue et va rapidement"
669 ." résoudre ce problème.\n";
fdf0200a 670 }
671
1e33266a 672 $mailer = new PlMailer();
fdf0200a 673 $mailer->addTo($to);
0fab5209 674 $mailer->setFrom('"' . S::user()->fullName() . '" <' . S::user()->forlifeEmail() . '>');
fdf0200a 675 $mailer->setSubject('['.$globals->asso('nom').'] Demande d\'inscription');
5e2307dc 676 $mailer->setTxtBody(Post::v('message').$append);
fdf0200a 677 $mailer->send();
678 }
679 }
680
26ba053e 681 function handler_subscribe_valid($page)
4af7fd22
FB
682 {
683 global $globals;
684
685 if (Post::has('valid')) {
686 S::assert_xsrf_token();
687 $subs = Post::v('subs');
688 if (is_array($subs)) {
689 $users = array();
0fab5209 690 foreach ($subs as $hruid => $val) {
4af7fd22 691 if ($val == '1') {
0fab5209
VZ
692 $user = User::get($hruid);
693 if ($user) {
694 $this->validSubscription($user);
4af7fd22
FB
695 }
696 }
697 }
698 }
699 }
700
aa21c568 701 $it = XDB::iterator('SELECT s.uid, a.hruid, s.ts AS date
eb41eda9 702 FROM group_member_sub_requests AS s
c8d75c58 703 INNER JOIN accounts AS a ON(s.uid = a.uid)
aa21c568
FB
704 WHERE s.asso_id = {?}
705 ORDER BY s.ts', $globals->asso('id'));
4af7fd22
FB
706 $page->changeTpl('xnetgrp/subscribe-valid.tpl');
707 $page->assign('valid', $it);
708 }
709
26ba053e 710 function handler_change_rights($page)
b8e265bf 711 {
0c02607e 712 if (Env::has('right') && (may_update() || S::suid())) {
b8e265bf 713 switch (Env::v('right')) {
eaf30d86 714 case 'admin':
ab694eb5 715 Platal::session()->stopSUID();
b8e265bf 716 break;
717 case 'anim':
ab694eb5 718 Platal::session()->doSelfSuid();
b8e265bf 719 may_update(true);
720 is_member(true);
721 break;
722 case 'member':
ab694eb5 723 Platal::session()->doSelfSuid();
b8e265bf 724 may_update(false, true);
725 is_member(true);
726 break;
727 case 'logged':
ab694eb5 728 Platal::session()->doSelfSuid();
b8e265bf 729 may_update(false, true);
730 is_member(false, true);
731 break;
732 }
733 }
5603d2ce 734 http_redirect($_SERVER['HTTP_REFERER']);
b8e265bf 735 }
736
26ba053e 737 function handler_admin_annuaire($page)
4e310c61 738 {
739 global $globals;
740
460d8f55 741 $this->load('mail.inc.php');
1490093c 742 $page->changeTpl('xnetgrp/annuaire-admin.tpl');
aa21c568
FB
743 $user = S::user();
744 $mmlist = new MMList($user, $globals->asso('mail_domain'));
9bb8bf21 745 $lists = $mmlist->get_lists();
4e310c61 746 if (!$lists) $lists = array();
747 $listes = array_map(create_function('$arr', 'return $arr["list"];'), $lists);
748
749 $subscribers = array();
750
751 foreach ($listes as $list) {
9bb8bf21 752 list(,$members) = $mmlist->get_members($list);
4e310c61 753 $mails = array_map(create_function('$arr', 'return $arr[1];'), $members);
754 $subscribers = array_unique(array_merge($subscribers, $mails));
755 }
756
757 $not_in_group_x = array();
758 $not_in_group_ext = array();
759
760 foreach ($subscribers as $mail) {
c8763ca3 761 $uf = new UserFilter(new PFC_And(new UFC_Group($globals->asso('id')),
aa21c568
FB
762 new UFC_Email($mail)));
763 if ($uf->getTotalCount() == 0) {
764 if (User::isForeignEmailAddress($mail)) {
4e310c61 765 $not_in_group_ext[] = $mail;
766 } else {
767 $not_in_group_x[] = $mail;
768 }
769 }
770 }
771
772 $page->assign('not_in_group_ext', $not_in_group_ext);
773 $page->assign('not_in_group_x', $not_in_group_x);
774 $page->assign('lists', $lists);
775 }
ef7c8560 776
26ba053e 777 function handler_admin_member_new($page, $email = null)
ef7c8560 778 {
779 global $globals;
780
1490093c 781 $page->changeTpl('xnetgrp/membres-add.tpl');
ef7c8560 782
783 if (is_null($email)) {
784 return;
785 }
786
bb88d138 787 S::assert_xsrf_token();
bc6e8005 788 $suggest_account_activation = false;
bb88d138 789
41905adf
RB
790 // FS#703 : $_GET is urldecoded twice, hence
791 // + (the data) => %2B (in the url) => + (first decoding) => ' ' (second decoding)
792 // Since there can be no spaces in emails, we can fix this with :
793 $email = str_replace(' ', '+', $email);
794
33a4f3f9 795 // Finds or creates account: first cases are for users with an account.
a1642859 796 if (!User::isForeignEmailAddress($email)) {
33a4f3f9 797 // Standard account
5142a832 798 $user = User::getSilent($email);
bb88d138
PC
799 } else if (!isvalid_email($email)) {
800 // email might not be a regular email but an alias or a hruid
5142a832 801 $user = User::getSilent($email);
bb88d138
PC
802 if (!$user) {
803 // need a valid email address
33a4f3f9 804 $page->trigError('«&nbsp;<strong>' . $email . '</strong>&nbsp;» n\'est pas une adresse email valide.');
bb88d138 805 return;
ef7c8560 806 }
bb88d138 807 } else if (Env::v('x') && Env::i('userid')) {
5142a832 808 $user = User::getSilentWithUID(Env::i('userid'));
bb88d138 809 if (!$user) {
33a4f3f9 810 $page->trigError('Utilisateur invalide.');
bb88d138
PC
811 return;
812 }
33a4f3f9
SJ
813
814 // User has an account but is not yet registered.
815 if ($user->state == 'pending') {
816 // Add email in account table.
817 XDB::query('UPDATE accounts
818 SET email = {?}
819 WHERE uid = {?} AND email IS NULL',
820 Post::t('email'), $user->id());
821 // Add email for marketing if required.
822 if (Env::v('market')) {
823 $market = Marketing::get($user->uid, $email);
824 if (!$market) {
825 $market = new Marketing($user->uid, $email, 'group', $globals->asso('nom'),
826 Env::v('market_from'), S::v('uid'));
827 $market->add();
828 }
dc2073c3 829 }
bb88d138
PC
830 }
831 } else {
bc6e8005
SJ
832 // User is of type xnet. There are 3 possible cases:
833 // * the email is not known yet: we create a new account and
834 // propose to send an email to the user so he can activate
835 // his account,
836 // * the email is known but the user was not contacted in order to
837 // activate yet: we propose to send an email to the user so he
838 // can activate his account,
839 // * the email is known and the user was already contacted or has
840 // an active account: nothing to be done.
445d244c
RB
841 list($mbox, $domain) = explode('@', strtolower($email));
842 $hruid = User::makeHrid($mbox, $domain, 'ext');
33a4f3f9 843 // User might already have an account (in another group for example).
5142a832 844 $user = User::getSilent($hruid);
33a4f3f9
SJ
845
846 // If the user has no account yet, creates new account: build names from email address.
bb88d138 847 if (empty($user)) {
445d244c
RB
848 $parts = explode('.', $mbox);
849 if (count($parts) == 1) {
b7753795
SJ
850 $lastname = $display_name = $full_name = $directory_name = ucfirst($mbox);
851 $firstname = '';
445d244c
RB
852 } else {
853 $firstname = ucfirst($parts[0]);
854 $lastname = ucwords(implode(' ', array_slice($parts, 1)));
855 $display_name = $firstname;
856 $full_name = "$firstname $lastname";
857 $directory_name = strtoupper($lastname) . " " . $firstname;
858 }
b7753795 859 XDB::execute('INSERT INTO accounts (hruid, display_name, full_name, directory_name, firstname, lastname, email, type, state)
5142a832 860 VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, \'xnet\', \'disabled\')',
b7753795 861 $hruid, $display_name, $full_name, $directory_name, $firstname, $lastname, $email);
5142a832 862 $user = User::getSilent($hruid);
ef7c8560 863 }
bc6e8005 864
fb422cab 865 $suggest_account_activation = $this->suggest($user);
ef7c8560 866 }
33a4f3f9 867
bb88d138 868 if ($user) {
00ba8a74
SJ
869 XDB::execute('INSERT IGNORE INTO group_members (uid, asso_id)
870 VALUES ({?}, {?})',
bb88d138
PC
871 $user->id(), $globals->asso('id'));
872 $this->removeSubscriptionRequest($user->id());
bc6e8005
SJ
873 if ($suggest_account_activation) {
874 pl_redirect('member/suggest/' . $user->login() . '/' . $email . '/' . $globals->asso('nom'));
875 } else {
876 pl_redirect('member/' . $user->login());
877 }
878 }
879 }
880
fb422cab
SJ
881 // Check if the user has a pending or active account, and thus if we should her account's activation.
882 private function suggest(PlUser $user)
883 {
884 $active = XDB::fetchOneCell('SELECT state = \'active\'
885 FROM accounts
886 WHERE uid = {?}',
887 $user->id());
888 $pending = XDB::fetchOneCell('SELECT uid
889 FROM register_pending_xnet
890 WHERE uid = {?}',
891 $user->id());
c329751f 892 $requested = AccountReq::isPending($user->id()) || BulkAccountsReq::isPending($user->id());
fb422cab
SJ
893
894 if ($active || $pending || $requested) {
895 return false;
896 }
897 return true;
898 }
899
bc6e8005
SJ
900 function handler_admin_member_suggest($page, $hruid, $email)
901 {
902 $page->changeTpl('xnetgrp/membres-suggest.tpl');
41905adf
RB
903
904 // FS#703 : $_GET is urldecoded twice, hence
905 // + (the data) => %2B (in the url) => + (first decoding) => ' ' (second decoding)
906 // Since there can be no spaces in emails, we can fix this with :
907 $email = str_replace(' ', '+', $email);
bc6e8005
SJ
908
909 if (Post::has('suggest')) {
910 if (Post::t('suggest') == 'yes') {
911 $user = S::user();
912 $group = Platal::globals()->asso('nom');
913 $request = new AccountReq($user, $hruid, $email, $group);
914 $request->submit();
915 $page->trigSuccessRedirect('Un email va bien être envoyé à ' . $email . ' pour l\'activation de son compte.',
916 $group . '/member/' . $hruid);
917 } else {
918 pl_redirect('member/' . $hruid);
919 }
bb88d138 920 }
bc6e8005
SJ
921 $page->assign('email', $email);
922 $page->assign('hruid', $hruid);
ef7c8560 923 }
924
26ba053e 925 function handler_admin_member_new_ajax($page)
dc2073c3 926 {
3cb500d5 927 pl_content_headers("text/html");
8b1f8e12 928 $page->changeTpl('xnetgrp/membres-new-search.tpl', NO_SKIN);
aa21c568 929 $users = array();
0baf0741 930 if (Env::has('login')) {
aa21c568
FB
931 $user = User::getSilent(Env::t('login'));
932 if ($user && $user->state != 'pending') {
933 $users = array($user);
934 }
e2b0a45c 935 }
aa21c568 936 if (empty($users)) {
33a4f3f9 937 list($lastname, $firstname) = str_replace(array('-', ' ', "'"), '%', array(Env::t('nom'), Env::t('prenom')));
c8763ca3 938 $cond = new PFC_And(new PFC_Not(new UFC_Registered()));
33a4f3f9
SJ
939 if (!empty($lastname)) {
940 $cond->addChild(new UFC_Name(Profile::LASTNAME, $lastname, UFC_Name::CONTAINS));
0baf0741 941 }
33a4f3f9
SJ
942 if (!empty($firstname)) {
943 $cond->addChild(new UFC_Name(Profile::FIRSTNAME, $firstname, UFC_Name::CONTAINS));
0baf0741 944 }
33a4f3f9
SJ
945 if (Env::t('promo')) {
946 $cond->addChild(new UFC_Promo('=', UserFilter::DISPLAY, Env::t('promo')));
aa21c568
FB
947 }
948 $uf = new UserFilter($cond);
e1406965 949 $users = $uf->getUsers(new PlLimit(30));
aa21c568
FB
950 if ($uf->getTotalCount() > 30) {
951 $page->assign('too_many', true);
952 $users = array();
0baf0741 953 }
dc2073c3 954 }
aa21c568 955 $page->assign('users', $users);
dc2073c3 956 }
957
26ba053e 958 function unsubscribe(PlUser $user)
ef7c8560 959 {
d7610c35 960 global $globals;
3a299a1a 961 Group::unsubscribe($globals->asso('id'), $user->id());
ef7c8560 962
fa9493fe
FB
963 if ($globals->asso('notif_unsub')) {
964 $mailer = new PlMailer('xnetgrp/unsubscription-notif.mail.tpl');
57c1f1d7
SJ
965 $admins = $globals->asso()->iterAdmins();
966 while ($admin = $admins->next()) {
967 $mailer->addTo($admin);
fa9493fe
FB
968 }
969 $mailer->assign('group', $globals->asso('nom'));
45dcd6dd
FB
970 $mailer->assign('user', $user);
971 $mailer->assign('selfdone', $user->id() == S::i('uid'));
fa9493fe
FB
972 $mailer->send();
973 }
eca5d69f 974
30032578 975 $domain = $globals->asso('mail_domain');
45dcd6dd 976 if (!$domain) {
30032578 977 return true;
978 }
ef7c8560 979
dc81a0b2 980 $mmlist = new MMList(S::user(), $domain);
45dcd6dd 981 $listes = $mmlist->get_lists($user->forlifeEmail());
ef7c8560 982
30032578 983 $may_update = may_update();
984 $warning = false;
23ba40c4
PC
985 if (is_array($listes)) {
986 foreach ($listes as $liste) {
987 if ($liste['sub'] == 2) {
988 if ($may_update) {
989 $mmlist->mass_unsubscribe($liste['list'], Array($user->forlifeEmail()));
990 } else {
991 $mmlist->unsubscribe($liste['list']);
992 }
993 } elseif ($liste['sub']) {
994 Platal::page()->trigWarning($user->fullName() . " a une"
995 ." demande d'inscription en cours sur la"
996 ." liste {$liste['list']}@ !");
997 $warning = true;
ef7c8560 998 }
999 }
30032578 1000 }
ef7c8560 1001
831aa467
SJ
1002 XDB::execute('DELETE v
1003 FROM email_virtual AS v
1004 INNER JOIN email_virtual_domains AS d ON (v.domain = d.id)
1005 WHERE v.redirect = {?} AND d.name = {?}',
1006 $user->forlifeEmail(), $domain);
30032578 1007 return !$warning;
1008 }
1009
26ba053e 1010 function handler_unsubscribe($page)
30032578 1011 {
1490093c 1012 $page->changeTpl('xnetgrp/membres-del.tpl');
035de9c1 1013 $user = S::user();
cb1f5408 1014 if (empty($user)) {
30032578 1015 return PL_NOT_FOUND;
ef7c8560 1016 }
30032578 1017 $page->assign('self', true);
cb1f5408 1018 $page->assign('user', $user);
ef7c8560 1019
30032578 1020 if (!Post::has('confirm')) {
1021 return;
e7fdf9dd
VZ
1022 } else {
1023 S::assert_xsrf_token();
30032578 1024 }
1025
9a7f3d8e 1026 $hasSingleGroup = ($user->groupCount() == 1);
cb1f5408 1027
30032578 1028 if ($this->unsubscribe($user)) {
cb1f5408 1029 $page->trigSuccess('Tu as été désinscrit du groupe avec succès.');
30032578 1030 } else {
cb1f5408
SJ
1031 $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.');
1032 }
8d014576
SJ
1033
1034 // If user is of type xnet account and this was her last group, disable the account.
1035 if ($user->type == 'xnet' && $hasSingleGroup) {
1036 $user->clear(true);
30032578 1037 }
c1863ee9 1038 $page->assign('is_member', is_member(true));
30032578 1039 }
1040
26ba053e 1041 function handler_admin_member_del($page, $user = null)
30032578 1042 {
1490093c 1043 $page->changeTpl('xnetgrp/membres-del.tpl');
45dcd6dd 1044 $user = User::getSilent($user);
30032578 1045 if (empty($user)) {
1046 return PL_NOT_FOUND;
1047 }
4a648e80
SJ
1048
1049 global $globals;
1050
1051 if (!$user->inGroup($globals->asso('id'))) {
1052 pl_redirect('annuaire');
1053 }
1054
cb1f5408 1055 $page->assign('self', false);
30032578 1056 $page->assign('user', $user);
1057
1058 if (!Post::has('confirm')) {
1059 return;
e7fdf9dd
VZ
1060 } else {
1061 S::assert_xsrf_token();
30032578 1062 }
1063
9a7f3d8e 1064 $hasSingleGroup = ($user->groupCount() == 1);
91d2135c 1065
30032578 1066 if ($this->unsubscribe($user)) {
e46cf8c4 1067 $page->trigSuccess("{$user->fullName()} a été désinscrit du groupe&nbsp;!");
30032578 1068 } else {
e46cf8c4 1069 $page->trigWarning("{$user->fullName()} a été désinscrit du groupe, mais des erreurs subsistent&nbsp;!");
30032578 1070 }
91d2135c 1071
8d014576 1072 // If user is of type xnet account and this was her last group, disable the account.
91d2135c 1073 if ($user->type == 'xnet' && $hasSingleGroup) {
8d014576 1074 $user->clear(true);
91d2135c 1075 }
ef7c8560 1076 }
1077
2a1cd4ab 1078 private function changeLogin(PlPage $page, PlUser $user, $login)
631565e1 1079 {
33a4f3f9 1080 // Search the user's uid.
bb88d138
PC
1081 $xuser = User::getSilent($login);
1082 if (!$xuser) {
61a7d279
SJ
1083 $accounts = User::getPendingAccounts($login);
1084 if (!$accounts) {
1085 $page->trigError("L'identifiant $login ne correspond à aucun X.");
631565e1 1086 return false;
61a7d279
SJ
1087 } else if (count($accounts) > 1) {
1088 $page->trigError("L'identifiant $login correspond à plusieurs camarades.");
631565e1
FB
1089 return false;
1090 }
bb88d138 1091 $xuser = User::getSilent($accounts[0]['uid']);
631565e1
FB
1092 }
1093
bb88d138
PC
1094 if (!$xuser) {
1095 return false;
631565e1
FB
1096 }
1097
33a4f3f9
SJ
1098 if ($user->mergeIn($xuser)) {
1099 return $xuser->login();
1100 }
1101 return $user->login();
631565e1
FB
1102 }
1103
26ba053e 1104 function handler_admin_member($page, $user)
ef7c8560 1105 {
1106 global $globals;
1107
45dcd6dd 1108 $user = User::getSilent($user);
ef7c8560 1109 if (empty($user)) {
1110 return PL_NOT_FOUND;
1111 }
1112
7ae5c545
SJ
1113 if (!$user->inGroup($globals->asso('id'))) {
1114 pl_redirect('annuaire');
1115 }
1116
1117 $page->changeTpl('xnetgrp/membres-edit.tpl');
1118
dc81a0b2 1119 $mmlist = new MMList(S::user(), $globals->asso('mail_domain'));
ef7c8560 1120
1121 if (Post::has('change')) {
ca6980dc 1122 require_once 'emails.inc.php';
e7fdf9dd
VZ
1123 S::assert_xsrf_token();
1124
631565e1 1125 // Convert user status to X
bb88d138 1126 if (!Post::blank('login_X')) {
bb94f7b6 1127 $forlife = $this->changeLogin($page, $user, Post::t('login_X'));
631565e1
FB
1128 if ($forlife) {
1129 pl_redirect('member/' . $forlife);
1130 }
1131 }
1132
1133 // Update user info
bb88d138
PC
1134 $email_changed = (!$user->profile() && strtolower($user->forlifeEmail()) != strtolower(Post::v('email')));
1135 $from_email = $user->forlifeEmail();
1d6870e1 1136 if ($user->type == 'virtual' || ($user->type == 'xnet' && !$user->perms)) {
b7753795
SJ
1137 $lastname = Post::s('lastname');
1138 if (Post::s('type') != 'virtual') {
1139 $firstname = Post::s('firstname');
1140 $full_name = $firstname . ' ' . $lastname;
1141 $directory_name = mb_strtoupper($lastname) . ' ' . $firstname;
1142 } else {
1143 $firstname = '';
1144 $full_name = $lastname;
1145 $directory_name = mb_strtoupper($lastname);
1146 }
bb88d138 1147 XDB::query('UPDATE accounts
33a4f3f9 1148 SET full_name = {?}, directory_name = {?}, display_name = {?},
b7753795 1149 firstname = {?}, lastname = {?}, sex = {?}, email = {?}, type = {?}
bb88d138 1150 WHERE uid = {?}',
b7753795 1151 $full_name, $directory_name, Post::t('display_name'), $firstname, $lastname,
33a4f3f9
SJ
1152 (Post::t('sex') == 'male') ? 'male' : 'female', Post::t('email'),
1153 (Post::t('type') == 'xnet') ? 'xnet' : 'virtual', $user->id());
1154 } else if (!$user->perms) {
1155 XDB::query('UPDATE accounts
1156 SET email = {?}
1157 WHERE uid = {?}',
1158 Post::t('email'), $user->id());
1159 }
ca6980dc
SJ
1160 if (require_email_update($user, Post::t('email'))) {
1161 $listClient = new MMList(S::user());
1162 $listClient->change_user_email($user->forlifeEmail(), Post::t('email'));
1163 update_alias_user($user->forlifeEmail(), Post::t('email'));
1164 }
33a4f3f9 1165 if (XDB::affectedRows()) {
94bf736e 1166 $page->trigSuccess('Données de l\'utilisateur mises à jour.');
ef7c8560 1167 }
1168
fb422cab
SJ
1169 if (($user->type == 'xnet' && !$user->perms) && Post::b('suggest')) {
1170 $request = new AccountReq(S::user(), $user->hruid, Post::t('email'), $globals->asso('nom'));
1171 $request->submit();
1172 $page->trigSuccess('Le compte va bientôt être activé.');
1173 }
1174
bb88d138
PC
1175 // Update group params for user
1176 $perms = Post::v('group_perms');
a6761ca9 1177 $comm = Post::t('comm');
33fcb12c
SJ
1178 $position = (Post::t('group_position') == '') ? null : Post::v('group_position');
1179 if ($user->group_perms != $perms || $user->group_comm != $comm || $user->group_position != $position) {
eb41eda9 1180 XDB::query('UPDATE group_members
33fcb12c 1181 SET perms = {?}, comm = {?}, position = {?}
00112b2e 1182 WHERE uid = {?} AND asso_id = {?}',
33fcb12c 1183 ($perms == 'admin') ? 'admin' : 'membre', $comm, $position,
bb88d138 1184 $user->id(), $globals->asso('id'));
33a4f3f9
SJ
1185 if (XDB::affectedRows()) {
1186 if ($perms != $user->group_perms) {
1187 $page->trigSuccess('Permissions modifiées&nbsp;!');
1188 }
1189 if ($comm != $user->group_comm) {
1190 $page->trigSuccess('Commentaire mis à jour.');
1191 }
58149849
SJ
1192 if ($position != $user->group_position) {
1193 $page->trigSuccess('Poste mis à jour.');
1194 }
54b24ba2 1195 }
ef7c8560 1196 }
1197
bb88d138
PC
1198 // Gets user info again as they might have change
1199 $user = User::getSilent($user->id());
1200
631565e1 1201 // Update ML subscriptions
5e2307dc 1202 foreach (Env::v('ml1', array()) as $ml => $state) {
ef7c8560 1203 $ask = empty($_REQUEST['ml2'][$ml]) ? 0 : 2;
c4d57bd8 1204 if ($ask == $state) {
06db561e 1205 if ($state && $email_changed) {
bb88d138
PC
1206 $mmlist->replace_email($ml, $from_email, $user->forlifeEmail());
1207 $page->trigSuccess("L'abonnement de {$user->fullName()} à $ml@ a été mis à jour.");
c4d57bd8 1208 }
1209 continue;
1210 }
ef7c8560 1211 if ($state == '1') {
bb88d138 1212 $page->trigWarning("{$user->fullName()} a "
ef7c8560 1213 ."actuellement une demande d'inscription en "
1214 ."cours sur <strong>$ml@</strong> !!!");
1215 } elseif ($ask) {
bb88d138
PC
1216 $mmlist->mass_subscribe($ml, Array($user->forlifeEmail()));
1217 $page->trigSuccess("{$user->fullName()} a été abonné à $ml@.");
ef7c8560 1218 } else {
c4d57bd8 1219 if ($email_changed) {
1220 $mmlist->mass_unsubscribe($ml, Array($from_email));
1221 } else {
bb88d138 1222 $mmlist->mass_unsubscribe($ml, Array($user->forlifeEmail()));
c4d57bd8 1223 }
bb88d138 1224 $page->trigSuccess("{$user->fullName()} a été désabonné de $ml@.");
ef7c8560 1225 }
1226 }
1227
631565e1 1228 // Change subscriptioin to aliases
5e2307dc 1229 foreach (Env::v('ml3', array()) as $ml => $state) {
831aa467 1230 require_once 'emails.inc.php';
ef7c8560 1231 $ask = !empty($_REQUEST['ml4'][$ml]);
7e82b545 1232 list($local_part, ) = explode('@', $ml);
bb88d138
PC
1233 if($state == $ask) {
1234 if ($state && $email_changed) {
7e82b545 1235 update_list_alias($user->id(), $from_email, $local_part, $globals->asso('mail_domain'));
bb88d138
PC
1236 $page->trigSuccess("L'abonnement de {$user->fullName()} à $ml a été mis à jour.");
1237 }
1238 } else if($ask) {
7e82b545 1239 add_to_list_alias($user->id(), $local_part, $globals->asso('mail_domain'));
bb88d138 1240 $page->trigSuccess("{$user->fullName()} a été abonné à $ml.");
ef7c8560 1241 } else {
7e82b545 1242 delete_from_list_alias($user->id(), $local_part, $globals->asso('mail_domain'));
bb88d138 1243 $page->trigSuccess("{$user->fullName()} a été désabonné de $ml.");
ef7c8560 1244 }
1245 }
bf26b317
SJ
1246
1247 if ($globals->asso('has_nl')) {
1248 // Updates group's newsletter subscription.
1249 if (Post::i('newsletter') == 1) {
1250 XDB::execute('INSERT IGNORE INTO newsletter_ins (uid, nlid)
1251 SELECT {?}, id
1252 FROM newsletters
1253 WHERE group_id = {?}',
1254 $user->id(), $globals->asso('id'));
1255 } else {
1256 XDB::execute('DELETE ni
1257 FROM newsletter_ins AS ni
1258 INNER JOIN newsletters AS n ON (n.id = ni.nlid)
1259 WHERE ni.uid = {?} AND n.group_id = {?}',
1260 $user->id(), $globals->asso('id'));
1261 }
1262 }
ef7c8560 1263 }
1264
33fcb12c
SJ
1265 $res = XDB::rawFetchAllAssoc('SHOW COLUMNS FROM group_members LIKE \'position\'');
1266 $positions = str_replace(array('enum(', ')', '\''), '', $res[0]['Type']);
bf26b317
SJ
1267 $nl_registered = XDB::fetchOneCell('SELECT COUNT(ni.uid)
1268 FROM newsletter_ins AS ni
1269 INNER JOIN newsletters AS n ON (n.id = ni.nlid)
1270 WHERE ni.uid = {?} AND n.group_id = {?}',
1271 $user->id(), $globals->asso('id'));
33fcb12c 1272
ef7c8560 1273 $page->assign('user', $user);
fb422cab 1274 $page->assign('suggest', $this->suggest($user));
a6761ca9 1275 $page->assign('listes', $mmlist->get_lists($user->forlifeEmail()));
06a548e5 1276 $page->assign('alias', $user->emailGroupAliases($globals->asso('mail_domain')));
33fcb12c 1277 $page->assign('positions', explode(',', $positions));
bf26b317 1278 $page->assign('nl_registered', $nl_registered);
ef7c8560 1279 }
24bcf50c 1280
82af3fc3 1281 function handler_rss(PlPage $page, PlUser $user)
24bcf50c 1282 {
1283 global $globals;
24bcf50c 1284 $page->assign('asso', $globals->asso());
4f18bb11 1285
460d8f55 1286 $this->load('feed.inc.php');
4f18bb11 1287 $feed = new XnetGrpEventFeed();
190efb3a 1288 return $feed->run($page, $user, false);
24bcf50c 1289 }
1290
26ba053e 1291 private function upload_image(PlPage $page, PlUpload $upload)
ff95a302
FB
1292 {
1293 if (@!$_FILES['image']['tmp_name'] && !Env::v('image_url')) {
1294 return true;
1295 }
1296 if (!$upload->upload($_FILES['image']) && !$upload->download(Env::v('image_url'))) {
a7d35093 1297 $page->trigError('Impossible de télécharger l\'image');
ff95a302
FB
1298 return false;
1299 } elseif (!$upload->isType('image')) {
a7d35093 1300 $page->trigError('Le fichier n\'est pas une image valide au format JPEG, GIF ou PNG.');
ff95a302
FB
1301 $upload->rm();
1302 return false;
a6f76d68 1303 } elseif (!$upload->resizeImage(80, 100, 100, 100, 32284)) {
a7d35093 1304 $page->trigError('Impossible de retraiter l\'image');
ff95a302
FB
1305 return false;
1306 }
1307 return true;
1308 }
1309
26ba053e 1310 function handler_photo_announce($page, $eid = null) {
ff95a302 1311 if ($eid) {
14bc135e
SJ
1312 $res = XDB::query('SELECT *
1313 FROM group_announces_photo
1314 WHERE eid = {?}', $eid);
ff95a302
FB
1315 if ($res->numRows()) {
1316 $photo = $res->fetchOneAssoc();
3cb500d5 1317 pl_cached_dynamic_content_headers("image/" . $photo['attachmime']);
ff95a302
FB
1318 echo $photo['attach'];
1319 exit;
1320 }
1321 } else {
f3df6d38 1322 $upload = new PlUpload(S::user()->login(), 'xnetannounce');
ff95a302 1323 if ($upload->exists() && $upload->isType('image')) {
3cb500d5 1324 pl_cached_dynamic_content_headers($upload->contentType());
ff95a302
FB
1325 echo $upload->getContents();
1326 exit;
1327 }
1328 }
1329 global $globals;
3cb500d5 1330 pl_cached_dynamic_content_headers("image/png");
ff95a302
FB
1331 echo file_get_contents($globals->spoolroot . '/htdocs/images/logo.png');
1332 exit;
1333 }
1334
26ba053e 1335 function handler_edit_announce($page, $aid = null)
24bcf50c 1336 {
1337 global $globals, $platal;
1490093c 1338 $page->changeTpl('xnetgrp/announce-edit.tpl');
24bcf50c 1339 $page->assign('new', is_null($aid));
1340 $art = array();
1341
ff95a302 1342 if (Post::v('valid') == 'Visualiser' || Post::v('valid') == 'Enregistrer'
2f8677c2 1343 || Post::v('valid') == 'Supprimer l\'image' || Post::v('valid') == 'Pas d\'image') {
e7fdf9dd
VZ
1344 S::assert_xsrf_token();
1345
24bcf50c 1346 if (!is_null($aid)) {
1347 $art['id'] = $aid;
1348 }
1349 $art['titre'] = Post::v('titre');
1350 $art['texte'] = Post::v('texte');
1351 $art['contacts'] = Post::v('contacts');
1352 $art['promo_min'] = Post::i('promo_min');
1353 $art['promo_max'] = Post::i('promo_max');
1354 $art['nom'] = S::v('nom');
1355 $art['prenom'] = S::v('prenom');
1356 $art['promo'] = S::v('promo');
0fab5209 1357 $art['hruid'] = S::user()->login();
79e610a9 1358 $art['uid'] = S::user()->id();
b58e5ac2 1359 $art['expiration'] = Post::v('expiration');
24bcf50c 1360 $art['public'] = Post::has('public');
1361 $art['xorg'] = Post::has('xorg');
1362 $art['nl'] = Post::has('nl');
1363 $art['event'] = Post::v('event');
f3df6d38 1364 $upload = new PlUpload(S::user()->login(), 'xnetannounce');
ff95a302 1365 $this->upload_image($page, $upload);
24bcf50c 1366
1367 $art['contact_html'] = $art['contacts'];
b9a1ba64 1368 if ($art['event']) {
1369 $art['contact_html'] .= "\n{$globals->baseurl}/{$platal->ns}events/sub/{$art['event']}";
24bcf50c 1370 }
2a557a09 1371
1372 if (!$art['public'] &&
d1c97e42 1373 (($art['promo_min'] > $art['promo_max'] && $art['promo_max'] != 0) ||
2a557a09 1374 ($art['promo_min'] != 0 && ($art['promo_min'] <= 1900 || $art['promo_min'] >= 2020)) ||
1375 ($art['promo_max'] != 0 && ($art['promo_max'] <= 1900 || $art['promo_max'] >= 2020))))
1376 {
a7d35093 1377 $page->trigError("L'intervalle de promotions est invalide.");
2a557a09 1378 Post::kill('valid');
1379 }
1970c12b 1380
1381 if (!trim($art['titre']) || !trim($art['texte'])) {
a7d35093 1382 $page->trigError("L'article doit avoir un titre et un contenu.");
1970c12b 1383 Post::kill('valid');
1384 }
ff95a302
FB
1385
1386 if (Post::v('valid') == 'Supprimer l\'image') {
1387 $upload->rm();
1388 Post::kill('valid');
1389 }
2f8677c2
FB
1390 $art['photo'] = $upload->exists() || Post::i('photo');
1391 if (Post::v('valid') == 'Pas d\'image' && !is_null($aid)) {
14bc135e
SJ
1392 XDB::query('DELETE FROM group_announces_photo
1393 WHERE eid = {?}', $aid);
2f8677c2
FB
1394 $upload->rm();
1395 Post::kill('valid');
1396 $art['photo'] = false;
1397 }
24bcf50c 1398 }
1399
1400 if (Post::v('valid') == 'Enregistrer') {
2a557a09 1401 $promo_min = ($art['public'] ? 0 : $art['promo_min']);
1402 $promo_max = ($art['public'] ? 0 : $art['promo_max']);
113f6de8 1403 $flags = new PlFlagSet();
ff95a302 1404 if ($art['public']) {
77e786e1 1405 $flags->addFlag('public');
ff95a302
FB
1406 }
1407 if ($art['photo']) {
77e786e1 1408 $flags->addFlag('photo');
ff95a302 1409 }
24bcf50c 1410 if (is_null($aid)) {
eaf30d86
PH
1411 $fulltext = $art['texte'];
1412 if (!empty($art['contact_html'])) {
1413 $fulltext .= "\n\n'''Contacts :'''\\\\\n" . $art['contact_html'];
e219710a 1414 }
91cf1bdb 1415 $post = null;
e219710a 1416 if ($globals->asso('forum')) {
1417 require_once 'banana/forum.inc.php';
e3a55098 1418 $banana = new ForumsBanana(S::user());
e219710a 1419 $post = $banana->post($globals->asso('forum'), null,
1420 $art['titre'], MiniWiki::wikiToText($fulltext, false, 0, 80));
91cf1bdb 1421 }
14bc135e 1422 XDB::query('INSERT INTO group_announces (uid, asso_id, create_date, titre, texte, contacts,
b58e5ac2 1423 expiration, promo_min, promo_max, flags, post_id)
14bc135e 1424 VALUES ({?}, {?}, NOW(), {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})',
24bcf50c 1425 S::i('uid'), $globals->asso('id'), $art['titre'], $art['texte'], $art['contact_html'],
b58e5ac2 1426 $art['expiration'], $promo_min, $promo_max, $flags, $post);
8b83a166 1427 $aid = XDB::insertId();
ff95a302
FB
1428 if ($art['photo']) {
1429 list($imgx, $imgy, $imgtype) = $upload->imageInfo();
14bc135e
SJ
1430 XDB::execute('INSERT INTO group_announces_photo
1431 SET eid = {?}, attachmime = {?}, x = {?}, y = {?}, attach = {?}',
ff95a302
FB
1432 $aid, $imgtype, $imgx, $imgy, $upload->getContents());
1433 }
24bcf50c 1434 if ($art['xorg']) {
794feea7 1435 $article = new EvtReq("[{$globals->asso('nom')}] " . $art['titre'], $fulltext,
b58e5ac2 1436 $art['promo_min'], $art['promo_max'], $art['expiration'], "", S::user(),
ff95a302 1437 $upload);
24bcf50c 1438 $article->submit();
a7d35093 1439 $page->trigWarning("L'affichage sur la page d'accueil de Polytechnique.org est en attente de validation.");
ff95a302
FB
1440 } else if ($upload && $upload->exists()) {
1441 $upload->rm();
24bcf50c 1442 }
1443 if ($art['nl']) {
5daf68f6 1444 $article = new NLReq(S::user(), $globals->asso('nom') . " : " .$art['titre'],
2a557a09 1445 $art['texte'], $art['contact_html']);
24bcf50c 1446 $article->submit();
a7d35093 1447 $page->trigWarning("La parution dans la Lettre Mensuelle est en attente de validation.");
24bcf50c 1448 }
1449 } else {
14bc135e 1450 XDB::query('UPDATE group_announces
b58e5ac2 1451 SET titre = {?}, texte = {?}, contacts = {?}, expiration = {?},
14bc135e
SJ
1452 promo_min = {?}, promo_max = {?}, flags = {?}
1453 WHERE id = {?} AND asso_id = {?}',
b58e5ac2 1454 $art['titre'], $art['texte'], $art['contacts'], $art['expiration'],
ff95a302 1455 $promo_min, $promo_max, $flags,
24bcf50c 1456 $art['id'], $globals->asso('id'));
2f8677c2
FB
1457 if ($art['photo'] && $upload->exists()) {
1458 list($imgx, $imgy, $imgtype) = $upload->imageInfo();
00ba8a74
SJ
1459 XDB::execute('INSERT INTO group_announces_photo (eid, attachmime, attach, x, y)
1460 VALUES ({?}, {?}, {?}, {?}, {?})
1461 ON DUPLICATE KEY UPDATE attachmime = VALUES(attachmime), attach = VALUES(attach), x = VALUES(x), y = VALUES(y)',
1462 $aid, $imgtype, $upload->getContents(), $imgx, $imgy);
2f8677c2
FB
1463 $upload->rm();
1464 }
24bcf50c 1465 }
2a557a09 1466 }
1467 if (Post::v('valid') == 'Enregistrer' || Post::v('valid') == 'Annuler') {
24bcf50c 1468 pl_redirect("");
eaf30d86 1469 }
24bcf50c 1470
1471 if (empty($art) && !is_null($aid)) {
14bc135e
SJ
1472 $res = XDB::query("SELECT *, FIND_IN_SET('public', flags) AS public,
1473 FIND_IN_SET('photo', flags) AS photo
1474 FROM group_announces
1475 WHERE asso_id = {?} AND id = {?}",
24bcf50c 1476 $globals->asso('id'), $aid);
1477 if ($res->numRows()) {
1478 $art = $res->fetchOneAssoc();
1479 $art['contact_html'] = $art['contacts'];
1480 } else {
567553ac 1481 $page->kill("Aucun article correspond à l'identifiant indiqué.");
24bcf50c 1482 }
1483 }
1484
24bcf50c 1485 if (is_null($aid)) {
1486 $events = XDB::iterator("SELECT *
eb41eda9 1487 FROM group_events
24bcf50c 1488 WHERE asso_id = {?} AND archive = 0",
1489 $globals->asso('id'));
1490 if ($events->total()) {
1491 $page->assign('events', $events);
1492 }
eaf30d86 1493 }
24bcf50c 1494
72b2f8bb 1495 $art['contact_html'] = @MiniWiki::WikiToHTML($art['contact_html']);
24bcf50c 1496 $page->assign('art', $art);
ff95a302 1497 $page->assign_by_ref('upload', $upload);
24bcf50c 1498 }
1499
26ba053e 1500 function handler_admin_announce($page)
24bcf50c 1501 {
1502 global $globals;
1490093c 1503 $page->changeTpl('xnetgrp/announce-admin.tpl');
24bcf50c 1504
1505 if (Env::has('del')) {
e7fdf9dd 1506 S::assert_xsrf_token();
14bc135e
SJ
1507 XDB::execute('DELETE FROM group_announces
1508 WHERE id = {?} AND asso_id = {?}',
24bcf50c 1509 Env::i('del'), $globals->asso('id'));
1510 }
b58e5ac2 1511 $res = XDB::iterator('SELECT id, titre, expiration, expiration < CURRENT_DATE() AS perime
14bc135e
SJ
1512 FROM group_announces
1513 WHERE asso_id = {?}
b58e5ac2 1514 ORDER BY expiration DESC',
24bcf50c 1515 $globals->asso('id'));
1516 $page->assign('articles', $res);
1517 }
ae7bb180 1518}
1519
a7de4ef7 1520// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
ae7bb180 1521?>