MDL-50837 mod_scorm: Fix availability checks
authorJuan Leyva <juanleyvadelgado@gmail.com>
Thu, 22 Oct 2015 06:03:12 +0000 (08:03 +0200)
committerEloy Lafuente (stronk7) <stronk7@moodle.org>
Wed, 4 Nov 2015 11:54:55 +0000 (12:54 +0100)
mod/scorm/lib.php
mod/scorm/loadSCO.php
mod/scorm/player.php
mod/scorm/view.php

index bafc6d3..66c6926 100644 (file)
@@ -930,7 +930,7 @@ function scorm_get_file_info($browser, $areas, $course, $cm, $context, $filearea
  * @return bool false if file not found, does not return if found - just send the file
  */
 function scorm_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options=array()) {
-    global $CFG;
+    global $CFG, $DB;
 
     if ($context->contextlevel != CONTEXT_MODULE) {
         return false;
@@ -938,8 +938,18 @@ function scorm_pluginfile($course, $cm, $context, $filearea, $args, $forcedownlo
 
     require_login($course, true, $cm);
 
+    $canmanageactivity = has_capability('moodle/course:manageactivities', $context);
     $lifetime = null;
 
+    // Check SCORM availability.
+    if (!$canmanageactivity) {
+        $scorm = $DB->get_record('scorm', array('id' => $cm->instance), 'id, timeopen, timeclose', MUST_EXIST);
+        list($available, $warnings) = scorm_get_availability_status($scorm);
+        if (!$available) {
+            return false;
+        }
+    }
+
     if ($filearea === 'content') {
         $revision = (int)array_shift($args); // Prevents caching problems - ignored here.
         $relativepath = implode('/', $args);
@@ -949,7 +959,7 @@ function scorm_pluginfile($course, $cm, $context, $filearea, $args, $forcedownlo
     } else if ($filearea === 'package') {
         // Check if the global setting for disabling package downloads is enabled.
         $protectpackagedownloads = get_config('scorm', 'protectpackagedownloads');
-        if ($protectpackagedownloads and !has_capability('moodle/course:manageactivities', $context)) {
+        if ($protectpackagedownloads and !$canmanageactivity) {
             return false;
         }
         $revision = (int)array_shift($args); // Prevents caching problems - ignored here.
index 5e04d5e..3641f47 100644 (file)
@@ -60,15 +60,8 @@ if (!isloggedin()) { // Prevent login page from being shown in iframe.
 
 require_login($course, false, $cm, false); // Call require_login anyway to set up globals correctly.
 
-// Check if scorm closed.
-$timenow = time();
-if ($scorm->timeclose != 0) {
-    if ($scorm->timeopen > $timenow) {
-        print_error('notopenyet', 'scorm', null, userdate($scorm->timeopen));
-    } else if ($timenow > $scorm->timeclose) {
-        print_error('expired', 'scorm', null, userdate($scorm->timeclose));
-    }
-}
+// Check if SCORM is available.
+scorm_require_available($scorm);
 
 $context = context_module::instance($cm->id);
 
index 060fdd4..30789ee 100644 (file)
@@ -116,22 +116,16 @@ if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', cont
     die;
 }
 
-// Check if scorm closed.
-$timenow = time();
-if ($scorm->timeclose != 0) {
-    if ($scorm->timeopen > $timenow) {
-        echo $OUTPUT->header();
-        echo $OUTPUT->box(get_string("notopenyet", "scorm", userdate($scorm->timeopen)), "generalbox boxaligncenter");
-        echo $OUTPUT->footer();
-        die;
-    } else if ($timenow > $scorm->timeclose) {
-        echo $OUTPUT->header();
-        echo $OUTPUT->box(get_string("expired", "scorm", userdate($scorm->timeclose)), "generalbox boxaligncenter");
-        echo $OUTPUT->footer();
-
-        die;
-    }
+// Check if SCORM available.
+list($available, $warnings) = scorm_get_availability_status($scorm);
+if (!$available) {
+    $reason = current(array_keys($warnings));
+    echo $OUTPUT->header();
+    echo $OUTPUT->box(get_string($reason, "scorm", $warnings[$reason]), "generalbox boxaligncenter");
+    echo $OUTPUT->footer();
+    die;
 }
+
 // TOC processing
 $scorm->version = strtolower(clean_param($scorm->version, PARAM_SAFEDIR));   // Just to be safe.
 if (!file_exists($CFG->dirroot.'/mod/scorm/datamodels/'.$scorm->version.'lib.php')) {
index 61ca320..7fe2216 100644 (file)
@@ -158,17 +158,14 @@ if (empty($launch) && ($scorm->displayattemptstatus == SCORM_DISPLAY_ATTEMPTSTAT
 }
 echo $OUTPUT->box(format_module_intro('scorm', $scorm, $cm->id).$attemptstatus, 'generalbox boxaligncenter boxwidthwide', 'intro');
 
-$scormopen = true;
-$timenow = time();
-if (!empty($scorm->timeopen) && $scorm->timeopen > $timenow) {
-    echo $OUTPUT->box(get_string("notopenyet", "scorm", userdate($scorm->timeopen)), "generalbox boxaligncenter");
-    $scormopen = false;
+// Check if SCORM available.
+list($available, $warnings) = scorm_get_availability_status($scorm);
+if (!$available) {
+    $reason = current(array_keys($warnings));
+    echo $OUTPUT->box(get_string($reason, "scorm", $warnings[$reason]), "generalbox boxaligncenter");
 }
-if (!empty($scorm->timeclose) && $timenow > $scorm->timeclose) {
-    echo $OUTPUT->box(get_string("expired", "scorm", userdate($scorm->timeclose)), "generalbox boxaligncenter");
-    $scormopen = false;
-}
-if ($scormopen && empty($launch)) {
+
+if ($available && empty($launch)) {
     scorm_print_launch($USER, $scorm, 'view.php?id='.$cm->id, $cm);
 }
 if (!empty($forcejs)) {