X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=modules%2Faxletter.php;h=523b09a73d8aaf6bd9b7d8cab115513a3067d33e;hb=22467482830abab21d288fab22458450801f6da0;hp=9ad82929af0ffae40b86eac93ba3639b4ed3addb;hpb=a0f050273b792f222a0ae6ec8baf2f3e4fe23023;p=platal.git diff --git a/modules/axletter.php b/modules/axletter.php index 9ad8292..523b09a 100644 --- a/modules/axletter.php +++ b/modules/axletter.php @@ -30,11 +30,11 @@ class AXLetterModule extends PLModule '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/rights' => $this->make_hook('admin_rights', AUTH_MDP, 'admin'), + 'admin/axletter' => $this->make_hook('admin', AUTH_MDP, 'admin'), ); } - function handler_out(&$page, $hash) + function handler_out(&$page, $hash = null) { if (!$hash) { if (!S::logged()) { @@ -62,6 +62,8 @@ class AXLetterModule extends PLModule $perm = AXLetter::hasPerms(); if ($perm) { + $res = XDB::query("SELECT * FROM axletter_ins"); + $page->assign('count', $res->numRows()); $page->assign('new', AXLetter::awaiting()); } $page->assign('axs', AXLetter::subscriptionState()); @@ -128,13 +130,13 @@ class AXLetterModule extends PLModule $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é " + $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); if ($res->numRows() && $res->fetchOneCell() != $id) { - $page->trig("Le nom $shortname est déjà utilisé, merci d'en choisir un autre"); + $page->trig("Le nom $shortname est déjà utilisé, merci d'en choisir un autre"); $shortname = Post::v('old_shortname'); if (empty($shortname)) { Post::kill('valid'); @@ -143,7 +145,7 @@ class AXLetterModule extends PLModule } 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, $promo_min, $promo_max, $echeance, 0, 'new')); @@ -155,6 +157,32 @@ class AXLetterModule extends PLModule SET id = {?}, shortname = {?}, subject = {?}, title = {?}, body = {?}, signature = {?}, promo_min = {?}, promo_max = {?}, echeance = {?}", $id, $shortname, $subject, $title, $body, $signature, $promo_min, $promo_max, $echeance); + if (!$saved) { + $mailer = new PlMailer(); + $mailer->setFrom("support@polytechnique.org"); + $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))"); + global $globals; + 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; @@ -231,7 +259,7 @@ 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) @@ -276,6 +304,97 @@ class AXLetterModule extends PLModule S::v('mail_fmt') != 'texte'); } } + + function handler_admin(&$page, $action = null, $uid = null) + { + require_once dirname(__FILE__) . '/axletter/axletter.inc.php'; + if (Post::has('action')) { + $action = Post::v('action'); + $uid = Post::v('uid'); + } + if ($uid) { + $uids = preg_split('/ *[,;\: ] */', $uid); + foreach ($uids as $uid) { + switch ($action) { + case 'add': + $res = AXLetter::grantPerms($uid); + break; + case 'del'; + $res = AXLetter::revokePerms($uid); + break; + } + if (!$res) { + $page->trig("Personne ne oorrespond à l'identifiant '$uid'"); + } + } + } + + $page->changeTpl('axletter/admin.tpl'); + $res = XDB::iterator("SELECT IF(u.nom_usage != '', u.nom_usage, u.nom) AS nom, + u.prenom, u.promo, a.alias AS forlife + 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 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', '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) { + if (isset($line[$fld])) { + $field = $fld; + break; + } + } + } + $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'; + } + + function createHash($line, $key) + { + $hash = implode(time(), $line) . rand(); + $hash = md5($hash); + return $hash; + } } +// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: ?>