moodle/mod/forum/subscribe.php

69 lines
2.2 KiB
PHP
Raw Normal View History

<?PHP // $Id$
// Subscribe to or unsubscribe from a forum.
require("../../config.php");
require("lib.php");
require_variable($id); // The forum to subscribe or unsubscribe to
optional_variable($force); // Force everyone to be subscribed to this forum?
if (isguest()) {
error("Guests are not allowed to subscribe to posts.", $HTTP_REFERER);
}
if (! $forum = get_record("forum", "id", $id)) {
error("Forum ID was incorrect");
}
if (! $course = get_record("course", "id", $forum->course)) {
error("Forum doesn't belong to a course!");
}
if ($course->category) {
require_login($forum->course);
} else {
require_login();
}
if ($forum->type == "teacher") {
if (!isteacher($course->id)) {
error("You must be a $course->teacher to subscribe to this forum");
}
}
$returnto = forum_go_back_to("index.php?id=$course->id");
if ($force and isteacher($course->id)) {
if (forum_is_forcesubscribed($forum->id)) {
forum_forcesubscribe($forum->id, 0);
redirect($returnto, get_string("everyonecanchoose", "forum"), 1);
} else {
forum_forcesubscribe($forum->id, 1);
redirect($returnto, get_string("everyoneissubscribed", "forum"), 1);
}
}
if (forum_is_forcesubscribed($forum->id)) {
redirect($returnto, get_string("everyoneissubscribed", "forum"), 1);
}
if ( forum_is_subscribed($USER->id, $forum->id) ) {
if (forum_unsubscribe($USER->id, $forum->id) ) {
2002-07-31 16:33:50 +00:00
add_to_log($course->id, "forum", "unsubscribe", "view.php?f=$forum->id", "$forum->id");
redirect($returnto, get_string("nownotsubscribed", "forum", "$forum->name"), 1);
} else {
error("Could not unsubscribe you from that forum", "$HTTP_REFERER");
}
} else { // subscribe
if (forum_subscribe($USER->id, $forum->id) ) {
2002-07-31 16:33:50 +00:00
add_to_log($course->id, "forum", "subscribe", "view.php?f=$forum->id", "$forum->id");
redirect($returnto, get_string("nowsubscribed", "forum", "$forum->name"), 1);
} else {
error("Could not subscribe you to that forum", "$HTTP_REFERER");
}
}
?>