1<?php
2// This file is part of BOINC.
3// http://boinc.berkeley.edu
4// Copyright (C) 2014 University of California
5//
6// BOINC is free software; you can redistribute it and/or modify it
7// under the terms of the GNU Lesser General Public License
8// as published by the Free Software Foundation,
9// either version 3 of the License, or (at your option) any later version.
10//
11// BOINC 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.
14// See the GNU Lesser General Public License for more details.
15//
16// You should have received a copy of the GNU Lesser General Public License
17// along with BOINC.  If not, see <http://www.gnu.org/licenses/>.
18
19// This file allows people to subscribe to threads.
20// Whenever someone posts to the thread
21// the subscribers will receive a notification email
22
23require_once('../inc/forum.inc');
24
25if (DISABLE_FORUMS) error_page("Forums are disabled");
26
27check_get_args(array("action", "thread", "tnow", "ttok"));
28
29$action = get_str('action');
30$threadid = get_int('thread');
31$thread = BoincThread::lookup_id($threadid);
32$forum = BoincForum::lookup_id($thread->forum);
33
34function show_title($forum, $thread) {
35    switch ($forum->parent_type) {
36    case 0:
37        $category = BoincCategory::lookup_id($forum->category);
38        show_forum_title($category, $forum, $thread);
39        break;
40    case 1:
41        show_team_forum_title($forum, $thread);
42        break;
43    }
44}
45
46function subscribe($forum, $thread, $user) {
47    if (BoincSubscription::replace($user->id, $thread->id)) {
48        page_head(tra("Subscription successful"));
49        show_forum_header($user);
50        show_title($forum, $thread);
51        echo "<p>".tra("You are now subscribed to %1. You will be notified whenever there is a new post.", "<b>".cleanup_title($thread->title)."</b>");
52    } else {
53        page_head(tra("Subscription failed"));
54        echo "<p>".tra("We are currently unable to subscribe you to %1. Please try again later..", "<b>".cleanup_title($thread->title)."</b>");
55    }
56    echo "</p><p><br /><a href=\"forum_thread.php?id=".$thread->id."\">".tra("Return to thread")."</a></p>";
57    page_tail();
58}
59
60function unsubscribe($forum, $thread, $user) {
61    BoincSubscription::delete($user->id, $thread->id);
62    if (!BoincSubscription::lookup($user->id, $thread->id)) {
63        page_head(tra("Unsubscription successful"));
64        show_forum_header($user);
65        show_title($forum, $thread);
66        echo "<p>".tra("You are no longer subscribed to %1. You will no longer receive notifications for this thread.", "<b>".cleanup_title($thread->title)."</b>");
67    } else {
68        page_head(tra("Unsubscription failed"));
69        echo "<p>".tra("We are currently unable to unsubscribe you from %1. Please try again later..", "<b>".cleanup_title($thread->title)."</b>");
70    }
71    echo "</p><p><br /><a href=\"forum_thread.php?id=".$thread->id."\">".tra("Return to thread")."</a></p>";
72    page_tail();
73}
74
75if (!$thread || !$action) {
76    error_page(tra("Unknown subscription action"));
77}
78
79$user = get_logged_in_user();
80check_tokens($user->authenticator);
81
82if ($action == "subscribe") {
83    subscribe($forum, $thread, $user);
84    exit();
85} else if ($action == "unsubscribe") {
86    unsubscribe($forum, $thread, $user);
87    exit();
88}
89
90?>
91
92