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 * 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
25 * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
26 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
29 require_once('../../config.php');
30 require_once($CFG->dirroot
.'/mod/lesson/locallib.php');
32 $id = required_param('id', PARAM_INT
); // Course Module ID
33 $printclose = optional_param('printclose', 0, PARAM_INT
);
35 $cm = get_coursemodule_from_id('lesson', $id, 0, false, MUST_EXIST
);
36 $course = $DB->get_record('course', array('id' => $cm->course
), '*', MUST_EXIST
);
37 $lesson = new lesson($DB->get_record('lesson', array('id' => $cm->instance
), '*', MUST_EXIST
), $cm);
39 require_login($course, false, $cm);
42 $lesson->update_effective_access($USER->id
);
44 $context = $lesson->context
;
45 $canmanage = $lesson->can_manage();
47 $url = new moodle_url('/mod/lesson/mediafile.php', array('id'=>$id));
48 if ($printclose !== '') {
49 $url->param('printclose', $printclose);
52 $PAGE->set_pagelayout('popup');
53 $PAGE->set_title($course->shortname
);
55 $lessonoutput = $PAGE->get_renderer('mod_lesson');
58 $mimetype = mimeinfo("type", $lesson->mediafile
);
60 if ($printclose) { // this is for framesets
61 if ($lesson->mediaclose
) {
62 echo $lessonoutput->header($lesson, $cm);
63 echo $OUTPUT->box('<form><div><input type="button" onclick="top.close();" value="'.get_string("closewindow").'" /></div></form>', 'lessonmediafilecontrol');
64 echo $lessonoutput->footer();
69 // Check access restrictions.
70 if ($timerestriction = $lesson->get_time_restriction_status()) { // Deadline restrictions.
71 echo $lessonoutput->header($lesson, $cm, '', false, null, get_string('notavailable'));
72 echo $lessonoutput->lesson_inaccessible(get_string($timerestriction->reason
, 'lesson', userdate($timerestriction->time
)));
73 echo $lessonoutput->footer();
75 } else if ($passwordrestriction = $lesson->get_password_restriction_status(null)) { // Password protected lesson code.
76 echo $lessonoutput->header($lesson, $cm, '', false, null, get_string('passwordprotectedlesson', 'lesson', format_string($lesson->name
)));
77 echo $lessonoutput->login_prompt($lesson, $userpassword !== '');
78 echo $lessonoutput->footer();
80 } else if ($dependenciesrestriction = $lesson->get_dependencies_restriction_status()) { // Check for dependencies.
81 echo $lessonoutput->header($lesson, $cm, '', false, null, get_string('completethefollowingconditions', 'lesson', format_string($lesson->name
)));
82 echo $lessonoutput->dependancy_errors($dependenciesrestriction->dependentlesson
, $dependenciesrestriction->errors
);
83 echo $lessonoutput->footer();
87 echo $lessonoutput->header($lesson, $cm);
89 // print the embedded media html code
90 echo $OUTPUT->box(lesson_get_media_html($lesson, $context));
92 if ($lesson->mediaclose
) {
93 echo '<div class="lessonmediafilecontrol">';
94 echo $OUTPUT->close_window_button();
98 echo $lessonoutput->footer();