<?php
require_once($CFG->dirroot.'/mod/scorm/locallib.php');
-
+
if (isset($userdata->status)) {
- if (!isset($userdata->{'cmi.exit'}) || (($userdata->{'cmi.exit'} == 'time-out') || ($userdata->{'cmi.exit'} == 'normal'))) {
+ if (!isset($userdata->{'cmi.exit'}) || (($userdata->{'cmi.exit'} == 'time-out') || ($userdata->{'cmi.exit'} == 'normal'))) {
$userdata->entry = 'ab-initio';
} else {
if (isset($userdata->{'cmi.exit'}) && (($userdata->{'cmi.exit'} == 'suspend') || ($userdata->{'cmi.exit'} == 'logout'))) {
?>
// Used need to debug cmi content (if you uncomment this, you must comment the definition inside SCORMapi1_3)
-//var cmi = new Object();
+//var cmi = new Object();
//
// SCORM 1.3 API Implementation
//
function SCORMapi1_3() {
// Standard Data Type Definition
-
+
// language key has to be checked for language dependent strings
- var validLanguages = {'aa':'aa', 'ab':'ab', 'ae':'ae', 'af':'af', 'ak':'ak', 'am':'am', 'an':'an', 'ar':'ar', 'as':'as', 'av':'av', 'ay':'ay', 'az':'az',
+ var validLanguages = {'aa':'aa', 'ab':'ab', 'ae':'ae', 'af':'af', 'ak':'ak', 'am':'am', 'an':'an', 'ar':'ar', 'as':'as', 'av':'av', 'ay':'ay', 'az':'az',
'ba':'ba', 'be':'be', 'bg':'bg', 'bh':'bh', 'bi':'bi', 'bm':'bm', 'bn':'bn', 'bo':'bo', 'br':'br', 'bs':'bs',
- 'ca':'ca', 'ce':'ce', 'ch':'ch', 'co':'co', 'cr':'cr', 'cs':'cs', 'cu':'cu', 'cv':'cv', 'cy':'cy',
+ 'ca':'ca', 'ce':'ce', 'ch':'ch', 'co':'co', 'cr':'cr', 'cs':'cs', 'cu':'cu', 'cv':'cv', 'cy':'cy',
'da':'da', 'de':'de', 'dv':'dv', 'dz':'dz', 'ee':'ee', 'el':'el', 'en':'en', 'eo':'eo', 'es':'es', 'et':'et', 'eu':'eu',
'fa':'fa', 'ff':'ff', 'fi':'fi', 'fj':'fj', 'fo':'fo', 'fr':'fr', 'fy':'fy', 'ga':'ga', 'gd':'gd', 'gl':'gl', 'gn':'gn', 'gu':'gu', 'gv':'gv',
'ha':'ha', 'he':'he', 'hi':'hi', 'ho':'ho', 'hr':'hr', 'ht':'ht', 'hu':'hu', 'hy':'hy', 'hz':'hz',
'tam':'tam', 'tel':'tel', 'tgk':'tgk', 'tha':'tha', 'tir':'tir', 'tuk':'tuk', 'tgl':'tgl', 'tsn':'tsn', 'ton':'ton', 'tur':'tur', 'tso':'tso', 'tat':'tat', 'twi':'twi', 'tah':'tah',
'uig':'uig', 'ukr':'ukr', 'urd':'urd', 'uzb':'uzb', 'ven':'ven', 'vie':'vie', 'vol':'vol', 'wln':'wln', 'wol':'wol', 'xho':'xho', 'yid':'yid', 'yor':'yor', 'zha':'zha', 'chi':'chi', 'zho':'zho', 'zul':'zul'};
- var CMIString200 = '^.{0,200}$';
- var CMIString250 = '^.{0,250}$';
- var CMIString1000 = '^.{0,1500}$';
- var CMIString4000 = '^.{0,4000}$';
- var CMIString64000 = '^.{0,64000}$';
+ var CMIString200 = '^[\\u0000-\\uFFFF]{0,200}$$';
+ var CMIString250 = '^[\\u0000-\\uFFFF]{0,250}$';
+ var CMIString1000 = '^[\\u0000-\\uFFFF]{0,1000}$';
+ var CMIString4000 = '^[\\u0000-\\uFFFF]{0,4000}$';
+ var CMIString64000 = '^[\\u0000-\\uFFFF]{0,64000}$';
var CMILang = '^([a-zA-Z]{2,3}|i|x)(\-[a-zA-Z0-9\-]{2,8})?$|^$';
var CMILangString250 = '^(\{lang=([a-zA-Z]{2,3}|i|x)(\-[a-zA-Z0-9\-]{2,8})?\})?([^\{].{0,250}$)?';
var CMILangcr = '^((\{lang=([a-zA-Z]{2,3}|i|x)?(\-[a-zA-Z0-9\-]{2,8})?\}))(.*?)$';
'numeric':{'format':CMIDecimal, 'max':1, 'delimiter':'', 'unique':false},
'other':{'format':CMIString4000, 'max':1, 'delimiter':'', 'unique':false}
}
-
+
var correct_responses = {
'true-false':{'pre':'', 'max':1, 'delimiter':'', 'unique':false, 'duplicate':false,
- 'format':'^true$|^false$',
+ 'format':'^true$|^false$',
'limit':1},
'choice':{'pre':'', 'max':36, 'delimiter':'[,]', 'unique':true, 'duplicate':false,
'format':CMIShortIdentifier},
if (cmi.completion_status == '') {
cmi.completion_status = 'not attempted';
- }
-
+ }
+
//
// API Methods definition
//
if ((!Initialized) && (!Terminated)) {
Initialized = true;
errorCode = "0";
- <?php
+ <?php
if (scorm_debugging($scorm)) {
// echo 'alert("Initialized SCORM 1.3");';
echo 'LogAPICall("Initialize", param, "", errorCode);';
} else {
errorCode = "201";
}
- <?php
+ <?php
if (scorm_debugging($scorm)) {
// echo 'alert("Initialize: "+GetErrorString(errorCode));';
echo 'LogAPICall("Initialize", param, "", errorCode);';
?>
return "false";
}
-
+
function Terminate (param) {
errorCode = "0";
if (param == "") {
if ((Initialized) && (!Terminated)) {
- <?php
+ <?php
if (scorm_debugging($scorm)) {
// echo 'alert("Terminated SCORM 1.3");';
echo 'LogAPICall("Terminate", param, "", 0);';
if (<?php echo $scorm->auto ?> == 1) {
setTimeout('top.nextSCO();',500);
}
- }
+ }
return "true";
} else {
if (Terminated) {
} else {
errorCode = "201";
}
- <?php
+ <?php
if (scorm_debugging($scorm)) {
echo 'alert("Terminate: "+GetErrorString(errorCode));';
}
?>
return "false";
}
-
+
function GetValue (element) {
errorCode = "0";
diagnostic = "";
if ((typeof eval(subelement) != "undefined") && (eval(subelement) != null)) {
errorCode = "0";
- <?php
+ <?php
if (scorm_debugging($scorm)) {
// echo 'alert("GetValue("+element+") -> "+eval(element));';
echo 'LogAPICall("GetValue", element, eval(element), 0);';
errorCode = "301";
}
} else {
- if (Terminated) {
+ if (Terminated) {
errorCode = "123";
} else {
errorCode = "122";
}
}
- <?php
+ <?php
if (scorm_debugging($scorm)) {
// echo 'alert("GetValue("+element+") -> "+GetErrorString(errorCode));';
echo 'LogAPICall("GetValue", element, "", errorCode);';
?>
return "";
}
-
+
function SetValue (element,value) {
errorCode = "0";
diagnostic = "";
if ((typeof eval(subelement)) == "undefined") {
switch (elementmodel) {
- case 'cmi.objectives.n.id':
+ case 'cmi.objectives.n.id':
if (!duplicatedID(element,parentelement,value)) {
if (elementIndexes[elementIndexes.length-2] == eval(parentelement+'._count')) {
eval(parentelement+'._count++;');
var subobject = eval(subelement);
subobject.objectives = new Object();
subobject.objectives._count = 0;
- }
+ }
break;
case 'cmi.interactions.n.objectives.n.id':
if (typeof eval(parentelement) != "undefined") {
errorCode = "351";
diagnostic = "Data Model Element Pattern Too Long";
}
- if ((errorCode == "0") && ((correct_responses[interactiontype].duplicate == false) ||
+ if ((errorCode == "0") && ((correct_responses[interactiontype].duplicate == false) ||
(!duplicatedPA(element,parentelement,value))) || (errorCode == "0" && value == "")) {
eval(parentelement+'._count++;');
eval(subelement+' = new Object();');
} else {
errorCode="351";
diagnostic = "Data Model Element Collection Set Out Of Order";
- }
+ }
} else {
errorCode="408";
}
errorCode = "351";
diagnostic = "Write Once Violation";
}
- break;
+ break;
case 'cmi.interactions.n.objectives.n.id':
if (duplicatedID(element,parentelement,value)) {
errorCode = "351";
} else {
nodes[0] = value;
}
-
+
if ((nodes.length > 0) && (nodes.length <= correct_responses[interactiontype].max)) {
errorCode = CRcheckValueNodes (element, interactiontype, nodes, value, errorCode);
} else if (nodes.length > correct_responses[interactiontype].max) {
}
}
break;
- }
+ }
}
}
}
if ((ranges[1] == '*') || (value <= ranges[1])) {
eval(element+'=value;');
errorCode = "0";
- <?php
+ <?php
if (scorm_debugging($scorm)) {
// echo 'alert("SetValue("+element+","+value+") -> OK");';
echo 'LogAPICall("SetValue", element, value, errorCode);';
}
} else {
eval(element+'=value;');
- errorCode = "0";
- <?php
+ errorCode = "0";
+ <?php
if (scorm_debugging($scorm)) {
// echo 'alert("SetValue("+element+","+value+") -> OK");';
echo 'LogAPICall("SetValue", element, value, errorCode);';
errorCode = "132";
}
}
- <?php
+ <?php
if (scorm_debugging($scorm)) {
echo 'LogAPICall("SetValue", element, value, errorCode);';
}
function CRremovePrefixes (node) {
// check for prefixes lang, case, order
- // case and then order
+ // case and then order
var seenOrder = false;
var seenCase = false;
var seenLang = false;
}
seenLang = true;
break;
-
+
case 'case_matters':
// check for correct case answer
if (! seenLang && ! seenOrder && ! seenCase) {
}
seenCase = true;
break;
-
+
case 'order_matters':
// check for correct case answer
if (! seenCase && ! seenLang && ! seenOrder) {
}
seenOrder = true;
break;
-
+
default:
break;
}
errorCode = result.errorCode;
nodes[i] = result.node;
}
-
+
// check for prefix on each node
if (correct_responses[interactiontype].pre != '') {
matches = nodes[i].match(correct_responses[interactiontype].pre);
nodes[i] = nodes[i].substr(matches[1].length);
}
}
-
+
if (correct_responses[interactiontype].delimiter2 != undefined) {
values = nodes[i].split(correct_responses[interactiontype].delimiter2);
if (values.length == 2) {
return errorCode;
}
-
+
function Commit (param) {
errorCode = "0";
if (param == "") {
if ((Initialized) && (!Terminated)) {
result = StoreData(cmi,false);
- <?php
+ <?php
if (scorm_debugging($scorm)) {
echo 'LogAPICall("Commit", param, "", 0);';
//echo 'alert("Data Commited");';
} else {
errorCode = "201";
}
- <?php
+ <?php
if (scorm_debugging($scorm)) {
echo 'LogAPICall("Commit", param, "", 0);';
// echo 'alert("Commit: "+GetErrorString(errorCode));';
?>
return "false";
}
-
+
function GetLastError () {
- <?php
+ <?php
if (scorm_debugging($scorm)) {
echo 'LogAPICall("GetLastError", "", "", errorCode);';
}
?>
return errorCode;
}
-
+
function GetErrorString (param) {
if (param != "") {
var errorString = "";
errorString = "Data Model Dependency Not Established";
break;
}
- <?php
+ <?php
if (scorm_debugging($scorm)) {
echo 'LogAPICall("GetErrorString", param, errorString, 0);';
}
?>
return errorString;
} else {
- <?php
+ <?php
if (scorm_debugging($scorm)) {
echo 'LogAPICall("GetErrorString", param, "No error string found!", 0);';
}
return "";
}
}
-
+
function GetDiagnostic (param) {
if (diagnostic != "") {
- <?php
+ <?php
if (scorm_debugging($scorm)) {
echo 'LogAPICall("GetDiagnostic", param, diagnostic, 0);';
}
?>
return diagnostic;
}
- <?php
+ <?php
if (scorm_debugging($scorm)) {
echo 'LogAPICall("GetDiagnostic", param, param, 0);';
}
if ((parent+'.N'+n+'.id' != element) && (eval(parent+'.N'+n+'.id') == value)) {
found = true;
}
- }
+ }
return found;
}
if ((parent+'.N'+n+'.pattern' != element) && (eval(parent+'.N'+n+'.pattern') == value)) {
found = true;
}
- }
+ }
return found;
}
}
function AddTime (first, second) {
- <?php
+ <?php
// if (scorm_debugging($scorm)) {
// echo 'alert("AddTime: "+first+" + "+second);';
// }
if(parseInt(firstarray[9],10)>0){ firsthours=parseInt(firstarray[9],10); }
var secondhours=0;
if(parseInt(secondarray[9],10)>0){ secondhours=parseInt(secondarray[9],10); }
- var hours = firsthours+secondhours+change; //Hours
+ var hours = firsthours+secondhours+change; //Hours
change = Math.floor(hours/24);
hours = Math.round(hours-(change*24));
var firstdays=0;
errorCode = results[1];
return results[0];
}
-
+
this.Initialize = Initialize;
this.Terminate = Terminate;
this.GetValue = GetValue;