|
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 00027 require('../../config.php'); 00028 require_once("$CFG->dirroot/mod/url/locallib.php"); 00029 require_once($CFG->libdir . '/completionlib.php'); 00030 00031 $id = optional_param('id', 0, PARAM_INT); // Course module ID 00032 $u = optional_param('u', 0, PARAM_INT); // URL instance id 00033 $redirect = optional_param('redirect', 0, PARAM_BOOL); 00034 00035 if ($u) { // Two ways to specify the module 00036 $url = $DB->get_record('url', array('id'=>$u), '*', MUST_EXIST); 00037 $cm = get_coursemodule_from_instance('url', $url->id, $url->course, false, MUST_EXIST); 00038 00039 } else { 00040 $cm = get_coursemodule_from_id('url', $id, 0, false, MUST_EXIST); 00041 $url = $DB->get_record('url', array('id'=>$cm->instance), '*', MUST_EXIST); 00042 } 00043 00044 $course = $DB->get_record('course', array('id'=>$cm->course), '*', MUST_EXIST); 00045 00046 require_course_login($course, true, $cm); 00047 $context = get_context_instance(CONTEXT_MODULE, $cm->id); 00048 require_capability('mod/url:view', $context); 00049 00050 add_to_log($course->id, 'url', 'view', 'view.php?id='.$cm->id, $url->id, $cm->id); 00051 00052 // Update 'viewed' state if required by completion system 00053 $completion = new completion_info($course); 00054 $completion->set_module_viewed($cm); 00055 00056 $PAGE->set_url('/mod/url/view.php', array('id' => $cm->id)); 00057 00058 // Make sure URL exists before generating output - some older sites may contain empty urls 00059 // Do not use PARAM_URL here, it is too strict and does not support general URIs! 00060 $exturl = trim($url->externalurl); 00061 if (empty($exturl) or $exturl === 'http://') { 00062 url_print_header($url, $cm, $course); 00063 url_print_heading($url, $cm, $course); 00064 url_print_intro($url, $cm, $course); 00065 notice(get_string('invalidstoredurl', 'url'), new moodle_url('/course/view.php', array('id'=>$cm->course))); 00066 die; 00067 } 00068 unset($exturl); 00069 00070 $displaytype = url_get_final_display_type($url); 00071 if ($displaytype == RESOURCELIB_DISPLAY_OPEN) { 00072 // For 'open' links, we always redirect to the content - except if the user 00073 // just chose 'save and display' from the form then that would be confusing 00074 if (!isset($_SERVER['HTTP_REFERER']) || strpos($_SERVER['HTTP_REFERER'], 'modedit.php') === false) { 00075 $redirect = true; 00076 } 00077 } 00078 00079 if ($redirect) { 00080 // coming from course page or url index page, 00081 // the redirection is needed for completion tracking and logging 00082 $fullurl = url_get_full_url($url, $cm, $course); 00083 redirect(str_replace('&', '&', $fullurl)); 00084 } 00085 00086 switch ($displaytype) { 00087 case RESOURCELIB_DISPLAY_EMBED: 00088 url_display_embed($url, $cm, $course); 00089 break; 00090 case RESOURCELIB_DISPLAY_FRAME: 00091 url_display_frame($url, $cm, $course); 00092 break; 00093 default: 00094 url_print_workaround($url, $cm, $course); 00095 break; 00096 }