X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=modules%2Faxletter.php;h=67bdf555ac2d955c697bd8000ddedfc1441634e9;hb=12262f1306059765d8625a6752364679c8625d31;hp=01628154c627968b8a4f9e9be44cabb03dc1710b;hpb=6e909db8e8f8a25a0d44e3ff74bcc5f76eb2ea92;p=platal.git diff --git a/modules/axletter.php b/modules/axletter.php index 0162815..67bdf55 100644 --- a/modules/axletter.php +++ b/modules/axletter.php @@ -1,6 +1,6 @@ $this->make_hook('index', AUTH_COOKIE), + 'ax' => $this->make_hook('index', AUTH_COOKIE), 'ax/out' => $this->make_hook('out', AUTH_PUBLIC), 'ax/show' => $this->make_hook('show', AUTH_COOKIE), 'ax/edit' => $this->make_hook('submit', AUTH_MDP), 'ax/edit/cancel' => $this->make_hook('cancel', AUTH_MDP), 'ax/edit/valid' => $this->make_hook('valid', AUTH_MDP), - 'admin/axletter' => $this->make_hook('admin', AUTH_MDP, 'admin'), + 'admin/axletter' => $this->make_hook('admin', AUTH_MDP, 'admin'), ); } @@ -90,6 +90,9 @@ class AXLetterModule extends PLModule $signature = trim(Post::v('signature')); $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_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'); @@ -100,6 +103,8 @@ class AXLetterModule extends PLModule $res = XDB::query("SELECT * FROM axletter WHERE FIND_IN_SET('new', bits)"); if ($res->numRows()) { extract($res->fetchOneAssoc(), EXTR_OVERWRITE); + $subset_to = ($subset ? explode("\n", $subset) : array()); + $subset = (count($subset_to) > 0); $saved = true; } else { XDB::execute("INSERT INTO axletter SET id = NULL"); @@ -148,18 +153,50 @@ class AXLetterModule extends PLModule } switch (@Post::v('valid')) { + case 'Vérifier les emails': + // Same as 'preview', but performs a test of all provided emails + if ($subset) { + require_once 'emails.inc.php'; + $ids = ids_from_mails($subset_to); + $nb_error = 0; + foreach ($subset_to as $e) { + if (!array_key_exists($e, $ids)) { + if ($nb_error == 0) { + $page->trigError("Emails inconnus :"); + } + $nb_error++; + $page->trigError($e); + } + } + if ($nb_error == 0) { + if (count($subset_to) == 1) { + $page->trigSuccess("L'email soumis a été reconnu avec succès."); + } else { + $page->trigSuccess("Les " . count($subset_to) . " emails soumis ont été reconnus avec succès."); + } + } else { + $page->trigError("Total : $nb_error erreur" . ($nb_error > 1 ? "s" : "") . " sur " . count($subset_to) . " adresses mail soumises."); + } + $page->trigSuccess("Les adresses soumises correspondent à un total de " . count(array_unique($ids)) . " camarades."); + } + // No break here, since Vérifier is a subcase of Aperçu. case 'Aperçu': $this->load('axletter.inc.php'); $al = new AXLetter(array($id, $short_name, $subject, $title, $body, $signature, - $promo_min, $promo_max, $echeance, 0, 'new')); - $al->toHtml($page, S::v('prenom'), S::v('nom'), S::v('femme')); + $promo_min, $promo_max, $subset, $subset_rm, $echeance, 0, 'new')); + $al->toHtml($page, S::user()); break; case 'Confirmer': - XDB::execute("REPLACE INTO axletter - SET id = {?}, short_name = {?}, subject = {?}, title = {?}, body = {?}, - signature = {?}, promo_min = {?}, promo_max = {?}, echeance = {?}", - $id, $short_name, $subject, $title, $body, $signature, $promo_min, $promo_max, $echeance); + XDB::execute('INSERT INTO axletter (id, short_name, subject, title, body, signature, + promo_min, promo_max, echeance, subset, subset_rm) + VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}) + ON DUPLICATE KEY UPDATE short_name = VALUES(short_name), subject = VALUES(subject), title = VALUES(title), + body = VALUES(body), signature = VALUES(signature), promo_min = VALUES(promo_min), + promo_max = VALUES(promo_max), echeance = VALUES(echeance), subset = VALUES(subset), + subset_rm = VALUES(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(); @@ -175,14 +212,10 @@ class AXLetterModule extends PLModule . "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(); } @@ -201,12 +234,15 @@ class AXLetterModule extends PLModule $page->assign('signature', $signature); $page->assign('promo_min', $promo_min); $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); $page->assign('saved', $saved); $page->assign('new', $new); - $page->assign('is_xorg', S::has_perms()); + $page->assign('is_xorg', S::admin()); if (!$saved) { $select = ''; @@ -240,7 +276,7 @@ class AXLetterModule extends PLModule return; } - $page->kill("L'envoi de l'annonce {$al->title()} est annulé"); + $page->killSuccess("L'envoi de l'annonce {$al->title()} est annulé."); } function handler_valid(&$page, $force = null) @@ -260,7 +296,7 @@ class AXLetterModule extends PLModule return; } - $page->kill("L'envoi de l'annonce aura lieu dans l'heure qui vient."); + $page->killSuccess("L'envoi de l'annonce aura lieu dans l'heure qui vient."); } function handler_show(&$page, $nid = 'last') @@ -268,15 +304,19 @@ class AXLetterModule extends PLModule $this->load('axletter.inc.php'); $page->changeTpl('axletter/show.tpl'); - $nl = new AXLetter($nid); - $user =& S::user(); - if (Get::has('text')) { - $nl->toText($page, $user); - } else { - $nl->toHtml($page, $user); - } - if (Post::has('send')) { - $nl->sendTo($user); + try { + $nl = new AXLetter($nid); + $user =& S::user(); + if (Get::has('text')) { + $nl->toText($page, $user); + } else { + $nl->toHtml($page, $user); + } + if (Post::has('send')) { + $nl->sendTo($user); + } + } catch (MailNotFound $e) { + return PL_NOT_FOUND; } } @@ -307,19 +347,16 @@ class AXLetterModule extends PLModule } $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) + function idFromMail($line, $key, $relation = null) { static $field; global $globals; @@ -332,39 +369,12 @@ class AXLetterModule extends PLModule } } } - $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) + function createHash($line, $key, $relation) { $hash = implode(time(), $line) . rand(); $hash = md5($hash);