From 738b4620af26b943d2fa3bfe72a0f4e53ab2a789 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rapha=C3=ABl=20Barrois?= Date: Thu, 5 May 2011 23:23:47 +0200 Subject: [PATCH] Allow group admins to enable NLs for their groups. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Raphaël Barrois --- classes/xnetpage.php | 3 +++ configs/mails.conf | 4 +++ modules/xnetnl.php | 31 +++++++++++++++++++++++ templates/newsletter/enable.mail.tpl | 34 +++++++++++++++++++++++++ templates/newsletter/enable.tpl | 48 ++++++++++++++++++++++++++++++++++++ 5 files changed, 120 insertions(+) create mode 100644 templates/newsletter/enable.mail.tpl create mode 100644 templates/newsletter/enable.tpl diff --git a/classes/xnetpage.php b/classes/xnetpage.php index 0f1a1cd..d32374d 100644 --- a/classes/xnetpage.php +++ b/classes/xnetpage.php @@ -128,6 +128,9 @@ class XnetPage extends PlPage $sub['créer une liste'] = "$dim/lists/create"; $sub['créer un alias'] = "$dim/alias/create"; } + if (!$globals->asso('has_nl')) { + $sub['créer la newsletter'] = "$dim/admin/nl/enable"; + } if (S::admin()) { $sub['gérer les groupes'] = array('href' => 'admin', 'style' => 'color: gray;'); $sub['clear cache'] = array('href' => 'purge_cache?token=' . S::v('xsrf_token'), 'style' => 'color: gray;'); diff --git a/configs/mails.conf b/configs/mails.conf index d17d066..9ded13a 100644 --- a/configs/mails.conf +++ b/configs/mails.conf @@ -82,6 +82,10 @@ from="Polytechnique.org" from="Gestion des NLs" to=br@staff.polytechnique.org +[newsletter_group_enable] +from="Gestion des NLs" +to=br@staff.polytechnique.org + [xnet_registration] from=register@polytechnique.org subject="Inscription à Polytechnique.net" diff --git a/modules/xnetnl.php b/modules/xnetnl.php index 1979087..e04c4d3 100644 --- a/modules/xnetnl.php +++ b/modules/xnetnl.php @@ -30,6 +30,7 @@ class XnetNlModule extends NewsletterModule '%grp/nl/show' => $this->make_hook('nl_show', AUTH_MDP), '%grp/nl/search' => $this->make_hook('nl_search', AUTH_MDP), '%grp/admin/nl' => $this->make_hook('admin_nl', AUTH_MDP, 'groupadmin'), + '%grp/admin/nl/enable' => $this->make_hook('admin_nl_enable', AUTH_MDP, 'groupadmin'), '%grp/admin/nl/edit' => $this->make_hook('admin_nl_edit', AUTH_MDP, 'groupadmin'), '%grp/admin/nl/edit/cancel' => $this->make_hook('admin_nl_cancel', AUTH_MDP, 'groupadmin'), '%grp/admin/nl/edit/valid' => $this->make_hook('admin_nl_valid', AUTH_MDP, 'groupadmin'), @@ -43,6 +44,36 @@ class XnetNlModule extends NewsletterModule $group = $globals->asso('shortname'); return NewsLetter::forGroup($group); } + + public function handler_admin_nl_enable($page) + { + global $globals; + $nl = $this->getNl(); + if ($nl) { + return PL_FORBIDDEN; + } + + if (Post::has('title')) { + if (!S::has_xsrf_token()) { + return PL_FORBIDDEN; + } + + XDB::execute('INSERT INTO newsletters + SET group_id = {?}, name = {?}', + $globals->asso('id'), Post::s('title')); + + $mailer = new PlMailer(); + $mailer->assign('group', $globals->asso('nom')); + $mailer->assign('user', S::user()); + $mailer->send(); + + $page->trigSuccessRedirect("La lettre d'informations du groupe " . + $globals->asso('nom') . " a bien été créée", + $globals->asso('shortname') . '/admin/nl'); + } + $page->setTitle('Activation de la newsletter'); + $page->changeTpl('newsletter/enable.tpl'); + } } // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: diff --git a/templates/newsletter/enable.mail.tpl b/templates/newsletter/enable.mail.tpl new file mode 100644 index 0000000..90ba6cb --- /dev/null +++ b/templates/newsletter/enable.mail.tpl @@ -0,0 +1,34 @@ +{**************************************************************************} +{* *} +{* Copyright (C) 2003-2011 Polytechnique.org *} +{* http://opensource.polytechnique.org/ *} +{* *} +{* This program is free software; you can redistribute it and/or modify *} +{* it under the terms of the GNU General Public License as published by *} +{* the Free Software Foundation; either version 2 of the License, or *} +{* (at your option) any later version. *} +{* *} +{* This program is distributed in the hope that it will be useful, *} +{* but WITHOUT ANY WARRANTY; without even the implied warranty of *} +{* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *} +{* GNU General Public License for more details. *} +{* *} +{* You should have received a copy of the GNU General Public License *} +{* along with this program; if not, write to the Free Software *} +{* Foundation, Inc., *} +{* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *} +{* *} +{**************************************************************************} + +{config_load file="mails.conf" section="newsletter_group_enable"} +{if $mail_part eq 'head'} +{from full=#from#} +{to addr=#to#} +{subject text="Activation de la newsletter du groupe $group"} +{elseif $mail_part eq 'text'} + +La newsletter du groupe $group a été activée par {$user->fullName()}. +{/if} + +{* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *} + diff --git a/templates/newsletter/enable.tpl b/templates/newsletter/enable.tpl new file mode 100644 index 0000000..dce615b --- /dev/null +++ b/templates/newsletter/enable.tpl @@ -0,0 +1,48 @@ +{**************************************************************************} +{* *} +{* Copyright (C) 2003-2011 Polytechnique.org *} +{* http://opensource.polytechnique.org/ *} +{* *} +{* This program is free software; you can redistribute it and/or modify *} +{* it under the terms of the GNU General Public License as published by *} +{* the Free Software Foundation; either version 2 of the License, or *} +{* (at your option) any later version. *} +{* *} +{* This program is distributed in the hope that it will be useful, *} +{* but WITHOUT ANY WARRANTY; without even the implied warranty of *} +{* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *} +{* GNU General Public License for more details. *} +{* *} +{* You should have received a copy of the GNU General Public License *} +{* along with this program; if not, write to the Free Software *} +{* Foundation, Inc., *} +{* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *} +{* *} +{**************************************************************************} + +

+ Mise en place de la lettre d'informations du groupe {$asso->nom} +

+ +

+Tu peux demander sur cette page la mise en place d'une newsletter pour le groupe. + +Tu pourras ensuite envoyer aux membres du groupe qui auront choisi de s'y inscrire, + avec une structure plus adaptée que l'outil d'envoi de mails. +

+ +

+Si le titre par défaut de la newsletter ne te convient pas, n'hésite pas à +le modifier. + +

+{xsrf_token_field} +

+ + +

+

+ +

+
+ -- 2.1.4