3 // This file is part of Moodle - http://moodle.org/
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.
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/>.
19 * URL module main user interface
23 * @copyright 2009 Petr Skoda {@link http://skodak.org}
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27 require('../../config.php');
28 require_once("$CFG->dirroot/mod/url/locallib.php");
29 require_once($CFG->libdir
. '/completionlib.php');
31 $id = optional_param('id', 0, PARAM_INT
); // Course module ID
32 $u = optional_param('u', 0, PARAM_INT
); // URL instance id
33 $redirect = optional_param('redirect', 0, PARAM_BOOL
);
35 if ($u) { // Two ways to specify the module
36 $url = $DB->get_record('url', array('id'=>$u), '*', MUST_EXIST
);
37 $cm = get_coursemodule_from_instance('url', $url->id
, $url->course
, false, MUST_EXIST
);
40 $cm = get_coursemodule_from_id('url', $id, 0, false, MUST_EXIST
);
41 $url = $DB->get_record('url', array('id'=>$cm->instance
), '*', MUST_EXIST
);
44 $course = $DB->get_record('course', array('id'=>$cm->course
), '*', MUST_EXIST
);
46 require_course_login($course, true, $cm);
47 $context = get_context_instance(CONTEXT_MODULE
, $cm->id
);
48 require_capability('mod/url:view', $context);
50 add_to_log($course->id
, 'url', 'view', 'view.php?id='.$cm->id
, $url->id
, $cm->id
);
52 // Update 'viewed' state if required by completion system
53 $completion = new completion_info($course);
54 $completion->set_module_viewed($cm);
56 $PAGE->set_url('/mod/url/view.php', array('id' => $cm->id
));
59 // coming from course page or url index page,
60 // the redirection is needed for completion tracking and logging
61 $fullurl = url_get_full_url($url, $cm, $course);
62 redirect(str_replace('&', '&', $fullurl));
65 switch (url_get_final_display_type($url)) {
66 case RESOURCELIB_DISPLAY_EMBED
:
67 url_display_embed($url, $cm, $course);
69 case RESOURCELIB_DISPLAY_FRAME
:
70 url_display_frame($url, $cm, $course);
73 url_print_workaround($url, $cm, $course);