X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=modules%2Faxletter.php;h=d093bd3bf8f1fc9200a4aa0abd4ee8f663b193d9;hb=e8dfa21cb3ade890694157170de1a1c6d7519531;hp=d1f1c443e161d44c340123f4b71a3878649ce582;hpb=0d75939a5e7640b66188ab4fc5d03a999b2c574e;p=platal.git diff --git a/modules/axletter.php b/modules/axletter.php index d1f1c44..d093bd3 100644 --- a/modules/axletter.php +++ b/modules/axletter.php @@ -1,6 +1,6 @@ assign('count', $res->numRows()); $page->assign('new', AXLetter::awaiting()); } $page->assign('axs', AXLetter::subscriptionState()); @@ -78,18 +80,19 @@ class AXLetterModule extends PLModule $page->changeTpl('axletter/edit.tpl'); - $saved = Post::i('saved'); - $new = false; - $id = Post::i('id'); - $shortname = trim(Post::v('shortname')); - $subject = trim(Post::v('subject')); - $title = trim(Post::v('title')); - $body = rtrim(Post::v('body')); - $signature = trim(Post::v('signature')); - $promo_min = Post::i('promo_min'); - $promo_max = Post::i('promo_max'); - $echeance = Post::has('echeance_date') ? Post::v('echeance_date') . ' ' . Post::v('echeance_time') - : Post::v('echeance'); + $saved = Post::i('saved'); + $new = false; + $id = Post::i('id'); + $short_name = trim(Post::v('short_name')); + $subject = trim(Post::v('subject')); + $title = trim(Post::v('title')); + $body = rtrim(Post::v('body')); + $signature = trim(Post::v('signature')); + $promo_min = Post::i('promo_min'); + $promo_max = Post::i('promo_max'); + $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'); $echeance_date = Post::v('echeance_date'); $echeance_time = Post::v('echeance_time'); @@ -106,7 +109,7 @@ class AXLetterModule extends PLModule $saved = false; $new = true; } - } elseif (Post::has('valid')) { + } elseif (Post::has('valid') && S::has_xsrf_token()) { if (!$subject && $title) { $subject = $title; } @@ -124,46 +127,74 @@ class AXLetterModule extends PLModule $page->trig("L'intervalle de promotions n'est pas valide"); Post::kill('valid'); } - if (empty($shortname)) { + if (empty($short_name)) { $page->trig("L'annonce doit avoir un nom raccourci pour simplifier la navigation dans les archives"); Post::kill('valid'); - } elseif (!preg_match('/^[a-z][-a-z0-9]*[a-z0-9]$/', $shortname)) { - $page->trig("Le nom raccourci n'est pas valide, il doit comporter au moins 2 caractères et n'être composé " + } elseif (!preg_match('/^[a-z][-a-z0-9]*[a-z0-9]$/', $short_name)) { + $page->trig("Le nom raccourci n'est pas valide, il doit comporter au moins 2 caractères et n'être composé " . "que de chiffres, lettres et tirets"); Post::kill('valid'); - } elseif ($shortname != Post::v('old_shortname')) { - $res = XDB::query("SELECT id FROM axletter WHERE shortname = {?}", $shortname); + } elseif ($short_name != Post::v('old_short_name')) { + $res = XDB::query("SELECT id FROM axletter WHERE short_name = {?}", $short_name); if ($res->numRows() && $res->fetchOneCell() != $id) { - $page->trig("Le nom $shortname est déjà utilisé, merci d'en choisir un autre"); - $shortname = Post::v('old_shortname'); - if (empty($shortname)) { + $page->trig("Le nom $short_name est déjà utilisé, merci d'en choisir un autre"); + $short_name = Post::v('old_short_name'); + if (empty($short_name)) { Post::kill('valid'); } } } switch (@Post::v('valid')) { - case 'Aperçu': + case 'Aperçu': require_once dirname(__FILE__) . '/axletter/axletter.inc.php'; - $al = new AXLetter(array($id, $shortname, $subject, $title, $body, $signature, + $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')); break; case 'Confirmer': XDB::execute("REPLACE INTO axletter - SET id = {?}, shortname = {?}, subject = {?}, title = {?}, body = {?}, + SET id = {?}, short_name = {?}, subject = {?}, title = {?}, body = {?}, signature = {?}, promo_min = {?}, promo_max = {?}, echeance = {?}", - $id, $shortname, $subject, $title, $body, $signature, $promo_min, $promo_max, $echeance); + $id, $short_name, $subject, $title, $body, $signature, $promo_min, $promo_max, $echeance); + if (!$saved) { + global $globals; + $mailer = new PlMailer(); + $mailer->setFrom("support@" . $globals->mail->domain); + $mailer->setSubject("Un nouveau projet de mail de l'AX vient d'être proposé"); + $mailer->setTxtBody("Un nouveau mail vient d'être rédigé en prévision d'un envoi prochain. Vous pouvez " + . "le modifier jusqu'à ce qu'il soit verrouillé pour l'envoi\n\n" + . "Le sujet du mail : $subject\n" + . "L'échéance d'envoi est fixée à $echeance.\n" + . "Le mail pourra néanmoins partir avant cette échéance si un administrateur de " + . "Polytechnique.org le valide.\n\n" + . "Pour modifier, valider ou annuler le mail :\n" + . "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}>"); + } + $mailer->send(); + } $saved = true; $echeance_date = null; $echeance_time = null; pl_redirect('ax'); break; } + } elseif (Post::has('valid')) { + $page->trig("L'opération a échouée, merci de réessayer."); } $page->assign('id', $id); - $page->assign('shortname', $shortname); + $page->assign('short_name', $short_name); $page->assign('subject', $subject); $page->assign('title', $title); $page->assign('body', $body); @@ -179,23 +210,6 @@ class AXLetterModule extends PLModule if (!$saved) { $select = ''; - $time = time() + 3600 * 24 * 2; - for ($i = 0 ; $i < 15 ; $i++) { - $time += 3600 * 24; - $p_stamp = date('Ymd', $time); - $year = date('Y', $time); - $month = date('m', $time); - $day = date('d', $time); - - if ($p_stamp == $echeance_date) { - $sel = ' selected="selected"'; - } else { - $sel = ''; - } - $select .= "\n"; - } - $page->assign('echeance_date', $select); - $select = ''; for ($i = 0 ; $i < 24 ; $i++) { $stamp = sprintf('%02d:00:00', $i); if ($stamp == $echeance_time) { @@ -206,23 +220,18 @@ class AXLetterModule extends PLModule $select .= "\n"; } $page->assign('echeance_time', $select); - } + } } function handler_cancel(&$page, $force = null) { require_once dirname(__FILE__) . '/axletter/axletter.inc.php'; - if (!AXLetter::hasPerms()) { - return PL_FORBIDDEN; - } - - $url = parse_url($_SERVER['HTTP_REFERER']); - if ($force != 'force' && trim($url['path'], '/') != 'ax/edit') { + if (!AXLetter::hasPerms() || !S::has_xsrf_token()) { return PL_FORBIDDEN; } $al = AXLetter::awaiting(); - if (!$alg) { + if (!$al) { $page->kill("Aucune lettre en attente"); return; } @@ -231,18 +240,13 @@ class AXLetterModule extends PLModule return; } - $page->kill("L'envoi de l'annonce {$al->title()} est annulé"); + $page->kill("L'envoi de l'annonce {$al->title()} est annulé"); } function handler_valid(&$page, $force = null) { require_once dirname(__FILE__) . '/axletter/axletter.inc.php'; - if (!AXLetter::hasPerms()) { - return PL_FORBIDDEN; - } - - $url = parse_url($_SERVER['HTTP_REFERER']); - if ($force != 'force' && trim($url['path'], '/') != 'ax/edit') { + if (!AXLetter::hasPerms() || !S::has_xsrf_token()) { return PL_FORBIDDEN; } @@ -284,7 +288,7 @@ class AXLetterModule extends PLModule $action = Post::v('action'); $uid = Post::v('uid'); } - if ($uid) { + if ($uid && S::has_xsrf_token()) { $uids = preg_split('/ *[,;\: ] */', $uid); foreach ($uids as $uid) { switch ($action) { @@ -296,9 +300,11 @@ class AXLetterModule extends PLModule break; } if (!$res) { - $page->trig("Personne ne oorrespond à l'identifiant '$uid'"); + $page->trig("Personne ne correspond à l'identifiant '$uid'"); } } + } elseif ($uid) { + $page->trig("L'opération sur la liste des administrateurs AX a échouée, merci de réessayer."); } $page->changeTpl('axletter/admin.tpl'); @@ -308,16 +314,17 @@ class AXLetterModule extends PLModule INNER JOIN auth_user_md5 AS u USING(user_id) INNER JOIN aliases AS a ON (u.user_id = a.id AND a.type = 'a_vie')"); $page->assign('admins', $res); - + $importer = new CSVImporter('axletter_ins'); $importer->registerFunction('user_id', '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', 'hash')); + $importer->apply($page, "admin/axletter", array('user_id', 'email', 'prenom', 'nom', 'promo', 'flag', 'hash')); } function idFromMail($line, $key) { static $field; + global $globals; if (!isset($field)) { $field = array('email', 'mail', 'login', 'bestalias', 'forlife', 'flag'); foreach ($field as $fld) { @@ -330,23 +337,29 @@ class AXLetterModule extends PLModule $email = $line[$field]; if (strpos($email, '@') === false) { $user = $email; + $domain = $globals->mail->domain2; } else { - global $globals; - list($user, $domain) = explode('@', $email); - if ($domain != $globals->mail->domain && $domain != $globals->mail->domain2 + list($user, $domain) = explode('@', $email); + } + if ($domain != $globals->mail->domain && $domain != $globals->mail->domain2 && $domain != $globals->mail->alias_dom && $domain != $globals->mail->alias_dom2) { - return '0'; - } - 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 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(); @@ -355,10 +368,11 @@ class AXLetterModule extends PLModule function createHash($line, $key) { - $hash = implode(time(), $line); + $hash = implode(time(), $line) . rand(); $hash = md5($hash); return $hash; } } +// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: ?>