From 751b4b0421056806761bbb04b51256ff8dd49692 Mon Sep 17 00:00:00 2001
From: Mathew Gancarz
Date: Tue, 21 Feb 2017 16:49:23 -0500
Subject: [PATCH] Loading in tweaks from Denis Noctor from
https://moodle.org/mod/forum/discuss.php?d=339315 and updating to Moodle
3.1.4
---
mod/scorm/lang/en/scorm.php | 13 +++++++++
mod/scorm/loadSCO.php | 64 +++++++++++++++++++++++++++++++++++++++++----
mod/scorm/locallib.php | 6 +++--
mod/scorm/mod_form.php | 13 ++++++---
mod/scorm/player.php | 14 ++++++----
mod/scorm/view.php | 6 +++--
6 files changed, 99 insertions(+), 17 deletions(-)
diff --git a/mod/scorm/lang/en/scorm.php b/mod/scorm/lang/en/scorm.php
index 8b2d014..55bb74a 100644
--- a/mod/scorm/lang/en/scorm.php
+++ b/mod/scorm/lang/en/scorm.php
@@ -1,4 +1,17 @@
Your content is playing in another window.
Do not close this page until the content is finished playing.
';
+$string['popup_simple_closenotice'] = 'A content window is open.\\\nThat window will also be closed.';
+$string['popup_simple_popupblockednotice'] = 'Your content did not launch.
Make sure popups are enabled for this site and try again.
';
+$string['popup_simple_popupmanuallaunch'] = 'Click to Launch Manually';
+$string['popup_simple_redirectingnotice'] = 'Progress is being saved. Redirecting to course page...';
+
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
diff --git a/mod/scorm/loadSCO.php b/mod/scorm/loadSCO.php
index 07cc0b2..175d99e 100644
--- a/mod/scorm/loadSCO.php
+++ b/mod/scorm/loadSCO.php
@@ -72,7 +72,7 @@ if ($sco->scormtype == 'asset') {
$attempt = scorm_get_last_attempt($scorm->id, $USER->id);
$element = (scorm_version_check($scorm->version, SCORM_13)) ? 'cmi.completion_status' : 'cmi.core.lesson_status';
$value = 'completed';
- scorm_insert_track($USER->id, $scorm->id, $sco->id, $attempt, $element, $value);
+ $result = scorm_insert_track($USER->id, $scorm->id, $sco->id, $attempt, $element, $value);
}
// Trigger the SCO launched event.
@@ -136,8 +136,20 @@ echo html_writer::tag('title', 'LoadSCO');
function doredirect() {
if (myGetAPIHandle() != null) {
- location = "";
- }
+ popup == 2)
+ echo 'openContentWindow();';
+ else
+ echo 'location = "'. $scolaunchurl .'";';
+ /*
+ * Simple-Popup mods end
+ */
+ ?>
+ }
else {
document.body.innerHTML = "" +
" " +
@@ -151,11 +163,52 @@ echo html_writer::tag('title', 'LoadSCO');
} else {
clearInterval(timer);
document.body.innerHTML = "
";
- location = "";
- }
+ popup == 2)
+ echo 'openContentWindow();';
+ else
+ echo 'location = "'. $scolaunchurl .'";';
+ ?>
+ }
}, 1000);
}
}
+
+ function openContentWindow() {
+ cWin = window.top.open("","scorm_content_id; ?>");
+ monitorContentWindow();
+ }
+ function monitorContentWindow() {
+ if (cWin != null) cWin.focus();
+ document.body.innerHTML = ""
+ window.top.onbeforeunload = function() { if (cWin != null && !cWin.closed) return "" };
+ window.top.onunload = function() { if (cWin != null && !cWin.closed) cWin.close(); };
+ setTimeout(checkContentWindowOpen,500);
+ }
+ function checkContentWindowOpen() {
+ if (cWin == null) {
+ document.body.innerHTML = '
';
+ } else if (cWin.closed) {
+ document.body.innerHTML = " '>";
+ setTimeout((function(){window.top.location = "wwwroot.'/course/view.php?id='.$scorm->course; ?>";}),2000);
+ } else {
+ setTimeout(checkContentWindowOpen,2000);
+ }
+ }
+
//]]>
@@ -165,3 +218,4 @@ echo html_writer::tag('title', 'LoadSCO');
echo html_writer::end_tag('head');
echo html_writer::tag('body', html_writer::tag('p', get_string('activitypleasewait', 'scorm')), array('onload' => "doredirect();"));
echo html_writer::end_tag('html');
+?>
\ No newline at end of file
diff --git a/mod/scorm/locallib.php b/mod/scorm/locallib.php
index e161a88..fefbc47 100644
--- a/mod/scorm/locallib.php
+++ b/mod/scorm/locallib.php
@@ -74,7 +74,7 @@ class scorm_package_file_info extends file_info_stored {
}
/**
- * Returns an array of the popup options for SCORM and each options default value
+ * Returns an array of the popup options for SCORM and each options default value / some variables in the original code changed as underscores were removed Denis Noctor
*
* @return array an array of popup options as the key and their defaults as the value
*/
@@ -152,9 +152,11 @@ function scorm_get_updatefreq_array() {
*
* @return array an array of popup display options
*/
+// Simple-Popup - added new option to array
function scorm_get_popup_display_array() {
return array(0 => get_string('currentwindow', 'scorm'),
- 1 => get_string('popup', 'scorm'));
+ 1 => get_string('popup', 'scorm'),
+ 2 => get_string('popup_simple', 'scorm'));
}
/**
diff --git a/mod/scorm/mod_form.php b/mod/scorm/mod_form.php
index 983937c..4b67c6a 100644
--- a/mod/scorm/mod_form.php
+++ b/mod/scorm/mod_form.php
@@ -13,6 +13,7 @@
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
+// some variables in the original code changed as underscores in 2014 code were removed Denis Noctor
if (!defined('MOODLE_INTERNAL')) {
die('Direct access to this script is forbidden.'); // It must be included from a Moodle page.
@@ -111,14 +112,18 @@ class mod_scorm_mod_form extends moodleform_mod {
$mform->setDefault('width', $cfgscorm->framewidth);
$mform->setType('width', PARAM_INT);
$mform->setAdvanced('width', $cfgscorm->framewidth_adv);
- $mform->disabledIf('width', 'popup', 'eq', 0);
+ // Simple-Popup - mod
+ //$mform->disabledIf('width', 'popup', 'eq', 0);
+ $mform->disabledIf('width', 'popup', 'noteq', 1);
// Height.
$mform->addElement('text', 'height', get_string('height', 'scorm'), 'maxlength="5" size="5"');
$mform->setDefault('height', $cfgscorm->frameheight);
$mform->setType('height', PARAM_INT);
$mform->setAdvanced('height', $cfgscorm->frameheight_adv);
- $mform->disabledIf('height', 'popup', 'eq', 0);
+ // Simple-Popup - mod
+ //$mform->disabledIf('height', 'popup', 'eq', 0);
+ $mform->disabledIf('height', 'popup', 'noteq', 1);
// Window Options.
$winoptgrp = array();
@@ -127,7 +132,9 @@ class mod_scorm_mod_form extends moodleform_mod {
$mform->setDefault($key, $value);
}
$mform->addGroup($winoptgrp, 'winoptgrp', get_string('options', 'scorm'), ' ', false);
- $mform->disabledIf('winoptgrp', 'popup', 'eq', 0);
+ // Simple-Popup - mod
+ //$mform->disabledIf('winoptgrp', 'popup', 'eq', 0);
+ $mform->disabledIf('winoptgrp', 'popup', 'noteq', 1);
$mform->setAdvanced('winoptgrp', $cfgscorm->winoptgrp_adv);
// Display activity name.
diff --git a/mod/scorm/player.php b/mod/scorm/player.php
index beca474..fafd6a3 100644
--- a/mod/scorm/player.php
+++ b/mod/scorm/player.php
@@ -105,7 +105,7 @@ $strexit = get_string('exitactivity', 'scorm');
$coursecontext = context_course::instance($course->id);
if ($displaymode == 'popup') {
- $PAGE->set_pagelayout('embedded');
+ $PAGE->set_pagelayout('popup');
} else {
$shortname = format_string($course->shortname, true, array('context' => $coursecontext));
$pagetitle = strip_tags("$shortname: ".format_string($scorm->name));
@@ -159,7 +159,8 @@ $completion = new completion_info($course);
$completion->set_module_viewed($cm);
// Print the page header.
-if (empty($scorm->popup) || $displaymode == 'popup') {
+// Simple-Popup - changed from empty($scorm->popup) to $scorm->popup != 1
+if ($scorm->popup != 1 || $displaymode=='popup') {
// Redirect back to the correct section if one section per page is being used.
$exiturl = course_get_url($course, $cm->sectionnum);
@@ -214,7 +215,8 @@ if ($scorm->hidetoc == SCORM_TOC_POPUP or $mode == 'browse' or $mode == 'review'
echo html_writer::start_div('', array('id' => 'toctree'));
-if (empty($scorm->popup) || $displaymode == 'popup') {
+// Simple-Popup - changed from empty($scorm->popup) to $scorm->popup != 1
+if ($scorm->popup != 1 || $displaymode == 'popup') {
echo $result->toc;
} else {
// Added incase javascript popups are blocked we don't provide a direct link
@@ -228,7 +230,8 @@ echo html_writer::end_div(); // Toc box ends.
echo html_writer::tag('noscript', html_writer::div(get_string('noscriptnoscorm', 'scorm'), '', array('id' => 'noscript')));
if ($result->prerequisites) {
- if ($scorm->popup != 0 && $displaymode !== 'popup') {
+ // Simple-Popup - changed from $scorm->popup != 0 to $scorm->popup == 1
+ if ($scorm->popup == 1 && $displaymode !=='popup') {
// Clean the name for the window as IE is fussy.
$name = preg_replace("/[^A-Za-z0-9]/", "", $scorm->name);
if (!$name) {
@@ -252,7 +255,8 @@ echo html_writer::end_div(); // Scorm page ends.
$scoes = scorm_get_toc_object($USER, $scorm, $currentorg, $sco->id, $mode, $attempt);
$adlnav = scorm_get_adlnav_json($scoes['scoes']);
-if (empty($scorm->popup) || $displaymode == 'popup') {
+// Simple-Popup - changed from empty($scorm->popup) to $scorm->popup != 1
+if ($scorm->popup != 1 || $displaymode == 'popup') {
if (!isset($result->toctitle)) {
$result->toctitle = get_string('toc', 'scorm');
}
diff --git a/mod/scorm/view.php b/mod/scorm/view.php
index 7fe2216..1b52c56 100644
--- a/mod/scorm/view.php
+++ b/mod/scorm/view.php
@@ -65,7 +65,8 @@ $context = context_course::instance($course->id);
$contextmodule = context_module::instance($cm->id);
$launch = false; // Does this automatically trigger a launch based on skipview.
-if (!empty($scorm->popup)) {
+// Simple-Popup - changed from if (!empty($scorm->popup))
+if ($scorm->popup == 1) {
$orgidentifier = '';
$scoid = 0;
@@ -172,7 +173,8 @@ if (!empty($forcejs)) {
echo $OUTPUT->box(get_string("forcejavascriptmessage", "scorm"), "generalbox boxaligncenter forcejavascriptmessage");
}
-if (!empty($scorm->popup)) {
+// Simple-Popup - changed from if (!empty($scorm->popup))
+if ($scorm->popup == 1) {
$PAGE->requires->js_init_call('M.mod_scormform.init');
}
--
2.8.1.windows.1