MDL-37801 mod_glossary - encode / decode links to 'showentry' pages during backup...
[moodle.git] / mod / lesson / mediafile.php
blobecf94896c7f63b85f114ace0f3440136f3058da3
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 * This file plays the mediafile set in lesson settings.
21 * If there is a way to use the resource class instead of this code, please change to do so
24 * @package mod
25 * @subpackage lesson
26 * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
27 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28 **/
30 require_once('../../config.php');
31 require_once($CFG->dirroot.'/mod/lesson/locallib.php');
33 $id = required_param('id', PARAM_INT); // Course Module ID
34 $printclose = optional_param('printclose', 0, PARAM_INT);
36 $cm = get_coursemodule_from_id('lesson', $id, 0, false, MUST_EXIST);;
37 $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
38 $lesson = new lesson($DB->get_record('lesson', array('id' => $cm->instance), '*', MUST_EXIST));
40 require_login($course, false, $cm);
42 $context = context_module::instance($cm->id);
43 $canmanage = has_capability('mod/lesson:manage', $context);
45 $url = new moodle_url('/mod/lesson/mediafile.php', array('id'=>$id));
46 if ($printclose !== '') {
47 $url->param('printclose', $printclose);
49 $PAGE->set_url($url);
50 $PAGE->set_pagelayout('popup');
51 $PAGE->set_title($course->shortname);
53 $lessonoutput = $PAGE->get_renderer('mod_lesson');
55 // Get the mimetype
56 $mimetype = mimeinfo("type", $lesson->mediafile);
58 if ($printclose) { // this is for framesets
59 if ($lesson->mediaclose) {
60 echo $lessonoutput->header($lesson, $cm);
61 echo $OUTPUT->box('<form><div><input type="button" onclick="top.close();" value="'.get_string("closewindow").'" /></div></form>', 'lessonmediafilecontrol');
62 echo $lessonoutput->footer();
64 exit();
67 echo $lessonoutput->header($lesson, $cm);
69 //TODO: this is copied from view.php - the access should be the same!
70 /// Check these for students only TODO: Find a better method for doing this!
71 /// Check lesson availability
72 /// Check for password
73 /// Check dependencies
74 /// Check for high scores
75 if (!$canmanage) {
76 if (!$lesson->is_accessible()) { // Deadline restrictions
77 echo $lessonoutput->header($lesson, $cm);
78 if ($lesson->deadline != 0 && time() > $lesson->deadline) {
79 echo $lessonoutput->lesson_inaccessible(get_string('lessonclosed', 'lesson', userdate($lesson->deadline)));
80 } else {
81 echo $lessonoutput->lesson_inaccessible(get_string('lessonopen', 'lesson', userdate($lesson->available)));
83 echo $lessonoutput->footer();
84 exit();
85 } else if ($lesson->usepassword && empty($USER->lessonloggedin[$lesson->id])) { // Password protected lesson code
86 $correctpass = false;
87 if (!empty($userpassword) && (($lesson->password == md5(trim($userpassword))) || ($lesson->password == trim($userpassword)))) {
88 // with or without md5 for backward compatibility (MDL-11090)
89 $USER->lessonloggedin[$lesson->id] = true;
90 if ($lesson->highscores) {
91 // Logged in - redirect so we go through all of these checks before starting the lesson.
92 redirect("$CFG->wwwroot/mod/lesson/view.php?id=$cm->id");
94 } else {
95 echo $lessonoutput->header($lesson, $cm);
96 echo $lessonoutput->login_prompt($lesson, $userpassword !== '');
97 echo $lessonoutput->footer();
98 exit();
103 // print the embedded media html code
104 echo $OUTPUT->box(lesson_get_media_html($lesson, $context));
106 if ($lesson->mediaclose) {
107 echo '<div class="lessonmediafilecontrol">';
108 echo $OUTPUT->close_window_button();
109 echo '</div>';
112 echo $lessonoutput->footer();