2 /***************************************************************************
3 * Copyright (C) 2003-2011 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
22 Platal
::load('newsletter');
24 class XnetNlModule
extends NewsletterModule
29 '%grp/nl' => $this->make_hook('nl', AUTH_MDP
),
30 '%grp/nl/show' => $this->make_hook('nl_show', AUTH_MDP
),
31 '%grp/nl/search' => $this->make_hook('nl_search', AUTH_MDP
),
32 '%grp/admin/nl' => $this->make_hook('admin_nl', AUTH_MDP
, 'groupadmin'),
33 '%grp/admin/nl/sync' => $this->make_hook('admin_nl_sync', AUTH_MDP
, 'groupadmin'),
34 '%grp/admin/nl/enable' => $this->make_hook('admin_nl_enable', AUTH_MDP
, 'groupadmin'),
35 '%grp/admin/nl/edit' => $this->make_hook('admin_nl_edit', AUTH_MDP
, 'groupadmin'),
36 '%grp/admin/nl/edit/cancel' => $this->make_hook('admin_nl_cancel', AUTH_MDP
, 'groupadmin'),
37 '%grp/admin/nl/edit/valid' => $this->make_hook('admin_nl_valid', AUTH_MDP
, 'groupadmin'),
38 '%grp/admin/nl/categories' => $this->make_hook('admin_nl_cat', AUTH_MDP
, 'groupadmin'),
42 protected function getNl()
45 $group = $globals->asso('shortname');
46 return NewsLetter
::forGroup($group);
49 public function handler_admin_nl_sync($page)
57 if (Env
::has('add_users')) {
58 S
::assert_xsrf_token();
60 XDB
::execute('INSERT IGNORE INTO newsletter_ins (uid, nlid)
62 FROM group_members AS g
63 INNER JOIN newsletters AS n ON (n.group_id = g.asso_id)
64 WHERE g.uid IN {?} AND g.asso_id = {?}',
65 array_keys(Env
::v('add_users')), $globals->asso('id'));
67 $page->trigSuccess('Ajouts réalisés avec succès.');
70 $uids = XDB
::fetchColumn('SELECT DISTINCT(g.uid)
71 FROM group_members AS g
72 WHERE g.asso_id = {?} AND NOT EXISTS (SELECT ni.*
73 FROM newsletter_ins AS ni
74 INNER JOIN newsletters AS n ON (ni.nlid = n.id)
75 WHERE g.uid = ni.uid AND n.group_id = g.asso_id)',
76 $globals->asso('id'));
78 $users = User
::getBulkUsersWithUIDs($uids);
79 usort($users, 'User::compareDirectoryName');
81 $page->setTitle('Synchronisation de la newsletter');
82 $page->changeTpl('newsletter/sync.tpl');
83 $page->assign('users', $users);
86 public function handler_admin_nl_enable($page)
94 if (Post
::has('title')) {
95 if (!S
::has_xsrf_token()) {
99 XDB
::execute('INSERT INTO newsletters
100 SET group_id = {?}, name = {?}',
101 $globals->asso('id'), Post
::s('title'));
103 $mailer = new PlMailer();
104 $mailer->assign('group', $globals->asso('nom'));
105 $mailer->assign('user', S
::user());
108 $page->trigSuccessRedirect("La lettre d'informations du groupe " .
109 $globals->asso('nom') . " a bien été créée",
110 $globals->asso('shortname') . '/admin/nl');
112 $page->setTitle('Activation de la newsletter');
113 $page->changeTpl('newsletter/enable.tpl');
117 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: