Skip to content

Commit

Permalink
Merge branch 'master_MDL-27036' of git://github.com/danmarsden/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
stronk7 committed Nov 9, 2011
2 parents df087b8 + 3cfffd8 commit ec25a72
Show file tree
Hide file tree
Showing 11 changed files with 200 additions and 47 deletions.
94 changes: 58 additions & 36 deletions mod/scorm/aicc.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,32 +33,47 @@
$sessionid = required_param('session_id', PARAM_ALPHANUM);
$aiccdata = optional_param('aicc_data', '', PARAM_RAW);

$cfg_scorm = get_config('scorm');

$url = new moodle_url('/mod/scorm/aicc.php', array('command'=>$command, 'session_id'=>$sessionid));
if ($aiccdata !== 0) {
$url->param('aicc_data', $aiccdata);
}
$PAGE->set_url($url);

require_login();
if (empty($cfg_scorm->allowaicchacp)) {
require_login();
if (!confirm_sesskey($sessionid)) {
print_error('invalidsesskey');
}
$aiccuser = $USER;
$scormsession = $SESSION->scorm;
} else {
$scormsession = scorm_aicc_confirm_hacp_session($sessionid);
if (empty($scormsession)) {
print_error('invalidhacpsession', 'scorm');
}
$aiccuser = $DB->get_record('user', array('id'=>$scormsession->userid), 'id,username,lastname,firstname', MUST_EXIST);
}

