2005-04-25 10:56:11 +00:00
|
|
|
<?php // $Id$
|
2005-04-25 03:56:02 +00:00
|
|
|
|
2005-04-25 10:56:11 +00:00
|
|
|
// Set tracking option for the forum.
|
2005-04-25 03:56:02 +00:00
|
|
|
|
|
|
|
require_once("../../config.php");
|
|
|
|
require_once("lib.php");
|
|
|
|
|
2008-04-13 19:15:02 +00:00
|
|
|
$f = required_param('f',PARAM_INT); // The forum to mark
|
|
|
|
$mark = required_param('mark',PARAM_ALPHA); // Read or unread?
|
|
|
|
$d = optional_param('d',0,PARAM_INT); // Discussion to mark.
|
2005-06-10 19:54:41 +00:00
|
|
|
$returnpage = optional_param('returnpage', 'index.php', PARAM_FILE); // Page to return to.
|
2005-04-25 03:56:02 +00:00
|
|
|
|
2008-06-05 20:16:09 +00:00
|
|
|
if (! $forum = $DB->get_record("forum", array("id" => $f))) {
|
2008-04-13 19:15:02 +00:00
|
|
|
error("Forum ID was incorrect");
|
2005-04-25 03:56:02 +00:00
|
|
|
}
|
|
|
|
|
2008-06-05 20:16:09 +00:00
|
|
|
if (! $course = $DB->get_record("course", array("id" => $forum->course))) {
|
2008-04-13 19:15:02 +00:00
|
|
|
error("Forum doesn't belong to a course!");
|
2005-04-25 03:56:02 +00:00
|
|
|
}
|
|
|
|
|
2008-04-13 19:15:02 +00:00
|
|
|
if (!$cm = get_coursemodule_from_instance("forum", $forum->id, $course->id)) {
|
|
|
|
error("Incorrect cm!");
|
2005-04-25 03:56:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$user = $USER;
|
|
|
|
|
|
|
|
require_course_login($course, false, $cm);
|
|
|
|
|
2008-04-13 19:15:02 +00:00
|
|
|
if ($returnpage == 'index.php') {
|
|
|
|
$returnto = forum_go_back_to($returnpage.'?id='.$course->id);
|
|
|
|
} else {
|
|
|
|
$returnto = forum_go_back_to($returnpage.'?f='.$forum->id);
|
|
|
|
}
|
|
|
|
|
2005-04-25 03:56:02 +00:00
|
|
|
if (isguest()) { // Guests can't change forum
|
|
|
|
$wwwroot = $CFG->wwwroot.'/login/index.php';
|
|
|
|
if (!empty($CFG->loginhttps)) {
|
2007-08-22 19:36:24 +00:00
|
|
|
$wwwroot = str_replace('http:','https:', $wwwroot);
|
2005-04-25 03:56:02 +00:00
|
|
|
}
|
|
|
|
|
2007-10-12 15:55:49 +00:00
|
|
|
$navigation = build_navigation('', $cm);
|
2007-04-16 21:12:29 +00:00
|
|
|
print_header($course->shortname, $course->fullname, $navigation, '', '', true, "", navmenu($course, $cm));
|
2005-04-25 03:56:02 +00:00
|
|
|
notice_yesno(get_string('noguesttracking', 'forum').'<br /><br />'.get_string('liketologin'),
|
2008-04-13 19:15:02 +00:00
|
|
|
$wwwroot, $returnto);
|
2005-04-25 03:56:02 +00:00
|
|
|
print_footer($course);
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2008-04-13 19:15:02 +00:00
|
|
|
$info = new object();
|
2005-04-25 03:56:02 +00:00
|
|
|
$info->name = fullname($user);
|
|
|
|
$info->forum = format_string($forum->name);
|
|
|
|
|
|
|
|
if ($mark == 'read') {
|
2005-04-25 15:00:27 +00:00
|
|
|
if (!empty($d)) {
|
2008-06-05 20:16:09 +00:00
|
|
|
if (! $discussion = $DB->get_record('forum_discussions', array('id'=> $d, 'forum'=> $forum->id))) {
|
2008-04-13 19:15:02 +00:00
|
|
|
error("Discussion ID was incorrect");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (forum_tp_mark_discussion_read($user, $d)) {
|
2005-04-25 15:00:27 +00:00
|
|
|
add_to_log($course->id, "discussion", "mark read", "view.php?f=$forum->id", $d, $cm->id);
|
|
|
|
}
|
2005-04-25 03:56:02 +00:00
|
|
|
} else {
|
2008-07-14 15:39:55 +00:00
|
|
|
// Mark all messages read in current group
|
|
|
|
$currentgroup = groups_get_activity_group($cm);
|
|
|
|
if(!$currentgroup) {
|
|
|
|
// mark_forum_read requires ===false, while get_activity_group
|
|
|
|
// may return 0
|
|
|
|
$currentgroup=false;
|
|
|
|
}
|
2008-11-14 13:34:39 +00:00
|
|
|
if (forum_tp_mark_forum_read($user, $forum->id,$currentgroup)) {
|
2005-04-25 15:00:27 +00:00
|
|
|
add_to_log($course->id, "forum", "mark read", "view.php?f=$forum->id", $forum->id, $cm->id);
|
|
|
|
}
|
2005-04-25 03:56:02 +00:00
|
|
|
}
|
|
|
|
|
2005-04-25 14:02:00 +00:00
|
|
|
/// FUTURE - Add ability to mark them as unread.
|
2005-04-25 03:56:02 +00:00
|
|
|
// } else { // subscribe
|
|
|
|
// if (forum_tp_start_tracking($forum->id, $user->id)) {
|
|
|
|
// add_to_log($course->id, "forum", "mark unread", "view.php?f=$forum->id", $forum->id, $cm->id);
|
|
|
|
// redirect($returnto, get_string("nowtracking", "forum", $info), 1);
|
|
|
|
// } else {
|
2008-04-13 19:15:02 +00:00
|
|
|
// error("Could not start tracking that forum", $_SERVER["HTTP_REFERER"]);
|
2005-04-25 03:56:02 +00:00
|
|
|
// }
|
|
|
|
}
|
|
|
|
|
2005-05-03 16:32:25 +00:00
|
|
|
redirect($returnto);
|
|
|
|
|
2005-04-25 03:56:02 +00:00
|
|
|
?>
|