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