2002-06-20 15:15:22 +00:00
|
|
|
<?PHP // $Id$
|
|
|
|
|
|
|
|
// Subscribe to or unsubscribe from a forum.
|
|
|
|
|
2003-01-05 14:19:20 +00:00
|
|
|
require_once("../../config.php");
|
|
|
|
require_once("lib.php");
|
2002-06-20 15:15:22 +00:00
|
|
|
|
2002-07-31 14:19:35 +00:00
|
|
|
require_variable($id); // The forum to subscribe or unsubscribe to
|
|
|
|
optional_variable($force); // Force everyone to be subscribed to this forum?
|
2002-08-17 07:53:32 +00:00
|
|
|
optional_variable($user); // Force everyone to be subscribed to this forum?
|
2002-06-20 15:15:22 +00:00
|
|
|
|
|
|
|
if (isguest()) {
|
2003-01-05 06:45:20 +00:00
|
|
|
error("Guests are not allowed to subscribe to posts.", $_SERVER["HTTP_REFERER"]);
|
2002-06-20 15:15:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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!");
|
|
|
|
}
|
|
|
|
|
2002-08-17 07:53:32 +00:00
|
|
|
if ($user) {
|
|
|
|
if (!isteacher($course->id)) {
|
|
|
|
error("Only teachers can subscribe/unsubscribe other people!");
|
|
|
|
}
|
|
|
|
if (! $user = get_record("user", "id", $user)) {
|
|
|
|
error("User ID was incorrect");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$user = $USER;
|
|
|
|
}
|
|
|
|
|
2002-06-20 15:15:22 +00:00
|
|
|
if ($course->category) {
|
|
|
|
require_login($forum->course);
|
|
|
|
} else {
|
|
|
|
require_login();
|
|
|
|
}
|
|
|
|
|
2002-07-04 08:30:36 +00:00
|
|
|
if ($forum->type == "teacher") {
|
|
|
|
if (!isteacher($course->id)) {
|
|
|
|
error("You must be a $course->teacher to subscribe to this forum");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-08-01 03:50:27 +00:00
|
|
|
$returnto = forum_go_back_to("index.php?id=$course->id");
|
2002-06-20 15:15:22 +00:00
|
|
|
|
2002-07-31 14:19:35 +00:00
|
|
|
if ($force and isteacher($course->id)) {
|
|
|
|
if (forum_is_forcesubscribed($forum->id)) {
|
|
|
|
forum_forcesubscribe($forum->id, 0);
|
2002-08-15 17:41:24 +00:00
|
|
|
redirect($returnto, get_string("everyonecanchoose", "forum"), 1);
|
2002-07-31 14:19:35 +00:00
|
|
|
} else {
|
|
|
|
forum_forcesubscribe($forum->id, 1);
|
2002-08-15 17:41:24 +00:00
|
|
|
redirect($returnto, get_string("everyoneissubscribed", "forum"), 1);
|
2002-07-31 14:19:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (forum_is_forcesubscribed($forum->id)) {
|
2002-08-15 17:41:24 +00:00
|
|
|
redirect($returnto, get_string("everyoneissubscribed", "forum"), 1);
|
2002-07-31 14:19:35 +00:00
|
|
|
}
|
|
|
|
|
2002-08-17 07:53:32 +00:00
|
|
|
$info->name = "$user->firstname $user->lastname";
|
|
|
|
$info->forum = $forum->name;
|
|
|
|
|
|
|
|
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");
|
2002-08-17 07:53:32 +00:00
|
|
|
redirect($returnto, get_string("nownotsubscribed", "forum", $info), 1);
|
2002-06-20 15:15:22 +00:00
|
|
|
} else {
|
2003-01-05 06:45:20 +00:00
|
|
|
error("Could not unsubscribe you from that forum", $_SERVER["HTTP_REFERER"]);
|
2002-06-20 15:15:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} else { // subscribe
|
2002-08-17 07:53:32 +00:00
|
|
|
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");
|
2002-08-17 07:53:32 +00:00
|
|
|
redirect($returnto, get_string("nowsubscribed", "forum", $info), 1);
|
2002-06-20 15:15:22 +00:00
|
|
|
} else {
|
2003-01-05 06:45:20 +00:00
|
|
|
error("Could not subscribe you to that forum", $_SERVER["HTTP_REFERER"]);
|
2002-06-20 15:15:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|