Commit | Line | Data |
---|---|---|
a0f05027 | 1 | <?php |
2 | /*************************************************************************** | |
12262f13 | 3 | * Copyright (C) 2003-2011 Polytechnique.org * |
a0f05027 | 4 | * http://opensource.polytechnique.org/ * |
5 | * * | |
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. * | |
10 | * * | |
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. * | |
15 | * * | |
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 * | |
18 | * Foundation, Inc., * | |
19 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * | |
20 | ***************************************************************************/ | |
21 | ||
84163d58 | 22 | Platal::load('newsletter'); |
a0f05027 | 23 | |
84163d58 RB |
24 | class XnetNlModule extends NewsletterModule |
25 | { | |
26 | function handlers() | |
27 | { | |
28 | return array( | |
5ae3e9a9 SJ |
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'), | |
be166df9 | 33 | '%grp/admin/nl/sync' => $this->make_hook('admin_nl_sync', AUTH_MDP, 'groupadmin'), |
738b4620 | 34 | '%grp/admin/nl/enable' => $this->make_hook('admin_nl_enable', AUTH_MDP, 'groupadmin'), |
5ae3e9a9 SJ |
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'), | |
84163d58 RB |
39 | ); |
40 | } | |
41 | ||
42 | protected function getNl() | |
43 | { | |
44 | global $globals; | |
45 | $group = $globals->asso('shortname'); | |
46 | return NewsLetter::forGroup($group); | |
47 | } | |
738b4620 | 48 | |
be166df9 SJ |
49 | public function handler_admin_nl_sync($page) |
50 | { | |
51 | global $globals; | |
52 | $nl = $this->getNl(); | |
53 | if (!$nl) { | |
54 | return PL_FORBIDDEN; | |
55 | } | |
56 | ||
57 | if (Env::has('add_users')) { | |
58 | S::assert_xsrf_token(); | |
59 | ||
60 | XDB::execute('INSERT IGNORE INTO newsletter_ins (uid, nlid) | |
61 | SELECT g.uid, n.id | |
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')); | |
66 | ||
67 | $page->trigSuccess('Ajouts réalisés avec succès.'); | |
68 | } | |
69 | ||
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')); | |
77 | ||
78 | $users = User::getBulkUsersWithUIDs($uids); | |
79 | usort($users, 'User::compareDirectoryName'); | |
80 | ||
81 | $page->setTitle('Synchronisation de la newsletter'); | |
82 | $page->changeTpl('newsletter/sync.tpl'); | |
83 | $page->assign('users', $users); | |
84 | } | |
85 | ||
738b4620 RB |
86 | public function handler_admin_nl_enable($page) |
87 | { | |
88 | global $globals; | |
89 | $nl = $this->getNl(); | |
90 | if ($nl) { | |
91 | return PL_FORBIDDEN; | |
92 | } | |
93 | ||
94 | if (Post::has('title')) { | |
95 | if (!S::has_xsrf_token()) { | |
96 | return PL_FORBIDDEN; | |
97 | } | |
98 | ||
99 | XDB::execute('INSERT INTO newsletters | |
100 | SET group_id = {?}, name = {?}', | |
101 | $globals->asso('id'), Post::s('title')); | |
102 | ||
103 | $mailer = new PlMailer(); | |
104 | $mailer->assign('group', $globals->asso('nom')); | |
105 | $mailer->assign('user', S::user()); | |
106 | $mailer->send(); | |
107 | ||
108 | $page->trigSuccessRedirect("La lettre d'informations du groupe " . | |
109 | $globals->asso('nom') . " a bien été créée", | |
110 | $globals->asso('shortname') . '/admin/nl'); | |
111 | } | |
112 | $page->setTitle('Activation de la newsletter'); | |
113 | $page->changeTpl('newsletter/enable.tpl'); | |
114 | } | |
a0f05027 | 115 | } |
116 | ||
a7de4ef7 | 117 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
a0f05027 | 118 | ?> |