MDL-52136 mod_forum: forum_post is templatable
[moodle.git] / mod / lesson / mediafile.php
blob65755ba8682a9f91e0956d340d34cef93f102850
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_lesson
25 * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
26 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27 **/
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));
39 require_login($course, false, $cm);
42 // Apply overrides.
43 $lesson->update_effective_access($USER->id);
45 $context = context_module::instance($cm->id);
46 $canmanage = has_capability('mod/lesson:manage', $context);
48 $url = new moodle_url('/mod/lesson/mediafile.php', array('id'=>$id));
49 if ($printclose !== '') {
50 $url->param('printclose', $printclose);
52 $PAGE->set_url($url);
53 $PAGE->set_pagelayout('popup');
54 $PAGE->set_title($course->shortname);
56 $lessonoutput = $PAGE->get_renderer('mod_lesson');
58 // Get the mimetype
59 $mimetype = mimeinfo("type", $lesson->mediafile);
61 if ($printclose) { // this is for framesets
62 if ($lesson->mediaclose) {
63 echo $lessonoutput->header($lesson, $cm);
64 echo $OUTPUT->box('<form><div><input type="button" onclick="top.close();" value="'.get_string("closewindow").'" /></div></form>', 'lessonmediafilecontrol');
65 echo $lessonoutput->footer();
67 exit();
70 echo $lessonoutput->header($lesson, $cm);
72 //TODO: this is copied from view.php - the access should be the same!
73 /// Check these for students only TODO: Find a better method for doing this!
74 /// Check lesson availability
75 /// Check for password
76 /// Check dependencies
77 if (!$canmanage) {
78 if (!$lesson->is_accessible()) { // Deadline restrictions
79 echo $lessonoutput->header($lesson, $cm);
80 if ($lesson->deadline != 0 && time() > $lesson->deadline) {
81 echo $lessonoutput->lesson_inaccessible(get_string('lessonclosed', 'lesson', userdate($lesson->deadline)));
82 } else {
83 echo $lessonoutput->lesson_inaccessible(get_string('lessonopen', 'lesson', userdate($lesson->available)));
85 echo $lessonoutput->footer();
86 exit();
87 } else if ($lesson->usepassword && empty($USER->lessonloggedin[$lesson->id])) { // Password protected lesson code
88 $correctpass = false;
89 if (!empty($userpassword) && (($lesson->password == md5(trim($userpassword))) || ($lesson->password == trim($userpassword)))) {
90 require_sesskey();
91 // with or without md5 for backward compatibility (MDL-11090)
92 $USER->lessonloggedin[$lesson->id] = true;
93 $correctpass = true;
94 } else if (isset($lesson->extrapasswords)) {
95 // Group overrides may have additional passwords.
96 foreach ($lesson->extrapasswords as $password) {
97 if (strcmp($password, md5(trim($userpassword))) === 0 || strcmp($password, trim($userpassword)) === 0) {
98 require_sesskey();
99 $correctpass = true;
100 $USER->lessonloggedin[$lesson->id] = true;
104 if (!$correctpass) {
105 echo $lessonoutput->header($lesson, $cm);
106 echo $lessonoutput->login_prompt($lesson, $userpassword !== '');
107 echo $lessonoutput->footer();
108 exit();
113 // print the embedded media html code
114 echo $OUTPUT->box(lesson_get_media_html($lesson, $context));
116 if ($lesson->mediaclose) {
117 echo '<div class="lessonmediafilecontrol">';
118 echo $OUTPUT->close_window_button();
119 echo '</div>';
122 echo $lessonoutput->footer();