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_MDP
, 'groupadmin'),
33 '%grp/mail' => $this->make_hook('mail', AUTH_MDP
, 'groupadmin'),
34 '%grp/forum' => $this->make_hook('forum', AUTH_MDP
, 'groupmember'),
35 '%grp/annuaire' => $this->make_hook('annuaire', AUTH_MDP
, 'groupannu'),
36 '%grp/annuaire/vcard' => $this->make_hook('vcard', AUTH_MDP
, 'groupmember:groupannu'),
37 '%grp/annuaire/csv' => $this->make_hook('csv', AUTH_MDP
, 'groupmember:groupannu'),
38 '%grp/trombi' => $this->make_hook('trombi', AUTH_MDP
, 'groupannu'),
39 '%grp/geoloc' => $this->make_hook('geoloc', AUTH_MDP
, 'groupannu'),
40 '%grp/subscribe' => $this->make_hook('subscribe', AUTH_MDP
),
41 '%grp/subscribe/valid' => $this->make_hook('subscribe_valid', AUTH_MDP
, 'groupadmin'),
42 '%grp/unsubscribe' => $this->make_hook('unsubscribe', AUTH_MDP
, 'groupmember'),
44 '%grp/change_rights' => $this->make_hook('change_rights', AUTH_MDP
),
45 '%grp/admin/annuaire' => $this->make_hook('admin_annuaire', AUTH_MDP
, 'groupadmin'),
46 '%grp/member' => $this->make_hook('admin_member', AUTH_MDP
, 'groupadmin'),
47 '%grp/member/new' => $this->make_hook('admin_member_new', AUTH_MDP
, 'groupadmin'),
48 '%grp/member/new/ajax' => $this->make_hook('admin_member_new_ajax', AUTH_MDP
, 'user', NO_AUTH
),
49 '%grp/member/del' => $this->make_hook('admin_member_del', AUTH_MDP
, 'groupadmin'),
51 '%grp/rss' => $this->make_token_hook('rss', AUTH_PUBLIC
),
52 '%grp/announce/new' => $this->make_hook('edit_announce', AUTH_MDP
, 'groupadmin'),
53 '%grp/announce/edit' => $this->make_hook('edit_announce', AUTH_MDP
, 'groupadmin'),
54 '%grp/announce/photo' => $this->make_hook('photo_announce', AUTH_PUBLIC
),
55 '%grp/admin/announces' => $this->make_hook('admin_announce', AUTH_MDP
, 'groupadmin'),
59 function handler_index($page, $arg = null
)
61 global $globals, $platal;
65 $page->changeTpl('xnetgrp/asso.tpl');
68 if (Env
::has('read')) {
69 XDB
::query('DELETE r.*
70 FROM group_announces_read AS r
71 INNER JOIN group_announces AS a ON (a.id = r.announce_id)
72 WHERE expiration < CURRENT_DATE()');
73 XDB
::query('INSERT INTO group_announces_read
75 Env
::i('read'), S
::i('uid'));
78 if (Env
::has('unread')) {
79 XDB
::query('DELETE FROM group_announces_read
80 WHERE announce_id = {?} AND uid = {?}',
81 Env
::i('unread'), S
::i('uid'));
82 pl_redirect("#art" . Env
::i('unread'));
85 /* TODO: refines this filter on promotions by using userfilter. */
87 if ($user->hasProfile()) {
88 $promo = XDB
::format('{?}', $user->profile()->entry_year
);
89 $minCondition = ' OR promo_min <= ' . $promo;
90 $maxCondition = ' OR promo_max >= ' . $promo;
95 $arts = XDB
::iterator('SELECT a.*, FIND_IN_SET(\'photo\', a.flags) AS photo
96 FROM group_announces AS a
97 LEFT JOIN group_announces_read AS r ON (r.uid = {?} AND r.announce_id = a.id)
98 WHERE asso_id = {?} AND expiration >= CURRENT_DATE()
99 AND (promo_min = 0' . $minCondition . ')
100 AND (promo_max = 0' . $maxCondition . ')
101 AND r.announce_id IS NULL
102 ORDER BY a.expiration',
103 S
::i('uid'), $globals->asso('id'));
104 $index = XDB
::iterator('SELECT a.id, a.titre, r.uid IS NULL AS nonlu
105 FROM group_announces AS a
106 LEFT JOIN group_announces_read AS r ON (a.id = r.announce_id AND r.uid = {?})
107 WHERE asso_id = {?} AND expiration >= CURRENT_DATE()
108 AND (promo_min = 0' . $minCondition . ')
109 AND (promo_max = 0' . $maxCondition . ')
110 ORDER BY a.expiration',
111 S
::i('uid'), $globals->asso('id'));
112 $page->assign('article_index', $index);
114 $arts = XDB
::iterator("SELECT *, FIND_IN_SET('photo', flags) AS photo
116 WHERE asso_id = {?} AND expiration >= CURRENT_DATE()
117 AND FIND_IN_SET('public', flags)",
118 $globals->asso('id'));
121 $subs_valid = XDB
::query("SELECT uid
122 FROM group_member_sub_requests
123 WHERE asso_id = {?}",
124 $globals->asso('id'));
125 $page->assign('requests', $subs_valid->numRows());
128 if (!S
::hasAuthToken()) {
129 $page->setRssLink("Polytechnique.net :: {$globals->asso("nom
")} :: News publiques",
130 $platal->ns
. "rss/rss.xml");
132 $page->setRssLink("Polytechnique.net :: {$globals->asso("nom
")} :: News",
133 $platal->ns
. 'rss/' . S
::v('hruid') . '/' . S
::user()->token
. '/rss.xml');
136 $page->assign('articles', $arts);
139 function handler_logo($page)
142 $globals->asso()->getLogo()->send();
145 function handler_site($page)
148 $site = $globals->asso('site');
150 $page->trigError('Le groupe n\'a pas de site web.');
151 return $this->handler_index($page);
153 http_redirect($site);
157 function handler_edit($page)
160 $page->changeTpl('xnetgrp/edit.tpl');
162 if (Post
::has('submit')) {
163 S
::assert_xsrf_token();
165 $flags = new PlFlagSet('wiki_desc');
166 $flags->addFlag('notif_unsub', Post
::i('notif_unsub') == 1);
167 $site = Post
::t('site');
168 if ($site && ($site != "http://")) {
169 $scheme = parse_url($site, PHP_URL_SCHEME
);
171 $site = "http://" . $site;
177 $page->assign('super', true
);
179 if (Post
::v('mail_domain') && (strstr(Post
::v('mail_domain'), '.') === false
)) {
180 $page->trigError('Le domaine doit être un FQDN (aucune modification effectuée) !!!');
183 if (Post
::t('nom') == '' || Post
::t('diminutif') == '') {
184 $page->trigError('Ni le nom ni le diminutif du groupe ne peuvent être vide.');
187 $axDate = make_datetime(Post
::v('axDate'));
188 if (Post
::t('axDate') != '') {
189 $axDate = make_datetime(Post
::v('axDate'))->format('Y-m-d');
195 SET nom={?}, diminutif={?}, cat={?}, dom={?},
196 descr={?}, site={?}, mail={?}, resp={?},
197 forum={?}, mail_domain={?}, ax={?}, axDate = {?}, pub={?},
198 sub_url={?}, inscriptible={?}, unsub_url={?},
199 flags = {?}, welcome_msg = {?}
201 Post
::v('nom'), Post
::v('diminutif'),
202 Post
::v('cat'), (Post
::i('dom') == 0) ? null
: Post
::i('dom'),
203 Post
::v('descr'), $site,
204 Post
::v('mail'), Post
::v('resp'),
205 Post
::v('forum'), Post
::v('mail_domain'),
206 Post
::has('ax'), $axDate, Post
::v('pub'),
207 Post
::v('sub_url'), Post
::v('inscriptible'),
208 Post
::v('unsub_url'), $flags, Post
::t('welcome_msg'),
209 $globals->asso('id'));
210 if (Post
::v('mail_domain')) {
211 XDB
::execute('INSERT IGNORE INTO email_virtual_domains (name)
213 Post
::t('mail_domain'));
214 XDB
::execute('UPDATE email_virtual_domains
217 Post
::t('mail_domain'));
222 SET descr={?}, site={?}, mail={?}, resp={?},
223 forum={?}, pub= {?}, sub_url={?},
224 unsub_url = {?}, flags = {?}, welcome_msg = {?}
226 Post
::v('descr'), $site,
227 Post
::v('mail'), Post
::v('resp'),
228 Post
::v('forum'), Post
::v('pub'),
229 Post
::v('sub_url'), Post
::v('unsub_url'),
230 $flags, Post
::t('welcome_msg'),
231 $globals->asso('id'));
234 Phone
::deletePhones(0, Phone
::LINK_GROUP
, $globals->asso('id'));
235 $phone = new Phone(array('link_type' => 'group', 'link_id' => $globals->asso('id'), 'id' => 0,
236 'type' => 'fixed', 'display' => Post
::v('phone'), 'pub' => 'public'));
237 $fax = new Phone(array('link_type' => 'group', 'link_id' => $globals->asso('id'), 'id' => 1,
238 'type' => 'fax', 'display' => Post
::v('fax'), 'pub' => 'public'));
241 Address
::deleteAddresses(null
, Address
::LINK_GROUP
, null
, $globals->asso('id'));
242 $address = new Address(array('groupid' => $globals->asso('id'), 'type' => Address
::LINK_GROUP
, 'text' => Post
::v('address')));
245 if ($_FILES['logo']['name']) {
246 $upload = PlUpload
::get($_FILES['logo'], $globals->asso('id'), 'asso.logo', true
);
248 $page->trigError("Impossible de télécharger le logo.");
250 XDB
::execute('UPDATE groups
251 SET logo = {?}, logo_mime = {?}
252 WHERE id = {?}', $upload->getContents(), $upload->contentType(),
253 $globals->asso('id'));
258 pl_redirect('../' . Post
::v('diminutif', $globals->asso('diminutif')) . '/edit');
262 $dom = XDB
::iterator('SELECT *
265 $page->assign('dom', $dom);
266 $page->assign('super', true
);
270 function handler_mail($page)
274 $page->changeTpl('xnetgrp/mail.tpl');
275 $mmlist = new MMList(S
::user(), $globals->asso('mail_domain'));
276 $page->assign('listes', $mmlist->get_lists());
277 $page->assign('user', S
::user());
279 if (Post
::has('send')) {
280 S
::assert_xsrf_token();
281 $from = Post
::v('from');
282 $sujet = Post
::v('sujet');
283 $body = Post
::v('body');
285 $mls = array_keys(Env
::v('ml', array()));
286 $mbr = array_keys(Env
::v('membres', array()));
288 $this->load('mail.inc.php');
290 $tos = get_all_redirects($mbr, $mls, $mmlist);
292 $upload = PlUpload
::get($_FILES['uploaded'], S
::user()->login(), 'xnet.emails', true
);
293 if (!$upload && @$_FILES['uploaded']['name'] && PlUpload
::$lastError != null
) {
294 $page->trigError(PlUpload
::$lastError);
298 send_xnet_mails($from, $sujet, $body, Env
::v('wiki'), $tos, Post
::v('replyto'), $upload, @$_FILES['uploaded']['name']);
302 $page->killSuccess("Email envoyé !");
303 $page->assign('sent', true
);
307 function handler_forum($page, $group = null
, $artid = null
)
310 $page->changeTpl('xnetgrp/forum.tpl');
311 if (!$globals->asso('forum')) {
314 require_once 'banana/forum.inc.php';
316 get_banana_params($get, $globals->asso('forum'), $group, $artid);
317 run_banana($page, 'ForumsBanana', $get);
320 function handler_annuaire($page, $action = null
, $subaction = null
)
324 if ($action == 'trombi') {
325 __autoload('userset');
326 if ($action == 'trombi') {
327 $view = new ProfileSet(new UFC_Group($globals->asso('id')));
329 $view = new UserSet(new UFC_Group($globals->asso('id')));
331 $view->addMod('trombi', 'Trombinoscope');
332 $view->apply('annuaire', $page, $action, $subaction);
333 $page->changeTpl('xnetgrp/annuaire.tpl');
334 $count = XDB
::fetchOneCell('SELECT COUNT(*)
336 WHERE asso_id = {?}',
337 $globals->asso('id'));
338 $page->assign('nb_tot', $count);
342 $page->changeTpl('xnetgrp/annuaire.tpl');
343 $sort = Env
::s('order', 'directory_name');
344 $ofs = Env
::i('offset');
349 $sdesc = $sort{0} == '-';
350 $sf = $sdesc ?
substr($sort, 1) : $sort;
351 if ($sf == 'promo') {
352 $se = new UFO_Promo(null
, $sdesc);
354 $se = new UFO_Name($sf, null
, null
, $sdesc);
357 if (Env
::b('admin')) {
358 $uf = $globals->asso()->getAdminsFilter(null
, $se);
360 $uf = $globals->asso()->getMembersFilter(null
, $se);
362 $users = $uf->getUsers(new PlLimit(NB_PER_PAGE
, $ofs * NB_PER_PAGE
));
363 $count = $uf->getTotalCount();
365 $page->assign('nb_tot', $count);
366 $page->assign('pages', floor(($count + NB_PER_PAGE
- 1) / NB_PER_PAGE
));
367 $page->assign('current', $ofs);
368 $page->assign('order', $sort);
369 $page->assign('users', $users);
370 $page->assign('only_admin', Env
::b('admin'));
373 function handler_trombi($page)
375 pl_redirect('annuaire/trombi');
378 function handler_geoloc($page)
380 pl_redirect('annuaire/geoloc');
383 function handler_vcard($page, $photos = null
)
386 $vcard = new VCard($photos == 'photos', 'Membre du groupe ' . $globals->asso('nom'));
387 $vcard->addProfiles($globals->asso()->getMembersFilter()->getProfiles(null
, Profile
::FETCH_ALL
));
391 function handler_csv($page, $filename = null
)
394 if (is_null($filename)) {
395 $filename = $globals->asso('diminutif') . '.csv';
397 $users = $globals->asso()->getMembersFilter(null
, new UFO_Name('directory_name'))->getUsers();
398 pl_cached_content_headers('text/x-csv', 1);
399 $page->changeTpl('xnetgrp/annuaire-csv.tpl', NO_SKIN
);
400 $page->assign('users', $users);
403 private function removeSubscriptionRequest($uid)
406 XDB
::execute("DELETE FROM group_member_sub_requests
407 WHERE asso_id = {?} AND uid = {?}",
408 $globals->asso('id'), $uid);
411 private function validSubscription(User
$user)
414 $this->removeSubscriptionRequest($user->id());
415 XDB
::execute("INSERT IGNORE INTO group_members (asso_id, uid)
417 $globals->asso('id'), $user->id());
418 if (XDB
::affectedRows() == 1) {
419 $mailer = new PlMailer();
420 $mailer->addTo($user->forlifeEmail());
421 $mailer->setFrom('"' . S
::user()->fullName() . '" <' . S
::user()->forlifeEmail() . '>');
422 $mailer->setSubject('[' . $globals->asso('nom') . '] Demande d\'inscription');
423 $message = ($user->isFemale() ?
'Chère' : 'Cher') . " Camarade,\n"
425 . " Suite à ta demande d'adhésion à " . $globals->asso('nom')
426 . ", j'ai le plaisir de t'annoncer que ton inscription a été validée !\n"
427 . (is_null($globals->asso('welcome_msg')) ?
'' : "\n" . $globals->asso('welcome_msg') . "\n")
429 . "Bien cordialement,\n"
431 . S
::user()->fullName() . '.';
432 $mailer->setTxtBody(wordwrap($message, 72));
437 function handler_subscribe($page, $u = null
)
440 $page->changeTpl('xnetgrp/inscrire.tpl');
442 if (!$globals->asso('inscriptible'))
443 $page->kill("Il n'est pas possible de s'inscire en ligne à ce "
444 ."groupe. Essaie de joindre le contact indiqué "
445 ."sur la page de présentation.");
447 if (!is_null($u) && may_update()) {
448 $user = User
::get($u);
452 $page->assign('user', $user);
455 // Retrieves the subscription status, and the reason.
456 $res = XDB
::query("SELECT reason
457 FROM group_member_sub_requests
458 WHERE asso_id = {?} AND uid = {?}",
459 $globals->asso('id'), $user->id());
460 $reason = ($res->numRows() ?
$res->fetchOneCell() : null
);
462 $res = XDB
::query("SELECT COUNT(*)
464 WHERE asso_id = {?} AND uid = {?}",
465 $globals->asso('id'), $user->id());
466 $already_member = ($res->fetchOneCell() > 0);
468 // Handles the membership request.
469 if ($already_member) {
470 $this->removeSubscriptionRequest($user->id());
471 $page->kill($user->fullName() . ' est déjà membre du groupe !');
472 } elseif (Env
::has('accept')) {
473 S
::assert_xsrf_token();
475 $this->validSubscription($user);
476 pl_redirect("member/" . $user->login());
477 } elseif (Env
::has('refuse')) {
478 S
::assert_xsrf_token();
480 $this->removeSubscriptionRequest($user->id());
481 $mailer = new PlMailer();
482 $mailer->addTo($user->forlifeEmail());
483 $mailer->setFrom('"' . S
::user()->fullName() . '" <' . S
::user()->forlifeEmail() . '>');
484 $mailer->setSubject('['.$globals->asso('nom').'] Demande d\'inscription annulée');
485 $mailer->setTxtBody(Env
::v('motif'));
487 $page->killSuccess("La demande de {$user->fullName()} a bien été refusée.");
489 $page->assign('show_form', true
);
490 $page->assign('reason', $reason);
496 $page->kill("Tu es déjà membre !");
500 $res = XDB
::query("SELECT uid
501 FROM group_member_sub_requests
502 WHERE uid = {?} AND asso_id = {?}",
503 S
::i('uid'), $globals->asso('id'));
504 if ($res->numRows() != 0) {
505 $page->kill("Tu as déjà demandé ton inscription à ce groupe. Cette demande est actuellement en attente de validation.");
509 if (Post
::has('inscrire')) {
510 S
::assert_xsrf_token();
512 XDB
::execute("INSERT INTO group_member_sub_requests (asso_id, uid, ts, reason)
513 VALUES ({?}, {?}, NOW(), {?})",
514 $globals->asso('id'), S
::i('uid'), Post
::v('message'));
515 $uf = New UserFilter(New UFC_Group($globals->asso('id'), true
));
516 $admins = $uf->iterUsers();
517 $admin = $admins->next();
518 $to = $admin->bestEmail();
519 while ($admin = $admins->next()) {
520 $to .= ', ' . $admin->bestEmail();
525 . "Ce message a été envoyé suite à la demande d'inscription de\n"
526 . S
::user()->fullName() . ' (X' . S
::v('promo') . ")\n"
527 . "Via le site www.polytechnique.net. Tu peux choisir de valider ou\n"
528 . "de refuser sa demande d'inscription depuis la page :\n"
529 . "http://www.polytechnique.net/" . $globals->asso("diminutif") . "/subscribe/" . S
::user()->login() . "\n"
531 . "En cas de problème, contacter l'équipe de Polytechnique.org\n"
532 . "à l'adresse : support@polytechnique.org\n";
535 $to = ($globals->asso('mail') != '') ?
$globals->asso('mail') . ', ' : '';
536 $to .= 'support@polytechnique.org';
537 $append = "\n-- \nLe groupe ".$globals->asso("nom")
538 ." n'a pas d'administrateur, l'équipe de"
539 ." Polytechnique.org a été prévenue et va rapidement"
540 ." résoudre ce problème.\n";
543 $mailer = new PlMailer();
545 $mailer->setFrom('"' . S
::user()->fullName() . '" <' . S
::user()->forlifeEmail() . '>');
546 $mailer->setSubject('['.$globals->asso('nom').'] Demande d\'inscription');
547 $mailer->setTxtBody(Post
::v('message').$append);
552 function handler_subscribe_valid($page)
556 if (Post
::has('valid')) {
557 S
::assert_xsrf_token();
558 $subs = Post
::v('subs');
559 if (is_array($subs)) {
561 foreach ($subs as $hruid => $val) {
563 $user = User
::get($hruid);
565 $this->validSubscription($user);
572 $it = XDB
::iterator('SELECT s.uid, a.hruid, s.ts AS date
573 FROM group_member_sub_requests AS s
574 INNER JOIN accounts AS a ON(s.uid = a.uid)
575 WHERE s.asso_id = {?}
576 ORDER BY s.ts', $globals->asso('id'));
577 $page->changeTpl('xnetgrp/subscribe-valid.tpl');
578 $page->assign('valid', $it);
581 function handler_change_rights($page)
583 if (Env
::has('right') && (may_update() || S
::suid())) {
584 switch (Env
::v('right')) {
586 Platal
::session()->stopSUID();
589 Platal
::session()->doSelfSuid();
594 Platal
::session()->doSelfSuid();
595 may_update(false
, true
);
599 Platal
::session()->doSelfSuid();
600 may_update(false
, true
);
601 is_member(false
, true
);
605 http_redirect($_SERVER['HTTP_REFERER']);
608 function handler_admin_annuaire($page)
612 $this->load('mail.inc.php');
613 $page->changeTpl('xnetgrp/annuaire-admin.tpl');
615 $mmlist = new MMList($user, $globals->asso('mail_domain'));
616 $lists = $mmlist->get_lists();
617 if (!$lists) $lists = array();
618 $listes = array_map(create_function('$arr', 'return $arr["list"];'), $lists);
620 $subscribers = array();
622 foreach ($listes as $list) {
623 list(,$members) = $mmlist->get_members($list);
624 $mails = array_map(create_function('$arr', 'return $arr[1];'), $members);
625 $subscribers = array_unique(array_merge($subscribers, $mails));
628 $not_in_group_x = array();
629 $not_in_group_ext = array();
631 foreach ($subscribers as $mail) {
632 $uf = new UserFilter(new PFC_And(new UFC_Group($globals->asso('id')),
633 new UFC_Email($mail)));
634 if ($uf->getTotalCount() == 0) {
635 if (User
::isForeignEmailAddress($mail)) {
636 $not_in_group_ext[] = $mail;
638 $not_in_group_x[] = $mail;
643 $page->assign('not_in_group_ext', $not_in_group_ext);
644 $page->assign('not_in_group_x', $not_in_group_x);
645 $page->assign('lists', $lists);
648 function handler_admin_member_new($page, $email = null
)
652 $page->changeTpl('xnetgrp/membres-add.tpl');
654 if (is_null($email)) {
658 S
::assert_xsrf_token();
660 // Finds or creates account: first cases are for users with an account.
661 if (!User
::isForeignEmailAddress($email)) {
663 $user = User
::get($email);
664 } else if (!isvalid_email($email)) {
665 // email might not be a regular email but an alias or a hruid
666 $user = User
::get($email);
668 // need a valid email address
669 $page->trigError('« <strong>' . $email . '</strong> » n\'est pas une adresse email valide.');
672 } else if (Env
::v('x') && Env
::i('userid')) {
673 $user = User
::getWithUID(Env
::i('userid'));
675 $page->trigError('Utilisateur invalide.');
679 // User has an account but is not yet registered.
680 if ($user->state
== 'pending') {
681 // Add email in account table.
682 XDB
::query('UPDATE accounts
684 WHERE uid = {?} AND email IS NULL',
685 Post
::t('email'), $user->id());
686 // Add email for marketing if required.
687 if (Env
::v('market')) {
688 $market = Marketing
::get($user->uid
, $email);
690 $market = new Marketing($user->uid
, $email, 'group', $globals->asso('nom'),
691 Env
::v('market_from'), S
::v('uid'));
697 // User is of type xnet.
698 list($mbox, $domain) = explode('@', strtolower($email));
699 $hruid = User
::makeHrid($mbox, $domain, 'ext');
700 // User might already have an account (in another group for example).
701 $user = User
::get($hruid);
703 // If the user has no account yet, creates new account: build names from email address.
705 $parts = explode('.', $mbox);
706 if (count($parts) == 1) {
707 $display_name = $full_name = $directory_name = ucfirst($mbox);
709 $firstname = ucfirst($parts[0]);
710 $lastname = ucwords(implode(' ', array_slice($parts, 1)));
711 $display_name = $firstname;
712 $full_name = "$firstname $lastname";
713 $directory_name = strtoupper($lastname) . " " . $firstname;
715 XDB
::execute('INSERT INTO accounts (hruid, display_name, full_name, directory_name,
717 VALUES ({?}, {?}, {?}, {?}, {?}, \'xnet\')',
718 $hruid, $display_name, $full_name, $directory_name, $email);
719 $user = User
::get($hruid);
724 XDB
::execute('INSERT IGNORE INTO group_members (uid, asso_id)
726 $user->id(), $globals->asso('id'));
727 $this->removeSubscriptionRequest($user->id());
728 pl_redirect('member/' . $user->login());
732 function handler_admin_member_new_ajax($page)
734 pl_content_headers("text/html");
735 $page->changeTpl('xnetgrp/membres-new-search.tpl', NO_SKIN
);
737 if (Env
::has('login')) {
738 $user = User
::getSilent(Env
::t('login'));
739 if ($user && $user->state
!= 'pending') {
740 $users = array($user);
744 list($lastname, $firstname) = str_replace(array('-', ' ', "'"), '%', array(Env
::t('nom'), Env
::t('prenom')));
745 $cond = new PFC_And(new PFC_Not(new UFC_Registered()));
746 if (!empty($lastname)) {
747 $cond->addChild(new UFC_Name(Profile
::LASTNAME
, $lastname, UFC_Name
::CONTAINS
));
749 if (!empty($firstname)) {
750 $cond->addChild(new UFC_Name(Profile
::FIRSTNAME
, $firstname, UFC_Name
::CONTAINS
));
752 if (Env
::t('promo')) {
753 $cond->addChild(new UFC_Promo('=', UserFilter
::DISPLAY
, Env
::t('promo')));
755 $uf = new UserFilter($cond);
756 $users = $uf->getUsers(new PlLimit(30));
757 if ($uf->getTotalCount() > 30) {
758 $page->assign('too_many', true
);
762 $page->assign('users', $users);
765 function unsubscribe(PlUser
$user)
768 XDB
::execute("DELETE FROM group_members
769 WHERE uid = {?} AND asso_id = {?}",
770 $user->id(), $globals->asso('id'));
772 if ($globals->asso('notif_unsub')) {
773 $mailer = new PlMailer('xnetgrp/unsubscription-notif.mail.tpl');
774 $admins = $globals->asso()->iterAdmins();
775 while ($admin = $admins->next()) {
776 $mailer->addTo($admin);
778 $mailer->assign('group', $globals->asso('nom'));
779 $mailer->assign('user', $user);
780 $mailer->assign('selfdone', $user->id() == S
::i('uid'));
784 $domain = $globals->asso('mail_domain');
789 $mmlist = new MMList(S
::user(), $domain);
790 $listes = $mmlist->get_lists($user->forlifeEmail());
792 $may_update = may_update();
794 if (is_array($listes)) {
795 foreach ($listes as $liste) {
796 if ($liste['sub'] == 2) {
798 $mmlist->mass_unsubscribe($liste['list'], Array($user->forlifeEmail()));
800 $mmlist->unsubscribe($liste['list']);
802 } elseif ($liste['sub']) {
803 Platal
::page()->trigWarning($user->fullName() . " a une"
804 ." demande d'inscription en cours sur la"
805 ." liste {$liste['list']}@ !");
811 XDB
::execute('DELETE v
812 FROM email_virtual AS v
813 INNER JOIN email_virtual_domains AS d ON (v.domain = d.id)
814 WHERE v.redirect = {?} AND d.name = {?}',
815 $user->forlifeEmail(), $domain);
819 function handler_unsubscribe($page)
821 $page->changeTpl('xnetgrp/membres-del.tpl');
823 $uid = S
::user()->id();
827 $page->assign('self', true
);
828 $page->assign('user', $uid);
830 if (!Post
::has('confirm')) {
833 S
::assert_xsrf_token();
836 if ($this->unsubscribe($user)) {
837 $page->trigSuccess('Vous avez été désinscrit du groupe avec succès.');
839 $page->trigWarning('Vous avez été désinscrit du groupe, mais des erreurs se sont produites lors des désinscriptions des alias et des listes de diffusion.');
841 $page->assign('is_member', is_member(true
));
844 function handler_admin_member_del($page, $user = null
)
846 $page->changeTpl('xnetgrp/membres-del.tpl');
847 $user = User
::getSilent($user);
851 $page->assign('user', $user);
853 if (!Post
::has('confirm')) {
856 S
::assert_xsrf_token();
859 if ($this->unsubscribe($user)) {
860 $page->trigSuccess("{$user->fullName()} a été désinscrit du groupe !");
862 $page->trigWarning("{$user->fullName()} a été désinscrit du groupe, mais des erreurs subsistent !");
866 private function changeLogin(PlPage
$page, PlUser
$user, MMList
$mmlist, $login)
868 // Search the user's uid.
869 $xuser = User
::getSilent($login);
871 $accounts = User
::getPendingAccounts($login);
873 $page->trigError("L'identifiant $login ne correspond à aucun X.");
875 } else if (count($accounts) > 1) {
876 $page->trigError("L'identifiant $login correspond à plusieurs camarades.");
879 $xuser = User
::getSilent($accounts[0]['uid']);
886 if ($user->mergeIn($xuser)) {
887 return $xuser->login();
889 return $user->login();
892 function handler_admin_member($page, $user)
896 $page->changeTpl('xnetgrp/membres-edit.tpl');
898 $user = User
::getSilent($user);
903 $mmlist = new MMList(S
::user(), $globals->asso('mail_domain'));
905 if (Post
::has('change')) {
906 S
::assert_xsrf_token();
908 // Convert user status to X
909 if (!Post
::blank('login_X')) {
910 $forlife = $this->changeLogin($page, $user, $mmlist, Post
::t('login_X'));
912 pl_redirect('member/' . $forlife);
917 $email_changed = (!$user->profile() && strtolower($user->forlifeEmail()) != strtolower(Post
::v('email')));
918 $from_email = $user->forlifeEmail();
919 if ($user->type
== 'virtual' ||
$user->type
== 'xnet') {
920 XDB
::query('UPDATE accounts
921 SET full_name = {?}, directory_name = {?}, display_name = {?},
922 sex = {?}, email = {?}, type = {?}
924 Post
::t('full_name'), Post
::t('directory_name'), Post
::t('display_name'),
925 (Post
::t('sex') == 'male') ?
'male' : 'female', Post
::t('email'),
926 (Post
::t('type') == 'xnet') ?
'xnet' : 'virtual', $user->id());
927 } else if (!$user->perms
) {
928 XDB
::query('UPDATE accounts
931 Post
::t('email'), $user->id());
933 if (XDB
::affectedRows()) {
934 $page->trigSuccess('Données de l\'utilisateur mise à jour.');
937 // Update group params for user
938 $perms = Post
::v('group_perms');
939 $comm = Post
::t('comm');
940 $position = (Post
::t('group_position') == '') ? null
: Post
::v('group_position');
941 if ($user->group_perms
!= $perms ||
$user->group_comm
!= $comm ||
$user->group_position
!= $position) {
942 XDB
::query('UPDATE group_members
943 SET perms = {?}, comm = {?}, position = {?}
944 WHERE uid = {?} AND asso_id = {?}',
945 ($perms == 'admin') ?
'admin' : 'membre', $comm, $position,
946 $user->id(), $globals->asso('id'));
947 if (XDB
::affectedRows()) {
948 if ($perms != $user->group_perms
) {
949 $page->trigSuccess('Permissions modifiées !');
951 if ($comm != $user->group_comm
) {
952 $page->trigSuccess('Commentaire mis à jour.');
954 if ($position != $user->group_position
) {
955 $page->trigSuccess('Poste mis à jour.');
960 // Gets user info again as they might have change
961 $user = User
::getSilent($user->id());
963 // Update ML subscriptions
964 foreach (Env
::v('ml1', array()) as $ml => $state) {
965 $ask = empty($_REQUEST['ml2'][$ml]) ?
0 : 2;
966 if ($ask == $state) {
967 if ($state && $email_changed) {
968 $mmlist->replace_email($ml, $from_email, $user->forlifeEmail());
969 $page->trigSuccess("L'abonnement de {$user->fullName()} à $ml@ a été mis à jour.");
974 $page->trigWarning("{$user->fullName()} a "
975 ."actuellement une demande d'inscription en "
976 ."cours sur <strong>$ml@</strong> !!!");
978 $mmlist->mass_subscribe($ml, Array($user->forlifeEmail()));
979 $page->trigSuccess("{$user->fullName()} a été abonné à $ml@.");
981 if ($email_changed) {
982 $mmlist->mass_unsubscribe($ml, Array($from_email));
984 $mmlist->mass_unsubscribe($ml, Array($user->forlifeEmail()));
986 $page->trigSuccess("{$user->fullName()} a été désabonné de $ml@.");
990 // Change subscriptioin to aliases
991 foreach (Env
::v('ml3', array()) as $ml => $state) {
992 require_once 'emails.inc.php';
993 $ask = !empty($_REQUEST['ml4'][$ml]);
995 if ($state && $email_changed) {
996 update_list_alias($user, $from_email, $ml, $globals->asso('mail_domain'));
997 $page->trigSuccess("L'abonnement de {$user->fullName()} à $ml a été mis à jour.");
1000 add_to_list_alias($user, $ml, $globals->asso('mail_domain'));
1001 $page->trigSuccess("{$user->fullName()} a été abonné à $ml.");
1003 delete_from_list_alias($user, $ml, $globals->asso('mail_domain'));
1004 $page->trigSuccess("{$user->fullName()} a été désabonné de $ml.");
1009 $res = XDB
::rawFetchAllAssoc('SHOW COLUMNS FROM group_members LIKE \'position\'');
1010 $positions = str_replace(array('enum(', ')', '\''), '', $res[0]['Type']);
1012 $page->assign('user', $user);
1013 $page->assign('listes', $mmlist->get_lists($user->forlifeEmail()));
1014 $page->assign('alias', $user->emailGroupAliases($globals->asso('mail_domain')));
1015 $page->assign('positions', explode(',', $positions));
1018 function handler_rss(PlPage
$page, PlUser
$user)
1021 $page->assign('asso', $globals->asso());
1023 $this->load('feed.inc.php');
1024 $feed = new XnetGrpEventFeed();
1025 return $feed->run($page, $user, false
);
1028 private function upload_image(PlPage
$page, PlUpload
$upload)
1030 if (@!$_FILES['image']['tmp_name'] && !Env
::v('image_url')) {
1033 if (!$upload->upload($_FILES['image']) && !$upload->download(Env
::v('image_url'))) {
1034 $page->trigError('Impossible de télécharger l\'image');
1036 } elseif (!$upload->isType('image')) {
1037 $page->trigError('Le fichier n\'est pas une image valide au format JPEG, GIF ou PNG.');
1040 } elseif (!$upload->resizeImage(200, 300, 100, 100, 32284)) {
1041 $page->trigError('Impossible de retraiter l\'image');
1047 function handler_photo_announce($page, $eid = null
) {
1049 $res = XDB
::query('SELECT *
1050 FROM group_announces_photo
1051 WHERE eid = {?}', $eid);
1052 if ($res->numRows()) {
1053 $photo = $res->fetchOneAssoc();
1054 pl_cached_dynamic_content_headers("image/" . $photo['attachmime']);
1055 echo $photo['attach'];
1059 $upload = new PlUpload(S
::user()->login(), 'xnetannounce');
1060 if ($upload->exists() && $upload->isType('image')) {
1061 pl_cached_dynamic_content_headers($upload->contentType());
1062 echo $upload->getContents();
1067 pl_cached_dynamic_content_headers("image/png");
1068 echo file_get_contents($globals->spoolroot
. '/htdocs/images/logo.png');
1072 function handler_edit_announce($page, $aid = null
)
1074 global $globals, $platal;
1075 $page->changeTpl('xnetgrp/announce-edit.tpl');
1076 $page->assign('new', is_null($aid));
1079 if (Post
::v('valid') == 'Visualiser' || Post
::v('valid') == 'Enregistrer'
1080 || Post
::v('valid') == 'Supprimer l\'image' || Post
::v('valid') == 'Pas d\'image') {
1081 S
::assert_xsrf_token();
1083 if (!is_null($aid)) {
1086 $art['titre'] = Post
::v('titre');
1087 $art['texte'] = Post
::v('texte');
1088 $art['contacts'] = Post
::v('contacts');
1089 $art['promo_min'] = Post
::i('promo_min');
1090 $art['promo_max'] = Post
::i('promo_max');
1091 $art['nom'] = S
::v('nom');
1092 $art['prenom'] = S
::v('prenom');
1093 $art['promo'] = S
::v('promo');
1094 $art['hruid'] = S
::user()->login();
1095 $art['uid'] = S
::user()->id();
1096 $art['expiration'] = Post
::v('expiration');
1097 $art['public'] = Post
::has('public');
1098 $art['xorg'] = Post
::has('xorg');
1099 $art['nl'] = Post
::has('nl');
1100 $art['event'] = Post
::v('event');
1101 $upload = new PlUpload(S
::user()->login(), 'xnetannounce');
1102 $this->upload_image($page, $upload);
1104 $art['contact_html'] = $art['contacts'];
1105 if ($art['event']) {
1106 $art['contact_html'] .= "\n{$globals->baseurl}/{$platal->ns}events/sub/{$art['event']}";
1109 if (!$art['public'] &&
1110 (($art['promo_min'] > $art['promo_max'] && $art['promo_max'] != 0) ||
1111 ($art['promo_min'] != 0 && ($art['promo_min'] <= 1900 ||
$art['promo_min'] >= 2020)) ||
1112 ($art['promo_max'] != 0 && ($art['promo_max'] <= 1900 ||
$art['promo_max'] >= 2020))))
1114 $page->trigError("L'intervalle de promotions est invalide.");
1115 Post
::kill('valid');
1118 if (!trim($art['titre']) ||
!trim($art['texte'])) {
1119 $page->trigError("L'article doit avoir un titre et un contenu.");
1120 Post
::kill('valid');
1123 if (Post
::v('valid') == 'Supprimer l\'image') {
1125 Post
::kill('valid');
1127 $art['photo'] = $upload->exists() || Post
::i('photo');
1128 if (Post
::v('valid') == 'Pas d\'image' && !is_null($aid)) {
1129 XDB
::query('DELETE FROM group_announces_photo
1130 WHERE eid = {?}', $aid);
1132 Post
::kill('valid');
1133 $art['photo'] = false
;
1137 if (Post
::v('valid') == 'Enregistrer') {
1138 $promo_min = ($art['public'] ?
0 : $art['promo_min']);
1139 $promo_max = ($art['public'] ?
0 : $art['promo_max']);
1140 $flags = new PlFlagSet();
1141 if ($art['public']) {
1142 $flags->addFlag('public');
1144 if ($art['photo']) {
1145 $flags->addFlag('photo');
1147 if (is_null($aid)) {
1148 $fulltext = $art['texte'];
1149 if (!empty($art['contact_html'])) {
1150 $fulltext .= "\n\n'''Contacts :'''\\\\\n" . $art['contact_html'];
1153 if ($globals->asso('forum')) {
1154 require_once 'banana/forum.inc.php';
1155 $banana = new ForumsBanana(S::user());
1156 $post = $banana->post($globals->asso('forum'), null,
1157 $art['titre'], MiniWiki::wikiToText($fulltext, false, 0, 80));
1159 XDB
::query('INSERT INTO group_announces (uid, asso_id, create_date, titre, texte, contacts,
1160 expiration, promo_min, promo_max, flags, post_id)
1161 VALUES ({?}, {?}, NOW(), {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})',
1162 S
::i('uid'), $globals->asso('id'), $art['titre'], $art['texte'], $art['contact_html'],
1163 $art['expiration'], $promo_min, $promo_max, $flags, $post);
1164 $aid = XDB
::insertId();
1165 if ($art['photo']) {
1166 list($imgx, $imgy, $imgtype) = $upload->imageInfo();
1167 XDB
::execute('INSERT INTO group_announces_photo
1168 SET eid = {?}, attachmime = {?}, x = {?}, y = {?}, attach = {?}',
1169 $aid, $imgtype, $imgx, $imgy, $upload->getContents());
1172 $article = new EvtReq("[{$globals->asso('nom')}] " . $art['titre'], $fulltext,
1173 $art['promo_min'], $art['promo_max'], $art['expiration'], "", S
::user(),
1176 $page->trigWarning("L'affichage sur la page d'accueil de Polytechnique.org est en attente de validation.");
1177 } else if ($upload && $upload->exists()) {
1181 $article = new NLReq(S
::user(), $globals->asso('nom') . " : " .$art['titre'],
1182 $art['texte'], $art['contact_html']);
1184 $page->trigWarning("La parution dans la Lettre Mensuelle est en attente de validation.");
1187 XDB
::query('UPDATE group_announces
1188 SET titre = {?}, texte = {?}, contacts = {?}, expiration = {?},
1189 promo_min = {?}, promo_max = {?}, flags = {?}
1190 WHERE id = {?} AND asso_id = {?}',
1191 $art['titre'], $art['texte'], $art['contacts'], $art['expiration'],
1192 $promo_min, $promo_max, $flags,
1193 $art['id'], $globals->asso('id'));
1194 if ($art['photo'] && $upload->exists()) {
1195 list($imgx, $imgy, $imgtype) = $upload->imageInfo();
1196 XDB
::execute('INSERT INTO group_announces_photo (eid, attachmime, attach, x, y)
1197 VALUES ({?}, {?}, {?}, {?}, {?})
1198 ON DUPLICATE KEY UPDATE attachmime = VALUES(attachmime), attach = VALUES(attach), x = VALUES(x), y = VALUES(y)',
1199 $aid, $imgtype, $upload->getContents(), $imgx, $imgy);
1204 if (Post
::v('valid') == 'Enregistrer' || Post
::v('valid') == 'Annuler') {
1208 if (empty($art) && !is_null($aid)) {
1209 $res = XDB
::query("SELECT *, FIND_IN_SET('public', flags) AS public,
1210 FIND_IN_SET('photo', flags) AS photo
1211 FROM group_announces
1212 WHERE asso_id = {?} AND id = {?}",
1213 $globals->asso('id'), $aid);
1214 if ($res->numRows()) {
1215 $art = $res->fetchOneAssoc();
1216 $art['contact_html'] = $art['contacts'];
1218 $page->kill("Aucun article correspond à l'identifiant indiqué.");
1222 if (is_null($aid)) {
1223 $events = XDB
::iterator("SELECT *
1225 WHERE asso_id = {?} AND archive = 0",
1226 $globals->asso('id'));
1227 if ($events->total()) {
1228 $page->assign('events', $events);
1232 $art['contact_html'] = @MiniWiki
::WikiToHTML($art['contact_html']);
1233 $page->assign('art', $art);
1234 $page->assign_by_ref('upload', $upload);
1237 function handler_admin_announce($page)
1240 $page->changeTpl('xnetgrp/announce-admin.tpl');
1242 if (Env
::has('del')) {
1243 S
::assert_xsrf_token();
1244 XDB
::execute('DELETE FROM group_announces
1245 WHERE id = {?} AND asso_id = {?}',
1246 Env
::i('del'), $globals->asso('id'));
1248 $res = XDB
::iterator('SELECT id, titre, expiration, expiration < CURRENT_DATE() AS perime
1249 FROM group_announces
1251 ORDER BY expiration DESC',
1252 $globals->asso('id'));
1253 $page->assign('articles', $res);
1257 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: