96fd4c6c5693a36b72296ff18c36cf992c6e1a25
2 /***************************************************************************
3 * Copyright (C) 2003-2011 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
23 class XnetGrpModule
extends PLModule
28 '%grp' => $this->make_hook('index', AUTH_PUBLIC
),
29 '%grp/asso.php' => $this->make_hook('index', AUTH_PUBLIC
),
30 '%grp/logo' => $this->make_hook('logo', AUTH_PUBLIC
),
31 '%grp/site' => $this->make_hook('site', AUTH_PUBLIC
),
32 '%grp/edit' => $this->make_hook('edit', AUTH_PASSWD
, 'groupadmin'),
33 '%grp/mail' => $this->make_hook('mail', AUTH_PASSWD
, 'groupadmin'),
34 '%grp/forum' => $this->make_hook('forum', AUTH_PASSWD
, 'groupmember'),
35 '%grp/former_users' => $this->make_hook('former_users', AUTH_PASSWD
, 'admin'),
36 '%grp/annuaire' => $this->make_hook('annuaire', AUTH_PASSWD
, 'groupannu'),
37 '%grp/annuaire/vcard' => $this->make_hook('vcard', AUTH_PASSWD
, 'groupmember:groupannu'),
38 '%grp/annuaire/csv' => $this->make_hook('csv', AUTH_PASSWD
, 'groupmember:groupannu'),
39 '%grp/directory/sync' => $this->make_hook('directory_sync', AUTH_PASSWD
, 'groupadmin'),
40 '%grp/directory/unact' => $this->make_hook('non_active', AUTH_PASSWD
, 'groupadmin'),
41 '%grp/trombi' => $this->make_hook('trombi', AUTH_PASSWD
, 'groupannu'),
42 '%grp/geoloc' => $this->make_hook('geoloc', AUTH_PASSWD
, 'groupannu'),
43 '%grp/subscribe' => $this->make_hook('subscribe', AUTH_PASSWD
, 'groups'),
44 '%grp/subscribe/valid' => $this->make_hook('subscribe_valid', AUTH_PASSWD
, 'groupadmin'),
45 '%grp/unsubscribe' => $this->make_hook('unsubscribe', AUTH_PASSWD
, 'groupmember'),
47 '%grp/change_rights' => $this->make_hook('change_rights', AUTH_PASSWD
, 'groups'),
48 '%grp/admin/annuaire' => $this->make_hook('admin_annuaire', AUTH_PASSWD
, 'groupadmin'),
49 '%grp/member' => $this->make_hook('admin_member', AUTH_PASSWD
, 'groupadmin'),
50 '%grp/member/new' => $this->make_hook('admin_member_new', AUTH_PASSWD
, 'groupadmin'),
51 '%grp/member/new/ajax' => $this->make_hook('admin_member_new_ajax', AUTH_PASSWD
, 'groups', NO_AUTH
),
52 '%grp/member/del' => $this->make_hook('admin_member_del', AUTH_PASSWD
, 'groupadmin'),
53 '%grp/member/suggest' => $this->make_hook('admin_member_suggest', AUTH_PASSWD
, 'groupadmin'),
55 '%grp/rss' => $this->make_token_hook('rss', AUTH_PUBLIC
),
56 '%grp/announce/new' => $this->make_hook('edit_announce', AUTH_PASSWD
, 'groupadmin'),
57 '%grp/announce/edit' => $this->make_hook('edit_announce', AUTH_PASSWD
, 'groupadmin'),
58 '%grp/announce/photo' => $this->make_hook('photo_announce', AUTH_PUBLIC
),
59 '%grp/admin/announces' => $this->make_hook('admin_announce', AUTH_PASSWD
, 'groupadmin'),
63 function handler_index($page, $arg = null
)
65 global $globals, $platal;
69 $page->changeTpl('xnetgrp/asso.tpl');
72 if (Env
::has('read')) {
73 XDB
::query('DELETE r.*
74 FROM group_announces_read AS r
75 INNER JOIN group_announces AS a ON (a.id = r.announce_id)
76 WHERE expiration < CURRENT_DATE()');
77 XDB
::query('INSERT INTO group_announces_read
79 Env
::i('read'), S
::i('uid'));
82 if (Env
::has('unread')) {
83 XDB
::query('DELETE FROM group_announces_read
84 WHERE announce_id = {?} AND uid = {?}',
85 Env
::i('unread'), S
::i('uid'));
86 pl_redirect("#art" . Env
::i('unread'));
89 /* TODO: refines this filter on promotions by using userfilter. */
91 if ($user->hasProfile()) {
92 $promo = XDB
::format('{?}', $user->profile()->entry_year
);
93 $minCondition = ' OR promo_min <= ' . $promo;
94 $maxCondition = ' OR promo_max >= ' . $promo;
99 $arts = XDB
::iterator('SELECT a.*, FIND_IN_SET(\'photo\', a.flags) AS photo
100 FROM group_announces AS a
101 LEFT JOIN group_announces_read AS r ON (r.uid = {?} AND r.announce_id = a.id)
102 WHERE asso_id = {?} AND expiration >= CURRENT_DATE()
103 AND (promo_min = 0' . $minCondition . ')
104 AND (promo_max = 0' . $maxCondition . ')
105 AND r.announce_id IS NULL
106 ORDER BY a.expiration',
107 S
::i('uid'), $globals->asso('id'));
108 $index = XDB
::iterator('SELECT a.id, a.titre, r.uid IS NULL AS nonlu
109 FROM group_announces AS a
110 LEFT JOIN group_announces_read AS r ON (a.id = r.announce_id AND r.uid = {?})
111 WHERE asso_id = {?} AND expiration >= CURRENT_DATE()
112 AND (promo_min = 0' . $minCondition . ')
113 AND (promo_max = 0' . $maxCondition . ')
114 ORDER BY a.expiration',
115 S
::i('uid'), $globals->asso('id'));
116 $page->assign('article_index', $index);
118 $arts = XDB
::iterator("SELECT *, FIND_IN_SET('photo', flags) AS photo
120 WHERE asso_id = {?} AND expiration >= CURRENT_DATE()
121 AND FIND_IN_SET('public', flags)",
122 $globals->asso('id'));
123 $payments = XDB
::fetchAllAssoc("SELECT id, text
125 WHERE asso_id = {?} AND NOT FIND_IN_SET('old', flags) AND FIND_IN_SET('public', flags)
127 $globals->asso('id'));
128 $page->assign('payments', $payments);
131 $subs_valid = XDB
::query("SELECT uid
132 FROM group_member_sub_requests
133 WHERE asso_id = {?}",
134 $globals->asso('id'));
135 $page->assign('requests', $subs_valid->numRows());
138 if (!S
::hasAuthToken()) {
139 $page->setRssLink("Polytechnique.net :: {$globals->asso("nom
")} :: News publiques",
140 $platal->ns
. "rss/rss.xml");
142 $page->setRssLink("Polytechnique.net :: {$globals->asso("nom
")} :: News",
143 $platal->ns
. 'rss/' . S
::v('hruid') . '/' . S
::user()->token
. '/rss.xml');
146 $page->assign('articles', $arts);
149 function handler_logo($page)
152 $globals->asso()->getLogo()->send();
155 function handler_site($page)
158 $site = $globals->asso('site');
160 $page->trigError('Le groupe n\'a pas de site web.');
161 return $this->handler_index($page);
163 http_redirect($site);
167 function handler_edit($page)
170 $page->changeTpl('xnetgrp/edit.tpl');
174 $domains = XDB
::iterator('SELECT *
177 $page->assign('domains', $domains);
178 $page->assign('super', true
);
181 if (Post
::has('submit')) {
182 S
::assert_xsrf_token();
184 $flags = new PlFlagSet('wiki_desc');
185 $flags->addFlag('notif_unsub', Post
::i('notif_unsub') == 1);
186 $site = Post
::t('site');
187 if ($site && ($site != "http://")) {
188 $scheme = parse_url($site, PHP_URL_SCHEME
);
190 $site = "http://" . $site;
196 $notify_all = (Post
::v('notify_all') ? true
: false
);
198 $to_notify = array();
199 $uf = New UserFilter(New UFC_Group($globals->asso('id'), true
));
200 $uids = $uf->getIds();
201 foreach ($uids as $uid) {
202 if (Post
::b('to_notify_' . $uid)) {
206 if (count($to_notify) == 0) {
208 $page->trigWarning("Aucun animateur n'ayant été selectionné pour recevoir les demandes d'inscriptions, tous le seront.");
211 $flags->addFlag('notify_all', $notify_all);
214 $page->assign('super', true
);
216 if (Post
::v('mail_domain') && (strstr(Post
::v('mail_domain'), '.') === false
)) {
217 $page->trigError('Le domaine doit être un FQDN (aucune modification effectuée) !!!');
220 if (Post
::t('nom') == '' || Post
::t('diminutif') == '') {
221 $page->trigError('Ni le nom ni le diminutif du groupe ne peuvent être vide.');
225 $page->assign('nom', Post
::t('nom'));
226 $page->assign('diminutif', Post
::t('diminutif'));
227 $page->assign('mail_domain', Post
::t('mail_domain'));
228 $page->assign('cat', Post
::v('cat'));
229 $page->assign('dom', Post
::v('dom'));
230 $page->assign('ax', Post
::v('ax'));
231 $page->assign('axDate', Post
::t('axDate'));
232 $page->assign('site', $site);
233 $page->assign('resp', Post
::t('resp'));
234 $page->assign('mail', Post
::t('mail'));
235 $page->assign('phone', Post
::t('phone'));
236 $page->assign('fax', Post
::t('fax'));
237 $page->assign('address', Post
::t('address'));
238 $page->assign('forum', Post
::t('forum'));
239 $page->assign('inscriptible', Post
::v('inscriptible'));
240 $page->assign('sub_url', Post
::t('sub_url'));
241 $page->assign('unsub_url', Post
::t('unsub_url'));
242 $page->assign('welcome_msg', Post
::t('welcome_msg'));
243 $page->assign('pub', Post
::v('pub'));
244 $page->assign('notif_unsub', Post
::i('notif_unsub'));
245 $page->assign('descr', Post
::t('descr'));
246 $page->assign('error', $error);
250 $axDate = make_datetime(Post
::v('axDate'));
251 if (Post
::t('axDate') != '') {
252 $axDate = make_datetime(Post
::v('axDate'))->format('Y-m-d');
258 SET nom={?}, diminutif={?}, cat={?}, dom={?},
259 descr={?}, site={?}, mail={?}, resp={?},
260 forum={?}, mail_domain={?}, ax={?}, axDate = {?}, pub={?},
261 sub_url={?}, inscriptible={?}, unsub_url={?},
262 flags = {?}, welcome_msg = {?}
264 Post
::v('nom'), Post
::v('diminutif'),
265 Post
::v('cat'), (Post
::i('dom') == 0) ? null
: Post
::i('dom'),
266 Post
::v('descr'), $site,
267 Post
::v('mail'), Post
::v('resp'),
268 Post
::v('forum'), Post
::v('mail_domain'),
269 Post
::has('ax'), $axDate, Post
::v('pub'),
270 Post
::v('sub_url'), Post
::v('inscriptible'),
271 Post
::v('unsub_url'), $flags, Post
::t('welcome_msg'),
272 $globals->asso('id'));
273 if (Post
::v('mail_domain')) {
274 XDB
::execute('INSERT IGNORE INTO email_virtual_domains (name)
276 Post
::t('mail_domain'));
277 XDB
::execute('UPDATE email_virtual_domains
280 Post
::t('mail_domain'));
285 SET descr={?}, site={?}, mail={?}, resp={?},
286 forum={?}, pub= {?}, sub_url={?},
287 unsub_url = {?}, flags = {?}, welcome_msg = {?}
289 Post
::v('descr'), $site,
290 Post
::v('mail'), Post
::v('resp'),
291 Post
::v('forum'), Post
::v('pub'),
292 Post
::v('sub_url'), Post
::v('unsub_url'),
293 $flags, Post
::t('welcome_msg'),
294 $globals->asso('id'));
297 Phone
::deletePhones(0, Phone
::LINK_GROUP
, $globals->asso('id'));
298 $phone = new Phone(array('link_type' => 'group', 'link_id' => $globals->asso('id'), 'id' => 0,
299 'type' => 'fixed', 'display' => Post
::v('phone'), 'pub' => 'public'));
300 $fax = new Phone(array('link_type' => 'group', 'link_id' => $globals->asso('id'), 'id' => 1,
301 'type' => 'fax', 'display' => Post
::v('fax'), 'pub' => 'public'));
304 Address
::deleteAddresses(null
, Address
::LINK_GROUP
, null
, $globals->asso('id'));
305 $address = new Address(array('groupid' => $globals->asso('id'), 'type' => Address
::LINK_GROUP
, 'text' => Post
::v('address')));
308 if ($_FILES['logo']['name']) {
309 $upload = PlUpload
::get($_FILES['logo'], $globals->asso('id'), 'asso.logo', true
);
311 $page->trigError("Impossible de télécharger le logo.");
313 XDB
::execute('UPDATE groups
314 SET logo = {?}, logo_mime = {?}
315 WHERE id = {?}', $upload->getContents(), $upload->contentType(),
316 $globals->asso('id'));
321 XDB
::execute("UPDATE group_members
323 WHERE asso_id = {?}",
324 $globals->asso('id'));
326 XDB
::execute("UPDATE group_members
328 WHERE asso_id = {?} AND uid IN {?}",
329 $globals->asso('id'), $to_notify);
332 pl_redirect('../' . Post
::v('diminutif', $globals->asso('diminutif')) . '/edit');
335 $uf = New UserFilter(New UFC_Group($globals->asso('id'), true
, UFC_Group
::NOTIFIED
));
336 $page->assign('notified', $uf->getUsers());
337 $uf = New UserFilter(New UFC_Group($globals->asso('id'), true
, UFC_Group
::UNNOTIFIED
));
338 $page->assign('unnotified', $uf->getUsers());
340 $page->assign('error', $error);
341 $page->assign('cat', $globals->asso('cat'));
342 $page->assign('dom', $globals->asso('dom'));
343 $page->assign('ax', $globals->asso('ax'));
344 $page->assign('inscriptible', $globals->asso('inscriptible'));
345 $page->assign('pub', $globals->asso('pub'));
346 $page->assign('notif_unsub', $globals->asso('notif_unsub'));
347 $page->assign('notify_all', $globals->asso('notify_all'));
350 function handler_mail($page)
354 $page->changeTpl('xnetgrp/mail.tpl');
355 $mmlist = new MMList(S
::user(), $globals->asso('mail_domain'));
356 $page->assign('listes', $mmlist->get_lists());
357 $page->assign('user', S
::user());
359 if (Post
::has('send')) {
360 S
::assert_xsrf_token();
361 $from = Post
::v('from');
362 $sujet = Post
::v('sujet');
363 $body = Post
::v('body');
365 $mls = array_keys(Env
::v('ml', array()));
366 $mbr = array_keys(Env
::v('membres', array()));
368 $this->load('mail.inc.php');
370 $tos = get_all_redirects($mbr, $mls, $mmlist);
372 $upload = PlUpload
::get($_FILES['uploaded'], S
::user()->login(), 'xnet.emails', true
);
373 if (!$upload && @$_FILES['uploaded']['name'] && PlUpload
::$lastError != null
) {
374 $page->trigError(PlUpload
::$lastError);
378 send_xnet_mails($from, $sujet, $body, Env
::v('wiki'), $tos, Post
::v('replyto'), $upload, @$_FILES['uploaded']['name']);
382 $page->killSuccess("Email envoyé !");
383 $page->assign('sent', true
);
387 function handler_forum($page, $group = null
, $artid = null
)
390 $page->changeTpl('xnetgrp/forum.tpl');
391 if (!$globals->asso('forum')) {
394 require_once 'banana/forum.inc.php';
396 get_banana_params($get, $globals->asso('forum'), $group, $artid);
397 run_banana($page, 'ForumsBanana', $get);
400 function handler_annuaire($page, $action = null
, $subaction = null
)
404 __autoload('userset');
406 if ($action == 'admins') {
408 $action = $subaction;
410 $view = new UserSet(new UFC_Group($globals->asso('id'), $admins));
411 $view->addMod('groupmember', 'Annuaire');
412 $view->addMod('trombi', 'Trombinoscope');
413 $view->addMod('map', 'Planisphère');
414 $view->apply('annuaire', $page, $action);
415 $page->assign('only_admin', $admins);
416 $page->changeTpl('xnetgrp/annuaire.tpl');
419 function handler_former_users($page)
422 require_once 'userset.inc.php';
424 $view = new UserSet(new UFC_GroupFormerMember($globals->asso('id')));
425 $view->addMod('groupmember', 'Anciens membres', true
, array('noadmin' => true
));
426 $view->apply('former_users', $page);
427 $page->changeTpl('xnetgrp/former_users.tpl');
430 function handler_trombi($page)
432 pl_redirect('annuaire/trombi');
435 function handler_geoloc($page)
437 pl_redirect('annuaire/geoloc');
440 function handler_vcard($page, $photos = null
)
443 $vcard = new VCard($photos == 'photos', 'Membre du groupe ' . $globals->asso('nom'));
444 $vcard->addProfiles($globals->asso()->getMembersFilter()->getProfiles(null
, Profile
::FETCH_ALL
));
448 function handler_csv($page, $filename = null
)
451 if (is_null($filename)) {
452 $filename = $globals->asso('diminutif') . '.csv';
454 $users = $globals->asso()->getMembersFilter(null
, new UFO_Name())->getUsers();
455 pl_cached_content_headers('text/x-csv', 'iso-8859-1', 1);
457 echo utf8_decode("Nom;Prénom;Sexe;Promotion;Commentaire\n");
458 foreach ($users as $user) {
459 $line = $user->lastName() . ';' . $user->firstName() . ';' . ($user->isFemale() ?
'F' : 'M')
460 . ';' . $user->promo() . ';' . strtr($user->group_comm
, ';', ',');
461 echo utf8_decode($line) . "\n";
466 function handler_directory_sync($page)
469 require_once 'emails.inc.php';
471 $page->changeTpl('xnetgrp/sync.tpl');
472 Platal
::load('lists', 'lists.inc.php');
474 if (Env
::has('add_users')) {
475 S
::assert_xsrf_token();
477 $users = array_keys(Env
::v('add_users'));
478 $former_users = XDB
::fetchColumn('SELECT uid
479 FROM group_former_members
480 WHERE remember = TRUE AND uid IN {?}',
482 $new_users = array_diff($users, $former_users);
484 foreach ($former_users as $uid) {
485 $user = User
::getSilentWithUID($uid);
486 $page->trigWarning($user->fullName() . ' est un ancien membre du groupe qui ne souhaite pas y revenir.');
488 if (count($former_users) > 1) {
489 $page->trigWarning('S\'ils souhaitent revenir dans le groupe, il faut qu\'ils en fassent la demande sur la page d\'accueil du groupe.');
490 } elseif (count($former_users)) {
491 $page->trigWarning('S\'il souhaite revenir dans le groupe, il faut qu\'il en fasse la demande sur la page d\'accueil du groupe.');
495 foreach ($new_users as $uid) {
496 $data[] = XDB
::format('({?}, {?})', $globals->asso('id'), $uid);
498 XDB
::rawExecute('INSERT INTO group_members (asso_id, uid)
499 VALUES ' . implode(',', $data));
502 if (Env
::has('add_nonusers')) {
503 S
::assert_xsrf_token();
505 $nonusers = array_keys(Env
::v('add_nonusers'));
506 foreach ($nonusers as $email) {
507 if ($user = User
::getSilent($email) ||
!isvalid_email($email)) {
511 list($local_part, $domain) = explode('@', strtolower($email));
512 $hruid = User
::makeHrid($local_part, $domain, 'ext');
513 if ($user = User
::getSilent($hruid)) {
517 require_once 'name.func.inc.php';
518 $parts = explode('.', $local_part);
519 if (count($parts) == 1) {
520 $lastname = $display_name = capitalize_name($mbox);
523 $display_name = $firstname = capitalize_name($parts[0]);
524 $lastname = capitalize_name(implode(' ', array_slice($parts, 1)));
526 $full_name = build_full_name($firstname, $lastname);
527 $directory_name = build_directory_name($firstname, $lastname);
528 $sort_name = build_sort_name($firstname, $lastname);
529 XDB
::execute('INSERT INTO accounts (hruid, display_name, full_name, directory_name, sort_name,
530 firstname, lastname, email, type, state)
531 VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, \'xnet\', \'disabled\')',
532 $hruid, $display_name, $full_name, $directory_name, $sort_name, $firstname, $lastname, $email);
533 $uid = XDB
::insertId();
534 XDB
::execute('INSERT INTO group_members (asso_id, uid)
536 $globals->asso('id'), $uid);
540 if (Env
::has('add_users') || Env
::has('add_nonusers')) {
541 $page->trigSuccess('Ajouts réalisés avec succès.');
545 $client = new MMList($user, $globals->asso('mail_domain'));
546 $lists = $client->get_lists();
548 foreach ($lists as $list) {
549 $details = $client->get_members($list['list']);
550 $members = array_merge($members, list_extract_members($details[1]));
552 $members = array_unique($members);
556 foreach ($members as $email) {
557 if ($user = User
::getSilent($email)) {
558 $uids[] = $user->id();
560 $nonusers[] = $email;
564 $aliases = iterate_list_alias($globals->asso('mail_domain'));
565 foreach ($aliases as $alias) {
566 list($local_part, $domain) = explode('@', $alias);
567 $aliases_members = list_alias_members($local_part, $domain);
568 $users = array_merge($users, $aliases_members['users']);
569 $nonusers = array_merge($nonusers, $aliases_members['nonusers']);
571 foreach ($users as $user) {
572 $uids[] = $user->id();
574 $nonusers = array_unique($nonusers);
575 $uids = array_unique($uids);
577 $uids = XDB
::fetchColumn('SELECT a.uid
579 WHERE a.uid IN {?} AND NOT EXISTS (SELECT *
580 FROM group_members AS g
581 WHERE a.uid = g.uid AND g.asso_id = {?})',
582 $uids, $globals->asso('id'));
584 $users = User
::getBulkUsersWithUIDs($uids);
585 usort($users, 'User::compareDirectoryName');
591 $page->assign('users', $users);
592 $page->assign('nonusers', $nonusers);
595 function handler_non_active($page)
598 $page->changeTpl('xnetgrp/non_active.tpl');
600 $uids = XDB
::fetchColumn('SELECT g.uid
601 FROM group_members AS g
602 INNER JOIN accounts AS a ON (a.uid = g.uid)
603 LEFT JOIN register_pending_xnet AS p ON (p.uid = g.uid)
604 WHERE a.uid = g.uid AND g.asso_id = {?} AND a.type = \'xnet\' AND a.state = \'disabled\' AND p.uid IS NULL',
605 $globals->asso('id'));
606 foreach ($uids as $key => $uid) {
607 if (AccountReq
::isPending($uid) || BulkAccountsReq
::isPending($uid)) {
612 if (Post
::has('enable_accounts')) {
613 S
::assert_xsrf_token();
615 $uids_to_enable = array_intersect(array_keys(Post
::v('enable_accounts')), $uids);
618 $group = Platal
::globals()->asso('nom');
619 $request = new BulkAccountsReq($user, $uids_to_enable, $group);
621 $page->trigSuccess('Un email va bientôt être envoyé aux personnes sélectionnées pour l\'activation de leur compte.');
623 foreach ($uids as $key => $uid) {
624 if (in_array($uid, $uids_to_enable)) {
630 $users = User
::getBulkUsersWithUIDs($uids);
631 $page->assign('users', $users);
634 private function removeSubscriptionRequest($uid)
637 XDB
::execute("DELETE FROM group_member_sub_requests
638 WHERE asso_id = {?} AND uid = {?}",
639 $globals->asso('id'), $uid);
642 private function validSubscription(User
$user)
645 $this->removeSubscriptionRequest($user->id());
646 Group
::subscribe($globals->asso('id'), $user->id());
648 if (XDB
::affectedRows() == 1) {
649 $mailer = new PlMailer();
650 $mailer->addTo($user->forlifeEmail());
651 $mailer->setFrom('"' . S
::user()->fullName() . '" <' . S
::user()->forlifeEmail() . '>');
652 $mailer->setSubject('[' . $globals->asso('nom') . '] Demande d\'inscription');
653 $message = ($user->isFemale() ?
'Chère' : 'Cher') . " Camarade,\n"
655 . " Suite à ta demande d'adhésion à " . $globals->asso('nom')
656 . ", j'ai le plaisir de t'annoncer que ton inscription a été validée !\n"
657 . (is_null($globals->asso('welcome_msg')) ?
'' : "\n" . $globals->asso('welcome_msg') . "\n")
659 . "Bien cordialement,\n"
661 . S
::user()->fullName() . '.';
662 $mailer->setTxtBody(wordwrap($message, 72));
667 function handler_subscribe($page, $u = null
)
670 $page->changeTpl('xnetgrp/inscrire.tpl');
672 if (!$globals->asso('inscriptible'))
673 $page->kill("Il n'est pas possible de s'inscire en ligne à ce "
674 ."groupe. Essaie de joindre le contact indiqué "
675 ."sur la page de présentation.");
677 if (!is_null($u) && may_update()) {
678 $user = User
::get($u);
682 $page->assign('user', $user);
685 // Retrieves the subscription status, and the reason.
686 $res = XDB
::query("SELECT reason
687 FROM group_member_sub_requests
688 WHERE asso_id = {?} AND uid = {?}",
689 $globals->asso('id'), $user->id());
690 $reason = ($res->numRows() ?
$res->fetchOneCell() : null
);
692 $res = XDB
::query("SELECT COUNT(*)
694 WHERE asso_id = {?} AND uid = {?}",
695 $globals->asso('id'), $user->id());
696 $already_member = ($res->fetchOneCell() > 0);
698 // Handles the membership request.
699 if ($already_member) {
700 $this->removeSubscriptionRequest($user->id());
701 $page->kill($user->fullName() . ' est déjà membre du groupe !');
702 } elseif (Env
::has('accept')) {
703 S
::assert_xsrf_token();
705 $this->validSubscription($user);
706 pl_redirect("member/" . $user->login());
707 } elseif (Env
::has('refuse')) {
708 S
::assert_xsrf_token();
710 $this->removeSubscriptionRequest($user->id());
711 $mailer = new PlMailer();
712 $mailer->addTo($user->forlifeEmail());
713 $mailer->setFrom('"' . S
::user()->fullName() . '" <' . S
::user()->forlifeEmail() . '>');
714 $mailer->setSubject('['.$globals->asso('nom').'] Demande d\'inscription annulée');
715 $mailer->setTxtBody(Env
::v('motif'));
717 $page->killSuccess("La demande de {$user->fullName()} a bien été refusée.");
719 $page->assign('show_form', true
);
720 $page->assign('reason', $reason);
726 $page->kill("Tu es déjà membre !");
730 $res = XDB
::query("SELECT uid
731 FROM group_member_sub_requests
732 WHERE uid = {?} AND asso_id = {?}",
733 S
::i('uid'), $globals->asso('id'));
734 if ($res->numRows() != 0) {
735 $page->kill("Tu as déjà demandé ton inscription à ce groupe. Cette demande est actuellement en attente de validation.");
739 if (Post
::has('inscrire')) {
740 S
::assert_xsrf_token();
742 XDB
::execute("INSERT INTO group_member_sub_requests (asso_id, uid, ts, reason)
743 VALUES ({?}, {?}, NOW(), {?})",
744 $globals->asso('id'), S
::i('uid'), Post
::v('message'));
745 XDB
::execute('DELETE FROM group_former_members
746 WHERE uid = {?} AND asso_id = {?}',
747 S
::i('uid'), $globals->asso('id'));
748 $admins = $globals->asso()->iterToNotify();
749 $admin = $admins->next();
750 $to = $admin->bestEmail();
751 while ($admin = $admins->next()) {
752 $to .= ', ' . $admin->bestEmail();
757 . "Ce message a été envoyé suite à la demande d'inscription de\n"
758 . S
::user()->fullName(true
) . "\n"
759 . "Via le site www.polytechnique.net. Tu peux choisir de valider ou\n"
760 . "de refuser sa demande d'inscription depuis la page :\n"
761 . "http://www.polytechnique.net/" . $globals->asso("diminutif") . "/subscribe/" . S
::user()->login() . "\n"
763 . "En cas de problème, contacter l'équipe de Polytechnique.org\n"
764 . "à l'adresse : support@polytechnique.org\n";
767 $to = ($globals->asso('mail') != '') ?
$globals->asso('mail') . ', ' : '';
768 $to .= 'support@polytechnique.org';
769 $append = "\n-- \nLe groupe ".$globals->asso("nom")
770 ." n'a pas d'administrateur, l'équipe de"
771 ." Polytechnique.org a été prévenue et va rapidement"
772 ." résoudre ce problème.\n";
775 $mailer = new PlMailer();
777 $mailer->setFrom('"' . S
::user()->fullName() . '" <' . S
::user()->forlifeEmail() . '>');
778 $mailer->setSubject('['.$globals->asso('nom').'] Demande d\'inscription');
779 $mailer->setTxtBody(Post
::v('message').$append);
784 function handler_subscribe_valid($page)
788 if (Post
::has('valid')) {
789 S
::assert_xsrf_token();
790 $subs = Post
::v('subs');
791 if (is_array($subs)) {
793 foreach ($subs as $hruid => $val) {
795 $user = User
::get($hruid);
797 $this->validSubscription($user);
804 $it = XDB
::iterator('SELECT s.uid, a.hruid, s.ts AS date
805 FROM group_member_sub_requests AS s
806 INNER JOIN accounts AS a ON(s.uid = a.uid)
807 WHERE s.asso_id = {?}
808 ORDER BY s.ts', $globals->asso('id'));
809 $page->changeTpl('xnetgrp/subscribe-valid.tpl');
810 $page->assign('valid', $it);
813 function handler_change_rights($page)
815 if (Env
::has('right') && (may_update() || S
::suid())) {
816 switch (Env
::v('right')) {
818 Platal
::session()->stopSUID();
821 Platal
::session()->doSelfSuid();
826 Platal
::session()->doSelfSuid();
827 may_update(false
, true
);
831 Platal
::session()->doSelfSuid();
832 may_update(false
, true
);
833 is_member(false
, true
);
837 http_redirect($_SERVER['HTTP_REFERER']);
840 function handler_admin_annuaire($page)
844 $this->load('mail.inc.php');
845 $page->changeTpl('xnetgrp/annuaire-admin.tpl');
847 $mmlist = new MMList($user, $globals->asso('mail_domain'));
848 $lists = $mmlist->get_lists();
849 if (!$lists) $lists = array();
850 $listes = array_map(create_function('$arr', 'return $arr["list"];'), $lists);
852 $subscribers = array();
854 foreach ($listes as $list) {
855 list(,$members) = $mmlist->get_members($list);
856 $mails = array_map(create_function('$arr', 'return $arr[1];'), $members);
857 $subscribers = array_unique(array_merge($subscribers, $mails));
860 $not_in_group_x = array();
861 $not_in_group_ext = array();
863 foreach ($subscribers as $mail) {
864 $uf = new UserFilter(new PFC_And(new UFC_Group($globals->asso('id')),
865 new UFC_Email($mail)));
866 if ($uf->getTotalCount() == 0) {
867 if (User
::isForeignEmailAddress($mail)) {
868 $not_in_group_ext[] = $mail;
870 $not_in_group_x[] = $mail;
875 $page->assign('not_in_group_ext', $not_in_group_ext);
876 $page->assign('not_in_group_x', $not_in_group_x);
877 $page->assign('lists', $lists);
880 function handler_admin_member_new($page, $email = null
)
884 $page->changeTpl('xnetgrp/membres-add.tpl');
886 if (is_null($email)) {
890 S
::assert_xsrf_token();
891 $suggest_account_activation = false
;
893 // FS#703 : $_GET is urldecoded twice, hence
894 // + (the data) => %2B (in the url) => + (first decoding) => ' ' (second decoding)
895 // Since there can be no spaces in emails, we can fix this with :
896 $email = str_replace(' ', '+', $email);
897 $is_valid_email = isvalid_email($email);
899 // X not registered to main site.
900 if (Env
::v('x') && Env
::i('userid') && $is_valid_email) {
901 $user = User
::getSilentWithUID(Env
::i('userid'));
903 $page->trigError('Utilisateur invalide.');
907 // User has an account but is not yet registered.
908 if ($user->state
== 'pending') {
909 // Add email in account table.
910 XDB
::query('UPDATE accounts
912 WHERE uid = {?} AND email IS NULL',
913 Post
::t('email'), $user->id());
914 // Add email for marketing if required.
915 if (Env
::v('market')) {
916 $market = Marketing
::get($user->uid
, $email);
918 $market = new Marketing($user->uid
, $email, 'group', $globals->asso('nom'),
919 Env
::v('market_from'), S
::v('uid'));
925 $user = User
::getSilent($email);
927 // Wrong email and no user: failure.
928 if (is_null($user) && (!$is_valid_email ||
!User
::isForeignEmailAddress($email))) {
929 $page->trigError('« <strong>' . $email . '</strong> » n\'est pas une adresse email valide.');
933 // Deals with xnet accounts.
934 if (is_null($user) ||
$user->type
== 'xnet') {
935 // User is of type xnet. There are 3 possible cases:
936 // * the email is not known yet: we create a new account and
937 // propose to send an email to the user so he can activate
939 // * the email is known but the user was not contacted in order to
940 // activate yet: we propose to send an email to the user so he
941 // can activate his account,
942 // * the email is known and the user was already contacted or has
943 // an active account: nothing to be done.
944 list($mbox, $domain) = explode('@', strtolower($email));
945 $hruid = User
::makeHrid($mbox, $domain, 'ext');
946 // User might already have an account (in another group for example).
947 $user = User
::getSilent($hruid);
949 // If the user has no account yet, creates new account: build names from email address.
951 require_once 'name.func.inc.php';
952 $parts = explode('.', $mbox);
953 if (count($parts) == 1) {
954 $lastname = $display_name = capitalize_name($mbox);
957 $display_name = $firstname = capitalize_name($parts[0]);
958 $lastname = capitalize_name(implode(' ', array_slice($parts, 1)));
960 $full_name = build_full_name($firstname, $lastname);
961 $directory_name = build_directory_name($firstname, $lastname);
962 $sort_name = build_sort_name($firstname, $lastname);
963 XDB
::execute('INSERT INTO accounts (hruid, display_name, full_name, directory_name, sort_name,
964 firstname, lastname, email, type, state)
965 VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, \'xnet\', \'disabled\')',
966 $hruid, $display_name, $full_name, $directory_name, $sort_name, $firstname, $lastname, $email);
967 $user = User
::getSilent($hruid);
970 $suggest_account_activation = $this->suggest($user);
975 // First check if the user used to be in this group.
976 XDB
::rawExecute('DELETE FROM group_former_members
977 WHERE remember AND DATE_SUB(NOW(), INTERVAL 1 YEAR) > unsubsciption_date');
978 $former_member = XDB
::fetchOneCell('SELECT remember
979 FROM group_former_members
980 WHERE uid = {?} AND asso_id = {?}',
981 $user->id(), $globals->asso('id'));
982 if ($former_member === 1) {
983 $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.');
985 } elseif (!is_null($former_member) && Post
::i('force_continue') == 0) {
986 $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.');
987 $page->assign('force_continue', 1);
991 Group
::subscribe($globals->asso('id'), $user->id());
992 $this->removeSubscriptionRequest($user->id());
993 if ($suggest_account_activation) {
994 pl_redirect('member/suggest/' . $user->login() . '/' . $email . '/' . $globals->asso('nom'));
996 pl_redirect('member/' . $user->login());
1001 // Check if the user has a pending or active account, and thus if we should her account's activation.
1002 private function suggest(PlUser
$user)
1004 $active = XDB
::fetchOneCell('SELECT state = \'active\'
1008 $pending = XDB
::fetchOneCell('SELECT uid
1009 FROM register_pending_xnet
1012 $requested = AccountReq
::isPending($user->id()) || BulkAccountsReq
::isPending($user->id());
1014 if ($active ||
$pending ||
$requested) {
1020 function handler_admin_member_suggest($page, $hruid, $email)
1022 $page->changeTpl('xnetgrp/membres-suggest.tpl');
1024 // FS#703 : $_GET is urldecoded twice, hence
1025 // + (the data) => %2B (in the url) => + (first decoding) => ' ' (second decoding)
1026 // Since there can be no spaces in emails, we can fix this with :
1027 $email = str_replace(' ', '+', $email);
1029 if (Post
::has('suggest')) {
1030 if (Post
::t('suggest') == 'yes') {
1032 $request = new AccountReq($user, $hruid, $email, Platal
::globals()->asso('nom'));
1034 $page->trigSuccessRedirect('Un email va bien être envoyé à ' . $email . ' pour l\'activation de son compte.',
1035 Platal
::globals()->asso('diminutif') . '/member/' . $hruid);
1037 pl_redirect('member/' . $hruid);
1040 $page->assign('email', $email);
1041 $page->assign('hruid', $hruid);
1044 function handler_admin_member_new_ajax($page)
1046 pl_content_headers("text/html");
1047 $page->changeTpl('xnetgrp/membres-new-search.tpl', NO_SKIN
);
1049 if (Env
::has('login')) {
1050 $user = User
::getSilent(Env
::t('login'));
1051 if ($user && $user->state
!= 'pending') {
1052 $users = array($user);
1055 if (empty($users)) {
1056 list($lastname, $firstname) = str_replace(array('-', ' ', "'"), '%', array(Env
::t('nom'), Env
::t('prenom')));
1057 $cond = new PFC_And(new PFC_Not(new UFC_Registered()));
1058 if (!empty($lastname)) {
1059 $cond->addChild(new UFC_NameTokens($lastname, array(), false
, false
, Profile
::LASTNAME
));
1061 if (!empty($firstname)) {
1062 $cond->addChild(new UFC_NameTokens($firstname, array(), false
, false
, Profile
::FIRSTNAME
));
1064 if (Env
::t('promo')) {
1065 $cond->addChild(new UFC_Promo('=', UserFilter
::DISPLAY
, Env
::t('promo')));
1067 $uf = new UserFilter($cond);
1068 $users = $uf->getUsers(new PlLimit(30));
1069 if ($uf->getTotalCount() > 30) {
1070 $page->assign('too_many', true
);
1074 $page->assign('users', $users);
1077 function unsubscribe(PlUser
$user, $remember = false
)
1080 Group
::unsubscribe($globals->asso('id'), $user->id(), $remember);
1082 if ($globals->asso('notif_unsub')) {
1083 $mailer = new PlMailer('xnetgrp/unsubscription-notif.mail.tpl');
1084 $admins = $globals->asso()->iterToNotify();
1085 while ($admin = $admins->next()) {
1086 $mailer->addTo($admin);
1088 $mailer->assign('group', $globals->asso('nom'));
1089 $mailer->assign('user', $user);
1090 $mailer->assign('selfdone', $user->id() == S
::i('uid'));
1094 $domain = $globals->asso('mail_domain');
1099 $mmlist = new MMList(S
::user(), $domain);
1100 $listes = $mmlist->get_lists($user->forlifeEmail());
1102 $may_update = may_update();
1104 if (is_array($listes)) {
1105 foreach ($listes as $liste) {
1106 if ($liste['sub'] == 2) {
1108 $mmlist->mass_unsubscribe($liste['list'], Array($user->forlifeEmail()));
1110 $mmlist->unsubscribe($liste['list']);
1112 } elseif ($liste['sub']) {
1113 Platal
::page()->trigWarning($user->fullName() . " a une"
1114 ." demande d'inscription en cours sur la"
1115 ." liste {$liste['list']}@ !");
1121 XDB
::execute('DELETE v
1122 FROM email_virtual AS v
1123 INNER JOIN email_virtual_domains AS d ON (v.domain = d.id)
1124 WHERE v.redirect = {?} AND d.name = {?}',
1125 $user->forlifeEmail(), $domain);
1129 function handler_unsubscribe($page)
1131 $page->changeTpl('xnetgrp/membres-del.tpl');
1134 return PL_NOT_FOUND
;
1136 $page->assign('self', true
);
1137 $page->assign('user', $user);
1139 if (!Post
::has('confirm')) {
1142 S
::assert_xsrf_token();
1145 $hasSingleGroup = ($user->groupCount() == 1);
1147 if ($this->unsubscribe($user, Post
::b('remember'))) {
1148 $page->trigSuccess('Tu as été désinscrit du groupe avec succès.');
1150 $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.');
1153 // If user is of type xnet account and this was her last group, disable the account.
1154 if ($user->type
== 'xnet' && $hasSingleGroup) {
1157 $page->assign('is_member', is_member(true
));
1160 function handler_admin_member_del($page, $user = null
)
1162 $page->changeTpl('xnetgrp/membres-del.tpl');
1163 $user = User
::getSilent($user);
1165 return PL_NOT_FOUND
;
1170 if (!$user->inGroup($globals->asso('id'))) {
1171 pl_redirect('annuaire');
1174 $page->assign('self', false
);
1175 $page->assign('user', $user);
1177 if (!Post
::has('confirm')) {
1180 S
::assert_xsrf_token();
1183 $hasSingleGroup = ($user->groupCount() == 1);
1185 if ($this->unsubscribe($user)) {
1186 $page->trigSuccess("{$user->fullName()} a été désinscrit du groupe !");
1188 $page->trigWarning("{$user->fullName()} a été désinscrit du groupe, mais des erreurs subsistent !");
1191 // If user is of type xnet account and this was her last group, disable the account.
1192 if ($user->type
== 'xnet' && $hasSingleGroup) {
1197 private function changeLogin(PlPage
$page, PlUser
$user, $login)
1199 // Search the user's uid.
1200 $xuser = User
::getSilent($login);
1202 $accounts = User
::getPendingAccounts($login);
1204 $page->trigError("L'identifiant $login ne correspond à aucun X.");
1206 } else if (count($accounts) > 1) {
1207 $page->trigError("L'identifiant $login correspond à plusieurs camarades.");
1210 $xuser = User
::getSilent($accounts[0]['uid']);
1217 if ($user->mergeIn($xuser)) {
1218 return $xuser->login();
1220 return $user->login();
1223 function handler_admin_member($page, $user)
1227 $user = User
::getSilent($user);
1229 return PL_NOT_FOUND
;
1232 if (!$user->inGroup($globals->asso('id'))) {
1233 pl_redirect('annuaire');
1236 $page->changeTpl('xnetgrp/membres-edit.tpl');
1238 $mmlist = new MMList(S
::user(), $globals->asso('mail_domain'));
1240 if (Post
::has('change')) {
1241 S
::assert_xsrf_token();
1242 require_once 'emails.inc.php';
1243 require_once 'name.func.inc.php';
1245 // Convert user status to X
1246 if (!Post
::blank('login_X')) {
1247 $forlife = $this->changeLogin($page, $user, Post
::t('login_X'));
1249 pl_redirect('member/' . $forlife);
1254 if ($user->type
== 'virtual' ||
($user->type
== 'xnet' && !$user->perms
)) {
1255 $lastname = capitalize_name(Post
::t('lastname'));
1256 if (Post
::s('type') != 'virtual') {
1257 $firstname = capitalize_name(Post
::t('firstname'));
1261 $full_name = build_full_name($firstname, $lastname);
1262 $directory_name = build_directory_name($firstname, $lastname);
1263 $sort_name = build_sort_name($firstname, $lastname);
1264 XDB
::query('UPDATE accounts
1265 SET full_name = {?}, directory_name = {?}, sort_name = {?}, display_name = {?},
1266 firstname = {?}, lastname = {?}, sex = {?}, type = {?}
1268 $full_name, $directory_name, $sort_name, Post
::t('display_name'), $firstname, $lastname,
1269 (Post
::t('sex') == 'male') ?
'male' : 'female',
1270 (Post
::t('type') == 'xnet') ?
'xnet' : 'virtual', $user->id());
1274 $new_email = strtolower(Post
::t('email'));
1275 if (!$user->perms
&& require_email_update($user, $new_email)) {
1276 XDB
::query('UPDATE accounts
1279 $new_email, $user->id());
1280 $listClient = new MMList(S
::user());
1281 $listClient->change_user_email($user->forlifeEmail(), $new_email);
1282 update_alias_user($user->forlifeEmail(), $new_email);
1284 if (XDB
::affectedRows()) {
1285 $page->trigSuccess('Données de l\'utilisateur mises à jour.');
1288 if (($user->type
== 'xnet' && !$user->perms
)) {
1289 if (Post
::b('suggest')) {
1290 $request = new AccountReq(S
::user(), $user->hruid
, Post
::t('email'), $globals->asso('nom'));
1292 $page->trigSuccess('Le compte va bientôt être activé.');
1294 if (Post
::b('again')) {
1295 $data = XDB
::fetchOneAssoc('SELECT hash, group_name, sender_name, email
1296 FROM register_pending_xnet
1300 $mailer = new PlMailer('xnet/account.mail.tpl');
1301 $mailer->addCc('validation+xnet_account@polytechnique.org');
1302 $mailer->setTo($data['email']);
1303 $mailer->assign('hash', $data['hash']);
1304 $mailer->assign('email', $data['email']);
1305 $mailer->assign('group', $data['group_name']);
1306 $mailer->assign('sender_name', $data['sender_name']);
1307 $mailer->assign('again', true
);
1309 $page->trigSuccess('Relance effectuée avec succès.');
1313 // Update group params for user
1314 $perms = Post
::v('group_perms');
1315 $comm = Post
::t('comm');
1316 $position = (Post
::t('group_position') == '') ? null
: Post
::v('group_position');
1317 if ($user->group_perms
!= $perms ||
$user->group_comm
!= $comm ||
$user->group_position
!= $position) {
1318 XDB
::query('UPDATE group_members
1319 SET perms = {?}, comm = {?}, position = {?}
1320 WHERE uid = {?} AND asso_id = {?}',
1321 ($perms == 'admin') ?
'admin' : 'membre', $comm, $position,
1322 $user->id(), $globals->asso('id'));
1323 if (XDB
::affectedRows()) {
1324 if ($perms != $user->group_perms
) {
1325 $page->trigSuccess('Permissions modifiées !');
1327 if ($comm != $user->group_comm
) {
1328 $page->trigSuccess('Commentaire mis à jour.');
1330 if ($position != $user->group_position
) {
1331 $page->trigSuccess('Poste mis à jour.');
1336 // Gets user info again as they might have change
1337 $user = User
::getSilent($user->id());
1339 // Update ML subscriptions
1340 foreach (Env
::v('ml1', array()) as $ml => $state) {
1341 $ask = empty($_REQUEST['ml2'][$ml]) ?
0 : 2;
1342 if ($ask == $state) {
1345 if ($state == '1') {
1346 $page->trigWarning("{$user->fullName()} a "
1347 ."actuellement une demande d'inscription en "
1348 ."cours sur <strong>$ml@</strong> !!!");
1350 $mmlist->mass_subscribe($ml, Array($user->forlifeEmail()));
1351 $page->trigSuccess("{$user->fullName()} a été abonné à $ml@.");
1353 $mmlist->mass_unsubscribe($ml, Array($user->forlifeEmail()));
1354 $page->trigSuccess("{$user->fullName()} a été désabonné de $ml@.");
1358 // Change subscriptioin to aliases
1359 foreach (Env
::v('ml3', array()) as $ml => $state) {
1360 require_once 'emails.inc.php';
1361 $ask = !empty($_REQUEST['ml4'][$ml]);
1362 list($local_part, ) = explode('@', $ml);
1363 if ($ask == $state) {
1367 add_to_list_alias($user->id(), $local_part, $globals->asso('mail_domain'));
1368 $page->trigSuccess("{$user->fullName()} a été abonné à $ml.");
1370 delete_from_list_alias($user->id(), $local_part, $globals->asso('mail_domain'));
1371 $page->trigSuccess("{$user->fullName()} a été désabonné de $ml.");
1375 if ($globals->asso('has_nl')) {
1376 $nl = NewsLetter
::forGroup($globals->asso('shortname'));
1377 // Updates group's newsletter subscription.
1378 if (Post
::i('newsletter') == 1) {
1379 $nl->subscribe($user);
1381 $nl->unsubscribe(null
, $user->id());
1386 $res = XDB
::rawFetchAllAssoc('SHOW COLUMNS FROM group_members LIKE \'position\'');
1387 $positions = str_replace(array('enum(', ')', '\''), '', $res[0]['Type']);
1388 if ($globals->asso('has_nl')) {
1389 $nl = NewsLetter
::forGroup($globals->asso('shortname'));
1390 $nl_registered = $nl->subscriptionState($user);
1392 $nl_registered = false
;
1395 $page->assign('user', $user);
1396 $page->assign('suggest', $this->suggest($user));
1397 $page->assign('listes', $mmlist->get_lists($user->forlifeEmail()));
1398 $page->assign('alias', $user->emailGroupAliases($globals->asso('mail_domain')));
1399 $page->assign('positions', explode(',', $positions));
1400 $page->assign('nl_registered', $nl_registered);
1401 $page->assign('pending_xnet_account', XDB
::fetchOneCell('SELECT 1
1402 FROM register_pending_xnet
1407 function handler_rss(PlPage
$page, PlUser
$user)
1410 $page->assign('asso', $globals->asso());
1412 $this->load('feed.inc.php');
1413 $feed = new XnetGrpEventFeed();
1414 return $feed->run($page, $user, false
);
1417 private function upload_image(PlPage
$page, PlUpload
$upload)
1419 if (@!$_FILES['image']['tmp_name'] && !Env
::v('image_url')) {
1422 if (!$upload->upload($_FILES['image']) && !$upload->download(Env
::v('image_url'))) {
1423 $page->trigError('Impossible de télécharger l\'image');
1425 } elseif (!$upload->isType('image')) {
1426 $page->trigError('Le fichier n\'est pas une image valide au format JPEG, GIF ou PNG.');
1429 } elseif (!$upload->resizeImage(80, 100, 100, 100, 32284)) {
1430 $page->trigError('Impossible de retraiter l\'image');
1436 function handler_photo_announce($page, $eid = null
) {
1438 $res = XDB
::query('SELECT *
1439 FROM group_announces_photo
1440 WHERE eid = {?}', $eid);
1441 if ($res->numRows()) {
1442 $photo = $res->fetchOneAssoc();
1443 pl_cached_dynamic_content_headers("image/" . $photo['attachmime']);
1444 echo $photo['attach'];
1448 $upload = new PlUpload(S
::user()->login(), 'xnetannounce');
1449 if ($upload->exists() && $upload->isType('image')) {
1450 pl_cached_dynamic_content_headers($upload->contentType());
1451 echo $upload->getContents();
1456 pl_cached_dynamic_content_headers("image/png");
1457 echo file_get_contents($globals->spoolroot
. '/htdocs/images/logo.png');
1461 function handler_edit_announce($page, $aid = null
)
1463 global $globals, $platal;
1464 $page->changeTpl('xnetgrp/announce-edit.tpl');
1465 $page->assign('new', is_null($aid));
1468 if (Post
::v('valid') == 'Visualiser' || Post
::v('valid') == 'Enregistrer'
1469 || Post
::v('valid') == 'Supprimer l\'image' || Post
::v('valid') == 'Pas d\'image') {
1470 S
::assert_xsrf_token();
1472 if (!is_null($aid)) {
1475 $art['titre'] = Post
::v('titre');
1476 $art['texte'] = Post
::v('texte');
1477 $art['contacts'] = Post
::v('contacts');
1478 $art['promo_min'] = Post
::i('promo_min');
1479 $art['promo_max'] = Post
::i('promo_max');
1480 $art['nom'] = S
::v('nom');
1481 $art['prenom'] = S
::v('prenom');
1482 $art['promo'] = S
::v('promo');
1483 $art['hruid'] = S
::user()->login();
1484 $art['uid'] = S
::user()->id();
1485 $art['expiration'] = Post
::v('expiration');
1486 $art['public'] = Post
::has('public');
1487 $art['xorg'] = Post
::has('xorg');
1488 $art['nl'] = Post
::has('nl');
1489 $art['event'] = Post
::v('event');
1490 $upload = new PlUpload(S
::user()->login(), 'xnetannounce');
1491 $this->upload_image($page, $upload);
1493 $art['contact_html'] = $art['contacts'];
1494 if ($art['event']) {
1495 $art['contact_html'] .= "\n{$globals->baseurl}/{$platal->ns}events/sub/{$art['event']}";
1498 if (!$art['public'] &&
1499 (($art['promo_min'] > $art['promo_max'] && $art['promo_max'] != 0) ||
1500 ($art['promo_min'] != 0 && ($art['promo_min'] <= 1900 ||
$art['promo_min'] >= 2020)) ||
1501 ($art['promo_max'] != 0 && ($art['promo_max'] <= 1900 ||
$art['promo_max'] >= 2020))))
1503 $page->trigError("L'intervalle de promotions est invalide.");
1504 Post
::kill('valid');
1507 if (!trim($art['titre']) ||
!trim($art['texte'])) {
1508 $page->trigError("L'article doit avoir un titre et un contenu.");
1509 Post
::kill('valid');
1512 if (Post
::v('valid') == 'Supprimer l\'image') {
1514 Post
::kill('valid');
1516 $art['photo'] = $upload->exists() || Post
::i('photo');
1517 if (Post
::v('valid') == 'Pas d\'image' && !is_null($aid)) {
1518 XDB
::query('DELETE FROM group_announces_photo
1519 WHERE eid = {?}', $aid);
1521 Post
::kill('valid');
1522 $art['photo'] = false
;
1526 if (Post
::v('valid') == 'Enregistrer') {
1527 $promo_min = ($art['public'] ?
0 : $art['promo_min']);
1528 $promo_max = ($art['public'] ?
0 : $art['promo_max']);
1529 $flags = new PlFlagSet();
1530 if ($art['public']) {
1531 $flags->addFlag('public');
1533 if ($art['photo']) {
1534 $flags->addFlag('photo');
1536 if (is_null($aid)) {
1537 $fulltext = $art['texte'];
1538 if (!empty($art['contact_html'])) {
1539 $fulltext .= "\n\n'''Contacts :'''\\\\\n" . $art['contact_html'];
1542 if ($globals->asso('forum')) {
1543 require_once 'banana/forum.inc.php';
1544 $banana = new ForumsBanana(S
::user());
1545 $post = $banana->post($globals->asso('forum'), null
,
1546 $art['titre'], MiniWiki
::wikiToText($fulltext, false
, 0, 80));
1548 XDB
::query('INSERT INTO group_announces (uid, asso_id, create_date, titre, texte, contacts,
1549 expiration, promo_min, promo_max, flags, post_id)
1550 VALUES ({?}, {?}, NOW(), {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})',
1551 S
::i('uid'), $globals->asso('id'), $art['titre'], $art['texte'], $art['contact_html'],
1552 $art['expiration'], $promo_min, $promo_max, $flags, $post);
1553 $aid = XDB
::insertId();
1554 if ($art['photo']) {
1555 list($imgx, $imgy, $imgtype) = $upload->imageInfo();
1556 XDB
::execute('INSERT INTO group_announces_photo
1557 SET eid = {?}, attachmime = {?}, x = {?}, y = {?}, attach = {?}',
1558 $aid, $imgtype, $imgx, $imgy, $upload->getContents());
1561 $article = new EvtReq("[{$globals->asso('nom')}] " . $art['titre'], $fulltext,
1562 $art['promo_min'], $art['promo_max'], $art['expiration'], "", S
::user(),
1565 $page->trigWarning("L'affichage sur la page d'accueil de Polytechnique.org est en attente de validation.");
1566 } else if ($upload && $upload->exists()) {
1570 $article = new NLReq(S
::user(), $globals->asso('nom') . " : " .$art['titre'],
1571 $art['texte'], $art['contact_html']);
1573 $page->trigWarning("La parution dans la Lettre Mensuelle est en attente de validation.");
1576 XDB
::query('UPDATE group_announces
1577 SET titre = {?}, texte = {?}, contacts = {?}, expiration = {?},
1578 promo_min = {?}, promo_max = {?}, flags = {?}
1579 WHERE id = {?} AND asso_id = {?}',
1580 $art['titre'], $art['texte'], $art['contacts'], $art['expiration'],
1581 $promo_min, $promo_max, $flags,
1582 $art['id'], $globals->asso('id'));
1583 if ($art['photo'] && $upload->exists()) {
1584 list($imgx, $imgy, $imgtype) = $upload->imageInfo();
1585 XDB
::execute('INSERT INTO group_announces_photo (eid, attachmime, attach, x, y)
1586 VALUES ({?}, {?}, {?}, {?}, {?})
1587 ON DUPLICATE KEY UPDATE attachmime = VALUES(attachmime), attach = VALUES(attach), x = VALUES(x), y = VALUES(y)',
1588 $aid, $imgtype, $upload->getContents(), $imgx, $imgy);
1593 if (Post
::v('valid') == 'Enregistrer' || Post
::v('valid') == 'Annuler') {
1597 if (empty($art) && !is_null($aid)) {
1598 $res = XDB
::query("SELECT *, FIND_IN_SET('public', flags) AS public,
1599 FIND_IN_SET('photo', flags) AS photo
1600 FROM group_announces
1601 WHERE asso_id = {?} AND id = {?}",
1602 $globals->asso('id'), $aid);
1603 if ($res->numRows()) {
1604 $art = $res->fetchOneAssoc();
1605 $art['contact_html'] = $art['contacts'];
1607 $page->kill("Aucun article correspond à l'identifiant indiqué.");
1611 if (is_null($aid)) {
1612 $events = XDB
::iterator("SELECT *
1614 WHERE asso_id = {?} AND archive = 0",
1615 $globals->asso('id'));
1616 if ($events->total()) {
1617 $page->assign('events', $events);
1621 $art['contact_html'] = @MiniWiki
::WikiToHTML($art['contact_html']);
1622 $page->assign('art', $art);
1623 $page->assign_by_ref('upload', $upload);
1626 function handler_admin_announce($page)
1629 $page->changeTpl('xnetgrp/announce-admin.tpl');
1631 if (Env
::has('del')) {
1632 S
::assert_xsrf_token();
1633 XDB
::execute('DELETE FROM group_announces
1634 WHERE id = {?} AND asso_id = {?}',
1635 Env
::i('del'), $globals->asso('id'));
1637 $res = XDB
::iterator('SELECT id, titre, expiration, expiration < CURRENT_DATE() AS perime
1638 FROM group_announces
1640 ORDER BY expiration DESC',
1641 $globals->asso('id'));
1642 $page->assign('articles', $res);
1646 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: