<?php
/***************************************************************************
- * Copyright (C) 2003-2009 Polytechnique.org *
+ * Copyright (C) 2003-2010 Polytechnique.org *
* http://opensource.polytechnique.org/ *
* *
* This program is free software; you can redistribute it and/or modify *
$promo_min = Post::i('promo_min');
$promo_max = Post::i('promo_max');
$subset_to = preg_split("/[ ,;\:\n\r]+/", Post::v('subset_to'), -1, PREG_SPLIT_NO_EMPTY);
- $subset = ( count($subset_to) > 0);
+ $subset = (count($subset_to) > 0);
+ $subset_rm = Post::b('subset_rm');
$echeance = Post::has('echeance_date') ?
preg_replace('/^(\d\d\d\d)(\d\d)(\d\d)$/', '\1-\2-\3', Post::v('echeance_date')) . ' ' . Post::v('echeance_time')
: Post::v('echeance');
$res = XDB::query("SELECT * FROM axletter WHERE FIND_IN_SET('new', bits)");
if ($res->numRows()) {
extract($res->fetchOneAssoc(), EXTR_OVERWRITE);
- if ($subset) {
- $res = XDB::query('SELECT email FROM axletter_subsets WHERE letter_id = {?}', $id);
- $subset_to = $res->fetchColumn();
- }
+ $subset_to = ($subset ? explode("\n", $subset) : null);
+ $subset = (count($subset_to) > 0);
$saved = true;
} else {
XDB::execute("INSERT INTO axletter SET id = NULL");
case 'Aperçu':
$this->load('axletter.inc.php');
$al = new AXLetter(array($id, $short_name, $subject, $title, $body, $signature,
- $promo_min, $promo_max, $subset, $echeance, 0, 'new'));
+ $promo_min, $promo_max, $subset, $subset_rm, $echeance, 0, 'new'));
$al->toHtml($page, S::v('prenom'), S::v('nom'), S::v('femme'));
break;
case 'Confirmer':
XDB::execute("REPLACE INTO axletter
SET id = {?}, short_name = {?}, subject = {?}, title = {?}, body = {?},
- signature = {?}, promo_min = {?}, promo_max = {?}, echeance = {?}, subset = {?}",
- $id, $short_name, $subject, $title, $body, $signature, $promo_min, $promo_max, $echeance, $subset);
- if ($subset) {
- XDB::execute('DELETE FROM axletter_subsets
- WHERE letter_id = {?}', $id);
- foreach ($subset_to as $email) {
- $uid = $this->idFromMail(array('email' => $email));
- if ($uid) {
- XDB::execute('INSERT INTO axletter_subsets
- SET letter_id = {?}, user_id = {?}, email = {?}',
- $id, $uid, $email);
- }
- }
- }
+ signature = {?}, promo_min = {?}, promo_max = {?}, echeance = {?}, subset = {?}, subset_rm = {?}",
+ $id, $short_name, $subject, $title, $body, $signature, $promo_min, $promo_max, $echeance, $subset ? implode("\n", $subset_to) : null, $subset_rm);
if (!$saved) {
global $globals;
$mailer = new PlMailer();
. "https://www.polytechnique.org/ax/edit\n"
. "-- \n"
. "Association Polytechnique.org\n");
- $res = XDB::iterRow("SELECT IF(u.nom_usage != '', u.nom_usage, u.nom) AS nom,
- u.prenom, a.alias AS bestalias
- FROM axletter_rights AS ar
- INNER JOIN auth_user_md5 AS u USING(user_id)
- INNER JOIN aliases AS a ON (u.user_id = a.id
- AND FIND_IN_SET('bestalias', a.flags))");
- while (list($nom, $prenom, $alias) = $res->next()) {
- $mailer->addTo("$nom $prenom <$alias@{$globals->mail->domain}>");
+ $users = User::getBulkUsersWithUIDs(XDB::fetchColumn('SELECT uid
+ FROM axletter_rights'));
+ foreach ($users as $user) {
+ $mailer->addTo($user);
}
$mailer->send();
}
$page->assign('promo_max', $promo_max);
$page->assign('subset_to', implode("\n", $subset_to));
$page->assign('subset', $subset);
+ $page->assign('subset_rm', $subset_rm);
$page->assign('echeance', $echeance);
$page->assign('echeance_date', $echeance_date);
$page->assign('echeance_time', $echeance_time);
try {
$nl = new AXLetter($nid);
+ $user =& S::user();
if (Get::has('text')) {
- $nl->toText($page, S::v('prenom'), S::v('nom'), S::v('femme'));
+ $nl->toText($page, $user);
} else {
- $nl->toHtml($page, S::v('prenom'), S::v('nom'), S::v('femme'));
+ $nl->toHtml($page, $user);
}
if (Post::has('send')) {
- $nl->sendTo(S::user()->login(), S::user()->bestEmail(),
- S::v('prenom'), S::v('nom'),
- S::v('femme'), S::v('mail_fmt') != 'texte');
+ $nl->sendTo($user);
}
} catch (MailNotFound $e) {
return PL_NOT_FOUND;
}
$page->changeTpl('axletter/admin.tpl');
- $res = XDB::iterator("SELECT IF(u.nom_usage != '', u.nom_usage, u.nom) AS nom,
- u.prenom, u.promo, u.hruid
- FROM axletter_rights AS ar
- INNER JOIN auth_user_md5 AS u USING(user_id)");
- $page->assign('admins', $res);
+ $page->assign('admins', User::getBulkUsersWithUIDs(XDB::fetchColumn('SELECT uid
+ FROM axletter_rights')));
$importer = new CSVImporter('axletter_ins');
- $importer->registerFunction('user_id', 'email vers Id X.org', array($this, 'idFromMail'));
+ $importer->registerFunction('uid', 'email vers Id X.org', array($this, 'idFromMail'));
$importer->forceValue('hash', array($this, 'createHash'));
- $importer->apply($page, "admin/axletter", array('user_id', 'email', 'prenom', 'nom', 'promo', 'flag', 'hash'));
+ $importer->apply($page, "admin/axletter", array('uid', 'email', 'prenom', 'nom', 'promo', 'flag', 'hash'));
}
function idFromMail($line, $key, $relation = null)
}
}
}
- $email = $line[$field];
- if (strpos($email, '@') === false) {
- $user = $email;
- $domain = $globals->mail->domain2;
- } else {
- list($user, $domain) = explode('@', $email);
- }
- if ($domain != $globals->mail->domain && $domain != $globals->mail->domain2
- && $domain != $globals->mail->alias_dom && $domain != $globals->mail->alias_dom2) {
- $res = XDB::query("SELECT uid FROM emails WHERE email = {?}", $email);
- if ($res->numRows() == 1) {
- return $res->fetchOneCell();
- }
- return '0';
- }
- list($user) = explode('+', $user);
- list($user) = explode('_', $user);
- if ($domain == $globals->mail->alias_dom || $domain == $globals->mail->alias_dom2) {
- $res = XDB::query("SELECT a.id
- FROM virtual AS v
- INNER JOIN virtual_redirect AS r USING(vid)
- INNER JOIN aliases AS a ON (a.type = 'a_vie'
- AND r.redirect = CONCAT(a.alias, '@{$globals->mail->domain2}'))
- WHERE v.alias = CONCAT({?}, '@{$globals->mail->alias_dom}')", $user);
- $id = $res->fetchOneCell();
- return $id ? $id : '0';
- }
- $res = XDB::query("SELECT id FROM aliases WHERE alias = {?}", $user);
- $id = $res->fetchOneCell();
- return $id ? $id : '0';
+ $uf = new UserFilter(new UFC_Email($line[$field]));
+ $id = $uf->getUIDs();
+ return count($id) == 1 ? $id[0] : 0;
}
function createHash($line, $key, $relation)