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 $page->assign('super', true
);
198 if (Post
::v('mail_domain') && (strstr(Post
::v('mail_domain'), '.') === false
)) {
199 $page->trigError('Le domaine doit être un FQDN (aucune modification effectuée) !!!');
202 if (Post
::t('nom') == '' || Post
::t('diminutif') == '') {
203 $page->trigError('Ni le nom ni le diminutif du groupe ne peuvent être vide.');
207 $page->assign('nom', Post
::t('nom'));
208 $page->assign('diminutif', Post
::t('diminutif'));
209 $page->assign('mail_domain', Post
::t('mail_domain'));
210 $page->assign('cat', Post
::v('cat'));
211 $page->assign('dom', Post
::v('dom'));
212 $page->assign('ax', Post
::v('ax'));
213 $page->assign('axDate', Post
::t('axDate'));
214 $page->assign('site', $site);
215 $page->assign('resp', Post
::t('resp'));
216 $page->assign('mail', Post
::t('mail'));
217 $page->assign('phone', Post
::t('phone'));
218 $page->assign('fax', Post
::t('fax'));
219 $page->assign('address', Post
::t('address'));
220 $page->assign('forum', Post
::t('forum'));
221 $page->assign('inscriptible', Post
::v('inscriptible'));
222 $page->assign('sub_url', Post
::t('sub_url'));
223 $page->assign('unsub_url', Post
::t('unsub_url'));
224 $page->assign('welcome_msg', Post
::t('welcome_msg'));
225 $page->assign('pub', Post
::v('pub'));
226 $page->assign('notif_unsub', Post
::i('notif_unsub'));
227 $page->assign('descr', Post
::t('descr'));
228 $page->assign('error', $error);
232 $axDate = make_datetime(Post
::v('axDate'));
233 if (Post
::t('axDate') != '') {
234 $axDate = make_datetime(Post
::v('axDate'))->format('Y-m-d');
240 SET nom={?}, diminutif={?}, cat={?}, dom={?},
241 descr={?}, site={?}, mail={?}, resp={?},
242 forum={?}, mail_domain={?}, ax={?}, axDate = {?}, pub={?},
243 sub_url={?}, inscriptible={?}, unsub_url={?},
244 flags = {?}, welcome_msg = {?}
246 Post
::v('nom'), Post
::v('diminutif'),
247 Post
::v('cat'), (Post
::i('dom') == 0) ? null
: Post
::i('dom'),
248 Post
::v('descr'), $site,
249 Post
::v('mail'), Post
::v('resp'),
250 Post
::v('forum'), Post
::v('mail_domain'),
251 Post
::has('ax'), $axDate, Post
::v('pub'),
252 Post
::v('sub_url'), Post
::v('inscriptible'),
253 Post
::v('unsub_url'), $flags, Post
::t('welcome_msg'),
254 $globals->asso('id'));
255 if (Post
::v('mail_domain')) {
256 XDB
::execute('INSERT IGNORE INTO email_virtual_domains (name)
258 Post
::t('mail_domain'));
259 XDB
::execute('UPDATE email_virtual_domains
262 Post
::t('mail_domain'));
267 SET descr={?}, site={?}, mail={?}, resp={?},
268 forum={?}, pub= {?}, sub_url={?},
269 unsub_url = {?}, flags = {?}, welcome_msg = {?}
271 Post
::v('descr'), $site,
272 Post
::v('mail'), Post
::v('resp'),
273 Post
::v('forum'), Post
::v('pub'),
274 Post
::v('sub_url'), Post
::v('unsub_url'),
275 $flags, Post
::t('welcome_msg'),
276 $globals->asso('id'));
279 Phone
::deletePhones(0, Phone
::LINK_GROUP
, $globals->asso('id'));
280 $phone = new Phone(array('link_type' => 'group', 'link_id' => $globals->asso('id'), 'id' => 0,
281 'type' => 'fixed', 'display' => Post
::v('phone'), 'pub' => 'public'));
282 $fax = new Phone(array('link_type' => 'group', 'link_id' => $globals->asso('id'), 'id' => 1,
283 'type' => 'fax', 'display' => Post
::v('fax'), 'pub' => 'public'));
286 Address
::deleteAddresses(null
, Address
::LINK_GROUP
, null
, $globals->asso('id'));
287 $address = new Address(array('groupid' => $globals->asso('id'), 'type' => Address
::LINK_GROUP
, 'text' => Post
::v('address')));
290 if ($_FILES['logo']['name']) {
291 $upload = PlUpload
::get($_FILES['logo'], $globals->asso('id'), 'asso.logo', true
);
293 $page->trigError("Impossible de télécharger le logo.");
295 XDB
::execute('UPDATE groups
296 SET logo = {?}, logo_mime = {?}
297 WHERE id = {?}', $upload->getContents(), $upload->contentType(),
298 $globals->asso('id'));
303 pl_redirect('../' . Post
::v('diminutif', $globals->asso('diminutif')) . '/edit');
305 $page->assign('error', $error);
306 $page->assign('cat', $globals->asso('cat'));
307 $page->assign('dom', $globals->asso('dom'));
308 $page->assign('ax', $globals->asso('ax'));
309 $page->assign('inscriptible', $globals->asso('inscriptible'));
310 $page->assign('pub', $globals->asso('pub'));
311 $page->assign('notif_unsub', $globals->asso('notif_unsub'));
314 function handler_mail($page)
318 $page->changeTpl('xnetgrp/mail.tpl');
319 $mmlist = new MMList(S
::user(), $globals->asso('mail_domain'));
320 $page->assign('listes', $mmlist->get_lists());
321 $page->assign('user', S
::user());
323 if (Post
::has('send')) {
324 S
::assert_xsrf_token();
325 $from = Post
::v('from');
326 $sujet = Post
::v('sujet');
327 $body = Post
::v('body');
329 $mls = array_keys(Env
::v('ml', array()));
330 $mbr = array_keys(Env
::v('membres', array()));
332 $this->load('mail.inc.php');
334 $tos = get_all_redirects($mbr, $mls, $mmlist);
336 $upload = PlUpload
::get($_FILES['uploaded'], S
::user()->login(), 'xnet.emails', true
);
337 if (!$upload && @$_FILES['uploaded']['name'] && PlUpload
::$lastError != null
) {
338 $page->trigError(PlUpload
::$lastError);
342 send_xnet_mails($from, $sujet, $body, Env
::v('wiki'), $tos, Post
::v('replyto'), $upload, @$_FILES['uploaded']['name']);
346 $page->killSuccess("Email envoyé !");
347 $page->assign('sent', true
);
351 function handler_forum($page, $group = null
, $artid = null
)
354 $page->changeTpl('xnetgrp/forum.tpl');
355 if (!$globals->asso('forum')) {
358 require_once 'banana/forum.inc.php';
360 get_banana_params($get, $globals->asso('forum'), $group, $artid);
361 run_banana($page, 'ForumsBanana', $get);
364 function handler_annuaire($page, $action = null
, $subaction = null
)
368 __autoload('userset');
370 if ($action == 'admins') {
372 $action = $subaction;
374 $view = new UserSet(new UFC_Group($globals->asso('id'), $admins));
375 $view->addMod('groupmember', 'Annuaire');
376 $view->addMod('trombi', 'Trombinoscope');
377 $view->apply('annuaire', $page, $action);
378 $page->assign('only_admin', $admins);
379 $page->changeTpl('xnetgrp/annuaire.tpl');
382 function handler_former_users($page)
385 require_once 'userset.inc.php';
387 $view = new UserSet(new UFC_GroupFormerMember($globals->asso('id')));
388 $view->addMod('groupmember', 'Anciens membres', true
, array('noadmin' => true
));
389 $view->apply('former_users', $page);
390 $page->changeTpl('xnetgrp/former_users.tpl');
393 function handler_trombi($page)
395 pl_redirect('annuaire/trombi');
398 function handler_geoloc($page)
400 pl_redirect('annuaire/geoloc');
403 function handler_vcard($page, $photos = null
)
406 $vcard = new VCard($photos == 'photos', 'Membre du groupe ' . $globals->asso('nom'));
407 $vcard->addProfiles($globals->asso()->getMembersFilter()->getProfiles(null
, Profile
::FETCH_ALL
));
411 function handler_csv($page, $filename = null
)
414 if (is_null($filename)) {
415 $filename = $globals->asso('diminutif') . '.csv';
417 $users = $globals->asso()->getMembersFilter(null
, new UFO_Name())->getUsers();
418 pl_cached_content_headers('text/x-csv', 1);
419 $page->changeTpl('xnetgrp/annuaire-csv.tpl', NO_SKIN
);
420 $page->assign('users', $users);
423 function handler_directory_sync($page)
426 require_once 'emails.inc.php';
428 $page->changeTpl('xnetgrp/sync.tpl');
429 Platal
::load('lists', 'lists.inc.php');
431 if (Env
::has('add_users')) {
432 S
::assert_xsrf_token();
434 $users = array_keys(Env
::v('add_users'));
435 $former_users = XDB
::fetchColumn('SELECT uid
436 FROM group_former_members
437 WHERE remember = TRUE AND uid IN {?}',
439 $new_users = array_diff($users, $former_users);
441 foreach ($former_users as $uid) {
442 $user = User
::getSilentWithUID($uid);
443 $page->trigWarning($user->fullName() . ' est un ancien membre du groupe qui ne souhaite pas y revenir.');
445 if (count($former_users) > 1) {
446 $page->trigWarning('S\'ils souhaitent revenir dans le groupe, il faut qu\'ils en fassent la demande sur la page d\'accueil du groupe.');
447 } elseif (count($former_users)) {
448 $page->trigWarning('S\'il souhaite revenir dans le groupe, il faut qu\'il en fasse la demande sur la page d\'accueil du groupe.');
452 foreach ($new_users as $uid) {
453 $data[] = XDB
::format('({?}, {?})', $globals->asso('id'), $uid);
455 XDB
::rawExecute('INSERT INTO group_members (asso_id, uid)
456 VALUES ' . implode(',', $data));
459 if (Env
::has('add_nonusers')) {
460 S
::assert_xsrf_token();
462 $nonusers = array_keys(Env
::v('add_nonusers'));
463 foreach ($nonusers as $email) {
464 if ($user = User
::getSilent($email) ||
!isvalid_email($email)) {
468 list($local_part, $domain) = explode('@', strtolower($email));
469 $hruid = User
::makeHrid($local_part, $domain, 'ext');
470 if ($user = User
::getSilent($hruid)) {
474 $parts = explode('.', $local_part);
475 if (count($parts) == 1) {
476 $lastname = $display_name = $full_name = $directory_name = ucfirst($local_part);
479 $firstname = ucfirst($parts[0]);
480 $lastname = ucwords(implode(' ', array_slice($parts, 1)));
481 $display_name = $firstname;
482 $full_name = $firstname . ' ' . $lastname;
483 $directory_name = strtoupper($lastname) . ' ' . $firstname;
485 XDB
::execute('INSERT INTO accounts (hruid, display_name, full_name, directory_name, firstname, lastname, email, type, state)
486 VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, \'xnet\', \'disabled\')',
487 $hruid, $display_name, $full_name, $directory_name, $firstname, $lastname, $email);
488 $uid = XDB
::insertId();
489 XDB
::execute('INSERT INTO group_members (asso_id, uid)
491 $globals->asso('id'), $uid);
495 if (Env
::has('add_users') || Env
::has('add_nonusers')) {
496 $page->trigSuccess('Ajouts réalisés avec succès.');
500 $client = new MMList($user, $globals->asso('mail_domain'));
501 $lists = $client->get_lists();
503 foreach ($lists as $list) {
504 $details = $client->get_members($list['list']);
505 $members = array_merge($members, list_extract_members($details[1]));
507 $members = array_unique($members);
511 foreach ($members as $email) {
512 if ($user = User
::getSilent($email)) {
513 $uids[] = $user->id();
515 $nonusers[] = $email;
519 $aliases = iterate_list_alias($globals->asso('mail_domain'));
520 foreach ($aliases as $alias) {
521 list($local_part, $domain) = explode('@', $alias);
522 $aliases_members = list_alias_members($local_part, $domain);
523 $users = array_merge($users, $aliases_members['users']);
524 $nonusers = array_merge($nonusers, $aliases_members['nonusers']);
526 foreach ($users as $user) {
527 $uids[] = $user->id();
529 $nonusers = array_unique($nonusers);
530 $uids = array_unique($uids);
532 $uids = XDB
::fetchColumn('SELECT a.uid
534 WHERE a.uid IN {?} AND NOT EXISTS (SELECT *
535 FROM group_members AS g
536 WHERE a.uid = g.uid AND g.asso_id = {?})',
537 $uids, $globals->asso('id'));
539 $users = User
::getBulkUsersWithUIDs($uids);
540 usort($users, 'User::compareDirectoryName');
546 $page->assign('users', $users);
547 $page->assign('nonusers', $nonusers);
550 function handler_non_active($page)
553 $page->changeTpl('xnetgrp/non_active.tpl');
555 $uids = XDB
::fetchColumn('SELECT g.uid
556 FROM group_members AS g
557 INNER JOIN accounts AS a ON (a.uid = g.uid)
558 LEFT JOIN register_pending_xnet AS p ON (p.uid = g.uid)
559 WHERE a.uid = g.uid AND g.asso_id = {?} AND a.type = \'xnet\' AND a.state = \'disabled\' AND p.uid IS NULL',
560 $globals->asso('id'));
561 foreach ($uids as $key => $uid) {
562 if (AccountReq
::isPending($uid) || BulkAccountsReq
::isPending($uid)) {
567 if (Post
::has('enable_accounts')) {
568 S
::assert_xsrf_token();
570 $uids_to_enable = array_intersect(array_keys(Post
::v('enable_accounts')), $uids);
573 $group = Platal
::globals()->asso('nom');
574 $request = new BulkAccountsReq($user, $uids_to_enable, $group);
576 $page->trigSuccess('Un email va bientôt être envoyé aux personnes sélectionnées pour l\'activation de leur compte.');
578 foreach ($uids as $key => $uid) {
579 if (in_array($uid, $uids_to_enable)) {
585 $users = User
::getBulkUsersWithUIDs($uids);
586 $page->assign('users', $users);
589 private function removeSubscriptionRequest($uid)
592 XDB
::execute("DELETE FROM group_member_sub_requests
593 WHERE asso_id = {?} AND uid = {?}",
594 $globals->asso('id'), $uid);
597 private function validSubscription(User
$user)
600 $this->removeSubscriptionRequest($user->id());
601 Group
::subscribe($globals->asso('id'), $user->id());
603 if (XDB
::affectedRows() == 1) {
604 $mailer = new PlMailer();
605 $mailer->addTo($user->forlifeEmail());
606 $mailer->setFrom('"' . S
::user()->fullName() . '" <' . S
::user()->forlifeEmail() . '>');
607 $mailer->setSubject('[' . $globals->asso('nom') . '] Demande d\'inscription');
608 $message = ($user->isFemale() ?
'Chère' : 'Cher') . " Camarade,\n"
610 . " Suite à ta demande d'adhésion à " . $globals->asso('nom')
611 . ", j'ai le plaisir de t'annoncer que ton inscription a été validée !\n"
612 . (is_null($globals->asso('welcome_msg')) ?
'' : "\n" . $globals->asso('welcome_msg') . "\n")
614 . "Bien cordialement,\n"
616 . S
::user()->fullName() . '.';
617 $mailer->setTxtBody(wordwrap($message, 72));
622 function handler_subscribe($page, $u = null
)
625 $page->changeTpl('xnetgrp/inscrire.tpl');
627 if (!$globals->asso('inscriptible'))
628 $page->kill("Il n'est pas possible de s'inscire en ligne à ce "
629 ."groupe. Essaie de joindre le contact indiqué "
630 ."sur la page de présentation.");
632 if (!is_null($u) && may_update()) {
633 $user = User
::get($u);
637 $page->assign('user', $user);
640 // Retrieves the subscription status, and the reason.
641 $res = XDB
::query("SELECT reason
642 FROM group_member_sub_requests
643 WHERE asso_id = {?} AND uid = {?}",
644 $globals->asso('id'), $user->id());
645 $reason = ($res->numRows() ?
$res->fetchOneCell() : null
);
647 $res = XDB
::query("SELECT COUNT(*)
649 WHERE asso_id = {?} AND uid = {?}",
650 $globals->asso('id'), $user->id());
651 $already_member = ($res->fetchOneCell() > 0);
653 // Handles the membership request.
654 if ($already_member) {
655 $this->removeSubscriptionRequest($user->id());
656 $page->kill($user->fullName() . ' est déjà membre du groupe !');
657 } elseif (Env
::has('accept')) {
658 S
::assert_xsrf_token();
660 $this->validSubscription($user);
661 pl_redirect("member/" . $user->login());
662 } elseif (Env
::has('refuse')) {
663 S
::assert_xsrf_token();
665 $this->removeSubscriptionRequest($user->id());
666 $mailer = new PlMailer();
667 $mailer->addTo($user->forlifeEmail());
668 $mailer->setFrom('"' . S
::user()->fullName() . '" <' . S
::user()->forlifeEmail() . '>');
669 $mailer->setSubject('['.$globals->asso('nom').'] Demande d\'inscription annulée');
670 $mailer->setTxtBody(Env
::v('motif'));
672 $page->killSuccess("La demande de {$user->fullName()} a bien été refusée.");
674 $page->assign('show_form', true
);
675 $page->assign('reason', $reason);
681 $page->kill("Tu es déjà membre !");
685 $res = XDB
::query("SELECT uid
686 FROM group_member_sub_requests
687 WHERE uid = {?} AND asso_id = {?}",
688 S
::i('uid'), $globals->asso('id'));
689 if ($res->numRows() != 0) {
690 $page->kill("Tu as déjà demandé ton inscription à ce groupe. Cette demande est actuellement en attente de validation.");
694 if (Post
::has('inscrire')) {
695 S
::assert_xsrf_token();
697 XDB
::execute("INSERT INTO group_member_sub_requests (asso_id, uid, ts, reason)
698 VALUES ({?}, {?}, NOW(), {?})",
699 $globals->asso('id'), S
::i('uid'), Post
::v('message'));
700 XDB
::execute('DELETE FROM group_former_members
701 WHERE uid = {?} AND asso_id = {?}',
702 S
::i('uid'), $globals->asso('id'));
703 $uf = New UserFilter(New UFC_Group($globals->asso('id'), true
));
704 $admins = $uf->iterUsers();
705 $admin = $admins->next();
706 $to = $admin->bestEmail();
707 while ($admin = $admins->next()) {
708 $to .= ', ' . $admin->bestEmail();
713 . "Ce message a été envoyé suite à la demande d'inscription de\n"
714 . S
::user()->fullName(true
) . "\n"
715 . "Via le site www.polytechnique.net. Tu peux choisir de valider ou\n"
716 . "de refuser sa demande d'inscription depuis la page :\n"
717 . "http://www.polytechnique.net/" . $globals->asso("diminutif") . "/subscribe/" . S
::user()->login() . "\n"
719 . "En cas de problème, contacter l'équipe de Polytechnique.org\n"
720 . "à l'adresse : support@polytechnique.org\n";
723 $to = ($globals->asso('mail') != '') ?
$globals->asso('mail') . ', ' : '';
724 $to .= 'support@polytechnique.org';
725 $append = "\n-- \nLe groupe ".$globals->asso("nom")
726 ." n'a pas d'administrateur, l'équipe de"
727 ." Polytechnique.org a été prévenue et va rapidement"
728 ." résoudre ce problème.\n";
731 $mailer = new PlMailer();
733 $mailer->setFrom('"' . S
::user()->fullName() . '" <' . S
::user()->forlifeEmail() . '>');
734 $mailer->setSubject('['.$globals->asso('nom').'] Demande d\'inscription');
735 $mailer->setTxtBody(Post
::v('message').$append);
740 function handler_subscribe_valid($page)
744 if (Post
::has('valid')) {
745 S
::assert_xsrf_token();
746 $subs = Post
::v('subs');
747 if (is_array($subs)) {
749 foreach ($subs as $hruid => $val) {
751 $user = User
::get($hruid);
753 $this->validSubscription($user);
760 $it = XDB
::iterator('SELECT s.uid, a.hruid, s.ts AS date
761 FROM group_member_sub_requests AS s
762 INNER JOIN accounts AS a ON(s.uid = a.uid)
763 WHERE s.asso_id = {?}
764 ORDER BY s.ts', $globals->asso('id'));
765 $page->changeTpl('xnetgrp/subscribe-valid.tpl');
766 $page->assign('valid', $it);
769 function handler_change_rights($page)
771 if (Env
::has('right') && (may_update() || S
::suid())) {
772 switch (Env
::v('right')) {
774 Platal
::session()->stopSUID();
777 Platal
::session()->doSelfSuid();
782 Platal
::session()->doSelfSuid();
783 may_update(false
, true
);
787 Platal
::session()->doSelfSuid();
788 may_update(false
, true
);
789 is_member(false
, true
);
793 http_redirect($_SERVER['HTTP_REFERER']);
796 function handler_admin_annuaire($page)
800 $this->load('mail.inc.php');
801 $page->changeTpl('xnetgrp/annuaire-admin.tpl');
803 $mmlist = new MMList($user, $globals->asso('mail_domain'));
804 $lists = $mmlist->get_lists();
805 if (!$lists) $lists = array();
806 $listes = array_map(create_function('$arr', 'return $arr["list"];'), $lists);
808 $subscribers = array();
810 foreach ($listes as $list) {
811 list(,$members) = $mmlist->get_members($list);
812 $mails = array_map(create_function('$arr', 'return $arr[1];'), $members);
813 $subscribers = array_unique(array_merge($subscribers, $mails));
816 $not_in_group_x = array();
817 $not_in_group_ext = array();
819 foreach ($subscribers as $mail) {
820 $uf = new UserFilter(new PFC_And(new UFC_Group($globals->asso('id')),
821 new UFC_Email($mail)));
822 if ($uf->getTotalCount() == 0) {
823 if (User
::isForeignEmailAddress($mail)) {
824 $not_in_group_ext[] = $mail;
826 $not_in_group_x[] = $mail;
831 $page->assign('not_in_group_ext', $not_in_group_ext);
832 $page->assign('not_in_group_x', $not_in_group_x);
833 $page->assign('lists', $lists);
836 function handler_admin_member_new($page, $email = null
)
840 $page->changeTpl('xnetgrp/membres-add.tpl');
842 if (is_null($email)) {
846 S
::assert_xsrf_token();
847 $suggest_account_activation = false
;
849 // FS#703 : $_GET is urldecoded twice, hence
850 // + (the data) => %2B (in the url) => + (first decoding) => ' ' (second decoding)
851 // Since there can be no spaces in emails, we can fix this with :
852 $email = str_replace(' ', '+', $email);
853 $is_valid_email = isvalid_email($email);
855 // X not registered to main site.
856 if (Env
::v('x') && Env
::i('userid') && $is_valid_email) {
857 $user = User
::getSilentWithUID(Env
::i('userid'));
859 $page->trigError('Utilisateur invalide.');
863 // User has an account but is not yet registered.
864 if ($user->state
== 'pending') {
865 // Add email in account table.
866 XDB
::query('UPDATE accounts
868 WHERE uid = {?} AND email IS NULL',
869 Post
::t('email'), $user->id());
870 // Add email for marketing if required.
871 if (Env
::v('market')) {
872 $market = Marketing
::get($user->uid
, $email);
874 $market = new Marketing($user->uid
, $email, 'group', $globals->asso('nom'),
875 Env
::v('market_from'), S
::v('uid'));
881 $user = User
::getSilent($email);
883 // Wrong email and no user: failure.
884 if (is_null($user) && !$is_valid_email) {
885 $page->trigError('« <strong>' . $email . '</strong> » n\'est pas une adresse email valide.');
889 // Deals with xnet accounts.
890 if (is_null($user) ||
$user->type
== 'xnet') {
891 // User is of type xnet. There are 3 possible cases:
892 // * the email is not known yet: we create a new account and
893 // propose to send an email to the user so he can activate
895 // * the email is known but the user was not contacted in order to
896 // activate yet: we propose to send an email to the user so he
897 // can activate his account,
898 // * the email is known and the user was already contacted or has
899 // an active account: nothing to be done.
900 list($mbox, $domain) = explode('@', strtolower($email));
901 $hruid = User
::makeHrid($mbox, $domain, 'ext');
902 // User might already have an account (in another group for example).
903 $user = User
::getSilent($hruid);
905 // If the user has no account yet, creates new account: build names from email address.
907 $parts = explode('.', $mbox);
908 if (count($parts) == 1) {
909 $lastname = $display_name = $full_name = $directory_name = ucfirst($mbox);
912 $firstname = ucfirst($parts[0]);
913 $lastname = ucwords(implode(' ', array_slice($parts, 1)));
914 $display_name = $firstname;
915 $full_name = "$firstname $lastname";
916 $directory_name = strtoupper($lastname) . " " . $firstname;
918 XDB
::execute('INSERT INTO accounts (hruid, display_name, full_name, directory_name, firstname, lastname, email, type, state)
919 VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, \'xnet\', \'disabled\')',
920 $hruid, $display_name, $full_name, $directory_name, $firstname, $lastname, $email);
921 $user = User
::getSilent($hruid);
924 $suggest_account_activation = $this->suggest($user);
929 // First check if the user used to be in this group.
930 XDB
::rawExecute('DELETE FROM group_former_members
931 WHERE remember AND DATE_SUB(NOW(), INTERVAL 1 YEAR) > unsubsciption_date');
932 $former_member = XDB
::fetchOneCell('SELECT remember
933 FROM group_former_members
934 WHERE uid = {?} AND asso_id = {?}',
935 $user->id(), $globals->asso('id'));
936 if ($former_member === 1) {
937 $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.');
939 } elseif (!is_null($former_member) && Post
::i('force_continue') == 0) {
940 $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.');
941 $page->assign('force_continue', 1);
945 Group
::subscribe($globals->asso('id'), $user->id());
946 $this->removeSubscriptionRequest($user->id());
947 if ($suggest_account_activation) {
948 pl_redirect('member/suggest/' . $user->login() . '/' . $email . '/' . $globals->asso('nom'));
950 pl_redirect('member/' . $user->login());
955 // Check if the user has a pending or active account, and thus if we should her account's activation.
956 private function suggest(PlUser
$user)
958 $active = XDB
::fetchOneCell('SELECT state = \'active\'
962 $pending = XDB
::fetchOneCell('SELECT uid
963 FROM register_pending_xnet
966 $requested = AccountReq
::isPending($user->id()) || BulkAccountsReq
::isPending($user->id());
968 if ($active ||
$pending ||
$requested) {
974 function handler_admin_member_suggest($page, $hruid, $email)
976 $page->changeTpl('xnetgrp/membres-suggest.tpl');
978 // FS#703 : $_GET is urldecoded twice, hence
979 // + (the data) => %2B (in the url) => + (first decoding) => ' ' (second decoding)
980 // Since there can be no spaces in emails, we can fix this with :
981 $email = str_replace(' ', '+', $email);
983 if (Post
::has('suggest')) {
984 if (Post
::t('suggest') == 'yes') {
986 $request = new AccountReq($user, $hruid, $email, Platal
::globals()->asso('nom'));
988 $page->trigSuccessRedirect('Un email va bien être envoyé à ' . $email . ' pour l\'activation de son compte.',
989 Platal
::globals()->asso('diminutif') . '/member/' . $hruid);
991 pl_redirect('member/' . $hruid);
994 $page->assign('email', $email);
995 $page->assign('hruid', $hruid);
998 function handler_admin_member_new_ajax($page)
1000 pl_content_headers("text/html");
1001 $page->changeTpl('xnetgrp/membres-new-search.tpl', NO_SKIN
);
1003 if (Env
::has('login')) {
1004 $user = User
::getSilent(Env
::t('login'));
1005 if ($user && $user->state
!= 'pending') {
1006 $users = array($user);
1009 if (empty($users)) {
1010 list($lastname, $firstname) = str_replace(array('-', ' ', "'"), '%', array(Env
::t('nom'), Env
::t('prenom')));
1011 $cond = new PFC_And(new PFC_Not(new UFC_Registered()));
1012 if (!empty($lastname)) {
1013 $cond->addChild(new UFC_NameTokens($lastname, array(), false
, false
, Profile
::LASTNAME
));
1015 if (!empty($firstname)) {
1016 $cond->addChild(new UFC_NameTokens($firstname, array(), false
, false
, Profile
::FIRSTNAME
));
1018 if (Env
::t('promo')) {
1019 $cond->addChild(new UFC_Promo('=', UserFilter
::DISPLAY
, Env
::t('promo')));
1021 $uf = new UserFilter($cond);
1022 $users = $uf->getUsers(new PlLimit(30));
1023 if ($uf->getTotalCount() > 30) {
1024 $page->assign('too_many', true
);
1028 $page->assign('users', $users);
1031 function unsubscribe(PlUser
$user, $remember = false
)
1034 Group
::unsubscribe($globals->asso('id'), $user->id(), $remember);
1036 if ($globals->asso('notif_unsub')) {
1037 $mailer = new PlMailer('xnetgrp/unsubscription-notif.mail.tpl');
1038 $admins = $globals->asso()->iterAdmins();
1039 while ($admin = $admins->next()) {
1040 $mailer->addTo($admin);
1042 $mailer->assign('group', $globals->asso('nom'));
1043 $mailer->assign('user', $user);
1044 $mailer->assign('selfdone', $user->id() == S
::i('uid'));
1048 $domain = $globals->asso('mail_domain');
1053 $mmlist = new MMList(S
::user(), $domain);
1054 $listes = $mmlist->get_lists($user->forlifeEmail());
1056 $may_update = may_update();
1058 if (is_array($listes)) {
1059 foreach ($listes as $liste) {
1060 if ($liste['sub'] == 2) {
1062 $mmlist->mass_unsubscribe($liste['list'], Array($user->forlifeEmail()));
1064 $mmlist->unsubscribe($liste['list']);
1066 } elseif ($liste['sub']) {
1067 Platal
::page()->trigWarning($user->fullName() . " a une"
1068 ." demande d'inscription en cours sur la"
1069 ." liste {$liste['list']}@ !");
1075 XDB
::execute('DELETE v
1076 FROM email_virtual AS v
1077 INNER JOIN email_virtual_domains AS d ON (v.domain = d.id)
1078 WHERE v.redirect = {?} AND d.name = {?}',
1079 $user->forlifeEmail(), $domain);
1083 function handler_unsubscribe($page)
1085 $page->changeTpl('xnetgrp/membres-del.tpl');
1088 return PL_NOT_FOUND
;
1090 $page->assign('self', true
);
1091 $page->assign('user', $user);
1093 if (!Post
::has('confirm')) {
1096 S
::assert_xsrf_token();
1099 $hasSingleGroup = ($user->groupCount() == 1);
1101 if ($this->unsubscribe($user, Post
::b('remember'))) {
1102 $page->trigSuccess('Tu as été désinscrit du groupe avec succès.');
1104 $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.');
1107 // If user is of type xnet account and this was her last group, disable the account.
1108 if ($user->type
== 'xnet' && $hasSingleGroup) {
1111 $page->assign('is_member', is_member(true
));
1114 function handler_admin_member_del($page, $user = null
)
1116 $page->changeTpl('xnetgrp/membres-del.tpl');
1117 $user = User
::getSilent($user);
1119 return PL_NOT_FOUND
;
1124 if (!$user->inGroup($globals->asso('id'))) {
1125 pl_redirect('annuaire');
1128 $page->assign('self', false
);
1129 $page->assign('user', $user);
1131 if (!Post
::has('confirm')) {
1134 S
::assert_xsrf_token();
1137 $hasSingleGroup = ($user->groupCount() == 1);
1139 if ($this->unsubscribe($user)) {
1140 $page->trigSuccess("{$user->fullName()} a été désinscrit du groupe !");
1142 $page->trigWarning("{$user->fullName()} a été désinscrit du groupe, mais des erreurs subsistent !");
1145 // If user is of type xnet account and this was her last group, disable the account.
1146 if ($user->type
== 'xnet' && $hasSingleGroup) {
1151 private function changeLogin(PlPage
$page, PlUser
$user, $login)
1153 // Search the user's uid.
1154 $xuser = User
::getSilent($login);
1156 $accounts = User
::getPendingAccounts($login);
1158 $page->trigError("L'identifiant $login ne correspond à aucun X.");
1160 } else if (count($accounts) > 1) {
1161 $page->trigError("L'identifiant $login correspond à plusieurs camarades.");
1164 $xuser = User
::getSilent($accounts[0]['uid']);
1171 if ($user->mergeIn($xuser)) {
1172 return $xuser->login();
1174 return $user->login();
1177 function handler_admin_member($page, $user)
1181 $user = User
::getSilent($user);
1183 return PL_NOT_FOUND
;
1186 if (!$user->inGroup($globals->asso('id'))) {
1187 pl_redirect('annuaire');
1190 $page->changeTpl('xnetgrp/membres-edit.tpl');
1192 $mmlist = new MMList(S
::user(), $globals->asso('mail_domain'));
1194 if (Post
::has('change')) {
1195 require_once 'emails.inc.php';
1196 S
::assert_xsrf_token();
1198 // Convert user status to X
1199 if (!Post
::blank('login_X')) {
1200 $forlife = $this->changeLogin($page, $user, Post
::t('login_X'));
1202 pl_redirect('member/' . $forlife);
1207 if ($user->type
== 'virtual' ||
($user->type
== 'xnet' && !$user->perms
)) {
1208 $lastname = Post
::s('lastname');
1209 if (Post
::s('type') != 'virtual') {
1210 $firstname = Post
::s('firstname');
1211 $full_name = $firstname . ' ' . $lastname;
1212 $directory_name = mb_strtoupper($lastname) . ' ' . $firstname;
1215 $full_name = $lastname;
1216 $directory_name = mb_strtoupper($lastname);
1218 XDB
::query('UPDATE accounts
1219 SET full_name = {?}, directory_name = {?}, display_name = {?},
1220 firstname = {?}, lastname = {?}, sex = {?}, email = {?}, type = {?}
1222 $full_name, $directory_name, Post
::t('display_name'), $firstname, $lastname,
1223 (Post
::t('sex') == 'male') ?
'male' : 'female', Post
::t('email'),
1224 (Post
::t('type') == 'xnet') ?
'xnet' : 'virtual', $user->id());
1225 } else if (!$user->perms
&& Post
::has('email') && require_email_update($user, Post
::t('email'))) {
1226 XDB
::query('UPDATE accounts
1229 Post
::t('email'), $user->id());
1230 $listClient = new MMList(S
::user());
1231 $listClient->change_user_email($user->forlifeEmail(), Post
::t('email'));
1232 update_alias_user($user->forlifeEmail(), Post
::t('email'));
1234 if (XDB
::affectedRows()) {
1235 $page->trigSuccess('Données de l\'utilisateur mises à jour.');
1238 if (($user->type
== 'xnet' && !$user->perms
)) {
1239 if (Post
::b('suggest')) {
1240 $request = new AccountReq(S
::user(), $user->hruid
, Post
::t('email'), $globals->asso('nom'));
1242 $page->trigSuccess('Le compte va bientôt être activé.');
1244 if (Post
::b('again')) {
1245 $data = XDB
::fetchOneAssoc('SELECT hash, group_name, sender_name, email
1246 FROM register_pending_xnet
1250 $mailer = new PlMailer('xnet/account.mail.tpl');
1251 $mailer->addCc('validation+xnet_account@polytechnique.org');
1252 $mailer->setTo($data['email']);
1253 $mailer->assign('hash', $data['hash']);
1254 $mailer->assign('email', $data['email']);
1255 $mailer->assign('group', $data['group_name']);
1256 $mailer->assign('sender_name', $data['sender_name']);
1257 $mailer->assign('again', true
);
1259 $page->trigSuccess('Relance effectuée avec succès.');
1263 // Update group params for user
1264 $perms = Post
::v('group_perms');
1265 $comm = Post
::t('comm');
1266 $position = (Post
::t('group_position') == '') ? null
: Post
::v('group_position');
1267 if ($user->group_perms
!= $perms ||
$user->group_comm
!= $comm ||
$user->group_position
!= $position) {
1268 XDB
::query('UPDATE group_members
1269 SET perms = {?}, comm = {?}, position = {?}
1270 WHERE uid = {?} AND asso_id = {?}',
1271 ($perms == 'admin') ?
'admin' : 'membre', $comm, $position,
1272 $user->id(), $globals->asso('id'));
1273 if (XDB
::affectedRows()) {
1274 if ($perms != $user->group_perms
) {
1275 $page->trigSuccess('Permissions modifiées !');
1277 if ($comm != $user->group_comm
) {
1278 $page->trigSuccess('Commentaire mis à jour.');
1280 if ($position != $user->group_position
) {
1281 $page->trigSuccess('Poste mis à jour.');
1286 // Gets user info again as they might have change
1287 $user = User
::getSilent($user->id());
1289 // Update ML subscriptions
1290 foreach (Env
::v('ml1', array()) as $ml => $state) {
1291 $ask = empty($_REQUEST['ml2'][$ml]) ?
0 : 2;
1292 if ($ask == $state) {
1295 if ($state == '1') {
1296 $page->trigWarning("{$user->fullName()} a "
1297 ."actuellement une demande d'inscription en "
1298 ."cours sur <strong>$ml@</strong> !!!");
1300 $mmlist->mass_subscribe($ml, Array($user->forlifeEmail()));
1301 $page->trigSuccess("{$user->fullName()} a été abonné à $ml@.");
1303 $mmlist->mass_unsubscribe($ml, Array($user->forlifeEmail()));
1304 $page->trigSuccess("{$user->fullName()} a été désabonné de $ml@.");
1308 // Change subscriptioin to aliases
1309 foreach (Env
::v('ml3', array()) as $ml => $state) {
1310 require_once 'emails.inc.php';
1311 $ask = !empty($_REQUEST['ml4'][$ml]);
1312 list($local_part, ) = explode('@', $ml);
1313 if ($ask == $state) {
1317 add_to_list_alias($user->id(), $local_part, $globals->asso('mail_domain'));
1318 $page->trigSuccess("{$user->fullName()} a été abonné à $ml.");
1320 delete_from_list_alias($user->id(), $local_part, $globals->asso('mail_domain'));
1321 $page->trigSuccess("{$user->fullName()} a été désabonné de $ml.");
1325 if ($globals->asso('has_nl')) {
1326 $nl = NewsLetter
::forGroup($globals->asso('shortname'));
1327 // Updates group's newsletter subscription.
1328 if (Post
::i('newsletter') == 1) {
1329 $nl->subscribe($user);
1331 $nl->unsubscribe(null
, $user->id());
1336 $res = XDB
::rawFetchAllAssoc('SHOW COLUMNS FROM group_members LIKE \'position\'');
1337 $positions = str_replace(array('enum(', ')', '\''), '', $res[0]['Type']);
1338 if ($globals->asso('has_nl')) {
1339 $nl = NewsLetter
::forGroup($globals->asso('shortname'));
1340 $nl_registered = $nl->subscriptionState($user);
1342 $nl_registered = false
;
1345 $page->assign('user', $user);
1346 $page->assign('suggest', $this->suggest($user));
1347 $page->assign('listes', $mmlist->get_lists($user->forlifeEmail()));
1348 $page->assign('alias', $user->emailGroupAliases($globals->asso('mail_domain')));
1349 $page->assign('positions', explode(',', $positions));
1350 $page->assign('nl_registered', $nl_registered);
1351 $page->assign('pending_xnet_account', XDB
::fetchOneCell('SELECT 1
1352 FROM register_pending_xnet
1357 function handler_rss(PlPage
$page, PlUser
$user)
1360 $page->assign('asso', $globals->asso());
1362 $this->load('feed.inc.php');
1363 $feed = new XnetGrpEventFeed();
1364 return $feed->run($page, $user, false
);
1367 private function upload_image(PlPage
$page, PlUpload
$upload)
1369 if (@!$_FILES['image']['tmp_name'] && !Env
::v('image_url')) {
1372 if (!$upload->upload($_FILES['image']) && !$upload->download(Env
::v('image_url'))) {
1373 $page->trigError('Impossible de télécharger l\'image');
1375 } elseif (!$upload->isType('image')) {
1376 $page->trigError('Le fichier n\'est pas une image valide au format JPEG, GIF ou PNG.');
1379 } elseif (!$upload->resizeImage(80, 100, 100, 100, 32284)) {
1380 $page->trigError('Impossible de retraiter l\'image');
1386 function handler_photo_announce($page, $eid = null
) {
1388 $res = XDB
::query('SELECT *
1389 FROM group_announces_photo
1390 WHERE eid = {?}', $eid);
1391 if ($res->numRows()) {
1392 $photo = $res->fetchOneAssoc();
1393 pl_cached_dynamic_content_headers("image/" . $photo['attachmime']);
1394 echo $photo['attach'];
1398 $upload = new PlUpload(S
::user()->login(), 'xnetannounce');
1399 if ($upload->exists() && $upload->isType('image')) {
1400 pl_cached_dynamic_content_headers($upload->contentType());
1401 echo $upload->getContents();
1406 pl_cached_dynamic_content_headers("image/png");
1407 echo file_get_contents($globals->spoolroot
. '/htdocs/images/logo.png');
1411 function handler_edit_announce($page, $aid = null
)
1413 global $globals, $platal;
1414 $page->changeTpl('xnetgrp/announce-edit.tpl');
1415 $page->assign('new', is_null($aid));
1418 if (Post
::v('valid') == 'Visualiser' || Post
::v('valid') == 'Enregistrer'
1419 || Post
::v('valid') == 'Supprimer l\'image' || Post
::v('valid') == 'Pas d\'image') {
1420 S
::assert_xsrf_token();
1422 if (!is_null($aid)) {
1425 $art['titre'] = Post
::v('titre');
1426 $art['texte'] = Post
::v('texte');
1427 $art['contacts'] = Post
::v('contacts');
1428 $art['promo_min'] = Post
::i('promo_min');
1429 $art['promo_max'] = Post
::i('promo_max');
1430 $art['nom'] = S
::v('nom');
1431 $art['prenom'] = S
::v('prenom');
1432 $art['promo'] = S
::v('promo');
1433 $art['hruid'] = S
::user()->login();
1434 $art['uid'] = S
::user()->id();
1435 $art['expiration'] = Post
::v('expiration');
1436 $art['public'] = Post
::has('public');
1437 $art['xorg'] = Post
::has('xorg');
1438 $art['nl'] = Post
::has('nl');
1439 $art['event'] = Post
::v('event');
1440 $upload = new PlUpload(S
::user()->login(), 'xnetannounce');
1441 $this->upload_image($page, $upload);
1443 $art['contact_html'] = $art['contacts'];
1444 if ($art['event']) {
1445 $art['contact_html'] .= "\n{$globals->baseurl}/{$platal->ns}events/sub/{$art['event']}";
1448 if (!$art['public'] &&
1449 (($art['promo_min'] > $art['promo_max'] && $art['promo_max'] != 0) ||
1450 ($art['promo_min'] != 0 && ($art['promo_min'] <= 1900 ||
$art['promo_min'] >= 2020)) ||
1451 ($art['promo_max'] != 0 && ($art['promo_max'] <= 1900 ||
$art['promo_max'] >= 2020))))
1453 $page->trigError("L'intervalle de promotions est invalide.");
1454 Post
::kill('valid');
1457 if (!trim($art['titre']) ||
!trim($art['texte'])) {
1458 $page->trigError("L'article doit avoir un titre et un contenu.");
1459 Post
::kill('valid');
1462 if (Post
::v('valid') == 'Supprimer l\'image') {
1464 Post
::kill('valid');
1466 $art['photo'] = $upload->exists() || Post
::i('photo');
1467 if (Post
::v('valid') == 'Pas d\'image' && !is_null($aid)) {
1468 XDB
::query('DELETE FROM group_announces_photo
1469 WHERE eid = {?}', $aid);
1471 Post
::kill('valid');
1472 $art['photo'] = false
;
1476 if (Post
::v('valid') == 'Enregistrer') {
1477 $promo_min = ($art['public'] ?
0 : $art['promo_min']);
1478 $promo_max = ($art['public'] ?
0 : $art['promo_max']);
1479 $flags = new PlFlagSet();
1480 if ($art['public']) {
1481 $flags->addFlag('public');
1483 if ($art['photo']) {
1484 $flags->addFlag('photo');
1486 if (is_null($aid)) {
1487 $fulltext = $art['texte'];
1488 if (!empty($art['contact_html'])) {
1489 $fulltext .= "\n\n'''Contacts :'''\\\\\n" . $art['contact_html'];
1492 if ($globals->asso('forum')) {
1493 require_once 'banana/forum.inc.php';
1494 $banana = new ForumsBanana(S
::user());
1495 $post = $banana->post($globals->asso('forum'), null
,
1496 $art['titre'], MiniWiki
::wikiToText($fulltext, false
, 0, 80));
1498 XDB
::query('INSERT INTO group_announces (uid, asso_id, create_date, titre, texte, contacts,
1499 expiration, promo_min, promo_max, flags, post_id)
1500 VALUES ({?}, {?}, NOW(), {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})',
1501 S
::i('uid'), $globals->asso('id'), $art['titre'], $art['texte'], $art['contact_html'],
1502 $art['expiration'], $promo_min, $promo_max, $flags, $post);
1503 $aid = XDB
::insertId();
1504 if ($art['photo']) {
1505 list($imgx, $imgy, $imgtype) = $upload->imageInfo();
1506 XDB
::execute('INSERT INTO group_announces_photo
1507 SET eid = {?}, attachmime = {?}, x = {?}, y = {?}, attach = {?}',
1508 $aid, $imgtype, $imgx, $imgy, $upload->getContents());
1511 $article = new EvtReq("[{$globals->asso('nom')}] " . $art['titre'], $fulltext,
1512 $art['promo_min'], $art['promo_max'], $art['expiration'], "", S
::user(),
1515 $page->trigWarning("L'affichage sur la page d'accueil de Polytechnique.org est en attente de validation.");
1516 } else if ($upload && $upload->exists()) {
1520 $article = new NLReq(S
::user(), $globals->asso('nom') . " : " .$art['titre'],
1521 $art['texte'], $art['contact_html']);
1523 $page->trigWarning("La parution dans la Lettre Mensuelle est en attente de validation.");
1526 XDB
::query('UPDATE group_announces
1527 SET titre = {?}, texte = {?}, contacts = {?}, expiration = {?},
1528 promo_min = {?}, promo_max = {?}, flags = {?}
1529 WHERE id = {?} AND asso_id = {?}',
1530 $art['titre'], $art['texte'], $art['contacts'], $art['expiration'],
1531 $promo_min, $promo_max, $flags,
1532 $art['id'], $globals->asso('id'));
1533 if ($art['photo'] && $upload->exists()) {
1534 list($imgx, $imgy, $imgtype) = $upload->imageInfo();
1535 XDB
::execute('INSERT INTO group_announces_photo (eid, attachmime, attach, x, y)
1536 VALUES ({?}, {?}, {?}, {?}, {?})
1537 ON DUPLICATE KEY UPDATE attachmime = VALUES(attachmime), attach = VALUES(attach), x = VALUES(x), y = VALUES(y)',
1538 $aid, $imgtype, $upload->getContents(), $imgx, $imgy);
1543 if (Post
::v('valid') == 'Enregistrer' || Post
::v('valid') == 'Annuler') {
1547 if (empty($art) && !is_null($aid)) {
1548 $res = XDB
::query("SELECT *, FIND_IN_SET('public', flags) AS public,
1549 FIND_IN_SET('photo', flags) AS photo
1550 FROM group_announces
1551 WHERE asso_id = {?} AND id = {?}",
1552 $globals->asso('id'), $aid);
1553 if ($res->numRows()) {
1554 $art = $res->fetchOneAssoc();
1555 $art['contact_html'] = $art['contacts'];
1557 $page->kill("Aucun article correspond à l'identifiant indiqué.");
1561 if (is_null($aid)) {
1562 $events = XDB
::iterator("SELECT *
1564 WHERE asso_id = {?} AND archive = 0",
1565 $globals->asso('id'));
1566 if ($events->total()) {
1567 $page->assign('events', $events);
1571 $art['contact_html'] = @MiniWiki
::WikiToHTML($art['contact_html']);
1572 $page->assign('art', $art);
1573 $page->assign_by_ref('upload', $upload);
1576 function handler_admin_announce($page)
1579 $page->changeTpl('xnetgrp/announce-admin.tpl');
1581 if (Env
::has('del')) {
1582 S
::assert_xsrf_token();
1583 XDB
::execute('DELETE FROM group_announces
1584 WHERE id = {?} AND asso_id = {?}',
1585 Env
::i('del'), $globals->asso('id'));
1587 $res = XDB
::iterator('SELECT id, titre, expiration, expiration < CURRENT_DATE() AS perime
1588 FROM group_announces
1590 ORDER BY expiration DESC',
1591 $globals->asso('id'));
1592 $page->assign('articles', $res);
1596 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: