// create the Mathdox.LMS namespace, if it doesn't already exist
var Mathdox;
if (!Mathdox) {
Mathdox = {}
}
if (!Mathdox.LMS) {
Mathdox.LMS = {
// ----------------------------------
// SCRIPT FOR OLD STYLE SCORMPACKAGES
// can be removed when these packages
// are replaced...
// ----------------------------------
// store all values in the 'values' attribute
values : {
userid : "",
username : "",
exerciseid : "",
date : "",
time : "",
status : "",
masteryscore : "",
totaltime : "",
score : ""
},
// set an LMS value
setValue : function(name, value) {
this.values[name] = value
},
// retrieve a previously set LMS value
getValue : function(name) {
return this.values[name]
},
// submit the LMS values to the server
submit : function() {
// create an xml document containing the LMS values
var xml = "<lms>"
for (var x in this.values) {
xml +=
"<" + x + ">" +
this.getValue(x) +
"</" + x + ">"
}
xml += "</lms>"
// get an XMLHttpRequest object
var request;
try {
request = new XMLHttpRequest()
}
catch(exception) {
request = new ActiveXObject("Msxml2.XMLHTTP")
}
// open synchronous request to /mathdox-lms-submission url
var url = ""
request.open("POST", url, false)
// send XML document containing the LMS values
request.setRequestHeader("Content-Type","text/xml")
// Use sendAsBinary if available (fix for FF3)
if(request.sendAsBinary) {
request.sendAsBinary(xml)
} else {
request.send(xml)
}
},
// ----------------------------------
// SCRIPT FOR NEW STYLE SCORMPACKAGES
// ----------------------------------
// store all data in the 'data' attribute
data : {
//lms data
cmi_core_student_id : "",
cmi_core_student_name : "",
cmi_core_credit : "",
cmi_core_lesson_status : "",
cmi_core_entry : "",
cmi_core_score_raw : "",
cmi_core_session_time : "",
cmi_launch_data : "",
cmi_student_data_attempt_number : "",
cmi_student_data_mastery_score : "",
//other data
xml_launch_data : ""
},
// set an LMS value
setData : function(name, value) {
if(typeof this.data[name] != "undefined") {
this.data[name] = value;
}
},
// retrieve a previously set LMS value
getData : function(name) {
if(typeof this.data[name] != "undefined") {
return this.data[name];
} else {
return "";
}
},
// retrieve a node from previously set LMS value (info from launchdata)
getXMLData : function(name, node) {
var xml = this.getData(name);
if((xml.getElementsByTagName(node).length>0) && (xml.getElementsByTagName(node)[0].childNodes.length>0)) {
return xml.getElementsByTagName(node)[0].childNodes[0].nodeValue;
} else {
return "";
}
},
// called on start
onInit : function(api, data) {
//set session time
if(typeof data['sessiontime'] != "undefined") {
this.setData("cmi_core_session_time",data['sessiontime']);
} else {
this.setData("cmi_core_session_time",0);
}
//set session reloads
if(typeof data['sessionreloads'] != "undefined") {
this.setData("cmi_student_data_attempt_number",data['sessionreloads']);
} else {
this.setData("cmi_student_data_attempt_number",0);
}
//get info from LMS
this.setData("cmi_core_student_id",api.LMSGetValue("cmi.core.student_id"));
this.setData("cmi_core_student_name",api.LMSGetValue("cmi.core.student_name"));
this.setData("cmi_core_credit",api.LMSGetValue("cmi.core.credit"));
this.setData("cmi_core_lesson_status",api.LMSGetValue("cmi.core.lesson_status"));
this.setData("cmi_core_entry",api.LMSGetValue("cmi.core.entry"));
this.setData("cmi_launch_data",api.LMSGetValue("cmi.launch_data"));
this.setData("cmi_student_data_mastery_score",api.LMSGetValue("cmi.student_data.mastery_score"));
//process launchdata
this.setData("xml_launch_data",this.readXMLString(this.getData("cmi_launch_data")));
//update status
if(this.getData("cmi.core.lesson_status")=="not attempted") {
api.LMSSetValue("cmi.core.lesson_status","browsed");
this.setData("cmi_core_lesson_status",api.LMSGetValue("cmi.core.lesson_status"));
}
//do Commit
var result = api.LMSCommit("");
},
// called on reload
onLoad : function(api, data) {
//set session time
if(typeof data['sessiontime'] != "undefined") {
this.setData("cmi_core_session_time",data['sessiontime']);
} else {
this.setData("cmi_core_session_time",0);
}
//set session reloads
if(typeof data['sessionreloads'] != "undefined") {
this.setData("cmi_student_data_attempt_number",data['sessionreloads']);
} else {
this.setData("cmi_student_data_attempt_number",0);
}
//set info on LMS
api.LMSSetValue("cmi.core.score.raw",this.getData("cmi_core_score_raw"));
api.LMSSetValue("cmi.core.session_time",this.makeTime(this.getData("cmi_core_session_time")));
//get info from LMS
this.setData("cmi_core_student_id",api.LMSGetValue("cmi.core.student_id"));
this.setData("cmi_core_student_name",api.LMSGetValue("cmi.core.student_name"));
this.setData("cmi_core_credit",api.LMSGetValue("cmi.core.credit"));
this.setData("cmi_core_lesson_status",api.LMSGetValue("cmi.core.lesson_status"));
this.setData("cmi_core_entry",api.LMSGetValue("cmi.core.entry"));
this.setData("cmi_launch_data",api.LMSGetValue("cmi.launch_data"));
this.setData("cmi_student_data_mastery_score",api.LMSGetValue("cmi.student_data.mastery_score"));
//process launchdata
this.setData("xml_launch_data",this.readXMLString(this.getData("cmi_launch_data")));
//set lesson_status
if(parseInt(api.LMSGetValue("cmi.core.score.raw"),10)>parseInt(api.LMSGetValue("cmi.student_data.mastery_score"),10)) {
api.LMSSetValue("cmi.core.lesson_status","passed");
this.setData("cmi_core_lesson_status",api.LMSGetValue("cmi.core.lesson_status"));
} else {
api.LMSSetValue("cmi.core.lesson_status","failed");
this.setData("cmi_core_lesson_status",api.LMSGetValue("cmi.core.lesson_status"));
}
//do Commit
var result = api.LMSCommit("");
},
// called on finish
onFinish : function(api, data) {
//set session time
if(typeof data['sessiontime'] != "undefined") {
this.setData("cmi_core_session_time",data['sessiontime']);
} else {
this.setData("cmi_core_session_time",0);
}
//set info on LMS
api.LMSSetValue("cmi.core.session_time",this.makeTime(this.getData("cmi_core_session_time")));
// create an xml document containing the LMS values
var xml = "";
xml += "<lms>";
xml += "<userid>"+this.getData("cmi_core_student_id")+"</userid>";
xml += "<username>"+this.getData("cmi_core_student_name")+"</username>";
xml += "<exerciseid>"+this.getXMLData("xml_launch_data","exercise")+"</exerciseid>";
xml += "<status>"+this.getData("cmi_core_lesson_status")+"</status>";
xml += "<masteryscore>"+this.getData("cmi_student_data_mastery_score")+"</masteryscore>";
xml += "<totaltime>"+this.getData("cmi_core_session_time")+"</totaltime>";
xml += "<score>"+this.getData("cmi_core_score_raw")+"</score>";
xml += "<attempts>"+this.getData("cmi_student_data_attempt_number")+"</attempts>";
xml += this.writeXMLString(this.getData("xml_launch_data"));
xml += "</lms>"
// get an XMLHttpRequest object
var request;
try {
request = new XMLHttpRequest()
} catch(exception) {
request = new ActiveXObject("Msxml2.XMLHTTP")
}
// open synchronous request to /mathdox-lms-submission url
var url = ""
request.open("POST", url, false)
// send XML document containing the LMS values
request.setRequestHeader("Content-Type","text/xml")
// Use sendAsBinary if available (fix for FF3)
if(request.sendAsBinary) {
request.sendAsBinary(xml)
} else {
request.send(xml)
}
//alert(xml);
},
//create valid timestring for sessiontime
makeTime : function(seconds) {
var time_hours;
var time_minutes;
var time_seconds;
var result;
//make time in format HHHH:MM:SS
time_hours = "" + Math.floor(seconds/3600);
time_minutes = "" + (Math.floor(seconds/60) - (60*time_hours));
time_seconds = "" + (seconds - (3600*time_hours) - (60*time_minutes));
while(time_hours.length<2) time_hours = "0"+time_hours;
while(time_minutes.length<2) time_minutes = "0"+time_minutes;
while(time_seconds.length<2) time_seconds = "0"+time_seconds;
result = time_hours+":"+time_minutes+":"+time_seconds;
//return time
return result;
},
//process xml string
readXMLString : function(xmlString) {
try {
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async="false";
xmlDoc.loadXML(xmlString);
return xmlDoc;
} catch(e) {
try {
parser=new DOMParser();
xmlDoc=parser.parseFromString(xmlString,"text/xml");
return xmlDoc;
} catch(e) {
return false;
}
}
},
//process xml
writeXMLString : function(xmlObject) {
try {
var XMLString = (new XMLSerializer()).serializeToString(xmlObject);
return XMLString;
} catch(e) {
try {
var XMLString = xmlObject.xml;
return XMLString;
} catch(e) {
return "";
}
}
}
}
}