3 // This file is part of Moodle - http://moodle.org/
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
19 * Set tracking option for the forum.
22 * @copyright 2005 mchurch
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 require_once("../../config.php");
27 require_once("lib.php");
29 $f = required_param('f',PARAM_INT
); // The forum to mark
30 $mark = required_param('mark',PARAM_ALPHA
); // Read or unread?
31 $d = optional_param('d',0,PARAM_INT
); // Discussion to mark.
32 $returnpage = optional_param('returnpage', 'index.php', PARAM_FILE
); // Page to return to.
34 $url = new moodle_url('/mod/forum/markposts.php', array('f'=>$f, 'mark'=>$mark));
38 if ($returnpage !== 'index.php') {
39 $url->param('returnpage', $returnpage);
43 if (! $forum = $DB->get_record("forum", array("id" => $f))) {
44 print_error('invalidforumid', 'forum');
47 if (! $course = $DB->get_record("course", array("id" => $forum->course
))) {
48 print_error('invalidcourseid');
51 if (!$cm = get_coursemodule_from_instance("forum", $forum->id
, $course->id
)) {
52 print_error('invalidcoursemodule');
57 require_login($course, false, $cm);
59 if ($returnpage == 'index.php') {
60 $returnto = forum_go_back_to($returnpage.'?id='.$course->id
);
62 $returnto = forum_go_back_to($returnpage.'?f='.$forum->id
);
65 if (isguestuser()) { // Guests can't change forum
66 $PAGE->set_title($course->shortname
);
67 $PAGE->set_heading($course->fullname
);
68 echo $OUTPUT->header();
69 echo $OUTPUT->confirm(get_string('noguesttracking', 'forum').'<br /><br />'.get_string('liketologin'), get_login_url(), $returnto);
70 echo $OUTPUT->footer();
74 $info = new stdClass();
75 $info->name
= fullname($user);
76 $info->forum
= format_string($forum->name
);
78 if ($mark == 'read') {
80 if (! $discussion = $DB->get_record('forum_discussions', array('id'=> $d, 'forum'=> $forum->id
))) {
81 print_error('invaliddiscussionid', 'forum');
84 forum_tp_mark_discussion_read($user, $d);
86 // Mark all messages read in current group
87 $currentgroup = groups_get_activity_group($cm);
89 // mark_forum_read requires ===false, while get_activity_group
93 forum_tp_mark_forum_read($user, $forum->id
, $currentgroup);
96 /// FUTURE - Add ability to mark them as unread.
97 // } else { // subscribe
98 // if (forum_tp_start_tracking($forum->id, $user->id)) {
99 // redirect($returnto, get_string("nowtracking", "forum", $info), 1);
101 // print_error("Could not start tracking that forum", $_SERVER["HTTP_REFERER"]);