Skip to content

Commit

Permalink
MDL-28295 SCORM change mangement of pop-up windows, load full SCORM A…
Browse files Browse the repository at this point in the history
…PI in existing window - this fixes an issue with IE 7 and httpreq communication
  • Loading branch information
danmarsden committed Aug 10, 2011
1 parent 4b85dc1 commit cca2289
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 40 deletions.
16 changes: 16 additions & 0 deletions mod/scorm/db/upgrade.php
Expand Up @@ -540,6 +540,22 @@ function xmldb_scorm_upgrade($oldversion) {
upgrade_mod_savepoint(true, 2011021402, 'scorm');
}

if ($oldversion < 2011021403) {
//MDL-28295 the behaviour of pop-up windows has now changed - it now loads the full Player in the window
//because of this, pop-up windows now include the TOC and the nav bar - disabling these for existing SCORMS
//as it is a change that most users won't expect.
//get all SCORMS that use a new window.
require_once($CFG->dirroot."/mod/scorm/lib.php");
$rs = $DB->get_recordset('scorm', array('popup' => 1), '', 'id,hidetoc,hidenav');
foreach ($rs as $scorm) {
$scorm->hidetoc = SCORM_TOC_DISABLED;
$scorm->hidenav = 1;
$DB->update_record('scorm', $scorm);
}
$rs->close();

upgrade_mod_savepoint(true, 2011021403, 'scorm');
}
return true;
}