if (!empty($command) && confirm_sesskey($sessionid)) {
if (!empty($command)) {
$command = strtolower($command);

if (isset($SESSION->scorm_scoid)) {
$scoid = $SESSION->scorm_scoid;
if (isset($scormsession->scoid)) {
$scoid = $scormsession->scoid;
} else {
print_error('cannotcallscript');
}
$mode = 'normal';
if (isset($SESSION->scorm_mode)) {
$mode = $SESSION->scorm_mode;
if (isset($scormsession->scormmode)) {
$mode = $scormsession->scormmode;
}
$status = 'Not Initialized';
if (isset($SESSION->scorm_status)) {
$status = $SESSION->scorm_status;
if (isset($scormsession->scormstatus)) {
$status = $scormsession->scormstatus;
}
if (isset($SESSION->scorm_attempt)) {
$attempt = $SESSION->scorm_attempt;
if (isset($scormsession->attempt)) {
$attempt = $scormsession->attempt;
} else {
$attempt = 1;
}
Expand All @@ -84,20 +99,20 @@
switch ($command) {
case 'getparam':
if ($status == 'Not Initialized') {
$SESSION->scorm_status = 'Running';
$scormsession->scormstatus = 'Running';
$status = 'Running';
}
if ($status != 'Running') {
echo "error=101\r\nerror_text=Terminated\r\n";
} else {
if ($usertrack=scorm_get_tracks($scoid, $USER->id, $attempt)) {
if ($usertrack=scorm_get_tracks($scoid, $aiccuser->id, $attempt)) {
$userdata = $usertrack;
} else {
$userdata->status = '';
$userdata->score_raw = '';
}
$userdata->student_id = $USER->username;
$userdata->student_name = $USER->lastname .', '. $USER->firstname;
$userdata->student_id = $aiccuser->username;
$userdata->student_name = $aiccuser->lastname .', '. $aiccuser->firstname;
$userdata->mode = $mode;
if ($userdata->mode == 'normal') {
$userdata->credit = 'credit';
Expand Down Expand Up @@ -135,10 +150,10 @@
}
if (isset($userdata->{'cmi.core.lesson_status'})) {
echo 'Lesson_Status='.$userdata->{'cmi.core.lesson_status'}.$userdata->entry."\r\n";
$SESSION->scorm_lessonstatus = $userdata->{'cmi.core.lesson_status'};
$scormsession->scorm_lessonstatus = $userdata->{'cmi.core.lesson_status'};
} else {
echo 'Lesson_Status=not attempted'.$userdata->entry."\r\n";
$SESSION->scorm_lessonstatus = 'not attempted';
$scormsession->scorm_lessonstatus = 'not attempted';
}
if (isset($userdata->{'cmi.core.score.raw'})) {
$max = '';
Expand Down Expand Up @@ -183,8 +198,8 @@
if (!empty($aiccdata) && has_capability('mod/scorm:savetrack', get_context_instance(CONTEXT_MODULE, $cm->id))) {
$initlessonstatus = 'not attempted';
$lessonstatus = 'not attempted';
if (isset($SESSION->scorm_lessonstatus)) {
$initlessonstatus = $SESSION->scorm_lessonstatus;
if (isset($scormsession->scorm_lessonstatus)) {
$initlessonstatus = $scormsession->scorm_lessonstatus;
}
$score = '';
$datamodel['lesson_location'] = 'cmi.core.lesson_location';
Expand All @@ -203,7 +218,7 @@
$element = $datamodel[$element];
switch ($element) {
case 'cmi.core.lesson_location':
$id = scorm_insert_track($USER->id, $scorm->id, $sco->id, $attempt, $element, $value);
$id = scorm_insert_track($aiccuser->id, $scorm->id, $sco->id, $attempt, $element, $value);
break;
case 'cmi.core.lesson_status':
$statuses = array(
Expand Down Expand Up @@ -239,13 +254,13 @@
}
if (empty($value) || isset($exites[$value])) {
$subelement = 'cmi.core.exit';
$id = scorm_insert_track($USER->id, $scorm->id, $sco->id, $attempt, $subelement, $value);
$id = scorm_insert_track($aiccuser->id, $scorm->id, $sco->id, $attempt, $subelement, $value);
}
$value = trim(strtolower($values[0]));
$value = $value[0];
if (isset($statuses[$value]) && ($mode == 'normal')) {
$value = $statuses[$value];
$id = scorm_insert_track($USER->id, $scorm->id, $sco->id, $attempt, $element, $value);
$id = scorm_insert_track($aiccuser->id, $scorm->id, $sco->id, $attempt, $element, $value);
}
$lessonstatus = $value;
break;
Expand All @@ -254,23 +269,23 @@
if ((count($values) > 1) && ($values[1] >= $values[0]) && is_numeric($values[1])) {
$subelement = 'cmi.core.score.max';
$value = trim($values[1]);
$id = scorm_insert_track($USER->id, $scorm->id, $sco->id, $attempt, $subelement, $value);
$id = scorm_insert_track($aiccuser->id, $scorm->id, $sco->id, $attempt, $subelement, $value);
if ((count($values) == 3) && ($values[2] <= $values[0]) && is_numeric($values[2])) {
$subelement = 'cmi.core.score.min';
$value = trim($values[2]);
$id = scorm_insert_track($USER->id, $scorm->id, $sco->id, $attempt, $subelement, $value);
$id = scorm_insert_track($aiccuser->id, $scorm->id, $sco->id, $attempt, $subelement, $value);
}
}

$value = '';
if (is_numeric($values[0])) {
$value = trim($values[0]);
$id = scorm_insert_track($USER->id, $scorm->id, $sco->id, $attempt, $element, $value);
$id = scorm_insert_track($aiccuser->id, $scorm->id, $sco->id, $attempt, $element, $value);
}
$score = $value;
break;
case 'cmi.core.session_time':
$SESSION->scorm_session_time = $value;
$scormsession->sessiontime = $value;
break;
}
}
Expand All @@ -283,13 +298,13 @@
next($datarows);
}
$value = rawurlencode($value);
$id = scorm_insert_track($USER->id, $scorm->id, $sco->id, $attempt, $element, $value);
$id = scorm_insert_track($aiccuser->id, $scorm->id, $sco->id, $attempt, $element, $value);
}
}
}
if (($mode == 'browse') && ($initlessonstatus == 'not attempted')) {
$lessonstatus = 'browsed';
$id = scorm_insert_track($USER->id, $scorm->id, $sco->id, $attempt, 'cmi.core.lesson_status', 'browsed');
$id = scorm_insert_track($aiccuser->id, $scorm->id, $sco->id, $attempt, 'cmi.core.lesson_status', 'browsed');
}
if ($mode == 'normal') {
if ($sco = scorm_get_sco($scoid)) {
Expand All @@ -302,7 +317,7 @@
}
}
}
$id = scorm_insert_track($USER->id, $scorm->id, $sco->id, $attempt, 'cmi.core.lesson_status', $lessonstatus);
$id = scorm_insert_track($aiccuser->id, $scorm->id, $sco->id, $attempt, 'cmi.core.lesson_status', $lessonstatus);
}
}
}
Expand Down Expand Up @@ -360,32 +375,32 @@
break;
case 'exitau':
if ($status == 'Running') {
if (isset($SESSION->scorm_session_time) && ($SESSION->scorm_session_time != '')) {
if ($track = $DB->get_record('scorm_scoes_track', array("userid"=>$USER->id,
if (isset($scormsession->sessiontime) && ($scormsession->sessiontime != '')) {
if ($track = $DB->get_record('scorm_scoes_track', array("userid"=>$aiccuser->id,
"scormid"=>$scorm->id,
"scoid"=>$sco->id,
"attempt"=>$attempt,
"element"=>'cmi.core.total_time'))) {
// Add session_time to total_time
$value = scorm_add_time($track->value, $SESSION->scorm_session_time);
$value = scorm_add_time($track->value, $scormsession->sessiontime);
$track->value = $value;
$track->timemodified = time();
$DB->update_record('scorm_scoes_track', $track);
} else {
$track = new stdClass();
$track->userid = $USER->id;
$track->userid = $aiccuser->id;
$track->scormid = $scorm->id;
$track->scoid = $sco->id;
$track->element = 'cmi.core.total_time';
$track->value = $SESSION->scorm_session_time;
$track->value = $scormsession->sessiontime;
$track->attempt = $attempt;
$track->timemodified = time();
$id = $DB->insert_record('scorm_scoes_track', $track);
}
scorm_update_grades($scorm, $USER->id);
scorm_update_grades($scorm, $aiccuser->id);
}
$SESSION->scorm_status = 'Terminated';
$SESSION->scorm_session_time = '';
$scormsession->scormstatus = 'Terminated';
$scormsession->session_time = '';
echo "error=0\r\nerror_text=Successful\r\n";
} else if ($status == 'Terminated') {
echo "error=1\r\nerror_text=Terminated\r\n";
Expand All @@ -405,6 +420,13 @@
echo "error=3\r\nerror_text=Invalid Session ID\r\n";
}
}
if (empty($cfg_scorm->allowaicchacp)) {
$SESSION->scorm = $scormsession;
} else {
$scormsession->timemodified = time();
$DB->update_record('scorm_aicc_session', $scormsession);
}

$aiccresponse = ob_get_contents();
scorm_debug_log_write("aicc", "HACP Response:\r\n$aiccresponse", $scoid);
ob_end_flush();
48 changes: 48 additions & 0 deletions mod/scorm/datamodels/aicclib.php
Original file line number Diff line number Diff line change
Expand Up @@ -341,3 +341,51 @@ function scorm_parse_aicc($scorm) {

return true;
}

/**
* Given a scormid creates an AICC Session record to allow HACP
*
* @param int $scormid - id from scorm table
* @return string hacpsession
*/
function scorm_aicc_get_hacp_session($scormid) {
global $USER, $DB, $SESSION;
$cfg_scorm = get_config('scorm');
if (empty($cfg_scorm->allowaicchacp)) {
return false;
}
$now = time();

$hacpsession = $SESSION->scorm;
$hacpsession->scormid = $scormid;
$hacpsession->hacpsession = random_string(20);
$hacpsession->userid = $USER->id;
$hacpsession->timecreated = $now;
$hacpsession->timemodified = $now;
$DB->insert_record('scorm_aicc_session', $hacpsession);

return $hacpsession->hacpsession;
}

/**
* Check the hacp_session for whether it is valid.
*
* @param string $hacpsession The hacpsession value to check (optional). Normally leave this blank
* and this function will do required_param('sesskey', ...).
* @return mixed - false if invalid, otherwise returns record from scorm_aicc_session table.
*/
function scorm_aicc_confirm_hacp_session($hacpsession) {
global $DB;
$cfg_scorm = get_config('scorm');
if (empty($cfg_scorm->allowaicchacp)) {
return false;
}
$time = time()-($cfg_scorm->aicchacptimeout * 60);
$sql = "hacpsession = ? AND timemodified > ?";
$hacpsession = $DB->get_record_select('scorm_aicc_session', $sql, array($hacpsession, $time));
if (!empty($hacpsession)) { //update timemodified as this is still an active session - resets the timeout.
$hacpsession->timemodified = time();
$DB->update_record('scorm_aicc_session', $hacpsession);
}
return $hacpsession;
}
26 changes: 24 additions & 2 deletions mod/scorm/db/install.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="mod/scorm/db" VERSION="20110731" COMMENT="XMLDB file for Moodle mod/scorm"
<XMLDB PATH="mod/scorm/db" VERSION="20111105" COMMENT="XMLDB file for Moodle mod/scorm"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
>
Expand Down Expand Up @@ -179,7 +179,7 @@
<KEY NAME="scorm_rolluprule_scoid" TYPE="foreign" FIELDS="scoid" REFTABLE="scorm_scoes" REFFIELDS="id" COMMENT="The relative sco" PREVIOUS="scorm_rolluprule_uniq"/>
</KEYS>
</TABLE>
<TABLE NAME="scorm_seq_rolluprulecond" COMMENT="SCORM2004 sequencing rule" PREVIOUS="scorm_seq_rolluprule">
<TABLE NAME="scorm_seq_rolluprulecond" COMMENT="SCORM2004 sequencing rule" PREVIOUS="scorm_seq_rolluprule" NEXT="scorm_aicc_session">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="scoid"/>
<FIELD NAME="scoid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="id" NEXT="rollupruleid"/>
Expand All @@ -194,5 +194,27 @@
<KEY NAME="scorm_rolluprulecond_rolluprule" TYPE="foreign" FIELDS="rollupruleid" REFTABLE="scorm_seq_rolluprule" REFFIELDS="id" COMMENT="The relative rolluprule" PREVIOUS="scorm_rolluprulecond_scoid"/>
</KEYS>
</TABLE>
<TABLE NAME="scorm_aicc_session" COMMENT="Used by AICC HACP to store session information" PREVIOUS="scorm_seq_rolluprulecond">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="userid"/>
<FIELD NAME="userid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="id from user table" PREVIOUS="id" NEXT="scormid"/>
<FIELD NAME="scormid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="id from scorm table" PREVIOUS="userid" NEXT="hacpsession"/>
<FIELD NAME="hacpsession" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" COMMENT="sessionid used to authenticate AICC HACP communication" PREVIOUS="scormid" NEXT="scoid"/>
<FIELD NAME="scoid" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="id from scorm_scoes table" PREVIOUS="hacpsession" NEXT="scormmode"/>
<FIELD NAME="scormmode" TYPE="char" LENGTH="50" NOTNULL="false" SEQUENCE="false" PREVIOUS="scoid" NEXT="scormstatus"/>
<FIELD NAME="scormstatus" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false" PREVIOUS="scormmode" NEXT="attempt"/>
<FIELD NAME="attempt" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" PREVIOUS="scormstatus" NEXT="lessonstatus"/>
<FIELD NAME="lessonstatus" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false" PREVIOUS="attempt" NEXT="sessiontime"/>
<FIELD NAME="sessiontime" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false" PREVIOUS="lessonstatus" NEXT="timecreated"/>
<FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="time this session was created" PREVIOUS="sessiontime" NEXT="timemodified"/>
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="time this session was last used" PREVIOUS="timecreated"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" NEXT="scormid"/>
<KEY NAME="scormid" TYPE="foreign" FIELDS="scormid" REFTABLE="scorm" REFFIELDS="id" PREVIOUS="primary" NEXT="userid"/>
<KEY NAME="userid" TYPE="foreign" FIELDS="userid" REFTABLE="user" REFFIELDS="id" PREVIOUS="scormid"/>
</KEYS>
</TABLE>

</TABLES>
</XMLDB>
Loading

0 comments on commit ec25a72

Please sign in to comment.