2 /***************************************************************************
3 * Copyright (C) 2003-2006 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(flags, 'femme') 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(u.flags, 'femme') 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 INNER 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/edit' => $this->make_hook('edit', AUTH_MDP
),
80 '%grp/mail' => $this->make_hook('mail', AUTH_MDP
),
81 '%grp/annuaire' => $this->make_hook('annuaire', AUTH_MDP
),
82 '%grp/annuaire/vcard' => $this->make_hook('vcard', AUTH_MDP
),
83 '%grp/trombi' => $this->make_hook('trombi', AUTH_MDP
),
84 '%grp/subscribe' => $this->make_hook('subscribe', AUTH_MDP
),
87 => $this->make_hook('admin_annuaire', AUTH_MDP
),
90 => $this->make_hook('admin_member', AUTH_MDP
),
92 => $this->make_hook('admin_member_new', AUTH_MDP
),
93 '%grp/member/new/ajax'
94 => $this->make_hook('admin_member_new_ajax', AUTH_MDP
, '', NO_AUTH
),
96 => $this->make_hook('admin_member_del', AUTH_MDP
),
98 '%grp/rss' => $this->make_hook('rss', AUTH_PUBLIC
),
99 '%grp/announce/new' => $this->make_hook('edit_announce', AUTH_MDP
),
100 '%grp/announce/edit' => $this->make_hook('edit_announce', AUTH_MDP
),
101 '%grp/admin/announces' => $this->make_hook('admin_announce', AUTH_MDP
),
105 function handler_index(&$page, $arg = null
)
107 global $globals, $platal;
109 if (!is_null($arg)) {
113 new_group_open_page('xnet/groupe/asso.tpl');
116 if (Env
::has('read')) {
117 XDB
::query('DELETE r.*
118 FROM groupex.announces_read AS r
119 INNER JOIN groupex.announces AS a ON a.id = r.announce_id
120 WHERE peremption < CURRENT_DATE()');
121 XDB
::query('INSERT INTO groupex.announces_read
123 Env
::i('read'), S
::i('uid'));
126 if (Env
::has('unread')) {
127 XDB
::query('DELETE FROM groupex.announces_read
128 WHERE announce_id={?} AND user_id={?}',
129 Env
::i('unread'), S
::i('uid'));
130 pl_redirect("#art" . Env
::i('unread'));
132 $arts = XDB
::iterator("SELECT a.*, u.nom, u.prenom, u.promo, l.alias AS forlife
133 FROM groupex.announces AS a
134 INNER JOIN auth_user_md5 AS u USING(user_id)
135 INNER JOIN aliases AS l ON (u.user_id = l.id AND l.type = 'a_vie')
136 LEFT JOIN groupex.announces_read AS r ON (r.user_id = {?} AND r.announce_id = a.id)
137 WHERE asso_id = {?} AND peremption >= CURRENT_DATE()
138 AND (promo_min = 0 OR promo_min <= {?})
139 AND (promo_max = 0 OR promo_max >= {?})
140 AND r.announce_id IS NULL
141 ORDER BY a.peremption",
142 S
::i('uid'), $globals->asso('id'), S
::i('promo'), S
::i('promo'));
143 $index = XDB
::iterator("SELECT a.id, a.titre, r.user_id IS NULL AS nonlu
144 FROM groupex.announces AS a
145 LEFT JOIN groupex.announces_read AS r ON (a.id = r.announce_id AND r.user_id = {?})
146 WHERE asso_id = {?} AND peremption >= CURRENT_DATE()
147 AND (promo_min = 0 OR promo_min <= {?})
148 AND (promo_max = 0 OR promo_max >= {?})
149 ORDER BY a.peremption",
150 S
::i('uid'), $globals->asso('id'), S
::i('promo'), S
::i('promo'));
151 $page->assign('article_index', $index);
153 $arts = XDB
::iterator("SELECT a.*, u.nom, u.prenom, u.promo
154 FROM groupex.announces AS a
155 INNER JOIN auth_user_md5 AS u USING(user_id)
156 WHERE asso_id = {?} AND peremption >= CURRENT_DATE()
157 AND FIND_IN_SET(a.flags, 'public')",
158 $globals->asso('id'));
161 if (!S
::has('core_rss_hash')) {
162 $page->setRssLink("Polytechnique.net :: {$globals->asso("nom
")} :: News publiques",
165 $page->setRssLink("Polytechnique.net :: {$globals->asso("nom
")} :: News",
166 'rss/'.S
::v('forlife') .'/'.S
::v('core_rss_hash').'/rss.xml');
169 require_once('url_catcher.inc.php');
170 $page->register_modifier('url_catcher', 'url_catcher');
171 $page->assign('articles', $arts);
173 $page->assign('asso', $globals->asso());
176 function handler_logo(&$page)
180 $res = XDB
::query("SELECT logo, logo_mime
181 FROM groupex.asso WHERE id = {?}",
182 $globals->asso('id'));
183 list($logo, $logo_mime) = $res->fetchOneRow();
186 header("Content-type: $mime");
187 header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
188 header('Last-Modified:' . gmdate('D, d M Y H:i:s') . ' GMT');
189 header('Cache-Control: no-cache, must-revalidate');
190 header('Pragma: no-cache');
193 header('Content-type: image/jpeg');
194 header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
195 header('Last-Modified:' . gmdate('D, d M Y H:i:s') . ' GMT');
196 header('Cache-Control: no-cache, must-revalidate');
197 header('Pragma: no-cache');
198 readfile(dirname(__FILE__
).'/../htdocs/images/dflt_carre.jpg');
204 function handler_edit(&$page)
208 new_groupadmin_page('xnet/groupe/edit.tpl');
210 if (Post
::has('submit')) {
211 if (S
::has_perms()) {
212 if (Post
::v('mail_domain') && (strstr(Post
::v('mail_domain'), '.') === false
)) {
213 $page->trig("le domaine doit être un FQDN (aucune modif effectuée) !!!");
218 SET nom={?}, diminutif={?}, cat={?}, dom={?},
219 descr={?}, site={?}, mail={?}, resp={?},
220 forum={?}, mail_domain={?}, ax={?}, pub={?},
221 sub_url={?}, inscriptible={?}
223 Post
::v('nom'), Post
::v('diminutif'),
224 Post
::v('cat'), Post
::i('dom'),
225 Post
::v('descr'), Post
::v('site'),
226 Post
::v('mail'), Post
::v('resp'),
227 Post
::v('forum'), Post
::v('mail_domain'),
228 Post
::has('ax'), Post
::has('pub')?
'private':'public',
229 Post
::v('sub_url'), Post
::v('inscriptible'),
230 $globals->asso('id'));
231 if (Post
::v('mail_domain')) {
232 XDB
::execute('INSERT INTO virtual_domains (domain) VALUES({?})',
233 Post
::v('mail_domain'));
238 SET descr={?}, site={?}, mail={?}, resp={?},
239 forum={?}, ax={?}, pub= {?}, sub_url={?}
241 Post
::v('descr'), Post
::v('site'),
242 Post
::v('mail'), Post
::v('resp'),
243 Post
::v('forum'), Post
::has('ax'),
244 Post
::has('pub')?
'private':'public',
245 Post
::v('sub_url'), $globals->asso('id'));
248 if ($_FILES['logo']['name']) {
249 $logo = file_get_contents($_FILES['logo']['tmp_name']);
250 $mime = $_FILES['logo']['type'];
251 XDB
::execute('UPDATE groupex.asso
252 SET logo={?}, logo_mime={?}
253 WHERE id={?}', $logo, $mime,
254 $globals->asso('id'));
257 pl_redirect('../'.Post
::v('diminutif', $globals->asso('diminutif')).'/edit');
260 if (S
::has_perms()) {
261 $dom = XDB
::iterator('SELECT * FROM groupex.dom ORDER BY nom');
262 $page->assign('dom', $dom);
263 $page->assign('super', true
);
267 function handler_mail(&$page)
271 new_groupadmin_page('xnet/groupe/mail.tpl');
272 $mmlist = new MMList(S
::v('uid'), S
::v('password'),
273 $globals->asso('mail_domain'));
274 $page->assign('listes', $mmlist->get_lists());
276 if (Post
::has('send')) {
277 $from = Post
::v('from');
278 $sujet = Post
::v('sujet');
279 $body = Post
::v('body');
281 $mls = array_keys(Env
::v('ml', array()));
283 require_once 'xnet/mail.inc.php';
284 $tos = get_all_redirects(Post
::has('membres'), $mls, $mmlist);
285 send_xnet_mails($from, $sujet, $body, $tos, Post
::v('replyto'));
286 $page->kill("Mail envoyé !");
287 $page->assign('sent', true
);
291 function handler_annuaire(&$page)
294 new_annu_page('xnet/groupe/annuaire.tpl');
296 $sort = Env
::v('order');
297 switch (Env
::v('order')) {
298 case 'promo' : $group = 'promo'; $tri = 'promo_o DESC, nom, prenom'; break;
299 case 'promo_inv': $group = 'promo'; $tri = 'promo_o, nom, prenom'; break;
300 case 'alpha_inv': $group = 'initiale'; $tri = 'nom DESC, prenom DESC, promo'; break;
301 default : $group = 'initiale'; $tri = 'nom, prenom, promo'; $sort = 'alpha';
303 $page->assign('sort', $sort);
305 if ($group == 'initiale')
307 'SELECT UPPER(SUBSTRING(
308 IF(m.origine="X", IF(u.nom_usage<>"", u.nom_usage, u.nom),m.nom),
309 1, 1)) as letter, COUNT(*)
310 FROM groupex.membres AS m
311 LEFT JOIN auth_user_md5 AS u ON ( u.user_id = m.uid )
314 ORDER BY letter', $globals->asso('id'));
317 'SELECT IF(m.origine="X",u.promo,"extérieur") AS promo,
318 COUNT(*), IF(m.origine="X",u.promo,"") AS promo_o
319 FROM groupex.membres AS m
320 LEFT JOIN auth_user_md5 AS u ON ( u.user_id = m.uid )
323 ORDER BY promo_o DESC', $globals->asso('id'));
327 while (list($char, $nb) = $res->next()) {
330 if (Env
::has($group) && $char == strtoupper(Env
::v($group))) {
334 $page->assign('group', $group);
335 $page->assign('request_group', Env
::v($group));
336 $page->assign('only_admin', Env
::has('admin'));
337 $page->assign('alphabet', $alphabet);
338 $page->assign('nb_tot', $nb_tot);
340 $ofs = Env
::i('offset');
341 $tot = Env
::v($group) ?
$tot : $nb_tot;
342 $nbp = intval(($tot-1)/NB_PER_PAGE
);
345 $links['précédent'] = $ofs-1;
347 for ($i = 0; $i <= $nbp; $i++
) {
348 $links[(string)($i+
1)] = $i;
351 $links['suivant'] = $ofs+
1;
353 if (count($links)>1) {
354 $page->assign('links', $links);
358 if (Env
::has('initiale')) {
359 $ini = 'AND IF(m.origine="X",
360 IF(u.nom_usage<>"", u.nom_usage, u.nom),
361 m.nom) LIKE "'.addslashes(Env
::v('initiale')).'%"';
362 } elseif (Env
::has('promo')) {
363 $ini = 'AND IF(m.origine="X", u.promo, "extérieur") = "'
364 .addslashes(Env
::v('promo')).'"';
365 } elseif (Env
::has('admin')) {
366 $ini = 'AND m.perms = "admin"';
369 $ann = XDB
::iterator(
370 "SELECT IF(m.origine='X',IF(u.nom_usage<>'', u.nom_usage, u.nom) ,m.nom) AS nom,
371 IF(m.origine='X',u.prenom,m.prenom) AS prenom,
372 IF(m.origine='X',u.promo,'extérieur') AS promo,
373 IF(m.origine='X',u.promo,'') AS promo_o,
374 IF(m.origine='X' AND u.perms != 'pending',a.alias,m.email) AS email,
375 IF(m.origine='X',FIND_IN_SET('femme', u.flags), m.sexe) AS femme,
376 m.perms='admin' AS admin,
378 u.perms!='pending' AS inscrit,
380 FROM groupex.membres AS m
381 LEFT JOIN auth_user_md5 AS u ON ( u.user_id = m.uid )
382 LEFT JOIN aliases AS a ON ( a.id = m.uid AND a.type='a_vie' )
383 WHERE m.asso_id = {?} $ini
384 AND (m.origine = 'ext' OR u.perms != 'pending' OR m.email IS NOT NULL)
386 LIMIT {?},{?}", $globals->asso('id'), $ofs*NB_PER_PAGE
, NB_PER_PAGE
);
387 $page->assign('ann', $ann);
390 function handler_trombi(&$page, $num = 1)
393 new_annu_page('xnet/groupe/trombi.tpl');
395 $page->assign('urlmainsite', "https://www.polytechnique.org/");
396 $trombi = new Trombi(array($this, '_trombi_getlist'));
397 $trombi->hidePromo();
399 $page->assign_by_ref('trombi', $trombi);
402 function _trombi_getlist($offset, $limit)
405 $where = "WHERE m.asso_id= '".addslashes($globals->asso('id'))."'";
409 FROM auth_user_md5 AS u
410 RIGHT JOIN photo AS p ON u.user_id=p.uid
411 INNER JOIN groupex.membres AS m ON (m.uid = u.user_id)
413 $pnb = $res->fetchOneCell();
415 $res = XDB
::query("SELECT promo, user_id, a.alias AS forlife,
416 IF (nom_usage='', u.nom, nom_usage) AS nom, u.prenom
418 INNER JOIN auth_user_md5 AS u ON u.user_id=p.uid
419 INNER JOIN aliases AS a ON ( u.user_id=a.id AND a.type='a_vie' )
420 INNER JOIN groupex.membres AS m ON (m.uid = u.user_id)
422 ORDER BY promo, u.nom, u.prenom LIMIT {?}, {?}", $offset*$limit, $limit);
424 return array($pnb, $res->fetchAllAssoc());
427 function handler_vcard(&$page, $photos = null
)
431 if (($globals->asso('pub') == 'public' && is_member()) ||
may_update()) {
432 $res = XDB
::query('SELECT uid
434 WHERE asso_id = {?}', $globals->asso('id'));
435 require_once('vcard.inc.php');
436 $vcard = new VCard($res->fetchColumn(), $photos == 'photos', 'Membre du groupe ' . $globals->asso('nom'));
437 $vcard->do_page($page);
439 return PL_NOTALLOWED
;
443 function handler_subscribe(&$page, $u = null
)
447 new_group_open_page('xnet/groupe/inscrire.tpl');
449 if (!$globals->asso('inscriptible'))
450 $page->kill("Il n'est pas possible de s'inscire en ligne à ce "
451 ."groupe. Essaie de joindre le contact indiqué "
452 ."sur la page de présentation.");
454 if (!is_null($u) && may_update()) {
455 $page->assign('u', $u);
456 $res = XDB
::query("SELECT nom, prenom, promo, user_id
457 FROM auth_user_md5 AS u
458 INNER JOIN aliases AS al ON (al.id = u.user_id
459 AND al.type != 'liste')
460 WHERE al.alias = {?}", $u);
462 if (list($nom, $prenom, $promo, $uid) = $res->fetchOneRow()) {
463 $res = XDB
::query("SELECT COUNT(*)
464 FROM groupex.membres AS m
465 INNER JOIN aliases AS a ON (m.uid = a.id
466 AND a.type != 'homonyme')
467 WHERE a.alias = {?} AND m.asso_id = {?}",
468 $u, $globals->asso('id'));
469 $n = $res->fetchOneCell();
471 $page->kill("$prenom $nom est déjà membre du groupe !");
474 elseif (Env
::has('accept'))
476 XDB
::execute("INSERT INTO groupex.membres
477 VALUES ({?}, {?}, 'membre', 'X', NULL, NULL, NULL, NULL, NULL)",
478 $globals->asso('id'), $uid);
479 require_once 'diogenes/diogenes.hermes.inc.php';
480 $mailer = new HermesMailer();
481 $mailer->addTo("$u@polytechnique.org");
482 $mailer->setFrom('"'.S
::v('prenom').' '.S
::v('nom')
483 .'" <'.S
::v('forlife').'@polytechnique.org>');
484 $mailer->setSubject('['.$globals->asso('nom').'] Demande d\'inscription');
485 $message = "Cher Camarade,\n"
487 . " Suite à ta demande d'adhésion à ".$globals->asso('nom').",\n"
488 . "j'ai le plaisir de t'annoncer que ton inscription a été validée !\n"
490 . "Bien cordialement,\n"
491 . "{$_SESSION["prenom
"]} {$_SESSION["nom
"]}.";
492 $mailer->setTxtBody($message);
494 $page->kill("$prenom $nom a bien été inscrit");
496 elseif (Env
::has('refuse'))
498 require_once 'diogenes/diogenes.hermes.inc.php';
499 $mailer = new HermesMailer();
500 $mailer->addTo("$u@polytechnique.org");
501 $mailer->setFrom('"'.S
::v('prenom').' '.S
::v('nom')
502 .'" <'.S
::v('forlife').'@polytechnique.org>');
503 $mailer->setSubject('['.$globals->asso('nom').'] Demande d\'inscription annulée');
504 $mailer->setTxtBody(Env
::v('motif'));
506 $page->kill("la demande $prenom $nom a bien été refusée");
508 $page->assign('show_form', true
);
509 $page->assign('prenom', $prenom);
510 $page->assign('nom', $nom);
511 $page->assign('promo', $promo);
512 $page->assign('uid', $uid);
520 $page->kill("tu es déjà membre !");
524 if (Post
::has('inscrire')) {
525 $res = XDB
::query('SELECT IF(m.email IS NULL,
526 CONCAT(al.alias,"@polytechnique.org"),
528 FROM groupex.membres AS m
529 INNER JOIN aliases AS al ON (al.type = "a_vie"
531 WHERE perms="admin" AND m.asso_id = {?}',
532 $globals->asso('id'));
533 $emails = $res->fetchColumn();
534 $to = implode(',', $emails);
538 . "Ce message a été envoyé suite à la demande d'inscription de\n"
539 . S
::v('prenom').' '.S
::v('nom').' (X'.S
::v('promo').")\n"
540 . "Via le site www.polytechnique.net. Tu peux choisir de valider ou\n"
541 . "de refuser sa demande d'inscription depuis la page :\n"
543 "http://www.polytechnique.net/".$globals->asso("diminutif")."/subscribe/"
544 .S
::v('forlife')."\n"
546 . "En cas de problème, contacter l'équipe de Polytechnique.org\n"
547 . "à l'adresse : support@polytechnique.org\n";
550 $to = $globals->asso("mail").", support@polytechnique.org";
551 $append = "\n-- \nLe groupe ".$globals->asso("nom")
552 ." n'a pas d'administrateur, l'équipe de"
553 ." Polytechnique.org a été prévenue et va rapidement"
554 ." résoudre ce problème.\n";
557 require_once 'diogenes/diogenes.hermes.inc.php';
558 $mailer = new HermesMailer();
560 $mailer->setFrom('"'.S
::v('prenom').' '.S
::v('nom')
561 .'" <'.S
::v('forlife').'@polytechnique.org>');
562 $mailer->setSubject('['.$globals->asso('nom').'] Demande d\'inscription');
563 $mailer->setTxtBody(Post
::v('message').$append);
568 function handler_admin_annuaire(&$page)
572 require_once 'xnet/mail.inc.php';
574 new_groupadmin_page('xnet/groupe/annuaire-admin.tpl');
575 $mmlist = new MMList(S
::v('uid'), S
::v('password'),
576 $globals->asso('mail_domain'));
577 $lists = $mmlist->get_lists();
578 if (!$lists) $lists = array();
579 $listes = array_map(create_function('$arr', 'return $arr["list"];'), $lists);
581 $subscribers = array();
583 foreach ($listes as $list) {
584 list(,$members) = $mmlist->get_members($list);
585 $mails = array_map(create_function('$arr', 'return $arr[1];'), $members);
586 $subscribers = array_unique(array_merge($subscribers, $mails));
589 $not_in_group_x = array();
590 $not_in_group_ext = array();
592 foreach ($subscribers as $mail) {
595 FROM groupex.membres AS m
596 LEFT JOIN auth_user_md5 AS u ON (m.uid=u.user_id AND m.uid<50000)
597 LEFT JOIN aliases AS a ON (a.id=u.user_id and a.type="a_vie")
598 WHERE asso_id = {?} AND
599 (m.email = {?} OR CONCAT(a.alias, "@polytechnique.org") = {?})',
600 $globals->asso('id'), $mail, $mail);
601 if ($res->fetchOneCell() == 0) {
602 if (strstr($mail, '@polytechnique.org') === false
) {
603 $not_in_group_ext[] = $mail;
605 $not_in_group_x[] = $mail;
610 $page->assign('not_in_group_ext', $not_in_group_ext);
611 $page->assign('not_in_group_x', $not_in_group_x);
612 $page->assign('lists', $lists);
615 function handler_admin_member_new(&$page, $email = null
)
619 new_groupadmin_page('xnet/groupe/membres-add.tpl');
620 $page->addJsLink('ajax.js');
622 if (is_null($email)) {
626 list(,$fqdn) = explode('@', $email);
627 $fqdn = strtolower($fqdn);
628 $x = ($fqdn == 'polytechnique.org' ||
$fqdn == 'melix.org' ||
629 $fqdn == 'm4x.org' ||
$fqdn == 'melix.net');
632 require_once 'user.func.inc.php';
633 if ($forlife = get_user_forlife($email)) {
635 'INSERT INTO groupex.membres (uid,asso_id,origine)
636 SELECT user_id,{?},"X"
637 FROM auth_user_md5 AS u
638 INNER JOIN aliases AS a ON (u.user_id = a.id)
639 WHERE a.alias={?}', $globals->asso('id'), $forlife);
640 pl_redirect("member/$email");
642 $page->trig($email." n'est pas un alias polytechnique.org valide");
645 if (isvalid_email($email)) {
646 if (Env
::v('x') && Env
::has('userid') && Env
::i('userid')) {
647 $uid = Env
::i('userid');
648 $res = XDB
::query("SELECT *
650 WHERE user_id = {?} AND perms = 'pending'", $uid);
651 if ($res->numRows() == 1) {
652 XDB
::execute('INSERT INTO groupex.membres (uid, asso_id, origine, email)
653 VALUES ({?}, {?}, "X", {?})',
654 $uid, $globals->asso('id'), $email);
655 if (Env
::v('market')) {
656 $res = XDB
::query('SELECT COUNT(*)
657 FROM register_marketing
658 WHERE uid={?} AND email={?}', $uid, $email);
659 if (!$res->fetchOneCell()) {
660 XDB
::execute("INSERT INTO register_marketing (uid,sender,email,date,last,nb,type,hash)
661 VALUES ({?}, {?}, {?}, NOW(), 0, 0, {?}, '')",
662 $uid, S
::v('uid'), $email, Env
::v('market_from'));
663 require_once('validations.inc.php');
664 $req = new MarkReq(S
::v('uid'), $uid, $email, Env
::v('market_from') == 'user');
668 pl_redirect("member/$email");
670 $page->trig("Utilisateur invalide");
672 $res = XDB
::query('SELECT MAX(uid)+1 FROM groupex.membres');
673 $uid = max(intval($res->fetchOneCell()), 50001);
674 XDB
::execute('INSERT INTO groupex.membres (uid,asso_id,origine,email)
675 VALUES({?},{?},"ext",{?})', $uid,
676 $globals->asso('id'), $email);
677 pl_redirect("member/$email");
680 $page->trig("« <strong>$email</strong> » n'est pas une adresse mail valide");
685 function handler_admin_member_new_ajax(&$page)
687 header('Content-Type: text/html; charset="iso-8859-15"');
688 $page->changeTpl('xnet/groupe/membres-new-search.tpl', NO_SKIN
);
689 list($nom, $prenom) = str_replace(array('-', ' ', "'"), '%', array(Env
::v('nom'), Env
::v('prenom')));
690 $where = "perms = 'pending'";
692 $where .= " AND nom LIKE '%$nom%'";
694 if (!empty($prenom)) {
695 $where .= " AND prenom LIKE '%$prenom%'";
697 if (preg_match('/^[0-9]{4}$/', Env
::v('promo'))) {
698 $where .= " AND promo = " . Env
::i('promo');
699 } elseif (Env
::has('promo')) {
702 $res = XDB
::iterator("SELECT user_id, nom, prenom, promo
705 if ($res->total() < 30) {
706 $page->assign("choix", $res);
710 function handler_admin_member_del(&$page, $user = null
)
714 new_groupadmin_page('xnet/groupe/membres-del.tpl');
715 $user = get_infos($user);
719 $page->assign('user', $user);
721 if (!Post
::has('confirm')) {
726 "DELETE FROM groupex.membres WHERE uid={?} AND asso_id={?}",
727 $user['uid'], $globals->asso('id'));
729 // don't unsubscribe email from list if other user use same email
730 $user_same_email = get_infos($user['email']);
732 if (($domain = $globals->asso('mail_domain')) && empty($user_same_email)) {
734 $mmlist = new MMList(S
::v('uid'), S
::v('password'), $domain);
735 $listes = $mmlist->get_lists($user['email2']);
737 foreach ($listes as $liste) {
738 if ($liste['sub'] == 2) {
739 $mmlist->mass_unsubscribe($liste['list'], Array($user['email2']));
740 $page->trig("{$user['prenom']} {$user['nom']} a été"
741 ." désinscrit de {$liste['list']}");
742 } elseif ($liste['sub']) {
743 $page->trig("{$user['prenom']} {$user['nom']} a une"
744 ." demande d'inscription en cours sur la"
745 ." liste {$liste['list']}@ !");
750 "DELETE FROM virtual_redirect
751 USING virtual_redirect
752 INNER JOIN virtual USING(vid)
753 WHERE redirect={?} AND alias LIKE {?}", $user['email'], '%@'.$domain);
754 if (mysql_affected_rows()) {
755 $page->trig("{$user['prenom']} {$user['nom']} a été désabonné des alias du groupe !");
759 $page->trig("{$user['prenom']} {$user['nom']} a été retiré du groupe !");
762 function handler_admin_member(&$page, $user)
766 new_groupadmin_page('xnet/groupe/membres-edit.tpl');
768 $user = get_infos($user);
773 $mmlist = new MMList(S
::v('uid'), S
::v('password'),
774 $globals->asso('mail_domain'));
776 if (Post
::has('change')) {
777 $email_changed = ($user['origine'] != 'X' && strtolower($user['email']) != strtolower(Post
::v('email')));
778 $from_email = $user['email'];
779 if ($user['origine'] != 'X') {
780 XDB
::query('UPDATE groupex.membres
781 SET prenom={?}, nom={?}, email={?}, sexe={?}
782 WHERE uid={?} AND asso_id={?}',
783 Post
::v('prenom'), Post
::v('nom'),
784 Post
::v('email'), Post
::v('sexe'),
785 $user['uid'], $globals->asso('id'));
786 $user['nom'] = Post
::v('nom');
787 $user['prenom'] = Post
::v('prenom');
788 $user['sexe'] = Post
::v('sexe');
789 $user['email'] = Post
::v('email');
790 $user['email2'] = Post
::v('email');
793 $perms = Post
::i('is_admin');
794 if ($user['perms'] != $perms) {
795 XDB
::query('UPDATE groupex.membres SET perms={?}
796 WHERE uid={?} AND asso_id={?}',
797 $perms ?
'admin' : 'membre',
798 $user['uid'], $globals->asso('id'));
799 $user['perms'] = $perms;
800 $page->trig('permissions modifiées');
803 foreach (Env
::v('ml1', array()) as $ml => $state) {
804 $ask = empty($_REQUEST['ml2'][$ml]) ?
0 : 2;
805 if ($ask == $state) {
807 $mmlist->replace_email($ml, $from_email, $user['email2']);
808 $page->trig("L'abonnement de {$user['prenom']} {$user['nom']} à $ml@ a été mis à jour");
813 $page->trig("{$user['prenom']} {$user['nom']} a "
814 ."actuellement une demande d'inscription en "
815 ."cours sur <strong>$ml@</strong> !!!");
817 $mmlist->mass_subscribe($ml, Array($user['email2']));
818 $page->trig("{$user['prenom']} {$user['nom']} a été abonné à $ml@");
820 if ($email_changed) {
821 $mmlist->mass_unsubscribe($ml, Array($from_email));
823 $mmlist->mass_unsubscribe($ml, Array($user['email2']));
825 $page->trig("{$user['prenom']} {$user['nom']} a été désabonné de $ml@");
829 foreach (Env
::v('ml3', array()) as $ml => $state) {
830 $ask = !empty($_REQUEST['ml4'][$ml]);
831 if($state == $ask) continue;
833 XDB
::query("INSERT INTO virtual_redirect (vid,redirect)
834 SELECT vid,{?} FROM virtual WHERE alias={?}",
835 $user['email'], $ml);
836 $page->trig("{$user['prenom']} {$user['nom']} a été abonné à $ml");
838 XDB
::query("DELETE FROM virtual_redirect
839 USING virtual_redirect
840 INNER JOIN virtual USING(vid)
841 WHERE redirect={?} AND alias={?}",
842 $user['email'], $ml);
843 $page->trig("{$user['prenom']} {$user['nom']} a été désabonné de $ml");
848 $page->assign('user', $user);
849 $listes = $mmlist->get_lists($user['email2']);
850 $page->assign('listes', $listes);
853 'SELECT alias, redirect IS NOT NULL as sub
855 LEFT JOIN virtual_redirect AS vr ON(v.vid=vr.vid AND redirect={?})
856 WHERE alias LIKE {?} AND type="user"',
857 $user['email'], '%@'.$globals->asso('mail_domain'));
858 $page->assign('alias', $res->fetchAllAssoc());
861 function handler_rss(&$page, $user = null
, $hash = null
)
864 require_once('rss.inc.php');
865 require_once('url_catcher.inc.php');
866 $uid = init_rss('xnet/groupe/announce-rss.tpl', $user, $hash, false
);
867 $page->register_modifier('url_catcher', 'url_catcher');
870 $rss = XDB
::iterator("SELECT a.id, a.titre, a.texte, a.contacts, a.create_date,
871 IF(u2.nom_usage != '', u2.nom_usage, u2.nom) AS nom, u2.prenom, u2.promo
872 FROM auth_user_md5 AS u
873 INNER JOIN groupex.announces AS a ON ( (a.promo_min = 0 OR a.promo_min <= u.promo)
874 AND (a.promo_max = 0 OR a.promo_max <= u.promo))
875 INNER JOIN auth_user_md5 AS u2 ON (u2.user_id = a.user_id)
876 WHERE u.user_id = {?} AND peremption >= NOW() AND a.asso_id = {?}",
877 $uid, $globals->asso('id'));
879 $rss = XDB
::iterator("SELECT a.id, a.titre, a.texte, a.create_date,
880 IF(u.nom_usage != '', u.nom_usage, u.nom) AS nom, u.prenom, u.promo
881 FROM groupex.announces AS a
882 INNER JOIN auth_user_md5 AS u USING(user_id)
883 WHERE FIND_IN_SET(a.flags, 'public') AND peremption >= NOW() AND a.asso_id = {?}",
884 $globals->asso('id'));
886 $page->assign('asso', $globals->asso());
887 $page->assign('rss', $rss);
890 function handler_edit_announce(&$page, $aid = null
)
892 global $globals, $platal;
893 new_groupadmin_page('xnet/groupe/announce-edit.tpl');
894 $page->assign('new', is_null($aid));
897 if (Post
::v('valid') == 'Visualiser' || Post
::v('valid') == 'Enregistrer') {
898 if (!is_null($aid)) {
901 $art['titre'] = Post
::v('titre');
902 $art['texte'] = Post
::v('texte');
903 $art['contacts'] = Post
::v('contacts');
904 $art['promo_min'] = Post
::i('promo_min');
905 $art['promo_max'] = Post
::i('promo_max');
906 $art['nom'] = S
::v('nom');
907 $art['prenom'] = S
::v('prenom');
908 $art['promo'] = S
::v('promo');
909 $art['forlife'] = S
::v('forlife');
910 $art['peremption'] = Post
::v('peremption');
911 $art['public'] = Post
::has('public');
912 $art['xorg'] = Post
::has('xorg');
913 $art['nl'] = Post
::has('nl');
914 $art['event'] = Post
::v('event');
916 $art['contact_html'] = $art['contacts'];
918 $art['contact_html'] .= "\n{$globals->baseurl}/{$platal->ns}events/sub/{$art['event']}";
921 if (!$art['public'] &&
922 ($art['promo_min'] > $art['promo_max'] ||
923 ($art['promo_min'] != 0 && ($art['promo_min'] <= 1900 ||
$art['promo_min'] >= 2020)) ||
924 ($art['promo_max'] != 0 && ($art['promo_max'] <= 1900 ||
$art['promo_max'] >= 2020))))
926 $page->trig("L'intervalle de promotions est invalide");
931 if (Post
::v('valid') == 'Enregistrer') {
932 $promo_min = ($art['public'] ?
0 : $art['promo_min']);
933 $promo_max = ($art['public'] ?
0 : $art['promo_max']);
935 XDB
::query("INSERT INTO groupex.announces
936 (user_id, asso_id, create_date, titre, texte, contacts,
937 peremption, promo_min, promo_max, flags)
938 VALUES ({?}, {?}, NOW(), {?}, {?}, {?}, {?}, {?}, {?}, {?})",
939 S
::i('uid'), $globals->asso('id'), $art['titre'], $art['texte'], $art['contact_html'],
940 $art['peremption'], $promo_min, $promo_max, $art['public'] ?
'public' : '');
941 $aid = XDB
::insertId();
943 require_once('validations.inc.php');
944 require_once('url_catcher.inc.php');
945 $article = new EvtReq("[{$globals->asso('nom')}] " . $art['titre'],
946 url_catcher($art['texte'] . (!empty($art['contact_html']) ?
"\n\nContacts :\n" . $art['contact_html'] : "")),
947 $art['promo_min'], $art['promo_max'], $art['peremption'], "", S
::v('uid'));
949 $page->trig("L'affichage sur la page d'accueil de Polytechnique.org est en attente de validation");
952 require_once('validations.inc.php');
953 $article = new NLReq(S
::v('uid'), $globals->asso('nom') . " : " .$art['titre'],
954 $art['texte'], $art['contact_html']);
956 $page->trig("La parution dans la Lettre Mensuelle est en attente de validation");
959 XDB
::query("UPDATE groupex.announces
960 SET titre={?}, texte={?}, contacts={?}, peremption={?},
961 promo_min={?}, promo_max={?}, flags={?}
962 WHERE id={?} AND asso_id={?}",
963 $art['titre'], $art['texte'], $art['contacts'], $art['peremption'],
964 $promo_min, $promo_max, $art['public'] ?
'public' : '',
965 $art['id'], $globals->asso('id'));
968 if (Post
::v('valid') == 'Enregistrer' || Post
::v('valid') == 'Annuler') {
972 if (empty($art) && !is_null($aid)) {
973 $res = XDB
::query("SELECT a.*, u.nom, u.prenom, u.promo, l.alias AS forlife,
974 FIND_IN_SET(a.flags, 'public') AS public
975 FROM groupex.announces AS a
976 INNER JOIN auth_user_md5 AS u USING(user_id)
977 INNER JOIN aliases AS l ON (l.id = u.user_id AND l.type = 'a_vie')
978 WHERE asso_id = {?} AND a.id = {?}",
979 $globals->asso('id'), $aid);
980 if ($res->numRows()) {
981 $art = $res->fetchOneAssoc();
982 $art['contact_html'] = $art['contacts'];
984 $page->kill("Aucun article correspond à l'identifiant indiqué");
989 for ($i = 1 ; $i < 30 ; $i++
) {
990 $time = time() +
3600 * 24 * $i;
991 $p_stamp = date('Ymd', $time);
992 $year = date('Y', $time);
993 $month = date('m', $time);
994 $day = date('d', $time);
996 $select .= "<option value=\"$p_stamp\"";
997 if ($p_stamp == strtr(@$art['peremption'], array("-" => ""))) {
998 $select .= " selected='selected'";
1000 $select .= "> $day / $month / $year</option>\n";
1002 $page->assign('select', $select);
1004 if (is_null($aid)) {
1005 $events = XDB
::iterator("SELECT *
1006 FROM groupex.evenements
1007 WHERE asso_id = {?} AND archive = 0",
1008 $globals->asso('id'));
1009 if ($events->total()) {
1010 $page->assign('events', $events);
1014 require_once('url_catcher.inc.php');
1015 $art['contact_html'] = url_catcher($art['contact_html']);
1016 $page->assign('art', $art);
1019 function handler_admin_announce(&$page)
1022 new_groupadmin_page('xnet/groupe/announce-admin.tpl');
1024 if (Env
::has('del')) {
1025 XDB
::execute("DELETE FROM groupex.announces
1026 WHERE id = {?} AND asso_id = {?}",
1027 Env
::i('del'), $globals->asso('id'));
1029 $res = XDB
::iterator("SELECT a.id, a.titre, a.peremption, a.peremption < CURRENT_DATE() AS perime
1030 FROM groupex.announces AS a
1031 WHERE a.asso_id = {?}
1032 ORDER BY a.peremption DESC",
1033 $globals->asso('id'));
1034 $page->assign('articles', $res);