2 /***************************************************************************
3 * Copyright (C) 2003-2008 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 ***************************************************************************/
22 function get_infos($email)
25 // look for uid instead of email if numeric
26 $field = is_numeric($email) ?
'uid' : 'email';
28 if ($field == 'email') {
29 $email = strtolower($email);
30 if (strpos($email, '@') === false
) {
33 list($mbox,$dom) = explode('@', $email);
37 "SELECT uid, nom, prenom, email, email AS email2, perms='admin', origine, sexe
39 WHERE $field = {?} AND asso_id = {?}", $email, $globals->asso('id'));
41 if ($res->numRows()) {
42 $user = $res->fetchOneAssoc();
43 if ($user['origine'] == 'X') {
44 $res = XDB
::query("SELECT nom, prenom, promo, FIND_IN_SET('femme', flags) AS sexe
46 WHERE user_id = {?}", $user['uid']);
47 $user = array_merge($user, $res->fetchOneAssoc());
50 } elseif ($dom == 'polytechnique.org' ||
$dom == 'm4x.org') {
52 "SELECT user_id AS uid, u.promo,
53 IF(u.nom_usage<>'', u.nom_usage, u.nom) AS nom,
55 CONCAT(b.alias, '@m4x.org') AS email,
56 CONCAT(b.alias, '@polytechnique.org') AS email2,
57 m.perms = 'admin' AS perms, m.origine,
58 FIND_IN_SET('femme', u.flags) AS sexe
59 FROM auth_user_md5 AS u
60 INNER JOIN aliases AS a ON ( u.user_id = a.id AND a.type != 'homonyme' )
61 INNER JOIN aliases AS b ON ( u.user_id = b.id AND b.type = 'a_vie' )
62 LEFT JOIN groupex.membres AS m ON ( m.uid = u.user_id AND asso_id={?})
63 WHERE a.alias = {?} AND u.user_id < 50000", $globals->asso('id'), $mbox);
64 return $res->fetchOneAssoc();
71 class XnetGrpModule
extends PLModule
76 '%grp' => $this->make_hook('index', AUTH_PUBLIC
),
77 '%grp/asso.php' => $this->make_hook('index', AUTH_PUBLIC
),
78 '%grp/logo' => $this->make_hook('logo', AUTH_PUBLIC
),
79 '%grp/site' => $this->make_hook('site', AUTH_PUBLIC
),
80 '%grp/edit' => $this->make_hook('edit', AUTH_MDP
, 'groupadmin'),
81 '%grp/mail' => $this->make_hook('mail', AUTH_MDP
, 'groupadmin'),
82 '%grp/forum' => $this->make_hook('forum', AUTH_MDP
, 'groupmember'),
83 '%grp/annuaire' => $this->make_hook('annuaire', AUTH_MDP
, 'groupannu'),
84 '%grp/annuaire/vcard' => $this->make_hook('vcard', AUTH_MDP
, 'groupmember:groupannu'),
85 '%grp/trombi' => $this->make_hook('trombi', AUTH_MDP
, 'groupannu'),
86 '%grp/geoloc' => $this->make_hook('geoloc', AUTH_MDP
, 'groupannu'),
87 '%grp/subscribe' => $this->make_hook('subscribe', AUTH_MDP
),
88 '%grp/unsubscribe' => $this->make_hook('unsubscribe', AUTH_MDP
, 'groupmember'),
90 '%grp/change_rights' => $this->make_hook('change_rights', AUTH_MDP
),
93 => $this->make_hook('admin_annuaire', AUTH_MDP
, 'groupadmin'),
96 => $this->make_hook('admin_member', AUTH_MDP
, 'groupadmin'),
98 => $this->make_hook('admin_member_new', AUTH_MDP
, 'groupadmin'),
99 '%grp/member/new/ajax'
100 => $this->make_hook('admin_member_new_ajax', AUTH_MDP
, 'user', NO_AUTH
),
102 => $this->make_hook('admin_member_del', AUTH_MDP
, 'groupadmin'),
104 '%grp/rss' => $this->make_hook('rss', AUTH_PUBLIC
, 'user', NO_HTTPS
),
105 '%grp/announce/new' => $this->make_hook('edit_announce', AUTH_MDP
, 'groupadmin'),
106 '%grp/announce/edit' => $this->make_hook('edit_announce', AUTH_MDP
, 'groupadmin'),
107 '%grp/announce/photo' => $this->make_hook('photo_announce', AUTH_PUBLIC
),
108 '%grp/admin/announces' => $this->make_hook('admin_announce', AUTH_MDP
, 'groupadmin'),
112 function handler_index(&$page, $arg = null
)
114 global $globals, $platal;
116 if (!is_null($arg)) {
119 $page->changeTpl('xnetgrp/asso.tpl');
122 if (Env
::has('read')) {
123 XDB
::query('DELETE r.*
124 FROM groupex.announces_read AS r
125 INNER JOIN groupex.announces AS a ON a.id = r.announce_id
126 WHERE peremption < CURRENT_DATE()');
127 XDB
::query('INSERT INTO groupex.announces_read
129 Env
::i('read'), S
::i('uid'));
132 if (Env
::has('unread')) {
133 XDB
::query('DELETE FROM groupex.announces_read
134 WHERE announce_id={?} AND user_id={?}',
135 Env
::i('unread'), S
::i('uid'));
136 pl_redirect("#art" . Env
::i('unread'));
138 $arts = XDB
::iterator("SELECT a.*, u.nom, u.prenom, u.promo, l.alias AS forlife,
139 FIND_IN_SET('photo', a.flags) AS photo
140 FROM groupex.announces AS a
141 INNER JOIN auth_user_md5 AS u USING(user_id)
142 INNER JOIN aliases AS l ON (u.user_id = l.id AND l.type = 'a_vie')
143 LEFT JOIN groupex.announces_read AS r ON (r.user_id = {?} AND r.announce_id = a.id)
144 WHERE asso_id = {?} AND peremption >= CURRENT_DATE()
145 AND (promo_min = 0 OR promo_min <= {?})
146 AND (promo_max = 0 OR promo_max >= {?})
147 AND r.announce_id IS NULL
148 ORDER BY a.peremption",
149 S
::i('uid'), $globals->asso('id'), S
::i('promo'), S
::i('promo'));
150 $index = XDB
::iterator("SELECT a.id, a.titre, r.user_id IS NULL AS nonlu
151 FROM groupex.announces AS a
152 LEFT JOIN groupex.announces_read AS r ON (a.id = r.announce_id AND r.user_id = {?})
153 WHERE asso_id = {?} AND peremption >= CURRENT_DATE()
154 AND (promo_min = 0 OR promo_min <= {?})
155 AND (promo_max = 0 OR promo_max >= {?})
156 ORDER BY a.peremption",
157 S
::i('uid'), $globals->asso('id'), S
::i('promo'), S
::i('promo'));
158 $page->assign('article_index', $index);
160 $arts = XDB
::iterator("SELECT a.*, u.nom, u.prenom, u.promo, FIND_IN_SET('photo', a.flags) AS photo
161 FROM groupex.announces AS a
162 INNER JOIN auth_user_md5 AS u USING(user_id)
163 WHERE asso_id = {?} AND peremption >= CURRENT_DATE()
164 AND FIND_IN_SET('public', u.flags)",
165 $globals->asso('id'));
168 if (!S
::has('core_rss_hash')) {
169 $page->setRssLink("Polytechnique.net :: {$globals->asso("nom
")} :: News publiques",
170 $platal->ns
. "rss/rss.xml");
172 $page->setRssLink("Polytechnique.net :: {$globals->asso("nom
")} :: News",
173 $platal->ns
. 'rss/'.S
::v('forlife') .'/'.S
::v('core_rss_hash').'/rss.xml');
176 $page->assign('articles', $arts);
179 function handler_logo(&$page)
183 $res = XDB
::query("SELECT logo, logo_mime
184 FROM groupex.asso WHERE id = {?}",
185 $globals->asso('id'));
186 list($logo, $logo_mime) = $res->fetchOneRow();
189 header("Content-type: $mime");
190 header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
191 header('Last-Modified:' . gmdate('D, d M Y H:i:s') . ' GMT');
192 header('Cache-Control: no-cache, must-revalidate');
193 header('Pragma: no-cache');
196 header('Content-type: image/jpeg');
197 header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
198 header('Last-Modified:' . gmdate('D, d M Y H:i:s') . ' GMT');
199 header('Cache-Control: no-cache, must-revalidate');
200 header('Pragma: no-cache');
201 readfile(dirname(__FILE__
).'/../htdocs/images/dflt_carre.jpg');
207 function handler_site(&$page)
210 $site = $globals->asso('site');
212 $page->trig('Le groupe n\'a pas de site web.');
213 return $this->handler_index($page);
215 http_redirect($site);
219 function handler_edit(&$page)
222 $page->changeTpl('xnetgrp/edit.tpl');
224 if (Post
::has('submit')) {
225 S
::assert_xsrf_token();
227 if (S
::has_perms()) {
228 if (Post
::v('mail_domain') && (strstr(Post
::v('mail_domain'), '.') === false
)) {
229 $page->trig("le domaine doit être un FQDN (aucune modif effectuée) !!!");
234 SET nom={?}, diminutif={?}, cat={?}, dom={?},
235 descr={?}, site={?}, mail={?}, resp={?},
236 forum={?}, mail_domain={?}, ax={?}, pub={?},
237 sub_url={?}, inscriptible={?}, unsub_url={?},
240 Post
::v('nom'), Post
::v('diminutif'),
241 Post
::v('cat'), Post
::i('dom'),
242 Post
::v('descr'), Post
::v('site'),
243 Post
::v('mail'), Post
::v('resp'),
244 Post
::v('forum'), Post
::v('mail_domain'),
245 Post
::has('ax'), Post
::v('pub'),
246 Post
::v('sub_url'), Post
::v('inscriptible'),
247 Post
::v('unsub_url'),$globals->asso('id'));
248 if (Post
::v('mail_domain')) {
249 XDB
::execute('INSERT INTO virtual_domains (domain) VALUES({?})',
250 Post
::v('mail_domain'));
255 SET descr={?}, site={?}, mail={?}, resp={?},
256 forum={?}, ax={?}, pub= {?}, sub_url={?},
257 unsub_url={?},flags='wiki_desc'
259 Post
::v('descr'), Post
::v('site'),
260 Post
::v('mail'), Post
::v('resp'),
261 Post
::v('forum'), Post
::has('ax'),
263 Post
::v('sub_url'), Post
::v('unsub_url'),
264 $globals->asso('id'));
267 if ($_FILES['logo']['name']) {
268 $logo = file_get_contents($_FILES['logo']['tmp_name']);
269 $mime = $_FILES['logo']['type'];
270 XDB
::execute('UPDATE groupex.asso
271 SET logo={?}, logo_mime={?}
272 WHERE id={?}', $logo, $mime,
273 $globals->asso('id'));
276 pl_redirect('../'.Post
::v('diminutif', $globals->asso('diminutif')).'/edit');
279 if (S
::has_perms()) {
280 $dom = XDB
::iterator('SELECT * FROM groupex.dom ORDER BY nom');
281 $page->assign('dom', $dom);
282 $page->assign('super', true
);
284 if (!$globals->asso('wiki_desc') && $globals->asso('descr')) {
285 $page->trig("Attention, le format de la description a changé et utilise désormais la syntaxe wiki "
286 . "intégrée au site. Il te faudra probablement adapter le formatage du texte actuel pour "
287 . "qu'il s'affiche correctement avec cette nouvelle syntaxe.");
291 function handler_mail(&$page)
295 $page->changeTpl('xnetgrp/mail.tpl');
296 $mmlist = new MMList(S
::v('uid'), S
::v('password'),
297 $globals->asso('mail_domain'));
298 $page->assign('listes', $mmlist->get_lists());
299 $page->addJsLink('ajax.js');
301 if (Post
::has('send')) {
302 $from = Post
::v('from');
303 $sujet = Post
::v('sujet');
304 $body = Post
::v('body');
306 $mls = array_keys(Env
::v('ml', array()));
307 $mbr = array_keys(Env
::v('membres', array()));
309 require_once dirname(__FILE__
) . '/xnetgrp/mail.inc.php';
311 $tos = get_all_redirects($mbr, $mls, $mmlist);
312 $upload = PlUpload
::get($_FILES['uploaded'], S
::v('forlife'), 'xnet.emails', true
);
313 send_xnet_mails($from, $sujet, $body, Env
::v('wiki'), $tos, Post
::v('replyto'), $upload, @$_FILES['uploaded']['name']);
317 $page->kill("Mail envoyé !");
318 $page->assign('sent', true
);
322 function handler_forum(&$page, $group = null
, $artid = null
)
325 $page->changeTpl('xnetgrp/forum.tpl');
326 if (!$globals->asso('forum')) {
329 require_once 'banana/forum.inc.php';
331 get_banana_params($get, $globals->asso('forum'), $group, $artid);
332 run_banana($page, 'ForumsBanana', $get);
335 function handler_annuaire(&$page, $action = null
, $subaction = null
)
339 if ($action == 'search') {
340 http_redirect("https://www.polytechnique.org/search/adv?rechercher=Chercher&groupex={$globals->asso('id')}"
341 . "&cityid=" . Env
::v('cityid') . "&mapid=" . Env
::v('mapid'));
342 } else if ($action == 'geoloc' ||
$action == 'trombi') {
343 $view = new UserSet();
344 $view->addMod('trombi', 'Trombinoscope');
345 $view->addMod('geoloc', 'Planisphère', false
, array('with_annu' => 'annuaire/search'));
346 $view->apply('annuaire', $page, $action, $subaction);
347 if ($action == 'geoloc' && $subaction) {
351 $page->changeTpl('xnetgrp/annuaire.tpl');
353 $sort = Env
::v('order');
354 switch (Env
::v('order')) {
355 case 'promo' : $group = 'promo'; $tri = 'promo_o DESC, nom, prenom'; break;
356 case 'promo_inv': $group = 'promo'; $tri = 'promo_o, nom, prenom'; break;
357 case 'alpha_inv': $group = 'initiale'; $tri = 'nom DESC, prenom DESC, promo'; break;
358 default : $group = 'initiale'; $tri = 'nom, prenom, promo'; $sort = 'alpha';
360 $page->assign('sort', $sort);
362 if ($group == 'initiale') {
364 'SELECT UPPER(SUBSTRING(
365 IF(m.origine="X", IF(u.nom_usage<>"", u.nom_usage, u.nom),m.nom),
366 1, 1)) as letter, COUNT(*)
367 FROM groupex.membres AS m
368 LEFT JOIN auth_user_md5 AS u ON ( u.user_id = m.uid)
369 WHERE asso_id = {?} and (u.perms != \'pending\' OR m.email IS NOT NULL)
371 ORDER BY letter', $globals->asso('id'));
374 'SELECT IF(m.origine="X",u.promo,
375 IF(m.origine="ext", "extérieur", "personne morale")) AS promo,
376 COUNT(*), IF(m.origine="X",u.promo,"") AS promo_o
377 FROM groupex.membres AS m
378 LEFT JOIN auth_user_md5 AS u ON ( u.user_id = m.uid )
381 ORDER BY promo_o DESC', $globals->asso('id'));
385 while (list($char, $nb) = $res->next()) {
388 if (Env
::has($group) && $char == strtoupper(Env
::v($group))) {
392 $page->assign('group', $group);
393 $page->assign('request_group', Env
::v($group));
394 $page->assign('only_admin', Env
::has('admin'));
395 $page->assign('alphabet', $alphabet);
396 $page->assign('nb_tot', $nb_tot);
398 $ofs = Env
::i('offset');
399 $tot = Env
::v($group) ?
$tot : $nb_tot;
400 $nbp = intval(($tot-1)/NB_PER_PAGE
);
403 $links['précédent'] = $ofs-1;
405 for ($i = 0; $i <= $nbp; $i++
) {
406 $links[(string)($i+
1)] = $i;
409 $links['suivant'] = $ofs+
1;
411 if (count($links)>1) {
412 $page->assign('links', $links);
416 if (Env
::has('initiale')) {
417 $ini = 'AND IF(m.origine="X",
418 IF(u.nom_usage<>"", u.nom_usage, u.nom),
419 m.nom) LIKE "'.addslashes(Env
::v('initiale')).'%"';
420 } elseif (Env
::has('promo')) {
421 $ini = 'AND IF(m.origine="X", u.promo, IF(m.origine="ext", "extérieur", "personne morale")) = "'
422 .addslashes(Env
::v('promo')).'"';
423 } elseif (Env
::has('admin')) {
424 $ini = 'AND m.perms = "admin"';
427 $ann = XDB
::iterator(
428 "SELECT IF(m.origine='X',IF(u.nom_usage<>'', u.nom_usage, u.nom) ,m.nom) AS nom,
429 IF(m.origine='X',u.prenom,m.prenom) AS prenom,
430 IF(m.origine='X', u.promo, IF(m.origine='ext', 'extérieur', 'personne morale')) AS promo,
431 IF(m.origine='X',u.promo,'') AS promo_o,
432 IF(m.origine='X' AND u.perms != 'pending',a.alias,m.email) AS email,
433 IF(m.origine='X',FIND_IN_SET('femme', u.flags), m.sexe) AS femme,
434 m.perms='admin' AS admin,
436 u.perms!='pending' AS inscrit,
437 m.uid, IF(e.email IS NULL AND FIND_IN_SET('googleapps', u.mail_storage) = 0, NULL, 1) AS actif
438 FROM groupex.membres AS m
439 LEFT JOIN auth_user_md5 AS u ON ( u.user_id = m.uid )
440 LEFT JOIN aliases AS a ON ( a.id = m.uid AND a.type='a_vie' )
441 LEFT JOIN emails AS e ON ( e.flags = 'active' AND e.uid = m.uid)
442 WHERE m.asso_id = {?} $ini
443 AND (m.origine != 'X' OR u.perms != 'pending' OR m.email IS NOT NULL)
446 LIMIT {?},{?}", $globals->asso('id'), $ofs*NB_PER_PAGE
, NB_PER_PAGE
);
447 $page->assign('ann', $ann);
448 $page->jsonAssign('ann', $ann);
451 function handler_trombi(&$page)
453 pl_redirect('annuaire/trombi');
456 function handler_geoloc(&$page)
458 pl_redirect('annuaire/geoloc');
461 function handler_vcard(&$page, $photos = null
)
464 $res = XDB
::query('SELECT uid
466 WHERE asso_id = {?}', $globals->asso('id'));
467 $vcard = new VCard($res->fetchColumn(), $photos == 'photos', 'Membre du groupe ' . $globals->asso('nom'));
468 $vcard->do_page($page);
471 function handler_subscribe(&$page, $u = null
)
474 $page->changeTpl('xnetgrp/inscrire.tpl');
476 if (!$globals->asso('inscriptible'))
477 $page->kill("Il n'est pas possible de s'inscire en ligne à ce "
478 ."groupe. Essaie de joindre le contact indiqué "
479 ."sur la page de présentation.");
481 if (!is_null($u) && may_update()) {
482 $page->assign('u', $u);
483 $res = XDB
::query("SELECT u.nom, u.prenom, u.promo, u.user_id, FIND_IN_SET('femme', u.flags)
484 FROM auth_user_md5 AS u
485 INNER JOIN aliases AS al ON (al.id = u.user_id AND al.type != 'liste')
486 WHERE al.alias = {?}", $u);
488 if (list($nom, $prenom, $promo, $uid, $sexe) = $res->fetchOneRow()) {
489 $res = XDB
::query("SELECT COUNT(*)
490 FROM groupex.membres AS m
491 INNER JOIN aliases AS a ON (m.uid = a.id AND a.type != 'homonyme')
492 WHERE a.alias = {?} AND m.asso_id = {?}",
493 $u, $globals->asso('id'));
494 $n = $res->fetchOneCell();
496 $page->kill("$prenom $nom est déjà membre du groupe !");
499 elseif (Env
::has('accept'))
501 XDB
::execute("INSERT INTO groupex.membres (asso_id, uid)
503 $globals->asso('id'), $uid);
504 $mailer = new PlMailer();
505 $mailer->addTo("$u@polytechnique.org");
506 $mailer->setFrom('"'.S
::v('prenom').' '.S
::v('nom')
507 .'" <'.S
::v('forlife').'@polytechnique.org>');
508 $mailer->setSubject('['.$globals->asso('nom').'] Demande d\'inscription');
509 $message = ($sexe ?
'Chère' : 'Cher') . " Camarade,\n"
511 . " Suite à ta demande d'adhésion à ".$globals->asso('nom').",\n"
512 . "j'ai le plaisir de t'annoncer que ton inscription a été validée !\n"
514 . "Bien cordialement,\n"
516 . "{$_SESSION["prenom
"]} {$_SESSION["nom
"]}.";
517 $mailer->setTxtBody($message);
519 pl_redirect("member/$u");
521 elseif (Env
::has('refuse'))
523 $mailer = new PlMailer();
524 $mailer->addTo("$u@polytechnique.org");
525 $mailer->setFrom('"'.S
::v('prenom').' '.S
::v('nom')
526 .'" <'.S
::v('forlife').'@polytechnique.org>');
527 $mailer->setSubject('['.$globals->asso('nom').'] Demande d\'inscription annulée');
528 $mailer->setTxtBody(Env
::v('motif'));
530 $page->kill("La demande de $prenom $nom a bien été refusée.");
532 $page->assign('show_form', true
);
533 $page->assign('prenom', $prenom);
534 $page->assign('nom', $nom);
535 $page->assign('promo', $promo);
536 $page->assign('uid', $uid);
544 $page->kill("Tu es déjà membre !");
548 if (Post
::has('inscrire')) {
549 $res = XDB
::query('SELECT IF(m.email IS NULL,
550 CONCAT(al.alias,"@polytechnique.org"),
552 FROM groupex.membres AS m
553 INNER JOIN aliases AS al ON (al.type = "a_vie"
555 WHERE perms="admin" AND m.asso_id = {?}',
556 $globals->asso('id'));
557 $emails = $res->fetchColumn();
558 $to = implode(',', $emails);
562 . "Ce message a été envoyé suite à la demande d'inscription de\n"
563 . S
::v('prenom').' '.S
::v('nom').' (X'.S
::v('promo').")\n"
564 . "Via le site www.polytechnique.net. Tu peux choisir de valider ou\n"
565 . "de refuser sa demande d'inscription depuis la page :\n"
567 "http://www.polytechnique.net/".$globals->asso("diminutif")."/subscribe/"
568 .S
::v('forlife')."\n"
570 . "En cas de problème, contacter l'équipe de Polytechnique.org\n"
571 . "à l'adresse : support@polytechnique.org\n";
574 $to = $globals->asso("mail").", support@polytechnique.org";
575 $append = "\n-- \nLe groupe ".$globals->asso("nom")
576 ." n'a pas d'administrateur, l'équipe de"
577 ." Polytechnique.org a été prévenue et va rapidement"
578 ." résoudre ce problème.\n";
581 $mailer = new PlMailer();
583 $mailer->setFrom('"'.S
::v('prenom').' '.S
::v('nom')
584 .'" <'.S
::v('forlife').'@polytechnique.org>');
585 $mailer->setSubject('['.$globals->asso('nom').'] Demande d\'inscription');
586 $mailer->setTxtBody(Post
::v('message').$append);
591 function handler_change_rights(&$page)
593 if (Env
::has('right') && (may_update() || S
::has('suid'))) {
594 switch (Env
::v('right')) {
596 XnetSession
::killSuid();
599 XnetSession
::doSelfSuid();
604 XnetSession
::doSelfSuid();
605 may_update(false
, true
);
609 XnetSession
::doSelfSuid();
610 may_update(false
, true
);
611 is_member(false
, true
);
615 http_redirect($_SERVER['HTTP_REFERER']);
618 function handler_admin_annuaire(&$page)
622 require_once dirname(__FILE__
) . '/xnetgrp/mail.inc.php';
623 $page->changeTpl('xnetgrp/annuaire-admin.tpl');
624 $mmlist = new MMList(S
::v('uid'), S
::v('password'),
625 $globals->asso('mail_domain'));
626 $lists = $mmlist->get_lists();
627 if (!$lists) $lists = array();
628 $listes = array_map(create_function('$arr', 'return $arr["list"];'), $lists);
630 $subscribers = array();
632 foreach ($listes as $list) {
633 list(,$members) = $mmlist->get_members($list);
634 $mails = array_map(create_function('$arr', 'return $arr[1];'), $members);
635 $subscribers = array_unique(array_merge($subscribers, $mails));
638 $not_in_group_x = array();
639 $not_in_group_ext = array();
641 foreach ($subscribers as $mail) {
644 FROM groupex.membres AS m
645 LEFT JOIN auth_user_md5 AS u ON (m.uid=u.user_id AND m.uid<50000)
646 LEFT JOIN aliases AS a ON (a.id=u.user_id and a.type="a_vie")
647 WHERE asso_id = {?} AND
648 (m.email = {?} OR CONCAT(a.alias, "@polytechnique.org") = {?})',
649 $globals->asso('id'), $mail, $mail);
650 if ($res->fetchOneCell() == 0) {
651 if (strstr($mail, '@polytechnique.org') === false
) {
652 $not_in_group_ext[] = $mail;
654 $not_in_group_x[] = $mail;
659 $page->assign('not_in_group_ext', $not_in_group_ext);
660 $page->assign('not_in_group_x', $not_in_group_x);
661 $page->assign('lists', $lists);
664 function handler_admin_member_new(&$page, $email = null
)
668 $page->changeTpl('xnetgrp/membres-add.tpl');
669 $page->addJsLink('ajax.js');
671 if (is_null($email)) {
675 if (strpos($email, '@') === false
) {
678 list(,$fqdn) = explode('@', $email, 2);
679 $fqdn = strtolower($fqdn);
680 $x = ($fqdn == 'polytechnique.org' ||
$fqdn == 'melix.org' ||
681 $fqdn == 'm4x.org' ||
$fqdn == 'melix.net');
684 require_once 'user.func.inc.php';
685 if ($forlife = get_user_forlife($email)) {
687 'INSERT INTO groupex.membres (uid,asso_id,origine)
688 SELECT user_id,{?},"X"
689 FROM auth_user_md5 AS u
690 INNER JOIN aliases AS a ON (u.user_id = a.id)
691 WHERE a.alias={?}', $globals->asso('id'), $forlife);
692 pl_redirect("member/$forlife");
694 $page->trig($email." n'est pas un alias polytechnique.org valide.");
697 require_once 'xorg.misc.inc.php';
698 if (isvalid_email($email)) {
699 if (Env
::v('x') && Env
::has('userid') && Env
::i('userid')) {
700 $uid = Env
::i('userid');
701 $res = XDB
::query("SELECT *
703 WHERE user_id = {?} AND perms = 'pending'", $uid);
704 if ($res->numRows() == 1) {
705 if (Env
::v('market')) {
706 $market = Marketing
::get($uid, $email);
708 $market = new Marketing($uid, $email, 'group', $globals->asso('nom'),
709 Env
::v('market_from'), S
::v('uid'));
713 XDB
::execute('INSERT INTO groupex.membres (uid, asso_id, origine, email)
714 VALUES ({?}, {?}, "X", {?})',
715 $uid, $globals->asso('id'), $email);
716 pl_redirect("member/$email");
718 $page->trig("Utilisateur invalide");
720 $res = XDB
::query('SELECT MAX(uid)+1 FROM groupex.membres');
721 $uid = max(intval($res->fetchOneCell()), 50001);
722 XDB
::execute('INSERT INTO groupex.membres (uid,asso_id,origine,email)
723 VALUES({?},{?},"ext",{?})', $uid,
724 $globals->asso('id'), $email);
725 pl_redirect("member/$email");
728 $page->trig("« <strong>$email</strong> » n'est pas une adresse mail valide.");
733 function handler_admin_member_new_ajax(&$page)
735 header('Content-Type: text/html; charset="UTF-8"');
736 $page->changeTpl('xnetgrp/membres-new-search.tpl', NO_SKIN
);
738 if (Env
::has('login')) {
739 require_once 'user.func.inc.php';
740 $res = get_not_registered_user(Env
::v('login'), true
);
743 list($nom, $prenom) = str_replace(array('-', ' ', "'"), '%', array(Env
::v('nom'), Env
::v('prenom')));
744 $where = "perms = 'pending'";
746 $where .= " AND nom LIKE '%$nom%'";
748 if (!empty($prenom)) {
749 $where .= " AND prenom LIKE '%$prenom%'";
751 if (preg_match('/^[0-9]{4}$/', Env
::v('promo'))) {
752 $where .= " AND promo = " . Env
::i('promo');
753 } elseif (preg_match('/^[0-9]{2}$/', Env
::v('promo'))) {
754 $where .= " AND MOD(promo, 100) = " . Env
::i('promo');
755 } elseif (Env
::has('promo')) {
758 $res = XDB
::iterator("SELECT user_id, nom, prenom, promo
762 if ($res && $res->total() < 30) {
763 $page->assign("choix", $res);
767 function unsubscribe(&$user)
769 global $globals, $page;
771 "DELETE FROM groupex.membres WHERE uid={?} AND asso_id={?}",
772 $user['uid'], $globals->asso('id'));
774 $user_same_email = get_infos($user['email']);
775 $domain = $globals->asso('mail_domain');
777 if (!$domain ||
(!empty($user_same_email) && $user_same_email['uid'] != $user['uid'])) {
781 $mmlist = new MMList(S
::v('uid'), S
::v('password'), $domain);
782 $listes = $mmlist->get_lists($user['email2']);
784 $may_update = may_update();
786 foreach ($listes as $liste) {
787 if ($liste['sub'] == 2) {
789 $mmlist->mass_unsubscribe($liste['list'], Array($user['email2']));
791 $mmlist->unsubscribe($liste['list']);
793 } elseif ($liste['sub']) {
794 $page->trig("{$user['prenom']} {$user['nom']} a une"
795 ." demande d'inscription en cours sur la"
796 ." liste {$liste['list']}@ !");
802 "DELETE FROM virtual_redirect
803 USING virtual_redirect
804 INNER JOIN virtual USING(vid)
805 WHERE redirect={?} AND alias LIKE {?}", $user['email'], '%@'.$domain);
809 function handler_unsubscribe(&$page)
811 $page->changeTpl('xnetgrp/membres-del.tpl');
812 $user = get_infos(S
::v('forlife'));
816 $page->assign('self', true
);
817 $page->assign('user', $user);
819 if (!Post
::has('confirm')) {
823 if ($this->unsubscribe($user)) {
824 $page->trig('Vous avez été désinscrit du groupe avec succès.');
826 $page->trig('Vous avez été désinscrit du groupe, mais des erreurs se sont produites lors des désinscriptions des alias et des mailing-lists.');
828 $page->assign('is_member', is_member(true
));
831 function handler_admin_member_del(&$page, $user = null
)
833 $page->changeTpl('xnetgrp/membres-del.tpl');
834 $user = get_infos($user);
838 $page->assign('user', $user);
840 if (!Post
::has('confirm')) {
844 if ($this->unsubscribe($user)) {
845 $page->trig("{$user['prenom']} {$user['nom']} a été désabonné du groupe !");
847 $page->trig("{$user['prenom']} {$user['nom']} a été désabonné du groupe, mais des erreurs subsistent !");
851 private function changeLogin(PlatalPage
&$page, array &$user, MMList
&$mmlist, $login)
853 require_once 'user.func.inc.php';
854 // Search the uid of the user...
855 $res = XDB
::query("SELECT f.id, f.alias
857 INNER JOIN aliases AS f ON (f.id = a.id AND f.type = 'a_vie')
858 WHERE a.alias = {?}",
860 if ($res->numRows() == 0) {
861 $x = get_not_registered_user($login);
863 $page->trig("Le login $login ne correspond à aucun X.");
865 } else if (count($x) > 1) {
866 $page->trig("Le login $login correspond a plusieurs camarades.");
869 $uid = $x[0]['user_id'];
872 list($uid, $login) = $res->fetchOneRow();
876 // Check if the user is already in the group
878 $res = XDB
::query("SELECT uid, email
880 WHERE uid = {?} AND asso_id = {?}",
881 $uid, $globals->asso('id'));
882 if ($res->numRows()) {
883 list($uid, $email) = $res->fetchOneRow();
884 XDB
::execute("DELETE FROM groupex.membres
888 $email = $user['email'];
889 XDB
::execute("UPDATE groupex.membres
890 SET uid = {?}, origine = 'X'
891 WHERE uid = {?} AND asso_id = {?}",
892 $uid, $user['uid'], $globals->asso('id'));
895 $email = $login . '@' . $globals->mail
->domain
;
898 // Update subscription to aliases
899 if ($email != $user['email']) {
900 XDB
::execute("UPDATE IGNORE virtual_redirect AS vr
901 INNER JOIN virtual AS v ON(vr.vid = v.vid AND SUBSTRING_INDEX(alias, '@', 2) = {?})
902 SET vr.redirect = {?}
903 WHERE vr.redirect = {?}",
904 $globals->asso('mail_domain'), $email, $user['email']);
905 XDB
::execute("DELETE vr.*
906 FROM virtual_redirect AS vr
907 INNER JOIN virtual AS v ON(vr.vid = v.vid AND SUBSTRING_INDEX(alias, '@', 2) = {?})
908 WHERE vr.redirect = {?}",
909 $globals->asso('mail_domain'), $user['email']);
910 foreach (Env
::v('ml1', array()) as $ml => $state) {
911 $mmlist->replace_email($ml, $user['email'], $email);
917 function handler_admin_member(&$page, $user)
921 $page->changeTpl('xnetgrp/membres-edit.tpl');
923 $user = get_infos($user);
928 $mmlist = new MMList(S
::v('uid'), S
::v('password'),
929 $globals->asso('mail_domain'));
931 if (Post
::has('change')) {
932 // Convert user status to X
933 if ($user['origine'] == 'ext' && trim(Post
::v('login_X'))) {
934 $forlife = $this->changeLogin($page, $user, $mmlist, trim(Post
::v('login_X')));
936 pl_redirect('member/' . $forlife);
941 $email_changed = ($user['origine'] != 'X' && strtolower($user['email']) != strtolower(Post
::v('email')));
942 $from_email = $user['email'];
943 if ($user['origine'] != 'X') {
944 $user['nom'] = Post
::v('nom');
945 $user['prenom'] = (Post
::v('origine') == 'ext') ? Post
::v('prenom') : '';
946 $user['sexe'] = (Post
::v('origine') == 'ext') ? Post
::v('sexe') : 0;
947 $user['origine'] = Post
::v('origine');
948 XDB
::query('UPDATE groupex.membres
949 SET prenom={?}, nom={?}, email={?}, sexe={?}, origine={?}
950 WHERE uid={?} AND asso_id={?}',
951 $user['prenom'], $user['nom'], Post
::v('email'),
952 $user['sexe'], $user['origine'], $user['uid'],
953 $globals->asso('id'));
954 $user['email'] = Post
::v('email');
955 $user['email2'] = Post
::v('email');
958 $perms = Post
::i('is_admin');
959 if ($user['perms'] != $perms) {
960 XDB
::query('UPDATE groupex.membres SET perms={?}
961 WHERE uid={?} AND asso_id={?}',
962 $perms ?
'admin' : 'membre',
963 $user['uid'], $globals->asso('id'));
964 $user['perms'] = $perms;
965 $page->trig('Permissions modifiées !');
968 // Update ML subscriptions
969 foreach (Env
::v('ml1', array()) as $ml => $state) {
970 $ask = empty($_REQUEST['ml2'][$ml]) ?
0 : 2;
971 if ($ask == $state) {
972 if ($state && $email_changed) {
973 $mmlist->replace_email($ml, $from_email, $user['email2']);
974 $page->trig("L'abonnement de {$user['prenom']} {$user['nom']} à $ml@ a été mis à jour.");
979 $page->trig("{$user['prenom']} {$user['nom']} a "
980 ."actuellement une demande d'inscription en "
981 ."cours sur <strong>$ml@</strong> !!!");
983 $mmlist->mass_subscribe($ml, Array($user['email2']));
984 $page->trig("{$user['prenom']} {$user['nom']} a été abonné à $ml@.");
986 if ($email_changed) {
987 $mmlist->mass_unsubscribe($ml, Array($from_email));
989 $mmlist->mass_unsubscribe($ml, Array($user['email2']));
991 $page->trig("{$user['prenom']} {$user['nom']} a été désabonné de $ml@.");
995 // Change subscriptioin to aliases
996 foreach (Env
::v('ml3', array()) as $ml => $state) {
997 $ask = !empty($_REQUEST['ml4'][$ml]);
998 if($state == $ask) continue;
1000 XDB
::query("INSERT INTO virtual_redirect (vid,redirect)
1001 SELECT vid,{?} FROM virtual WHERE alias={?}",
1002 $user['email'], $ml);
1003 $page->trig("{$user['prenom']} {$user['nom']} a été abonné à $ml.");
1005 XDB
::query("DELETE FROM virtual_redirect
1006 USING virtual_redirect
1007 INNER JOIN virtual USING(vid)
1008 WHERE redirect={?} AND alias={?}",
1009 $user['email'], $ml);
1010 $page->trig("{$user['prenom']} {$user['nom']} a été désabonné de $ml.");
1015 $page->assign('user', $user);
1016 $listes = $mmlist->get_lists($user['email2']);
1017 $page->assign('listes', $listes);
1020 'SELECT alias, redirect IS NOT NULL as sub
1022 LEFT JOIN virtual_redirect AS vr ON(v.vid=vr.vid AND redirect={?})
1023 WHERE alias LIKE {?} AND type="user"',
1024 $user['email'], '%@'.$globals->asso('mail_domain'));
1025 $page->assign('alias', $res->fetchAllAssoc());
1028 function handler_rss(&$page, $user = null
, $hash = null
)
1031 require_once('rss.inc.php');
1032 $uid = init_rss('xnetgrp/announce-rss.tpl', $user, $hash, false
);
1035 $rss = XDB
::iterator("SELECT a.id, a.titre, a.texte, a.contacts, a.create_date,
1036 IF(u2.nom_usage != '', u2.nom_usage, u2.nom) AS nom, u2.prenom, u2.promo,
1037 FIND_IN_SET('photo', a.flags) AS photo
1038 FROM auth_user_md5 AS u
1039 INNER JOIN groupex.announces AS a ON ( (a.promo_min = 0 OR a.promo_min <= u.promo)
1040 AND (a.promo_max = 0 OR a.promo_max <= u.promo))
1041 INNER JOIN auth_user_md5 AS u2 ON (u2.user_id = a.user_id)
1042 WHERE u.user_id = {?} AND peremption >= NOW() AND a.asso_id = {?}",
1043 $uid, $globals->asso('id'));
1045 $rss = XDB
::iterator("SELECT a.id, a.titre, a.texte, a.create_date,
1046 IF(u.nom_usage != '', u.nom_usage, u.nom) AS nom, u.prenom, u.promo
1047 FROM groupex.announces AS a
1048 INNER JOIN auth_user_md5 AS u USING(user_id)
1049 WHERE FIND_IN_SET('public', a.flags) AND peremption >= NOW() AND a.asso_id = {?}",
1050 $globals->asso('id'));
1052 $page->assign('asso', $globals->asso());
1053 $page->assign('rss', $rss);
1056 private function upload_image(PlatalPage
&$page, PlUpload
&$upload)
1058 if (@!$_FILES['image']['tmp_name'] && !Env
::v('image_url')) {
1061 if (!$upload->upload($_FILES['image']) && !$upload->download(Env
::v('image_url'))) {
1062 $page->trig('Impossible de télécharger l\'image');
1064 } elseif (!$upload->isType('image')) {
1065 $page->trig('Le fichier n\'est pas une image valide au format JPEG, GIF ou PNG.');
1068 } elseif (!$upload->resizeImage(200, 300, 100, 100, 32284)) {
1069 $page->trig('Impossible de retraiter l\'image');
1075 function handler_photo_announce(&$page, $eid = null
) {
1077 $res = XDB
::query("SELECT * FROM groupex.announces_photo WHERE eid = {?}", $eid);
1078 if ($res->numRows()) {
1079 $photo = $res->fetchOneAssoc();
1080 header('Content-Type: image/' . $photo['attachmime']);
1081 echo $photo['attach'];
1085 $upload = new PlUpload(S
::v('forlife'), 'xnetannounce');
1086 if ($upload->exists() && $upload->isType('image')) {
1087 header('Content-Type: ' . $upload->contentType());
1088 echo $upload->getContents();
1093 header('Content-Type: image/png');
1094 echo file_get_contents($globals->spoolroot
. '/htdocs/images/logo.png');
1098 function handler_edit_announce(&$page, $aid = null
)
1100 global $globals, $platal;
1101 $page->changeTpl('xnetgrp/announce-edit.tpl');
1102 $page->assign('new', is_null($aid));
1105 if (Post
::v('valid') == 'Visualiser' || Post
::v('valid') == 'Enregistrer'
1106 || Post
::v('valid') == 'Supprimer l\'image' || Post
::v('valid') == 'Pas d\'image') {
1107 if (!is_null($aid)) {
1110 $art['titre'] = Post
::v('titre');
1111 $art['texte'] = Post
::v('texte');
1112 $art['contacts'] = Post
::v('contacts');
1113 $art['promo_min'] = Post
::i('promo_min');
1114 $art['promo_max'] = Post
::i('promo_max');
1115 $art['nom'] = S
::v('nom');
1116 $art['prenom'] = S
::v('prenom');
1117 $art['promo'] = S
::v('promo');
1118 $art['forlife'] = S
::v('forlife');
1119 $art['peremption'] = Post
::v('peremption');
1120 $art['public'] = Post
::has('public');
1121 $art['xorg'] = Post
::has('xorg');
1122 $art['nl'] = Post
::has('nl');
1123 $art['event'] = Post
::v('event');
1124 $upload = new PlUpload(S
::v('forlife'), 'xnetannounce');
1125 $this->upload_image($page, $upload);
1127 $art['contact_html'] = $art['contacts'];
1128 if ($art['event']) {
1129 $art['contact_html'] .= "\n{$globals->baseurl}/{$platal->ns}events/sub/{$art['event']}";
1132 if (!$art['public'] &&
1133 (($art['promo_min'] > $art['promo_max'] && $art['promo_max'] != 0) ||
1134 ($art['promo_min'] != 0 && ($art['promo_min'] <= 1900 ||
$art['promo_min'] >= 2020)) ||
1135 ($art['promo_max'] != 0 && ($art['promo_max'] <= 1900 ||
$art['promo_max'] >= 2020))))
1137 $page->trig("L'intervalle de promotions est invalide.");
1138 Post
::kill('valid');
1141 if (!trim($art['titre']) ||
!trim($art['texte'])) {
1142 $page->trig("L'article doit avoir un titre et un contenu.");
1143 Post
::kill('valid');
1146 if (Post
::v('valid') == 'Supprimer l\'image') {
1148 Post
::kill('valid');
1150 $art['photo'] = $upload->exists() || Post
::i('photo');
1151 if (Post
::v('valid') == 'Pas d\'image' && !is_null($aid)) {
1152 XDB
::query("DELETE FROM groupex.announces_photo WHERE eid = {?}", $aid);
1154 Post
::kill('valid');
1155 $art['photo'] = false
;
1159 if (Post
::v('valid') == 'Enregistrer') {
1160 $promo_min = ($art['public'] ?
0 : $art['promo_min']);
1161 $promo_max = ($art['public'] ?
0 : $art['promo_max']);
1163 if ($art['public']) {
1164 $flags[] = 'public';
1166 if ($art['photo']) {
1169 $flags = implode(',', $flags);
1170 if (is_null($aid)) {
1171 $fulltext = $art['texte'];
1172 if (!empty($art['contact_html'])) {
1173 $fulltext .= "\n\n'''Contacts :'''\\\\\n" . $art['contact_html'];
1176 if ($globals->asso('forum')) {
1177 require_once 'banana/forum.inc.php';
1178 $banana = new ForumsBanana(S::v('forlife'));
1179 $post = $banana->post($globals->asso('forum'), null,
1180 $art['titre'], MiniWiki::wikiToText($fulltext, false, 0, 80));
1182 XDB
::query("INSERT INTO groupex.announces
1183 (user_id, asso_id, create_date, titre, texte, contacts,
1184 peremption, promo_min, promo_max, flags, post_id)
1185 VALUES ({?}, {?}, NOW(), {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})",
1186 S
::i('uid'), $globals->asso('id'), $art['titre'], $art['texte'], $art['contact_html'],
1187 $art['peremption'], $promo_min, $promo_max, $flags, $post);
1188 $aid = XDB
::insertId();
1189 if ($art['photo']) {
1190 list($imgx, $imgy, $imgtype) = $upload->imageInfo();
1191 XDB
::execute("INSERT INTO groupex.announces_photo
1192 SET eid = {?}, attachmime = {?}, x = {?}, y = {?}, attach = {?}",
1193 $aid, $imgtype, $imgx, $imgy, $upload->getContents());
1196 require_once('validations.inc.php');
1197 $article = new EvtReq("[{$globals->asso('nom')}] " . $art['titre'], $fulltext,
1198 $art['promo_min'], $art['promo_max'], $art['peremption'], "", S
::v('uid'),
1201 $page->trig("L'affichage sur la page d'accueil de Polytechnique.org est en attente de validation.");
1202 } else if ($upload && $upload->exists()) {
1206 require_once('validations.inc.php');
1207 $article = new NLReq(S
::v('uid'), $globals->asso('nom') . " : " .$art['titre'],
1208 $art['texte'], $art['contact_html']);
1210 $page->trig("La parution dans la Lettre Mensuelle est en attente de validation.");
1213 XDB
::query("UPDATE groupex.announces
1214 SET titre={?}, texte={?}, contacts={?}, peremption={?},
1215 promo_min={?}, promo_max={?}, flags={?}
1216 WHERE id={?} AND asso_id={?}",
1217 $art['titre'], $art['texte'], $art['contacts'], $art['peremption'],
1218 $promo_min, $promo_max, $flags,
1219 $art['id'], $globals->asso('id'));
1220 if ($art['photo'] && $upload->exists()) {
1221 list($imgx, $imgy, $imgtype) = $upload->imageInfo();
1222 XDB
::execute("REPLACE INTO groupex.announces_photo
1223 SET eid = {?}, attachmime = {?}, x = {?}, y = {?}, attach = {?}",
1224 $aid, $imgtype, $imgx, $imgy, $upload->getContents());
1229 if (Post
::v('valid') == 'Enregistrer' || Post
::v('valid') == 'Annuler') {
1233 if (empty($art) && !is_null($aid)) {
1234 $res = XDB
::query("SELECT a.*, u.nom, u.prenom, u.promo, l.alias AS forlife,
1235 FIND_IN_SET('public', a.flags) AS public,
1236 FIND_IN_SET('photo', a.flags) AS photo
1237 FROM groupex.announces AS a
1238 INNER JOIN auth_user_md5 AS u USING(user_id)
1239 INNER JOIN aliases AS l ON (l.id = u.user_id AND l.type = 'a_vie')
1240 WHERE asso_id = {?} AND a.id = {?}",
1241 $globals->asso('id'), $aid);
1242 if ($res->numRows()) {
1243 $art = $res->fetchOneAssoc();
1244 $art['contact_html'] = $art['contacts'];
1246 $page->kill("Aucun article correspond à l'identifiant indiqué.");
1250 if (is_null($aid)) {
1251 $events = XDB
::iterator("SELECT *
1252 FROM groupex.evenements
1253 WHERE asso_id = {?} AND archive = 0",
1254 $globals->asso('id'));
1255 if ($events->total()) {
1256 $page->assign('events', $events);
1260 $art['contact_html'] = @MiniWiki
::WikiToHTML($art['contact_html']);
1261 $page->assign('art', $art);
1262 $page->assign_by_ref('upload', $upload);
1265 function handler_admin_announce(&$page)
1268 $page->changeTpl('xnetgrp/announce-admin.tpl');
1270 if (Env
::has('del')) {
1271 XDB
::execute("DELETE FROM groupex.announces
1272 WHERE id = {?} AND asso_id = {?}",
1273 Env
::i('del'), $globals->asso('id'));
1275 $res = XDB
::iterator("SELECT a.id, a.titre, a.peremption, a.peremption < CURRENT_DATE() AS perime
1276 FROM groupex.announces AS a
1277 WHERE a.asso_id = {?}
1278 ORDER BY a.peremption DESC",
1279 $globals->asso('id'));
1280 $page->assign('articles', $res);
1284 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: