diff --git a/mod/scorm/lib.php b/mod/scorm/lib.php index 4449ec7958b..d7edf9e40d3 100644 --- a/mod/scorm/lib.php +++ b/mod/scorm/lib.php @@ -1349,3 +1349,37 @@ function scorm_set_completion($scorm, $userid, $completionstate = COMPLETION_COM $completion->update_state($cm, $completionstate, $userid); } } + +/** + * Check and set the correct mode and attempt when entering a SCORM package. + * + * @param object $scorm object + * @param string $newattempt should a new attempt be generated here. + * @param int $attempt the attempt number this is for. + * @param int $userid the userid of the user. + * @param string $mode the current mode that has been selected. + */ +function scorm_check_mode($scorm, $newattempt, &$attempt, $userid, &$mode) { + global $DB; + if (($newattempt == 'on') && (($attempt < $scorm->maxattempt) || ($scorm->maxattempt == 0))) { + $attempt++; + $mode = 'normal'; + } else if ($mode != 'browse') { // Check if review mode should be set. + $mode = 'normal'; // Set to normal mode by default. + + // If all tracks == passed, failed or completed then use review mode. + $tracks = $DB->get_recordset('scorm_scoes_track', array('scormid' => $scorm->id, 'userid' => $userid, + 'attempt' => $attempt, 'element' => 'cmi.core.lesson_status')); + foreach ($tracks as $track) { + if (($track->value == 'completed') || ($track->value == 'passed') || ($track->value == 'failed')) { + $mode = 'review'; + } else { // Found an incomplete sco so exit and use normal mode. + $mode = 'normal'; + break; + } + } + $tracks->close(); + } else if (($mode == 'browse') && ($scorm->hidebrowse == 1)) { // Prevent Browse mode if hidebrowse is set. + $mode = 'normal'; + } +} diff --git a/mod/scorm/locallib.php b/mod/scorm/locallib.php index 59b75f67073..51d79ee37ce 100644 --- a/mod/scorm/locallib.php +++ b/mod/scorm/locallib.php @@ -1378,8 +1378,8 @@ function scorm_get_toc_object($user, $scorm, $currentorg='', $scoid='', $mode='n global $CFG, $DB, $PAGE, $OUTPUT; $modestr = ''; - if ($mode == 'browse') { - $modestr = '&mode='.$mode; + if ($mode != 'normal') { + $modestr = '&mode='.$mode; } $result = array(); @@ -1791,8 +1791,8 @@ function scorm_get_toc($user, $scorm, $cmid, $toclink=TOCJSLINK, $currentorg='', $tocmenu = scorm_format_toc_for_droplist($scorm, $scoes['scoes'][0]->children, $scoes['usertracks'], $currentorg, $organizationsco); $modestr = ''; - if ($mode == 'browse') { - $modestr = '&mode='.$mode; + if ($mode != 'normal') { + $modestr = '&mode='.$mode; } $url = new moodle_url('/mod/scorm/player.php?a='.$scorm->id.'¤torg='.$currentorg.$modestr); diff --git a/mod/scorm/player.php b/mod/scorm/player.php index 36dc9bc7fd7..2c1fc53ecf1 100644 --- a/mod/scorm/player.php +++ b/mod/scorm/player.php @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/// This page prints a particular instance of aicc/scorm package +// This page prints a particular instance of aicc/scorm package. require_once('../../config.php'); require_once($CFG->dirroot.'/mod/scorm/locallib.php'); @@ -25,8 +25,8 @@ $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); +$newattempt = optional_param('newattempt', 'off', PARAM_ALPHA); // the user request to start a new attempt. +$displaymode = optional_param('display', '', PARAM_ALPHA); // IE 9 workaround for Flash bug: MDL-29213 // Note that it's not clear if appending the meta tag via $CFG->additionalhtmlhead @@ -63,6 +63,11 @@ if (!empty($id)) { } else { print_error('missingparameter'); } +// If new attempt is being triggered set normal mode and increment attempt number. +$attempt = scorm_get_last_attempt($scorm->id, $USER->id); + +// Check mode is correct and set mode/attempt (uses pass by reference). +scorm_check_mode($scorm, $newattempt, $attempt, $USER->id, $mode); $url = new moodle_url('/mod/scorm/player.php', array('scoid'=>$scoid, 'cm'=>$cm->id)); if ($mode !== 'normal') { @@ -104,7 +109,7 @@ if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', $cou die; } -//check if scorm closed +// Check if scorm closed. $timenow = time(); if ($scorm->timeclose !=0) { if ($scorm->timeopen > $timenow) { @@ -121,17 +126,11 @@ if ($scorm->timeclose !=0) { } } // TOC processing -$scorm->version = strtolower(clean_param($scorm->version, PARAM_SAFEDIR)); // Just to be safe +$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')) { $scorm->version = 'scorm_12'; } require_once($CFG->dirroot.'/mod/scorm/datamodels/'.$scorm->version.'lib.php'); -$attempt = scorm_get_last_attempt($scorm->id, $USER->id); -if (($newattempt=='on') && (($attempt < $scorm->maxattempt) || ($scorm->maxattempt == 0))) { - $attempt++; - $mode = 'normal'; -} -$attemptstr = '&attempt=' . $attempt; $result = scorm_get_toc($USER, $scorm, $cm->id, TOCJSLINK, $currentorg, $scoid, $mode, $attempt, true, true); $sco = $result->sco; @@ -142,33 +141,11 @@ if ($scorm->lastattemptlock == 1 && $result->attemptleft == 0) { exit; } -if (($mode == 'browse') && ($scorm->hidebrowse == 1)) { - $mode = 'normal'; -} -if ($mode != 'browse') { - if ($trackdata = scorm_get_tracks($sco->id, $USER->id, $attempt)) { - if (($trackdata->status == 'completed') || ($trackdata->status == 'passed') || ($trackdata->status == 'failed')) { - $mode = 'review'; - } else { - $mode = 'normal'; - } - } else { - $mode = 'normal'; - } -} - add_to_log($course->id, 'scorm', 'view', "player.php?cm=$cm->id&scoid=$sco->id", "$scorm->id", $cm->id); $scoidstr = '&scoid='.$sco->id; -$scoidpop = '&scoid='.$sco->id; $modestr = '&mode='.$mode; -if ($mode == 'browse') { - $modepop = '&mode='.$mode; -} else { - $modepop = ''; -} -$orgstr = '¤torg='.$currentorg; $SESSION->scorm = new stdClass(); $SESSION->scorm->scoid = $sco->id; @@ -176,11 +153,11 @@ $SESSION->scorm->scormstatus = 'Not Initialized'; $SESSION->scorm->scormmode = $mode; $SESSION->scorm->attempt = $attempt; -// Mark module viewed +// Mark module viewed. $completion = new completion_info($course); $completion->set_module_viewed($cm); -// Print the page header +// Print the page header. if (empty($scorm->popup) || $displaymode=='popup') { $exitlink = ''.$strexit.' '; $PAGE->set_button($exitlink); @@ -198,7 +175,6 @@ $PAGE->requires->js('/mod/scorm/request.js', true); $PAGE->requires->js('/lib/cookies.js', true); echo $OUTPUT->header(); -// NEW IMS TOC $PAGE->requires->string_for_js('navigation', 'scorm'); $PAGE->requires->string_for_js('toc', 'scorm'); $PAGE->requires->string_for_js('hide', 'moodle'); @@ -252,7 +228,7 @@ if ($result->prerequisites) { } $name = 'scorm_'.$name; echo html_writer::script('', $CFG->wwwroot.'/mod/scorm/player.js'); - $url = new moodle_url($PAGE->url, array('scoid' => $sco->id, 'display' => 'popup')); + $url = new moodle_url($PAGE->url, array('scoid' => $sco->id, 'display' => 'popup', 'mode' => $mode)); echo html_writer::script( js_writer::function_call('scorm_openpopup', Array($url->out(false), $name, $scorm->options, @@ -276,7 +252,7 @@ if ($result->prerequisites) { id, $mode, $attempt); $adlnav = scorm_get_adlnav_json($scoes['scoes']); -// NEW IMS TOC + if (empty($scorm->popup) || $displaymode == 'popup') { if (!isset($result->toctitle)) { $result->toctitle = get_string('toc', 'scorm');