|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 // This file is part of Moodle - http://moodle.org/ 00004 // 00005 // Moodle is free software: you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation, either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // Moodle is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00017 00026 require_once("../../config.php"); 00027 require_once("lib.php"); 00028 00029 $f = required_param('f',PARAM_INT); // The forum to mark 00030 $mark = required_param('mark',PARAM_ALPHA); // Read or unread? 00031 $d = optional_param('d',0,PARAM_INT); // Discussion to mark. 00032 $returnpage = optional_param('returnpage', 'index.php', PARAM_FILE); // Page to return to. 00033 00034 $url = new moodle_url('/mod/forum/markposts.php', array('f'=>$f, 'mark'=>$mark)); 00035 if ($d !== 0) { 00036 $url->param('d', $d); 00037 } 00038 if ($returnpage !== 'index.php') { 00039 $url->param('returnpage', $returnpage); 00040 } 00041 $PAGE->set_url($url); 00042 00043 if (! $forum = $DB->get_record("forum", array("id" => $f))) { 00044 print_error('invalidforumid', 'forum'); 00045 } 00046 00047 if (! $course = $DB->get_record("course", array("id" => $forum->course))) { 00048 print_error('invalidcourseid'); 00049 } 00050 00051 if (!$cm = get_coursemodule_from_instance("forum", $forum->id, $course->id)) { 00052 print_error('invalidcoursemodule'); 00053 } 00054 00055 $user = $USER; 00056 00057 require_login($course, false, $cm); 00058 00059 if ($returnpage == 'index.php') { 00060 $returnto = forum_go_back_to($returnpage.'?id='.$course->id); 00061 } else { 00062 $returnto = forum_go_back_to($returnpage.'?f='.$forum->id); 00063 } 00064 00065 if (isguestuser()) { // Guests can't change forum 00066 $PAGE->set_title($course->shortname); 00067 $PAGE->set_heading($course->fullname); 00068 echo $OUTPUT->header(); 00069 echo $OUTPUT->confirm(get_string('noguesttracking', 'forum').'<br /><br />'.get_string('liketologin'), get_login_url(), $returnto); 00070 echo $OUTPUT->footer(); 00071 exit; 00072 } 00073 00074 $info = new stdClass(); 00075 $info->name = fullname($user); 00076 $info->forum = format_string($forum->name); 00077 00078 if ($mark == 'read') { 00079 if (!empty($d)) { 00080 if (! $discussion = $DB->get_record('forum_discussions', array('id'=> $d, 'forum'=> $forum->id))) { 00081 print_error('invaliddiscussionid', 'forum'); 00082 } 00083 00084 if (forum_tp_mark_discussion_read($user, $d)) { 00085 add_to_log($course->id, "discussion", "mark read", "view.php?f=$forum->id", $d, $cm->id); 00086 } 00087 } else { 00088 // Mark all messages read in current group 00089 $currentgroup = groups_get_activity_group($cm); 00090 if(!$currentgroup) { 00091 // mark_forum_read requires ===false, while get_activity_group 00092 // may return 0 00093 $currentgroup=false; 00094 } 00095 if (forum_tp_mark_forum_read($user, $forum->id,$currentgroup)) { 00096 add_to_log($course->id, "forum", "mark read", "view.php?f=$forum->id", $forum->id, $cm->id); 00097 } 00098 } 00099 00101 // } else { // subscribe 00102 // if (forum_tp_start_tracking($forum->id, $user->id)) { 00103 // add_to_log($course->id, "forum", "mark unread", "view.php?f=$forum->id", $forum->id, $cm->id); 00104 // redirect($returnto, get_string("nowtracking", "forum", $info), 1); 00105 // } else { 00106 // print_error("Could not start tracking that forum", $_SERVER["HTTP_REFERER"]); 00107 // } 00108 } 00109 00110 redirect($returnto); 00111