* @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;
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);
} 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.
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);
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')) {
}
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)) {