Commit | Line | Data |
---|---|---|
5dfdc904 SJ |
1 | <?php |
2 | /*************************************************************************** | |
3 | * Copyright (C) 2003-2009 Polytechnique.org * | |
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 | ||
22 | class ReminderMl extends Reminder | |
23 | { | |
24 | public function HandleAction($action) | |
25 | { | |
26 | switch ($action) { | |
27 | case 'suscribe': | |
28 | S::assert_xsrf_token(); | |
29 | $subs = array_keys(Post::v('sub_ml')); | |
30 | $current_domain = null; | |
31 | ||
32 | $res = XDB::iterRow("SELECT sub, domain | |
33 | FROM register_subs | |
34 | WHERE uid = {?} AND type = 'list' | |
35 | ORDER BY domain", | |
36 | S::i('uid')); | |
37 | while (list($sub, $domain) = $res->next()) { | |
38 | if (array_shift($subs) == "$sub@$domain") { | |
5dfdc904 SJ |
39 | if ($domain != $current_domain) { |
40 | $current_domain = $domain; | |
5dfdc904 | 41 | } |
e4a1bc55 | 42 | $client = new MMList(S::v('uid'), S::v('password'), $domain); |
5dfdc904 SJ |
43 | $client->subscribe($sub); |
44 | } | |
45 | } | |
46 | ||
47 | $this->UpdateOnYes(); | |
48 | pl_redirect('lists'); | |
49 | break; | |
50 | ||
51 | case 'dismiss': | |
52 | $this->UpdateOnDismiss(); | |
53 | break; | |
54 | ||
55 | case 'no': | |
56 | $this->UpdateOnNo(); | |
57 | break; | |
58 | } | |
59 | } | |
60 | ||
4b0cb388 | 61 | public function Prepare(&$page) |
5dfdc904 | 62 | { |
4b0cb388 | 63 | parent::Prepare($page); |
5dfdc904 SJ |
64 | |
65 | $res = XDB::iterRow("SELECT sub, domain | |
66 | FROM register_subs | |
67 | WHERE uid = {?} AND type = 'list' | |
68 | ORDER BY domain", | |
69 | S::i('uid')); | |
70 | $current_domain = null; | |
71 | $lists = array(); | |
72 | while (list($sub, $domain) = $res->next()) { | |
73 | if ($current_domain != $domain) { | |
74 | $current_domain = $domain; | |
75 | $client = new MMList(S::v('uid'), S::v('password'), $domain); | |
76 | } | |
77 | list($details, ) = $client->get_members($sub); | |
78 | $lists["$sub@$domain"] = $details; | |
79 | } | |
80 | $page->assign_by_ref('lists', $lists); | |
81 | } | |
82 | ||
4b0cb388 VZ |
83 | public function template() |
84 | { | |
85 | return 'reminder/ml.tpl'; | |
86 | } | |
87 | public function title() | |
88 | { | |
89 | return "Inscription aux listes de diffusion"; | |
90 | } | |
91 | ||
0e4b87b2 | 92 | public static function IsCandidate(User &$user, $candidate) |
5dfdc904 | 93 | { |
4b0cb388 VZ |
94 | $res = XDB::query("SELECT COUNT(*) AS lists |
95 | FROM register_subs | |
96 | WHERE uid = {?} AND type = 'list'", | |
97 | $user->id()); | |
5dfdc904 | 98 | |
700b1cf1 SJ |
99 | $mlCount = $res->fetchOneCell(); |
100 | if (!$mlCount) { | |
101 | Reminder::MarkCandidateAsAccepted($user->id(), $candidate); | |
102 | } | |
103 | return ($mlCount > 0); | |
5dfdc904 SJ |
104 | } |
105 | } | |
106 | ||
107 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: | |
108 | ?> |