- require_once dirname(__FILE__) . '/axletter/axletter.inc.php';
- if (!AXLetter::hasPerms()) {
- return PL_FORBIDDEN;
- }
-
- $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');
- $echeance_date = Post::v('echeance_date');
- $echeance_time = Post::v('echeance_time');
-
- if (!$id) {
- $res = XDB::query("SELECT * FROM axletter WHERE FIND_IN_SET('new', bits)");
- if ($res->numRows()) {
- extract($res->fetchOneAssoc(), EXTR_OVERWRITE);
- $saved = true;
- } else {
- XDB::execute("INSERT INTO axletter SET id = NULL");
- $id = XDB::insertId();
- }
- if (!$echeance || $echeance == '0000-00-00 00:00:00') {
- $saved = false;
- $new = true;
- }
- } elseif (Post::has('valid')) {
- if (!$subject && $title) {
- $subject = $title;
- }
- if (!$title && $subject) {
- $title = $subject;
- }
- if (!$subject || !$title || !$body) {
- $page->trig("L'article doit avoir un sujet et un contenu");
- Post::kill('valid');
- }
- if (($promo_min > $promo_max && $promo_max != 0)||
- ($promo_min != 0 && ($promo_min <= 1900 || $promo_min >= 2020)) ||
- ($promo_max != 0 && ($promo_max <= 1900 || $promo_max >= 2020)))
- {
- $page->trig("L'intervalle de promotions n'est pas valide");
- Post::kill('valid');
- }
- if (empty($shortname)) {
- $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é "
- . "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");
- $shortname = Post::v('old_shortname');
- if (empty($shortname)) {
- Post::kill('valid');
- }
- }
- }
-
- switch (@Post::v('valid')) {
- 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'));
- $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 = {?},
- 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@" . $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))");
- 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;
- pl_redirect('ax');
- break;
- }
- }
- $page->assign('id', $id);
- $page->assign('shortname', $shortname);
- $page->assign('subject', $subject);
- $page->assign('title', $title);
- $page->assign('body', $body);
- $page->assign('signature', $signature);
- $page->assign('promo_min', $promo_min);
- $page->assign('promo_max', $promo_max);
- $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());
-
- if (!$saved) {
- $select = '';
- for ($i = 0 ; $i < 24 ; $i++) {
- $stamp = sprintf('%02d:00:00', $i);
- if ($stamp == $echeance_time) {
- $sel = ' selected="selected"';
- } else {
- $sel = '';
- }
- $select .= "<option value=\"$stamp\"$sel>{$i}h</option>\n";
- }
- $page->assign('echeance_time', $select);
- }