X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=modules%2Fxnetgrp.php;h=bfdea5edef8fc476d21c4537fa982ff318d52f05;hb=2d8779e2808c8071eaea64420f553812e992bdce;hp=d4a961217397c8855480570f8aa6f2c0fae7a612;hpb=02fdd1c889526931990ed2f1cae1fc9a8b2d9459;p=platal.git
diff --git a/modules/xnetgrp.php b/modules/xnetgrp.php
index d4a9612..bfdea5e 100644
--- a/modules/xnetgrp.php
+++ b/modules/xnetgrp.php
@@ -1,6 +1,6 @@
asso('id'));
if ($res->numRows()) {
$user = $res->fetchOneAssoc();
if ($user['origine'] == 'X') {
- $res = XDB::query("SELECT nom, prenom, promo, FIND_IN_SET(flags, 'femme') AS sexe
+ $res = XDB::query("SELECT nom, prenom, promo, FIND_IN_SET('femme', flags) AS sexe
FROM auth_user_md5
WHERE user_id = {?}", $user['uid']);
$user = array_merge($user, $res->fetchOneAssoc());
}
- return $user;
+ return $user;
} elseif ($dom == 'polytechnique.org' || $dom == 'm4x.org') {
$res = XDB::query(
"SELECT user_id AS uid, u.promo,
@@ -54,12 +54,12 @@ function get_infos($email)
u.prenom, b.alias,
CONCAT(b.alias, '@m4x.org') AS email,
CONCAT(b.alias, '@polytechnique.org') AS email2,
- m.perms='admin' AS perms, m.origine,
- FIND_IN_SET(u.flags, 'femme') AS sexe
+ m.perms = 'admin' AS perms, m.origine, m.comm,
+ FIND_IN_SET('femme', u.flags) AS sexe
FROM auth_user_md5 AS u
INNER JOIN aliases AS a ON ( u.user_id = a.id AND a.type != 'homonyme' )
INNER JOIN aliases AS b ON ( u.user_id = b.id AND b.type = 'a_vie' )
- INNER JOIN groupex.membres AS m ON ( m.uid = u.user_id AND asso_id={?})
+ LEFT JOIN groupex.membres AS m ON ( m.uid = u.user_id AND asso_id={?})
WHERE a.alias = {?} AND u.user_id < 50000", $globals->asso('id'), $mbox);
return $res->fetchOneAssoc();
}
@@ -77,33 +77,37 @@ class XnetGrpModule extends PLModule
'%grp/asso.php' => $this->make_hook('index', AUTH_PUBLIC),
'%grp/logo' => $this->make_hook('logo', AUTH_PUBLIC),
'%grp/site' => $this->make_hook('site', AUTH_PUBLIC),
- '%grp/edit' => $this->make_hook('edit', AUTH_MDP),
- '%grp/mail' => $this->make_hook('mail', AUTH_MDP),
- '%grp/forum' => $this->make_hook('forum', AUTH_MDP),
- '%grp/annuaire' => $this->make_hook('annuaire', AUTH_MDP),
- '%grp/annuaire/vcard' => $this->make_hook('vcard', AUTH_MDP),
- '%grp/trombi' => $this->make_hook('trombi', AUTH_MDP),
+ '%grp/edit' => $this->make_hook('edit', AUTH_MDP, 'groupadmin'),
+ '%grp/mail' => $this->make_hook('mail', AUTH_MDP, 'groupadmin'),
+ '%grp/forum' => $this->make_hook('forum', AUTH_MDP, 'groupmember'),
+ '%grp/annuaire' => $this->make_hook('annuaire', AUTH_MDP, 'groupannu'),
+ '%grp/annuaire/vcard' => $this->make_hook('vcard', AUTH_MDP, 'groupmember:groupannu'),
+ '%grp/annuaire/csv' => $this->make_hook('csv', AUTH_MDP, 'groupmember:groupannu'),
+ '%grp/trombi' => $this->make_hook('trombi', AUTH_MDP, 'groupannu'),
+ '%grp/geoloc' => $this->make_hook('geoloc', AUTH_MDP, 'groupannu'),
'%grp/subscribe' => $this->make_hook('subscribe', AUTH_MDP),
- '%grp/unsubscribe' => $this->make_hook('unsubscribe', AUTH_MDP),
+ '%grp/subscribe/valid' => $this->make_hook('subscribe_valid', AUTH_MDP, 'groupadmin'),
+ '%grp/unsubscribe' => $this->make_hook('unsubscribe', AUTH_MDP, 'groupmember'),
'%grp/change_rights' => $this->make_hook('change_rights', AUTH_MDP),
'%grp/admin/annuaire'
- => $this->make_hook('admin_annuaire', AUTH_MDP),
+ => $this->make_hook('admin_annuaire', AUTH_MDP, 'groupadmin'),
'%grp/member'
- => $this->make_hook('admin_member', AUTH_MDP),
+ => $this->make_hook('admin_member', AUTH_MDP, 'groupadmin'),
'%grp/member/new'
- => $this->make_hook('admin_member_new', AUTH_MDP),
+ => $this->make_hook('admin_member_new', AUTH_MDP, 'groupadmin'),
'%grp/member/new/ajax'
- => $this->make_hook('admin_member_new_ajax', AUTH_MDP, 'user', NO_AUTH),
+ => $this->make_hook('admin_member_new_ajax', AUTH_MDP, 'user', NO_AUTH),
'%grp/member/del'
- => $this->make_hook('admin_member_del', AUTH_MDP),
+ => $this->make_hook('admin_member_del', AUTH_MDP, 'groupadmin'),
- '%grp/rss' => $this->make_hook('rss', AUTH_PUBLIC),
- '%grp/announce/new' => $this->make_hook('edit_announce', AUTH_MDP),
- '%grp/announce/edit' => $this->make_hook('edit_announce', AUTH_MDP),
- '%grp/admin/announces' => $this->make_hook('admin_announce', AUTH_MDP),
+ '%grp/rss' => $this->make_hook('rss', AUTH_PUBLIC, 'user', NO_HTTPS),
+ '%grp/announce/new' => $this->make_hook('edit_announce', AUTH_MDP, 'groupadmin'),
+ '%grp/announce/edit' => $this->make_hook('edit_announce', AUTH_MDP, 'groupadmin'),
+ '%grp/announce/photo' => $this->make_hook('photo_announce', AUTH_PUBLIC),
+ '%grp/admin/announces' => $this->make_hook('admin_announce', AUTH_MDP, 'groupadmin'),
);
}
@@ -114,15 +118,14 @@ class XnetGrpModule extends PLModule
if (!is_null($arg)) {
return PL_NOT_FOUND;
}
-
- new_group_open_page('xnetgrp/asso.tpl');
+ $page->changeTpl('xnetgrp/asso.tpl');
if (S::logged()) {
if (Env::has('read')) {
- XDB::query('DELETE r.*
+ XDB::query('DELETE groupex.r.*
FROM groupex.announces_read AS r
INNER JOIN groupex.announces AS a ON a.id = r.announce_id
- WHERE peremption < CURRENT_DATE()');
+ WHERE peremption < CURRENT_DATE()');
XDB::query('INSERT INTO groupex.announces_read
VALUES ({?}, {?})',
Env::i('read'), S::i('uid'));
@@ -134,10 +137,10 @@ class XnetGrpModule extends PLModule
Env::i('unread'), S::i('uid'));
pl_redirect("#art" . Env::i('unread'));
}
- $arts = XDB::iterator("SELECT a.*, u.nom, u.prenom, u.promo, l.alias AS forlife
+ $arts = XDB::iterator("SELECT a.*, u.nom, u.prenom, u.promo, u.hruid,
+ FIND_IN_SET('photo', a.flags) AS photo
FROM groupex.announces AS a
INNER JOIN auth_user_md5 AS u USING(user_id)
- INNER JOIN aliases AS l ON (u.user_id = l.id AND l.type = 'a_vie')
LEFT JOIN groupex.announces_read AS r ON (r.user_id = {?} AND r.announce_id = a.id)
WHERE asso_id = {?} AND peremption >= CURRENT_DATE()
AND (promo_min = 0 OR promo_min <= {?})
@@ -155,26 +158,30 @@ class XnetGrpModule extends PLModule
S::i('uid'), $globals->asso('id'), S::i('promo'), S::i('promo'));
$page->assign('article_index', $index);
} else {
- $arts = XDB::iterator("SELECT a.*, u.nom, u.prenom, u.promo
+ $arts = XDB::iterator("SELECT a.*, u.nom, u.prenom, u.promo, FIND_IN_SET('photo', a.flags) AS photo
FROM groupex.announces AS a
INNER JOIN auth_user_md5 AS u USING(user_id)
WHERE asso_id = {?} AND peremption >= CURRENT_DATE()
- AND FIND_IN_SET(a.flags, 'public')",
+ AND FIND_IN_SET('public', u.flags)",
$globals->asso('id'));
}
+ if (may_update()) {
+ $subs_valid = XDB::query("SELECT uid
+ FROM groupex.membres_sub_requests
+ WHERE asso_id = {?}",
+ $globals->asso('id'));
+ $page->assign('requests', $subs_valid->numRows());
+ }
if (!S::has('core_rss_hash')) {
$page->setRssLink("Polytechnique.net :: {$globals->asso("nom")} :: News publiques",
- "rss/rss.xml");
+ $platal->ns . "rss/rss.xml");
} else {
$page->setRssLink("Polytechnique.net :: {$globals->asso("nom")} :: News",
- 'rss/'.S::v('forlife') .'/'.S::v('core_rss_hash').'/rss.xml');
+ $platal->ns . 'rss/'.S::v('hruid') .'/'.S::v('core_rss_hash').'/rss.xml');
}
-
- $page->register_modifier('url_catcher', array(MiniWiki,'WikiToHTML'));
- $page->assign('articles', $arts);
- $page->assign('asso', $globals->asso());
+ $page->assign('articles', $arts);
}
function handler_logo(&$page)
@@ -210,7 +217,7 @@ class XnetGrpModule extends PLModule
global $globals;
$site = $globals->asso('site');
if (!$site) {
- $page->trig('Le groupe n\'a pas de site web');
+ $page->trigError('Le groupe n\'a pas de site web.');
return $this->handler_index($page);
}
http_redirect($site);
@@ -220,13 +227,27 @@ class XnetGrpModule extends PLModule
function handler_edit(&$page)
{
global $globals;
-
- new_groupadmin_page('xnetgrp/edit.tpl');
+ $page->changeTpl('xnetgrp/edit.tpl');
if (Post::has('submit')) {
+ S::assert_xsrf_token();
+
+ $flags = new PlFlagSet('wiki_desc');
+ if (Post::has('notif_unsub') && Post::i('notif_unsub') == 1) {
+ $flags->addFlag('notif_unsub');
+ }
+ $site = trim(Post::v('site'));
+ if ($site && ($site != "http://")) {
+ $scheme = parse_url($site, PHP_URL_SCHEME);
+ if (!$scheme) {
+ $site = "http://" . $site;
+ }
+ } else {
+ $site = "";
+ }
if (S::has_perms()) {
if (Post::v('mail_domain') && (strstr(Post::v('mail_domain'), '.') === false)) {
- $page->trig("le domaine doit être un FQDN (aucune modif effectuée) !!!");
+ $page->trigError("le domaine doit être un FQDN (aucune modif effectuée) !!!");
return;
}
XDB::execute(
@@ -234,18 +255,19 @@ class XnetGrpModule extends PLModule
SET nom={?}, diminutif={?}, cat={?}, dom={?},
descr={?}, site={?}, mail={?}, resp={?},
forum={?}, mail_domain={?}, ax={?}, pub={?},
- sub_url={?}, inscriptible={?}, unsub_url={?}
+ sub_url={?}, inscriptible={?}, unsub_url={?},
+ flags={?}
WHERE id={?}",
Post::v('nom'), Post::v('diminutif'),
Post::v('cat'), Post::i('dom'),
- Post::v('descr'), Post::v('site'),
+ Post::v('descr'), $site,
Post::v('mail'), Post::v('resp'),
Post::v('forum'), Post::v('mail_domain'),
- Post::has('ax'), Post::has('pub')?'private':'public',
+ Post::has('ax'), Post::v('pub'),
Post::v('sub_url'), Post::v('inscriptible'),
- Post::v('unsub_url'),$globals->asso('id'));
+ Post::v('unsub_url'), $flags, $globals->asso('id'));
if (Post::v('mail_domain')) {
- XDB::execute('INSERT INTO virtual_domains (domain) VALUES({?})',
+ XDB::execute('INSERT IGNORE INTO virtual_domains (domain) VALUES({?})',
Post::v('mail_domain'));
}
} else {
@@ -253,23 +275,23 @@ class XnetGrpModule extends PLModule
"UPDATE groupex.asso
SET descr={?}, site={?}, mail={?}, resp={?},
forum={?}, ax={?}, pub= {?}, sub_url={?},
- unsub_url={?}
+ unsub_url={?},flags={?}
WHERE id={?}",
- Post::v('descr'), Post::v('site'),
+ Post::v('descr'), $site,
Post::v('mail'), Post::v('resp'),
Post::v('forum'), Post::has('ax'),
- Post::has('pub')?'private':'public',
+ Post::v('pub'),
Post::v('sub_url'), Post::v('unsub_url'),
- $globals->asso('id'));
+ $flags, $globals->asso('id'));
}
if ($_FILES['logo']['name']) {
$logo = file_get_contents($_FILES['logo']['tmp_name']);
$mime = $_FILES['logo']['type'];
XDB::execute('UPDATE groupex.asso
- SET logo={?}, logo_mime={?}
- WHERE id={?}', $logo, $mime,
- $globals->asso('id'));
+ SET logo={?}, logo_mime={?}
+ WHERE id={?}', $logo, $mime,
+ $globals->asso('id'));
}
pl_redirect('../'.Post::v('diminutif', $globals->asso('diminutif')).'/edit');
@@ -280,18 +302,26 @@ class XnetGrpModule extends PLModule
$page->assign('dom', $dom);
$page->assign('super', true);
}
+ if (!$globals->asso('wiki_desc') && $globals->asso('descr')) {
+ $page->trigWarning("Attention, le format de la description a changé et utilise désormais la syntaxe wiki "
+ . "intégrée au site. Il te faudra probablement adapter le formatage du texte actuel pour "
+ . "qu'il s'affiche correctement avec cette nouvelle syntaxe.");
+ }
}
function handler_mail(&$page)
{
global $globals;
- new_groupadmin_page('xnetgrp/mail.tpl');
+ $page->changeTpl('xnetgrp/mail.tpl');
$mmlist = new MMList(S::v('uid'), S::v('password'),
$globals->asso('mail_domain'));
$page->assign('listes', $mmlist->get_lists());
+ $page->assign('user', S::user());
+ $page->addJsLink('ajax.js');
if (Post::has('send')) {
+ S::assert_xsrf_token();
$from = Post::v('from');
$sujet = Post::v('sujet');
$body = Post::v('body');
@@ -299,10 +329,15 @@ class XnetGrpModule extends PLModule
$mls = array_keys(Env::v('ml', array()));
$mbr = array_keys(Env::v('membres', array()));
- require_once dirname(__FILE__) . '/xnetgrp/mail.inc.php';
+ $this->load('mail.inc.php');
+ set_time_limit(120);
$tos = get_all_redirects($mbr, $mls, $mmlist);
- send_xnet_mails($from, $sujet, $body, $tos, Post::v('replyto'), $_FILES['uploaded']);
- $page->kill("Mail envoyé !");
+ $upload = PlUpload::get($_FILES['uploaded'], S::user()->login(), 'xnet.emails', true);
+ send_xnet_mails($from, $sujet, $body, Env::v('wiki'), $tos, Post::v('replyto'), $upload, @$_FILES['uploaded']['name']);
+ if ($upload) {
+ $upload->rm();
+ }
+ $page->kill("Email envoyé !");
$page->assign('sent', true);
}
}
@@ -310,7 +345,7 @@ class XnetGrpModule extends PLModule
function handler_forum(&$page, $group = null, $artid = null)
{
global $globals;
- new_group_page('xnetgrp/forum.tpl');
+ $page->changeTpl('xnetgrp/forum.tpl');
if (!$globals->asso('forum')) {
return PL_NOT_FOUND;
}
@@ -320,10 +355,23 @@ class XnetGrpModule extends PLModule
run_banana($page, 'ForumsBanana', $get);
}
- function handler_annuaire(&$page)
+ function handler_annuaire(&$page, $action = null, $subaction = null)
{
global $globals;
- new_annu_page('xnetgrp/annuaire.tpl');
+
+ if ($action == 'search') {
+ http_redirect("https://www.polytechnique.org/search/adv?rechercher=Chercher&groupex={$globals->asso('id')}"
+ . "&cityid=" . Env::v('cityid') . "&mapid=" . Env::v('mapid'));
+ } else if ($action == 'geoloc' || $action == 'trombi') {
+ $view = new UserSet();
+ $view->addMod('trombi', 'Trombinoscope');
+ $view->addMod('geoloc', 'Planisphère', false, array('with_annu' => 'annuaire/search'));
+ $view->apply('annuaire', $page, $action, $subaction);
+ if ($action == 'geoloc' && $subaction) {
+ return;
+ }
+ }
+ $page->changeTpl('xnetgrp/annuaire.tpl');
$sort = Env::v('order');
switch (Env::v('order')) {
@@ -341,7 +389,7 @@ class XnetGrpModule extends PLModule
1, 1)) as letter, COUNT(*)
FROM groupex.membres AS m
LEFT JOIN auth_user_md5 AS u ON ( u.user_id = m.uid)
- WHERE asso_id = {?} and u.perms != \'pending\'
+ WHERE asso_id = {?} and (u.perms != \'pending\' OR m.email IS NOT NULL)
GROUP BY letter
ORDER BY letter', $globals->asso('id'));
} else {
@@ -409,77 +457,105 @@ class XnetGrpModule extends PLModule
m.perms='admin' AS admin,
m.origine='X' AS x,
u.perms!='pending' AS inscrit,
- m.uid, e.email AS actif
+ m.comm as comm,
+ m.uid, IF(e.email IS NULL AND FIND_IN_SET('googleapps', u.mail_storage) = 0, NULL, 1) AS actif
FROM groupex.membres AS m
LEFT JOIN auth_user_md5 AS u ON ( u.user_id = m.uid )
LEFT JOIN aliases AS a ON ( a.id = m.uid AND a.type='a_vie' )
LEFT JOIN emails AS e ON ( e.flags = 'active' AND e.uid = m.uid)
WHERE m.asso_id = {?} $ini
AND (m.origine != 'X' OR u.perms != 'pending' OR m.email IS NOT NULL)
- GROUP BY m.uid
+ GROUP BY m.uid
ORDER BY $tri
LIMIT {?},{?}", $globals->asso('id'), $ofs*NB_PER_PAGE, NB_PER_PAGE);
$page->assign('ann', $ann);
+ $page->jsonAssign('ann', $ann);
}
- function handler_trombi(&$page, $num = 1)
+ function handler_trombi(&$page)
{
- global $globals;
- new_annu_page('xnetgrp/trombi.tpl');
-
- $page->assign('urlmainsite', "https://www.polytechnique.org/");
- $trombi = new Trombi(array($this, '_trombi_getlist'));
- $trombi->hidePromo();
- $trombi->setAdmin();
- $page->assign_by_ref('trombi', $trombi);
+ pl_redirect('annuaire/trombi');
}
- function _trombi_getlist($offset, $limit)
+ function handler_geoloc(&$page)
{
- global $globals;
- $where = "WHERE m.asso_id= '".addslashes($globals->asso('id'))."'";
-
- $res = XDB::query(
- "SELECT COUNT(*)
- FROM auth_user_md5 AS u
- RIGHT JOIN photo AS p ON u.user_id=p.uid
- INNER JOIN groupex.membres AS m ON (m.uid = u.user_id)
- $where");
- $pnb = $res->fetchOneCell();
-
- $res = XDB::query("SELECT promo, user_id, a.alias AS forlife,
- IF (nom_usage='', u.nom, nom_usage) AS nom, u.prenom
- FROM photo AS p
- INNER JOIN auth_user_md5 AS u ON u.user_id=p.uid
- INNER JOIN aliases AS a ON ( u.user_id=a.id AND a.type='a_vie' )
- INNER JOIN groupex.membres AS m ON (m.uid = u.user_id)
- $where
- ORDER BY promo, u.nom, u.prenom LIMIT {?}, {?}", $offset*$limit, $limit);
-
- return array($pnb, $res->fetchAllAssoc());
+ pl_redirect('annuaire/geoloc');
}
-
+
function handler_vcard(&$page, $photos = null)
{
global $globals;
+ $res = XDB::query('SELECT uid
+ FROM groupex.membres
+ WHERE asso_id = {?}', $globals->asso('id'));
+ $vcard = new VCard($photos == 'photos', 'Membre du groupe ' . $globals->asso('nom'));
+ $vcard->addUsers($res->fetchColumn());
+ $vcard->show();
+ }
- if (($globals->asso('pub') == 'public' && is_member()) || may_update()) {
- $res = XDB::query('SELECT uid
- FROM groupex.membres
- WHERE asso_id = {?}', $globals->asso('id'));
- require_once('vcard.inc.php');
- $vcard = new VCard($res->fetchColumn(), $photos == 'photos', 'Membre du groupe ' . $globals->asso('nom'));
- $vcard->do_page($page);
- } else {
- return PL_FORBIDDEN;
+ function handler_csv(&$page, $filename = null)
+ {
+ global $globals;
+ if (is_null($filename)) {
+ $filename = $globals->asso('diminutif') . '.csv';
}
+ $ann = XDB::iterator(
+ "SELECT IF(m.origine='X',IF(u.nom_usage<>'', u.nom_usage, u.nom) ,m.nom) AS nom,
+ IF(m.origine='X',u.prenom,m.prenom) AS prenom,
+ IF(m.origine='X', u.promo, IF(m.origine='ext', 'extérieur', 'personne morale')) AS promo,
+ IF(m.origine='X' AND u.perms != 'pending',CONCAT(a.alias, '@', {?}), m.email) AS email,
+ IF(m.origine='X',FIND_IN_SET('femme', u.flags), m.sexe) AS femme,
+ m.comm as comm
+ FROM groupex.membres AS m
+ LEFT JOIN auth_user_md5 AS u ON ( u.user_id = m.uid )
+ LEFT JOIN aliases AS a ON ( a.id = m.uid AND a.type = 'a_vie' )
+ WHERE m.asso_id = {?}
+ AND (m.origine != 'X' OR u.perms != 'pending' OR m.email IS NOT NULL)
+ GROUP BY m.uid
+ ORDER BY nom, prenom",
+ $globals->mail->domain, $globals->asso('id'));
+ header('Content-Type: text/x-csv; charset=utf-8;');
+ header('Pragma: ');
+ header('Cache-Control: ');
+ $page->changeTpl('xnetgrp/annuaire-csv.tpl', NO_SKIN);
+ $page->assign('ann', $ann);
}
- function handler_subscribe(&$page, $u = null)
+ private function removeSubscriptionRequest($uid)
{
global $globals;
+ XDB::execute("DELETE FROM groupex.membres_sub_requests
+ WHERE asso_id = {?} AND uid = {?}",
+ $globals->asso('id'), $uid);
+ }
- new_group_open_page('xnetgrp/inscrire.tpl');
+ private function validSubscription(User &$user)
+ {
+ global $globals;
+ $this->removeSubscriptionRequest($user->id());
+ XDB::execute("INSERT INTO groupex.membres (asso_id, uid)
+ VALUES ({?}, {?})",
+ $globals->asso('id'), $user->id());
+ $mailer = new PlMailer();
+ $mailer->addTo($user->forlifeEmail());
+ $mailer->setFrom('"' . S::user()->fullName() . '" <' . S::user()->forlifeEmail() . '>');
+ $mailer->setSubject('[' . $globals->asso('nom') . '] Demande d\'inscription');
+ $message = ($user->isFemale() ? 'Chère' : 'Cher') . " Camarade,\n"
+ . "\n"
+ . " Suite à ta demande d'adhésion à " . $globals->asso('nom') . ",\n"
+ . "j'ai le plaisir de t'annoncer que ton inscription a été validée !\n"
+ . "\n"
+ . "Bien cordialement,\n"
+ . "-- \n"
+ . S::user()->fullName() . '.';
+ $mailer->setTxtBody($message);
+ $mailer->send();
+ }
+
+ function handler_subscribe(&$page, $u = null)
+ {
+ global $globals;
+ $page->changeTpl('xnetgrp/inscrire.tpl');
if (!$globals->asso('inscriptible'))
$page->kill("Il n'est pas possible de s'inscire en ligne à ce "
@@ -487,94 +563,91 @@ class XnetGrpModule extends PLModule
."sur la page de présentation.");
if (!is_null($u) && may_update()) {
- $page->assign('u', $u);
- $res = XDB::query("SELECT nom, prenom, promo, user_id
- FROM auth_user_md5 AS u
- INNER JOIN aliases AS al ON (al.id = u.user_id
- AND al.type != 'liste')
- WHERE al.alias = {?}", $u);
-
- if (list($nom, $prenom, $promo, $uid) = $res->fetchOneRow()) {
- $res = XDB::query("SELECT COUNT(*)
- FROM groupex.membres AS m
- INNER JOIN aliases AS a ON (m.uid = a.id
- AND a.type != 'homonyme')
- WHERE a.alias = {?} AND m.asso_id = {?}",
- $u, $globals->asso('id'));
- $n = $res->fetchOneCell();
- if ($n) {
- $page->kill("$prenom $nom est déjà membre du groupe !");
- return;
- }
- elseif (Env::has('accept'))
- {
- XDB::execute("INSERT INTO groupex.membres
- VALUES ({?}, {?}, 'membre', 'X', NULL, NULL, NULL, NULL, NULL)",
- $globals->asso('id'), $uid);
- $mailer = new PlMailer();
- $mailer->addTo("$u@polytechnique.org");
- $mailer->setFrom('"'.S::v('prenom').' '.S::v('nom')
- .'" <'.S::v('forlife').'@polytechnique.org>');
- $mailer->setSubject('['.$globals->asso('nom').'] Demande d\'inscription');
- $message = "Cher Camarade,\n"
- . "\n"
- . " Suite à ta demande d'adhésion à ".$globals->asso('nom').",\n"
- . "j'ai le plaisir de t'annoncer que ton inscription a été validée !\n"
- . "\n"
- . "Bien cordialement,\n"
- . "{$_SESSION["prenom"]} {$_SESSION["nom"]}.";
- $mailer->setTxtBody($message);
- $mailer->send();
- $page->kill("$prenom $nom a bien été inscrit");
- }
- elseif (Env::has('refuse'))
- {
- $mailer = new PlMailer();
- $mailer->addTo("$u@polytechnique.org");
- $mailer->setFrom('"'.S::v('prenom').' '.S::v('nom')
- .'" <'.S::v('forlife').'@polytechnique.org>');
- $mailer->setSubject('['.$globals->asso('nom').'] Demande d\'inscription annulée');
- $mailer->setTxtBody(Env::v('motif'));
- $mailer->send();
- $page->kill("la demande $prenom $nom a bien été refusée");
- } else {
- $page->assign('show_form', true);
- $page->assign('prenom', $prenom);
- $page->assign('nom', $nom);
- $page->assign('promo', $promo);
- $page->assign('uid', $uid);
- }
- return;
+ $user = User::get($u);
+ if (!$user) {
+ return PL_NOT_FOUND;
+ } else {
+ $page->assign('user', $user);
}
- return PL_NOT_FOUND;
+
+ // Retrieves the subscription status, and the reason.
+ $res = XDB::query("SELECT reason
+ FROM groupex.membres_sub_requests
+ WHERE asso_id = {?} AND uid = {?}",
+ $globals->asso('id'), $user->id());
+ $reason = ($res->numRows() ? $res->fetchOneCell() : null);
+
+ $res = XDB::query("SELECT COUNT(*)
+ FROM groupex.membres
+ WHERE asso_id = {?} AND uid = {?}",
+ $globals->asso('id'), $user->id());
+ $already_member = ($res->fetchOneCell() > 0);
+
+ // Handles the membership request.
+ if ($already_member) {
+ $this->removeSubscriptionRequest($user->id());
+ $page->kill($user->fullName() . " est déjà membre du groupe !");
+ } elseif (Env::has('accept')) {
+ S::assert_xsrf_token();
+
+ $this->validSubscription($user);
+ pl_redirect("member/" . $user->login());
+ } elseif (Env::has('refuse')) {
+ S::assert_xsrf_token();
+
+ $this->removeSubscriptionRequest($user->id());
+ $mailer = new PlMailer();
+ $mailer->addTo($user->forlifeEmail());
+ $mailer->setFrom('"' . S::user()->fullName() . '" <' . S::user()->forlifeEmail() . '>');
+ $mailer->setSubject('['.$globals->asso('nom').'] Demande d\'inscription annulée');
+ $mailer->setTxtBody(Env::v('motif'));
+ $mailer->send();
+ $page->kill("La demande de {$user->fullName()} a bien été refusée.");
+ } else {
+ $page->assign('show_form', true);
+ $page->assign('reason', $reason);
+ }
+ return;
}
if (is_member()) {
- $page->kill("tu es déjà membre !");
+ $page->kill("Tu es déjà membre !");
+ return;
+ }
+
+ $res = XDB::query("SELECT uid
+ FROM groupex.membres_sub_requests
+ WHERE uid = {?} AND asso_id = {?}",
+ S::i('uid'), $globals->asso('id'));
+ if ($res->numRows() != 0) {
+ $page->kill("Tu as déjà demandé ton inscription à ce groupe. Cette demande est actuellement en attente de validation.");
return;
}
if (Post::has('inscrire')) {
+ S::assert_xsrf_token();
+
+ XDB::execute("INSERT INTO groupex.membres_sub_requests (asso_id, uid, ts, reason)
+ VALUES ({?}, {?}, NOW(), {?})",
+ $globals->asso('id'), S::i('uid'), Post::v('message'));
$res = XDB::query('SELECT IF(m.email IS NULL,
- CONCAT(al.alias,"@polytechnique.org"),
- m.email)
- FROM groupex.membres AS m
- INNER JOIN aliases AS al ON (al.type = "a_vie"
- AND al.id = m.uid)
- WHERE perms="admin" AND m.asso_id = {?}',
- $globals->asso('id'));
+ CONCAT(al.alias,"@polytechnique.org"),
+ m.email)
+ FROM groupex.membres AS m
+ INNER JOIN aliases AS al ON (al.type = "a_vie"
+ AND al.id = m.uid)
+ WHERE perms="admin" AND m.asso_id = {?}',
+ $globals->asso('id'));
$emails = $res->fetchColumn();
$to = implode(',', $emails);
$append = "\n"
. "-- \n"
. "Ce message a été envoyé suite à la demande d'inscription de\n"
- . S::v('prenom').' '.S::v('nom').' (X'.S::v('promo').")\n"
+ . S::user()->fullName() . ' (X' . S::v('promo') . ")\n"
. "Via le site www.polytechnique.net. Tu peux choisir de valider ou\n"
. "de refuser sa demande d'inscription depuis la page :\n"
- .
- "http://www.polytechnique.net/".$globals->asso("diminutif")."/subscribe/"
- .S::v('forlife')."\n"
+ . "http://www.polytechnique.net/" . $globals->asso("diminutif") . "/subscribe/" . S::user()->login() . "\n"
. "\n"
. "En cas de problème, contacter l'équipe de Polytechnique.org\n"
. "Ã l'adresse : support@polytechnique.org\n";
@@ -589,48 +662,79 @@ class XnetGrpModule extends PLModule
$mailer = new PlMailer();
$mailer->addTo($to);
- $mailer->setFrom('"'.S::v('prenom').' '.S::v('nom')
- .'" <'.S::v('forlife').'@polytechnique.org>');
+ $mailer->setFrom('"' . S::user()->fullName() . '" <' . S::user()->forlifeEmail() . '>');
$mailer->setSubject('['.$globals->asso('nom').'] Demande d\'inscription');
$mailer->setTxtBody(Post::v('message').$append);
$mailer->send();
}
}
+ function handler_subscribe_valid(&$page)
+ {
+ global $globals;
+
+ if (Post::has('valid')) {
+ S::assert_xsrf_token();
+ $subs = Post::v('subs');
+ if (is_array($subs)) {
+ $users = array();
+ foreach ($subs as $hruid => $val) {
+ if ($val == '1') {
+ $user = User::get($hruid);
+ if ($user) {
+ $this->validSubscription($user);
+ }
+ }
+ }
+ }
+ }
+
+ $it = XDB::iterator("SELECT IF(u.nom_usage != '', u.nom_usage, u.nom) AS nom,
+ u.prenom, u.promo, u.hruid, s.ts AS date
+ FROM groupex.membres_sub_requests AS s
+ INNER JOIN auth_user_md5 AS u ON (s.uid = u.user_id)
+ WHERE asso_id = {?}
+ ORDER BY nom, prenom",
+ $globals->asso('id'));
+
+ $page->changeTpl('xnetgrp/subscribe-valid.tpl');
+ $page->assign('valid', $it);
+ }
+
function handler_change_rights(&$page)
{
if (Env::has('right') && (may_update() || S::has('suid'))) {
switch (Env::v('right')) {
- case 'admin':
- XnetSession::killSuid();
+ case 'admin':
+ Platal::session()->stopSUID();
break;
case 'anim':
- XnetSession::doSelfSuid();
+ Platal::session()->doSelfSuid();
may_update(true);
is_member(true);
break;
case 'member':
- XnetSession::doSelfSuid();
+ Platal::session()->doSelfSuid();
may_update(false, true);
is_member(true);
break;
case 'logged':
- XnetSession::doSelfSuid();
+ Platal::session()->doSelfSuid();
may_update(false, true);
is_member(false, true);
break;
}
}
- pl_redirect("");
+// var_dump($_SESSION);
+ http_redirect($_SERVER['HTTP_REFERER']);
}
function handler_admin_annuaire(&$page)
{
global $globals;
- require_once dirname(__FILE__) . '/xnetgrp/mail.inc.php';
-
- new_groupadmin_page('xnetgrp/annuaire-admin.tpl');
+ $this->load('mail.inc.php');
+ $page->changeTpl('xnetgrp/annuaire-admin.tpl');
$mmlist = new MMList(S::v('uid'), S::v('password'),
$globals->asso('mail_domain'));
$lists = $mmlist->get_lists();
@@ -675,36 +779,24 @@ class XnetGrpModule extends PLModule
{
global $globals;
- new_groupadmin_page('xnetgrp/membres-add.tpl');
+ $page->changeTpl('xnetgrp/membres-add.tpl');
$page->addJsLink('ajax.js');
if (is_null($email)) {
return;
- }
-
- if (strpos($email, '@') === false) {
- $x = true;
} else {
- list(,$fqdn) = explode('@', $email, 2);
- $fqdn = strtolower($fqdn);
- $x = ($fqdn == 'polytechnique.org' || $fqdn == 'melix.org' ||
- $fqdn == 'm4x.org' || $fqdn == 'melix.net');
+ S::assert_xsrf_token();
}
- if ($x) {
- require_once 'user.func.inc.php';
- if ($forlife = get_user_forlife($email)) {
- XDB::execute(
- 'INSERT INTO groupex.membres (uid,asso_id,origine)
- SELECT user_id,{?},"X"
- FROM auth_user_md5 AS u
- INNER JOIN aliases AS a ON (u.user_id = a.id)
- WHERE a.alias={?}', $globals->asso('id'), $forlife);
- pl_redirect("member/$email");
- } else {
- $page->trig($email." n'est pas un alias polytechnique.org valide");
+
+ if (!User::isForeignEmailAddress($email)) {
+ $user = User::get($email);
+ if ($user) {
+ XDB::execute("REPLACE INTO groupex.membres (uid, asso_id, origine)
+ VALUES ({?}, {?}, 'X')",
+ $user->id(), $globals->asso('id'));
+ pl_redirect("member/" . $user->login());
}
} else {
- require_once 'xorg.misc.inc.php';
if (isvalid_email($email)) {
if (Env::v('x') && Env::has('userid') && Env::i('userid')) {
$uid = Env::i('userid');
@@ -712,25 +804,21 @@ class XnetGrpModule extends PLModule
FROM auth_user_md5
WHERE user_id = {?} AND perms = 'pending'", $uid);
if ($res->numRows() == 1) {
- XDB::execute('INSERT INTO groupex.membres (uid, asso_id, origine, email)
- VALUES ({?}, {?}, "X", {?})',
- $uid, $globals->asso('id'), $email);
if (Env::v('market')) {
- $res = XDB::query('SELECT COUNT(*)
- FROM register_marketing
- WHERE uid={?} AND email={?}', $uid, $email);
- if (!$res->fetchOneCell()) {
- XDB::execute("INSERT INTO register_marketing (uid,sender,email,date,last,nb,type,hash)
- VALUES ({?}, {?}, {?}, NOW(), 0, 0, {?}, '')",
- $uid, S::v('uid'), $email, Env::v('market_from'));
- require_once('validations.inc.php');
- $req = new MarkReq(S::v('uid'), $uid, $email, Env::v('market_from') == 'user');
- $req->submit();
- }
+ $market = Marketing::get($uid, $email);
+ if (!$market) {
+ $market = new Marketing($uid, $email, 'group', $globals->asso('nom'),
+ Env::v('market_from'), S::v('uid'));
+ $market->add();
+ }
}
+ XDB::execute('INSERT INTO groupex.membres (uid, asso_id, origine, email)
+ VALUES ({?}, {?}, "X", {?})',
+ $uid, $globals->asso('id'), $email);
+ $this->removeSubscriptionRequest($uid);
pl_redirect("member/$email");
}
- $page->trig("Utilisateur invalide");
+ $page->trigError("Utilisateur invalide");
} else {
$res = XDB::query('SELECT MAX(uid)+1 FROM groupex.membres');
$uid = max(intval($res->fetchOneCell()), 50001);
@@ -740,7 +828,7 @@ class XnetGrpModule extends PLModule
pl_redirect("member/$email");
}
} else {
- $page->trig("« $email » n'est pas une adresse mail valide");
+ $page->trigError("« $email » n'est pas une adresse email valide.");
}
}
}
@@ -749,38 +837,66 @@ class XnetGrpModule extends PLModule
{
header('Content-Type: text/html; charset="UTF-8"');
$page->changeTpl('xnetgrp/membres-new-search.tpl', NO_SKIN);
- list($nom, $prenom) = str_replace(array('-', ' ', "'"), '%', array(Env::v('nom'), Env::v('prenom')));
- $where = "perms = 'pending'";
- if (!empty($nom)) {
- $where .= " AND nom LIKE '%$nom%'";
- }
- if (!empty($prenom)) {
- $where .= " AND prenom LIKE '%$prenom%'";
+ $res = null;
+ if (Env::has('login')) {
+ require_once 'user.func.inc.php';
+ $res = get_not_registered_user(Env::v('login'), true);
}
- if (preg_match('/^[0-9]{4}$/', Env::v('promo'))) {
- $where .= " AND promo = " . Env::i('promo');
- } elseif (Env::has('promo')) {
- return;
+ if (is_null($res)) {
+ list($nom, $prenom) = str_replace(array('-', ' ', "'"), '%', array(Env::v('nom'), Env::v('prenom')));
+ $where = "perms = 'pending'";
+ if (!empty($nom)) {
+ $where .= " AND nom LIKE '%$nom%'";
+ }
+ if (!empty($prenom)) {
+ $where .= " AND prenom LIKE '%$prenom%'";
+ }
+ if (preg_match('/^[0-9]{4}$/', Env::v('promo'))) {
+ $where .= " AND promo = " . Env::i('promo');
+ } elseif (preg_match('/^[0-9]{2}$/', Env::v('promo'))) {
+ $where .= " AND MOD(promo, 100) = " . Env::i('promo');
+ } elseif (Env::has('promo')) {
+ return;
+ }
+ $res = XDB::iterator("SELECT user_id, nom, prenom, promo
+ FROM auth_user_md5
+ WHERE $where");
}
- $res = XDB::iterator("SELECT user_id, nom, prenom, promo
- FROM auth_user_md5
- WHERE $where");
- if ($res->total() < 30) {
+ if ($res && $res->total() < 30) {
$page->assign("choix", $res);
}
}
function unsubscribe(&$user)
{
- global $globals, $page;
+ global $globals;
XDB::execute(
"DELETE FROM groupex.membres WHERE uid={?} AND asso_id={?}",
$user['uid'], $globals->asso('id'));
+ if ($globals->asso('notif_unsub')) {
+ $mailer = new PlMailer('xnetgrp/unsubscription-notif.mail.tpl');
+ $res = XDB::iterRow("SELECT a.alias, u.prenom, IF(u.nom_usage != '', u.nom_usage, u.nom) AS nom
+ FROM groupex.membres AS m
+ INNER JOIN aliases AS a ON (m.uid = a.id AND FIND_IN_SET('bestalias', a.flags))
+ INNER JOIn auth_user_md5 AS u ON (u.user_id = a.id)
+ WHERE m.asso_id = {?} AND m.perms = 'admin'",
+ $globals->asso('id'));
+ while (list($alias, $prenom, $nom) = $res->next()) {
+ $mailer->addTo("\"$prenom $nom\" <$alias@{$globals->mail->domain}>");
+ }
+ $mailer->assign('group', $globals->asso('nom'));
+ $mailer->assign('prenom', $user['prenom']);
+ $mailer->assign('nom', $user['nom']);
+ $mailer->assign('mail', $user['email2']);
+ $mailer->assign('selfdone', $user['uid'] == S::i('uid'));
+ $mailer->send();
+ }
+
$user_same_email = get_infos($user['email']);
$domain = $globals->asso('mail_domain');
- if (!$domain || !empty($user_same_email)) {
+ if (!$domain || (!empty($user_same_email) && $user_same_email['uid'] != $user['uid'])) {
return true;
}
@@ -797,9 +913,9 @@ class XnetGrpModule extends PLModule
$mmlist->unsubscribe($liste['list']);
}
} elseif ($liste['sub']) {
- $page->trig("{$user['prenom']} {$user['nom']} a une"
- ." demande d'inscription en cours sur la"
- ." liste {$liste['list']}@ !");
+ Platal::page()->trigWarning("{$user['prenom']} {$user['nom']} a une"
+ ." demande d'inscription en cours sur la"
+ ." liste {$liste['list']}@ !");
$warning = true;
}
}
@@ -814,8 +930,8 @@ class XnetGrpModule extends PLModule
function handler_unsubscribe(&$page)
{
- new_group_page('xnetgrp/membres-del.tpl');
- $user = get_infos(S::v('forlife'));
+ $page->changeTpl('xnetgrp/membres-del.tpl');
+ $user = get_infos(S::user()->id());
if (empty($user)) {
return PL_NOT_FOUND;
}
@@ -824,19 +940,21 @@ class XnetGrpModule extends PLModule
if (!Post::has('confirm')) {
return;
+ } else {
+ S::assert_xsrf_token();
}
if ($this->unsubscribe($user)) {
- $page->trig('Vous avez été désinscrit du groupe avec succès');
+ $page->trigSuccess('Vous avez été désinscrit du groupe avec succès.');
} else {
- $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.');
+ $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.');
}
$page->assign('is_member', is_member(true));
}
function handler_admin_member_del(&$page, $user = null)
{
- new_groupadmin_page('xnetgrp/membres-del.tpl');
+ $page->changeTpl('xnetgrp/membres-del.tpl');
$user = get_infos($user);
if (empty($user)) {
return PL_NOT_FOUND;
@@ -845,20 +963,91 @@ class XnetGrpModule extends PLModule
if (!Post::has('confirm')) {
return;
+ } else {
+ S::assert_xsrf_token();
}
if ($this->unsubscribe($user)) {
- $page->trig("{$user['prenom']} {$user['nom']} a été désabonné du groupe !");
+ $page->trigSuccess("{$user['prenom']} {$user['nom']} a été désabonné du groupe !");
+ } else {
+ $page->trigWarning("{$user['prenom']} {$user['nom']} a été désabonné du groupe, mais des erreurs subsistent !");
+ }
+ }
+
+ private function changeLogin(PlPage &$page, array &$user, MMList &$mmlist, $login)
+ {
+ require_once 'user.func.inc.php';
+ // Search the uid of the user...
+ $res = XDB::query("SELECT f.id, f.alias
+ FROM aliases AS a
+ INNER JOIN aliases AS f ON (f.id = a.id AND f.type = 'a_vie')
+ WHERE a.alias = {?}",
+ $login);
+ if ($res->numRows() == 0) {
+ $x = get_not_registered_user($login);
+ if (!$x) {
+ $page->trigError("Le login $login ne correspond à aucun X.");
+ return false;
+ } else if (count($x) > 1) {
+ $page->trigError("Le login $login correspond a plusieurs camarades.");
+ return false;
+ }
+ $uid = $x[0]['user_id'];
+ $sub = false;
+ } else {
+ list($uid, $login) = $res->fetchOneRow();
+ $sub = true;
+ }
+
+ // Check if the user is already in the group
+ global $globals;
+ $res = XDB::query("SELECT uid, email
+ FROM groupex.membres
+ WHERE uid = {?} AND asso_id = {?}",
+ $uid, $globals->asso('id'));
+ if ($res->numRows()) {
+ list($uid, $email) = $res->fetchOneRow();
+ XDB::execute("DELETE FROM groupex.membres
+ WHERE uid = {?}",
+ $user['uid']);
} else {
- $page->trig("{$user['prenom']} {$user['nom']} a été désabonné du groupe, mais des erreurs subsistent !");
+ $email = $user['email'];
+ XDB::execute("UPDATE groupex.membres
+ SET uid = {?}, origine = 'X'
+ WHERE uid = {?} AND asso_id = {?}",
+ $uid, $user['uid'], $globals->asso('id'));
+ }
+ if ($sub) {
+ $email = $login . '@' . $globals->mail->domain;
+ }
+
+ // Update subscription to aliases
+ if ($email != $user['email']) {
+ XDB::execute("UPDATE IGNORE virtual_redirect AS vr
+ INNER JOIN virtual AS v ON(vr.vid = v.vid AND SUBSTRING_INDEX(alias, '@', -1) = {?})
+ SET vr.redirect = {?}
+ WHERE vr.redirect = {?}",
+ $globals->asso('mail_domain'), $email, $user['email']);
+ XDB::execute("DELETE vr.*
+ FROM virtual_redirect AS vr
+ INNER JOIN virtual AS v ON(vr.vid = v.vid AND SUBSTRING_INDEX(alias, '@', -1) = {?})
+ WHERE vr.redirect = {?}",
+ $globals->asso('mail_domain'), $user['email']);
+ foreach (Env::v('ml1', array()) as $ml => $state) {
+ $mmlist->replace_email($ml, $user['email'], $email);
+ }
}
+ if ($sub) {
+ return $login;
+ }
+ return $user['email'];
}
function handler_admin_member(&$page, $user)
{
global $globals;
- new_groupadmin_page('xnetgrp/membres-edit.tpl');
+ $page->changeTpl('xnetgrp/membres-edit.tpl');
$user = get_infos($user);
if (empty($user)) {
@@ -869,6 +1058,17 @@ class XnetGrpModule extends PLModule
$globals->asso('mail_domain'));
if (Post::has('change')) {
+ S::assert_xsrf_token();
+
+ // Convert user status to X
+ if ($user['origine'] == 'ext' && trim(Post::v('login_X'))) {
+ $forlife = $this->changeLogin($page, $user, $mmlist, trim(Post::v('login_X')));
+ if ($forlife) {
+ pl_redirect('member/' . $forlife);
+ }
+ }
+
+ // Update user info
$email_changed = ($user['origine'] != 'X' && strtolower($user['email']) != strtolower(Post::v('email')));
$from_email = $user['email'];
if ($user['origine'] != 'X') {
@@ -880,48 +1080,59 @@ class XnetGrpModule extends PLModule
SET prenom={?}, nom={?}, email={?}, sexe={?}, origine={?}
WHERE uid={?} AND asso_id={?}',
$user['prenom'], $user['nom'], Post::v('email'),
- $user['sexe'], $user['origine'], $user['uid'],
- $globals->asso('id'));
+ $user['sexe'], $user['origine'],
+ $user['uid'], $globals->asso('id'));
$user['email'] = Post::v('email');
$user['email2'] = Post::v('email');
+ $page->trigSuccess('Données de l\'utilisateur mise à jour.');
}
$perms = Post::i('is_admin');
- if ($user['perms'] != $perms) {
- XDB::query('UPDATE groupex.membres SET perms={?}
+ $comm = trim(Post::s('comm'));
+ if ($user['perms'] != $perms || $user['comm'] != $comm) {
+ XDB::query('UPDATE groupex.membres
+ SET perms={?}, comm={?}
WHERE uid={?} AND asso_id={?}',
- $perms ? 'admin' : 'membre',
+ $perms ? 'admin' : 'membre', $comm,
$user['uid'], $globals->asso('id'));
+ if ($perms != $user['perms']) {
+ $page->trigSuccess('Permissions modifiées !');
+ }
+ if ($comm != $user['comm']) {
+ $page->trigSuccess('Commentaire mis à jour.');
+ }
$user['perms'] = $perms;
- $page->trig('permissions modifiées');
+ $user['comm'] = $comm;
}
+ // Update ML subscriptions
foreach (Env::v('ml1', array()) as $ml => $state) {
$ask = empty($_REQUEST['ml2'][$ml]) ? 0 : 2;
if ($ask == $state) {
if ($state && $email_changed) {
$mmlist->replace_email($ml, $from_email, $user['email2']);
- $page->trig("L'abonnement de {$user['prenom']} {$user['nom']} à $ml@ a été mis à jour");
+ $page->trigSuccess("L'abonnement de {$user['prenom']} {$user['nom']} à $ml@ a été mis à jour.");
}
continue;
}
if ($state == '1') {
- $page->trig("{$user['prenom']} {$user['nom']} a "
+ $page->trigWarning("{$user['prenom']} {$user['nom']} a "
."actuellement une demande d'inscription en "
."cours sur $ml@ !!!");
} elseif ($ask) {
$mmlist->mass_subscribe($ml, Array($user['email2']));
- $page->trig("{$user['prenom']} {$user['nom']} a été abonné à $ml@");
+ $page->trigSuccess("{$user['prenom']} {$user['nom']} a été abonné à $ml@.");
} else {
if ($email_changed) {
$mmlist->mass_unsubscribe($ml, Array($from_email));
} else {
$mmlist->mass_unsubscribe($ml, Array($user['email2']));
}
- $page->trig("{$user['prenom']} {$user['nom']} a été désabonné de $ml@");
+ $page->trigSuccess("{$user['prenom']} {$user['nom']} a été désabonné de $ml@.");
}
}
+ // Change subscriptioin to aliases
foreach (Env::v('ml3', array()) as $ml => $state) {
$ask = !empty($_REQUEST['ml4'][$ml]);
if($state == $ask) continue;
@@ -929,14 +1140,14 @@ class XnetGrpModule extends PLModule
XDB::query("INSERT INTO virtual_redirect (vid,redirect)
SELECT vid,{?} FROM virtual WHERE alias={?}",
$user['email'], $ml);
- $page->trig("{$user['prenom']} {$user['nom']} a été abonné à $ml");
+ $page->trigSuccess("{$user['prenom']} {$user['nom']} a été abonné à $ml.");
} else {
XDB::query("DELETE FROM virtual_redirect
USING virtual_redirect
INNER JOIN virtual USING(vid)
WHERE redirect={?} AND alias={?}",
$user['email'], $ml);
- $page->trig("{$user['prenom']} {$user['nom']} a été désabonné de $ml");
+ $page->trigSuccess("{$user['prenom']} {$user['nom']} a été désabonné de $ml.");
}
}
}
@@ -948,49 +1159,75 @@ class XnetGrpModule extends PLModule
$res = XDB::query(
'SELECT alias, redirect IS NOT NULL as sub
FROM virtual AS v
- LEFT JOIN virtual_redirect AS vr ON(v.vid=vr.vid AND redirect={?})
+ LEFT JOIN virtual_redirect AS vr ON(v.vid=vr.vid AND (redirect = {?} OR redirect = {?}))
WHERE alias LIKE {?} AND type="user"',
- $user['email'], '%@'.$globals->asso('mail_domain'));
+ $user['email'], $user['email2'], '%@'.$globals->asso('mail_domain'));
$page->assign('alias', $res->fetchAllAssoc());
}
function handler_rss(&$page, $user = null, $hash = null)
{
global $globals;
- require_once('rss.inc.php');
- $uid = init_rss('xnetgrp/announce-rss.tpl', $user, $hash, false);
- $page->register_modifier('url_catcher', array(MiniWiki,'WikiToHTML'));
-
- if ($uid) {
- $rss = XDB::iterator("SELECT a.id, a.titre, a.texte, a.contacts, a.create_date,
- IF(u2.nom_usage != '', u2.nom_usage, u2.nom) AS nom, u2.prenom, u2.promo
- FROM auth_user_md5 AS u
- INNER JOIN groupex.announces AS a ON ( (a.promo_min = 0 OR a.promo_min <= u.promo)
- AND (a.promo_max = 0 OR a.promo_max <= u.promo))
- INNER JOIN auth_user_md5 AS u2 ON (u2.user_id = a.user_id)
- WHERE u.user_id = {?} AND peremption >= NOW() AND a.asso_id = {?}",
- $uid, $globals->asso('id'));
+ $page->assign('asso', $globals->asso());
+
+ $this->load('feed.inc.php');
+ $feed = new XnetGrpEventFeed();
+ return $feed->run($page, $user, $hash, false);
+ }
+
+ private function upload_image(PlPage &$page, PlUpload &$upload)
+ {
+ if (@!$_FILES['image']['tmp_name'] && !Env::v('image_url')) {
+ return true;
+ }
+ if (!$upload->upload($_FILES['image']) && !$upload->download(Env::v('image_url'))) {
+ $page->trigError('Impossible de télécharger l\'image');
+ return false;
+ } elseif (!$upload->isType('image')) {
+ $page->trigError('Le fichier n\'est pas une image valide au format JPEG, GIF ou PNG.');
+ $upload->rm();
+ return false;
+ } elseif (!$upload->resizeImage(200, 300, 100, 100, 32284)) {
+ $page->trigError('Impossible de retraiter l\'image');
+ return false;
+ }
+ return true;
+ }
+
+ function handler_photo_announce(&$page, $eid = null) {
+ if ($eid) {
+ $res = XDB::query("SELECT * FROM groupex.announces_photo WHERE eid = {?}", $eid);
+ if ($res->numRows()) {
+ $photo = $res->fetchOneAssoc();
+ header('Content-Type: image/' . $photo['attachmime']);
+ echo $photo['attach'];
+ exit;
+ }
} else {
- $rss = XDB::iterator("SELECT a.id, a.titre, a.texte, a.create_date,
- IF(u.nom_usage != '', u.nom_usage, u.nom) AS nom, u.prenom, u.promo
- FROM groupex.announces AS a
- INNER JOIN auth_user_md5 AS u USING(user_id)
- WHERE FIND_IN_SET(a.flags, 'public') AND peremption >= NOW() AND a.asso_id = {?}",
- $globals->asso('id'));
+ $upload = new PlUpload(S::user()->login(), 'xnetannounce');
+ if ($upload->exists() && $upload->isType('image')) {
+ header('Content-Type: ' . $upload->contentType());
+ echo $upload->getContents();
+ exit;
+ }
}
- $page->assign('asso', $globals->asso());
- $page->assign('rss', $rss);
+ global $globals;
+ header('Content-Type: image/png');
+ echo file_get_contents($globals->spoolroot . '/htdocs/images/logo.png');
+ exit;
}
function handler_edit_announce(&$page, $aid = null)
{
global $globals, $platal;
- new_groupadmin_page('xnetgrp/announce-edit.tpl');
- $page->register_modifier('url_catcher', array(MiniWiki,'WikiToHTML'));
+ $page->changeTpl('xnetgrp/announce-edit.tpl');
$page->assign('new', is_null($aid));
$art = array();
- if (Post::v('valid') == 'Visualiser' || Post::v('valid') == 'Enregistrer') {
+ if (Post::v('valid') == 'Visualiser' || Post::v('valid') == 'Enregistrer'
+ || Post::v('valid') == 'Supprimer l\'image' || Post::v('valid') == 'Pas d\'image') {
+ S::assert_xsrf_token();
+
if (!is_null($aid)) {
$art['id'] = $aid;
}
@@ -1002,12 +1239,14 @@ class XnetGrpModule extends PLModule
$art['nom'] = S::v('nom');
$art['prenom'] = S::v('prenom');
$art['promo'] = S::v('promo');
- $art['forlife'] = S::v('forlife');
+ $art['hruid'] = S::user()->login();
$art['peremption'] = Post::v('peremption');
$art['public'] = Post::has('public');
$art['xorg'] = Post::has('xorg');
$art['nl'] = Post::has('nl');
$art['event'] = Post::v('event');
+ $upload = new PlUpload(S::user()->login(), 'xnetannounce');
+ $this->upload_image($page, $upload);
$art['contact_html'] = $art['contacts'];
if ($art['event']) {
@@ -1019,41 +1258,79 @@ class XnetGrpModule extends PLModule
($art['promo_min'] != 0 && ($art['promo_min'] <= 1900 || $art['promo_min'] >= 2020)) ||
($art['promo_max'] != 0 && ($art['promo_max'] <= 1900 || $art['promo_max'] >= 2020))))
{
- $page->trig("L'intervalle de promotions est invalide");
+ $page->trigError("L'intervalle de promotions est invalide.");
Post::kill('valid');
}
if (!trim($art['titre']) || !trim($art['texte'])) {
- $page->trig("L'article doit avoir un titre et un contenu");
+ $page->trigError("L'article doit avoir un titre et un contenu.");
+ Post::kill('valid');
+ }
+
+ if (Post::v('valid') == 'Supprimer l\'image') {
+ $upload->rm();
+ Post::kill('valid');
+ }
+ $art['photo'] = $upload->exists() || Post::i('photo');
+ if (Post::v('valid') == 'Pas d\'image' && !is_null($aid)) {
+ XDB::query("DELETE FROM groupex.announces_photo WHERE eid = {?}", $aid);
+ $upload->rm();
Post::kill('valid');
+ $art['photo'] = false;
}
}
if (Post::v('valid') == 'Enregistrer') {
$promo_min = ($art['public'] ? 0 : $art['promo_min']);
$promo_max = ($art['public'] ? 0 : $art['promo_max']);
+ $flags = new PlFlagSet();
+ if ($art['public']) {
+ $flags->addFlag('public');
+ }
+ if ($art['photo']) {
+ $flags->addFlag('photo');
+ }
if (is_null($aid)) {
+ $fulltext = $art['texte'];
+ if (!empty($art['contact_html'])) {
+ $fulltext .= "\n\n'''Contacts :'''\\\\\n" . $art['contact_html'];
+ }
+ $post = null;/*
+ if ($globals->asso('forum')) {
+ require_once 'banana/forum.inc.php';
+ $banana = new ForumsBanana(S::user());
+ $post = $banana->post($globals->asso('forum'), null,
+ $art['titre'], MiniWiki::wikiToText($fulltext, false, 0, 80));
+ }*/
XDB::query("INSERT INTO groupex.announces
(user_id, asso_id, create_date, titre, texte, contacts,
- peremption, promo_min, promo_max, flags)
- VALUES ({?}, {?}, NOW(), {?}, {?}, {?}, {?}, {?}, {?}, {?})",
+ peremption, promo_min, promo_max, flags, post_id)
+ VALUES ({?}, {?}, NOW(), {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})",
S::i('uid'), $globals->asso('id'), $art['titre'], $art['texte'], $art['contact_html'],
- $art['peremption'], $promo_min, $promo_max, $art['public'] ? 'public' : '');
+ $art['peremption'], $promo_min, $promo_max, $flags, $post);
$aid = XDB::insertId();
+ if ($art['photo']) {
+ list($imgx, $imgy, $imgtype) = $upload->imageInfo();
+ XDB::execute("INSERT INTO groupex.announces_photo
+ SET eid = {?}, attachmime = {?}, x = {?}, y = {?}, attach = {?}",
+ $aid, $imgtype, $imgx, $imgy, $upload->getContents());
+ }
if ($art['xorg']) {
require_once('validations.inc.php');
- $article = new EvtReq("[{$globals->asso('nom')}] " . $art['titre'],
- MiniWiki::WikiToHTML($art['texte'] . (!empty($art['contact_html']) ? "\n\nContacts :\n" . $art['contact_html'] : "")),
- $art['promo_min'], $art['promo_max'], $art['peremption'], "", S::v('uid'));
+ $article = new EvtReq("[{$globals->asso('nom')}] " . $art['titre'], $fulltext,
+ $art['promo_min'], $art['promo_max'], $art['peremption'], "", S::user(),
+ $upload);
$article->submit();
- $page->trig("L'affichage sur la page d'accueil de Polytechnique.org est en attente de validation");
+ $page->trigWarning("L'affichage sur la page d'accueil de Polytechnique.org est en attente de validation.");
+ } else if ($upload && $upload->exists()) {
+ $upload->rm();
}
if ($art['nl']) {
require_once('validations.inc.php');
- $article = new NLReq(S::v('uid'), $globals->asso('nom') . " : " .$art['titre'],
+ $article = new NLReq(S::user(), $globals->asso('nom') . " : " .$art['titre'],
$art['texte'], $art['contact_html']);
$article->submit();
- $page->trig("La parution dans la Lettre Mensuelle est en attente de validation");
+ $page->trigWarning("La parution dans la Lettre Mensuelle est en attente de validation.");
}
} else {
XDB::query("UPDATE groupex.announces
@@ -1061,46 +1338,37 @@ class XnetGrpModule extends PLModule
promo_min={?}, promo_max={?}, flags={?}
WHERE id={?} AND asso_id={?}",
$art['titre'], $art['texte'], $art['contacts'], $art['peremption'],
- $promo_min, $promo_max, $art['public'] ? 'public' : '',
+ $promo_min, $promo_max, $flags,
$art['id'], $globals->asso('id'));
+ if ($art['photo'] && $upload->exists()) {
+ list($imgx, $imgy, $imgtype) = $upload->imageInfo();
+ XDB::execute("REPLACE INTO groupex.announces_photo
+ SET eid = {?}, attachmime = {?}, x = {?}, y = {?}, attach = {?}",
+ $aid, $imgtype, $imgx, $imgy, $upload->getContents());
+ $upload->rm();
+ }
}
}
if (Post::v('valid') == 'Enregistrer' || Post::v('valid') == 'Annuler') {
pl_redirect("");
- }
+ }
if (empty($art) && !is_null($aid)) {
- $res = XDB::query("SELECT a.*, u.nom, u.prenom, u.promo, l.alias AS forlife,
- FIND_IN_SET(a.flags, 'public') AS public
+ $res = XDB::query("SELECT a.*, u.nom, u.prenom, u.promo, u.hruid,
+ FIND_IN_SET('public', a.flags) AS public,
+ FIND_IN_SET('photo', a.flags) AS photo
FROM groupex.announces AS a
INNER JOIN auth_user_md5 AS u USING(user_id)
- INNER JOIN aliases AS l ON (l.id = u.user_id AND l.type = 'a_vie')
WHERE asso_id = {?} AND a.id = {?}",
$globals->asso('id'), $aid);
if ($res->numRows()) {
$art = $res->fetchOneAssoc();
$art['contact_html'] = $art['contacts'];
} else {
- $page->kill("Aucun article correspond à l'identifiant indiqué");
+ $page->kill("Aucun article correspond à l'identifiant indiqué.");
}
}
- $select = '';
- for ($i = 1 ; $i < 30 ; $i++) {
- $time = time() + 3600 * 24 * $i;
- $p_stamp = date('Ymd', $time);
- $year = date('Y', $time);
- $month = date('m', $time);
- $day = date('d', $time);
-
- $select .= "\n";
- }
- $page->assign('select', $select);
-
if (is_null($aid)) {
$events = XDB::iterator("SELECT *
FROM groupex.evenements
@@ -1109,26 +1377,28 @@ class XnetGrpModule extends PLModule
if ($events->total()) {
$page->assign('events', $events);
}
- }
+ }
- $art['contact_html'] = MiniWiki::WikiToHTML($art['contact_html']);
+ $art['contact_html'] = @MiniWiki::WikiToHTML($art['contact_html']);
$page->assign('art', $art);
+ $page->assign_by_ref('upload', $upload);
}
function handler_admin_announce(&$page)
{
global $globals;
- new_groupadmin_page('xnetgrp/announce-admin.tpl');
+ $page->changeTpl('xnetgrp/announce-admin.tpl');
if (Env::has('del')) {
- XDB::execute("DELETE FROM groupex.announces
- WHERE id = {?} AND asso_id = {?}",
+ S::assert_xsrf_token();
+ XDB::execute("DELETE FROM groupex.announces
+ WHERE id = {?} AND asso_id = {?}",
Env::i('del'), $globals->asso('id'));
}
- $res = XDB::iterator("SELECT a.id, a.titre, a.peremption, a.peremption < CURRENT_DATE() AS perime
- FROM groupex.announces AS a
- WHERE a.asso_id = {?}
- ORDER BY a.peremption DESC",
+ $res = XDB::iterator("SELECT a.id, a.titre, a.peremption, a.peremption < CURRENT_DATE() AS perime
+ FROM groupex.announces AS a
+ WHERE a.asso_id = {?}
+ ORDER BY a.peremption DESC",
$globals->asso('id'));
$page->assign('articles', $res);
}