|
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 $id = required_param('id',PARAM_INT); // The forum to subscribe or unsubscribe to 00030 $returnpage = optional_param('returnpage', 'index.php', PARAM_FILE); // Page to return to. 00031 00032 $url = new moodle_url('/mod/forum/settracking.php', array('id'=>$id)); 00033 if ($returnpage !== 'index.php') { 00034 $url->param('returnpage', $returnpage); 00035 } 00036 $PAGE->set_url($url); 00037 00038 if (! $forum = $DB->get_record("forum", array("id" => $id))) { 00039 print_error('invalidforumid', 'forum'); 00040 } 00041 00042 if (! $course = $DB->get_record("course", array("id" => $forum->course))) { 00043 print_error('invalidcoursemodule'); 00044 } 00045 00046 if (! $cm = get_coursemodule_from_instance("forum", $forum->id, $course->id)) { 00047 print_error('invalidcoursemodule'); 00048 } 00049 00050 require_course_login($course, false, $cm); 00051 00052 $returnto = forum_go_back_to($returnpage.'?id='.$course->id.'&f='.$forum->id); 00053 00054 if (!forum_tp_can_track_forums($forum)) { 00055 redirect($returnto); 00056 } 00057 00058 $info = new stdClass(); 00059 $info->name = fullname($USER); 00060 $info->forum = format_string($forum->name); 00061 if (forum_tp_is_tracked($forum) ) { 00062 if (forum_tp_stop_tracking($forum->id)) { 00063 add_to_log($course->id, "forum", "stop tracking", "view.php?f=$forum->id", $forum->id, $cm->id); 00064 redirect($returnto, get_string("nownottracking", "forum", $info), 1); 00065 } else { 00066 print_error('cannottrack', '', $_SERVER["HTTP_REFERER"]); 00067 } 00068 00069 } else { // subscribe 00070 if (forum_tp_start_tracking($forum->id)) { 00071 add_to_log($course->id, "forum", "start tracking", "view.php?f=$forum->id", $forum->id, $cm->id); 00072 redirect($returnto, get_string("nowtracking", "forum", $info), 1); 00073 } else { 00074 print_error('cannottrack', '', $_SERVER["HTTP_REFERER"]); 00075 } 00076 } 00077 00078