X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=modules%2Faxletter.php;h=b0f654e94f6d437fea0f005a6a3e4f9832e20bd9;hb=723d4c6b7736df20e07d2c6e32e4c37c6c80ca05;hp=206fe6218bdf7cbed845508bbc0653ac194bd453;hpb=fb813fb52d5ab65ca9a5b92b5cb9089523380d79;p=platal.git diff --git a/modules/axletter.php b/modules/axletter.php index 206fe62..b0f654e 100644 --- a/modules/axletter.php +++ b/modules/axletter.php @@ -103,7 +103,7 @@ 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) : null); + $subset_to = ($subset ? explode("\n", $subset) : array()); $subset = (count($subset_to) > 0); $saved = true; } else { @@ -153,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, $subset, $subset_rm, $echeance, 0, 'new')); - $al->toHtml($page, S::v('prenom'), S::v('nom'), S::v('femme')); + $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 = {?}, subset = {?}, subset_rm = {?}", - $id, $short_name, $subject, $title, $body, $signature, $promo_min, $promo_max, $echeance, $subset ? implode("\n", $subset_to) : null, $subset_rm); + 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(); @@ -180,7 +212,7 @@ class AXLetterModule extends PLModule . "https://www.polytechnique.org/ax/edit\n" . "-- \n" . "Association Polytechnique.org\n"); - $users = User::getBulkUsersWithUIDs(XDB::fetchColumn('SELECT user_id + $users = User::getBulkUsersWithUIDs(XDB::fetchColumn('SELECT uid FROM axletter_rights')); foreach ($users as $user) { $mailer->addTo($user); @@ -315,13 +347,13 @@ class AXLetterModule extends PLModule } $page->changeTpl('axletter/admin.tpl'); - $page->assign('admins', User::getBulkUsersWithUIDs(XDB::fetchColumn('SELECT user_id + $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)