X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=modules%2Fxnetgrp.php;h=7cf8d267656d7f62f74559270b77c3e745c90a4f;hb=28c20b86be8b40cecba0d83080879f81c49e07ad;hp=3b43dd295748a4aee77c4a20d076d64487e935cd;hpb=353f2d2b11c4e3c6c0bc3553813368b6f42fa9c6;p=platal.git
diff --git a/modules/xnetgrp.php b/modules/xnetgrp.php
index 3b43dd2..7cf8d26 100644
--- a/modules/xnetgrp.php
+++ b/modules/xnetgrp.php
@@ -1,6 +1,6 @@
= CURRENT_DATE()
+ FROM group_announces AS a
+ LEFT JOIN group_announces_read AS r ON (r.uid = {?} AND r.announce_id = a.id)
+ WHERE asso_id = {?} AND expiration >= CURRENT_DATE()
AND (promo_min = 0 OR promo_min <= {?})
AND (promo_max = 0 OR promo_max >= {?})
AND r.announce_id IS NULL
- ORDER BY a.peremption",
+ ORDER BY a.expiration",
S::i('uid'), $globals->asso('id'), S::i('promo'), S::i('promo'));
- $index = XDB::iterator("SELECT a.id, a.titre, r.user_id IS NULL AS nonlu
- FROM #groupex#.announces AS a
- LEFT JOIN #groupex#.announces_read AS r ON (a.id = r.announce_id AND r.user_id = {?})
- WHERE asso_id = {?} AND peremption >= CURRENT_DATE()
+ $index = XDB::iterator("SELECT a.id, a.titre, r.uid IS NULL AS nonlu
+ FROM group_announces AS a
+ LEFT JOIN group_announces_read AS r ON (a.id = r.announce_id AND r.uid = {?})
+ WHERE asso_id = {?} AND expiration >= CURRENT_DATE()
AND (promo_min = 0 OR promo_min <= {?})
AND (promo_max = 0 OR promo_max >= {?})
- ORDER BY a.peremption",
+ ORDER BY a.expiration",
S::i('uid'), $globals->asso('id'), S::i('promo'), S::i('promo'));
$page->assign('article_index', $index);
} else {
- $arts = XDB::iterator("SELECT a.*, FIND_IN_SET('photo', a.flags) AS photo
- FROM #groupex#.announces AS a
- WHERE asso_id = {?} AND peremption >= CURRENT_DATE()
- AND FIND_IN_SET('public', a.flags)",
+ $arts = XDB::iterator("SELECT *, FIND_IN_SET('photo', flags) AS photo
+ FROM group_announces
+ WHERE asso_id = {?} AND expiration >= CURRENT_DATE()
+ AND FIND_IN_SET('public', flags)",
$globals->asso('id'));
}
if (may_update()) {
$subs_valid = XDB::query("SELECT uid
- FROM #groupex#.membres_sub_requests
+ FROM group_member_sub_requests
WHERE asso_id = {?}",
$globals->asso('id'));
$page->assign('requests', $subs_valid->numRows());
@@ -129,15 +129,7 @@ class XnetGrpModule extends PLModule
function handler_logo(&$page)
{
global $globals;
-
- $res = XDB::query("SELECT logo, logo_mime
- FROM #groupex#.asso
- WHERE id = {?}",
- $globals->asso('id'));
- list($logo, $logo_mime) = $res->fetchOneRow();
-
- pl_cached_dynamic_content_headers(empty($logo) ? "image/jpeg" : $logo_mime);
- exit;
+ $globals->asso()->getLogo()->send();
}
function handler_site(&$page)
@@ -171,13 +163,19 @@ class XnetGrpModule extends PLModule
} else {
$site = "";
}
- if (S::has_perms()) {
+ if (S::admin()) {
+ $page->assign('super', true);
+
if (Post::v('mail_domain') && (strstr(Post::v('mail_domain'), '.') === false)) {
$page->trigError('Le domaine doit être un FQDN (aucune modification effectuée) !!!');
return;
}
+ if (Post::t('nom') == '' || Post::t('diminutif') == '') {
+ $page->trigError('Ni le nom ni le diminutif du groupe ne peuvent être vide.');
+ return;
+ }
XDB::execute(
- "UPDATE #groupex#.asso
+ "UPDATE groups
SET nom={?}, diminutif={?}, cat={?}, dom={?},
descr={?}, site={?}, mail={?}, resp={?},
forum={?}, mail_domain={?}, ax={?}, pub={?},
@@ -198,7 +196,7 @@ class XnetGrpModule extends PLModule
}
} else {
XDB::execute(
- "UPDATE #groupex#.asso
+ "UPDATE groups
SET descr={?}, site={?}, mail={?}, resp={?},
forum={?}, pub= {?}, sub_url={?},
unsub_url={?},flags={?}
@@ -216,7 +214,7 @@ class XnetGrpModule extends PLModule
if (!$upload) {
$page->trigError("Impossible de télécharger le logo.");
} else {
- XDB::execute('UPDATE #groupex#.asso
+ XDB::execute('UPDATE groups
SET logo = {?}, logo_mime = {?}
WHERE id = {?}', $upload->getContents(), $upload->contentType(),
$globals->asso('id'));
@@ -224,11 +222,13 @@ class XnetGrpModule extends PLModule
}
}
- pl_redirect('../'.Post::v('diminutif', $globals->asso('diminutif')).'/edit');
+ pl_redirect('../' . Post::v('diminutif', $globals->asso('diminutif')) . '/edit');
}
if (S::admin()) {
- $dom = XDB::iterator('SELECT * FROM #groupex#.dom ORDER BY nom');
+ $dom = XDB::iterator('SELECT *
+ FROM group_dom
+ ORDER BY nom');
$page->assign('dom', $dom);
$page->assign('super', true);
}
@@ -290,20 +290,25 @@ class XnetGrpModule extends PLModule
{
global $globals;
- 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();
+ if ($action == 'trombi') {
+ __autoload('userset');
+ if ($action == 'trombi') {
+ $view = new ProfileSet(new UFC_Group($globals->asso('id')));
+ } else {
+ $view = new UserSet(new UFC_Group($globals->asso('id')));
+ }
$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');
+ $count = XDB::fetchOneCell('SELECT COUNT(*)
+ FROM group_members
+ WHERE asso_id = {?}',
+ $globals->asso('id'));
+ $page->assign('nb_tot', $count);
+ return;
}
- $page->changeTpl('xnetgrp/annuaire.tpl');
+ $page->changeTpl('xnetgrp/annuaire.tpl');
$sort = Env::s('order', 'directory_name');
$ofs = Env::i('offset');
if ($ofs < 0) {
@@ -319,13 +324,14 @@ class XnetGrpModule extends PLModule
}
if (Env::b('admin')) {
- $uf = $globals->asso()->getAdmins(null, $se);
+ $uf = $globals->asso()->getAdminsFilter(null, $se);
} else {
- $uf = $globals->asso()->getMembers(null, $se);
+ $uf = $globals->asso()->getMembersFilter(null, $se);
}
- $users = $uf->getUsers(NB_PER_PAGE, $ofs * NB_PER_PAGE);
+ $users = $uf->getUsers(new PlLimit(NB_PER_PAGE, $ofs * NB_PER_PAGE));
$count = $uf->getTotalCount();
+ $page->assign('nb_tot', $count);
$page->assign('pages', floor(($count + NB_PER_PAGE - 1) / NB_PER_PAGE));
$page->assign('current', $ofs);
$page->assign('order', $sort);
@@ -347,7 +353,7 @@ class XnetGrpModule extends PLModule
{
global $globals;
$vcard = new VCard($photos == 'photos', 'Membre du groupe ' . $globals->asso('nom'));
- $vcard->addUsers($globals->asso()->getMembers()->getUIDs());
+ $vcard->addProfiles($globals->asso()->getMembersFilter()->getProfiles());
$vcard->show();
}
@@ -357,10 +363,7 @@ class XnetGrpModule extends PLModule
if (is_null($filename)) {
$filename = $globals->asso('diminutif') . '.csv';
}
- $users = $globals->asso()->getMembers(null, new UFO_Name('directory_name'))->getUsers();
- header('Content-Type: text/x-csv; charset=utf-8;');
- header('Pragma: ');
- header('Cache-Control: ');
+ $users = $globals->asso()->getMembersFilter(null, new UFO_Name('directory_name'))->getUsers();
pl_content_headers("text/x-csv");
$page->changeTpl('xnetgrp/annuaire-csv.tpl', NO_SKIN);
$page->assign('users', $users);
@@ -369,7 +372,7 @@ class XnetGrpModule extends PLModule
private function removeSubscriptionRequest($uid)
{
global $globals;
- XDB::execute("DELETE FROM #groupex#.membres_sub_requests
+ XDB::execute("DELETE FROM group_member_sub_requests
WHERE asso_id = {?} AND uid = {?}",
$globals->asso('id'), $uid);
}
@@ -378,7 +381,7 @@ class XnetGrpModule extends PLModule
{
global $globals;
$this->removeSubscriptionRequest($user->id());
- XDB::execute("INSERT IGNORE INTO #groupex#.membres (asso_id, uid)
+ XDB::execute("INSERT IGNORE INTO group_members (asso_id, uid)
VALUES ({?}, {?})",
$globals->asso('id'), $user->id());
if (XDB::affectedRows() == 1) {
@@ -419,13 +422,13 @@ class XnetGrpModule extends PLModule
// Retrieves the subscription status, and the reason.
$res = XDB::query("SELECT reason
- FROM #groupex#.membres_sub_requests
+ FROM group_member_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
+ FROM group_members
WHERE asso_id = {?} AND uid = {?}",
$globals->asso('id'), $user->id());
$already_member = ($res->fetchOneCell() > 0);
@@ -463,7 +466,7 @@ class XnetGrpModule extends PLModule
}
$res = XDB::query("SELECT uid
- FROM #groupex#.membres_sub_requests
+ FROM group_member_sub_requests
WHERE uid = {?} AND asso_id = {?}",
S::i('uid'), $globals->asso('id'));
if ($res->numRows() != 0) {
@@ -474,19 +477,16 @@ 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)
+ XDB::execute("INSERT INTO group_member_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 #x4dat#.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);
+ $uf = New UserFilter(New UFC_Group($globals->asso('id'), true));
+ $admins = $uf->iterUsers();
+ $admin = $admins->next();
+ $to = $admin->bestalias;
+ while ($admin = $admins->next()) {
+ $to .= ', ' . $admin->bestalias;
+ }
$append = "\n"
. "-- \n"
@@ -538,8 +538,8 @@ class XnetGrpModule extends PLModule
}
$it = XDB::iterator('SELECT s.uid, a.hruid, s.ts AS date
- FROM #groupex#.membres_sub_requests AS s
- INNER JOIN #x4dat#.accounts AS a ON(s.uid = a.uid)
+ FROM group_member_sub_requests AS s
+ INNER JOIN accounts AS a ON(s.uid = a.uid)
WHERE s.asso_id = {?}
ORDER BY s.ts', $globals->asso('id'));
$page->changeTpl('xnetgrp/subscribe-valid.tpl');
@@ -597,7 +597,7 @@ class XnetGrpModule extends PLModule
$not_in_group_ext = array();
foreach ($subscribers as $mail) {
- $uf = new UserFilter(new UFC_And(new UFC_Group($globals->asso('id')),
+ $uf = new UserFilter(new PFC_And(new UFC_Group($globals->asso('id')),
new UFC_Email($mail)));
if ($uf->getTotalCount() == 0) {
if (User::isForeignEmailAddress($mail)) {
@@ -622,51 +622,60 @@ class XnetGrpModule extends PLModule
if (is_null($email)) {
return;
- } else {
- S::assert_xsrf_token();
}
+ S::assert_xsrf_token();
+
+ // Finds or creates account
if (!User::isForeignEmailAddress($email)) {
+ // standard x account
$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 if (!isvalid_email($email)) {
+ // email might not be a regular email but an alias or a hruid
+ $user = User::get($email);
+ if (!$user) {
+ // need a valid email address
+ $page->trigError("« $email » n'est pas une adresse email valide.");
+ return;
}
- } else {
- if (isvalid_email($email)) {
- if (Env::v('x') && Env::i('userid')) {
- $uid = Env::i('userid');
- $user = User::getWithUID($uid);
- if ($user && $user->state == 'pending') {
- if (Env::v('market')) {
- $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('REPLACE INTO #groupex#.membres (uid, asso_id, origine, email)
- VALUES ({?}, {?}, "X", {?})',
- $uid, $globals->asso('id'), $email);
- $this->removeSubscriptionRequest($uid);
- pl_redirect("member/$email");
- }
- $page->trigError("Utilisateur invalide");
- } else {
- $res = XDB::query('SELECT MAX(uid) + 1 FROM #groupex#.membres');
- $uid = max(intval($res->fetchOneCell()), 50001);
- XDB::execute('REPLACE INTO #groupex#.membres (uid, asso_id, origine, email)
- VALUES ({?}, {?}, "ext", {?})',
- $uid, $globals->asso('id'), $email);
- pl_redirect("member/$email");
+ } else if (Env::v('x') && Env::i('userid')) {
+ // user is an x but might not yet be registered
+ $user = User::getWithUID(Env::i('userid'));
+ if (!$user) {
+ $page->trigError("Utilisateur invalide");
+ return;
+ }
+ // add email for marketing if unknown
+ if ($user->state == 'pending' && Env::v('market')) {
+ $market = Marketing::get($user->uid, $email);
+ if (!$market) {
+ $market = new Marketing($user->uid, $email, 'group', $globals->asso('nom'),
+ Env::v('market_from'), S::v('uid'));
+ $market->add();
}
- } else {
- $page->trigError("« $email » n'est pas une adresse email valide.");
+ }
+ } else {
+ // user is not an x
+ $hruid = strtolower(str_replace('@','.',$email).'.ext');
+ // might already exists (in another group for example)
+ $user = User::get($hruid);
+ if (empty($user)) {
+ // creates new account: build names from email address
+ $display_name = ucwords(strtolower(substr($hruid, strpos('.', $hruid))));
+ $full_name = ucwords(strtolower(str_replace('.', ' ',substr($email, strpos('@', $email)))));
+ XDB::execute("INSERT INTO accounts (hruid, display_name, full_name, email, type)
+ VALUES({?}, {?}, {?}, {?}, 'xnet')",
+ $hruid, $display_name, $full_name, $email);
+ $user = User::get($hruid);
}
}
+ if ($user) {
+ XDB::execute("REPLACE INTO group_members (uid, asso_id)
+ VALUES ({?}, {?})",
+ $user->id(), $globals->asso('id'));
+ $this->removeSubscriptionRequest($user->id());
+ pl_redirect("member/" . $user->login());
+ }
}
function handler_admin_member_new_ajax(&$page)
@@ -682,18 +691,18 @@ class XnetGrpModule extends PLModule
}
if (empty($users)) {
list($nom, $prenom) = str_replace(array('-', ' ', "'"), '%', array(Env::t('nom'), Env::t('prenom')));
- $cond = new UFC_And(new UFC_Not(new UFC_Registered()));
+ $cond = new PFC_And(new PFC_Not(new UFC_Registered()));
if (!empty($nom)) {
- $cond->addChild(new UFC_Name(UserFilter::LASTNAME, $nom, UFC_Name::CONTAINS));
+ $cond->addChild(new UFC_Name(Profile::LASTNAME, $nom, UFC_Name::CONTAINS));
}
if (!empty($prenom)) {
- $cond->addChild(new UFC_Name(UserFilter::FIRSTNAME, $prenom, UFC_Name::CONTAINS));
+ $cond->addChild(new UFC_Name(Profile::FIRSTNAME, $prenom, UFC_Name::CONTAINS));
}
if (Env::i('promo')) {
$cond->addChild(new UFC_Promo('=', UserFilter::GRADE_ING, Env::i('promo')));
}
$uf = new UserFilter($cond);
- $users = $uf->getUsers(30);
+ $users = $uf->getUsers(new PlLimit(30));
if ($uf->getTotalCount() > 30) {
$page->assign('too_many', true);
$users = array();
@@ -705,14 +714,15 @@ class XnetGrpModule extends PLModule
function unsubscribe(PlUser &$user)
{
global $globals;
- XDB::execute("DELETE FROM #groupex#.membres
+ XDB::execute("DELETE FROM group_members
WHERE uid = {?} AND asso_id = {?}",
$user->id(), $globals->asso('id'));
if ($globals->asso('notif_unsub')) {
$mailer = new PlMailer('xnetgrp/unsubscription-notif.mail.tpl');
- foreach ($globals->asso()->getMembers()->getUsers() as $user) {
- $mailer->addTo($user);
+ $admins = $globals->asso()->iterAdmins();
+ while ($admin = $admins->next()) {
+ $mailer->addTo($admin);
}
$mailer->assign('group', $globals->asso('nom'));
$mailer->assign('user', $user);
@@ -730,18 +740,20 @@ class XnetGrpModule extends PLModule
$may_update = may_update();
$warning = false;
- foreach ($listes as $liste) {
- if ($liste['sub'] == 2) {
- if ($may_update) {
- $mmlist->mass_unsubscribe($liste['list'], Array($user->forlifeEmail()));
- } else {
- $mmlist->unsubscribe($liste['list']);
+ if (is_array($listes)) {
+ foreach ($listes as $liste) {
+ if ($liste['sub'] == 2) {
+ if ($may_update) {
+ $mmlist->mass_unsubscribe($liste['list'], Array($user->forlifeEmail()));
+ } else {
+ $mmlist->unsubscribe($liste['list']);
+ }
+ } elseif ($liste['sub']) {
+ Platal::page()->trigWarning($user->fullName() . " a une"
+ ." demande d'inscription en cours sur la"
+ ." liste {$liste['list']}@ !");
+ $warning = true;
}
- } elseif ($liste['sub']) {
- Platal::page()->trigWarning($user->fullName() . " a une"
- ." demande d'inscription en cours sur la"
- ." liste {$liste['list']}@ !");
- $warning = true;
}
}
@@ -756,12 +768,13 @@ class XnetGrpModule extends PLModule
function handler_unsubscribe(&$page)
{
$page->changeTpl('xnetgrp/membres-del.tpl');
- $user = S::user()->id();
- if (empty($user)) {
+ $user = S::user();
+ $uid = S::user()->id();
+ if (empty($uid)) {
return PL_NOT_FOUND;
}
$page->assign('self', true);
- $page->assign('user', $user);
+ $page->assign('user', $uid);
if (!Post::has('confirm')) {
return;
@@ -801,71 +814,28 @@ class XnetGrpModule extends PLModule
private function changeLogin(PlPage &$page, PlUser &$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.");
+ $xuser = User::getSilent($login);
+ if (!$xuser) {
+ $accounts = User::getPendingAccounts($login);
+ if (!$accounts) {
+ $page->trigError("L'identifiant $login ne correspond à aucun X.");
return false;
- } else if (count($x) > 1) {
- $page->trigError("Le login $login correspond a plusieurs camarades.");
+ } else if (count($accounts) > 1) {
+ $page->trigError("L'identifiant $login correspond à plusieurs camarades.");
return false;
}
- $uid = $x[0]['user_id'];
+ $xuser = User::getSilent($accounts[0]['uid']);
$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 {
- $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;
+ if (!$xuser) {
+ return false;
}
- // 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'];
+ $user->mergeIn($xuser);
+
+ return $xuser->login();
}
function handler_admin_member(&$page, $user)
@@ -885,8 +855,7 @@ class XnetGrpModule extends PLModule
S::assert_xsrf_token();
// Convert user status to X
- if (Post::blank('login_X')) {
- // TODO: Rewrite changeLogin!!!
+ if (!Post::blank('login_X')) {
$forlife = $this->changeLogin($page, $user, $mmlist, Post::t('login_X'));
if ($forlife) {
pl_redirect('member/' . $forlife);
@@ -894,85 +863,89 @@ class XnetGrpModule extends PLModule
}
// Update user info
- $email_changed = ($user['origine'] != 'X' && strtolower($user['email']) != strtolower(Post::v('email')));
- $from_email = $user['email'];
- if ($user['origine'] != 'X') {
- $user['nom'] = Post::v('nom');
- $user['prenom'] = (Post::v('origine') == 'ext') ? Post::v('prenom') : '';
- $user['sexe'] = (Post::v('origine') == 'ext') ? Post::v('sexe') : 0;
- $user['origine'] = Post::v('origine');
- XDB::query('UPDATE #groupex#.membres
- 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['email'] = Post::v('email');
- $user['email2'] = Post::v('email');
- $page->trigSuccess('Données de l\'utilisateur mise à jour.');
+ $email_changed = (!$user->profile() && strtolower($user->forlifeEmail()) != strtolower(Post::v('email')));
+ $from_email = $user->forlifeEmail();
+ if (!$user->profile()) {
+ XDB::query('UPDATE accounts
+ SET full_name = {?}, display_name = {?}, sex = {?}, email = {?}, type = {?}
+ WHERE uid = {?}',
+ Post::v('full_name'), Post::v('display_name'), (Post::v('sex') == 'male')?'male':'female', Post::v('email'), (Post::v('type') == 'xnet')?'xnet':'virtual',
+ $user->id());
+ if (XDB::affectedRows()) {
+ $page->trigSuccess('Données de l\'utilisateur mise à jour.');
+ }
}
- $perms = Post::i('is_admin');
+ // Update group params for user
+ $perms = Post::v('group_perms');
$comm = Post::t('comm');
- if ($user['perms'] != $perms || $user['comm'] != $comm) {
- XDB::query('UPDATE #groupex#.membres
+ if ($user->group_perms != $perms || $user->group_comm != $comm) {
+ XDB::query('UPDATE group_members
SET perms = {?}, comm = {?}
WHERE uid = {?} AND asso_id = {?}',
- $perms ? 'admin' : 'membre', $comm,
- $user['uid'], $globals->asso('id'));
- if ($perms != $user['perms']) {
+ ($perms == 'admin') ? 'admin' : 'membre', $comm,
+ $user->id(), $globals->asso('id'));
+ if ($perms != $user->group_perms) {
$page->trigSuccess('Permissions modifiées !');
}
- if ($comm != $user['comm']) {
+ if ($comm != $user->group_comm) {
$page->trigSuccess('Commentaire mis à jour.');
}
- $user['perms'] = $perms;
- $user['comm'] = $comm;
}
+ // Gets user info again as they might have change
+ $user = User::getSilent($user->id());
+
// 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->trigSuccess("L'abonnement de {$user['prenom']} {$user['nom']} à $ml@ a été mis à jour.");
+ $mmlist->replace_email($ml, $from_email, $user->forlifeEmail());
+ $page->trigSuccess("L'abonnement de {$user->fullName()} à $ml@ a été mis à jour.");
}
continue;
}
if ($state == '1') {
- $page->trigWarning("{$user['prenom']} {$user['nom']} a "
+ $page->trigWarning("{$user->fullName()} a "
."actuellement une demande d'inscription en "
."cours sur $ml@ !!!");
} elseif ($ask) {
- $mmlist->mass_subscribe($ml, Array($user['email2']));
- $page->trigSuccess("{$user['prenom']} {$user['nom']} a été abonné à $ml@.");
+ $mmlist->mass_subscribe($ml, Array($user->forlifeEmail()));
+ $page->trigSuccess("{$user->fullName()} a été abonné à $ml@.");
} else {
if ($email_changed) {
$mmlist->mass_unsubscribe($ml, Array($from_email));
} else {
- $mmlist->mass_unsubscribe($ml, Array($user['email2']));
+ $mmlist->mass_unsubscribe($ml, Array($user->forlifeEmail()));
}
- $page->trigSuccess("{$user['prenom']} {$user['nom']} a été désabonné de $ml@.");
+ $page->trigSuccess("{$user->fullName()} 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;
- if($ask) {
+ if($state == $ask) {
+ if ($state && $email_changed) {
+ XDB::query("UPDATE virtual_redirect AS vr, virtual AS v
+ SET vr.redirect = {?}
+ WHERE vr.vid = v.vid AND v.alias = {?} AND vr.redirect = {?}",
+ $user->forlifeEmail(), $ml, $from_email);
+ $page->trigSuccess("L'abonnement de {$user->fullName()} à $ml a été mis à jour.");
+ }
+ } else if($ask) {
XDB::query("INSERT INTO virtual_redirect (vid,redirect)
SELECT vid,{?} FROM virtual WHERE alias={?}",
- $user['email'], $ml);
- $page->trigSuccess("{$user['prenom']} {$user['nom']} a été abonné à $ml.");
+ $user->forlifeEmail(), $ml);
+ $page->trigSuccess("{$user->fullName()} 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->trigSuccess("{$user['prenom']} {$user['nom']} a été désabonné de $ml.");
+ $from_email, $ml);
+ $page->trigSuccess("{$user->fullName()} a été désabonné de $ml.");
}
}
}
@@ -1013,7 +986,9 @@ class XnetGrpModule extends PLModule
function handler_photo_announce(&$page, $eid = null) {
if ($eid) {
- $res = XDB::query("SELECT * FROM #groupex#.announces_photo WHERE eid = {?}", $eid);
+ $res = XDB::query('SELECT *
+ FROM group_announces_photo
+ WHERE eid = {?}', $eid);
if ($res->numRows()) {
$photo = $res->fetchOneAssoc();
pl_cached_dynamic_content_headers("image/" . $photo['attachmime']);
@@ -1057,7 +1032,8 @@ class XnetGrpModule extends PLModule
$art['prenom'] = S::v('prenom');
$art['promo'] = S::v('promo');
$art['hruid'] = S::user()->login();
- $art['peremption'] = Post::v('peremption');
+ $art['uid'] = S::user()->id();
+ $art['expiration'] = Post::v('expiration');
$art['public'] = Post::has('public');
$art['xorg'] = Post::has('xorg');
$art['nl'] = Post::has('nl');
@@ -1090,7 +1066,8 @@ class XnetGrpModule extends PLModule
}
$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);
+ XDB::query('DELETE FROM group_announces_photo
+ WHERE eid = {?}', $aid);
$upload->rm();
Post::kill('valid');
$art['photo'] = false;
@@ -1119,23 +1096,22 @@ class XnetGrpModule extends PLModule
$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, post_id)
- VALUES ({?}, {?}, NOW(), {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})",
+ XDB::query('INSERT INTO group_announces (uid, asso_id, create_date, titre, texte, contacts,
+ expiration, 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, $flags, $post);
+ $art['expiration'], $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 = {?}",
+ XDB::execute('INSERT INTO group_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'], $fulltext,
- $art['promo_min'], $art['promo_max'], $art['peremption'], "", S::user(),
+ $art['promo_min'], $art['promo_max'], $art['expiration'], "", S::user(),
$upload);
$article->submit();
$page->trigWarning("L'affichage sur la page d'accueil de Polytechnique.org est en attente de validation.");
@@ -1150,16 +1126,16 @@ class XnetGrpModule extends PLModule
$page->trigWarning("La parution dans la Lettre Mensuelle est en attente de validation.");
}
} else {
- XDB::query("UPDATE #groupex#.announces
- SET titre={?}, texte={?}, contacts={?}, peremption={?},
- promo_min={?}, promo_max={?}, flags={?}
- WHERE id={?} AND asso_id={?}",
- $art['titre'], $art['texte'], $art['contacts'], $art['peremption'],
+ XDB::query('UPDATE group_announces
+ SET titre = {?}, texte = {?}, contacts = {?}, expiration = {?},
+ promo_min = {?}, promo_max = {?}, flags = {?}
+ WHERE id = {?} AND asso_id = {?}',
+ $art['titre'], $art['texte'], $art['contacts'], $art['expiration'],
$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
+ XDB::execute("REPLACE INTO group_announces_photo
SET eid = {?}, attachmime = {?}, x = {?}, y = {?}, attach = {?}",
$aid, $imgtype, $imgx, $imgy, $upload->getContents());
$upload->rm();
@@ -1171,10 +1147,10 @@ class XnetGrpModule extends PLModule
}
if (empty($art) && !is_null($aid)) {
- $res = XDB::query("SELECT a.*, FIND_IN_SET('public', a.flags) AS public,
- FIND_IN_SET('photo', a.flags) AS photo
- FROM #groupex#.announces AS a
- WHERE asso_id = {?} AND a.id = {?}",
+ $res = XDB::query("SELECT *, FIND_IN_SET('public', flags) AS public,
+ FIND_IN_SET('photo', flags) AS photo
+ FROM group_announces
+ WHERE asso_id = {?} AND id = {?}",
$globals->asso('id'), $aid);
if ($res->numRows()) {
$art = $res->fetchOneAssoc();
@@ -1186,7 +1162,7 @@ class XnetGrpModule extends PLModule
if (is_null($aid)) {
$events = XDB::iterator("SELECT *
- FROM #groupex#.evenements
+ FROM group_events
WHERE asso_id = {?} AND archive = 0",
$globals->asso('id'));
if ($events->total()) {
@@ -1206,14 +1182,14 @@ class XnetGrpModule extends PLModule
if (Env::has('del')) {
S::assert_xsrf_token();
- XDB::execute("DELETE FROM #groupex#.announces
- WHERE id = {?} AND asso_id = {?}",
+ XDB::execute('DELETE FROM group_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 id, titre, expiration, expiration < CURRENT_DATE() AS perime
+ FROM group_announces
+ WHERE asso_id = {?}
+ ORDER BY expiration DESC',
$globals->asso('id'));
$page->assign('articles', $res);
}