4fccb1b6345af16593083a274ee66f5604611de0
2 /***************************************************************************
3 * Copyright (C) 2003-2011 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
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. *
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. *
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 *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
23 class XnetGrpModule
extends PLModule
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
),
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'),
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'),
54 '%grp/member/reg' => $this->make_hook('admin_member_reg', AUTH_PASSWD
, 'groupadmin'),
56 '%grp/rss' => $this->make_token_hook('rss', AUTH_PUBLIC
),
57 '%grp/announce/new' => $this->make_hook('edit_announce', AUTH_PASSWD
, 'groupadmin'),
58 '%grp/announce/edit' => $this->make_hook('edit_announce', AUTH_PASSWD
, 'groupadmin'),
59 '%grp/announce/photo' => $this->make_hook('photo_announce', AUTH_PUBLIC
),
60 '%grp/admin/announces' => $this->make_hook('admin_announce', AUTH_PASSWD
, 'groupadmin'),
64 function handler_index($page, $arg = null
)
66 global $globals, $platal;
70 $page->changeTpl('xnetgrp/asso.tpl');
73 if (Env
::has('read')) {
74 XDB
::query('DELETE r.*
75 FROM group_announces_read AS r
76 INNER JOIN group_announces AS a ON (a.id = r.announce_id)
77 WHERE expiration < CURRENT_DATE()');
78 XDB
::query('INSERT INTO group_announces_read
80 Env
::i('read'), S
::i('uid'));
83 if (Env
::has('unread')) {
84 XDB
::query('DELETE FROM group_announces_read
85 WHERE announce_id = {?} AND uid = {?}',
86 Env
::i('unread'), S
::i('uid'));
87 pl_redirect("#art" . Env
::i('unread'));
90 /* TODO: refines this filter on promotions by using userfilter. */
92 if ($user->hasProfile()) {
93 $promo = XDB
::format('{?}', $user->profile()->entry_year
);
94 $minCondition = ' OR promo_min <= ' . $promo;
95 $maxCondition = ' OR promo_max >= ' . $promo;
100 $arts = XDB
::iterator('SELECT a.*, FIND_IN_SET(\'photo\', a.flags) AS photo
101 FROM group_announces AS a
102 LEFT JOIN group_announces_read AS r ON (r.uid = {?} AND r.announce_id = a.id)
103 WHERE asso_id = {?} AND expiration >= CURRENT_DATE()
104 AND (promo_min = 0' . $minCondition . ')
105 AND (promo_max = 0' . $maxCondition . ')
106 AND r.announce_id IS NULL
107 ORDER BY a.expiration',
108 S
::i('uid'), $globals->asso('id'));
109 $index = XDB
::iterator('SELECT a.id, a.titre, r.uid IS NULL AS nonlu
110 FROM group_announces AS a
111 LEFT JOIN group_announces_read AS r ON (a.id = r.announce_id AND r.uid = {?})
112 WHERE asso_id = {?} AND expiration >= CURRENT_DATE()
113 AND (promo_min = 0' . $minCondition . ')
114 AND (promo_max = 0' . $maxCondition . ')
115 ORDER BY a.expiration',
116 S
::i('uid'), $globals->asso('id'));
117 $page->assign('article_index', $index);
119 $arts = XDB
::iterator("SELECT *, FIND_IN_SET('photo', flags) AS photo
121 WHERE asso_id = {?} AND expiration >= CURRENT_DATE()
122 AND FIND_IN_SET('public', flags)",
123 $globals->asso('id'));
124 $payments = XDB
::fetchAllAssoc("SELECT id, text
126 WHERE asso_id = {?} AND NOT FIND_IN_SET('old', flags) AND FIND_IN_SET('public', flags)
128 $globals->asso('id'));
129 $page->assign('payments', $payments);
132 $subs_valid = XDB
::query("SELECT uid
133 FROM group_member_sub_requests
134 WHERE asso_id = {?}",
135 $globals->asso('id'));
136 $page->assign('requests', $subs_valid->numRows());
139 if (!S
::hasAuthToken()) {
140 $page->setRssLink("Polytechnique.net :: {$globals->asso("nom
")} :: News publiques",
141 $platal->ns
. "rss/rss.xml");
143 $page->setRssLink("Polytechnique.net :: {$globals->asso("nom
")} :: News",
144 $platal->ns
. 'rss/' . S
::v('hruid') . '/' . S
::user()->token
. '/rss.xml');
147 $page->assign('articles', $arts);
150 function handler_logo($page)
153 $globals->asso()->getLogo()->send();
156 function handler_site($page)
159 $site = $globals->asso('site');
161 $page->trigError('Le groupe n\'a pas de site web.');
162 return $this->handler_index($page);
164 http_redirect($site);
168 function handler_edit($page)
171 $page->changeTpl('xnetgrp/edit.tpl');
175 $domains = XDB
::iterator('SELECT *
178 $page->assign('domains', $domains);
179 $page->assign('super', true
);
182 if (Post
::has('submit')) {
183 S
::assert_xsrf_token();
185 $flags = new PlFlagSet('wiki_desc');
186 $flags->addFlag('notif_unsub', Post
::i('notif_unsub') == 1);
187 $site = Post
::t('site');
188 if ($site && ($site != "http://")) {
189 $scheme = parse_url($site, PHP_URL_SCHEME
);
191 $site = "http://" . $site;
197 $notify_all = (Post
::v('notify_all') ? true
: false
);
199 $to_notify = array();
200 $uf = New UserFilter(New UFC_Group($globals->asso('id'), true
));
201 $uids = $uf->getIds();
202 foreach ($uids as $uid) {
203 if (Post
::b('to_notify_' . $uid)) {
207 if (count($to_notify) == 0) {
209 $page->trigWarning("Aucun animateur n'ayant été selectionné pour recevoir les demandes d'inscriptions, tous le seront.");
212 $flags->addFlag('notify_all', $notify_all);
215 $page->assign('super', true
);
217 if (Post
::v('mail_domain') && (strstr(Post
::v('mail_domain'), '.') === false
)) {
218 $page->trigError('Le domaine doit être un FQDN (aucune modification effectuée) !!!');
221 if (Post
::t('nom') == '' || Post
::t('diminutif') == '') {
222 $page->trigError('Ni le nom ni le diminutif du groupe ne peuvent être vide.');
226 $page->assign('nom', Post
::t('nom'));
227 $page->assign('diminutif', Post
::t('diminutif'));
228 $page->assign('mail_domain', Post
::t('mail_domain'));
229 $page->assign('cat', Post
::v('cat'));
230 $page->assign('dom', Post
::v('dom'));
231 $page->assign('ax', Post
::v('ax'));
232 $page->assign('axDate', Post
::t('axDate'));
233 $page->assign('site', $site);
234 $page->assign('resp', Post
::t('resp'));
235 $page->assign('mail', Post
::t('mail'));
236 $page->assign('phone', Post
::t('phone'));
237 $page->assign('fax', Post
::t('fax'));
238 $page->assign('address', Post
::t('address'));
239 $page->assign('forum', Post
::t('forum'));
240 $page->assign('inscriptible', Post
::v('inscriptible'));
241 $page->assign('sub_url', Post
::t('sub_url'));
242 $page->assign('unsub_url', Post
::t('unsub_url'));
243 $page->assign('welcome_msg', Post
::t('welcome_msg'));
244 $page->assign('pub', Post
::v('pub'));
245 $page->assign('notif_unsub', Post
::i('notif_unsub'));
246 $page->assign('descr', Post
::t('descr'));
247 $page->assign('error', $error);
251 $axDate = make_datetime(Post
::v('axDate'));
252 if (Post
::t('axDate') != '') {
253 $axDate = make_datetime(Post
::v('axDate'))->format('Y-m-d');
259 SET nom={?}, diminutif={?}, cat={?}, dom={?},
260 descr={?}, site={?}, mail={?}, resp={?},
261 forum={?}, mail_domain={?}, ax={?}, axDate = {?}, pub={?},
262 sub_url={?}, inscriptible={?}, unsub_url={?},
263 flags = {?}, welcome_msg = {?}
265 Post
::v('nom'), Post
::v('diminutif'),
266 Post
::v('cat'), (Post
::i('dom') == 0) ? null
: Post
::i('dom'),
267 Post
::v('descr'), $site,
268 Post
::v('mail'), Post
::v('resp'),
269 Post
::v('forum'), Post
::v('mail_domain'),
270 Post
::has('ax'), $axDate, Post
::v('pub'),
271 Post
::v('sub_url'), Post
::v('inscriptible'),
272 Post
::v('unsub_url'), $flags, Post
::t('welcome_msg'),
273 $globals->asso('id'));
274 if (Post
::v('mail_domain')) {
275 XDB
::execute('INSERT IGNORE INTO email_virtual_domains (name)
277 Post
::t('mail_domain'));
278 XDB
::execute('UPDATE email_virtual_domains
281 Post
::t('mail_domain'));
286 SET descr={?}, site={?}, mail={?}, resp={?},
287 forum={?}, pub= {?}, sub_url={?},
288 unsub_url = {?}, flags = {?}, welcome_msg = {?}
290 Post
::v('descr'), $site,
291 Post
::v('mail'), Post
::v('resp'),
292 Post
::v('forum'), Post
::v('pub'),
293 Post
::v('sub_url'), Post
::v('unsub_url'),
294 $flags, Post
::t('welcome_msg'),
295 $globals->asso('id'));
298 Phone
::deletePhones(0, Phone
::LINK_GROUP
, $globals->asso('id'));
299 $phone = new Phone(array('link_type' => 'group', 'link_id' => $globals->asso('id'), 'id' => 0,
300 'type' => 'fixed', 'display' => Post
::v('phone'), 'pub' => 'public'));
301 $fax = new Phone(array('link_type' => 'group', 'link_id' => $globals->asso('id'), 'id' => 1,
302 'type' => 'fax', 'display' => Post
::v('fax'), 'pub' => 'public'));
305 Address
::deleteAddresses(null
, Address
::LINK_GROUP
, null
, $globals->asso('id'));
306 $address = new Address(array('groupid' => $globals->asso('id'), 'type' => Address
::LINK_GROUP
, 'text' => Post
::v('address')));
309 if ($_FILES['logo']['name']) {
310 $upload = PlUpload
::get($_FILES['logo'], $globals->asso('id'), 'asso.logo', true
);
312 $page->trigError("Impossible de télécharger le logo.");
314 XDB
::execute('UPDATE groups
315 SET logo = {?}, logo_mime = {?}
316 WHERE id = {?}', $upload->getContents(), $upload->contentType(),
317 $globals->asso('id'));
322 XDB
::execute("UPDATE group_members
324 WHERE asso_id = {?}",
325 $globals->asso('id'));
327 XDB
::execute("UPDATE group_members
329 WHERE asso_id = {?} AND uid IN {?}",
330 $globals->asso('id'), $to_notify);
333 pl_redirect('../' . Post
::v('diminutif', $globals->asso('diminutif')) . '/edit');
336 $uf = New UserFilter(New UFC_Group($globals->asso('id'), true
, UFC_Group
::NOTIFIED
));
337 $page->assign('notified', $uf->getUsers());
338 $uf = New UserFilter(New UFC_Group($globals->asso('id'), true
, UFC_Group
::UNNOTIFIED
));
339 $page->assign('unnotified', $uf->getUsers());
341 $page->assign('error', $error);
342 $page->assign('cat', $globals->asso('cat'));
343 $page->assign('dom', $globals->asso('dom'));
344 $page->assign('ax', $globals->asso('ax'));
345 $page->assign('inscriptible', $globals->asso('inscriptible'));
346 $page->assign('pub', $globals->asso('pub'));
347 $page->assign('notif_unsub', $globals->asso('notif_unsub'));
348 $page->assign('notify_all', $globals->asso('notify_all'));
351 function handler_mail($page)
355 $page->changeTpl('xnetgrp/mail.tpl');
356 $mmlist = new MMList(S
::user(), $globals->asso('mail_domain'));
357 $page->assign('listes', $mmlist->get_lists());
358 $page->assign('user', S
::user());
360 if (Post
::has('send')) {
361 S
::assert_xsrf_token();
362 $from = Post
::v('from');
363 $sujet = Post
::v('sujet');
364 $body = Post
::v('body');
366 $mls = array_keys(Env
::v('ml', array()));
367 $mbr = array_keys(Env
::v('membres', array()));
369 $this->load('mail.inc.php');
371 $tos = get_all_redirects($mbr, $mls, $mmlist);
373 $upload = PlUpload
::get($_FILES['uploaded'], S
::user()->login(), 'xnet.emails', true
);
374 if (!$upload && @$_FILES['uploaded']['name'] && PlUpload
::$lastError != null
) {
375 $page->trigError(PlUpload
::$lastError);
379 send_xnet_mails($from, $sujet, $body, Env
::v('wiki'), $tos, Post
::v('replyto'), $upload, @$_FILES['uploaded']['name']);
383 $page->killSuccess("Email envoyé !");
384 $page->assign('sent', true
);
388 function handler_forum($page, $group = null
, $artid = null
)
391 $page->changeTpl('xnetgrp/forum.tpl');
392 if (!$globals->asso('forum')) {
395 require_once 'banana/forum.inc.php';
397 get_banana_params($get, $globals->asso('forum'), $group, $artid);
398 run_banana($page, 'ForumsBanana', $get);
401 function handler_annuaire($page, $action = null
, $subaction = null
)
405 __autoload('userset');
407 if ($action == 'admins') {
409 $action = $subaction;
411 $view = new UserSet(new UFC_Group($globals->asso('id'), $admins));
412 $view->addMod('groupmember', 'Annuaire');
413 $view->addMod('trombi', 'Trombinoscope');
414 $view->addMod('map', 'Planisphère');
415 $view->apply('annuaire', $page, $action);
416 $page->assign('only_admin', $admins);
417 $page->changeTpl('xnetgrp/annuaire.tpl');
420 function handler_former_users($page)
423 require_once 'userset.inc.php';
425 $view = new UserSet(new UFC_GroupFormerMember($globals->asso('id')));
426 $view->addMod('groupmember', 'Anciens membres', true
, array('noadmin' => true
));
427 $view->apply('former_users', $page);
428 $page->changeTpl('xnetgrp/former_users.tpl');
431 function handler_trombi($page)
433 pl_redirect('annuaire/trombi');
436 function handler_geoloc($page)
438 pl_redirect('annuaire/geoloc');
441 function handler_vcard($page, $photos = null
)
444 $vcard = new VCard($photos == 'photos', 'Membre du groupe ' . $globals->asso('nom'));
445 $vcard->addProfiles($globals->asso()->getMembersFilter()->getProfiles(null
, Profile
::FETCH_ALL
));
449 function handler_csv($page, $filename = null
)
452 if (is_null($filename)) {
453 $filename = $globals->asso('diminutif') . '.csv';
455 $users = $globals->asso()->getMembersFilter(null
, new UFO_Name())->getUsers();
456 pl_cached_content_headers('text/x-csv', 'iso-8859-1', 1);
458 echo utf8_decode("Nom;Prénom;Sexe;Promotion;Commentaire\n");
459 foreach ($users as $user) {
460 $line = $user->lastName() . ';' . $user->firstName() . ';' . ($user->isFemale() ?
'F' : 'M')
461 . ';' . $user->promo() . ';' . strtr($user->group_comm
, ';', ',');
462 echo utf8_decode($line) . "\n";
467 function handler_directory_sync($page)
470 require_once 'emails.inc.php';
472 $page->changeTpl('xnetgrp/sync.tpl');
473 Platal
::load('lists', 'lists.inc.php');
475 if (Env
::has('add_users')) {
476 S
::assert_xsrf_token();
478 $users = array_keys(Env
::v('add_users'));
479 $former_users = XDB
::fetchColumn('SELECT uid
480 FROM group_former_members
481 WHERE remember = TRUE AND uid IN {?}',
483 $new_users = array_diff($users, $former_users);
485 foreach ($former_users as $uid) {
486 $user = User
::getSilentWithUID($uid);
487 $page->trigWarning($user->fullName() . ' est un ancien membre du groupe qui ne souhaite pas y revenir.');
489 if (count($former_users) > 1) {
490 $page->trigWarning('S\'ils souhaitent revenir dans le groupe, il faut qu\'ils en fassent la demande sur la page d\'accueil du groupe.');
491 } elseif (count($former_users)) {
492 $page->trigWarning('S\'il souhaite revenir dans le groupe, il faut qu\'il en fasse la demande sur la page d\'accueil du groupe.');
496 foreach ($new_users as $uid) {
497 $data[] = XDB
::format('({?}, {?})', $globals->asso('id'), $uid);
499 XDB
::rawExecute('INSERT INTO group_members (asso_id, uid)
500 VALUES ' . implode(',', $data));
503 if (Env
::has('add_nonusers')) {
504 S
::assert_xsrf_token();
506 $nonusers = array_keys(Env
::v('add_nonusers'));
507 foreach ($nonusers as $email) {
508 if ($user = User
::getSilent($email) ||
!isvalid_email($email)) {
512 list($local_part, $domain) = explode('@', strtolower($email));
513 $hruid = User
::makeHrid($local_part, $domain, 'ext');
514 if ($user = User
::getSilent($hruid)) {
518 require_once 'name.func.inc.php';
519 $parts = explode('.', $local_part);
520 if (count($parts) == 1) {
521 $lastname = $display_name = capitalize_name($mbox);
524 $display_name = $firstname = capitalize_name($parts[0]);
525 $lastname = capitalize_name(implode(' ', array_slice($parts, 1)));
527 $full_name = build_full_name($firstname, $lastname);
528 $directory_name = build_directory_name($firstname, $lastname);
529 $sort_name = build_sort_name($firstname, $lastname);
530 XDB
::execute('INSERT INTO accounts (hruid, display_name, full_name, directory_name, sort_name,
531 firstname, lastname, email, type, state)
532 VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, \'xnet\', \'disabled\')',
533 $hruid, $display_name, $full_name, $directory_name, $sort_name, $firstname, $lastname, $email);
534 $uid = XDB
::insertId();
535 XDB
::execute('INSERT INTO group_members (asso_id, uid)
537 $globals->asso('id'), $uid);
541 if (Env
::has('add_users') || Env
::has('add_nonusers')) {
542 $page->trigSuccess('Ajouts réalisés avec succès.');
546 $client = new MMList($user, $globals->asso('mail_domain'));
547 $lists = $client->get_lists();
549 foreach ($lists as $list) {
550 $details = $client->get_members($list['list']);
551 $members = array_merge($members, list_extract_members($details[1]));
553 $members = array_unique($members);
557 foreach ($members as $email) {
558 if ($user = User
::getSilent($email)) {
559 $uids[] = $user->id();
561 $nonusers[] = $email;
565 $aliases = iterate_list_alias($globals->asso('mail_domain'));
566 foreach ($aliases as $alias) {
567 list($local_part, $domain) = explode('@', $alias);
568 $aliases_members = list_alias_members($local_part, $domain);
569 $users = array_merge($users, $aliases_members['users']);
570 $nonusers = array_merge($nonusers, $aliases_members['nonusers']);
572 foreach ($users as $user) {
573 $uids[] = $user->id();
575 $nonusers = array_unique($nonusers);
576 $uids = array_unique($uids);
578 $uids = XDB
::fetchColumn('SELECT a.uid
580 WHERE a.uid IN {?} AND NOT EXISTS (SELECT *
581 FROM group_members AS g
582 WHERE a.uid = g.uid AND g.asso_id = {?})',
583 $uids, $globals->asso('id'));
585 $users = User
::getBulkUsersWithUIDs($uids);
586 usort($users, 'User::compareDirectoryName');
592 $page->assign('users', $users);
593 $page->assign('nonusers', $nonusers);
596 function handler_non_active($page)
599 $page->changeTpl('xnetgrp/non_active.tpl');
601 $uids = XDB
::fetchColumn('SELECT g.uid
602 FROM group_members AS g
603 INNER JOIN accounts AS a ON (a.uid = g.uid)
604 LEFT JOIN register_pending_xnet AS p ON (p.uid = g.uid)
605 WHERE a.uid = g.uid AND g.asso_id = {?} AND a.type = \'xnet\' AND a.state = \'disabled\' AND p.uid IS NULL',
606 $globals->asso('id'));
607 foreach ($uids as $key => $uid) {
608 if (AccountReq
::isPending($uid) || BulkAccountsReq
::isPending($uid)) {
613 if (Post
::has('enable_accounts')) {
614 S
::assert_xsrf_token();
616 $uids_to_enable = array_intersect(array_keys(Post
::v('enable_accounts')), $uids);
619 $request = new BulkAccountsReq($user, $uids_to_enable, $globals->asso('nom'), $globals->asso('diminutif'));
621 $page->trigSuccess('Un email va bientôt être envoyé aux personnes sélectionnées pour l\'activation de leur compte.');
623 foreach ($uids as $key => $uid) {
624 if (in_array($uid, $uids_to_enable)) {
630 $users = User
::getBulkUsersWithUIDs($uids);
631 $page->assign('users', $users);
634 private function removeSubscriptionRequest($uid)
637 XDB
::execute("DELETE FROM group_member_sub_requests
638 WHERE asso_id = {?} AND uid = {?}",
639 $globals->asso('id'), $uid);
642 private function validSubscription(User
$user)
645 $this->removeSubscriptionRequest($user->id());
646 Group
::subscribe($globals->asso('id'), $user->id());
648 if (XDB
::affectedRows() == 1) {
649 $mailer = new PlMailer();
650 $mailer->addTo($user->forlifeEmail());
651 $mailer->setFrom('"' . S
::user()->fullName() . '" <' . S
::user()->forlifeEmail() . '>');
652 $mailer->setSubject('[' . $globals->asso('nom') . '] Demande d\'inscription');
653 $message = ($user->isFemale() ?
'Chère' : 'Cher') . " Camarade,\n"
655 . " Suite à ta demande d'adhésion à " . $globals->asso('nom')
656 . ", j'ai le plaisir de t'annoncer que ton inscription a été validée !\n"
657 . (is_null($globals->asso('welcome_msg')) ?
'' : "\n" . $globals->asso('welcome_msg') . "\n")
659 . "Bien cordialement,\n"
661 . S
::user()->fullName() . '.';
662 $mailer->setTxtBody(wordwrap($message, 72));
667 function handler_subscribe($page, $u = null
)
670 $page->changeTpl('xnetgrp/inscrire.tpl');
672 if (!$globals->asso('inscriptible'))
673 $page->kill("Il n'est pas possible de s'inscire en ligne à ce "
674 ."groupe. Essaie de joindre le contact indiqué "
675 ."sur la page de présentation.");
677 if (!is_null($u) && may_update()) {
678 $user = User
::get($u);
682 $page->assign('user', $user);
685 // Retrieves the subscription status, and the reason.
686 $res = XDB
::query("SELECT reason
687 FROM group_member_sub_requests
688 WHERE asso_id = {?} AND uid = {?}",
689 $globals->asso('id'), $user->id());
690 $reason = ($res->numRows() ?
$res->fetchOneCell() : null
);
692 $res = XDB
::query("SELECT COUNT(*)
694 WHERE asso_id = {?} AND uid = {?}",
695 $globals->asso('id'), $user->id());
696 $already_member = ($res->fetchOneCell() > 0);
698 // Handles the membership request.
699 if ($already_member) {
700 $this->removeSubscriptionRequest($user->id());
701 $page->kill($user->fullName() . ' est déjà membre du groupe !');
702 } elseif (Env
::has('accept')) {
703 S
::assert_xsrf_token();
705 $this->validSubscription($user);
706 pl_redirect("member/" . $user->login());
707 } elseif (Env
::has('refuse')) {
708 S
::assert_xsrf_token();
710 $this->removeSubscriptionRequest($user->id());
711 $mailer = new PlMailer();
712 $mailer->addTo($user->forlifeEmail());
713 $mailer->setFrom('"' . S
::user()->fullName() . '" <' . S
::user()->forlifeEmail() . '>');
714 $mailer->setSubject('['.$globals->asso('nom').'] Demande d\'inscription annulée');
715 $mailer->setTxtBody(Env
::v('motif'));
717 $page->killSuccess("La demande de {$user->fullName()} a bien été refusée.");
719 $page->assign('show_form', true
);
720 $page->assign('reason', $reason);
726 $page->kill("Tu es déjà membre !");
730 $res = XDB
::query("SELECT uid
731 FROM group_member_sub_requests
732 WHERE uid = {?} AND asso_id = {?}",
733 S
::i('uid'), $globals->asso('id'));
734 if ($res->numRows() != 0) {
735 $page->kill("Tu as déjà demandé ton inscription à ce groupe. Cette demande est actuellement en attente de validation.");
739 if (Post
::has('inscrire')) {
740 S
::assert_xsrf_token();
742 XDB
::execute("INSERT INTO group_member_sub_requests (asso_id, uid, ts, reason)
743 VALUES ({?}, {?}, NOW(), {?})",
744 $globals->asso('id'), S
::i('uid'), Post
::v('message'));
745 XDB
::execute('DELETE FROM group_former_members
746 WHERE uid = {?} AND asso_id = {?}',
747 S
::i('uid'), $globals->asso('id'));
748 $admins = $globals->asso()->iterToNotify();
749 $admin = $admins->next();
750 $to = $admin->bestEmail();
751 while ($admin = $admins->next()) {
752 $to .= ', ' . $admin->bestEmail();
757 . "Ce message a été envoyé suite à la demande d'inscription de\n"
758 . S
::user()->fullName(true
) . "\n"
759 . "Via le site www.polytechnique.net. Tu peux choisir de valider ou\n"
760 . "de refuser sa demande d'inscription depuis la page :\n"
761 . "http://www.polytechnique.net/" . $globals->asso("diminutif") . "/subscribe/" . S
::user()->login() . "\n"
763 . "En cas de problème, contacter l'équipe de Polytechnique.org\n"
764 . "à l'adresse : support@polytechnique.org\n";
767 $to = ($globals->asso('mail') != '') ?
$globals->asso('mail') . ', ' : '';
768 $to .= 'support@polytechnique.org';
769 $append = "\n-- \nLe groupe ".$globals->asso("nom")
770 ." n'a pas d'administrateur, l'équipe de"
771 ." Polytechnique.org a été prévenue et va rapidement"
772 ." résoudre ce problème.\n";
775 $mailer = new PlMailer();
777 $mailer->setFrom('"' . S
::user()->fullName() . '" <' . S
::user()->forlifeEmail() . '>');
778 $mailer->setSubject('['.$globals->asso('nom').'] Demande d\'inscription');
779 $mailer->setTxtBody(Post
::v('message').$append);
784 function handler_subscribe_valid($page)
788 if (Post
::has('valid')) {
789 S
::assert_xsrf_token();
790 $subs = Post
::v('subs');
791 if (is_array($subs)) {
793 foreach ($subs as $hruid => $val) {
795 $user = User
::get($hruid);
797 $this->validSubscription($user);
804 $it = XDB
::iterator('SELECT s.uid, a.hruid, s.ts AS date
805 FROM group_member_sub_requests AS s
806 INNER JOIN accounts AS a ON(s.uid = a.uid)
807 WHERE s.asso_id = {?}
808 ORDER BY s.ts', $globals->asso('id'));
809 $page->changeTpl('xnetgrp/subscribe-valid.tpl');
810 $page->assign('valid', $it);
813 function handler_change_rights($page)
815 if (Env
::has('right') && (may_update() || S
::suid())) {
816 switch (Env
::v('right')) {
818 Platal
::session()->stopSUID();
821 Platal
::session()->doSelfSuid();
826 Platal
::session()->doSelfSuid();
827 may_update(false
, true
);
831 Platal
::session()->doSelfSuid();
832 may_update(false
, true
);
833 is_member(false
, true
);
837 http_redirect($_SERVER['HTTP_REFERER']);
840 function handler_admin_annuaire($page)
844 $this->load('mail.inc.php');
845 $page->changeTpl('xnetgrp/annuaire-admin.tpl');
847 $mmlist = new MMList($user, $globals->asso('mail_domain'));
848 $lists = $mmlist->get_lists();
849 if (!$lists) $lists = array();
850 $listes = array_map(create_function('$arr', 'return $arr["list"];'), $lists);
852 $subscribers = array();
854 foreach ($listes as $list) {
855 list(,$members) = $mmlist->get_members($list);
856 $mails = array_map(create_function('$arr', 'return $arr[1];'), $members);
857 $subscribers = array_unique(array_merge($subscribers, $mails));
860 $not_in_group_x = array();
861 $not_in_group_ext = array();
863 foreach ($subscribers as $mail) {
864 $uf = new UserFilter(new PFC_And(new UFC_Group($globals->asso('id')),
865 new UFC_Email($mail)));
866 if ($uf->getTotalCount() == 0) {
867 if (User
::isForeignEmailAddress($mail)) {
868 $not_in_group_ext[] = $mail;
870 $not_in_group_x[] = $mail;
875 $page->assign('not_in_group_ext', $not_in_group_ext);
876 $page->assign('not_in_group_x', $not_in_group_x);
877 $page->assign('lists', $lists);
880 function handler_admin_member_new($page, $email = null
)
884 $page->changeTpl('xnetgrp/membres-add.tpl');
885 $page->addJsLink('xnet_members.js');
887 if (is_null($email)) {
891 S
::assert_xsrf_token();
892 $suggest_account_activation = false
;
894 // FS#703 : $_GET is urldecoded twice, hence
895 // + (the data) => %2B (in the url) => + (first decoding) => ' ' (second decoding)
896 // Since there can be no spaces in emails, we can fix this with :
897 $email = str_replace(' ', '+', $email);
898 $is_valid_email = isvalid_email($email);
900 // X not registered to main site.
901 if (Env
::v('x') && Env
::i('userid') && $is_valid_email) {
902 $user = User
::getSilentWithUID(Env
::i('userid'));
904 $page->trigError('Utilisateur invalide.');
908 // User has an account but is not yet registered.
909 if ($user->state
== 'pending') {
910 // Add email in account table.
911 XDB
::query('UPDATE accounts
913 WHERE uid = {?} AND email IS NULL',
914 $email, $user->id());
915 // Add email for marketing if required.
916 if (Env
::v('marketing')) {
917 $market = Marketing
::get($user->uid
, $email);
919 $market = new Marketing($user->uid
, $email, 'group', $globals->asso('nom'),
920 Env
::v('marketing_from'), S
::v('uid'));
924 } elseif (Env
::v('broken')) {
925 // Add email for broken if required.
926 $valid = new BrokenReq(S
::user(), $user, $email, 'Groupe : ' . $globals->asso('nom'));
930 $user = User
::getSilent($email);
932 // Wrong email and no user: failure.
933 if (is_null($user) && (!$is_valid_email ||
!User
::isForeignEmailAddress($email))) {
934 $page->trigError('« <strong>' . $email . '</strong> » n\'est pas une adresse email valide.');
938 // Deals with xnet accounts.
939 if (is_null($user) ||
$user->type
== 'xnet') {
940 // User is of type xnet. There are 3 possible cases:
941 // * the email is not known yet: we create a new account and
942 // propose to send an email to the user so he can activate
944 // * the email is known but the user was not contacted in order to
945 // activate yet: we propose to send an email to the user so he
946 // can activate his account,
947 // * the email is known and the user was already contacted or has
948 // an active account: nothing to be done.
949 list($mbox, $domain) = explode('@', strtolower($email));
950 $hruid = User
::makeHrid($mbox, $domain, 'ext');
951 // User might already have an account (in another group for example).
952 $user = User
::getSilent($hruid);
954 // If the user has no account yet, creates new account: build names from email address.
956 require_once 'name.func.inc.php';
957 $parts = explode('.', $mbox);
958 if (count($parts) == 1) {
959 $lastname = $display_name = capitalize_name($mbox);
962 $display_name = $firstname = capitalize_name($parts[0]);
963 $lastname = capitalize_name(implode(' ', array_slice($parts, 1)));
965 $full_name = build_full_name($firstname, $lastname);
966 $directory_name = build_directory_name($firstname, $lastname);
967 $sort_name = build_sort_name($firstname, $lastname);
968 XDB
::execute('INSERT INTO accounts (hruid, display_name, full_name, directory_name, sort_name,
969 firstname, lastname, email, type, state)
970 VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, \'xnet\', \'disabled\')',
971 $hruid, $display_name, $full_name, $directory_name, $sort_name, $firstname, $lastname, $email);
972 $user = User
::getSilent($hruid);
975 $suggest_account_activation = $this->suggest($user);
980 // First check if the user used to be in this group.
981 XDB
::rawExecute('DELETE FROM group_former_members
982 WHERE remember AND DATE_SUB(NOW(), INTERVAL 1 YEAR) > unsubsciption_date');
983 $former_member = XDB
::fetchOneCell('SELECT remember
984 FROM group_former_members
985 WHERE uid = {?} AND asso_id = {?}',
986 $user->id(), $globals->asso('id'));
987 if ($former_member === 1) {
988 $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.');
990 } elseif (!is_null($former_member) && Post
::i('force_continue') == 0) {
991 $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.');
992 $page->assign('force_continue', 1);
996 Group
::subscribe($globals->asso('id'), $user->id());
997 $this->removeSubscriptionRequest($user->id());
998 if ($suggest_account_activation) {
999 pl_redirect('member/suggest/' . $user->login() . '/' . $email . '/' . $globals->asso('nom'));
1001 pl_redirect('member/' . $user->login());
1006 // Check if the user has a pending or active account, and thus if we should her account's activation.
1007 private function suggest(PlUser
$user)
1009 $active = XDB
::fetchOneCell('SELECT state = \'active\'
1013 $pending = XDB
::fetchOneCell('SELECT uid
1014 FROM register_pending_xnet
1017 $requested = AccountReq
::isPending($user->id()) || BulkAccountsReq
::isPending($user->id());
1019 if ($active ||
$pending ||
$requested) {
1025 function handler_admin_member_suggest($page, $hruid, $email)
1027 $page->changeTpl('xnetgrp/membres-suggest.tpl');
1029 // FS#703 : $_GET is urldecoded twice, hence
1030 // + (the data) => %2B (in the url) => + (first decoding) => ' ' (second decoding)
1031 // Since there can be no spaces in emails, we can fix this with :
1032 $email = str_replace(' ', '+', $email);
1034 if (Post
::has('suggest')) {
1035 if (Post
::t('suggest') == 'yes') {
1039 $request = new AccountReq($user, $hruid, $email, $globals->asso('nom'), $globals->asso('diminutif'));
1041 $page->trigSuccessRedirect('Un email va bien être envoyé à ' . $email . ' pour l\'activation de son compte.',
1042 $globals->asso('diminutif') . '/member/' . $hruid);
1044 pl_redirect('member/' . $hruid);
1047 $page->assign('email', $email);
1048 $page->assign('hruid', $hruid);
1051 function handler_admin_member_reg($page, $uid)
1053 pl_content_headers('text/plain');
1055 $user = User
::getSilentWithUID($uid);
1056 if ($user && $user->state
!= 'pending' && $user->hasProfile()) {
1063 function handler_admin_member_new_ajax($page)
1065 pl_content_headers("text/html");
1066 $page->changeTpl('xnetgrp/membres-new-search.tpl', NO_SKIN
);
1068 $same_email = false
;
1069 if (Env
::has('login')) {
1070 $user = User
::getSilent(Env
::t('login'));
1071 if ($user && $user->state
!= 'pending') {
1072 $users = array($user->id() => $user);
1076 if (empty($users)) {
1077 list($lastname, $firstname) = str_replace(array('-', ' ', "'"), '%', array(Env
::t('nom'), Env
::t('prenom')));
1078 $cond = new PFC_And();
1079 if (!empty($lastname)) {
1080 $cond->addChild(new UFC_NameTokens($lastname, array(), false
, false
, Profile
::LASTNAME
));
1082 if (!empty($firstname)) {
1083 $cond->addChild(new UFC_NameTokens($firstname, array(), false
, false
, Profile
::FIRSTNAME
));
1085 if (Env
::t('promo')) {
1086 $cond->addChild(new UFC_Promo('=', UserFilter
::DISPLAY
, Env
::t('promo')));
1088 $uf = new UserFilter($cond);
1089 $users = $uf->getUsers(new PlLimit(30));
1090 if ($uf->getTotalCount() > 30) {
1091 $page->assign('too_many', true
);
1096 $page->assign('users', $users);
1097 $page->assign('same_email', $same_email);
1100 function unsubscribe(PlUser
$user, $remember = false
)
1103 Group
::unsubscribe($globals->asso('id'), $user->id(), $remember);
1105 if ($globals->asso('notif_unsub')) {
1106 $mailer = new PlMailer('xnetgrp/unsubscription-notif.mail.tpl');
1107 $admins = $globals->asso()->iterToNotify();
1108 while ($admin = $admins->next()) {
1109 $mailer->addTo($admin);
1111 $mailer->assign('group', $globals->asso('nom'));
1112 $mailer->assign('user', $user);
1113 $mailer->assign('selfdone', $user->id() == S
::i('uid'));
1117 $domain = $globals->asso('mail_domain');
1122 $mmlist = new MMList(S
::user(), $domain);
1123 $listes = $mmlist->get_lists($user->forlifeEmail());
1125 $may_update = may_update();
1127 if (is_array($listes)) {
1128 foreach ($listes as $liste) {
1129 if ($liste['sub'] == 2) {
1131 $mmlist->mass_unsubscribe($liste['list'], Array($user->forlifeEmail()));
1133 $mmlist->unsubscribe($liste['list']);
1135 } elseif ($liste['sub']) {
1136 Platal
::page()->trigWarning($user->fullName() . " a une"
1137 ." demande d'inscription en cours sur la"
1138 ." liste {$liste['list']}@ !");
1144 XDB
::execute('DELETE v
1145 FROM email_virtual AS v
1146 INNER JOIN email_virtual_domains AS d ON (v.domain = d.id)
1147 WHERE v.redirect = {?} AND d.name = {?}',
1148 $user->forlifeEmail(), $domain);
1152 function handler_unsubscribe($page)
1154 $page->changeTpl('xnetgrp/membres-del.tpl');
1157 return PL_NOT_FOUND
;
1159 $page->assign('self', true
);
1160 $page->assign('user', $user);
1162 if (!Post
::has('confirm')) {
1165 S
::assert_xsrf_token();
1168 $hasSingleGroup = ($user->groupCount() == 1);
1170 if ($this->unsubscribe($user, Post
::b('remember'))) {
1171 $page->trigSuccess('Tu as été désinscrit du groupe avec succès.');
1173 $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.');
1176 // If user is of type xnet account and this was her last group, disable the account.
1177 if ($user->type
== 'xnet' && $hasSingleGroup) {
1180 $page->assign('is_member', is_member(true
));
1183 function handler_admin_member_del($page, $user = null
)
1185 $page->changeTpl('xnetgrp/membres-del.tpl');
1186 $user = User
::getSilent($user);
1188 return PL_NOT_FOUND
;
1193 if (!$user->inGroup($globals->asso('id'))) {
1194 pl_redirect('annuaire');
1197 $page->assign('self', false
);
1198 $page->assign('user', $user);
1200 if (!Post
::has('confirm')) {
1203 S
::assert_xsrf_token();
1206 $hasSingleGroup = ($user->groupCount() == 1);
1208 if ($this->unsubscribe($user)) {
1209 $page->trigSuccess("{$user->fullName()} a été désinscrit du groupe !");
1211 $page->trigWarning("{$user->fullName()} a été désinscrit du groupe, mais des erreurs subsistent !");
1214 // If user is of type xnet account and this was her last group, disable the account.
1215 if ($user->type
== 'xnet' && $hasSingleGroup) {
1220 private function changeLogin(PlPage
$page, PlUser
$user, $login, $req_broken = false
, $req_marketing = false
, $marketing_from = 'user')
1222 // Search the user's uid.
1223 $xuser = User
::getSilent($login);
1225 $accounts = User
::getPendingAccounts($login);
1227 $page->trigError("L'identifiant $login ne correspond à aucun X.");
1229 } else if (count($accounts) > 1) {
1230 $page->trigError("L'identifiant $login correspond à plusieurs camarades.");
1233 $xuser = User
::getSilent($accounts[0]['uid']);
1240 // Market or suggest new redirection if required.
1241 $email = $user->bestEmail();
1243 $valid = new BrokenReq(S
::user(), $xuser, $email, 'Groupe : ' . Platal
::globals()->asso('nom'));
1245 } elseif ($req_marketing) {
1246 $market = Marketing
::get($xuser->uid
, $email);
1248 $market = new Marketing($xuser->uid
, $email, 'group', Platal
::globals()->asso('nom'), $marketing_from, S
::i('uid'));
1253 if ($user->mergeIn($xuser)) {
1254 return $xuser->login();
1256 return $user->login();
1259 function handler_admin_member($page, $user)
1263 $user = User
::getSilent($user);
1265 return PL_NOT_FOUND
;
1268 if (!$user->inGroup($globals->asso('id'))) {
1269 pl_redirect('annuaire');
1272 $page->changeTpl('xnetgrp/membres-edit.tpl');
1273 $page->addJsLink('xnet_members.js');
1275 $mmlist = new MMList(S
::user(), $globals->asso('mail_domain'));
1277 if (Post
::has('change')) {
1278 S
::assert_xsrf_token();
1279 require_once 'emails.inc.php';
1280 require_once 'name.func.inc.php';
1282 // Convert user status to X
1283 if (!Post
::blank('x')) {
1284 $forlife = $this->changeLogin($page, $user, Post
::i('userid'), Post
::b('broken'), Post
::b('marketing'), Post
::v('marketing_from'));
1286 pl_redirect('member/' . $forlife);
1291 if ($user->type
== 'virtual' ||
($user->type
== 'xnet' && !$user->perms
)) {
1292 $lastname = capitalize_name(Post
::t('lastname'));
1293 if (Post
::s('type') != 'virtual') {
1294 $firstname = capitalize_name(Post
::t('firstname'));
1298 $full_name = build_full_name($firstname, $lastname);
1299 $directory_name = build_directory_name($firstname, $lastname);
1300 $sort_name = build_sort_name($firstname, $lastname);
1301 XDB
::query('UPDATE accounts
1302 SET full_name = {?}, directory_name = {?}, sort_name = {?}, display_name = {?},
1303 firstname = {?}, lastname = {?}, sex = {?}, type = {?}
1305 $full_name, $directory_name, $sort_name, Post
::t('display_name'), $firstname, $lastname,
1306 (Post
::t('sex') == 'male') ?
'male' : 'female',
1307 (Post
::t('type') == 'xnet') ?
'xnet' : 'virtual', $user->id());
1311 $new_email = strtolower(Post
::t('email'));
1312 if (($user->type
== 'virtual' ||
($user->type
== 'xnet' && !$user->perms
))
1313 && require_email_update($user, $new_email)) {
1314 XDB
::query('UPDATE accounts
1317 $new_email, $user->id());
1318 if ($user->forlifeEmail()) {
1319 $listClient = new MMList(S
::user());
1320 $listClient->change_user_email($user->forlifeEmail(), $new_email);
1321 update_alias_user($user->forlifeEmail(), $new_email);
1323 $user = User
::getWithUID($user->id());
1325 if (XDB
::affectedRows()) {
1326 $page->trigSuccess('Données de l\'utilisateur mises à jour.');
1329 if (($user->type
== 'xnet' && !$user->perms
)) {
1330 if (Post
::b('suggest')) {
1331 $request = new AccountReq(S
::user(), $user->hruid
, Post
::t('email'), $globals->asso('nom'), $globals->asso('diminutif'));
1333 $page->trigSuccess('Le compte va bientôt être activé.');
1335 if (Post
::b('again')) {
1336 $data = XDB
::fetchOneAssoc('SELECT hash, group_name, sender_name, email
1337 FROM register_pending_xnet
1341 $mailer = new PlMailer('xnet/account.mail.tpl');
1342 $mailer->addCc('validation+xnet_account@polytechnique.org');
1343 $mailer->setTo($data['email']);
1344 $mailer->assign('hash', $data['hash']);
1345 $mailer->assign('email', $data['email']);
1346 $mailer->assign('group', $data['group_name']);
1347 $mailer->assign('sender_name', $data['sender_name']);
1348 $mailer->assign('again', true
);
1349 $mailer->assign('baseurl', Platal
::globals()->xnet
->xorg_baseurl
);
1351 $page->trigSuccess('Relance effectuée avec succès.');
1355 // Update group params for user
1356 $perms = Post
::v('group_perms');
1357 $comm = Post
::t('comm');
1358 $position = (Post
::t('group_position') == '') ? null
: Post
::v('group_position');
1359 if ($user->group_perms
!= $perms ||
$user->group_comm
!= $comm ||
$user->group_position
!= $position) {
1360 XDB
::query('UPDATE group_members
1361 SET perms = {?}, comm = {?}, position = {?}
1362 WHERE uid = {?} AND asso_id = {?}',
1363 ($perms == 'admin') ?
'admin' : 'membre', $comm, $position,
1364 $user->id(), $globals->asso('id'));
1365 if (XDB
::affectedRows()) {
1366 if ($perms != $user->group_perms
) {
1367 $page->trigSuccess('Permissions modifiées !');
1369 if ($comm != $user->group_comm
) {
1370 $page->trigSuccess('Commentaire mis à jour.');
1372 if ($position != $user->group_position
) {
1373 $page->trigSuccess('Poste mis à jour.');
1378 // Gets user info again as they might have change
1379 $user = User
::getSilent($user->id());
1381 // Update ML subscriptions
1382 foreach (Env
::v('ml1', array()) as $ml => $state) {
1383 $ask = empty($_REQUEST['ml2'][$ml]) ?
0 : 2;
1384 if ($ask == $state) {
1387 if ($state == '1') {
1388 $page->trigWarning("{$user->fullName()} a "
1389 ."actuellement une demande d'inscription en "
1390 ."cours sur <strong>$ml@</strong> !!!");
1392 $mmlist->mass_subscribe($ml, Array($user->forlifeEmail()));
1393 $page->trigSuccess("{$user->fullName()} a été abonné à $ml@.");
1395 $mmlist->mass_unsubscribe($ml, Array($user->forlifeEmail()));
1396 $page->trigSuccess("{$user->fullName()} a été désabonné de $ml@.");
1400 // Change subscriptioin to aliases
1401 foreach (Env
::v('ml3', array()) as $ml => $state) {
1402 require_once 'emails.inc.php';
1403 $ask = !empty($_REQUEST['ml4'][$ml]);
1404 list($local_part, ) = explode('@', $ml);
1405 if ($ask == $state) {
1409 add_to_list_alias($user->id(), $local_part, $globals->asso('mail_domain'));
1410 $page->trigSuccess("{$user->fullName()} a été abonné à $ml.");
1412 delete_from_list_alias($user->id(), $local_part, $globals->asso('mail_domain'));
1413 $page->trigSuccess("{$user->fullName()} a été désabonné de $ml.");
1417 if ($globals->asso('has_nl')) {
1418 $nl = NewsLetter
::forGroup($globals->asso('shortname'));
1419 // Updates group's newsletter subscription.
1420 if (Post
::i('newsletter') == 1) {
1421 $nl->subscribe($user);
1423 $nl->unsubscribe(null
, $user->id());
1428 $res = XDB
::rawFetchAllAssoc('SHOW COLUMNS FROM group_members LIKE \'position\'');
1429 $positions = str_replace(array('enum(', ')', '\''), '', $res[0]['Type']);
1430 if ($globals->asso('has_nl')) {
1431 $nl = NewsLetter
::forGroup($globals->asso('shortname'));
1432 $nl_registered = $nl->subscriptionState($user);
1434 $nl_registered = false
;
1437 $page->assign('user', $user);
1438 $page->assign('suggest', $this->suggest($user));
1439 $page->assign('listes', $mmlist->get_lists($user->forlifeEmail()));
1440 $page->assign('alias', $user->emailGroupAliases($globals->asso('mail_domain')));
1441 $page->assign('positions', explode(',', $positions));
1442 $page->assign('nl_registered', $nl_registered);
1443 $page->assign('pending_xnet_account', XDB
::fetchOneCell('SELECT 1
1444 FROM register_pending_xnet
1449 function handler_rss(PlPage
$page, PlUser
$user)
1452 $page->assign('asso', $globals->asso());
1454 $this->load('feed.inc.php');
1455 $feed = new XnetGrpEventFeed();
1456 return $feed->run($page, $user, false
);
1459 private function upload_image(PlPage
$page, PlUpload
$upload)
1461 if (@!$_FILES['image']['tmp_name'] && !Env
::v('image_url')) {
1464 if (!$upload->upload($_FILES['image']) && !$upload->download(Env
::v('image_url'))) {
1465 $page->trigError('Impossible de télécharger l\'image');
1467 } elseif (!$upload->isType('image')) {
1468 $page->trigError('Le fichier n\'est pas une image valide au format JPEG, GIF ou PNG.');
1471 } elseif (!$upload->resizeImage(80, 100, 100, 100, 32284)) {
1472 $page->trigError('Impossible de retraiter l\'image');
1478 function handler_photo_announce($page, $eid = null
) {
1480 $res = XDB
::query('SELECT *
1481 FROM group_announces_photo
1482 WHERE eid = {?}', $eid);
1483 if ($res->numRows()) {
1484 $photo = $res->fetchOneAssoc();
1485 pl_cached_dynamic_content_headers("image/" . $photo['attachmime']);
1486 echo $photo['attach'];
1490 $upload = new PlUpload(S
::user()->login(), 'xnetannounce');
1491 if ($upload->exists() && $upload->isType('image')) {
1492 pl_cached_dynamic_content_headers($upload->contentType());
1493 echo $upload->getContents();
1498 pl_cached_dynamic_content_headers("image/png");
1499 echo file_get_contents($globals->spoolroot
. '/htdocs/images/logo.png');
1503 function handler_edit_announce($page, $aid = null
)
1505 global $globals, $platal;
1506 $page->changeTpl('xnetgrp/announce-edit.tpl');
1507 $page->assign('new', is_null($aid));
1510 if (Post
::v('valid') == 'Visualiser' || Post
::v('valid') == 'Enregistrer'
1511 || Post
::v('valid') == 'Supprimer l\'image' || Post
::v('valid') == 'Pas d\'image') {
1512 S
::assert_xsrf_token();
1514 if (!is_null($aid)) {
1517 $art['titre'] = Post
::v('titre');
1518 $art['texte'] = Post
::v('texte');
1519 $art['contacts'] = Post
::v('contacts');
1520 $art['promo_min'] = Post
::i('promo_min');
1521 $art['promo_max'] = Post
::i('promo_max');
1522 $art['nom'] = S
::v('nom');
1523 $art['prenom'] = S
::v('prenom');
1524 $art['promo'] = S
::v('promo');
1525 $art['hruid'] = S
::user()->login();
1526 $art['uid'] = S
::user()->id();
1527 $art['expiration'] = Post
::v('expiration');
1528 $art['public'] = Post
::has('public');
1529 $art['xorg'] = Post
::has('xorg');
1530 $art['nl'] = Post
::has('nl');
1531 $art['event'] = Post
::v('event');
1532 $upload = new PlUpload(S
::user()->login(), 'xnetannounce');
1533 $this->upload_image($page, $upload);
1535 $art['contact_html'] = $art['contacts'];
1536 if ($art['event']) {
1537 $art['contact_html'] .= "\n{$globals->baseurl}/{$platal->ns}events/sub/{$art['event']}";
1540 if (!$art['public'] &&
1541 (($art['promo_min'] > $art['promo_max'] && $art['promo_max'] != 0) ||
1542 ($art['promo_min'] != 0 && ($art['promo_min'] <= 1900 ||
$art['promo_min'] >= 2020)) ||
1543 ($art['promo_max'] != 0 && ($art['promo_max'] <= 1900 ||
$art['promo_max'] >= 2020))))
1545 $page->trigError("L'intervalle de promotions est invalide.");
1546 Post
::kill('valid');
1549 if (!trim($art['titre']) ||
!trim($art['texte'])) {
1550 $page->trigError("L'article doit avoir un titre et un contenu.");
1551 Post
::kill('valid');
1554 if (Post
::v('valid') == 'Supprimer l\'image') {
1556 Post
::kill('valid');
1558 $art['photo'] = $upload->exists() || Post
::i('photo');
1559 if (Post
::v('valid') == 'Pas d\'image' && !is_null($aid)) {
1560 XDB
::query('DELETE FROM group_announces_photo
1561 WHERE eid = {?}', $aid);
1563 Post
::kill('valid');
1564 $art['photo'] = false
;
1568 if (Post
::v('valid') == 'Enregistrer') {
1569 $promo_min = ($art['public'] ?
0 : $art['promo_min']);
1570 $promo_max = ($art['public'] ?
0 : $art['promo_max']);
1571 $flags = new PlFlagSet();
1572 if ($art['public']) {
1573 $flags->addFlag('public');
1575 if ($art['photo']) {
1576 $flags->addFlag('photo');
1578 if (is_null($aid)) {
1579 $fulltext = $art['texte'];
1580 if (!empty($art['contact_html'])) {
1581 $fulltext .= "\n\n'''Contacts :'''\\\\\n" . $art['contact_html'];
1584 if ($globals->asso('forum')) {
1585 require_once 'banana/forum.inc.php';
1586 $banana = new ForumsBanana(S
::user());
1587 $post = $banana->post($globals->asso('forum'), null
,
1588 $art['titre'], MiniWiki
::wikiToText($fulltext, false
, 0, 80));
1590 XDB
::query('INSERT INTO group_announces (uid, asso_id, create_date, titre, texte, contacts,
1591 expiration, promo_min, promo_max, flags, post_id)
1592 VALUES ({?}, {?}, NOW(), {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})',
1593 S
::i('uid'), $globals->asso('id'), $art['titre'], $art['texte'], $art['contact_html'],
1594 $art['expiration'], $promo_min, $promo_max, $flags, $post);
1595 $aid = XDB
::insertId();
1596 if ($art['photo']) {
1597 list($imgx, $imgy, $imgtype) = $upload->imageInfo();
1598 XDB
::execute('INSERT INTO group_announces_photo
1599 SET eid = {?}, attachmime = {?}, x = {?}, y = {?}, attach = {?}',
1600 $aid, $imgtype, $imgx, $imgy, $upload->getContents());
1603 $article = new EvtReq("[{$globals->asso('nom')}] " . $art['titre'], $fulltext,
1604 $art['promo_min'], $art['promo_max'], $art['expiration'], "", S
::user(),
1607 $page->trigWarning("L'affichage sur la page d'accueil de Polytechnique.org est en attente de validation.");
1608 } else if ($upload && $upload->exists()) {
1612 $article = new NLReq(S
::user(), $globals->asso('nom') . " : " .$art['titre'],
1613 $art['texte'], $art['contact_html']);
1615 $page->trigWarning("La parution dans la Lettre Mensuelle est en attente de validation.");
1618 XDB
::query('UPDATE group_announces
1619 SET titre = {?}, texte = {?}, contacts = {?}, expiration = {?},
1620 promo_min = {?}, promo_max = {?}, flags = {?}
1621 WHERE id = {?} AND asso_id = {?}',
1622 $art['titre'], $art['texte'], $art['contacts'], $art['expiration'],
1623 $promo_min, $promo_max, $flags,
1624 $art['id'], $globals->asso('id'));
1625 if ($art['photo'] && $upload->exists()) {
1626 list($imgx, $imgy, $imgtype) = $upload->imageInfo();
1627 XDB
::execute('INSERT INTO group_announces_photo (eid, attachmime, attach, x, y)
1628 VALUES ({?}, {?}, {?}, {?}, {?})
1629 ON DUPLICATE KEY UPDATE attachmime = VALUES(attachmime), attach = VALUES(attach), x = VALUES(x), y = VALUES(y)',
1630 $aid, $imgtype, $upload->getContents(), $imgx, $imgy);
1635 if (Post
::v('valid') == 'Enregistrer' || Post
::v('valid') == 'Annuler') {
1639 if (empty($art) && !is_null($aid)) {
1640 $res = XDB
::query("SELECT *, FIND_IN_SET('public', flags) AS public,
1641 FIND_IN_SET('photo', flags) AS photo
1642 FROM group_announces
1643 WHERE asso_id = {?} AND id = {?}",
1644 $globals->asso('id'), $aid);
1645 if ($res->numRows()) {
1646 $art = $res->fetchOneAssoc();
1647 $art['contact_html'] = $art['contacts'];
1649 $page->kill("Aucun article correspond à l'identifiant indiqué.");
1653 if (is_null($aid)) {
1654 $events = XDB
::iterator("SELECT *
1656 WHERE asso_id = {?} AND archive = 0",
1657 $globals->asso('id'));
1658 if ($events->total()) {
1659 $page->assign('events', $events);
1663 $art['contact_html'] = @MiniWiki
::WikiToHTML($art['contact_html']);
1664 $page->assign('art', $art);
1665 $page->assign_by_ref('upload', $upload);
1668 function handler_admin_announce($page)
1671 $page->changeTpl('xnetgrp/announce-admin.tpl');
1673 if (Env
::has('del')) {
1674 S
::assert_xsrf_token();
1675 XDB
::execute('DELETE FROM group_announces
1676 WHERE id = {?} AND asso_id = {?}',
1677 Env
::i('del'), $globals->asso('id'));
1679 $res = XDB
::iterator('SELECT id, titre, expiration, expiration < CURRENT_DATE() AS perime
1680 FROM group_announces
1682 ORDER BY expiration DESC',
1683 $globals->asso('id'));
1684 $page->assign('articles', $res);
1688 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: