Merge commit 'origin/master' into fusionax
[platal.git] / include / reminder / ml.inc.php
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") {
39 list($sub, $domain) = explode('@', $list);
40 if ($domain != $current_domain) {
41 $current_domain = $domain;
42 $client = new MMList(S::v('uid'), S::v('password'), $domain);
43 }
44 $client->subscribe($sub);
45 }
46 }
47
48 $this->UpdateOnYes();
49 pl_redirect('lists');
50 break;
51
52 case 'dismiss':
53 $this->UpdateOnDismiss();
54 break;
55
56 case 'no':
57 $this->UpdateOnNo();
58 break;
59 }
60 }
61
62 public function Prepare(&$page)
63 {
64 parent::Prepare($page);
65
66 $res = XDB::iterRow("SELECT sub, domain
67 FROM register_subs
68 WHERE uid = {?} AND type = 'list'
69 ORDER BY domain",
70 S::i('uid'));
71 $current_domain = null;
72 $lists = array();
73 while (list($sub, $domain) = $res->next()) {
74 if ($current_domain != $domain) {
75 $current_domain = $domain;
76 $client = new MMList(S::v('uid'), S::v('password'), $domain);
77 }
78 list($details, ) = $client->get_members($sub);
79 $lists["$sub@$domain"] = $details;
80 }
81 $page->assign_by_ref('lists', $lists);
82 }
83
84 public function template()
85 {
86 return 'reminder/ml.tpl';
87 }
88 public function title()
89 {
90 return "Inscription aux listes de diffusion";
91 }
92
93 public static function IsCandidate(User &$user, $candidate)
94 {
95 $res = XDB::query("SELECT COUNT(*) AS lists
96 FROM register_subs
97 WHERE uid = {?} AND type = 'list'",
98 $user->id());
99
100 $mlCount = $res->fetchOneCell();
101 if (!$mlCount) {
102 Reminder::MarkCandidateAsAccepted($user->id(), $candidate);
103 }
104 return ($mlCount > 0);
105 }
106 }
107
108 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
109 ?>