Allow group admins to enable NLs for their groups.
authorRaphaël Barrois <raphael.barrois@polytechnique.org>
Thu, 5 May 2011 21:23:47 +0000 (23:23 +0200)
committerRaphaël Barrois <raphael.barrois@polytechnique.org>
Thu, 5 May 2011 21:24:25 +0000 (23:24 +0200)
Signed-off-by: Raphaël Barrois <raphael.barrois@polytechnique.org>
classes/xnetpage.php
configs/mails.conf
modules/xnetnl.php
templates/newsletter/enable.mail.tpl [new file with mode: 0644]
templates/newsletter/enable.tpl [new file with mode: 0644]

index 0f1a1cd..d32374d 100644 (file)
@@ -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;');
index d17d066..9ded13a 100644 (file)
@@ -82,6 +82,10 @@ from="Polytechnique.org" <contact@polytechnique.org>
 from="Gestion des NLs" <support@polytechnique.org>
 to=br@staff.polytechnique.org
 
+[newsletter_group_enable]
+from="Gestion des NLs" <support@polytechnique.org>
+to=br@staff.polytechnique.org
+
 [xnet_registration]
 from=register@polytechnique.org
 subject="Inscription à Polytechnique.net"
index 1979087..e04c4d3 100644 (file)
@@ -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 (file)
index 0000000..90ba6cb
--- /dev/null
@@ -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 (file)
index 0000000..dce615b
--- /dev/null
@@ -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               *}
+{*                                                                        *}
+{**************************************************************************}
+
+<h1>
+  Mise en place de la lettre d'informations du groupe {$asso->nom}
+</h1>
+
+<p>
+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.
+</p>
+
+<p>
+Si le titre par défaut de la newsletter ne te convient pas, n'hésite pas à
+le modifier.
+
+<form method="post" action="{$platal->ns}admin/nl/enable">
+{xsrf_token_field}
+<p>
+  <label for='title'>Titre de la newsletter</label>
+  <input name='title' id='title' size="40" value="Lettre d'informations du groupe {$asso->nom}" />
+</p>
+<p>
+  <input type="submit" value="Créer" />
+</p>
+</form>
+