Expand Down
7 changes: 3 additions & 4 deletions mod/scorm/module.js
Expand Up @@ -126,10 +126,9 @@ M.mod_scorm.init = function(Y, hide_nav, hide_toc, toc_title, window_name, launc
var cwidth = scormplayerdata.cwidth;
var cheight = scormplayerdata.cheight;
var poptions = scormplayerdata.popupoptions;
scorm_openpopup("loadSCO.php?" + node.title, window_name, poptions, cwidth, cheight);
}
else {
content.replaceChild(obj, old);
scorm_openpopup(M.cfg.wwwroot + "/mod/scorm/loadSCO.php?" + node.title, window_name, poptions, cwidth, cheight);
} else {
content.replaceChild(obj, old);
}
} else {
content.appendChild(obj);
Expand Down
3 changes: 1 addition & 2 deletions mod/scorm/player.js
@@ -1,6 +1,5 @@
function scorm_openpopup(url,name,options,width,height) {
fullurl = M.cfg.wwwroot + '/mod/scorm/' + url;
windowobj = window.open(fullurl,name,options);
windowobj = window.open(url,name,options);
if (!windowobj) {
return;
}
Expand Down
62 changes: 30 additions & 32 deletions mod/scorm/player.php
Expand Up @@ -6,15 +6,13 @@
require_once($CFG->dirroot.'/mod/scorm/locallib.php');
require_once($CFG->libdir . '/completionlib.php');

//
// Checkin' script parameters
//
$id = optional_param('cm', '', PARAM_INT); // Course Module ID, or
$a = optional_param('a', '', PARAM_INT); // scorm ID
$scoid = required_param('scoid', PARAM_INT); // sco ID
$mode = optional_param('mode', 'normal', PARAM_ALPHA); // navigation mode
$currentorg = optional_param('currentorg', '', PARAM_RAW); // selected organization
$newattempt = optional_param('newattempt', 'off', PARAM_ALPHA); // the user request to start a new attempt
$displaymode = optional_param('display','',PARAM_ALPHA);

//IE 6 Bug workaround
if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 6') !== false) {
Expand Down Expand Up @@ -69,9 +67,13 @@
$strpopup = get_string('popup','scorm');
$strexit = get_string('exitactivity','scorm');

$pagetitle = strip_tags("$course->shortname: ".format_string($scorm->name));
$PAGE->set_title($pagetitle);
$PAGE->set_heading($course->fullname);
if ($displaymode == 'popup') {
$PAGE->set_pagelayout('popup');
} else {
$pagetitle = strip_tags("$course->shortname: ".format_string($scorm->name));
$PAGE->set_title($pagetitle);
$PAGE->set_heading($course->fullname);
}

if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_COURSE,$course->id))) {
echo $OUTPUT->header();
Expand Down Expand Up @@ -154,22 +156,16 @@
//
// Print the page header
//
$bodyscript = '';
if ($scorm->popup == 1) {
$bodyscript = 'onunload="main.close();"';
if (empty($scorm->popup) || $displaymode=='popup') {
$exitlink = '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$scorm->course.'" title="'.$strexit.'">'.$strexit.'</a> ';
$PAGE->set_button($exitlink);
}

$exitlink = '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$scorm->course.'" title="'.$strexit.'">'.$strexit.'</a> ';

$PAGE->set_button($exitlink);

$PAGE->requires->data_for_js('scormplayerdata', Array('cwidth'=>$scorm->width,'cheight'=>$scorm->height,
'popupoptions' => $scorm->options), true);
$PAGE->requires->js('/mod/scorm/request.js', true);
$PAGE->requires->js('/lib/cookies.js', true);
//$PAGE->requires->js('/mod/scorm/loaddatamodel.php?id='.$cm->id.$scoidstr.$modestr.$attemptstr, true);
$PAGE->requires->css('/mod/scorm/styles.css');

echo $OUTPUT->header();

// NEW IMS TOC
Expand All @@ -189,15 +185,6 @@
<script id="external-scormapi" type="text/JavaScript"></script>
</div>
<div id="scormtop">
<?php
if ($result->prerequisites) {
if ($scorm->popup != 0) {
//Added incase javascript popups are blocked we don't provide a direct link to the pop-up as JS communication can fail - the user must disable their pop-up blocker.
$linkcourse = '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$scorm->course.'">' . get_string('finishscormlinkname','scorm') . '</a>';
echo $OUTPUT->box(get_string('finishscorm','scorm',$linkcourse), 'generalbox', 'altfinishlink');
}
}
?>
<?php echo $mode == 'browse' ? '<div id="scormmode" class="scorm-left">'.get_string('browsemode','scorm')."</div>\n" : ''; ?>
<?php echo $mode == 'review' ? '<div id="scormmode" class="scorm-left">'.get_string('reviewmode','scorm')."</div>\n" : ''; ?>
<div id="scormnav" class="scorm-right">
Expand All @@ -209,7 +196,14 @@
</div> <!-- Scormnav -->
</div> <!-- Scormtop -->
<div id="toctree" class="generalbox">
<?php echo $result->toc; ?>
<?php
if (empty($scorm->popup) || $displaymode == 'popup') {
echo $result->toc;
} else {
//Added incase javascript popups are blocked we don't provide a direct link to the pop-up as JS communication can fail - the user must disable their pop-up blocker.
$linkcourse = '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$scorm->course.'">' . get_string('finishscormlinkname', 'scorm') . '</a>';
echo $OUTPUT->box(get_string('finishscorm', 'scorm', $linkcourse), 'generalbox', 'altfinishlink');
}?>
</div> <!-- toctree -->
</div> <!-- tocbox -->
<noscript>
Expand All @@ -220,7 +214,7 @@
</noscript>
<?php
if ($result->prerequisites) {
if ($scorm->popup != 0) {
if ($scorm->popup != 0 && $displaymode !=='popup') {
// Clean the name for the window as IE is fussy
$name = preg_replace("/[^A-Za-z0-9]/", "", $scorm->name);
if (!$name) {
Expand All @@ -229,7 +223,11 @@
$name = 'scorm_'.$name;

echo html_writer::script('', $CFG->wwwroot.'/mod/scorm/player.js');
echo html_writer::script(js_writer::function_call('scorm_openpopup', Array("loadSCO.php?id=".$cm->id.$scoidpop, $name, $scorm->options, $scorm->width, $scorm->height)));
$url = new moodle_url($PAGE->url, array('scoid' => $sco->id, 'display' => 'popup'));
echo html_writer::script(
js_writer::function_call('scorm_openpopup', Array($url->out(false),
$name, $scorm->options,
$scorm->width, $scorm->height)));
?>
<noscript>
<!--[if IE]>
Expand All @@ -248,12 +246,12 @@
</div> <!-- SCORM page -->
<?php
// NEW IMS TOC
if (!isset($result->toctitle)) {
$result->toctitle = get_string('toc', 'scorm');
if (empty($scorm->popup) || $displaymode == 'popup') {
if (!isset($result->toctitle)) {
$result->toctitle = get_string('toc', 'scorm');
}
$PAGE->requires->js_init_call('M.mod_scorm.init', array($scorm->hidenav, $scorm->hidetoc, $result->toctitle, $name, $sco->id));
}

$PAGE->requires->js_init_call('M.mod_scorm.init', array($scorm->hidenav, $scorm->hidetoc, $result->toctitle, $name, $sco->id));

if (!empty($forcejs)) {
echo $OUTPUT->box(get_string("forcejavascriptmessage", "scorm"), "generalbox boxaligncenter forcejavascriptmessage");
}
Expand Down
2 changes: 1 addition & 1 deletion mod/scorm/styles.css
Expand Up @@ -23,7 +23,7 @@
#page-mod-scorm-view .structurelist {list-style-type: none;white-space: nowrap;}
#page-mod-scorm-view .structurelist {list-style-type: none;white-space: nowrap;}

#page-mod-scorm-player #altfinishlink {float: right; border: 0px; padding: 0px; }
#page-mod-scorm-player #altfinishlink {font-size: 140%;border: 0px; padding: 0px; }
#page-mod-scorm-player #altpopuplink {position: left; padding: 5px; border: 0px; }
#page-mod-scorm-player #scormmode {float: left; border: 0px; }

Expand Down
2 changes: 1 addition & 1 deletion mod/scorm/version.php
Expand Up @@ -6,7 +6,7 @@
/////////////////////////////////////////////////////////////////////////////////


$module->version = 2011021402; // The (date) version of this module
$module->version = 2011021403; // The (date) version of this module
$module->requires = 2010080300; // The version of Moodle that is required
$module->cron = 300; // How often should cron check this module (seconds)?

0 comments on commit cca2289

Please sign in to comment.