X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=modules%2Fnewsletter.php;h=5428466de3c252e238f3bed8eee8a8f63f1ce641;hb=5c11ce3d14becb0799434db3f1c6cc37eab3ca0f;hp=0b84a38606e4e43fa6f2a5b2f4a5a0aa08504851;hpb=84163d5890a4217f6087b274051dcc99cbbafc29;p=platal.git diff --git a/modules/newsletter.php b/modules/newsletter.php index 0b84a38..5428466 100644 --- a/modules/newsletter.php +++ b/modules/newsletter.php @@ -26,12 +26,14 @@ class NewsletterModule extends PLModule return array( 'nl' => $this->make_hook('nl', AUTH_COOKIE), 'nl/show' => $this->make_hook('nl_show', AUTH_COOKIE), + 'nl/search' => $this->make_hook('nl_search', AUTH_COOKIE), 'nl/submit' => $this->make_hook('nl_submit', AUTH_MDP), + 'nl/remaining' => $this->make_hook('nl_remaining', AUTH_MDP), 'admin/nls' => $this->make_hook('admin_nl_groups', AUTH_MDP, 'admin'), 'admin/newsletter' => $this->make_hook('admin_nl', AUTH_MDP, 'admin'), 'admin/newsletter/categories' => $this->make_hook('admin_nl_cat', AUTH_MDP, 'admin'), 'admin/newsletter/edit' => $this->make_hook('admin_nl_edit', AUTH_MDP, 'admin'), - 'admin/newsletter/edit/delete' => $this->make_hook('delete', AUTH_MDP, 'admin'), + 'admin/newsletter/edit/delete' => $this->make_hook('admin_nl_delete', AUTH_MDP, 'admin'), // Automatic mailing is disabled for X.org NL // 'admin/newsletter/edit/cancel' => $this->make_hook('cancel', AUTH_MDP, 'admin'), // 'admin/newsletter/edit/valid' => $this->make_hook('valid', AUTH_MDP, 'admin'), @@ -46,7 +48,7 @@ class NewsletterModule extends PLModule return NewsLetter::forGroup(NewsLetter::GROUP_XORG); } - function handler_nl(&$page, $action = null, $hash = null) + function handler_nl($page, $action = null, $hash = null) { $nl = $this->getNl(); if (!$nl) { @@ -67,7 +69,7 @@ class NewsletterModule extends PLModule $page->assign('nl_list', $nl->listSentIssues(true)); } - function handler_nl_show(&$page, $nid = 'last') + function handler_nl_show($page, $nid = 'last') { $page->changeTpl('newsletter/show.tpl'); $nl = $this->getNl(); @@ -91,7 +93,56 @@ class NewsletterModule extends PLModule } } - function handler_nl_submit(&$page) + function handler_nl_search($page) + { + S::assert_xsrf_token(); + $nl = $this->getNl(); + if (!$nl) { + return PL_NOT_FOUND; + } + + if (!Post::has('nl_search')) { + pl_redirect($nl->prefix()); + } + + $nl_search = Post::t('nl_search'); + $nl_search_type = Post::t('nl_search_type'); + if (!$nl_search || !($nl_search_type > 0 && $nl_search_type < 10)) { + $page->trigErrorRedirect('La recherche est vide ou erronée.', $nl->prefix()); + } + + $page->changeTpl('newsletter/search.tpl'); + $user = S::user(); + $fields = array(1 => 'all', 2 => 'all', 3 => 'title', 4 => 'body', 5 => 'append', 6 => 'all', 7 => 'title', 8 => 'head', 9 => 'signature'); + $res_articles = $res_issues = array(); + if ($nl_search_type < 6) { + $res_articles = $nl->articleSearch($nl_search, $fields[$nl_search_type], $user); + } + if ($nl_search_type > 5 || $nl_search_type == 1) { + $res_issues = $nl->issueSearch($nl_search, $fields[$nl_search_type], $user); + } + + $articles_count = count($res_articles); + $issues_count = count($res_issues); + $results_count = $articles_count + $issues_count; + if ($results_count > 200) { + $page->trigError('Recherche trop générale.'); + } elseif ($results_count == 0) { + $page->trigWarning('Aucun résultat pour cette recherche.'); + } else { + $page->assign('res_articles', $res_articles); + $page->assign('res_issues', $res_issues); + $page->assign('articles_count', $articles_count); + $page->assign('issues_count', $issues_count); + } + + $page->assign_by_ref('nl', $nl); + $page->assign('nl_search', $nl_search); + $page->assign('nl_search_type', $nl_search_type); + $page->assign('results_count', $results_count); + } + + function handler_nl_submit($page) { $page->changeTpl('newsletter/submit.tpl'); @@ -118,7 +169,22 @@ class NewsletterModule extends PLModule $page->addCssLink($nl->cssFile()); } - function handler_admin_nl(&$page, $new = false) { + function handler_nl_remaining($page) + { + require_once 'newsletter.inc.php'; + + pl_content_headers('text/html'); + $page->changeTpl('newsletter/remaining.tpl', NO_SKIN); + + $article = new NLArticle('', Post::t('body'), ''); + $rest = $article->remain(); + + $page->assign('too_long', $rest['remaining_lines'] < 0); + $page->assign('last_line', ($rest['remaining_lines'] == 0)); + $page->assign('remaining', ($rest['remaining_lines'] == 0) ? $rest['remaining_characters_for_last_line'] : $rest['remaining_lines']); + } + + function handler_admin_nl($page, $new = false) { $page->changeTpl('newsletter/admin.tpl'); $page->setTitle('Administration - Newsletter : liste'); @@ -127,7 +193,10 @@ class NewsletterModule extends PLModule return PL_NOT_FOUND; } - if($new) { + if ($new == 'new') { + // Logs NL creation. + S::logger()->log('nl_issue_create', $nid); + $id = $nl->createPending(); pl_redirect($nl->adminPrefix() . '/edit/' . $id); } @@ -136,7 +205,7 @@ class NewsletterModule extends PLModule $page->assign('nl_list', $nl->listAllIssues()); } - function handler_admin_nl_groups(&$page) + function handler_admin_nl_groups($page) { require_once 'newsletter.inc.php'; @@ -146,7 +215,7 @@ class NewsletterModule extends PLModule $page->assign('nls', Newsletter::getAll()); } - function handler_admin_nl_edit(&$page, $nid = 'last', $aid = null, $action = 'edit') { + function handler_admin_nl_edit($page, $nid = 'last', $aid = null, $action = 'edit') { $page->changeTpl('newsletter/edit.tpl'); $page->addCssLink('nl.Polytechnique.org.css'); $page->setTitle('Administration - Newsletter : Édition'); @@ -173,7 +242,7 @@ class NewsletterModule extends PLModule ); // Update the current issue - if($aid == 'update') { + if($aid == 'update' && Post::has('submit')) { // Save common fields $issue->title = Post::s('title'); @@ -264,7 +333,7 @@ class NewsletterModule extends PLModule /** This handler will cancel the sending of the currently pending issue * It is disabled for X.org mailings. */ - function handler_admin_nl_cancel(&$page, $nid, $force = null) + function handler_admin_nl_cancel($page, $nid, $force = null) { $nl = $this->getNl(); if (!$nl) { @@ -287,13 +356,16 @@ class NewsletterModule extends PLModule $page->trigErrorRedirect("Une erreur est survenue lors de l'annulation de l'envoi.", $nl->adminPrefix()); } + // Logs NL cancelling. + S::logger()->log('nl_mailing_cancel', $nid); + $page->trigSuccessRedirect("L'envoi de l'annonce {$issue->title()} est annulé.", $nl->adminPrefix()); } /** This handler will enable the sending of the currently pending issue * It is disabled for X.org mailings. */ - function handler_admin_nl_valid(&$page, $nid, $force = null) + function handler_admin_nl_valid($page, $nid, $force = null) { $nl = $this->getNl(); if (!$nl) { @@ -316,12 +388,15 @@ class NewsletterModule extends PLModule $page->trigErrorRedirect("Une erreur est survenue lors de la validation de l'envoi.", $nl->adminPrefix()); } + // Logs NL validation. + S::logger()->log('nl_mailing_valid', $nid); + $page->trigSuccessRedirect("L'envoi de la newsletter {$issue->title()} a été validé.", $nl->adminPrefix()); } /** This handler will remove the given issue. */ - function handler_admin_nl_delete(&$page, $nid, $force = null) + function handler_admin_nl_delete($page, $nid, $force = null) { $nl = $this->getNl(); if (!$nl) { @@ -347,10 +422,13 @@ class NewsletterModule extends PLModule $page->trigErrorRedirect("Une erreur est survenue lors de la suppression de la lettre.", $nl->adminPrefix()); } + // Logs NL deletion. + S::logger()->log('nl_issue_delete', $nid); + $page->trigSuccessRedirect("La lettre a bien été supprimée.", $nl->adminPrefix()); } - function handler_admin_nl_cat(&$page, $action = 'list', $id = null) { + function handler_admin_nl_cat($page, $action = 'list', $id = null) { $page->setTitle('Administration - Newsletter : Catégories'); $page->assign('title', 'Gestion des catégories de la newsletter'); $table_editor = new PLTableEditor('admin/newsletter/categories','newsletter_cat','cid');