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/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('error', $error);
252 $axDate = make_datetime(Post
::v('axDate'));
253 if (Post
::t('axDate') != '') {
254 $axDate = make_datetime(Post
::v('axDate'))->format('Y-m-d');
260 SET nom={?}, diminutif={?}, cat={?}, dom={?},
261 descr={?}, site={?}, mail={?}, resp={?},
262 forum={?}, mail_domain={?}, ax={?}, axDate = {?}, pub={?},
263 sub_url={?}, inscriptible={?}, unsub_url={?},
264 flags = {?}, welcome_msg = {?}
266 Post
::v('nom'), Post
::v('diminutif'),
267 Post
::v('cat'), (Post
::i('dom') == 0) ? null
: Post
::i('dom'),
268 Post
::v('descr'), $site,
269 Post
::v('mail'), Post
::v('resp'),
270 Post
::v('forum'), Post
::v('mail_domain'),
271 Post
::has('ax'), $axDate, Post
::v('pub'),
272 Post
::v('sub_url'), Post
::v('inscriptible'),
273 Post
::v('unsub_url'), $flags, Post
::t('welcome_msg'),
274 $globals->asso('id'));
275 if (Post
::v('mail_domain')) {
276 XDB
::execute('INSERT IGNORE INTO email_virtual_domains (name)
278 Post
::t('mail_domain'));
279 XDB
::execute('UPDATE email_virtual_domains
282 Post
::t('mail_domain'));
287 SET descr={?}, site={?}, mail={?}, resp={?},
288 forum={?}, pub= {?}, sub_url={?},
289 unsub_url = {?}, flags = {?}, welcome_msg = {?}
291 Post
::v('descr'), $site,
292 Post
::v('mail'), Post
::v('resp'),
293 Post
::v('forum'), Post
::v('pub'),
294 Post
::v('sub_url'), Post
::v('unsub_url'),
295 $flags, Post
::t('welcome_msg'),
296 $globals->asso('id'));
299 Phone
::deletePhones(0, Phone
::LINK_GROUP
, $globals->asso('id'));
300 $phone = new Phone(array('link_type' => 'group', 'link_id' => $globals->asso('id'), 'id' => 0,
301 'type' => 'fixed', 'display' => Post
::v('phone'), 'pub' => 'public'));
302 $fax = new Phone(array('link_type' => 'group', 'link_id' => $globals->asso('id'), 'id' => 1,
303 'type' => 'fax', 'display' => Post
::v('fax'), 'pub' => 'public'));
306 Address
::deleteAddresses(null
, Address
::LINK_GROUP
, null
, $globals->asso('id'));
307 $address = new Address(array('groupid' => $globals->asso('id'), 'type' => Address
::LINK_GROUP
, 'text' => Post
::v('address')));
310 if ($_FILES['logo']['name']) {
311 $upload = PlUpload
::get($_FILES['logo'], $globals->asso('id'), 'asso.logo', true
);
313 $page->trigError("Impossible de télécharger le logo.");
315 XDB
::execute('UPDATE groups
316 SET logo = {?}, logo_mime = {?}
317 WHERE id = {?}', $upload->getContents(), $upload->contentType(),
318 $globals->asso('id'));
323 XDB
::execute("UPDATE group_members
325 WHERE asso_id = {?}",
326 $globals->asso('id'));
328 XDB
::execute("UPDATE group_members
330 WHERE asso_id = {?} AND uid IN {?}",
331 $globals->asso('id'), $to_notify);
334 pl_redirect('../' . Post
::v('diminutif', $globals->asso('diminutif')) . '/edit');
337 $uf = New UserFilter(New UFC_Group($globals->asso('id'), true
, UFC_Group
::NOTIFIED
));
338 $page->assign('notified', $uf->getUsers());
339 $uf = New UserFilter(New UFC_Group($globals->asso('id'), true
, UFC_Group
::UNNOTIFIED
));
340 $page->assign('unnotified', $uf->getUsers());
342 $page->assign('error', $error);
343 $page->assign('cat', $globals->asso('cat'));
344 $page->assign('dom', $globals->asso('dom'));
345 $page->assign('ax', $globals->asso('ax'));
346 $page->assign('inscriptible', $globals->asso('inscriptible'));
347 $page->assign('pub', $globals->asso('pub'));
348 $page->assign('notif_unsub', $globals->asso('notif_unsub'));
349 $page->assign('notify_all', $globals->asso('notify_all'));
352 function handler_mail($page)
356 $page->changeTpl('xnetgrp/mail.tpl');
357 $mmlist = new MMList(S
::user(), $globals->asso('mail_domain'));
358 $page->assign('listes', $mmlist->get_lists());
359 $page->assign('user', S
::user());
361 if (Post
::has('send')) {
362 S
::assert_xsrf_token();
363 $from = Post
::v('from');
364 $sujet = Post
::v('sujet');
365 $body = Post
::v('body');
367 $mls = array_keys(Env
::v('ml', array()));
368 $mbr = array_keys(Env
::v('membres', array()));
370 $this->load('mail.inc.php');
372 $tos = get_all_redirects($mbr, $mls, $mmlist);
374 $upload = PlUpload
::get($_FILES['uploaded'], S
::user()->login(), 'xnet.emails', true
);
375 if (!$upload && @$_FILES['uploaded']['name'] && PlUpload
::$lastError != null
) {
376 $page->trigError(PlUpload
::$lastError);
380 send_xnet_mails($from, $sujet, $body, Env
::v('wiki'), $tos, Post
::v('replyto'), $upload, @$_FILES['uploaded']['name']);
384 $page->killSuccess("Email envoyé !");
385 $page->assign('sent', true
);
389 function handler_forum($page, $group = null
, $artid = null
)
392 $page->changeTpl('xnetgrp/forum.tpl');
393 if (!$globals->asso('forum')) {
396 require_once 'banana/forum.inc.php';
398 get_banana_params($get, $globals->asso('forum'), $group, $artid);
399 run_banana($page, 'ForumsBanana', $get);
402 function handler_annuaire($page, $action = null
, $subaction = null
)
406 __autoload('userset');
408 if ($action == 'admins') {
410 $action = $subaction;
412 $view = new UserSet(new UFC_Group($globals->asso('id'), $admins));
413 $view->addMod('groupmember', 'Annuaire');
414 $view->addMod('trombi', 'Trombinoscope');
415 $view->addMod('map', 'Planisphère');
416 $view->apply('annuaire', $page, $action);
417 $page->assign('only_admin', $admins);
418 $page->changeTpl('xnetgrp/annuaire.tpl');
421 function handler_former_users($page)
424 require_once 'userset.inc.php';
426 $view = new UserSet(new UFC_GroupFormerMember($globals->asso('id')));
427 $view->addMod('groupmember', 'Anciens membres', true
, array('noadmin' => true
));
428 $view->apply('former_users', $page);
429 $page->changeTpl('xnetgrp/former_users.tpl');
432 function handler_trombi($page)
434 pl_redirect('annuaire/trombi');
437 function handler_geoloc($page)
439 pl_redirect('annuaire/geoloc');
442 function handler_vcard($page, $photos = null
)
445 $vcard = new VCard($photos == 'photos', 'Membre du groupe ' . $globals->asso('nom'));
446 $vcard->addProfiles($globals->asso()->getMembersFilter()->getProfiles(null
, Profile
::FETCH_ALL
));
450 function handler_csv($page, $filename = null
)
453 if (is_null($filename)) {
454 $filename = $globals->asso('diminutif') . '.csv';
456 $users = $globals->asso()->getMembersFilter(null
, new UFO_Name())->getUsers();
457 pl_cached_content_headers('text/x-csv', 'iso-8859-1', 1);
459 echo utf8_decode("Nom;Prénom;Sexe;Promotion;Commentaire\n");
460 foreach ($users as $user) {
461 $line = $user->lastName() . ';' . $user->firstName() . ';' . ($user->isFemale() ?
'F' : 'M')
462 . ';' . $user->promo() . ';' . strtr($user->group_comm
, ';', ',');
463 echo utf8_decode($line) . "\n";
468 function handler_directory_sync($page)
471 require_once 'emails.inc.php';
473 $page->changeTpl('xnetgrp/sync.tpl');
474 Platal
::load('lists', 'lists.inc.php');
476 if (Env
::has('add_users')) {
477 S
::assert_xsrf_token();
479 $users = array_keys(Env
::v('add_users'));
480 $former_users = XDB
::fetchColumn('SELECT uid
481 FROM group_former_members
482 WHERE remember = TRUE AND uid IN {?}',
484 $new_users = array_diff($users, $former_users);
486 foreach ($former_users as $uid) {
487 $user = User
::getSilentWithUID($uid);
488 $page->trigWarning($user->fullName() . ' est un ancien membre du groupe qui ne souhaite pas y revenir.');
490 if (count($former_users) > 1) {
491 $page->trigWarning('S\'ils souhaitent revenir dans le groupe, il faut qu\'ils en fassent la demande sur la page d\'accueil du groupe.');
492 } elseif (count($former_users)) {
493 $page->trigWarning('S\'il souhaite revenir dans le groupe, il faut qu\'il en fasse la demande sur la page d\'accueil du groupe.');
497 foreach ($new_users as $uid) {
498 $data[] = XDB
::format('({?}, {?})', $globals->asso('id'), $uid);
500 XDB
::rawExecute('INSERT INTO group_members (asso_id, uid)
501 VALUES ' . implode(',', $data));
504 if (Env
::has('add_nonusers')) {
505 S
::assert_xsrf_token();
507 $nonusers = array_keys(Env
::v('add_nonusers'));
508 foreach ($nonusers as $email) {
509 if ($user = User
::getSilent($email) ||
!isvalid_email($email)) {
513 list($local_part, $domain) = explode('@', strtolower($email));
514 $hruid = User
::makeHrid($local_part, $domain, 'ext');
515 if ($user = User
::getSilent($hruid)) {
519 require_once 'name.func.inc.php';
520 $parts = explode('.', $local_part);
521 if (count($parts) == 1) {
522 $lastname = $display_name = capitalize_name($mbox);
525 $display_name = $firstname = capitalize_name($parts[0]);
526 $lastname = capitalize_name(implode(' ', array_slice($parts, 1)));
528 $full_name = build_full_name($firstname, $lastname);
529 $directory_name = build_directory_name($firstname, $lastname);
530 $sort_name = build_sort_name($firstname, $lastname);
531 XDB
::execute('INSERT INTO accounts (hruid, display_name, full_name, directory_name, sort_name,
532 firstname, lastname, email, type, state)
533 VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, \'xnet\', \'disabled\')',
534 $hruid, $display_name, $full_name, $directory_name, $sort_name, $firstname, $lastname, $email);
535 $uid = XDB
::insertId();
536 XDB
::execute('INSERT INTO group_members (asso_id, uid)
538 $globals->asso('id'), $uid);
542 if (Env
::has('add_users') || Env
::has('add_nonusers')) {
543 $page->trigSuccess('Ajouts réalisés avec succès.');
547 $client = new MMList($user, $globals->asso('mail_domain'));
548 $lists = $client->get_lists();
550 foreach ($lists as $list) {
551 $details = $client->get_members($list['list']);
552 $members = array_merge($members, list_extract_members($details[1]));
554 $members = array_unique($members);
558 foreach ($members as $email) {
559 if ($user = User
::getSilent($email)) {
560 $uids[] = $user->id();
562 $nonusers[] = $email;
566 $aliases = iterate_list_alias($globals->asso('mail_domain'));
567 foreach ($aliases as $alias) {
568 list($local_part, $domain) = explode('@', $alias);
569 $aliases_members = list_alias_members($local_part, $domain);
570 $users = array_merge($users, $aliases_members['users']);
571 $nonusers = array_merge($nonusers, $aliases_members['nonusers']);
573 foreach ($users as $user) {
574 $uids[] = $user->id();
576 $nonusers = array_unique($nonusers);
577 $uids = array_unique($uids);
579 $uids = XDB
::fetchColumn('SELECT a.uid
581 WHERE a.uid IN {?} AND NOT EXISTS (SELECT *
582 FROM group_members AS g
583 WHERE a.uid = g.uid AND g.asso_id = {?})',
584 $uids, $globals->asso('id'));
586 $users = User
::getBulkUsersWithUIDs($uids);
587 usort($users, 'User::compareDirectoryName');
593 $page->assign('users', $users);
594 $page->assign('nonusers', $nonusers);
597 function handler_non_active($page)
600 $page->changeTpl('xnetgrp/non_active.tpl');
602 $uids = XDB
::fetchColumn('SELECT g.uid
603 FROM group_members AS g
604 INNER JOIN accounts AS a ON (a.uid = g.uid)
605 LEFT JOIN register_pending_xnet AS p ON (p.uid = g.uid)
606 WHERE a.uid = g.uid AND g.asso_id = {?} AND a.type = \'xnet\' AND a.state = \'disabled\' AND p.uid IS NULL',
607 $globals->asso('id'));
608 foreach ($uids as $key => $uid) {
609 if (AccountReq
::isPending($uid) || BulkAccountsReq
::isPending($uid)) {
614 if (Post
::has('enable_accounts')) {
615 S
::assert_xsrf_token();
617 $uids_to_enable = array_intersect(array_keys(Post
::v('enable_accounts')), $uids);
620 $request = new BulkAccountsReq($user, $uids_to_enable, $globals->asso('nom'), $globals->asso('diminutif'));
622 $page->trigSuccess('Un email va bientôt être envoyé aux personnes sélectionnées pour l\'activation de leur compte.');
624 foreach ($uids as $key => $uid) {
625 if (in_array($uid, $uids_to_enable)) {
631 $users = User
::getBulkUsersWithUIDs($uids);
632 $page->assign('users', $users);
635 private function again($uid)
637 $data = XDB
::fetchOneAssoc('SELECT hash, group_name, sender_name, email
638 FROM register_pending_xnet
641 XDB
::execute('UPDATE register_pending_xnet
642 SET last_date = NOW()
646 $mailer = new PlMailer('xnet/account.mail.tpl');
647 $mailer->addCc('validation+xnet_account@polytechnique.org');
648 $mailer->setTo($data['email']);
649 $mailer->assign('hash', $data['hash']);
650 $mailer->assign('email', $data['email']);
651 $mailer->assign('group', $data['group_name']);
652 $mailer->assign('sender_name', $data['sender_name']);
653 $mailer->assign('again', true
);
654 $mailer->assign('baseurl', Platal
::globals()->xnet
->xorg_baseurl
);
658 function handler_awaiting_active($page)
661 $page->changeTpl('xnetgrp/awaiting_active.tpl');
663 XDB
::execute('DELETE FROM register_pending_xnet
664 WHERE DATE_SUB(NOW(), INTERVAL 1 MONTH) > date');
666 $uids = XDB
::fetchColumn('SELECT g.uid
667 FROM group_members AS g
668 INNER JOIN accounts AS a ON (a.uid = g.uid)
669 INNER JOIN register_pending_xnet AS p ON (p.uid = g.uid)
670 WHERE a.uid = g.uid AND g.asso_id = {?} AND a.type = \'xnet\' AND a.state = \'pending\'',
671 $globals->asso('id'));
673 if (Post
::has('again')) {
674 S
::assert_xsrf_token();
676 $uids_to_again = array_intersect(array_keys(Post
::v('again')), $uids);
677 foreach ($uids_to_again as $uid) {
680 $page->trigSuccess('Relances effectuées avec succès.');
683 $registration_date = XDB
::fetchAllAssoc('uid', 'SELECT uid, date
684 FROM register_pending_xnet
685 WHERE uid IN {?}', $uids);
686 $last_date = XDB
::fetchAllAssoc('uid', 'SELECT uid, last_date
687 FROM register_pending_xnet
688 WHERE uid IN {?}', $uids);
690 $users = User
::getBulkUsersWithUIDs($uids);
691 $page->assign('users', $users);
692 $page->assign('registration_date', $registration_date);
693 $page->assign('last_date', $last_date);
697 private function removeSubscriptionRequest($uid)
700 XDB
::execute("DELETE FROM group_member_sub_requests
701 WHERE asso_id = {?} AND uid = {?}",
702 $globals->asso('id'), $uid);
705 private function validSubscription(User
$user)
708 $this->removeSubscriptionRequest($user->id());
709 Group
::subscribe($globals->asso('id'), $user->id());
711 if (XDB
::affectedRows() == 1) {
712 $mailer = new PlMailer();
713 $mailer->addTo($user->forlifeEmail());
714 $mailer->setFrom('"' . S
::user()->fullName() . '" <' . S
::user()->forlifeEmail() . '>');
715 $mailer->setSubject('[' . $globals->asso('nom') . '] Demande d\'inscription');
716 $message = ($user->isFemale() ?
'Chère' : 'Cher') . " Camarade,\n"
718 . " Suite à ta demande d'adhésion à " . $globals->asso('nom')
719 . ", j'ai le plaisir de t'annoncer que ton inscription a été validée !\n"
720 . (is_null($globals->asso('welcome_msg')) ?
'' : "\n" . $globals->asso('welcome_msg') . "\n")
722 . "Bien cordialement,\n"
724 . S
::user()->fullName() . '.';
725 $mailer->setTxtBody(wordwrap($message, 72));
730 function handler_subscribe($page, $u = null
)
733 $page->changeTpl('xnetgrp/inscrire.tpl');
735 if (!$globals->asso('inscriptible'))
736 $page->kill("Il n'est pas possible de s'inscire en ligne à ce "
737 ."groupe. Essaie de joindre le contact indiqué "
738 ."sur la page de présentation.");
740 if (!is_null($u) && may_update()) {
741 $user = User
::get($u);
745 $page->assign('user', $user);
748 // Retrieves the subscription status, and the reason.
749 $res = XDB
::query("SELECT reason
750 FROM group_member_sub_requests
751 WHERE asso_id = {?} AND uid = {?}",
752 $globals->asso('id'), $user->id());
753 $reason = ($res->numRows() ?
$res->fetchOneCell() : null
);
755 $res = XDB
::query("SELECT COUNT(*)
757 WHERE asso_id = {?} AND uid = {?}",
758 $globals->asso('id'), $user->id());
759 $already_member = ($res->fetchOneCell() > 0);
761 // Handles the membership request.
762 if ($already_member) {
763 $this->removeSubscriptionRequest($user->id());
764 $page->kill($user->fullName() . ' est déjà membre du groupe !');
765 } elseif (Env
::has('accept')) {
766 S
::assert_xsrf_token();
768 $this->validSubscription($user);
769 pl_redirect("member/" . $user->login());
770 } elseif (Env
::has('refuse')) {
771 S
::assert_xsrf_token();
773 $this->removeSubscriptionRequest($user->id());
774 $mailer = new PlMailer();
775 $mailer->addTo($user->forlifeEmail());
776 $mailer->setFrom('"' . S
::user()->fullName() . '" <' . S
::user()->forlifeEmail() . '>');
777 $mailer->setSubject('['.$globals->asso('nom').'] Demande d\'inscription annulée');
778 $mailer->setTxtBody(Env
::v('motif'));
780 $page->killSuccess("La demande de {$user->fullName()} a bien été refusée.");
782 $page->assign('show_form', true
);
783 $page->assign('reason', $reason);
789 $page->kill("Tu es déjà membre !");
793 $res = XDB
::query("SELECT uid
794 FROM group_member_sub_requests
795 WHERE uid = {?} AND asso_id = {?}",
796 S
::i('uid'), $globals->asso('id'));
797 if ($res->numRows() != 0) {
798 $page->kill("Tu as déjà demandé ton inscription à ce groupe. Cette demande est actuellement en attente de validation.");
802 if (Post
::has('inscrire')) {
803 S
::assert_xsrf_token();
805 XDB
::execute("INSERT INTO group_member_sub_requests (asso_id, uid, ts, reason)
806 VALUES ({?}, {?}, NOW(), {?})",
807 $globals->asso('id'), S
::i('uid'), Post
::v('message'));
808 XDB
::execute('DELETE FROM group_former_members
809 WHERE uid = {?} AND asso_id = {?}',
810 S
::i('uid'), $globals->asso('id'));
811 $admins = $globals->asso()->iterToNotify();
812 $admin = $admins->next();
813 $to = $admin->bestEmail();
814 while ($admin = $admins->next()) {
815 $to .= ', ' . $admin->bestEmail();
820 . "Ce message a été envoyé suite à la demande d'inscription de\n"
821 . S
::user()->fullName(true
) . "\n"
822 . "Via le site www.polytechnique.net. Tu peux choisir de valider ou\n"
823 . "de refuser sa demande d'inscription depuis la page :\n"
824 . "http://www.polytechnique.net/" . $globals->asso("diminutif") . "/subscribe/" . S
::user()->login() . "\n"
826 . "En cas de problème, contacter l'équipe de Polytechnique.org\n"
827 . "à l'adresse : support@polytechnique.org\n";
830 $to = ($globals->asso('mail') != '') ?
$globals->asso('mail') . ', ' : '';
831 $to .= 'support@polytechnique.org';
832 $append = "\n-- \nLe groupe ".$globals->asso("nom")
833 ." n'a pas d'administrateur, l'équipe de"
834 ." Polytechnique.org a été prévenue et va rapidement"
835 ." résoudre ce problème.\n";
838 $mailer = new PlMailer();
840 $mailer->setFrom('"' . S
::user()->fullName() . '" <' . S
::user()->forlifeEmail() . '>');
841 $mailer->setSubject('['.$globals->asso('nom').'] Demande d\'inscription');
842 $mailer->setTxtBody(Post
::v('message').$append);
847 function handler_subscribe_valid($page)
851 if (Post
::has('valid')) {
852 S
::assert_xsrf_token();
853 $subs = Post
::v('subs');
854 if (is_array($subs)) {
856 foreach ($subs as $hruid => $val) {
858 $user = User
::get($hruid);
860 $this->validSubscription($user);
867 $it = XDB
::iterator('SELECT s.uid, a.hruid, s.ts AS date
868 FROM group_member_sub_requests AS s
869 INNER JOIN accounts AS a ON(s.uid = a.uid)
870 WHERE s.asso_id = {?}
871 ORDER BY s.ts', $globals->asso('id'));
872 $page->changeTpl('xnetgrp/subscribe-valid.tpl');
873 $page->assign('valid', $it);
876 function handler_change_rights($page)
878 if (Env
::has('right') && (may_update() || S
::suid())) {
879 switch (Env
::v('right')) {
881 Platal
::session()->stopSUID();
884 Platal
::session()->doSelfSuid();
889 Platal
::session()->doSelfSuid();
890 may_update(false
, true
);
894 Platal
::session()->doSelfSuid();
895 may_update(false
, true
);
896 is_member(false
, true
);
900 http_redirect($_SERVER['HTTP_REFERER']);
903 function handler_admin_annuaire($page)
907 $this->load('mail.inc.php');
908 $page->changeTpl('xnetgrp/annuaire-admin.tpl');
910 $mmlist = new MMList($user, $globals->asso('mail_domain'));
911 $lists = $mmlist->get_lists();
912 if (!$lists) $lists = array();
913 $listes = array_map(create_function('$arr', 'return $arr["list"];'), $lists);
915 $subscribers = array();
917 foreach ($listes as $list) {
918 list(,$members) = $mmlist->get_members($list);
919 $mails = array_map(create_function('$arr', 'return $arr[1];'), $members);
920 $subscribers = array_unique(array_merge($subscribers, $mails));
923 $not_in_group_x = array();
924 $not_in_group_ext = array();
926 foreach ($subscribers as $mail) {
927 $uf = new UserFilter(new PFC_And(new UFC_Group($globals->asso('id')),
928 new UFC_Email($mail)));
929 if ($uf->getTotalCount() == 0) {
930 if (User
::isForeignEmailAddress($mail)) {
931 $not_in_group_ext[] = $mail;
933 $not_in_group_x[] = $mail;
938 $page->assign('not_in_group_ext', $not_in_group_ext);
939 $page->assign('not_in_group_x', $not_in_group_x);
940 $page->assign('lists', $lists);
943 function handler_admin_member_new($page, $email = null
)
947 $page->changeTpl('xnetgrp/membres-add.tpl');
948 $page->addJsLink('xnet_members.js');
950 if (is_null($email)) {
954 S
::assert_xsrf_token();
955 $suggest_account_activation = false
;
957 // FS#703 : $_GET is urldecoded twice, hence
958 // + (the data) => %2B (in the url) => + (first decoding) => ' ' (second decoding)
959 // Since there can be no spaces in emails, we can fix this with :
960 $email = str_replace(' ', '+', $email);
961 $is_valid_email = isvalid_email($email);
963 // X not registered to main site.
964 if (Env
::v('x') && Env
::i('userid') && $is_valid_email) {
965 $user = User
::getSilentWithUID(Env
::i('userid'));
967 $page->trigError('Utilisateur invalide.');
971 // User has an account but is not yet registered.
972 if ($user->state
== 'pending') {
973 // Add email in account table.
974 XDB
::query('UPDATE accounts
976 WHERE uid = {?} AND email IS NULL',
977 $email, $user->id());
978 // Add email for marketing if required.
979 if (Env
::v('marketing')) {
980 $market = Marketing
::get($user->uid
, $email);
982 $market = new Marketing($user->uid
, $email, 'group', $globals->asso('nom'),
983 Env
::v('marketing_from'), S
::v('uid'));
987 } elseif (Env
::v('broken')) {
988 // Add email for broken if required.
989 $valid = new BrokenReq(S
::user(), $user, $email, 'Groupe : ' . $globals->asso('nom'));
993 $user = User
::getSilent($email);
995 // Wrong email and no user: failure.
996 if (is_null($user) && (!$is_valid_email ||
!User
::isForeignEmailAddress($email))) {
997 $page->trigError('« <strong>' . $email . '</strong> » n\'est pas une adresse email valide.');
1001 // Deals with xnet accounts.
1002 if (is_null($user) ||
$user->type
== 'xnet') {
1003 // User is of type xnet. There are 3 possible cases:
1004 // * the email is not known yet: we create a new account and
1005 // propose to send an email to the user so he can activate
1007 // * the email is known but the user was not contacted in order to
1008 // activate yet: we propose to send an email to the user so he
1009 // can activate his account,
1010 // * the email is known and the user was already contacted or has
1011 // an active account: nothing to be done.
1012 list($mbox, $domain) = explode('@', strtolower($email));
1013 $hruid = User
::makeHrid($mbox, $domain, 'ext');
1014 // User might already have an account (in another group for example).
1015 $user = User
::getSilent($hruid);
1017 // If the user has no account yet, creates new account: build names from email address.
1019 require_once 'name.func.inc.php';
1020 $parts = explode('.', $mbox);
1021 if (count($parts) == 1) {
1022 $lastname = $display_name = capitalize_name($mbox);
1025 $display_name = $firstname = capitalize_name($parts[0]);
1026 $lastname = capitalize_name(implode(' ', array_slice($parts, 1)));
1028 $full_name = build_full_name($firstname, $lastname);
1029 $directory_name = build_directory_name($firstname, $lastname);
1030 $sort_name = build_sort_name($firstname, $lastname);
1031 XDB
::execute('INSERT INTO accounts (hruid, display_name, full_name, directory_name, sort_name,
1032 firstname, lastname, email, type, state)
1033 VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, \'xnet\', \'disabled\')',
1034 $hruid, $display_name, $full_name, $directory_name, $sort_name, $firstname, $lastname, $email);
1035 $user = User
::getSilent($hruid);
1038 $suggest_account_activation = $this->suggest($user);
1043 // First check if the user used to be in this group.
1044 XDB
::rawExecute('DELETE FROM group_former_members
1045 WHERE remember AND DATE_SUB(NOW(), INTERVAL 1 YEAR) > unsubsciption_date');
1046 $former_member = XDB
::fetchOneCell('SELECT remember
1047 FROM group_former_members
1048 WHERE uid = {?} AND asso_id = {?}',
1049 $user->id(), $globals->asso('id'));
1050 if ($former_member === 1) {
1051 $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.');
1053 } elseif (!is_null($former_member) && Post
::i('force_continue') == 0) {
1054 $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.');
1055 $page->assign('force_continue', 1);
1059 Group
::subscribe($globals->asso('id'), $user->id());
1060 $this->removeSubscriptionRequest($user->id());
1061 if ($suggest_account_activation) {
1062 pl_redirect('member/suggest/' . $user->login() . '/' . $email . '/' . $globals->asso('nom'));
1064 pl_redirect('member/' . $user->login());
1069 // Check if the user has a pending or active account, and thus if we should her account's activation.
1070 private function suggest(PlUser
$user)
1072 $active = XDB
::fetchOneCell('SELECT state = \'active\'
1076 $pending = XDB
::fetchOneCell('SELECT uid
1077 FROM register_pending_xnet
1080 $requested = AccountReq
::isPending($user->id()) || BulkAccountsReq
::isPending($user->id());
1082 if ($active ||
$pending ||
$requested) {
1088 function handler_admin_member_suggest($page, $hruid, $email)
1090 $page->changeTpl('xnetgrp/membres-suggest.tpl');
1092 // FS#703 : $_GET is urldecoded twice, hence
1093 // + (the data) => %2B (in the url) => + (first decoding) => ' ' (second decoding)
1094 // Since there can be no spaces in emails, we can fix this with :
1095 $email = str_replace(' ', '+', $email);
1097 if (Post
::has('suggest')) {
1098 if (Post
::t('suggest') == 'yes') {
1102 $request = new AccountReq($user, $hruid, $email, $globals->asso('nom'), $globals->asso('diminutif'));
1104 $page->trigSuccessRedirect('Un email va bien être envoyé à ' . $email . ' pour l\'activation de son compte.',
1105 $globals->asso('diminutif') . '/member/' . $hruid);
1107 pl_redirect('member/' . $hruid);
1110 $page->assign('email', $email);
1111 $page->assign('hruid', $hruid);
1114 function handler_admin_member_reg($page, $uid)
1116 pl_content_headers('text/plain');
1118 $user = User
::getSilentWithUID($uid);
1119 if ($user && $user->state
!= 'pending' && $user->hasProfile()) {
1126 function handler_admin_member_new_ajax($page)
1128 pl_content_headers("text/html");
1129 $page->changeTpl('xnetgrp/membres-new-search.tpl', NO_SKIN
);
1131 $same_email = false
;
1132 if (Env
::has('login')) {
1133 $user = User
::getSilent(Env
::t('login'));
1134 if ($user && $user->state
!= 'pending') {
1135 $users = array($user->id() => $user);
1139 if (empty($users)) {
1140 list($lastname, $firstname) = str_replace(array('-', ' ', "'"), '%', array(Env
::t('nom'), Env
::t('prenom')));
1141 $cond = new PFC_And();
1142 if (!empty($lastname)) {
1143 $cond->addChild(new UFC_NameTokens($lastname, array(), false
, false
, Profile
::LASTNAME
));
1145 if (!empty($firstname)) {
1146 $cond->addChild(new UFC_NameTokens($firstname, array(), false
, false
, Profile
::FIRSTNAME
));
1148 if (Env
::t('promo')) {
1149 $cond->addChild(new UFC_Promo('=', UserFilter
::DISPLAY
, Env
::t('promo')));
1151 $uf = new UserFilter($cond);
1152 $users = $uf->getUsers(new PlLimit(30));
1153 if ($uf->getTotalCount() > 30) {
1154 $page->assign('too_many', true
);
1159 $page->assign('users', $users);
1160 $page->assign('same_email', $same_email);
1163 function unsubscribe(PlUser
$user, $remember = false
)
1166 Group
::unsubscribe($globals->asso('id'), $user->id(), $remember);
1168 if ($globals->asso('notif_unsub')) {
1169 $mailer = new PlMailer('xnetgrp/unsubscription-notif.mail.tpl');
1170 $admins = $globals->asso()->iterToNotify();
1171 while ($admin = $admins->next()) {
1172 $mailer->addTo($admin);
1174 $mailer->assign('group', $globals->asso('nom'));
1175 $mailer->assign('user', $user);
1176 $mailer->assign('selfdone', $user->id() == S
::i('uid'));
1180 $domain = $globals->asso('mail_domain');
1185 $mmlist = new MMList(S
::user(), $domain);
1186 $listes = $mmlist->get_lists($user->forlifeEmail());
1188 $may_update = may_update();
1190 if (is_array($listes)) {
1191 foreach ($listes as $liste) {
1192 if ($liste['sub'] == 2) {
1194 $mmlist->mass_unsubscribe($liste['list'], Array($user->forlifeEmail()));
1196 $mmlist->unsubscribe($liste['list']);
1198 } elseif ($liste['sub']) {
1199 Platal
::page()->trigWarning($user->fullName() . " a une"
1200 ." demande d'inscription en cours sur la"
1201 ." liste {$liste['list']}@ !");
1207 XDB
::execute('DELETE v
1208 FROM email_virtual AS v
1209 INNER JOIN email_virtual_domains AS d ON (v.domain = d.id)
1210 WHERE v.redirect = {?} AND d.name = {?}',
1211 $user->forlifeEmail(), $domain);
1215 function handler_unsubscribe($page)
1217 $page->changeTpl('xnetgrp/membres-del.tpl');
1220 return PL_NOT_FOUND
;
1222 $page->assign('self', true
);
1223 $page->assign('user', $user);
1225 if (!Post
::has('confirm')) {
1228 S
::assert_xsrf_token();
1231 $hasSingleGroup = ($user->groupCount() == 1);
1233 if ($this->unsubscribe($user, Post
::b('remember'))) {
1234 $page->trigSuccess('Tu as été désinscrit du groupe avec succès.');
1236 $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.');
1239 // If user is of type xnet account and this was her last group, disable the account.
1240 if ($user->type
== 'xnet' && $hasSingleGroup) {
1243 $page->assign('is_member', is_member(true
));
1246 function handler_admin_member_del($page, $user = null
)
1248 $page->changeTpl('xnetgrp/membres-del.tpl');
1249 $user = User
::getSilent($user);
1251 return PL_NOT_FOUND
;
1256 if (!$user->inGroup($globals->asso('id'))) {
1257 pl_redirect('annuaire');
1260 $page->assign('self', false
);
1261 $page->assign('user', $user);
1263 if (!Post
::has('confirm')) {
1266 S
::assert_xsrf_token();
1269 $hasSingleGroup = ($user->groupCount() == 1);
1271 if ($this->unsubscribe($user)) {
1272 $page->trigSuccess("{$user->fullName()} a été désinscrit du groupe !");
1274 $page->trigWarning("{$user->fullName()} a été désinscrit du groupe, mais des erreurs subsistent !");
1277 // If user is of type xnet account and this was her last group, disable the account.
1278 if ($user->type
== 'xnet' && $hasSingleGroup) {
1283 private function changeLogin(PlPage
$page, PlUser
$user, $login, $req_broken = false
, $req_marketing = false
, $marketing_from = 'user')
1285 // Search the user's uid.
1286 $xuser = User
::getSilent($login);
1288 $accounts = User
::getPendingAccounts($login);
1290 $page->trigError("L'identifiant $login ne correspond à aucun X.");
1292 } else if (count($accounts) > 1) {
1293 $page->trigError("L'identifiant $login correspond à plusieurs camarades.");
1296 $xuser = User
::getSilent($accounts[0]['uid']);
1303 // Market or suggest new redirection if required.
1304 $email = $user->bestEmail();
1306 $valid = new BrokenReq(S
::user(), $xuser, $email, 'Groupe : ' . Platal
::globals()->asso('nom'));
1308 } elseif ($req_marketing) {
1309 $market = Marketing
::get($xuser->uid
, $email);
1311 $market = new Marketing($xuser->uid
, $email, 'group', Platal
::globals()->asso('nom'), $marketing_from, S
::i('uid'));
1316 if ($user->mergeIn($xuser)) {
1317 return $xuser->login();
1319 return $user->login();
1322 function handler_admin_member($page, $user)
1326 $user = User
::getSilent($user);
1328 return PL_NOT_FOUND
;
1331 if (!$user->inGroup($globals->asso('id'))) {
1332 pl_redirect('annuaire');
1335 $page->changeTpl('xnetgrp/membres-edit.tpl');
1336 $page->addJsLink('xnet_members.js');
1338 $mmlist = new MMList(S
::user(), $globals->asso('mail_domain'));
1340 if (Post
::has('change')) {
1341 S
::assert_xsrf_token();
1342 require_once 'emails.inc.php';
1343 require_once 'name.func.inc.php';
1345 // Convert user status to X
1346 if (!Post
::blank('x')) {
1347 $forlife = $this->changeLogin($page, $user, Post
::i('userid'), Post
::b('broken'), Post
::b('marketing'), Post
::v('marketing_from'));
1349 pl_redirect('member/' . $forlife);
1354 if ($user->type
== 'virtual' ||
($user->type
== 'xnet' && !$user->perms
)) {
1355 $lastname = capitalize_name(Post
::t('lastname'));
1356 if (Post
::s('type') != 'virtual') {
1357 $firstname = capitalize_name(Post
::t('firstname'));
1361 $full_name = build_full_name($firstname, $lastname);
1362 $directory_name = build_directory_name($firstname, $lastname);
1363 $sort_name = build_sort_name($firstname, $lastname);
1364 XDB
::query('UPDATE accounts
1365 SET full_name = {?}, directory_name = {?}, sort_name = {?}, display_name = {?},
1366 firstname = {?}, lastname = {?}, sex = {?}, type = {?}
1368 $full_name, $directory_name, $sort_name, Post
::t('display_name'), $firstname, $lastname,
1369 (Post
::t('sex') == 'male') ?
'male' : 'female',
1370 (Post
::t('type') == 'xnet') ?
'xnet' : 'virtual', $user->id());
1374 $new_email = strtolower(Post
::t('email'));
1375 if (($user->type
== 'virtual' ||
($user->type
== 'xnet' && !$user->perms
))
1376 && require_email_update($user, $new_email)) {
1377 XDB
::query('UPDATE accounts
1380 $new_email, $user->id());
1381 if ($user->forlifeEmail()) {
1382 $listClient = new MMList(S
::user());
1383 $listClient->change_user_email($user->forlifeEmail(), $new_email);
1384 update_alias_user($user->forlifeEmail(), $new_email);
1386 $user = User
::getWithUID($user->id());
1388 if (XDB
::affectedRows()) {
1389 $page->trigSuccess('Données de l\'utilisateur mises à jour.');
1392 if (($user->type
== 'xnet' && !$user->perms
)) {
1393 if (Post
::b('suggest')) {
1394 $request = new AccountReq(S
::user(), $user->hruid
, Post
::t('email'), $globals->asso('nom'), $globals->asso('diminutif'));
1396 $page->trigSuccess('Le compte va bientôt être activé.');
1398 if (Post
::b('again')) {
1399 $this->again($user->id());
1400 $page->trigSuccess('Relance effectuée avec succès.');
1404 // Update group params for user
1405 $perms = Post
::v('group_perms');
1406 $comm = Post
::t('comm');
1407 $position = (Post
::t('group_position') == '') ? null
: Post
::v('group_position');
1408 if ($user->group_perms
!= $perms ||
$user->group_comm
!= $comm ||
$user->group_position
!= $position) {
1409 XDB
::query('UPDATE group_members
1410 SET perms = {?}, comm = {?}, position = {?}
1411 WHERE uid = {?} AND asso_id = {?}',
1412 ($perms == 'admin') ?
'admin' : 'membre', $comm, $position,
1413 $user->id(), $globals->asso('id'));
1414 if (XDB
::affectedRows()) {
1415 if ($perms != $user->group_perms
) {
1416 $page->trigSuccess('Permissions modifiées !');
1418 if ($comm != $user->group_comm
) {
1419 $page->trigSuccess('Commentaire mis à jour.');
1421 if ($position != $user->group_position
) {
1422 $page->trigSuccess('Poste mis à jour.');
1427 // Gets user info again as they might have change
1428 $user = User
::getSilent($user->id());
1430 // Update ML subscriptions
1431 foreach (Env
::v('ml1', array()) as $ml => $state) {
1432 $ask = empty($_REQUEST['ml2'][$ml]) ?
0 : 2;
1433 if ($ask == $state) {
1436 if ($state == '1') {
1437 $page->trigWarning("{$user->fullName()} a "
1438 ."actuellement une demande d'inscription en "
1439 ."cours sur <strong>$ml@</strong> !!!");
1441 $mmlist->mass_subscribe($ml, Array($user->forlifeEmail()));
1442 $page->trigSuccess("{$user->fullName()} a été abonné à $ml@.");
1444 $mmlist->mass_unsubscribe($ml, Array($user->forlifeEmail()));
1445 $page->trigSuccess("{$user->fullName()} a été désabonné de $ml@.");
1449 // Change subscriptioin to aliases
1450 foreach (Env
::v('ml3', array()) as $ml => $state) {
1451 require_once 'emails.inc.php';
1452 $ask = !empty($_REQUEST['ml4'][$ml]);
1453 list($local_part, ) = explode('@', $ml);
1454 if ($ask == $state) {
1458 add_to_list_alias($user->id(), $local_part, $globals->asso('mail_domain'));
1459 $page->trigSuccess("{$user->fullName()} a été abonné à $ml.");
1461 delete_from_list_alias($user->id(), $local_part, $globals->asso('mail_domain'));
1462 $page->trigSuccess("{$user->fullName()} a été désabonné de $ml.");
1466 if ($globals->asso('has_nl')) {
1467 $nl = NewsLetter
::forGroup($globals->asso('shortname'));
1468 // Updates group's newsletter subscription.
1469 if (Post
::i('newsletter') == 1) {
1470 $nl->subscribe($user);
1472 $nl->unsubscribe(null
, $user->id());
1477 $res = XDB
::rawFetchAllAssoc('SHOW COLUMNS FROM group_members LIKE \'position\'');
1478 $positions = str_replace(array('enum(', ')', '\''), '', $res[0]['Type']);
1479 if ($globals->asso('has_nl')) {
1480 $nl = NewsLetter
::forGroup($globals->asso('shortname'));
1481 $nl_registered = $nl->subscriptionState($user);
1483 $nl_registered = false
;
1486 $page->assign('user', $user);
1487 $page->assign('suggest', $this->suggest($user));
1488 $page->assign('listes', $mmlist->get_lists($user->forlifeEmail()));
1489 $page->assign('alias', $user->emailGroupAliases($globals->asso('mail_domain')));
1490 $page->assign('positions', explode(',', $positions));
1491 $page->assign('nl_registered', $nl_registered);
1492 $page->assign('pending_xnet_account', XDB
::fetchOneCell('SELECT 1
1493 FROM register_pending_xnet
1498 function handler_rss(PlPage
$page, PlUser
$user)
1501 $page->assign('asso', $globals->asso());
1503 $this->load('feed.inc.php');
1504 $feed = new XnetGrpEventFeed();
1505 return $feed->run($page, $user, false
);
1508 private function upload_image(PlPage
$page, PlUpload
$upload)
1510 if (@!$_FILES['image']['tmp_name'] && !Env
::v('image_url')) {
1513 if (!$upload->upload($_FILES['image']) && !$upload->download(Env
::v('image_url'))) {
1514 $page->trigError('Impossible de télécharger l\'image');
1516 } elseif (!$upload->isType('image')) {
1517 $page->trigError('Le fichier n\'est pas une image valide au format JPEG, GIF ou PNG.');
1520 } elseif (!$upload->resizeImage(80, 100, 100, 100, 32284)) {
1521 $page->trigError('Impossible de retraiter l\'image');
1527 function handler_photo_announce($page, $eid = null
) {
1529 $res = XDB
::query('SELECT *
1530 FROM group_announces_photo
1531 WHERE eid = {?}', $eid);
1532 if ($res->numRows()) {
1533 $photo = $res->fetchOneAssoc();
1534 pl_cached_dynamic_content_headers("image/" . $photo['attachmime']);
1535 echo $photo['attach'];
1539 $upload = new PlUpload(S
::user()->login(), 'xnetannounce');
1540 if ($upload->exists() && $upload->isType('image')) {
1541 pl_cached_dynamic_content_headers($upload->contentType());
1542 echo $upload->getContents();
1547 pl_cached_dynamic_content_headers("image/png");
1548 echo file_get_contents($globals->spoolroot
. '/htdocs/images/logo.png');
1552 function handler_edit_announce($page, $aid = null
)
1554 global $globals, $platal;
1555 $page->changeTpl('xnetgrp/announce-edit.tpl');
1556 $page->assign('new', is_null($aid));
1559 if (Post
::v('valid') == 'Visualiser' || Post
::v('valid') == 'Enregistrer'
1560 || Post
::v('valid') == 'Supprimer l\'image' || Post
::v('valid') == 'Pas d\'image') {
1561 S
::assert_xsrf_token();
1563 if (!is_null($aid)) {
1566 $art['titre'] = Post
::v('titre');
1567 $art['texte'] = Post
::v('texte');
1568 $art['contacts'] = Post
::v('contacts');
1569 $art['promo_min'] = Post
::i('promo_min');
1570 $art['promo_max'] = Post
::i('promo_max');
1571 $art['nom'] = S
::v('nom');
1572 $art['prenom'] = S
::v('prenom');
1573 $art['promo'] = S
::v('promo');
1574 $art['hruid'] = S
::user()->login();
1575 $art['uid'] = S
::user()->id();
1576 $art['expiration'] = Post
::v('expiration');
1577 $art['public'] = Post
::has('public');
1578 $art['xorg'] = Post
::has('xorg');
1579 $art['nl'] = Post
::has('nl');
1580 $art['event'] = Post
::v('event');
1581 $upload = new PlUpload(S
::user()->login(), 'xnetannounce');
1582 $this->upload_image($page, $upload);
1584 $art['contact_html'] = $art['contacts'];
1585 if ($art['event']) {
1586 $art['contact_html'] .= "\n{$globals->baseurl}/{$platal->ns}events/sub/{$art['event']}";
1589 if (!$art['public'] &&
1590 (($art['promo_min'] > $art['promo_max'] && $art['promo_max'] != 0) ||
1591 ($art['promo_min'] != 0 && ($art['promo_min'] <= 1900 ||
$art['promo_min'] >= 2020)) ||
1592 ($art['promo_max'] != 0 && ($art['promo_max'] <= 1900 ||
$art['promo_max'] >= 2020))))
1594 $page->trigError("L'intervalle de promotions est invalide.");
1595 Post
::kill('valid');
1598 if (!trim($art['titre']) ||
!trim($art['texte'])) {
1599 $page->trigError("L'article doit avoir un titre et un contenu.");
1600 Post
::kill('valid');
1603 if (Post
::v('valid') == 'Supprimer l\'image') {
1605 Post
::kill('valid');
1607 $art['photo'] = $upload->exists() || Post
::i('photo');
1608 if (Post
::v('valid') == 'Pas d\'image' && !is_null($aid)) {
1609 XDB
::query('DELETE FROM group_announces_photo
1610 WHERE eid = {?}', $aid);
1612 Post
::kill('valid');
1613 $art['photo'] = false
;
1617 if (Post
::v('valid') == 'Enregistrer') {
1618 $promo_min = ($art['public'] ?
0 : $art['promo_min']);
1619 $promo_max = ($art['public'] ?
0 : $art['promo_max']);
1620 $flags = new PlFlagSet();
1621 if ($art['public']) {
1622 $flags->addFlag('public');
1624 if ($art['photo']) {
1625 $flags->addFlag('photo');
1627 if (is_null($aid)) {
1628 $fulltext = $art['texte'];
1629 if (!empty($art['contact_html'])) {
1630 $fulltext .= "\n\n'''Contacts :'''\\\\\n" . $art['contact_html'];
1633 if ($globals->asso('forum')) {
1634 require_once 'banana/forum.inc.php';
1635 $banana = new ForumsBanana(S
::user());
1636 $post = $banana->post($globals->asso('forum'), null
,
1637 $art['titre'], MiniWiki
::wikiToText($fulltext, false
, 0, 80));
1639 XDB
::query('INSERT INTO group_announces (uid, asso_id, create_date, titre, texte, contacts,
1640 expiration, promo_min, promo_max, flags, post_id)
1641 VALUES ({?}, {?}, NOW(), {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})',
1642 S
::i('uid'), $globals->asso('id'), $art['titre'], $art['texte'], $art['contact_html'],
1643 $art['expiration'], $promo_min, $promo_max, $flags, $post);
1644 $aid = XDB
::insertId();
1645 if ($art['photo']) {
1646 list($imgx, $imgy, $imgtype) = $upload->imageInfo();
1647 XDB
::execute('INSERT INTO group_announces_photo
1648 SET eid = {?}, attachmime = {?}, x = {?}, y = {?}, attach = {?}',
1649 $aid, $imgtype, $imgx, $imgy, $upload->getContents());
1652 $article = new EvtReq("[{$globals->asso('nom')}] " . $art['titre'], $fulltext,
1653 $art['promo_min'], $art['promo_max'], $art['expiration'], "", S
::user(),
1656 $page->trigWarning("L'affichage sur la page d'accueil de Polytechnique.org est en attente de validation.");
1657 } else if ($upload && $upload->exists()) {
1661 $article = new NLReq(S
::user(), $globals->asso('nom') . " : " .$art['titre'],
1662 $art['texte'], $art['contact_html']);
1664 $page->trigWarning("La parution dans la Lettre Mensuelle est en attente de validation.");
1667 XDB
::query('UPDATE group_announces
1668 SET titre = {?}, texte = {?}, contacts = {?}, expiration = {?},
1669 promo_min = {?}, promo_max = {?}, flags = {?}
1670 WHERE id = {?} AND asso_id = {?}',
1671 $art['titre'], $art['texte'], $art['contacts'], $art['expiration'],
1672 $promo_min, $promo_max, $flags,
1673 $art['id'], $globals->asso('id'));
1674 if ($art['photo'] && $upload->exists()) {
1675 list($imgx, $imgy, $imgtype) = $upload->imageInfo();
1676 XDB
::execute('INSERT INTO group_announces_photo (eid, attachmime, attach, x, y)
1677 VALUES ({?}, {?}, {?}, {?}, {?})
1678 ON DUPLICATE KEY UPDATE attachmime = VALUES(attachmime), attach = VALUES(attach), x = VALUES(x), y = VALUES(y)',
1679 $aid, $imgtype, $upload->getContents(), $imgx, $imgy);
1684 if (Post
::v('valid') == 'Enregistrer' || Post
::v('valid') == 'Annuler') {
1688 if (empty($art) && !is_null($aid)) {
1689 $res = XDB
::query("SELECT *, FIND_IN_SET('public', flags) AS public,
1690 FIND_IN_SET('photo', flags) AS photo
1691 FROM group_announces
1692 WHERE asso_id = {?} AND id = {?}",
1693 $globals->asso('id'), $aid);
1694 if ($res->numRows()) {
1695 $art = $res->fetchOneAssoc();
1696 $art['contact_html'] = $art['contacts'];
1698 $page->kill("Aucun article correspond à l'identifiant indiqué.");
1702 if (is_null($aid)) {
1703 $events = XDB
::iterator("SELECT *
1705 WHERE asso_id = {?} AND archive = 0",
1706 $globals->asso('id'));
1707 if ($events->total()) {
1708 $page->assign('events', $events);
1712 $art['contact_html'] = @MiniWiki
::WikiToHTML($art['contact_html']);
1713 $page->assign('art', $art);
1714 $page->assign_by_ref('upload', $upload);
1717 function handler_admin_announce($page)
1720 $page->changeTpl('xnetgrp/announce-admin.tpl');
1722 if (Env
::has('del')) {
1723 S
::assert_xsrf_token();
1724 XDB
::execute('DELETE FROM group_announces
1725 WHERE id = {?} AND asso_id = {?}',
1726 Env
::i('del'), $globals->asso('id'));
1728 $res = XDB
::iterator('SELECT id, titre, expiration, expiration < CURRENT_DATE() AS perime
1729 FROM group_announces
1731 ORDER BY expiration DESC',
1732 $globals->asso('id'));
1733 $page->assign('articles', $res);
1737 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: