Added the ability to mark all posts in a forum as read.
[moodle.git] / mod / forum / markposts.php
CommitLineData
331c512a 1<?php
2
3// Set tracking option for the forum.
4
5 require_once("../../config.php");
6 require_once("lib.php");
7
8 require_variable($id); // The forum to mark
9 require_variable($mark); // Read or unread?
10
11 if (! $forum = get_record("forum", "id", $id)) {
12 error("Forum ID was incorrect");
13 }
14
15 if (! $course = get_record("course", "id", $forum->course)) {
16 error("Forum doesn't belong to a course!");
17 }
18
19 if (!($cm = get_coursemodule_from_instance("forum", $forum->id, $course->id))) {
20 $cm->id = NULL;
21 }
22
23 $user = $USER;
24
25 require_course_login($course, false, $cm);
26
27 if (isguest()) { // Guests can't change forum
28 $wwwroot = $CFG->wwwroot.'/login/index.php';
29 if (!empty($CFG->loginhttps)) {
30 $wwwroot = str_replace('http','https', $wwwroot);
31 }
32
33 $strforums = get_string('modulenameplural', 'forum');
34 if ($course->category) {
35 print_header($course->shortname, $course->fullname,
36 "<a href=\"../../course/view.php?id=$course->id\">$course->shortname</a> ->
37 <a href=\"../forum/index.php?id=$course->id\">$strforums</a> ->
38 <a href=\"view.php?f=$forum->id\">".format_string($forum->name,true)."</a>", '', '', true, "", navmenu($course, $cm));
39 } else {
40 print_header($course->shortname, $course->fullname,
41 "<a href=\"../forum/index.php?id=$course->id\">$strforums</a> ->
42 <a href=\"view.php?f=$forum->id\">".format_string($forum->name,true)."</a>", '', '', true, "", navmenu($course, $cm));
43 }
44 notice_yesno(get_string('noguesttracking', 'forum').'<br /><br />'.get_string('liketologin'),
45 $wwwroot, $_SERVER['HTTP_REFERER']);
46 print_footer($course);
47 exit;
48 }
49
50 $returnto = forum_go_back_to("index.php?id=$course->id");
51
52 $info->name = fullname($user);
53 $info->forum = format_string($forum->name);
54
55 if ($mark == 'read') {
56 if (forum_tp_mark_forum_read($user->id, $forum->id)) {
57 add_to_log($course->id, "forum", "mark read", "view.php?f=$forum->id", $forum->id, $cm->id);
58 redirect($returnto);
59 } else {
60 error("Could not mark that forum read.", $_SERVER["HTTP_REFERER"]);
61 }
62
63// } else { // subscribe
64// if (forum_tp_start_tracking($forum->id, $user->id)) {
65// add_to_log($course->id, "forum", "mark unread", "view.php?f=$forum->id", $forum->id, $cm->id);
66// redirect($returnto, get_string("nowtracking", "forum", $info), 1);
67// } else {
68// error("Could not start tracking that forum", $_SERVER["HTTP_REFERER"]);
69// }
70 }
71
72?>