weekly release 2.7dev
[moodle.git] / mod / forum / markposts.php
CommitLineData
cd4e6b17 1<?php
2
8f685009
SH
3// This file is part of Moodle - http://moodle.org/
4//
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.
9//
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.
14//
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/>.
17
18/**
19 * Set tracking option for the forum.
2f67a9b3 20 *
8f685009
SH
21 * @package mod-forum
22 * @copyright 2005 mchurch
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 */
cd4e6b17 25
26require_once("../../config.php");
27require_once("lib.php");
28
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.
33
a6855934 34$url = new moodle_url('/mod/forum/markposts.php', array('f'=>$f, 'mark'=>$mark));
cd4e6b17 35if ($d !== 0) {
36 $url->param('d', $d);
37}
38if ($returnpage !== 'index.php') {
39 $url->param('returnpage', $returnpage);
40}
41$PAGE->set_url($url);
42
43if (! $forum = $DB->get_record("forum", array("id" => $f))) {
44 print_error('invalidforumid', 'forum');
45}
46
47if (! $course = $DB->get_record("course", array("id" => $forum->course))) {
48 print_error('invalidcourseid');
49}
50
51if (!$cm = get_coursemodule_from_instance("forum", $forum->id, $course->id)) {
52 print_error('invalidcoursemodule');
53}
54
55$user = $USER;
56
4f0c2d00 57require_login($course, false, $cm);
cd4e6b17 58
59if ($returnpage == 'index.php') {
60 $returnto = forum_go_back_to($returnpage.'?id='.$course->id);
61} else {
62 $returnto = forum_go_back_to($returnpage.'?f='.$forum->id);
63}
64
4f0c2d00 65if (isguestuser()) { // Guests can't change forum
cd4e6b17 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();
71 exit;
72}
73
39790bd8 74$info = new stdClass();
cd4e6b17 75$info->name = fullname($user);
76$info->forum = format_string($forum->name);
77
78if ($mark == 'read') {
79 if (!empty($d)) {
80 if (! $discussion = $DB->get_record('forum_discussions', array('id'=> $d, 'forum'=> $forum->id))) {
81 print_error('invaliddiscussionid', 'forum');
82 }
331c512a 83
cd4e6b17 84 if (forum_tp_mark_discussion_read($user, $d)) {
85 add_to_log($course->id, "discussion", "mark read", "view.php?f=$forum->id", $d, $cm->id);
86 }
90f4745c 87 } else {
cd4e6b17 88 // Mark all messages read in current group
89 $currentgroup = groups_get_activity_group($cm);
90 if(!$currentgroup) {
91 // mark_forum_read requires ===false, while get_activity_group
92 // may return 0
93 $currentgroup=false;
94 }
95 if (forum_tp_mark_forum_read($user, $forum->id,$currentgroup)) {
96 add_to_log($course->id, "forum", "mark read", "view.php?f=$forum->id", $forum->id, $cm->id);
331c512a 97 }
cd4e6b17 98 }
331c512a 99
45293cd3 100/// FUTURE - Add ability to mark them as unread.
331c512a 101// } else { // subscribe
102// if (forum_tp_start_tracking($forum->id, $user->id)) {
103// add_to_log($course->id, "forum", "mark unread", "view.php?f=$forum->id", $forum->id, $cm->id);
104// redirect($returnto, get_string("nowtracking", "forum", $info), 1);
105// } else {
12e57b92 106// print_error("Could not start tracking that forum", $_SERVER["HTTP_REFERER"]);
331c512a 107// }
cd4e6b17 108}
331c512a 109
cd4e6b17 110redirect($returnto);
524f9dbe 111