X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;ds=sidebyside;f=modules%2Fxnetgrp.php;h=47f4a8da0e845409be2c7bf8a477a4fb4b6a4972;hb=c9566e01c2add8f12a858abe0fbb0bc6b8e3c0d4;hp=0049ae0395f825871724b6bf8338f9d8200e5ad8;hpb=bfe9f4c752e8889ab5a269bddd27ea43b31d567e;p=platal.git
diff --git a/modules/xnetgrp.php b/modules/xnetgrp.php
index 0049ae0..47f4a8d 100644
--- a/modules/xnetgrp.php
+++ b/modules/xnetgrp.php
@@ -120,6 +120,12 @@ class XnetGrpModule extends PLModule
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
@@ -162,6 +168,15 @@ class XnetGrpModule extends PLModule
{
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();
@@ -177,17 +192,61 @@ 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) !!!');
- return;
+ $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');
@@ -259,16 +318,33 @@ class XnetGrpModule extends PLModule
}
}
+ 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);
+ }
+
pl_redirect('../' . Post::v('diminutif', $globals->asso('diminutif')) . '/edit');
}
- if (S::admin()) {
- $dom = XDB::iterator('SELECT *
- FROM group_dom
- ORDER BY nom');
- $page->assign('dom', $dom);
- $page->assign('super', true);
- }
+ $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)
@@ -334,6 +410,7 @@ class XnetGrpModule extends PLModule
$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');
@@ -375,9 +452,15 @@ class XnetGrpModule extends PLModule
$filename = $globals->asso('diminutif') . '.csv';
}
$users = $globals->asso()->getMembersFilter(null, new UFO_Name())->getUsers();
- pl_cached_content_headers('text/x-csv', 1);
- $page->changeTpl('xnetgrp/annuaire-csv.tpl', NO_SKIN);
- $page->assign('users', $users);
+ 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)
@@ -660,8 +743,7 @@ class XnetGrpModule extends PLModule
XDB::execute('DELETE FROM group_former_members
WHERE uid = {?} AND asso_id = {?}',
S::i('uid'), $globals->asso('id'));
- $uf = New UserFilter(New UFC_Group($globals->asso('id'), true));
- $admins = $uf->iterUsers();
+ $admins = $globals->asso()->iterToNotify();
$admin = $admins->next();
$to = $admin->bestEmail();
while ($admin = $admins->next()) {
@@ -810,20 +892,10 @@ class XnetGrpModule extends PLModule
// + (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);
- // Finds or creates account: first cases are for users with an account.
- if (!User::isForeignEmailAddress($email)) {
- // Standard account
- $user = User::getSilent($email);
- } else if (!isvalid_email($email)) {
- // email might not be a regular email but an alias or a hruid
- $user = User::getSilent($email);
- if (!$user) {
- // need a valid email address
- $page->trigError('« ' . $email . ' » n\'est pas une adresse email valide.');
- return;
- }
- } else if (Env::v('x') && Env::i('userid')) {
+ // 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.');
@@ -848,40 +920,51 @@ class XnetGrpModule extends PLModule
}
}
} else {
- // 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;
- }
- 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);
+ $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;
}
- $suggest_account_activation = $this->suggest($user);
+ // 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;
+ }
+ 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) {
@@ -942,11 +1025,10 @@ class XnetGrpModule extends PLModule
if (Post::has('suggest')) {
if (Post::t('suggest') == 'yes') {
$user = S::user();
- $group = Platal::globals()->asso('nom');
- $request = new AccountReq($user, $hruid, $email, $group);
+ $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.',
- $group . '/member/' . $hruid);
+ Platal::globals()->asso('diminutif') . '/member/' . $hruid);
} else {
pl_redirect('member/' . $hruid);
}
@@ -995,7 +1077,7 @@ class XnetGrpModule extends PLModule
if ($globals->asso('notif_unsub')) {
$mailer = new PlMailer('xnetgrp/unsubscription-notif.mail.tpl');
- $admins = $globals->asso()->iterAdmins();
+ $admins = $globals->asso()->iterToNotify();
while ($admin = $admins->next()) {
$mailer->addTo($admin);
}
@@ -1164,8 +1246,6 @@ class XnetGrpModule extends PLModule
}
// Update user info
- $email_changed = (!$user->profile() && strtolower($user->forlifeEmail()) != strtolower(Post::v('email')));
- $from_email = $user->forlifeEmail();
if ($user->type == 'virtual' || ($user->type == 'xnet' && !$user->perms)) {
$lastname = Post::s('lastname');
if (Post::s('type') != 'virtual') {
@@ -1179,30 +1259,51 @@ class XnetGrpModule extends PLModule
}
XDB::query('UPDATE accounts
SET full_name = {?}, directory_name = {?}, display_name = {?},
- firstname = {?}, lastname = {?}, sex = {?}, email = {?}, type = {?}
+ firstname = {?}, lastname = {?}, sex = {?}, type = {?}
WHERE uid = {?}',
$full_name, $directory_name, Post::t('display_name'), $firstname, $lastname,
- (Post::t('sex') == 'male') ? 'male' : 'female', Post::t('email'),
+ (Post::t('sex') == 'male') ? 'male' : 'female',
(Post::t('type') == 'xnet') ? 'xnet' : 'virtual', $user->id());
- } else if (!$user->perms) {
+ }
+
+ // 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 = {?}',
- Post::t('email'), $user->id());
- }
- if (require_email_update($user, Post::t('email'))) {
+ $new_email, $user->id());
$listClient = new MMList(S::user());
- $listClient->change_user_email($user->forlifeEmail(), Post::t('email'));
- update_alias_user($user->forlifeEmail(), Post::t('email'));
+ $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) && 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 (($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 (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
@@ -1235,10 +1336,6 @@ class XnetGrpModule extends PLModule
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->forlifeEmail());
- $page->trigSuccess("L'abonnement de {$user->fullName()} à $ml@ a été mis à jour.");
- }
continue;
}
if ($state == '1') {
@@ -1249,11 +1346,7 @@ class XnetGrpModule extends PLModule
$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->forlifeEmail()));
- }
+ $mmlist->mass_unsubscribe($ml, Array($user->forlifeEmail()));
$page->trigSuccess("{$user->fullName()} a été désabonné de $ml@.");
}
}
@@ -1263,12 +1356,10 @@ class XnetGrpModule extends PLModule
require_once 'emails.inc.php';
$ask = !empty($_REQUEST['ml4'][$ml]);
list($local_part, ) = explode('@', $ml);
- if($state == $ask) {
- if ($state && $email_changed) {
- update_list_alias($user->id(), $from_email, $local_part, $globals->asso('mail_domain'));
- $page->trigSuccess("L'abonnement de {$user->fullName()} à $ml a été mis à jour.");
- }
- } else if($ask) {
+ 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 {
@@ -1283,7 +1374,7 @@ class XnetGrpModule extends PLModule
if (Post::i('newsletter') == 1) {
$nl->subscribe($user);
} else {
- $nl->unsubscribe(null, $user->id);
+ $nl->unsubscribe(null, $user->id());
}
}
}
@@ -1303,6 +1394,10 @@ class XnetGrpModule extends PLModule
$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(PlPage $page, PlUser $user)