Fixes vim mode line.
[platal.git] / include / reminder / ml.inc.php
CommitLineData
5dfdc904
SJ
1<?php
2/***************************************************************************
c441aabe 3 * Copyright (C) 2003-2014 Polytechnique.org *
5dfdc904
SJ
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
22class 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'));
5dfdc904
SJ
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") {
f04660bf 38 MailingList::subscribeTo($sub, $domain);
5dfdc904
SJ
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
26ba053e 56 public function Prepare($page)
5dfdc904 57 {
4b0cb388 58 parent::Prepare($page);
5dfdc904
SJ
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'));
5dfdc904
SJ
65 $lists = array();
66 while (list($sub, $domain) = $res->next()) {
22c5024f 67 $mlist = new MailingList($sub, $domain);
92ac93ec 68 list($details, ) = $mlist->getMembers();
5dfdc904
SJ
69 $lists["$sub@$domain"] = $details;
70 }
71 $page->assign_by_ref('lists', $lists);
72 }
73
4b0cb388
VZ
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
26ba053e 83 public static function IsCandidate(User $user, $candidate)
5dfdc904 84 {
4b0cb388
VZ
85 $res = XDB::query("SELECT COUNT(*) AS lists
86 FROM register_subs
87 WHERE uid = {?} AND type = 'list'",
88 $user->id());
5dfdc904 89
700b1cf1
SJ
90 $mlCount = $res->fetchOneCell();
91 if (!$mlCount) {
92 Reminder::MarkCandidateAsAccepted($user->id(), $candidate);
93 }
94 return ($mlCount > 0);
5dfdc904
SJ
95 }
96}
97
448c8cdc 98// vim:set et sw=4 sts=4 sws=4 foldmethod=marker fenc=utf-8:
5dfdc904 99?>