X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;ds=sidebyside;f=modules%2Fxnetgrp.php;h=7bc12ae0b261b56b4a68958d59b162c046daa218;hb=34d91db6f55ab5398dbcde7cc10aaa5b5f8263a8;hp=a9a981548e014b399a178ab2e6fc6599da7b0f41;hpb=4af7fd22ba1dfbc9c042bbeafdbbedf9d7ecee06;p=platal.git
diff --git a/modules/xnetgrp.php b/modules/xnetgrp.php
index a9a9815..7bc12ae 100644
--- a/modules/xnetgrp.php
+++ b/modules/xnetgrp.php
@@ -1,6 +1,6 @@
$this->make_hook('index', AUTH_PUBLIC),
- '%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, '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/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, 'groupadmin'),
-
- '%grp/member'
- => $this->make_hook('admin_member', AUTH_MDP, 'groupadmin'),
- '%grp/member/new'
- => $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),
- '%grp/member/del'
- => $this->make_hook('admin_member_del', AUTH_MDP, 'groupadmin'),
-
- '%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'),
+ '%grp' => $this->make_hook('index', AUTH_PUBLIC),
+ '%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, '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/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, 'groupadmin'),
+ '%grp/member' => $this->make_hook('admin_member', AUTH_MDP, 'groupadmin'),
+ '%grp/member/new' => $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),
+ '%grp/member/del' => $this->make_hook('admin_member_del', AUTH_MDP, 'groupadmin'),
+
+ '%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'),
);
}
@@ -122,7 +115,7 @@ class XnetGrpModule extends PLModule
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()');
@@ -137,11 +130,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 <= {?})
@@ -179,7 +171,7 @@ class XnetGrpModule extends PLModule
$platal->ns . "rss/rss.xml");
} else {
$page->setRssLink("Polytechnique.net :: {$globals->asso("nom")} :: News",
- $platal->ns . '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->assign('articles', $arts);
@@ -233,10 +225,19 @@ class XnetGrpModule extends PLModule
if (Post::has('submit')) {
S::assert_xsrf_token();
- $flags = new FlagSet('wiki_desc');
+ $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->trigError("le domaine doit être un FQDN (aucune modif effectuée) !!!");
@@ -252,7 +253,7 @@ class XnetGrpModule extends PLModule
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::v('pub'),
@@ -269,7 +270,7 @@ class XnetGrpModule extends PLModule
forum={?}, ax={?}, pub= {?}, sub_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::v('pub'),
@@ -309,9 +310,11 @@ class XnetGrpModule extends PLModule
$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');
@@ -319,15 +322,21 @@ 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);
- $upload = PlUpload::get($_FILES['uploaded'], S::v('forlife'), 'xnet.emails', true);
+
+ $upload = PlUpload::get($_FILES['uploaded'], S::user()->login(), 'xnet.emails', true);
+ if (!$upload && @$_FILES['uploaded']['name'] && PlUpload::$lastError != null) {
+ $page->trigError(PlUpload::$lastError);
+ return;
+ }
+
send_xnet_mails($from, $sujet, $body, Env::v('wiki'), $tos, Post::v('replyto'), $upload, @$_FILES['uploaded']['name']);
if ($upload) {
$upload->rm();
}
- $page->kill("Mail envoyé !");
+ $page->killSuccess("Email envoyé !");
$page->assign('sent', true);
}
}
@@ -478,8 +487,9 @@ class XnetGrpModule extends PLModule
$res = XDB::query('SELECT uid
FROM groupex.membres
WHERE asso_id = {?}', $globals->asso('id'));
- $vcard = new VCard($res->fetchColumn(), $photos == 'photos', 'Membre du groupe ' . $globals->asso('nom'));
- $vcard->do_page($page);
+ $vcard = new VCard($photos == 'photos', 'Membre du groupe ' . $globals->asso('nom'));
+ $vcard->addUsers($res->fetchColumn());
+ $vcard->show();
}
function handler_csv(&$page, $filename = null)
@@ -518,28 +528,29 @@ class XnetGrpModule extends PLModule
$globals->asso('id'), $uid);
}
- private function validSubscription($nom, $prenom, $sexe, $uid, $forlife)
+ private function validSubscription(User &$user)
{
global $globals;
- $this->removeSubscriptionRequest($uid);
- XDB::execute("INSERT INTO groupex.membres (asso_id, uid)
- VALUES ({?}, {?})",
- $globals->asso('id'), $uid);
- $mailer = new PlMailer();
- $mailer->addTo("$forlife@polytechnique.org");
- $mailer->setFrom('"' . S::v('prenom') . ' ' . S::v('nom')
- . '" <' . S::v('forlife') . '@polytechnique.org>');
- $mailer->setSubject('[' . $globals->asso('nom') . '] Demande d\'inscription');
- $message = ($sexe ? '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::s('prenom') . ' ' . S::s('nom') . '.';
- $mailer->setTxtBody($message);
- $mailer->send();
+ $this->removeSubscriptionRequest($user->id());
+ XDB::execute("INSERT IGNORE INTO groupex.membres (asso_id, uid)
+ VALUES ({?}, {?})",
+ $globals->asso('id'), $user->id());
+ if (XDB::affectedRows() == 1) {
+ $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)
@@ -553,52 +564,51 @@ class XnetGrpModule extends PLModule
."sur la page de présentation.");
if (!is_null($u) && may_update()) {
- $page->assign('u', $u);
- $res = XDB::query("SELECT u.nom, u.prenom, u.promo, u.user_id, FIND_IN_SET('femme', u.flags), s.reason
- FROM auth_user_md5 AS u
- INNER JOIN aliases AS al ON (al.id = u.user_id AND al.type != 'liste')
- LEFT JOIN groupex.membres_sub_requests AS s ON (u.user_id = s.uid AND s.asso_id = {?})
- WHERE al.alias = {?}", $globals->asso('id'), $u);
-
- if (list($nom, $prenom, $promo, $uid, $sexe, $reason) = $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) {
- $this->removeSubscriptionRequest($uid);
- $page->kill("$prenom $nom est déjà membre du groupe !");
- return;
- }
- elseif (Env::has('accept'))
- {
- $this->validSubscription($nom, $prenom, $sexe, $uid, $u);
- pl_redirect("member/$u");
- }
- elseif (Env::has('refuse'))
- {
- $this->removeSubscriptionRequest($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 annulée');
- $mailer->setTxtBody(Env::v('motif'));
- $mailer->send();
- $page->kill("La demande de $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);
- $page->assign('reason', $reason);
- }
- 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->killSuccess("La demande de {$user->fullName()} a bien été refusée.");
+ } else {
+ $page->assign('show_form', true);
+ $page->assign('reason', $reason);
+ }
+ return;
}
if (is_member()) {
@@ -616,6 +626,8 @@ class XnetGrpModule extends PLModule
}
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'));
@@ -633,12 +645,10 @@ class XnetGrpModule extends PLModule
$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";
@@ -653,8 +663,7 @@ 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();
@@ -670,17 +679,11 @@ class XnetGrpModule extends PLModule
$subs = Post::v('subs');
if (is_array($subs)) {
$users = array();
- foreach ($subs as $forlife => $val) {
+ foreach ($subs as $hruid => $val) {
if ($val == '1') {
- $res = XDB::query("SELECT IF(u.nom_usage != '', u.nom_usage, u.nom) AS u,
- u.prenom, FIND_IN_SET('femme', u.flags) AS sexe,
- u.user_id
- FROM auth_user_md5 AS u
- INNER JOIN aliases AS a ON (a.id = u.user_id)
- WHERE a.alias = {?}", $forlife);
- if ($res->numRows() == 1) {
- list($nom, $prenom, $sexe, $uid) = $res->fetchOneRow();
- $this->validSubscription($nom, $prenom, $sexe, $uid, $forlife);
+ $user = User::get($hruid);
+ if ($user) {
+ $this->validSubscription($user);
}
}
}
@@ -688,10 +691,9 @@ class XnetGrpModule extends PLModule
}
$it = XDB::iterator("SELECT IF(u.nom_usage != '', u.nom_usage, u.nom) AS nom,
- u.prenom, u.promo, a.alias AS forlife, s.ts AS date
+ 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)
- INNER JOIN aliases AS a ON (a.id = s.uid AND a.type = 'a_vie')
WHERE asso_id = {?}
ORDER BY nom, prenom",
$globals->asso('id'));
@@ -705,25 +707,26 @@ class XnetGrpModule extends PLModule
if (Env::has('right') && (may_update() || S::has('suid'))) {
switch (Env::v('right')) {
case 'admin':
- XnetSession::killSuid();
+ 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;
}
}
+// var_dump($_SESSION);
http_redirect($_SERVER['HTTP_REFERER']);
}
@@ -731,7 +734,7 @@ class XnetGrpModule extends PLModule
{
global $globals;
- require_once dirname(__FILE__) . '/xnetgrp/mail.inc.php';
+ $this->load('mail.inc.php');
$page->changeTpl('xnetgrp/annuaire-admin.tpl');
$mmlist = new MMList(S::v('uid'), S::v('password'),
$globals->asso('mail_domain'));
@@ -782,31 +785,19 @@ class XnetGrpModule extends PLModule
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/$forlife");
- } else {
- $page->trigError($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');
@@ -822,8 +813,8 @@ class XnetGrpModule extends PLModule
$market->add();
}
}
- XDB::execute('INSERT INTO groupex.membres (uid, asso_id, origine, email)
- VALUES ({?}, {?}, "X", {?})',
+ XDB::execute('REPLACE INTO groupex.membres (uid, asso_id, origine, email)
+ VALUES ({?}, {?}, "X", {?})',
$uid, $globals->asso('id'), $email);
$this->removeSubscriptionRequest($uid);
pl_redirect("member/$email");
@@ -832,13 +823,13 @@ class XnetGrpModule extends PLModule
} else {
$res = XDB::query('SELECT MAX(uid)+1 FROM groupex.membres');
$uid = max(intval($res->fetchOneCell()), 50001);
- XDB::execute('INSERT INTO groupex.membres (uid,asso_id,origine,email)
- VALUES({?},{?},"ext",{?})', $uid,
- $globals->asso('id'), $email);
+ XDB::execute('REPLACE INTO groupex.membres (uid, asso_id, origine, email)
+ VALUES ({?}, {?}, "ext", {?})',
+ $uid, $globals->asso('id'), $email);
pl_redirect("member/$email");
}
} else {
- $page->trigError("« $email » n'est pas une adresse mail valide.");
+ $page->trigError("« $email » n'est pas une adresse email valide.");
}
}
}
@@ -879,7 +870,7 @@ class XnetGrpModule extends PLModule
function unsubscribe(&$user)
{
- global $globals, $page;
+ global $globals;
XDB::execute(
"DELETE FROM groupex.membres WHERE uid={?} AND asso_id={?}",
$user['uid'], $globals->asso('id'));
@@ -923,9 +914,9 @@ class XnetGrpModule extends PLModule
$mmlist->unsubscribe($liste['list']);
}
} elseif ($liste['sub']) {
- $page->trigWarning("{$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;
}
}
@@ -941,7 +932,7 @@ class XnetGrpModule extends PLModule
function handler_unsubscribe(&$page)
{
$page->changeTpl('xnetgrp/membres-del.tpl');
- $user = get_infos(S::v('forlife'));
+ $user = get_infos(S::user()->id());
if (empty($user)) {
return PL_NOT_FOUND;
}
@@ -950,12 +941,14 @@ class XnetGrpModule extends PLModule
if (!Post::has('confirm')) {
return;
+ } else {
+ S::assert_xsrf_token();
}
if ($this->unsubscribe($user)) {
$page->trigSuccess('Vous avez été désinscrit du groupe avec succès.');
} else {
- $page->trigWarning('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));
}
@@ -971,6 +964,8 @@ class XnetGrpModule extends PLModule
if (!Post::has('confirm')) {
return;
+ } else {
+ S::assert_xsrf_token();
}
if ($this->unsubscribe($user)) {
@@ -980,7 +975,7 @@ class XnetGrpModule extends PLModule
}
}
- private function changeLogin(PlatalPage &$page, array &$user, MMList &$mmlist, $login)
+ private function changeLogin(PlPage &$page, array &$user, MMList &$mmlist, $login)
{
require_once 'user.func.inc.php';
// Search the uid of the user...
@@ -1064,6 +1059,8 @@ 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')));
@@ -1172,32 +1169,14 @@ class XnetGrpModule extends PLModule
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);
-
- 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,
- FIND_IN_SET('photo', a.flags) AS photo
- 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'));
- } 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('public', a.flags) AND peremption >= NOW() AND a.asso_id = {?}",
- $globals->asso('id'));
- }
$page->assign('asso', $globals->asso());
- $page->assign('rss', $rss);
+
+ $this->load('feed.inc.php');
+ $feed = new XnetGrpEventFeed();
+ return $feed->run($page, $user, $hash, false);
}
- private function upload_image(PlatalPage &$page, PlUpload &$upload)
+ private function upload_image(PlPage &$page, PlUpload &$upload)
{
if (@!$_FILES['image']['tmp_name'] && !Env::v('image_url')) {
return true;
@@ -1226,7 +1205,7 @@ class XnetGrpModule extends PLModule
exit;
}
} else {
- $upload = new PlUpload(S::v('forlife'), 'xnetannounce');
+ $upload = new PlUpload(S::user()->login(), 'xnetannounce');
if ($upload->exists() && $upload->isType('image')) {
header('Content-Type: ' . $upload->contentType());
echo $upload->getContents();
@@ -1248,6 +1227,8 @@ class XnetGrpModule extends PLModule
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;
}
@@ -1259,13 +1240,13 @@ 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::v('forlife'), 'xnetannounce');
+ $upload = new PlUpload(S::user()->login(), 'xnetannounce');
$this->upload_image($page, $upload);
$art['contact_html'] = $art['contacts'];
@@ -1303,7 +1284,7 @@ class XnetGrpModule extends PLModule
if (Post::v('valid') == 'Enregistrer') {
$promo_min = ($art['public'] ? 0 : $art['promo_min']);
$promo_max = ($art['public'] ? 0 : $art['promo_max']);
- $flags = new FlagSet();
+ $flags = new PlFlagSet();
if ($art['public']) {
$flags->addFlag('public');
}
@@ -1318,7 +1299,7 @@ class XnetGrpModule extends PLModule
$post = null;/*
if ($globals->asso('forum')) {
require_once 'banana/forum.inc.php';
- $banana = new ForumsBanana(S::v('forlife'));
+ $banana = new ForumsBanana(S::user());
$post = $banana->post($globals->asso('forum'), null,
$art['titre'], MiniWiki::wikiToText($fulltext, false, 0, 80));
}*/
@@ -1338,7 +1319,7 @@ class XnetGrpModule extends PLModule
if ($art['xorg']) {
require_once('validations.inc.php');
$article = new EvtReq("[{$globals->asso('nom')}] " . $art['titre'], $fulltext,
- $art['promo_min'], $art['promo_max'], $art['peremption'], "", S::v('uid'),
+ $art['promo_min'], $art['promo_max'], $art['peremption'], "", S::user(),
$upload);
$article->submit();
$page->trigWarning("L'affichage sur la page d'accueil de Polytechnique.org est en attente de validation.");
@@ -1347,7 +1328,7 @@ class XnetGrpModule extends PLModule
}
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->trigWarning("La parution dans la Lettre Mensuelle est en attente de validation.");
@@ -1374,12 +1355,11 @@ class XnetGrpModule extends PLModule
}
if (empty($art) && !is_null($aid)) {
- $res = XDB::query("SELECT a.*, u.nom, u.prenom, u.promo, l.alias AS forlife,
+ $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()) {
@@ -1411,6 +1391,7 @@ class XnetGrpModule extends PLModule
$page->changeTpl('xnetgrp/announce-admin.tpl');
if (Env::has('del')) {
+ S::assert_xsrf_token();
XDB::execute("DELETE FROM groupex.announces
WHERE id = {?} AND asso_id = {?}",
Env::i('del'), $globals->asso('id'));