quiz MDL-10128 popup checker no longer requests a non-existent file which was causing...
[moodle.git] / mod / forum / markposts.php
CommitLineData
cd4e6b17 1<?php
2
3 // Set tracking option for the forum.
4
5require_once("../../config.php");
6require_once("lib.php");
7
8$f = required_param('f',PARAM_INT); // The forum to mark
9$mark = required_param('mark',PARAM_ALPHA); // Read or unread?
10$d = optional_param('d',0,PARAM_INT); // Discussion to mark.
11$returnpage = optional_param('returnpage', 'index.php', PARAM_FILE); // Page to return to.
12
13$url = new moodle_url($CFG->wwwroot.'/mod/forum/markposts.php', array('f'=>$f, 'mark'=>$mark));
14if ($d !== 0) {
15 $url->param('d', $d);
16}
17if ($returnpage !== 'index.php') {
18 $url->param('returnpage', $returnpage);
19}
20$PAGE->set_url($url);
21
22if (! $forum = $DB->get_record("forum", array("id" => $f))) {
23 print_error('invalidforumid', 'forum');
24}
25
26if (! $course = $DB->get_record("course", array("id" => $forum->course))) {
27 print_error('invalidcourseid');
28}
29
30if (!$cm = get_coursemodule_from_instance("forum", $forum->id, $course->id)) {
31 print_error('invalidcoursemodule');
32}
33
34$user = $USER;
35
36require_course_login($course, false, $cm);
37
38if ($returnpage == 'index.php') {
39 $returnto = forum_go_back_to($returnpage.'?id='.$course->id);
40} else {
41 $returnto = forum_go_back_to($returnpage.'?f='.$forum->id);
42}
43
44if (has_capability('moodle/legacy:guest', get_context_instance(CONTEXT_SYSTEM), 0, false)) { // Guests can't change forum
45 $PAGE->set_title($course->shortname);
46 $PAGE->set_heading($course->fullname);
47 echo $OUTPUT->header();
48 echo $OUTPUT->confirm(get_string('noguesttracking', 'forum').'<br /><br />'.get_string('liketologin'), get_login_url(), $returnto);
49 echo $OUTPUT->footer();
50 exit;
51}
52
53$info = new object();
54$info->name = fullname($user);
55$info->forum = format_string($forum->name);
56
57if ($mark == 'read') {
58 if (!empty($d)) {
59 if (! $discussion = $DB->get_record('forum_discussions', array('id'=> $d, 'forum'=> $forum->id))) {
60 print_error('invaliddiscussionid', 'forum');
61 }
331c512a 62
cd4e6b17 63 if (forum_tp_mark_discussion_read($user, $d)) {
64 add_to_log($course->id, "discussion", "mark read", "view.php?f=$forum->id", $d, $cm->id);
65 }
90f4745c 66 } else {
cd4e6b17 67 // Mark all messages read in current group
68 $currentgroup = groups_get_activity_group($cm);
69 if(!$currentgroup) {
70 // mark_forum_read requires ===false, while get_activity_group
71 // may return 0
72 $currentgroup=false;
73 }
74 if (forum_tp_mark_forum_read($user, $forum->id,$currentgroup)) {
75 add_to_log($course->id, "forum", "mark read", "view.php?f=$forum->id", $forum->id, $cm->id);
331c512a 76 }
cd4e6b17 77 }
331c512a 78
45293cd3 79/// FUTURE - Add ability to mark them as unread.
331c512a 80// } else { // subscribe
81// if (forum_tp_start_tracking($forum->id, $user->id)) {
82// add_to_log($course->id, "forum", "mark unread", "view.php?f=$forum->id", $forum->id, $cm->id);
83// redirect($returnto, get_string("nowtracking", "forum", $info), 1);
84// } else {
12e57b92 85// print_error("Could not start tracking that forum", $_SERVER["HTTP_REFERER"]);
331c512a 86// }
cd4e6b17 87}
331c512a 88
cd4e6b17 89redirect($returnto);
524f9dbe 90