Uses UserFilters to count NL members.
[platal.git] / modules / xnetnl.php
CommitLineData
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 22Platal::load('newsletter');
a0f05027 23
84163d58
RB
24class XnetNlModule extends NewsletterModule
25{
26 function handlers()
27 {
28 return array(
bfe9f4c7
SJ
29 '%grp/nl' => $this->make_hook('nl', AUTH_PASSWD, 'groups'),
30 '%grp/nl/show' => $this->make_hook('nl_show', AUTH_PASSWD, 'groups'),
31 '%grp/nl/search' => $this->make_hook('nl_search', AUTH_PASSWD, 'groups'),
32 '%grp/admin/nl' => $this->make_hook('admin_nl', AUTH_PASSWD, 'groupadmin'),
33 '%grp/admin/nl/sync' => $this->make_hook('admin_nl_sync', AUTH_PASSWD, 'groupadmin'),
34 '%grp/admin/nl/enable' => $this->make_hook('admin_nl_enable', AUTH_PASSWD, 'groupadmin'),
35 '%grp/admin/nl/edit' => $this->make_hook('admin_nl_edit', AUTH_PASSWD, 'groupadmin'),
36 '%grp/admin/nl/edit/cancel' => $this->make_hook('admin_nl_cancel', AUTH_PASSWD, 'groupadmin'),
37 '%grp/admin/nl/edit/valid' => $this->make_hook('admin_nl_valid', AUTH_PASSWD, 'groupadmin'),
38 '%grp/admin/nl/categories' => $this->make_hook('admin_nl_cat', AUTH_PASSWD, '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
e4b8520c 60 $nl->bulkSubscribe(array_keys(Env::v('add_users')));
be166df9
SJ
61
62 $page->trigSuccess('Ajouts réalisés avec succès.');
63 }
64
e4b8520c 65 // TODO(x2006barrois): remove raw SQL query.
be166df9
SJ
66 $uids = XDB::fetchColumn('SELECT DISTINCT(g.uid)
67 FROM group_members AS g
68 WHERE g.asso_id = {?} AND NOT EXISTS (SELECT ni.*
69 FROM newsletter_ins AS ni
70 INNER JOIN newsletters AS n ON (ni.nlid = n.id)
71 WHERE g.uid = ni.uid AND n.group_id = g.asso_id)',
72 $globals->asso('id'));
73
74 $users = User::getBulkUsersWithUIDs($uids);
75 usort($users, 'User::compareDirectoryName');
76
77 $page->setTitle('Synchronisation de la newsletter');
78 $page->changeTpl('newsletter/sync.tpl');
79 $page->assign('users', $users);
80 }
81
738b4620
RB
82 public function handler_admin_nl_enable($page)
83 {
84 global $globals;
85 $nl = $this->getNl();
86 if ($nl) {
87 return PL_FORBIDDEN;
88 }
89
90 if (Post::has('title')) {
91 if (!S::has_xsrf_token()) {
92 return PL_FORBIDDEN;
93 }
94
95 XDB::execute('INSERT INTO newsletters
96 SET group_id = {?}, name = {?}',
97 $globals->asso('id'), Post::s('title'));
98
99 $mailer = new PlMailer();
100 $mailer->assign('group', $globals->asso('nom'));
101 $mailer->assign('user', S::user());
102 $mailer->send();
103
104 $page->trigSuccessRedirect("La lettre d'informations du groupe " .
105 $globals->asso('nom') . " a bien été créée",
106 $globals->asso('shortname') . '/admin/nl');
107 }
108 $page->setTitle('Activation de la newsletter');
109 $page->changeTpl('newsletter/enable.tpl');
110 }
a0f05027 111}
112
a7de4ef7 113// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
a0f05027 114?>