2 /***************************************************************************
3 * Copyright (C) 2003-2014 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
, 'groupannu'),
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/directory/awact' => $this->make_hook('awaiting_active', AUTH_PASSWD
, 'groupadmin'),
42 '%grp/trombi' => $this->make_hook('trombi', AUTH_PASSWD
, 'groupannu'),
43 '%grp/geoloc' => $this->make_hook('geoloc', AUTH_PASSWD
, 'groupannu'),
44 '%grp/subscribe' => $this->make_hook('subscribe', AUTH_PASSWD
, 'groups'),
45 '%grp/subscribe/valid' => $this->make_hook('subscribe_valid', AUTH_PASSWD
, 'groupadmin'),
46 '%grp/unsubscribe' => $this->make_hook('unsubscribe', AUTH_PASSWD
, 'groupmember'),
48 '%grp/change_rights' => $this->make_hook('change_rights', AUTH_PASSWD
, 'groups'),
49 '%grp/admin/annuaire' => $this->make_hook('admin_annuaire', AUTH_PASSWD
, 'groupadmin'),
50 '%grp/member' => $this->make_hook('admin_member', AUTH_PASSWD
, 'groupadmin'),
51 '%grp/member/new' => $this->make_hook('admin_member_new', AUTH_PASSWD
, 'groupadmin'),
52 '%grp/member/new/ajax' => $this->make_hook('admin_member_new_ajax', AUTH_PASSWD
, 'groups', NO_AUTH
),
53 '%grp/member/del' => $this->make_hook('admin_member_del', AUTH_PASSWD
, 'groupadmin'),
54 '%grp/member/suggest' => $this->make_hook('admin_member_suggest', AUTH_PASSWD
, 'groupadmin'),
55 '%grp/member/reg' => $this->make_hook('admin_member_reg', AUTH_PASSWD
, 'groupadmin'),
57 '%grp/rss' => $this->make_token_hook('rss', AUTH_PUBLIC
),
58 '%grp/announce/new' => $this->make_hook('edit_announce', AUTH_PASSWD
, 'groupadmin'),
59 '%grp/announce/edit' => $this->make_hook('edit_announce', AUTH_PASSWD
, 'groupadmin'),
60 '%grp/announce/photo' => $this->make_hook('photo_announce', AUTH_PUBLIC
),
61 '%grp/admin/announces' => $this->make_hook('admin_announce', AUTH_PASSWD
, 'groupadmin'),
65 function handler_index($page, $arg = null
)
67 global $globals, $platal;
71 $page->changeTpl('xnetgrp/asso.tpl');
74 if (Env
::has('read')) {
75 XDB
::query('DELETE r.*
76 FROM group_announces_read AS r
77 INNER JOIN group_announces AS a ON (a.id = r.announce_id)
78 WHERE expiration < CURRENT_DATE()');
79 XDB
::query('INSERT INTO group_announces_read
81 Env
::i('read'), S
::i('uid'));
84 if (Env
::has('unread')) {
85 XDB
::query('DELETE FROM group_announces_read
86 WHERE announce_id = {?} AND uid = {?}',
87 Env
::i('unread'), S
::i('uid'));
88 pl_redirect("#art" . Env
::i('unread'));
91 /* TODO: refines this filter on promotions by using userfilter. */
93 if ($user->hasProfile()) {
94 $promo = XDB
::format('{?}', $user->profile()->entry_year
);
95 $minCondition = ' OR promo_min <= ' . $promo;
96 $maxCondition = ' OR promo_max >= ' . $promo;
101 $arts = XDB
::iterator('SELECT a.*, FIND_IN_SET(\'photo\', a.flags) AS photo
102 FROM group_announces AS a
103 LEFT JOIN group_announces_read AS r ON (r.uid = {?} AND r.announce_id = a.id)
104 WHERE asso_id = {?} AND expiration >= CURRENT_DATE()
105 AND (promo_min = 0' . $minCondition . ')
106 AND (promo_max = 0' . $maxCondition . ')
107 AND r.announce_id IS NULL
108 ORDER BY a.expiration',
109 S
::i('uid'), $globals->asso('id'));
110 $index = XDB
::iterator('SELECT a.id, a.titre, r.uid IS NULL AS nonlu
111 FROM group_announces AS a
112 LEFT JOIN group_announces_read AS r ON (a.id = r.announce_id AND r.uid = {?})
113 WHERE asso_id = {?} AND expiration >= CURRENT_DATE()
114 AND (promo_min = 0' . $minCondition . ')
115 AND (promo_max = 0' . $maxCondition . ')
116 ORDER BY a.expiration',
117 S
::i('uid'), $globals->asso('id'));
118 $page->assign('article_index', $index);
120 $arts = XDB
::iterator("SELECT *, FIND_IN_SET('photo', flags) AS photo
122 WHERE asso_id = {?} AND expiration >= CURRENT_DATE()
123 AND FIND_IN_SET('public', flags)",
124 $globals->asso('id'));
125 $payments = XDB
::fetchAllAssoc("SELECT id, text
127 WHERE asso_id = {?} AND NOT FIND_IN_SET('old', flags) AND FIND_IN_SET('public', flags)
129 $globals->asso('id'));
130 $page->assign('payments', $payments);
133 $subs_valid = XDB
::query("SELECT uid
134 FROM group_member_sub_requests
135 WHERE asso_id = {?}",
136 $globals->asso('id'));
137 $page->assign('requests', $subs_valid->numRows());
140 if (!S
::hasAuthToken()) {
141 $page->setRssLink("Polytechnique.net :: {$globals->asso("nom
")} :: News publiques",
142 $platal->ns
. "rss/rss.xml");
144 $page->setRssLink("Polytechnique.net :: {$globals->asso("nom
")} :: News",
145 $platal->ns
. 'rss/' . S
::v('hruid') . '/' . S
::user()->token
. '/rss.xml');
148 $page->assign('articles', $arts);
151 function handler_logo($page)
154 $globals->asso()->getLogo()->send();
157 function handler_site($page)
160 $site = $globals->asso('site');
162 $page->trigError('Le groupe n\'a pas de site web.');
163 return $this->handler_index($page);
165 http_redirect($site);
169 function handler_edit($page)
172 $page->changeTpl('xnetgrp/edit.tpl');
176 $domains = XDB
::iterator('SELECT *
179 $page->assign('domains', $domains);
180 $page->assign('super', true
);
183 if (Post
::has('submit')) {
184 S
::assert_xsrf_token();
186 $flags = new PlFlagSet('wiki_desc');
187 $flags->addFlag('notif_unsub', Post
::i('notif_unsub') == 1);
188 $site = Post
::t('site');
189 if ($site && ($site != "http://")) {
190 $scheme = parse_url($site, PHP_URL_SCHEME
);
192 $site = "http://" . $site;
198 $notify_all = (Post
::v('notify_all') ? true
: false
);
200 $to_notify = array();
201 $uf = New UserFilter(New UFC_Group($globals->asso('id'), true
));
202 $uids = $uf->getIds();
203 foreach ($uids as $uid) {
204 if (Post
::b('to_notify_' . $uid)) {
208 if (count($to_notify) == 0) {
210 $page->trigWarning("Aucun animateur n'ayant été selectionné pour recevoir les demandes d'inscriptions, tous le seront.");
213 $flags->addFlag('notify_all', $notify_all);
216 $page->assign('super', true
);
218 if (Post
::v('mail_domain') && (strstr(Post
::v('mail_domain'), '.') === false
)) {
219 $page->trigError('Le domaine doit être un FQDN (aucune modification effectuée) !!!');
222 if (Post
::t('nom') == '' || Post
::t('diminutif') == '') {
223 $page->trigError('Ni le nom ni le diminutif du groupe ne peuvent être vide.');
227 $page->assign('nom', Post
::t('nom'));
228 $page->assign('diminutif', Post
::t('diminutif'));
229 $page->assign('mail_domain', Post
::t('mail_domain'));
230 $page->assign('cat', Post
::v('cat'));
231 $page->assign('dom', Post
::v('dom'));
232 $page->assign('ax', Post
::v('ax'));
233 $page->assign('axDate', Post
::t('axDate'));
234 $page->assign('site', $site);
235 $page->assign('resp', Post
::t('resp'));
236 $page->assign('mail', Post
::t('mail'));
237 $page->assign('phone', Post
::t('phone'));
238 $page->assign('fax', Post
::t('fax'));
239 $page->assign('address', Post
::t('address'));
240 $page->assign('forum', Post
::t('forum'));
241 $page->assign('inscriptible', Post
::v('inscriptible'));
242 $page->assign('sub_url', Post
::t('sub_url'));
243 $page->assign('unsub_url', Post
::t('unsub_url'));
244 $page->assign('welcome_msg', Post
::t('welcome_msg'));
245 $page->assign('pub', Post
::v('pub'));
246 $page->assign('notif_unsub', Post
::i('notif_unsub'));
247 $page->assign('descr', Post
::t('descr'));
248 $page->assign('disable_mails', Post
::b('disable_mails'));
249 $page->assign('error', $error);
253 $axDate = make_datetime(Post
::v('axDate'));
254 if (Post
::t('axDate') != '') {
255 $axDate = make_datetime(Post
::v('axDate'))->format('Y-m-d');
261 SET nom={?}, diminutif={?}, cat={?}, dom={?},
262 descr={?}, site={?}, mail={?}, resp={?},
263 forum={?}, mail_domain={?}, ax={?}, axDate = {?}, pub={?},
264 sub_url={?}, inscriptible={?}, unsub_url={?},
265 flags = {?}, welcome_msg = {?}, disable_mails = {?}
267 Post
::v('nom'), Post
::v('diminutif'),
268 Post
::v('cat'), (Post
::i('dom') == 0) ? null
: Post
::i('dom'),
269 Post
::v('descr'), $site,
270 Post
::v('mail'), Post
::v('resp'),
271 Post
::v('forum'), Post
::v('mail_domain'),
272 Post
::has('ax'), $axDate, Post
::v('pub'),
273 Post
::v('sub_url'), Post
::v('inscriptible'),
274 Post
::v('unsub_url'), $flags, Post
::t('welcome_msg'),
275 Post
::b('disable_mails'),
276 $globals->asso('id'));
277 if (Post
::v('mail_domain')) {
278 XDB
::execute('INSERT IGNORE INTO email_virtual_domains (name)
280 Post
::t('mail_domain'));
281 XDB
::execute('UPDATE email_virtual_domains
284 Post
::t('mail_domain'));
289 SET descr={?}, site={?}, mail={?}, resp={?},
290 forum={?}, pub= {?}, sub_url={?},
291 unsub_url = {?}, flags = {?}, welcome_msg = {?}
293 Post
::v('descr'), $site,
294 Post
::v('mail'), Post
::v('resp'),
295 Post
::v('forum'), Post
::v('pub'),
296 Post
::v('sub_url'), Post
::v('unsub_url'),
297 $flags, Post
::t('welcome_msg'),
298 $globals->asso('id'));
301 Phone
::deletePhones(0, Phone
::LINK_GROUP
, $globals->asso('id'));
302 $phone = new Phone(array('link_type' => 'group', 'link_id' => $globals->asso('id'), 'id' => 0,
303 'type' => 'fixed', 'display' => Post
::v('phone'), 'pub' => 'public'));
304 $fax = new Phone(array('link_type' => 'group', 'link_id' => $globals->asso('id'), 'id' => 1,
305 'type' => 'fax', 'display' => Post
::v('fax'), 'pub' => 'public'));
308 Address
::deleteAddresses(null
, Address
::LINK_GROUP
, null
, $globals->asso('id'));
309 $address = new Address(array('groupid' => $globals->asso('id'), 'type' => Address
::LINK_GROUP
, 'text' => Post
::v('address')));
312 if ($_FILES['logo']['name']) {
313 $upload = PlUpload
::get($_FILES['logo'], $globals->asso('id'), 'asso.logo', true
);
315 $page->trigError("Impossible de télécharger le logo.");
317 XDB
::execute('UPDATE groups
318 SET logo = {?}, logo_mime = {?}
319 WHERE id = {?}', $upload->getContents(), $upload->contentType(),
320 $globals->asso('id'));
325 XDB
::execute("UPDATE group_members
327 WHERE asso_id = {?}",
328 $globals->asso('id'));
330 XDB
::execute("UPDATE group_members
332 WHERE asso_id = {?} AND uid IN {?}",
333 $globals->asso('id'), $to_notify);
336 pl_redirect('../' . Post
::v('diminutif', $globals->asso('diminutif')) . '/edit');
339 $uf = New UserFilter(New UFC_Group($globals->asso('id'), true
, UFC_Group
::NOTIFIED
));
340 $page->assign('notified', $uf->getUsers());
341 $uf = New UserFilter(New UFC_Group($globals->asso('id'), true
, UFC_Group
::UNNOTIFIED
));
342 $page->assign('unnotified', $uf->getUsers());
344 $page->assign('error', $error);
345 $page->assign('cat', $globals->asso('cat'));
346 $page->assign('dom', $globals->asso('dom'));
347 $page->assign('ax', $globals->asso('ax'));
348 $page->assign('inscriptible', $globals->asso('inscriptible'));
349 $page->assign('pub', $globals->asso('pub'));
350 $page->assign('notif_unsub', $globals->asso('notif_unsub'));
351 $page->assign('notify_all', $globals->asso('notify_all'));
352 $page->assign('disable_mails', $globals->asso('disable_mails'));
355 function handler_mail($page)
358 if ($globals->asso('disable_mails')) {
362 $page->changeTpl('xnetgrp/mail.tpl');
363 $mmlist = new MMList(S
::user(), $globals->asso('mail_domain'));
364 $page->assign('listes', $mmlist->get_lists());
365 $page->assign('user', S
::user());
367 if (Post
::has('send')) {
368 S
::assert_xsrf_token();
369 $from = Post
::v('from');
370 $sujet = Post
::v('sujet');
371 $body = Post
::v('body');
373 $mls = array_keys(Env
::v('ml', array()));
374 $mbr = array_keys(Env
::v('membres', array()));
376 $this->load('mail.inc.php');
378 $tos = get_all_redirects($mbr, $mls, $mmlist);
380 $upload = PlUpload
::get($_FILES['uploaded'], S
::user()->login(), 'xnet.emails', true
);
381 if (!$upload && @$_FILES['uploaded']['name'] && PlUpload
::$lastError != null
) {
382 $page->trigError(PlUpload
::$lastError);
386 send_xnet_mails($from, $sujet, $body, Env
::v('wiki'), $tos, Post
::v('replyto'), $upload, @$_FILES['uploaded']['name']);
390 $page->killSuccess("Email envoyé !");
391 $page->assign('sent', true
);
395 function handler_forum($page, $group = null
, $artid = null
)
398 $page->changeTpl('xnetgrp/forum.tpl');
399 if (!$globals->asso('forum')) {
402 require_once 'banana/forum.inc.php';
404 get_banana_params($get, $globals->asso('forum'), $group, $artid);
405 run_banana($page, 'ForumsBanana', $get);
408 function handler_annuaire($page, $action = null
, $subaction = null
)
412 __autoload('userset');
414 if ($action == 'admins') {
416 $action = $subaction;
418 $view = new UserSet(new UFC_Group($globals->asso('id'), $admins));
419 $view->addMod('groupmember', 'Annuaire');
420 $view->addMod('trombi', 'Trombinoscope');
421 $view->addMod('map', 'Planisphère');
422 $view->apply('annuaire', $page, $action);
423 $page->assign('only_admin', $admins);
424 $page->changeTpl('xnetgrp/annuaire.tpl');
427 function handler_former_users($page)
430 require_once 'userset.inc.php';
432 $view = new UserSet(new UFC_GroupFormerMember($globals->asso('id')));
433 $view->addMod('groupmember', 'Anciens membres', true
, array('noadmin' => true
));
434 $view->apply('former_users', $page);
435 $page->changeTpl('xnetgrp/former_users.tpl');
438 function handler_trombi($page)
440 pl_redirect('annuaire/trombi');
443 function handler_geoloc($page)
445 pl_redirect('annuaire/geoloc');
448 function handler_vcard($page, $photos = null
)
451 $vcard = new VCard($photos == 'photos', 'Membre du groupe ' . $globals->asso('nom'));
452 $vcard->addProfiles($globals->asso()->getMembersFilter()->getProfiles(null
, Profile
::FETCH_ALL
));
456 function handler_csv($page, $filename = null
)
459 if (is_null($filename)) {
460 $filename = $globals->asso('diminutif') . '.csv';
462 $users = $globals->asso()->getMembersFilter(null
, new UFO_Name())->getUsers();
463 $admin = may_update();
464 pl_cached_content_headers('text/x-csv', 'iso-8859-1', 1);
466 echo utf8_decode("Nom;Prénom;Sexe;Promotion;Commentaire");
468 echo utf8_decode(";Société;Poste\n");
470 echo utf8_decode("\n");
472 foreach ($users as $user) {
473 $line = $user->lastName() . ';' . $user->firstName() . ';' . ($user->isFemale() ?
'F' : 'M')
474 . ';' . $user->promo() . ';' . strtr($user->group_comm
, ';', ',');
476 if ($user->hasProfile()) {
477 $line .= ';' . $user->profile()->getMainJob()->company
->name
. ';' . $user->profile()->getMainJob()->description
;
482 echo utf8_decode($line) . "\n";
487 function handler_directory_sync($page)
490 require_once 'emails.inc.php';
492 $page->changeTpl('xnetgrp/sync.tpl');
493 Platal
::load('lists', 'lists.inc.php');
495 if (Env
::has('add_users')) {
496 S
::assert_xsrf_token();
498 $users = array_keys(Env
::v('add_users'));
499 $former_users = XDB
::fetchColumn('SELECT uid
500 FROM group_former_members
501 WHERE remember = TRUE AND asso_id = {?} AND uid IN {?}',
502 $globals->asso('id'), $users);
503 $new_users = array_diff($users, $former_users);
505 foreach ($former_users as $uid) {
506 $user = User
::getSilentWithUID($uid);
507 $page->trigWarning($user->fullName() . ' est un ancien membre du groupe qui ne souhaite pas y revenir.');
509 if (count($former_users) > 1) {
510 $page->trigWarning('S\'ils souhaitent revenir dans le groupe, il faut qu\'ils en fassent la demande sur la page d\'accueil du groupe.');
511 } elseif (count($former_users)) {
512 $page->trigWarning('S\'il souhaite revenir dans le groupe, il faut qu\'il en fasse la demande sur la page d\'accueil du groupe.');
516 foreach ($new_users as $uid) {
517 Group
::subscribe($globals->asso('id'), $uid);
521 if (Env
::has('add_nonusers')) {
522 S
::assert_xsrf_token();
524 $nonusers = array_keys(Env
::v('add_nonusers'));
525 foreach ($nonusers as $email) {
526 if ($user = User
::getSilent($email) ||
!isvalid_email($email)) {
530 list($local_part, $domain) = explode('@', strtolower($email));
531 $hruid = User
::makeHrid($local_part, $domain, 'ext');
532 if ($user = User
::getSilent($hruid)) {
536 require_once 'name.func.inc.php';
537 $parts = explode('.', $local_part);
538 if (count($parts) == 1) {
539 $lastname = $display_name = capitalize_name($mbox);
542 $display_name = $firstname = capitalize_name($parts[0]);
543 $lastname = capitalize_name(implode(' ', array_slice($parts, 1)));
545 $full_name = build_full_name($firstname, $lastname);
546 $directory_name = build_directory_name($firstname, $lastname);
547 $sort_name = build_sort_name($firstname, $lastname);
548 XDB
::execute('INSERT INTO accounts (hruid, display_name, full_name, directory_name, sort_name,
549 firstname, lastname, email, type, state)
550 VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, \'xnet\', \'disabled\')',
551 $hruid, $display_name, $full_name, $directory_name, $sort_name, $firstname, $lastname, $email);
552 $uid = XDB
::insertId();
553 Group
::subscribe($globals->asso('id'), $uid);
557 if (Env
::has('add_users') || Env
::has('add_nonusers')) {
558 $page->trigSuccess('Ajouts réalisés avec succès.');
562 $client = new MMList($user, $globals->asso('mail_domain'));
563 $lists = $client->get_lists();
565 foreach ($lists as $list) {
566 $details = $client->get_members($list['list']);
567 $members = array_merge($members, list_extract_members($details[1]));
569 $members = array_unique($members);
573 foreach ($members as $email) {
574 if ($user = User
::getSilent($email)) {
575 $uids[] = $user->id();
577 $nonusers[] = $email;
581 $aliases = iterate_list_alias($globals->asso('mail_domain'));
582 foreach ($aliases as $alias) {
583 list($local_part, $domain) = explode('@', $alias);
584 $aliases_members = list_alias_members($local_part, $domain);
585 $users = array_merge($users, $aliases_members['users']);
586 $nonusers = array_merge($nonusers, $aliases_members['nonusers']);
588 foreach ($users as $user) {
589 $uids[] = $user->id();
591 $nonusers = array_unique($nonusers);
592 $uids = array_unique($uids);
594 $uids = XDB
::fetchColumn('SELECT a.uid
596 WHERE a.uid IN {?} AND NOT EXISTS (SELECT *
597 FROM group_members AS g
598 WHERE a.uid = g.uid AND g.asso_id = {?})',
599 $uids, $globals->asso('id'));
601 $users = User
::getBulkUsersWithUIDs($uids);
602 usort($users, 'User::compareDirectoryName');
608 $page->assign('users', $users);
609 $page->assign('nonusers', $nonusers);
612 function handler_non_active($page)
615 $page->changeTpl('xnetgrp/non_active.tpl');
617 $uids = XDB
::fetchColumn('SELECT g.uid
618 FROM group_members AS g
619 INNER JOIN accounts AS a ON (a.uid = g.uid)
620 LEFT JOIN register_pending_xnet AS p ON (p.uid = g.uid)
621 WHERE a.uid = g.uid AND g.asso_id = {?} AND a.type = \'xnet\' AND a.state = \'disabled\' AND p.uid IS NULL',
622 $globals->asso('id'));
623 foreach ($uids as $key => $uid) {
624 if (AccountReq
::isPending($uid) || BulkAccountsReq
::isPending($uid)) {
629 if (Post
::has('enable_accounts')) {
630 S
::assert_xsrf_token();
632 $uids_to_enable = array_intersect(array_keys(Post
::v('enable_accounts')), $uids);
635 $request = new BulkAccountsReq($user, $uids_to_enable, $globals->asso('nom'), $globals->asso('diminutif'));
637 $page->trigSuccess('Un email va bientôt être envoyé aux personnes sélectionnées pour l\'activation de leur compte.');
639 foreach ($uids as $key => $uid) {
640 if (in_array($uid, $uids_to_enable)) {
646 $users = User
::getBulkUsersWithUIDs($uids);
647 $page->assign('users', $users);
650 private function again($uid)
652 $data = XDB
::fetchOneAssoc('SELECT hash, group_name, sender_name, email
653 FROM register_pending_xnet
656 XDB
::execute('UPDATE register_pending_xnet
657 SET last_date = NOW()
661 $mailer = new PlMailer('xnet/account.mail.tpl');
662 $mailer->addCc('validation+xnet_account@polytechnique.org');
663 $mailer->setTo($data['email']);
664 $mailer->assign('hash', $data['hash']);
665 $mailer->assign('email', $data['email']);
666 $mailer->assign('group', $data['group_name']);
667 $mailer->assign('sender_name', $data['sender_name']);
668 $mailer->assign('again', true
);
669 $mailer->assign('baseurl', Platal
::globals()->xnet
->xorg_baseurl
);
673 function handler_awaiting_active($page)
676 $page->changeTpl('xnetgrp/awaiting_active.tpl');
678 XDB
::execute('DELETE FROM register_pending_xnet
679 WHERE DATE_SUB(NOW(), INTERVAL 1 MONTH) > date');
681 $uids = XDB
::fetchColumn('SELECT g.uid
682 FROM group_members AS g
683 INNER JOIN accounts AS a ON (a.uid = g.uid)
684 INNER JOIN register_pending_xnet AS p ON (p.uid = g.uid)
685 WHERE a.uid = g.uid AND g.asso_id = {?} AND a.type = \'xnet\' AND a.state = \'pending\'',
686 $globals->asso('id'));
688 if (Post
::has('again')) {
689 S
::assert_xsrf_token();
691 $uids_to_again = array_intersect(array_keys(Post
::v('again')), $uids);
692 foreach ($uids_to_again as $uid) {
695 $page->trigSuccess('Relances effectuées avec succès.');
699 $registration_date = XDB
::fetchAllAssoc('uid', 'SELECT uid, date
700 FROM register_pending_xnet
701 WHERE uid IN {?}', $uids);
702 $last_date = XDB
::fetchAllAssoc('uid', 'SELECT uid, last_date
703 FROM register_pending_xnet
704 WHERE uid IN {?}', $uids);
706 $users = User
::getBulkUsersWithUIDs($uids);
707 $page->assign('users', $users);
708 $page->assign('registration_date', $registration_date);
709 $page->assign('last_date', $last_date);
714 private function removeSubscriptionRequest($uid)
717 XDB
::execute("DELETE FROM group_member_sub_requests
718 WHERE asso_id = {?} AND uid = {?}",
719 $globals->asso('id'), $uid);
722 private function validSubscription(User
$user)
725 $this->removeSubscriptionRequest($user->id());
726 Group
::subscribe($globals->asso('id'), $user->id());
728 if (XDB
::affectedRows() == 1) {
729 $mailer = new PlMailer();
730 $mailer->addTo($user->forlifeEmail());
731 $mailer->setFrom('"' . S
::user()->fullName() . '" <' . S
::user()->forlifeEmail() . '>');
732 $mailer->setSubject('[' . $globals->asso('nom') . '] Demande d\'inscription');
733 $message = ($user->isFemale() ?
'Chère' : 'Cher') . " Camarade,\n"
735 . " Suite à ta demande d'adhésion à " . $globals->asso('nom')
736 . ", j'ai le plaisir de t'annoncer que ton inscription a été validée !\n"
737 . (is_null($globals->asso('welcome_msg')) ?
'' : "\n" . $globals->asso('welcome_msg') . "\n")
739 . "Bien cordialement,\n"
741 . S
::user()->fullName() . '.';
742 $mailer->setTxtBody(wordwrap($message, 72));
747 function handler_subscribe($page, $u = null
)
750 $page->changeTpl('xnetgrp/inscrire.tpl');
752 if (!$globals->asso('inscriptible'))
753 $page->kill("Il n'est pas possible de s'inscire en ligne à ce "
754 ."groupe. Essaie de joindre le contact indiqué "
755 ."sur la page de présentation.");
757 if (!is_null($u) && may_update()) {
758 $user = User
::get($u);
762 $page->assign('user', $user);
765 // Retrieves the subscription status, and the reason.
766 $res = XDB
::query("SELECT reason
767 FROM group_member_sub_requests
768 WHERE asso_id = {?} AND uid = {?}",
769 $globals->asso('id'), $user->id());
770 $reason = ($res->numRows() ?
$res->fetchOneCell() : null
);
772 $res = XDB
::query("SELECT COUNT(*)
774 WHERE asso_id = {?} AND uid = {?}",
775 $globals->asso('id'), $user->id());
776 $already_member = ($res->fetchOneCell() > 0);
778 // Handles the membership request.
779 if ($already_member) {
780 $this->removeSubscriptionRequest($user->id());
781 $page->kill($user->fullName() . ' est déjà membre du groupe !');
782 } elseif (Env
::has('accept')) {
783 S
::assert_xsrf_token();
785 $this->validSubscription($user);
786 pl_redirect("member/" . $user->login());
787 } elseif (Env
::has('refuse')) {
788 S
::assert_xsrf_token();
790 $this->removeSubscriptionRequest($user->id());
791 $mailer = new PlMailer();
792 $mailer->addTo($user->forlifeEmail());
793 $mailer->setFrom('"' . S
::user()->fullName() . '" <' . S
::user()->forlifeEmail() . '>');
794 $mailer->setSubject('['.$globals->asso('nom').'] Demande d\'inscription annulée');
795 $mailer->setTxtBody(Env
::v('motif'));
797 $page->killSuccess("La demande de {$user->fullName()} a bien été refusée.");
799 $page->assign('show_form', true
);
800 $page->assign('reason', $reason);
806 $page->kill("Tu es déjà membre !");
810 $res = XDB
::query("SELECT uid
811 FROM group_member_sub_requests
812 WHERE uid = {?} AND asso_id = {?}",
813 S
::i('uid'), $globals->asso('id'));
814 if ($res->numRows() != 0) {
815 $page->kill("Tu as déjà demandé ton inscription à ce groupe. Cette demande est actuellement en attente de validation.");
819 if (Post
::has('inscrire')) {
820 S
::assert_xsrf_token();
822 XDB
::execute("INSERT INTO group_member_sub_requests (asso_id, uid, ts, reason)
823 VALUES ({?}, {?}, NOW(), {?})",
824 $globals->asso('id'), S
::i('uid'), Post
::v('message'));
825 XDB
::execute('DELETE FROM group_former_members
826 WHERE uid = {?} AND asso_id = {?}',
827 S
::i('uid'), $globals->asso('id'));
828 $admins = $globals->asso()->iterToNotify();
829 $admin = $admins->next();
830 if (!is_null($admin)) {
831 $to = $admin->bestEmail();
832 while ($admin = $admins->next()) {
833 $to .= ', ' . $admin->bestEmail();
841 . "Ce message a été envoyé suite à la demande d'inscription de\n"
842 . S
::user()->fullName(true
) . "\n"
843 . "Via le site www.polytechnique.net. Tu peux choisir de valider ou\n"
844 . "de refuser sa demande d'inscription depuis la page :\n"
845 . "http://www.polytechnique.net/" . $globals->asso("diminutif") . "/subscribe/" . S
::user()->login() . "\n"
847 . "En cas de problème, contacter l'équipe de Polytechnique.org\n"
848 . "à l'adresse : support@polytechnique.org\n";
851 $to = ($globals->asso('mail') != '') ?
$globals->asso('mail') . ', ' : '';
852 $to .= 'support@polytechnique.org';
853 $append = "\n-- \nLe groupe ".$globals->asso("nom")
854 ." n'a pas d'administrateur, l'équipe de"
855 ." Polytechnique.org a été prévenue et va rapidement"
856 ." résoudre ce problème.\n";
859 $mailer = new PlMailer();
861 $mailer->setFrom('"' . S
::user()->fullName() . '" <' . S
::user()->forlifeEmail() . '>');
862 $mailer->setSubject('['.$globals->asso('nom').'] Demande d\'inscription');
863 $mailer->setTxtBody(Post
::v('message').$append);
868 function handler_subscribe_valid($page)
872 if (Post
::has('valid')) {
873 S
::assert_xsrf_token();
874 $subs = Post
::v('subs');
875 if (is_array($subs)) {
877 foreach ($subs as $hruid => $val) {
879 $user = User
::get($hruid);
881 $this->validSubscription($user);
888 $it = XDB
::iterator('SELECT s.uid, a.hruid, s.ts AS date
889 FROM group_member_sub_requests AS s
890 INNER JOIN accounts AS a ON(s.uid = a.uid)
891 WHERE s.asso_id = {?}
892 ORDER BY s.ts', $globals->asso('id'));
893 $page->changeTpl('xnetgrp/subscribe-valid.tpl');
894 $page->assign('valid', $it);
897 function handler_change_rights($page)
899 if (Env
::has('right') && (may_update() || S
::suid())) {
900 switch (Env
::v('right')) {
902 Platal
::session()->stopSUID();
905 Platal
::session()->doSelfSuid();
910 Platal
::session()->doSelfSuid();
911 may_update(false
, true
);
915 Platal
::session()->doSelfSuid();
916 may_update(false
, true
);
917 is_member(false
, true
);
921 http_redirect($_SERVER['HTTP_REFERER']);
924 function handler_admin_annuaire($page)
928 $this->load('mail.inc.php');
929 $page->changeTpl('xnetgrp/annuaire-admin.tpl');
931 $mmlist = new MMList($user, $globals->asso('mail_domain'));
932 $lists = $mmlist->get_lists();
933 if (!$lists) $lists = array();
934 $listes = array_map(create_function('$arr', 'return $arr["list"];'), $lists);
936 $subscribers = array();
938 foreach ($listes as $list) {
939 list(,$members) = $mmlist->get_members($list);
940 $mails = array_map(create_function('$arr', 'return $arr[1];'), $members);
941 $subscribers = array_unique(array_merge($subscribers, $mails));
944 $not_in_group_x = array();
945 $not_in_group_ext = array();
947 foreach ($subscribers as $mail) {
948 $uf = new UserFilter(new PFC_And(new UFC_Group($globals->asso('id')),
949 new UFC_Email($mail)));
950 if ($uf->getTotalCount() == 0) {
951 if (User
::isForeignEmailAddress($mail)) {
952 $not_in_group_ext[] = $mail;
954 $not_in_group_x[] = $mail;
959 $page->assign('not_in_group_ext', $not_in_group_ext);
960 $page->assign('not_in_group_x', $not_in_group_x);
961 $page->assign('lists', $lists);
964 function handler_admin_member_new($page, $email = null
)
968 $page->changeTpl('xnetgrp/membres-add.tpl');
969 $page->addJsLink('xnet_members.js');
971 if (is_null($email)) {
975 S
::assert_xsrf_token();
976 $suggest_account_activation = false
;
978 // FS#703 : $_GET is urldecoded twice, hence
979 // + (the data) => %2B (in the url) => + (first decoding) => ' ' (second decoding)
980 // Since there can be no spaces in emails, we can fix this with :
981 $email = str_replace(' ', '+', $email);
982 $is_valid_email = isvalid_email($email);
984 // X not registered to main site.
985 if (Env
::v('x') && Env
::i('userid') && $is_valid_email) {
986 $user = User
::getSilentWithUID(Env
::i('userid'));
988 $page->trigError('Utilisateur invalide.');
992 // User has an account but is not yet registered.
993 if ($user->state
== 'pending') {
994 // Add email in account table.
995 XDB
::query('UPDATE accounts
997 WHERE uid = {?} AND email IS NULL',
998 $email, $user->id());
999 // Add email for marketing if required.
1000 if (Env
::v('marketing')) {
1001 $market = Marketing
::get($user->uid
, $email);
1003 $market = new Marketing($user->uid
, $email, 'group', $globals->asso('nom'),
1004 Env
::v('marketing_from'), S
::v('uid'));
1008 } elseif (Env
::v('broken')) {
1009 // Add email for broken if required.
1010 $valid = new BrokenReq(S
::user(), $user, $email, 'Groupe : ' . $globals->asso('nom'));
1014 $user = User
::getSilent($email);
1016 // Wrong email and no user: failure.
1017 if (is_null($user) && (!$is_valid_email ||
!User
::isForeignEmailAddress($email))) {
1018 $page->trigError('« <strong>' . $email . '</strong> » n\'est pas une adresse email valide.');
1022 // Deals with xnet accounts.
1023 if (is_null($user) ||
$user->type
== 'xnet') {
1024 // User is of type xnet. There are 3 possible cases:
1025 // * the email is not known yet: we create a new account and
1026 // propose to send an email to the user so he can activate
1028 // * the email is known but the user was not contacted in order to
1029 // activate yet: we propose to send an email to the user so he
1030 // can activate his account,
1031 // * the email is known and the user was already contacted or has
1032 // an active account: nothing to be done.
1033 list($mbox, $domain) = explode('@', strtolower($email));
1034 $hruid = User
::makeHrid($mbox, $domain, 'ext');
1035 // User might already have an account (in another group for example).
1036 $user = User
::getSilent($hruid);
1038 // If the user has no account yet, creates new account: build names from email address.
1040 require_once 'name.func.inc.php';
1041 $parts = explode('.', $mbox);
1042 if (count($parts) == 1) {
1043 $lastname = $display_name = capitalize_name($mbox);
1046 $display_name = $firstname = capitalize_name($parts[0]);
1047 $lastname = capitalize_name(implode(' ', array_slice($parts, 1)));
1049 $full_name = build_full_name($firstname, $lastname);
1050 $directory_name = build_directory_name($firstname, $lastname);
1051 $sort_name = build_sort_name($firstname, $lastname);
1052 XDB
::execute('INSERT INTO accounts (hruid, display_name, full_name, directory_name, sort_name,
1053 firstname, lastname, email, type, state)
1054 VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, \'xnet\', \'disabled\')',
1055 $hruid, $display_name, $full_name, $directory_name, $sort_name, $firstname, $lastname, $email);
1056 $user = User
::getSilent($hruid);
1059 $suggest_account_activation = $this->suggest($user);
1064 // First check if the user used to be in this group.
1065 XDB
::rawExecute('DELETE FROM group_former_members
1066 WHERE remember AND DATE_SUB(NOW(), INTERVAL 1 YEAR) > unsubsciption_date');
1067 $former_member = XDB
::fetchOneCell('SELECT remember
1068 FROM group_former_members
1069 WHERE uid = {?} AND asso_id = {?}',
1070 $user->id(), $globals->asso('id'));
1071 if ($former_member === 1) {
1072 $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.');
1074 } elseif (!is_null($former_member) && Post
::i('force_continue') == 0) {
1075 $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.');
1076 $page->assign('force_continue', 1);
1080 Group
::subscribe($globals->asso('id'), $user->id());
1081 $this->removeSubscriptionRequest($user->id());
1082 if ($user->isActive()) {
1083 $mailer = new PlMailer('xnetgrp/forced-subscription.mail.tpl');
1084 $mailer->addTo($user->bestEmail());
1085 $mailer->assign('group', $globals->asso('nom'));
1086 $mailer->assign('anim', S
::user()->fullname());
1087 $mailer->assign('diminutif', $globals->asso('diminutif'));
1091 // Check if the group has more than 1000 members, if so, disable the "send mail" function.
1092 $full_count = XDB
::fetchOneCell('SELECT COUNT(*)
1094 WHERE asso_id = {?}',
1095 $globals->asso('id'));
1096 if ($full_count > 999) {
1099 SET disable_mails = 1
1101 $globals->asso('id'));
1104 if ($suggest_account_activation) {
1105 pl_redirect('member/suggest/' . $user->login() . '/' . $email . '/' . $globals->asso('nom'));
1107 pl_redirect('member/' . $user->login());
1112 // Check if the user has a pending or active account, and thus if we should her account's activation.
1113 private function suggest(PlUser
$user)
1115 $active = XDB
::fetchOneCell('SELECT state = \'active\'
1119 $pending = XDB
::fetchOneCell('SELECT uid
1120 FROM register_pending_xnet
1123 $requested = AccountReq
::isPending($user->id()) || BulkAccountsReq
::isPending($user->id());
1125 if ($active ||
$pending ||
$requested) {
1131 function handler_admin_member_suggest($page, $hruid, $email)
1133 $page->changeTpl('xnetgrp/membres-suggest.tpl');
1135 // FS#703 : $_GET is urldecoded twice, hence
1136 // + (the data) => %2B (in the url) => + (first decoding) => ' ' (second decoding)
1137 // Since there can be no spaces in emails, we can fix this with :
1138 $email = str_replace(' ', '+', $email);
1140 if (Post
::has('suggest')) {
1141 if (Post
::t('suggest') == 'yes') {
1145 $request = new AccountReq($user, $hruid, $email, $globals->asso('nom'), $globals->asso('diminutif'));
1147 $page->trigSuccessRedirect('Un email va bien être envoyé à ' . $email . ' pour l\'activation de son compte.',
1148 $globals->asso('diminutif') . '/member/' . $hruid);
1150 pl_redirect('member/' . $hruid);
1153 $page->assign('email', $email);
1154 $page->assign('hruid', $hruid);
1157 function handler_admin_member_reg($page, $uid)
1159 pl_content_headers('text/plain');
1161 $user = User
::getSilentWithUID($uid);
1162 if ($user && $user->state
!= 'pending' && $user->hasProfile()) {
1169 function handler_admin_member_new_ajax($page)
1171 pl_content_headers("text/html");
1172 $page->changeTpl('xnetgrp/membres-new-search.tpl', NO_SKIN
);
1174 $same_email = false
;
1175 if (Env
::has('login')) {
1176 $user = User
::getSilent(Env
::t('login'));
1177 if ($user && $user->state
!= 'pending') {
1178 $users = array($user->id() => $user);
1182 if (empty($users)) {
1183 list($lastname, $firstname) = str_replace(array('-', ' ', "'"), '%', array(Env
::t('nom'), Env
::t('prenom')));
1184 $cond = new PFC_And();
1185 if (!empty($lastname)) {
1186 $cond->addChild(new UFC_NameTokens($lastname, array(), false
, false
, Profile
::LASTNAME
));
1188 if (!empty($firstname)) {
1189 $cond->addChild(new UFC_NameTokens($firstname, array(), false
, false
, Profile
::FIRSTNAME
));
1191 if (Env
::t('promo')) {
1192 $cond->addChild(new UFC_Promo('=', UserFilter
::DISPLAY
, Env
::t('promo')));
1194 $uf = new UserFilter($cond);
1195 $users = $uf->getUsers(new PlLimit(30));
1196 if ($uf->getTotalCount() > 30) {
1197 $page->assign('too_many', true
);
1202 $page->assign('users', $users);
1203 $page->assign('same_email', $same_email);
1206 function unsubscribe(PlUser
$user, $remember = false
)
1209 Group
::unsubscribe($globals->asso('id'), $user->id(), $remember);
1211 if ($globals->asso('notif_unsub')) {
1212 $mailer = new PlMailer('xnetgrp/unsubscription-notif.mail.tpl');
1213 $admins = $globals->asso()->iterToNotify();
1214 while ($admin = $admins->next()) {
1215 $mailer->addTo($admin);
1217 $mailer->assign('group', $globals->asso('nom'));
1218 $mailer->assign('user', $user);
1219 $mailer->assign('selfdone', $user->id() == S
::i('uid'));
1223 $domain = $globals->asso('mail_domain');
1228 $mmlist = new MMList(S
::user(), $domain);
1229 $listes = $mmlist->get_lists($user->forlifeEmail());
1231 $may_update = may_update();
1233 if (is_array($listes)) {
1234 foreach ($listes as $liste) {
1235 if ($liste['sub'] == 2) {
1237 $mmlist->mass_unsubscribe($liste['list'], Array($user->forlifeEmail()));
1239 $mmlist->unsubscribe($liste['list']);
1241 } elseif ($liste['sub']) {
1242 Platal
::page()->trigWarning($user->fullName() . " a une"
1243 ." demande d'inscription en cours sur la"
1244 ." liste {$liste['list']}@ !");
1250 XDB
::execute('DELETE v
1251 FROM email_virtual AS v
1252 INNER JOIN email_virtual_domains AS d ON (v.domain = d.id)
1253 WHERE v.redirect = {?} AND d.name = {?}',
1254 $user->forlifeEmail(), $domain);
1258 function handler_unsubscribe($page)
1260 $page->changeTpl('xnetgrp/membres-del.tpl');
1263 return PL_NOT_FOUND
;
1265 $page->assign('self', true
);
1266 $page->assign('user', $user);
1268 if (!Post
::has('confirm')) {
1271 S
::assert_xsrf_token();
1274 $hasSingleGroup = ($user->groupCount() == 1);
1276 if ($this->unsubscribe($user, Post
::b('remember'))) {
1277 $page->trigSuccess('Tu as été désinscrit du groupe avec succès.');
1279 $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.');
1282 // If user is of type xnet account and this was her last group, disable the account.
1283 if ($user->type
== 'xnet' && $hasSingleGroup) {
1286 $page->assign('is_member', is_member(true
));
1289 function handler_admin_member_del($page, $user = null
)
1291 $page->changeTpl('xnetgrp/membres-del.tpl');
1292 $user = User
::getSilent($user);
1294 return PL_NOT_FOUND
;
1299 if (!$user->inGroup($globals->asso('id'))) {
1300 pl_redirect('annuaire');
1303 $page->assign('self', false
);
1304 $page->assign('user', $user);
1306 if (!Post
::has('confirm')) {
1309 S
::assert_xsrf_token();
1312 $hasSingleGroup = ($user->groupCount() == 1);
1314 if ($this->unsubscribe($user)) {
1315 $page->trigSuccess("{$user->fullName()} a été désinscrit du groupe !");
1317 $page->trigWarning("{$user->fullName()} a été désinscrit du groupe, mais des erreurs subsistent !");
1320 // If user is of type xnet account and this was her last group, disable the account.
1321 if ($user->type
== 'xnet' && $hasSingleGroup) {
1326 private function changeLogin(PlPage
$page, PlUser
$user, $login, $req_broken = false
, $req_marketing = false
, $marketing_from = 'user')
1328 // Search the user's uid.
1329 $xuser = User
::getSilent($login);
1331 $accounts = User
::getPendingAccounts($login);
1333 $page->trigError("L'identifiant $login ne correspond à aucun X.");
1335 } else if (count($accounts) > 1) {
1336 $page->trigError("L'identifiant $login correspond à plusieurs camarades.");
1339 $xuser = User
::getSilent($accounts[0]['uid']);
1346 // Market or suggest new redirection if required.
1347 $email = $user->bestEmail();
1349 $valid = new BrokenReq(S
::user(), $xuser, $email, 'Groupe : ' . Platal
::globals()->asso('nom'));
1351 } elseif ($req_marketing) {
1352 $market = Marketing
::get($xuser->uid
, $email);
1354 $market = new Marketing($xuser->uid
, $email, 'group', Platal
::globals()->asso('nom'), $marketing_from, S
::i('uid'));
1359 if ($user->mergeIn($xuser)) {
1360 return $xuser->login();
1362 return $user->login();
1365 function handler_admin_member($page, $user)
1369 $user = User
::getSilent($user);
1371 return PL_NOT_FOUND
;
1374 if (!$user->inGroup($globals->asso('id'))) {
1375 pl_redirect('annuaire');
1378 $page->changeTpl('xnetgrp/membres-edit.tpl');
1379 $page->addJsLink('xnet_members.js');
1381 $mmlist = new MMList(S
::user(), $globals->asso('mail_domain'));
1383 if (Post
::has('change')) {
1384 S
::assert_xsrf_token();
1385 require_once 'emails.inc.php';
1386 require_once 'name.func.inc.php';
1388 // Convert user status to X
1389 if (!Post
::blank('x')) {
1390 $forlife = $this->changeLogin($page, $user, Post
::i('userid'), Post
::b('broken'), Post
::b('marketing'), Post
::v('marketing_from'));
1392 pl_redirect('member/' . $forlife);
1397 if ($user->type
== 'virtual' ||
($user->type
== 'xnet' && !$user->perms
)) {
1398 $lastname = capitalize_name(Post
::t('lastname'));
1399 if (Post
::s('type') != 'virtual') {
1400 $firstname = capitalize_name(Post
::t('firstname'));
1404 $full_name = build_full_name($firstname, $lastname);
1405 $directory_name = build_directory_name($firstname, $lastname);
1406 $sort_name = build_sort_name($firstname, $lastname);
1407 XDB
::query('UPDATE accounts
1408 SET full_name = {?}, directory_name = {?}, sort_name = {?}, display_name = {?},
1409 firstname = {?}, lastname = {?}, sex = {?}, type = {?}
1411 $full_name, $directory_name, $sort_name, Post
::t('display_name'), $firstname, $lastname,
1412 (Post
::t('sex') == 'male') ?
'male' : 'female',
1413 (Post
::t('type') == 'xnet') ?
'xnet' : 'virtual', $user->id());
1417 $new_email = strtolower(Post
::t('email'));
1418 if (($user->type
== 'virtual' ||
($user->type
== 'xnet' && !$user->perms
))
1419 && require_email_update($user, $new_email)) {
1420 XDB
::query('UPDATE accounts
1423 $new_email, $user->id());
1424 if ($user->forlifeEmail()) {
1425 $listClient = new MMList(S
::user());
1426 $listClient->change_user_email($user->forlifeEmail(), $new_email);
1427 update_alias_user($user->forlifeEmail(), $new_email);
1429 $user = User
::getWithUID($user->id());
1431 if (XDB
::affectedRows()) {
1432 $page->trigSuccess('Données de l\'utilisateur mises à jour.');
1435 if (($user->type
== 'xnet' && !$user->perms
)) {
1436 if (Post
::b('suggest')) {
1437 $request = new AccountReq(S
::user(), $user->hruid
, Post
::t('email'), $globals->asso('nom'), $globals->asso('diminutif'));
1439 $page->trigSuccess('Le compte va bientôt être activé.');
1441 if (Post
::b('again')) {
1442 $this->again($user->id());
1443 $page->trigSuccess('Relance effectuée avec succès.');
1447 // Update group params for user
1448 $perms = Post
::v('group_perms');
1449 $comm = Post
::t('comm');
1450 $position = (Post
::t('group_position') == '') ? null
: Post
::v('group_position');
1451 if ($user->group_perms
!= $perms ||
$user->group_comm
!= $comm ||
$user->group_position
!= $position) {
1452 XDB
::query('UPDATE group_members
1453 SET perms = {?}, comm = {?}, position = {?}
1454 WHERE uid = {?} AND asso_id = {?}',
1455 ($perms == 'admin') ?
'admin' : 'membre', $comm, $position,
1456 $user->id(), $globals->asso('id'));
1457 if (XDB
::affectedRows()) {
1458 if ($perms != $user->group_perms
) {
1459 $page->trigSuccess('Permissions modifiées !');
1461 if ($comm != $user->group_comm
) {
1462 $page->trigSuccess('Commentaire mis à jour.');
1464 if ($position != $user->group_position
) {
1465 $page->trigSuccess('Poste mis à jour.');
1470 // Gets user info again as they might have change
1471 $user = User
::getSilent($user->id());
1473 // Update ML subscriptions
1474 foreach (Env
::v('ml1', array()) as $ml => $state) {
1475 $ask = empty($_REQUEST['ml2'][$ml]) ?
0 : 2;
1476 if ($ask == $state) {
1479 if ($state == '1') {
1480 $page->trigWarning("{$user->fullName()} a "
1481 ."actuellement une demande d'inscription en "
1482 ."cours sur <strong>$ml@</strong> !!!");
1484 $mmlist->mass_subscribe($ml, Array($user->forlifeEmail()));
1485 $page->trigSuccess("{$user->fullName()} a été abonné à $ml@.");
1487 $mmlist->mass_unsubscribe($ml, Array($user->forlifeEmail()));
1488 $page->trigSuccess("{$user->fullName()} a été désabonné de $ml@.");
1492 // Change subscriptioin to aliases
1493 foreach (Env
::v('ml3', array()) as $ml => $state) {
1494 require_once 'emails.inc.php';
1495 $ask = !empty($_REQUEST['ml4'][$ml]);
1496 list($local_part, ) = explode('@', $ml);
1497 if ($ask == $state) {
1501 add_to_list_alias($user->id(), $local_part, $globals->asso('mail_domain'));
1502 $page->trigSuccess("{$user->fullName()} a été abonné à $ml.");
1504 delete_from_list_alias($user->id(), $local_part, $globals->asso('mail_domain'));
1505 $page->trigSuccess("{$user->fullName()} a été désabonné de $ml.");
1509 if ($globals->asso('has_nl')) {
1510 $nl = NewsLetter
::forGroup($globals->asso('shortname'));
1511 // Updates group's newsletter subscription.
1512 if (Post
::i('newsletter') == 1) {
1513 $nl->subscribe($user);
1515 $nl->unsubscribe(null
, $user->id());
1520 $res = XDB
::rawFetchAllAssoc('SHOW COLUMNS FROM group_members LIKE \'position\'');
1521 $positions = str_replace(array('enum(', ')', '\''), '', $res[0]['Type']);
1522 if ($globals->asso('has_nl')) {
1523 $nl = NewsLetter
::forGroup($globals->asso('shortname'));
1524 $nl_registered = $nl->subscriptionState($user);
1526 $nl_registered = false
;
1529 $page->assign('user', $user);
1530 $page->assign('suggest', $this->suggest($user));
1531 $page->assign('listes', $mmlist->get_lists($user->forlifeEmail()));
1532 $page->assign('alias', $user->emailGroupAliases($globals->asso('mail_domain')));
1533 $page->assign('positions', explode(',', $positions));
1534 $page->assign('nl_registered', $nl_registered);
1535 $page->assign('pending_xnet_account', XDB
::fetchOneCell('SELECT 1
1536 FROM register_pending_xnet
1541 function handler_rss(PlPage
$page, PlUser
$user)
1544 $page->assign('asso', $globals->asso());
1546 $this->load('feed.inc.php');
1547 $feed = new XnetGrpEventFeed();
1548 return $feed->run($page, $user, false
);
1551 private function upload_image(PlPage
$page, PlUpload
$upload)
1553 if (@!$_FILES['image']['tmp_name'] && !Env
::v('image_url')) {
1556 if (!$upload->upload($_FILES['image']) && !$upload->download(Env
::v('image_url'))) {
1557 $page->trigError('Impossible de télécharger l\'image');
1559 } elseif (!$upload->isType('image')) {
1560 $page->trigError('Le fichier n\'est pas une image valide au format JPEG, GIF ou PNG.');
1563 } elseif (!$upload->resizeImage(80, 100, 100, 100, 32284)) {
1564 $page->trigError('Impossible de retraiter l\'image');
1570 function handler_photo_announce($page, $eid = null
) {
1572 $res = XDB
::query('SELECT *
1573 FROM group_announces_photo
1574 WHERE eid = {?}', $eid);
1575 if ($res->numRows()) {
1576 $photo = $res->fetchOneAssoc();
1577 pl_cached_dynamic_content_headers("image/" . $photo['attachmime']);
1578 echo $photo['attach'];
1582 $upload = new PlUpload(S
::user()->login(), 'xnetannounce');
1583 if ($upload->exists() && $upload->isType('image')) {
1584 pl_cached_dynamic_content_headers($upload->contentType());
1585 echo $upload->getContents();
1590 pl_cached_dynamic_content_headers("image/png");
1591 echo file_get_contents($globals->spoolroot
. '/htdocs/images/logo.png');
1595 function handler_edit_announce($page, $aid = null
)
1597 global $globals, $platal;
1598 $page->changeTpl('xnetgrp/announce-edit.tpl');
1599 $page->assign('new', is_null($aid));
1602 if (Post
::v('valid') == 'Visualiser' || Post
::v('valid') == 'Enregistrer'
1603 || Post
::v('valid') == 'Supprimer l\'image' || Post
::v('valid') == 'Pas d\'image') {
1604 S
::assert_xsrf_token();
1606 if (!is_null($aid)) {
1609 $art['titre'] = Post
::v('titre');
1610 $art['texte'] = Post
::v('texte');
1611 $art['contacts'] = Post
::v('contacts');
1612 $art['promo_min'] = Post
::i('promo_min');
1613 $art['promo_max'] = Post
::i('promo_max');
1614 $art['nom'] = S
::v('nom');
1615 $art['prenom'] = S
::v('prenom');
1616 $art['promo'] = S
::v('promo');
1617 $art['hruid'] = S
::user()->login();
1618 $art['uid'] = S
::user()->id();
1619 $art['expiration'] = Post
::v('expiration');
1620 $art['public'] = Post
::has('public');
1621 $art['xorg'] = Post
::has('xorg');
1622 $art['nl'] = Post
::has('nl');
1623 $art['event'] = Post
::v('event');
1624 $upload = new PlUpload(S
::user()->login(), 'xnetannounce');
1625 $this->upload_image($page, $upload);
1627 $art['contact_html'] = $art['contacts'];
1628 if ($art['event']) {
1629 $art['contact_html'] .= "\n{$globals->baseurl}/{$platal->ns}events/sub/{$art['event']}";
1632 if (!$art['public'] &&
1633 (($art['promo_min'] > $art['promo_max'] && $art['promo_max'] != 0) ||
1634 ($art['promo_min'] != 0 && ($art['promo_min'] <= 1900 ||
$art['promo_min'] >= 2020)) ||
1635 ($art['promo_max'] != 0 && ($art['promo_max'] <= 1900 ||
$art['promo_max'] >= 2020))))
1637 $page->trigError("L'intervalle de promotions est invalide.");
1638 Post
::kill('valid');
1641 if (!trim($art['titre']) ||
!trim($art['texte'])) {
1642 $page->trigError("L'article doit avoir un titre et un contenu.");
1643 Post
::kill('valid');
1646 if (Post
::v('valid') == 'Supprimer l\'image') {
1648 Post
::kill('valid');
1650 $art['photo'] = $upload->exists() || Post
::i('photo');
1651 if (Post
::v('valid') == 'Pas d\'image' && !is_null($aid)) {
1652 XDB
::query('DELETE FROM group_announces_photo
1653 WHERE eid = {?}', $aid);
1655 Post
::kill('valid');
1656 $art['photo'] = false
;
1660 if (Post
::v('valid') == 'Enregistrer') {
1661 $promo_min = ($art['public'] ?
0 : $art['promo_min']);
1662 $promo_max = ($art['public'] ?
0 : $art['promo_max']);
1663 $flags = new PlFlagSet();
1664 if ($art['public']) {
1665 $flags->addFlag('public');
1667 if ($art['photo']) {
1668 $flags->addFlag('photo');
1670 if (is_null($aid)) {
1671 $fulltext = $art['texte'];
1672 if (!empty($art['contact_html'])) {
1673 $fulltext .= "\n\n'''Contacts :'''\\\\\n" . $art['contact_html'];
1676 if ($globals->asso('forum')) {
1677 require_once 'banana/forum.inc.php';
1678 $banana = new ForumsBanana(S
::user());
1679 $post = $banana->post($globals->asso('forum'), null
,
1680 $art['titre'], MiniWiki
::wikiToText($fulltext, false
, 0, 80));
1682 XDB
::query('INSERT INTO group_announces (uid, asso_id, create_date, titre, texte, contacts,
1683 expiration, promo_min, promo_max, flags, post_id)
1684 VALUES ({?}, {?}, NOW(), {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})',
1685 S
::i('uid'), $globals->asso('id'), $art['titre'], $art['texte'], $art['contact_html'],
1686 $art['expiration'], $promo_min, $promo_max, $flags, $post);
1687 $aid = XDB
::insertId();
1688 if ($art['photo']) {
1689 list($imgx, $imgy, $imgtype) = $upload->imageInfo();
1690 XDB
::execute('INSERT INTO group_announces_photo
1691 SET eid = {?}, attachmime = {?}, x = {?}, y = {?}, attach = {?}',
1692 $aid, $imgtype, $imgx, $imgy, $upload->getContents());
1695 $article = new EvtReq("[{$globals->asso('nom')}] " . $art['titre'], $fulltext,
1696 $art['promo_min'], $art['promo_max'], $art['expiration'], "", S
::user(),
1699 $page->trigWarning("L'affichage sur la page d'accueil de Polytechnique.org est en attente de validation.");
1700 } else if ($upload && $upload->exists()) {
1704 $article = new NLReq(S
::user(), $globals->asso('nom') . " : " .$art['titre'],
1705 $art['texte'], $art['contact_html']);
1707 $page->trigWarning("La parution dans la Lettre Mensuelle est en attente de validation.");
1710 XDB
::query('UPDATE group_announces
1711 SET titre = {?}, texte = {?}, contacts = {?}, expiration = {?},
1712 promo_min = {?}, promo_max = {?}, flags = {?}
1713 WHERE id = {?} AND asso_id = {?}',
1714 $art['titre'], $art['texte'], $art['contacts'], $art['expiration'],
1715 $promo_min, $promo_max, $flags,
1716 $art['id'], $globals->asso('id'));
1717 if ($art['photo'] && $upload->exists()) {
1718 list($imgx, $imgy, $imgtype) = $upload->imageInfo();
1719 XDB
::execute('INSERT INTO group_announces_photo (eid, attachmime, attach, x, y)
1720 VALUES ({?}, {?}, {?}, {?}, {?})
1721 ON DUPLICATE KEY UPDATE attachmime = VALUES(attachmime), attach = VALUES(attach), x = VALUES(x), y = VALUES(y)',
1722 $aid, $imgtype, $upload->getContents(), $imgx, $imgy);
1727 if (Post
::v('valid') == 'Enregistrer' || Post
::v('valid') == 'Annuler') {
1731 if (empty($art) && !is_null($aid)) {
1732 $res = XDB
::query("SELECT *, FIND_IN_SET('public', flags) AS public,
1733 FIND_IN_SET('photo', flags) AS photo
1734 FROM group_announces
1735 WHERE asso_id = {?} AND id = {?}",
1736 $globals->asso('id'), $aid);
1737 if ($res->numRows()) {
1738 $art = $res->fetchOneAssoc();
1739 $art['contact_html'] = $art['contacts'];
1741 $page->kill("Aucun article correspond à l'identifiant indiqué.");
1745 if (is_null($aid)) {
1746 $events = XDB
::iterator("SELECT *
1748 WHERE asso_id = {?} AND archive = 0",
1749 $globals->asso('id'));
1750 if ($events->total()) {
1751 $page->assign('events', $events);
1755 $art['contact_html'] = @MiniWiki
::WikiToHTML($art['contact_html']);
1756 $page->assign('art', $art);
1757 $page->assign_by_ref('upload', $upload);
1760 function handler_admin_announce($page)
1763 $page->changeTpl('xnetgrp/announce-admin.tpl');
1765 if (Env
::has('del')) {
1766 S
::assert_xsrf_token();
1767 XDB
::execute('DELETE FROM group_announces
1768 WHERE id = {?} AND asso_id = {?}',
1769 Env
::i('del'), $globals->asso('id'));
1771 $res = XDB
::iterator('SELECT id, titre, expiration, expiration < CURRENT_DATE() AS perime
1772 FROM group_announces
1774 ORDER BY expiration DESC',
1775 $globals->asso('id'));
1776 $page->assign('articles', $res);
1780 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker fenc=utf-8: