[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/mod/lesson/ -> mediafile.php (source)

   1  <?php
   2  
   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.
  14  //
  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/>.
  17  
  18  /**
  19   * This file plays the mediafile set in lesson settings.
  20   *
  21   *  If there is a way to use the resource class instead of this code, please change to do so
  22   *
  23   *
  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   **/
  28  
  29  require_once('../../config.php');
  30  require_once($CFG->dirroot.'/mod/lesson/locallib.php');
  31  
  32  $id = required_param('id', PARAM_INT);    // Course Module ID
  33  $printclose = optional_param('printclose', 0, PARAM_INT);
  34  
  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));
  38  
  39  require_login($course, false, $cm);
  40  
  41  $context = context_module::instance($cm->id);
  42  $canmanage = has_capability('mod/lesson:manage', $context);
  43  
  44  $url = new moodle_url('/mod/lesson/mediafile.php', array('id'=>$id));
  45  if ($printclose !== '') {
  46      $url->param('printclose', $printclose);
  47  }
  48  $PAGE->set_url($url);
  49  $PAGE->set_pagelayout('popup');
  50  $PAGE->set_title($course->shortname);
  51  
  52  $lessonoutput = $PAGE->get_renderer('mod_lesson');
  53  
  54  // Get the mimetype
  55  $mimetype = mimeinfo("type", $lesson->mediafile);
  56  
  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();
  62      }
  63      exit();
  64  }
  65  
  66  echo $lessonoutput->header($lesson, $cm);
  67  
  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)));
  81          }
  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              // with or without md5 for backward compatibility (MDL-11090)
  88              $USER->lessonloggedin[$lesson->id] = true;
  89              if ($lesson->highscores) {
  90                  // Logged in - redirect so we go through all of these checks before starting the lesson.
  91                  redirect("$CFG->wwwroot/mod/lesson/view.php?id=$cm->id");
  92              }
  93          } else {
  94              echo $lessonoutput->header($lesson, $cm);
  95              echo $lessonoutput->login_prompt($lesson, $userpassword !== '');
  96              echo $lessonoutput->footer();
  97              exit();
  98          }
  99      }
 100  }
 101  
 102  // print the embedded media html code
 103  echo $OUTPUT->box(lesson_get_media_html($lesson, $context));
 104  
 105  if ($lesson->mediaclose) {
 106     echo '<div class="lessonmediafilecontrol">';
 107     echo $OUTPUT->close_window_button();
 108     echo '</div>';
 109  }
 110  
 111  echo $lessonoutput->footer();


Generated: Fri Nov 28 20:29:05 2014 Cross-referenced by PHPXref 0.7.1