MDL-51569 mod_choice: Prevent users from updating choices with curl
[moodle.git] / mod / lesson / mediafile.php
blob897a20c067eb268824324d9e8269151641fb4d02
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);
41 $context = context_module::instance($cm->id);
42 $canmanage = has_capability('mod/lesson:manage', $context);
44 $url = new moodle_url('/mod/lesson/mediafile.php', array('id'=>$id));
45 if ($printclose !== '') {
46 $url->param('printclose', $printclose);
48 $PAGE->set_url($url);
49 $PAGE->set_pagelayout('popup');
50 $PAGE->set_title($course->shortname);
52 $lessonoutput = $PAGE->get_renderer('mod_lesson');
54 // Get the mimetype
55 $mimetype = mimeinfo("type", $lesson->mediafile);
57 if ($printclose) { // this is for framesets
58 if ($lesson->mediaclose) {
59 echo $lessonoutput->header($lesson, $cm);
60 echo $OUTPUT->box('<form><div><input type="button" onclick="top.close();" value="'.get_string("closewindow").'" /></div></form>', 'lessonmediafilecontrol');
61 echo $lessonoutput->footer();
63 exit();
66 echo $lessonoutput->header($lesson, $cm);
68 //TODO: this is copied from view.php - the access should be the same!
69 /// Check these for students only TODO: Find a better method for doing this!
70 /// Check lesson availability
71 /// Check for password
72 /// Check dependencies
73 /// Check for high scores
74 if (!$canmanage) {
75 if (!$lesson->is_accessible()) { // Deadline restrictions
76 echo $lessonoutput->header($lesson, $cm);
77 if ($lesson->deadline != 0 && time() > $lesson->deadline) {
78 echo $lessonoutput->lesson_inaccessible(get_string('lessonclosed', 'lesson', userdate($lesson->deadline)));
79 } else {
80 echo $lessonoutput->lesson_inaccessible(get_string('lessonopen', 'lesson', userdate($lesson->available)));
82 echo $lessonoutput->footer();
83 exit();
84 } else if ($lesson->usepassword && empty($USER->lessonloggedin[$lesson->id])) { // Password protected lesson code
85 $correctpass = false;
86 if (!empty($userpassword) && (($lesson->password == md5(trim($userpassword))) || ($lesson->password == trim($userpassword)))) {
87 require_sesskey();
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();