f93f848a |
1 | <?PHP // $Id$ |
2 | |
3 | // Subscribe to or unsubscribe from a forum. |
4 | |
5 | require("../../config.php"); |
6 | require("lib.php"); |
7 | |
8 | require_variable($id); // The forum to subscribe or unsubscribe to |
9 | |
10 | if (isguest()) { |
11 | error("Guests are not allowed to subscribe to posts.", $HTTP_REFERER); |
12 | } |
13 | |
14 | if (! $forum = get_record("forum", "id", $id)) { |
15 | error("Forum ID was incorrect"); |
16 | } |
17 | |
18 | if (! $course = get_record("course", "id", $forum->course)) { |
19 | error("Forum doesn't belong to a course!"); |
20 | } |
21 | |
22 | if ($course->category) { |
23 | require_login($forum->course); |
24 | } else { |
25 | require_login(); |
26 | } |
27 | |
28 | $returnto = go_back_to("index.php?id=$course->id"); |
29 | |
30 | if ( is_subscribed($USER->id, $forum->id) ) { |
31 | if (forum_unsubscribe($USER->id, $forum->id) ) { |
32 | add_to_log($course->id, "forum", "unsubscribe", "index.php?id=$course->id", "$forum->id"); |
33 | redirect($returnto, "You are now NOT subscribed to receive '$forum->name' by email.", 1); |
34 | } else { |
35 | error("Could not unsubscribe you from that forum", "$HTTP_REFERER"); |
36 | } |
37 | |
38 | } else { // subscribe |
39 | if (forum_subscribe($USER->id, $forum->id) ) { |
40 | add_to_log($course->id, "forum", "subscribe", "index.php?id=$course->id", "$forum->id"); |
41 | redirect($returnto, "You are now subscribed to recieve '$forum->name' by email.", 1); |
42 | } else { |
43 | error("Could not subscribe you to that forum", "$HTTP_REFERER"); |
44 | } |
45 | } |
46 | |
47 | ?> |