Start using the new MailingList class.
[platal.git] / include / reminder / ml.inc.php
1 <?php
2 /***************************************************************************
3 * Copyright (C) 2003-2011 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
31 $res = XDB::iterRow("SELECT sub, domain
32 FROM register_subs
33 WHERE uid = {?} AND type = 'list'
34 ORDER BY domain",
35 S::i('uid'));
36 while (list($sub, $domain) = $res->next()) {
37 if (array_shift($subs) == "$sub@$domain") {
38 $mlist = new MailingList($sub, $domain, S::user());
39 $mlist->subscribe();
40 }
41 }
42
43 $this->UpdateOnYes();
44 pl_redirect('lists');
45 break;
46
47 case 'dismiss':
48 $this->UpdateOnDismiss();
49 break;
50
51 case 'no':
52 $this->UpdateOnNo();
53 break;
54 }
55 }
56
57 public function Prepare($page)
58 {
59 parent::Prepare($page);
60
61 $res = XDB::iterRow("SELECT sub, domain
62 FROM register_subs
63 WHERE uid = {?} AND type = 'list'
64 ORDER BY domain",
65 S::i('uid'));
66 $lists = array();
67 while (list($sub, $domain) = $res->next()) {
68 $mlist = new MailingList($sub, $domain, S::user());
69 list($details, ) = $mlist->getMembers();
70 $lists["$sub@$domain"] = $details;
71 }
72 $page->assign_by_ref('lists', $lists);
73 }
74
75 public function template()
76 {
77 return 'reminder/ml.tpl';
78 }
79 public function title()
80 {
81 return "Inscription aux listes de diffusion";
82 }
83
84 public static function IsCandidate(User $user, $candidate)
85 {
86 $res = XDB::query("SELECT COUNT(*) AS lists
87 FROM register_subs
88 WHERE uid = {?} AND type = 'list'",
89 $user->id());
90
91 $mlCount = $res->fetchOneCell();
92 if (!$mlCount) {
93 Reminder::MarkCandidateAsAccepted($user->id(), $candidate);
94 }
95 return ($mlCount > 0);
96 }
97 }
98
99 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
100 ?>