X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=modules%2Fxnetgrp.php;h=47f4a8da0e845409be2c7bf8a477a4fb4b6a4972;hb=c9566e01c2add8f12a858abe0fbb0bc6b8e3c0d4;hp=e34b6901cd110ba6499dc485de97c8b160ba9e7b;hpb=9f5bd98e936d8cef7ca9f774eeef64dbb8a1b079;p=platal.git
diff --git a/modules/xnetgrp.php b/modules/xnetgrp.php
index e34b690..47f4a8d 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('femme', flags) AS sexe
- FROM auth_user_md5
- WHERE user_id = {?}", $user['uid']);
- $user = array_merge($user, $res->fetchOneAssoc());
- }
- return $user;
- } elseif ($dom == 'polytechnique.org' || $dom == 'm4x.org') {
- $res = XDB::query(
- "SELECT user_id AS uid, u.promo,
- IF(u.nom_usage<>'', u.nom_usage, u.nom) AS nom,
- 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, m.comm,
- FIND_IN_SET('femme', u.flags) AS sexe
- FROM #x4dat#.auth_user_md5 AS u
- INNER JOIN #x4dat#.aliases AS a ON ( u.user_id = a.id AND a.type != 'homonyme' )
- INNER JOIN #x4dat#.aliases AS b ON ( u.user_id = b.id AND b.type = 'a_vie' )
- 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();
- }
-
- return null;
-}
-
class XnetGrpModule extends PLModule
{
@@ -77,37 +29,40 @@ 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, '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/edit' => $this->make_hook('edit', AUTH_PASSWD, 'groupadmin'),
+ '%grp/mail' => $this->make_hook('mail', AUTH_PASSWD, 'groupadmin'),
+ '%grp/forum' => $this->make_hook('forum', AUTH_PASSWD, 'groupmember'),
+ '%grp/former_users' => $this->make_hook('former_users', AUTH_PASSWD, 'admin'),
+ '%grp/annuaire' => $this->make_hook('annuaire', AUTH_PASSWD, 'groupannu'),
+ '%grp/annuaire/vcard' => $this->make_hook('vcard', AUTH_PASSWD, 'groupmember:groupannu'),
+ '%grp/annuaire/csv' => $this->make_hook('csv', AUTH_PASSWD, 'groupmember:groupannu'),
+ '%grp/directory/sync' => $this->make_hook('directory_sync', AUTH_PASSWD, 'groupadmin'),
+ '%grp/directory/unact' => $this->make_hook('non_active', AUTH_PASSWD, 'groupadmin'),
+ '%grp/trombi' => $this->make_hook('trombi', AUTH_PASSWD, 'groupannu'),
+ '%grp/geoloc' => $this->make_hook('geoloc', AUTH_PASSWD, 'groupannu'),
+ '%grp/subscribe' => $this->make_hook('subscribe', AUTH_PASSWD, 'groups'),
+ '%grp/subscribe/valid' => $this->make_hook('subscribe_valid', AUTH_PASSWD, 'groupadmin'),
+ '%grp/unsubscribe' => $this->make_hook('unsubscribe', AUTH_PASSWD, 'groupmember'),
+
+ '%grp/change_rights' => $this->make_hook('change_rights', AUTH_PASSWD, 'groups'),
+ '%grp/admin/annuaire' => $this->make_hook('admin_annuaire', AUTH_PASSWD, 'groupadmin'),
+ '%grp/member' => $this->make_hook('admin_member', AUTH_PASSWD, 'groupadmin'),
+ '%grp/member/new' => $this->make_hook('admin_member_new', AUTH_PASSWD, 'groupadmin'),
+ '%grp/member/new/ajax' => $this->make_hook('admin_member_new_ajax', AUTH_PASSWD, 'groups', NO_AUTH),
+ '%grp/member/del' => $this->make_hook('admin_member_del', AUTH_PASSWD, 'groupadmin'),
+ '%grp/member/suggest' => $this->make_hook('admin_member_suggest', AUTH_PASSWD, 'groupadmin'),
+
+ '%grp/rss' => $this->make_token_hook('rss', AUTH_PUBLIC),
+ '%grp/announce/new' => $this->make_hook('edit_announce', AUTH_PASSWD, 'groupadmin'),
+ '%grp/announce/edit' => $this->make_hook('edit_announce', AUTH_PASSWD, 'groupadmin'),
'%grp/announce/photo' => $this->make_hook('photo_announce', AUTH_PUBLIC),
- '%grp/admin/announces' => $this->make_hook('admin_announce', AUTH_MDP, 'groupadmin'),
+ '%grp/admin/announces' => $this->make_hook('admin_announce', AUTH_PASSWD, 'groupadmin'),
);
}
- function handler_index(&$page, $arg = null)
+ function handler_index($page, $arg = null)
{
global $globals, $platal;
-
if (!is_null($arg)) {
return PL_NOT_FOUND;
}
@@ -115,87 +70,89 @@ class XnetGrpModule extends PLModule
if (S::logged()) {
if (Env::has('read')) {
- 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()');
- XDB::query('INSERT INTO #groupex#.announces_read
- VALUES ({?}, {?})',
+ XDB::query('DELETE r.*
+ FROM group_announces_read AS r
+ INNER JOIN group_announces AS a ON (a.id = r.announce_id)
+ WHERE expiration < CURRENT_DATE()');
+ XDB::query('INSERT INTO group_announces_read
+ VALUES ({?}, {?})',
Env::i('read'), S::i('uid'));
pl_redirect("");
}
if (Env::has('unread')) {
- XDB::query('DELETE FROM #groupex#.announces_read
- WHERE announce_id={?} AND user_id={?}',
+ XDB::query('DELETE FROM group_announces_read
+ WHERE announce_id = {?} AND uid = {?}',
Env::i('unread'), S::i('uid'));
pl_redirect("#art" . Env::i('unread'));
}
- $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 #x4dat#.auth_user_md5 AS u USING(user_id)
- 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 <= {?})
- AND (promo_max = 0 OR promo_max >= {?})
- AND r.announce_id IS NULL
- ORDER BY a.peremption",
- 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()
- AND (promo_min = 0 OR promo_min <= {?})
- AND (promo_max = 0 OR promo_max >= {?})
- ORDER BY a.peremption",
- S::i('uid'), $globals->asso('id'), S::i('promo'), S::i('promo'));
+
+ /* TODO: refines this filter on promotions by using userfilter. */
+ $user = S::user();
+ if ($user->hasProfile()) {
+ $promo = XDB::format('{?}', $user->profile()->entry_year);
+ $minCondition = ' OR promo_min <= ' . $promo;
+ $maxCondition = ' OR promo_max >= ' . $promo;
+ } else {
+ $minCondition = '';
+ $maxCondition = '';
+ }
+ $arts = XDB::iterator('SELECT a.*, FIND_IN_SET(\'photo\', a.flags) AS photo
+ 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' . $minCondition . ')
+ AND (promo_max = 0' . $maxCondition . ')
+ AND r.announce_id IS NULL
+ ORDER BY a.expiration',
+ S::i('uid'), $globals->asso('id'));
+ $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' . $minCondition . ')
+ AND (promo_max = 0' . $maxCondition . ')
+ ORDER BY a.expiration',
+ S::i('uid'), $globals->asso('id'));
$page->assign('article_index', $index);
} else {
- $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 #x4dat#.auth_user_md5 AS u USING(user_id)
- WHERE asso_id = {?} AND peremption >= CURRENT_DATE()
- AND FIND_IN_SET('public', u.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'));
+ $payments = XDB::fetchAllAssoc("SELECT id, text
+ FROM payments
+ WHERE asso_id = {?} AND NOT FIND_IN_SET('old', flags) AND FIND_IN_SET('public', flags)
+ ORDER BY id DESC",
+ $globals->asso('id'));
+ $page->assign('payments', $payments);
}
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());
}
- if (!S::has('core_rss_hash')) {
+ if (!S::hasAuthToken()) {
$page->setRssLink("Polytechnique.net :: {$globals->asso("nom")} :: News publiques",
$platal->ns . "rss/rss.xml");
} else {
$page->setRssLink("Polytechnique.net :: {$globals->asso("nom")} :: News",
- $platal->ns . 'rss/'.S::v('hruid') .'/'.S::v('core_rss_hash').'/rss.xml');
+ $platal->ns . 'rss/' . S::v('hruid') . '/' . S::user()->token . '/rss.xml');
}
$page->assign('articles', $arts);
}
- function handler_logo(&$page)
+ 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);
- if (!empty($logo)) {
- echo $logo;
- } else {
- readfile(dirname(__FILE__) . '/../htdocs/images/dflt_carre.jpg');
- }
- exit;
+ $globals->asso()->getLogo()->send();
}
- function handler_site(&$page)
+ function handler_site($page)
{
global $globals;
$site = $globals->asso('site');
@@ -207,19 +164,26 @@ class XnetGrpModule extends PLModule
exit;
}
- function handler_edit(&$page)
+ function handler_edit($page)
{
global $globals;
$page->changeTpl('xnetgrp/edit.tpl');
+ $error = false;
+
+ if (S::admin()) {
+ $domains = XDB::iterator('SELECT *
+ FROM group_dom
+ ORDER BY nom');
+ $page->assign('domains', $domains);
+ $page->assign('super', true);
+ }
if (Post::has('submit')) {
S::assert_xsrf_token();
- $flags = new PlFlagSet();
- if (Post::has('notif_unsub') && Post::i('notif_unsub') == 1) {
- $flags->addFlag('notif_unsub');
- }
- $site = trim(Post::v('site'));
+ $flags = new PlFlagSet('wiki_desc');
+ $flags->addFlag('notif_unsub', Post::i('notif_unsub') == 1);
+ $site = Post::t('site');
if ($site && ($site != "http://")) {
$scheme = parse_url($site, PHP_URL_SCHEME);
if (!$scheme) {
@@ -228,74 +192,169 @@ class XnetGrpModule extends PLModule
} else {
$site = "";
}
+
+ $notify_all = (Post::v('notify_all') ? true : false);
+ if (!$notify_all) {
+ $to_notify = array();
+ $uf = New UserFilter(New UFC_Group($globals->asso('id'), true));
+ $uids = $uf->getIds();
+ foreach ($uids as $uid) {
+ if (Post::b('to_notify_' . $uid)) {
+ $to_notify[] = $uid;
+ }
+ }
+ if (count($to_notify) == 0) {
+ $notify_all = true;
+ $page->trigWarning("Aucun animateur n'ayant été selectionné pour recevoir les demandes d'inscriptions, tous le seront.");
+ }
+ }
+ $flags->addFlag('notify_all', $notify_all);
+
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) !!!');
+ $error = true;
+ }
+ if (Post::t('nom') == '' || Post::t('diminutif') == '') {
+ $page->trigError('Ni le nom ni le diminutif du groupe ne peuvent être vide.');
+ $error = true;
+ }
+ if ($error) {
+ $page->assign('nom', Post::t('nom'));
+ $page->assign('diminutif', Post::t('diminutif'));
+ $page->assign('mail_domain', Post::t('mail_domain'));
+ $page->assign('cat', Post::v('cat'));
+ $page->assign('dom', Post::v('dom'));
+ $page->assign('ax', Post::v('ax'));
+ $page->assign('axDate', Post::t('axDate'));
+ $page->assign('site', $site);
+ $page->assign('resp', Post::t('resp'));
+ $page->assign('mail', Post::t('mail'));
+ $page->assign('phone', Post::t('phone'));
+ $page->assign('fax', Post::t('fax'));
+ $page->assign('address', Post::t('address'));
+ $page->assign('forum', Post::t('forum'));
+ $page->assign('inscriptible', Post::v('inscriptible'));
+ $page->assign('sub_url', Post::t('sub_url'));
+ $page->assign('unsub_url', Post::t('unsub_url'));
+ $page->assign('welcome_msg', Post::t('welcome_msg'));
+ $page->assign('pub', Post::v('pub'));
+ $page->assign('notif_unsub', Post::i('notif_unsub'));
+ $page->assign('descr', Post::t('descr'));
+ $page->assign('error', $error);
return;
}
+
+ $axDate = make_datetime(Post::v('axDate'));
+ if (Post::t('axDate') != '') {
+ $axDate = make_datetime(Post::v('axDate'))->format('Y-m-d');
+ } else {
+ $axDate = null;
+ }
XDB::execute(
- "UPDATE #groupex#.asso
+ "UPDATE groups
SET nom={?}, diminutif={?}, cat={?}, dom={?},
descr={?}, site={?}, mail={?}, resp={?},
- forum={?}, mail_domain={?}, ax={?}, pub={?},
+ forum={?}, mail_domain={?}, ax={?}, axDate = {?}, pub={?},
sub_url={?}, inscriptible={?}, unsub_url={?},
- flags={?}
+ flags = {?}, welcome_msg = {?}
WHERE id={?}",
Post::v('nom'), Post::v('diminutif'),
- Post::v('cat'), Post::i('dom'),
+ Post::v('cat'), (Post::i('dom') == 0) ? null : Post::i('dom'),
Post::v('descr'), $site,
Post::v('mail'), Post::v('resp'),
Post::v('forum'), Post::v('mail_domain'),
- Post::has('ax'), Post::v('pub'),
+ Post::has('ax'), $axDate, Post::v('pub'),
Post::v('sub_url'), Post::v('inscriptible'),
- Post::v('unsub_url'), $flags, $globals->asso('id'));
+ Post::v('unsub_url'), $flags, Post::t('welcome_msg'),
+ $globals->asso('id'));
if (Post::v('mail_domain')) {
- XDB::execute('INSERT IGNORE INTO virtual_domains (domain) VALUES({?})',
- Post::v('mail_domain'));
+ XDB::execute('INSERT IGNORE INTO email_virtual_domains (name)
+ VALUES ({?})',
+ Post::t('mail_domain'));
+ XDB::execute('UPDATE email_virtual_domains
+ SET aliasing = id
+ WHERE name = {?}',
+ Post::t('mail_domain'));
}
} else {
XDB::execute(
- "UPDATE #groupex#.asso
+ "UPDATE groups
SET descr={?}, site={?}, mail={?}, resp={?},
forum={?}, pub= {?}, sub_url={?},
- unsub_url={?},flags={?}
+ unsub_url = {?}, flags = {?}, welcome_msg = {?}
WHERE id={?}",
Post::v('descr'), $site,
Post::v('mail'), Post::v('resp'),
Post::v('forum'), Post::v('pub'),
Post::v('sub_url'), Post::v('unsub_url'),
- $flags, $globals->asso('id'));
+ $flags, Post::t('welcome_msg'),
+ $globals->asso('id'));
}
+ Phone::deletePhones(0, Phone::LINK_GROUP, $globals->asso('id'));
+ $phone = new Phone(array('link_type' => 'group', 'link_id' => $globals->asso('id'), 'id' => 0,
+ 'type' => 'fixed', 'display' => Post::v('phone'), 'pub' => 'public'));
+ $fax = new Phone(array('link_type' => 'group', 'link_id' => $globals->asso('id'), 'id' => 1,
+ 'type' => 'fax', 'display' => Post::v('fax'), 'pub' => 'public'));
+ $phone->save();
+ $fax->save();
+ Address::deleteAddresses(null, Address::LINK_GROUP, null, $globals->asso('id'));
+ $address = new Address(array('groupid' => $globals->asso('id'), 'type' => Address::LINK_GROUP, 'text' => Post::v('address')));
+ $address->save();
+
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'));
+ $upload = PlUpload::get($_FILES['logo'], $globals->asso('id'), 'asso.logo', true);
+ if (!$upload) {
+ $page->trigError("Impossible de télécharger le logo.");
+ } else {
+ XDB::execute('UPDATE groups
+ SET logo = {?}, logo_mime = {?}
+ WHERE id = {?}', $upload->getContents(), $upload->contentType(),
+ $globals->asso('id'));
+ $upload->rm();
+ }
}
- pl_redirect('../'.Post::v('diminutif', $globals->asso('diminutif')).'/edit');
- }
+ XDB::execute("UPDATE group_members
+ SET flags = ''
+ WHERE asso_id = {?}",
+ $globals->asso('id'));
+ if (!$notify_all) {
+ XDB::execute("UPDATE group_members
+ SET flags = 'notify'
+ WHERE asso_id = {?} AND uid IN {?}",
+ $globals->asso('id'), $to_notify);
+ }
- if (S::admin()) {
- $dom = XDB::iterator('SELECT * FROM #groupex#.dom ORDER BY nom');
- $page->assign('dom', $dom);
- $page->assign('super', true);
+ pl_redirect('../' . Post::v('diminutif', $globals->asso('diminutif')) . '/edit');
}
+
+ $uf = New UserFilter(New UFC_Group($globals->asso('id'), true, UFC_Group::NOTIFIED));
+ $page->assign('notified', $uf->getUsers());
+ $uf = New UserFilter(New UFC_Group($globals->asso('id'), true, UFC_Group::UNNOTIFIED));
+ $page->assign('unnotified', $uf->getUsers());
+
+ $page->assign('error', $error);
+ $page->assign('cat', $globals->asso('cat'));
+ $page->assign('dom', $globals->asso('dom'));
+ $page->assign('ax', $globals->asso('ax'));
+ $page->assign('inscriptible', $globals->asso('inscriptible'));
+ $page->assign('pub', $globals->asso('pub'));
+ $page->assign('notif_unsub', $globals->asso('notif_unsub'));
+ $page->assign('notify_all', $globals->asso('notify_all'));
}
- function handler_mail(&$page)
+ function handler_mail($page)
{
global $globals;
$page->changeTpl('xnetgrp/mail.tpl');
- $mmlist = new MMList(S::v('uid'), S::v('password'),
- $globals->asso('mail_domain'));
+ $mmlist = new MMList(S::user(), $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();
@@ -325,7 +384,7 @@ class XnetGrpModule extends PLModule
}
}
- function handler_forum(&$page, $group = null, $artid = null)
+ function handler_forum($page, $group = null, $artid = null)
{
global $globals;
$page->changeTpl('xnetgrp/forum.tpl');
@@ -338,185 +397,252 @@ class XnetGrpModule extends PLModule
run_banana($page, 'ForumsBanana', $get);
}
- function handler_annuaire(&$page, $action = null, $subaction = null)
+ function handler_annuaire($page, $action = null, $subaction = null)
{
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();
- $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;
- }
+ __autoload('userset');
+ $admins = false;
+ if ($action == 'admins') {
+ $admins = true;
+ $action = $subaction;
}
+ $view = new UserSet(new UFC_Group($globals->asso('id'), $admins));
+ $view->addMod('groupmember', 'Annuaire');
+ $view->addMod('trombi', 'Trombinoscope');
+ $view->addMod('map', 'Planisphère');
+ $view->apply('annuaire', $page, $action);
+ $page->assign('only_admin', $admins);
$page->changeTpl('xnetgrp/annuaire.tpl');
+ }
- $sort = Env::v('order');
- switch (Env::v('order')) {
- case 'promo' : $group = 'promo'; $tri = 'promo_o DESC, nom, prenom'; break;
- case 'promo_inv': $group = 'promo'; $tri = 'promo_o, nom, prenom'; break;
- case 'alpha_inv': $group = 'initiale'; $tri = 'nom DESC, prenom DESC, promo'; break;
- default : $group = 'initiale'; $tri = 'nom, prenom, promo'; $sort = 'alpha';
- }
- $page->assign('sort', $sort);
-
- if ($group == 'initiale') {
- $res = XDB::iterRow(
- 'SELECT UPPER(SUBSTRING(
- IF(m.origine="X", IF(u.nom_usage<>"", u.nom_usage, u.nom),m.nom),
- 1, 1)) as letter, COUNT(*)
- FROM #groupex#.membres AS m
- LEFT JOIN #x4dat#.auth_user_md5 AS u ON ( u.user_id = m.uid)
- WHERE asso_id = {?} and (u.perms != \'pending\' OR m.email IS NOT NULL)
- GROUP BY letter
- ORDER BY letter', $globals->asso('id'));
- } else {
- $res = XDB::iterRow(
- 'SELECT IF(m.origine="X",u.promo,
- IF(m.origine="ext", "extérieur", "personne morale")) AS promo,
- COUNT(*), IF(m.origine="X",u.promo,"") AS promo_o
- FROM #groupex#.membres AS m
- LEFT JOIN #x4dat#.auth_user_md5 AS u ON ( u.user_id = m.uid )
- WHERE asso_id = {?}
- GROUP BY promo
- ORDER BY promo_o DESC', $globals->asso('id'));
- }
- $alphabet = array();
- $nb_tot = 0;
- while (list($char, $nb) = $res->next()) {
- $alphabet[] = $char;
- $nb_tot += $nb;
- if (Env::has($group) && $char == mb_strtoupper(Env::v($group))) {
- $tot = $nb;
- }
- }
- $page->assign('group', $group);
- $page->assign('request_group', Env::v($group));
- $page->assign('only_admin', Env::has('admin'));
- $page->assign('alphabet', $alphabet);
- $page->assign('nb_tot', $nb_tot);
-
- $ofs = Env::i('offset');
- $tot = Env::v($group) ? $tot : $nb_tot;
- $nbp = intval(($tot-1)/NB_PER_PAGE);
- $links = array();
- if ($ofs) {
- $links['précédent'] = $ofs-1;
- }
- for ($i = 0; $i <= $nbp; $i++) {
- $links[(string)($i+1)] = $i;
- }
- if ($ofs < $nbp) {
- $links['suivant'] = $ofs+1;
- }
- if (count($links)>1) {
- $page->assign('links', $links);
- }
-
- $ini = '';
- if (Env::has('initiale')) {
- $ini = 'AND IF(m.origine="X",
- IF(u.nom_usage<>"", u.nom_usage, u.nom),
- m.nom) LIKE "'.addslashes(Env::v('initiale')).'%"';
- } elseif (Env::has('promo')) {
- $ini = 'AND IF(m.origine="X", u.promo, IF(m.origine="ext", "extérieur", "personne morale")) = "'
- .addslashes(Env::v('promo')).'"';
- } elseif (Env::has('admin')) {
- $ini = 'AND m.perms = "admin"';
- }
-
- $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',u.promo,'') AS promo_o,
- IF(m.origine='X' AND u.perms != 'pending',a.alias,m.email) AS email,
- IF(m.origine='X',FIND_IN_SET('femme', u.flags), m.sexe) AS femme,
- m.perms='admin' AS admin,
- m.origine='X' AS x,
- u.perms!='pending' AS inscrit,
- 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 #x4dat#.auth_user_md5 AS u ON ( u.user_id = m.uid )
- LEFT JOIN #x4dat#.aliases AS a ON ( a.id = m.uid AND a.type='a_vie' )
- LEFT JOIN #x4dat#.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
- ORDER BY $tri
- LIMIT {?},{?}", $globals->asso('id'), $ofs*NB_PER_PAGE, NB_PER_PAGE);
- $page->assign('ann', $ann);
- $page->jsonAssign('ann', $ann);
+ function handler_former_users($page)
+ {
+ global $globals;
+ require_once 'userset.inc.php';
+
+ $view = new UserSet(new UFC_GroupFormerMember($globals->asso('id')));
+ $view->addMod('groupmember', 'Anciens membres', true, array('noadmin' => true));
+ $view->apply('former_users', $page);
+ $page->changeTpl('xnetgrp/former_users.tpl');
}
- function handler_trombi(&$page)
+ function handler_trombi($page)
{
pl_redirect('annuaire/trombi');
}
- function handler_geoloc(&$page)
+ function handler_geoloc($page)
{
pl_redirect('annuaire/geoloc');
}
- function handler_vcard(&$page, $photos = null)
+ 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->addProfiles($globals->asso()->getMembersFilter()->getProfiles(null, Profile::FETCH_ALL));
$vcard->show();
}
- function handler_csv(&$page, $filename = null)
+ 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 #x4dat#.auth_user_md5 AS u ON ( u.user_id = m.uid )
- LEFT JOIN #x4dat#.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'));
- pl_content_headers("text/x-csv");
- $page->changeTpl('xnetgrp/annuaire-csv.tpl', NO_SKIN);
- $page->assign('ann', $ann);
+ $users = $globals->asso()->getMembersFilter(null, new UFO_Name())->getUsers();
+ pl_cached_content_headers('text/x-csv', 'iso-8859-1', 1);
+
+ echo utf8_decode("Nom;Prénom;Sexe;Promotion;Commentaire\n");
+ foreach ($users as $user) {
+ $line = $user->lastName() . ';' . $user->firstName() . ';' . ($user->isFemale() ? 'F' : 'M')
+ . ';' . $user->promo() . ';' . strtr($user->group_comm, ';', ',');
+ echo utf8_decode($line) . "\n";
+ }
+ exit();
+ }
+
+ function handler_directory_sync($page)
+ {
+ global $globals;
+ require_once 'emails.inc.php';
+
+ $page->changeTpl('xnetgrp/sync.tpl');
+ Platal::load('lists', 'lists.inc.php');
+
+ if (Env::has('add_users')) {
+ S::assert_xsrf_token();
+
+ $users = array_keys(Env::v('add_users'));
+ $former_users = XDB::fetchColumn('SELECT uid
+ FROM group_former_members
+ WHERE remember = TRUE AND uid IN {?}',
+ $users);
+ $new_users = array_diff($users, $former_users);
+
+ foreach ($former_users as $uid) {
+ $user = User::getSilentWithUID($uid);
+ $page->trigWarning($user->fullName() . ' est un ancien membre du groupe qui ne souhaite pas y revenir.');
+ }
+ if (count($former_users) > 1) {
+ $page->trigWarning('S\'ils souhaitent revenir dans le groupe, il faut qu\'ils en fassent la demande sur la page d\'accueil du groupe.');
+ } elseif (count($former_users)) {
+ $page->trigWarning('S\'il souhaite revenir dans le groupe, il faut qu\'il en fasse la demande sur la page d\'accueil du groupe.');
+ }
+
+ $data = array();
+ foreach ($new_users as $uid) {
+ $data[] = XDB::format('({?}, {?})', $globals->asso('id'), $uid);
+ }
+ XDB::rawExecute('INSERT INTO group_members (asso_id, uid)
+ VALUES ' . implode(',', $data));
+ }
+
+ if (Env::has('add_nonusers')) {
+ S::assert_xsrf_token();
+
+ $nonusers = array_keys(Env::v('add_nonusers'));
+ foreach ($nonusers as $email) {
+ if ($user = User::getSilent($email) || !isvalid_email($email)) {
+ continue;
+ }
+
+ list($local_part, $domain) = explode('@', strtolower($email));
+ $hruid = User::makeHrid($local_part, $domain, 'ext');
+ if ($user = User::getSilent($hruid)) {
+ continue;
+ }
+
+ $parts = explode('.', $local_part);
+ if (count($parts) == 1) {
+ $lastname = $display_name = $full_name = $directory_name = ucfirst($local_part);
+ $firstname = '';
+ } else {
+ $firstname = ucfirst($parts[0]);
+ $lastname = ucwords(implode(' ', array_slice($parts, 1)));
+ $display_name = $firstname;
+ $full_name = $firstname . ' ' . $lastname;
+ $directory_name = strtoupper($lastname) . ' ' . $firstname;
+ }
+ XDB::execute('INSERT INTO accounts (hruid, display_name, full_name, directory_name, firstname, lastname, email, type, state)
+ VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, \'xnet\', \'disabled\')',
+ $hruid, $display_name, $full_name, $directory_name, $firstname, $lastname, $email);
+ $uid = XDB::insertId();
+ XDB::execute('INSERT INTO group_members (asso_id, uid)
+ VALUES ({?}, {?})',
+ $globals->asso('id'), $uid);
+ }
+ }
+
+ if (Env::has('add_users') || Env::has('add_nonusers')) {
+ $page->trigSuccess('Ajouts réalisés avec succès.');
+ }
+
+ $user = S::user();
+ $client = new MMList($user, $globals->asso('mail_domain'));
+ $lists = $client->get_lists();
+ $members = array();
+ foreach ($lists as $list) {
+ $details = $client->get_members($list['list']);
+ $members = array_merge($members, list_extract_members($details[1]));
+ }
+ $members = array_unique($members);
+ $uids = array();
+ $users = array();
+ $nonusers = array();
+ foreach ($members as $email) {
+ if ($user = User::getSilent($email)) {
+ $uids[] = $user->id();
+ } else {
+ $nonusers[] = $email;
+ }
+ }
+
+ $aliases = iterate_list_alias($globals->asso('mail_domain'));
+ foreach ($aliases as $alias) {
+ list($local_part, $domain) = explode('@', $alias);
+ $aliases_members = list_alias_members($local_part, $domain);
+ $users = array_merge($users, $aliases_members['users']);
+ $nonusers = array_merge($nonusers, $aliases_members['nonusers']);
+ }
+ foreach ($users as $user) {
+ $uids[] = $user->id();
+ }
+ $nonusers = array_unique($nonusers);
+ $uids = array_unique($uids);
+ if (count($uids)) {
+ $uids = XDB::fetchColumn('SELECT a.uid
+ FROM accounts AS a
+ WHERE a.uid IN {?} AND NOT EXISTS (SELECT *
+ FROM group_members AS g
+ WHERE a.uid = g.uid AND g.asso_id = {?})',
+ $uids, $globals->asso('id'));
+
+ $users = User::getBulkUsersWithUIDs($uids);
+ usort($users, 'User::compareDirectoryName');
+ } else {
+ $users = array();
+ }
+ sort($nonusers);
+
+ $page->assign('users', $users);
+ $page->assign('nonusers', $nonusers);
+ }
+
+ function handler_non_active($page)
+ {
+ global $globals;
+ $page->changeTpl('xnetgrp/non_active.tpl');
+
+ $uids = XDB::fetchColumn('SELECT g.uid
+ FROM group_members AS g
+ INNER JOIN accounts AS a ON (a.uid = g.uid)
+ LEFT JOIN register_pending_xnet AS p ON (p.uid = g.uid)
+ WHERE a.uid = g.uid AND g.asso_id = {?} AND a.type = \'xnet\' AND a.state = \'disabled\' AND p.uid IS NULL',
+ $globals->asso('id'));
+ foreach ($uids as $key => $uid) {
+ if (AccountReq::isPending($uid) || BulkAccountsReq::isPending($uid)) {
+ unset($uids[$key]);
+ }
+ }
+
+ if (Post::has('enable_accounts')) {
+ S::assert_xsrf_token();
+
+ $uids_to_enable = array_intersect(array_keys(Post::v('enable_accounts')), $uids);
+
+ $user = S::user();
+ $group = Platal::globals()->asso('nom');
+ $request = new BulkAccountsReq($user, $uids_to_enable, $group);
+ $request->submit();
+ $page->trigSuccess('Un email va bientôt être envoyé aux personnes sélectionnées pour l\'activation de leur compte.');
+
+ foreach ($uids as $key => $uid) {
+ if (in_array($uid, $uids_to_enable)) {
+ unset($uids[$key]);
+ }
+ }
+ }
+
+ $users = User::getBulkUsersWithUIDs($uids);
+ $page->assign('users', $users);
}
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);
}
- private function validSubscription(User &$user)
+ private function validSubscription(User $user)
{
global $globals;
$this->removeSubscriptionRequest($user->id());
- XDB::execute("INSERT IGNORE INTO #groupex#.membres (asso_id, uid)
- VALUES ({?}, {?})",
- $globals->asso('id'), $user->id());
+ Group::subscribe($globals->asso('id'), $user->id());
+
if (XDB::affectedRows() == 1) {
$mailer = new PlMailer();
$mailer->addTo($user->forlifeEmail());
@@ -524,18 +650,19 @@ class XnetGrpModule extends PLModule
$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"
+ . " Suite à ta demande d'adhésion à " . $globals->asso('nom')
+ . ", j'ai le plaisir de t'annoncer que ton inscription a été validée !\n"
+ . (is_null($globals->asso('welcome_msg')) ? '' : "\n" . $globals->asso('welcome_msg') . "\n")
. "\n"
. "Bien cordialement,\n"
. "-- \n"
. S::user()->fullName() . '.';
- $mailer->setTxtBody($message);
+ $mailer->setTxtBody(wordwrap($message, 72));
$mailer->send();
}
}
- function handler_subscribe(&$page, $u = null)
+ function handler_subscribe($page, $u = null)
{
global $globals;
$page->changeTpl('xnetgrp/inscrire.tpl');
@@ -555,13 +682,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);
@@ -599,7 +726,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) {
@@ -610,24 +737,23 @@ 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);
+ XDB::execute('DELETE FROM group_former_members
+ WHERE uid = {?} AND asso_id = {?}',
+ S::i('uid'), $globals->asso('id'));
+ $admins = $globals->asso()->iterToNotify();
+ $admin = $admins->next();
+ $to = $admin->bestEmail();
+ while ($admin = $admins->next()) {
+ $to .= ', ' . $admin->bestEmail();
+ }
$append = "\n"
. "-- \n"
. "Ce message a été envoyé suite à la demande d'inscription de\n"
- . S::user()->fullName() . ' (X' . S::v('promo') . ")\n"
+ . S::user()->fullName(true) . "\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::user()->login() . "\n"
@@ -653,7 +779,7 @@ class XnetGrpModule extends PLModule
}
}
- function handler_subscribe_valid(&$page)
+ function handler_subscribe_valid($page)
{
global $globals;
@@ -673,21 +799,18 @@ class XnetGrpModule extends PLModule
}
}
- $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 #x4dat#.auth_user_md5 AS u ON (s.uid = u.user_id)
- WHERE asso_id = {?}
- ORDER BY nom, prenom",
- $globals->asso('id'));
-
+ $it = XDB::iterator('SELECT s.uid, a.hruid, s.ts AS date
+ 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');
$page->assign('valid', $it);
}
- function handler_change_rights(&$page)
+ function handler_change_rights($page)
{
- if (Env::has('right') && (may_update() || S::has('suid'))) {
+ if (Env::has('right') && (may_update() || S::suid())) {
switch (Env::v('right')) {
case 'admin':
Platal::session()->stopSUID();
@@ -709,18 +832,17 @@ class XnetGrpModule extends PLModule
break;
}
}
-// var_dump($_SESSION);
http_redirect($_SERVER['HTTP_REFERER']);
}
- function handler_admin_annuaire(&$page)
+ function handler_admin_annuaire($page)
{
global $globals;
$this->load('mail.inc.php');
$page->changeTpl('xnetgrp/annuaire-admin.tpl');
- $mmlist = new MMList(S::v('uid'), S::v('password'),
- $globals->asso('mail_domain'));
+ $user = S::user();
+ $mmlist = new MMList($user, $globals->asso('mail_domain'));
$lists = $mmlist->get_lists();
if (!$lists) $lists = array();
$listes = array_map(create_function('$arr', 'return $arr["list"];'), $lists);
@@ -737,16 +859,10 @@ class XnetGrpModule extends PLModule
$not_in_group_ext = array();
foreach ($subscribers as $mail) {
- $res = XDB::query(
- 'SELECT COUNT(*)
- FROM #groupex#.membres AS m
- LEFT JOIN #x4dat#.auth_user_md5 AS u ON (m.uid = u.user_id AND m.uid < 50000)
- LEFT JOIN #x4dat#.aliases AS a ON (a.id = u.user_id and a.type = "a_vie")
- WHERE asso_id = {?} AND
- (m.email = {?} OR CONCAT(a.alias, "@polytechnique.org") = {?})',
- $globals->asso('id'), $mail, $mail);
- if ($res->fetchOneCell() == 0) {
- if (strstr($mail, '@polytechnique.org') === false) {
+ $uf = new UserFilter(new PFC_And(new UFC_Group($globals->asso('id')),
+ new UFC_Email($mail)));
+ if ($uf->getTotalCount() == 0) {
+ if (User::isForeignEmailAddress($mail)) {
$not_in_group_ext[] = $mail;
} else {
$not_in_group_x[] = $mail;
@@ -759,163 +875,257 @@ class XnetGrpModule extends PLModule
$page->assign('lists', $lists);
}
- function handler_admin_member_new(&$page, $email = null)
+ function handler_admin_member_new($page, $email = null)
{
global $globals;
$page->changeTpl('xnetgrp/membres-add.tpl');
- $page->addJsLink('ajax.js');
if (is_null($email)) {
return;
- } else {
- S::assert_xsrf_token();
}
- 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());
+ S::assert_xsrf_token();
+ $suggest_account_activation = false;
+
+ // FS#703 : $_GET is urldecoded twice, hence
+ // + (the data) => %2B (in the url) => + (first decoding) => ' ' (second decoding)
+ // Since there can be no spaces in emails, we can fix this with :
+ $email = str_replace(' ', '+', $email);
+ $is_valid_email = isvalid_email($email);
+
+ // X not registered to main site.
+ if (Env::v('x') && Env::i('userid') && $is_valid_email) {
+ $user = User::getSilentWithUID(Env::i('userid'));
+ if (!$user) {
+ $page->trigError('Utilisateur invalide.');
+ return;
+ }
+
+ // User has an account but is not yet registered.
+ if ($user->state == 'pending') {
+ // Add email in account table.
+ XDB::query('UPDATE accounts
+ SET email = {?}
+ WHERE uid = {?} AND email IS NULL',
+ Post::t('email'), $user->id());
+ // Add email for marketing if required.
+ if (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 {
- if (isvalid_email($email)) {
- if (Env::v('x') && Env::has('userid') && Env::i('userid')) {
- $uid = Env::i('userid');
- $res = XDB::query("SELECT *
- FROM auth_user_md5
- WHERE user_id = {?} AND perms = 'pending'", $uid);
- if ($res->numRows() == 1) {
- 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");
+ $user = User::getSilent($email);
+
+ // Wrong email and no user: failure.
+ if (is_null($user) && (!$is_valid_email || !User::isForeignEmailAddress($email))) {
+ $page->trigError('« ' . $email . ' » n\'est pas une adresse email valide.');
+ return;
+ }
+
+ // Deals with xnet accounts.
+ if (is_null($user) || $user->type == 'xnet') {
+ // User is of type xnet. There are 3 possible cases:
+ // * the email is not known yet: we create a new account and
+ // propose to send an email to the user so he can activate
+ // his account,
+ // * the email is known but the user was not contacted in order to
+ // activate yet: we propose to send an email to the user so he
+ // can activate his account,
+ // * the email is known and the user was already contacted or has
+ // an active account: nothing to be done.
+ list($mbox, $domain) = explode('@', strtolower($email));
+ $hruid = User::makeHrid($mbox, $domain, 'ext');
+ // User might already have an account (in another group for example).
+ $user = User::getSilent($hruid);
+
+ // If the user has no account yet, creates new account: build names from email address.
+ if (empty($user)) {
+ $parts = explode('.', $mbox);
+ if (count($parts) == 1) {
+ $lastname = $display_name = $full_name = $directory_name = ucfirst($mbox);
+ $firstname = '';
+ } else {
+ $firstname = ucfirst($parts[0]);
+ $lastname = ucwords(implode(' ', array_slice($parts, 1)));
+ $display_name = $firstname;
+ $full_name = "$firstname $lastname";
+ $directory_name = strtoupper($lastname) . " " . $firstname;
}
- $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");
+ XDB::execute('INSERT INTO accounts (hruid, display_name, full_name, directory_name, firstname, lastname, email, type, state)
+ VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, \'xnet\', \'disabled\')',
+ $hruid, $display_name, $full_name, $directory_name, $firstname, $lastname, $email);
+ $user = User::getSilent($hruid);
}
+
+ $suggest_account_activation = $this->suggest($user);
+ }
+ }
+
+ if ($user) {
+ // First check if the user used to be in this group.
+ XDB::rawExecute('DELETE FROM group_former_members
+ WHERE remember AND DATE_SUB(NOW(), INTERVAL 1 YEAR) > unsubsciption_date');
+ $former_member = XDB::fetchOneCell('SELECT remember
+ FROM group_former_members
+ WHERE uid = {?} AND asso_id = {?}',
+ $user->id(), $globals->asso('id'));
+ if ($former_member === 1) {
+ $page->trigError($user->fullName() . ' est un ancien membre du groupe qui ne souhaite pas y revenir. S\'il souhaite revenir dans le groupe, il faut qu\'il en fasse la demande sur la page d\'accueil du groupe.');
+ return;
+ } elseif (!is_null($former_member) && Post::i('force_continue') == 0) {
+ $page->trigWarning($user->fullName() . ' est un ancien membre du groupe qui s\'est récemment désinscrit. Malgré cela, si tu penses qu\'il souhaite revenir, cliquer sur « Ajouter » l\'ajoutera bien au groupe cette fois.');
+ $page->assign('force_continue', 1);
+ return;
+ }
+
+ Group::subscribe($globals->asso('id'), $user->id());
+ $this->removeSubscriptionRequest($user->id());
+ if ($suggest_account_activation) {
+ pl_redirect('member/suggest/' . $user->login() . '/' . $email . '/' . $globals->asso('nom'));
} else {
- $page->trigError("« $email » n'est pas une adresse email valide.");
+ pl_redirect('member/' . $user->login());
}
}
}
- function handler_admin_member_new_ajax(&$page)
+ // Check if the user has a pending or active account, and thus if we should her account's activation.
+ private function suggest(PlUser $user)
+ {
+ $active = XDB::fetchOneCell('SELECT state = \'active\'
+ FROM accounts
+ WHERE uid = {?}',
+ $user->id());
+ $pending = XDB::fetchOneCell('SELECT uid
+ FROM register_pending_xnet
+ WHERE uid = {?}',
+ $user->id());
+ $requested = AccountReq::isPending($user->id()) || BulkAccountsReq::isPending($user->id());
+
+ if ($active || $pending || $requested) {
+ return false;
+ }
+ return true;
+ }
+
+ function handler_admin_member_suggest($page, $hruid, $email)
+ {
+ $page->changeTpl('xnetgrp/membres-suggest.tpl');
+
+ // FS#703 : $_GET is urldecoded twice, hence
+ // + (the data) => %2B (in the url) => + (first decoding) => ' ' (second decoding)
+ // Since there can be no spaces in emails, we can fix this with :
+ $email = str_replace(' ', '+', $email);
+
+ if (Post::has('suggest')) {
+ if (Post::t('suggest') == 'yes') {
+ $user = S::user();
+ $request = new AccountReq($user, $hruid, $email, Platal::globals()->asso('nom'));
+ $request->submit();
+ $page->trigSuccessRedirect('Un email va bien être envoyé à ' . $email . ' pour l\'activation de son compte.',
+ Platal::globals()->asso('diminutif') . '/member/' . $hruid);
+ } else {
+ pl_redirect('member/' . $hruid);
+ }
+ }
+ $page->assign('email', $email);
+ $page->assign('hruid', $hruid);
+ }
+
+ function handler_admin_member_new_ajax($page)
{
pl_content_headers("text/html");
$page->changeTpl('xnetgrp/membres-new-search.tpl', NO_SKIN);
- $res = null;
+ $users = array();
if (Env::has('login')) {
- require_once 'user.func.inc.php';
- $res = get_not_registered_user(Env::v('login'), true);
- }
- 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%'";
+ $user = User::getSilent(Env::t('login'));
+ if ($user && $user->state != 'pending') {
+ $users = array($user);
}
- if (!empty($prenom)) {
- $where .= " AND prenom LIKE '%$prenom%'";
+ }
+ if (empty($users)) {
+ list($lastname, $firstname) = str_replace(array('-', ' ', "'"), '%', array(Env::t('nom'), Env::t('prenom')));
+ $cond = new PFC_And(new PFC_Not(new UFC_Registered()));
+ if (!empty($lastname)) {
+ $cond->addChild(new UFC_NameTokens($lastname, array(), false, false, Profile::LASTNAME));
}
- 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;
+ if (!empty($firstname)) {
+ $cond->addChild(new UFC_NameTokens($firstname, array(), false, false, Profile::FIRSTNAME));
+ }
+ if (Env::t('promo')) {
+ $cond->addChild(new UFC_Promo('=', UserFilter::DISPLAY, Env::t('promo')));
+ }
+ $uf = new UserFilter($cond);
+ $users = $uf->getUsers(new PlLimit(30));
+ if ($uf->getTotalCount() > 30) {
+ $page->assign('too_many', true);
+ $users = array();
}
- $res = XDB::iterator("SELECT user_id, nom, prenom, promo
- FROM auth_user_md5
- WHERE $where");
- }
- if ($res && $res->total() < 30) {
- $page->assign("choix", $res);
}
+ $page->assign('users', $users);
}
- function unsubscribe(&$user)
+ function unsubscribe(PlUser $user, $remember = false)
{
global $globals;
- XDB::execute(
- "DELETE FROM #groupex#.membres WHERE uid={?} AND asso_id={?}",
- $user['uid'], $globals->asso('id'));
+ Group::unsubscribe($globals->asso('id'), $user->id(), $remember);
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 #x4dat#.aliases AS a ON (m.uid = a.id AND FIND_IN_SET('bestalias', a.flags))
- INNER JOIn #x4dat#.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}>");
+ $admins = $globals->asso()->iterToNotify();
+ while ($admin = $admins->next()) {
+ $mailer->addTo($admin);
}
$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->assign('user', $user);
+ $mailer->assign('selfdone', $user->id() == S::i('uid'));
$mailer->send();
}
- $user_same_email = get_infos($user['email']);
$domain = $globals->asso('mail_domain');
-
- if (!$domain || (!empty($user_same_email) && $user_same_email['uid'] != $user['uid'])) {
+ if (!$domain) {
return true;
}
- $mmlist = new MMList(S::v('uid'), S::v('password'), $domain);
- $listes = $mmlist->get_lists($user['email2']);
+ $mmlist = new MMList(S::user(), $domain);
+ $listes = $mmlist->get_lists($user->forlifeEmail());
$may_update = may_update();
$warning = false;
- foreach ($listes as $liste) {
- if ($liste['sub'] == 2) {
- if ($may_update) {
- $mmlist->mass_unsubscribe($liste['list'], Array($user['email2']));
- } 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['prenom']} {$user['nom']} a une"
- ." demande d'inscription en cours sur la"
- ." liste {$liste['list']}@ !");
- $warning = true;
}
}
- XDB::execute(
- "DELETE FROM virtual_redirect
- USING virtual_redirect
- INNER JOIN virtual USING(vid)
- WHERE redirect={?} AND alias LIKE {?}", $user['email'], '%@'.$domain);
+ XDB::execute('DELETE v
+ FROM email_virtual AS v
+ INNER JOIN email_virtual_domains AS d ON (v.domain = d.id)
+ WHERE v.redirect = {?} AND d.name = {?}',
+ $user->forlifeEmail(), $domain);
return !$warning;
}
- function handler_unsubscribe(&$page)
+ function handler_unsubscribe($page)
{
$page->changeTpl('xnetgrp/membres-del.tpl');
- $user = get_infos(S::user()->id());
+ $user = S::user();
if (empty($user)) {
return PL_NOT_FOUND;
}
@@ -928,21 +1138,36 @@ class XnetGrpModule extends PLModule
S::assert_xsrf_token();
}
- if ($this->unsubscribe($user)) {
- $page->trigSuccess('Vous avez été désinscrit du groupe avec succès.');
+ $hasSingleGroup = ($user->groupCount() == 1);
+
+ if ($this->unsubscribe($user, Post::b('remember'))) {
+ $page->trigSuccess('Tu as é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 listes de diffusion.');
+ $page->trigWarning('Tu as été désinscrit du groupe, mais des erreurs se sont produites lors des désinscriptions des alias et des listes de diffusion.');
+ }
+
+ // If user is of type xnet account and this was her last group, disable the account.
+ if ($user->type == 'xnet' && $hasSingleGroup) {
+ $user->clear(true);
}
$page->assign('is_member', is_member(true));
}
- function handler_admin_member_del(&$page, $user = null)
+ function handler_admin_member_del($page, $user = null)
{
$page->changeTpl('xnetgrp/membres-del.tpl');
- $user = get_infos($user);
+ $user = User::getSilent($user);
if (empty($user)) {
return PL_NOT_FOUND;
}
+
+ global $globals;
+
+ if (!$user->inGroup($globals->asso('id'))) {
+ pl_redirect('annuaire');
+ }
+
+ $page->assign('self', false);
$page->assign('user', $user);
if (!Post::has('confirm')) {
@@ -951,215 +1176,241 @@ class XnetGrpModule extends PLModule
S::assert_xsrf_token();
}
+ $hasSingleGroup = ($user->groupCount() == 1);
+
if ($this->unsubscribe($user)) {
- $page->trigSuccess("{$user['prenom']} {$user['nom']} a été désabonné du groupe !");
+ $page->trigSuccess("{$user->fullName()} a été désinscrit du groupe !");
} else {
- $page->trigWarning("{$user['prenom']} {$user['nom']} a été désabonné du groupe, mais des erreurs subsistent !");
+ $page->trigWarning("{$user->fullName()} a été désinscrit du groupe, mais des erreurs subsistent !");
+ }
+
+ // If user is of type xnet account and this was her last group, disable the account.
+ if ($user->type == 'xnet' && $hasSingleGroup) {
+ $user->clear(true);
}
}
- private function changeLogin(PlPage &$page, array &$user, MMList &$mmlist, $login)
+ private function changeLogin(PlPage $page, PlUser $user, $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.");
+ // Search the user's uid.
+ $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'];
- $sub = false;
- } else {
- list($uid, $login) = $res->fetchOneRow();
- $sub = true;
+ $xuser = User::getSilent($accounts[0]['uid']);
}
- // 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;
- }
-
- // 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 (!$xuser) {
+ return false;
}
- if ($sub) {
- return $login;
+
+ if ($user->mergeIn($xuser)) {
+ return $xuser->login();
}
- return $user['email'];
+ return $user->login();
}
- function handler_admin_member(&$page, $user)
+ function handler_admin_member($page, $user)
{
global $globals;
- $page->changeTpl('xnetgrp/membres-edit.tpl');
-
- $user = get_infos($user);
+ $user = User::getSilent($user);
if (empty($user)) {
return PL_NOT_FOUND;
}
- $mmlist = new MMList(S::v('uid'), S::v('password'),
- $globals->asso('mail_domain'));
+ if (!$user->inGroup($globals->asso('id'))) {
+ pl_redirect('annuaire');
+ }
+
+ $page->changeTpl('xnetgrp/membres-edit.tpl');
+
+ $mmlist = new MMList(S::user(), $globals->asso('mail_domain'));
if (Post::has('change')) {
+ require_once 'emails.inc.php';
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 (!Post::blank('login_X')) {
+ $forlife = $this->changeLogin($page, $user, Post::t('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') {
- $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.');
+ if ($user->type == 'virtual' || ($user->type == 'xnet' && !$user->perms)) {
+ $lastname = Post::s('lastname');
+ if (Post::s('type') != 'virtual') {
+ $firstname = Post::s('firstname');
+ $full_name = $firstname . ' ' . $lastname;
+ $directory_name = mb_strtoupper($lastname) . ' ' . $firstname;
+ } else {
+ $firstname = '';
+ $full_name = $lastname;
+ $directory_name = mb_strtoupper($lastname);
+ }
+ XDB::query('UPDATE accounts
+ SET full_name = {?}, directory_name = {?}, display_name = {?},
+ firstname = {?}, lastname = {?}, sex = {?}, type = {?}
+ WHERE uid = {?}',
+ $full_name, $directory_name, Post::t('display_name'), $firstname, $lastname,
+ (Post::t('sex') == 'male') ? 'male' : 'female',
+ (Post::t('type') == 'xnet') ? 'xnet' : 'virtual', $user->id());
}
- $perms = Post::i('is_admin');
- $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', $comm,
- $user['uid'], $globals->asso('id'));
- if ($perms != $user['perms']) {
- $page->trigSuccess('Permissions modifiées !');
+ // Updates email.
+ $new_email = strtolower(Post::t('email'));
+ if (!$user->perms && require_email_update($user, $new_email)) {
+ XDB::query('UPDATE accounts
+ SET email = {?}
+ WHERE uid = {?}',
+ $new_email, $user->id());
+ $listClient = new MMList(S::user());
+ $listClient->change_user_email($user->forlifeEmail(), $new_email);
+ update_alias_user($user->forlifeEmail(), $new_email);
+ }
+ if (XDB::affectedRows()) {
+ $page->trigSuccess('Données de l\'utilisateur mises à jour.');
+ }
+
+ if (($user->type == 'xnet' && !$user->perms)) {
+ if (Post::b('suggest')) {
+ $request = new AccountReq(S::user(), $user->hruid, Post::t('email'), $globals->asso('nom'));
+ $request->submit();
+ $page->trigSuccess('Le compte va bientôt être activé.');
}
- if ($comm != $user['comm']) {
- $page->trigSuccess('Commentaire mis à jour.');
+ if (Post::b('again')) {
+ $data = XDB::fetchOneAssoc('SELECT hash, group_name, sender_name, email
+ FROM register_pending_xnet
+ WHERE uid = {?}',
+ $user->id());
+
+ $mailer = new PlMailer('xnet/account.mail.tpl');
+ $mailer->addCc('validation+xnet_account@polytechnique.org');
+ $mailer->setTo($data['email']);
+ $mailer->assign('hash', $data['hash']);
+ $mailer->assign('email', $data['email']);
+ $mailer->assign('group', $data['group_name']);
+ $mailer->assign('sender_name', $data['sender_name']);
+ $mailer->assign('again', true);
+ $mailer->send();
+ $page->trigSuccess('Relance effectuée avec succès.');
+ }
+ }
+
+ // Update group params for user
+ $perms = Post::v('group_perms');
+ $comm = Post::t('comm');
+ $position = (Post::t('group_position') == '') ? null : Post::v('group_position');
+ if ($user->group_perms != $perms || $user->group_comm != $comm || $user->group_position != $position) {
+ XDB::query('UPDATE group_members
+ SET perms = {?}, comm = {?}, position = {?}
+ WHERE uid = {?} AND asso_id = {?}',
+ ($perms == 'admin') ? 'admin' : 'membre', $comm, $position,
+ $user->id(), $globals->asso('id'));
+ if (XDB::affectedRows()) {
+ if ($perms != $user->group_perms) {
+ $page->trigSuccess('Permissions modifiées !');
+ }
+ if ($comm != $user->group_comm) {
+ $page->trigSuccess('Commentaire mis à jour.');
+ }
+ if ($position != $user->group_position) {
+ $page->trigSuccess('Poste 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.");
- }
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']));
- }
- $page->trigSuccess("{$user['prenom']} {$user['nom']} a été désabonné de $ml@.");
+ $mmlist->mass_unsubscribe($ml, Array($user->forlifeEmail()));
+ $page->trigSuccess("{$user->fullName()} a été désabonné de $ml@.");
}
}
// Change subscriptioin to aliases
foreach (Env::v('ml3', array()) as $ml => $state) {
+ require_once 'emails.inc.php';
$ask = !empty($_REQUEST['ml4'][$ml]);
- if($state == $ask) continue;
- 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.");
+ list($local_part, ) = explode('@', $ml);
+ if ($ask == $state) {
+ continue;
+ }
+ if ($ask) {
+ add_to_list_alias($user->id(), $local_part, $globals->asso('mail_domain'));
+ $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.");
+ delete_from_list_alias($user->id(), $local_part, $globals->asso('mail_domain'));
+ $page->trigSuccess("{$user->fullName()} a été désabonné de $ml.");
}
}
+
+ if ($globals->asso('has_nl')) {
+ $nl = NewsLetter::forGroup($globals->asso('shortname'));
+ // Updates group's newsletter subscription.
+ if (Post::i('newsletter') == 1) {
+ $nl->subscribe($user);
+ } else {
+ $nl->unsubscribe(null, $user->id());
+ }
+ }
+ }
+
+ $res = XDB::rawFetchAllAssoc('SHOW COLUMNS FROM group_members LIKE \'position\'');
+ $positions = str_replace(array('enum(', ')', '\''), '', $res[0]['Type']);
+ if ($globals->asso('has_nl')) {
+ $nl = NewsLetter::forGroup($globals->asso('shortname'));
+ $nl_registered = $nl->subscriptionState($user);
+ } else {
+ $nl_registered = false;
}
$page->assign('user', $user);
- $listes = $mmlist->get_lists($user['email2']);
- $page->assign('listes', $listes);
-
- $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 = {?} OR redirect = {?}))
- WHERE alias LIKE {?} AND type="user"',
- $user['email'], $user['email2'], '%@'.$globals->asso('mail_domain'));
- $page->assign('alias', $res->fetchAllAssoc());
+ $page->assign('suggest', $this->suggest($user));
+ $page->assign('listes', $mmlist->get_lists($user->forlifeEmail()));
+ $page->assign('alias', $user->emailGroupAliases($globals->asso('mail_domain')));
+ $page->assign('positions', explode(',', $positions));
+ $page->assign('nl_registered', $nl_registered);
+ $page->assign('pending_xnet_account', XDB::fetchOneCell('SELECT 1
+ FROM register_pending_xnet
+ WHERE uid = {?}',
+ $user->id()));
}
- function handler_rss(&$page, $user = null, $hash = null)
+ function handler_rss(PlPage $page, PlUser $user)
{
global $globals;
$page->assign('asso', $globals->asso());
$this->load('feed.inc.php');
$feed = new XnetGrpEventFeed();
- return $feed->run($page, $user, $hash, false);
+ return $feed->run($page, $user, false);
}
- private function upload_image(PlPage &$page, PlUpload &$upload)
+ private function upload_image(PlPage $page, PlUpload $upload)
{
if (@!$_FILES['image']['tmp_name'] && !Env::v('image_url')) {
return true;
@@ -1171,16 +1422,18 @@ class XnetGrpModule extends PLModule
$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)) {
+ } elseif (!$upload->resizeImage(80, 100, 100, 100, 32284)) {
$page->trigError('Impossible de retraiter l\'image');
return false;
}
return true;
}
- function handler_photo_announce(&$page, $eid = null) {
+ 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']);
@@ -1201,7 +1454,7 @@ class XnetGrpModule extends PLModule
exit;
}
- function handler_edit_announce(&$page, $aid = null)
+ function handler_edit_announce($page, $aid = null)
{
global $globals, $platal;
$page->changeTpl('xnetgrp/announce-edit.tpl');
@@ -1224,7 +1477,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');
@@ -1257,7 +1511,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;
@@ -1279,30 +1534,28 @@ class XnetGrpModule extends PLModule
if (!empty($art['contact_html'])) {
$fulltext .= "\n\n'''Contacts :'''\\\\\n" . $art['contact_html'];
}
- $post = null;/*
+ $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, 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.");
@@ -1310,25 +1563,25 @@ class XnetGrpModule extends PLModule
$upload->rm();
}
if ($art['nl']) {
- require_once('validations.inc.php');
$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.");
}
} 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
- SET eid = {?}, attachmime = {?}, x = {?}, y = {?}, attach = {?}",
- $aid, $imgtype, $imgx, $imgy, $upload->getContents());
+ XDB::execute('INSERT INTO group_announces_photo (eid, attachmime, attach, x, y)
+ VALUES ({?}, {?}, {?}, {?}, {?})
+ ON DUPLICATE KEY UPDATE attachmime = VALUES(attachmime), attach = VALUES(attach), x = VALUES(x), y = VALUES(y)',
+ $aid, $imgtype, $upload->getContents(), $imgx, $imgy);
$upload->rm();
}
}
@@ -1338,12 +1591,10 @@ class XnetGrpModule extends PLModule
}
if (empty($art) && !is_null($aid)) {
- $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 #x4dat#.auth_user_md5 AS u USING(user_id)
- 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();
@@ -1355,7 +1606,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()) {
@@ -1368,21 +1619,21 @@ class XnetGrpModule extends PLModule
$page->assign_by_ref('upload', $upload);
}
- function handler_admin_announce(&$page)
+ function handler_admin_announce($page)
{
global $globals;
$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 = {?}",
+ 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);
}