mod-folder MDL-19799 Added set_url calls, replaced deprecated functions
[moodle.git] / mod / forum / markposts.php
CommitLineData
f2379d2d 1<?php // $Id$
331c512a 2
f2379d2d 3 // Set tracking option for the forum.
331c512a 4
5 require_once("../../config.php");
6 require_once("lib.php");
7
90f4745c 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.
70e3da07 11 $returnpage = optional_param('returnpage', 'index.php', PARAM_FILE); // Page to return to.
331c512a 12
4e445355 13 if (! $forum = $DB->get_record("forum", array("id" => $f))) {
12e57b92 14 print_error('invalidforumid', 'forum');
331c512a 15 }
16
4e445355 17 if (! $course = $DB->get_record("course", array("id" => $forum->course))) {
12e57b92 18 print_error('invalidcourseid');
331c512a 19 }
20
90f4745c 21 if (!$cm = get_coursemodule_from_instance("forum", $forum->id, $course->id)) {
12e57b92 22 print_error('invalidcoursemodule');
331c512a 23 }
24
25 $user = $USER;
26
27 require_course_login($course, false, $cm);
28
90f4745c 29 if ($returnpage == 'index.php') {
30 $returnto = forum_go_back_to($returnpage.'?id='.$course->id);
31 } else {
32 $returnto = forum_go_back_to($returnpage.'?f='.$forum->id);
33 }
34
331c512a 35 if (isguest()) { // Guests can't change forum
15ca5e5e 36 $PAGE->set_title($course->shortname);
37 $PAGE->set_heading($course->fullname);
38 echo $OUTPUT->header();
59e28d8f 39 echo $OUTPUT->confirm(get_string('noguesttracking', 'forum').'<br /><br />'.get_string('liketologin'), get_login_url(), $returnto);
396fb912 40 echo $OUTPUT->footer();
331c512a 41 exit;
42 }
43
90f4745c 44 $info = new object();
331c512a 45 $info->name = fullname($user);
46 $info->forum = format_string($forum->name);
47
48 if ($mark == 'read') {
20a3dad5 49 if (!empty($d)) {
4e445355 50 if (! $discussion = $DB->get_record('forum_discussions', array('id'=> $d, 'forum'=> $forum->id))) {
12e57b92 51 print_error('invaliddiscussionid', 'forum');
90f4745c 52 }
53
54 if (forum_tp_mark_discussion_read($user, $d)) {
20a3dad5 55 add_to_log($course->id, "discussion", "mark read", "view.php?f=$forum->id", $d, $cm->id);
20a3dad5 56 }
331c512a 57 } else {
5309fd39 58 // Mark all messages read in current group
59 $currentgroup = groups_get_activity_group($cm);
60 if(!$currentgroup) {
61 // mark_forum_read requires ===false, while get_activity_group
62 // may return 0
63 $currentgroup=false;
64 }
cad56b17 65 if (forum_tp_mark_forum_read($user, $forum->id,$currentgroup)) {
20a3dad5 66 add_to_log($course->id, "forum", "mark read", "view.php?f=$forum->id", $forum->id, $cm->id);
20a3dad5 67 }
331c512a 68 }
69
45293cd3 70/// FUTURE - Add ability to mark them as unread.
331c512a 71// } else { // subscribe
72// if (forum_tp_start_tracking($forum->id, $user->id)) {
73// add_to_log($course->id, "forum", "mark unread", "view.php?f=$forum->id", $forum->id, $cm->id);
74// redirect($returnto, get_string("nowtracking", "forum", $info), 1);
75// } else {
12e57b92 76// print_error("Could not start tracking that forum", $_SERVER["HTTP_REFERER"]);
331c512a 77// }
78 }
79
524f9dbe 80 redirect($returnto);
81
331c512a 82?>