MDL-21695 adding help string
[moodle.git] / mod / url / view.php
blob5d6e05c5f85710bf47553d9889c43cbcfbd3248b
1 <?php
3 // This file is part of Moodle - http://moodle.org/
4 //
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 /**
19 * URL module main user interface
21 * @package mod-url
22 * @copyright 2009 Petr Skoda (http://skodak.org)
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 require('../../config.php');
27 require_once("$CFG->dirroot/mod/url/locallib.php");
29 $id = optional_param('id', 0, PARAM_INT); // Course module ID
30 $u = optional_param('u', 0, PARAM_INT); // URL instance id
31 $redirect = optional_param('redirect', 0, PARAM_BOOL);
33 if ($u) { // Two ways to specify the module
34 $url = $DB->get_record('url', array('id'=>$u), '*', MUST_EXIST);
35 $cm = get_coursemodule_from_instance('url', $url->id, $url->course, false, MUST_EXIST);
37 } else {
38 $cm = get_coursemodule_from_id('url', $id, 0, false, MUST_EXIST);
39 $url = $DB->get_record('url', array('id'=>$cm->instance), '*', MUST_EXIST);
42 $course = $DB->get_record('course', array('id'=>$cm->course), '*', MUST_EXIST);
44 require_course_login($course, true, $cm);
45 $context = get_context_instance(CONTEXT_MODULE, $cm->id);
47 add_to_log($course->id, 'url', 'view', 'view.php?id='.$cm->id, $url->id, $cm->id);
49 // Update 'viewed' state if required by completion system
50 $completion = new completion_info($course);
51 $completion->set_module_viewed($cm);
53 $PAGE->set_url('/mod/url/view.php', array('id' => $cm->id));
55 if ($redirect) {
56 // coming from course page or url index page,
57 // the redirection is needed for completion tracking and logging
58 $fullurl = url_get_full_url($url, $cm, $course);
59 redirect($fullurl);
62 switch (url_get_final_display_type($url)) {
63 case RESOURCELIB_DISPLAY_EMBED:
64 url_display_embed($url, $cm, $course);
65 break;
66 case RESOURCELIB_DISPLAY_FRAME:
67 url_display_frame($url, $cm, $course);
68 break;
69 default:
70 url_print_workaround($url, $cm, $course);
71 break;