Skip to content

Commit

Permalink
MDL-26880 - Fixed missing of activity id
Browse files Browse the repository at this point in the history
Moved errorCode as global, to allow GetLastError() to work
Applied MDL-17891 mechanism against AJAX failures, "true if true, false otherwise"
Limited what added to log when in debug, to be compliant with mdl_log.action as VARCHAR(40)
  • Loading branch information
scara authored and danmarsden committed Apr 13, 2011
1 parent 50467e5 commit 489c6ef
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 55 deletions.
2 changes: 1 addition & 1 deletion mod/scorm/datamodel.php
Expand Up @@ -72,7 +72,7 @@
// Log every datamodel update requested
if (substr($element,0,15) == 'adl.nav.request' || substr($element,0,3) == 'cmi') {
if (scorm_debugging($scorm)) {
add_to_log($course->id, 'scorm', 'trk: '.trim($scorm->name).' at: '.$attempt, 'view.php?id='.$cm->id, "$element => $value", $cm->id);
add_to_log($course->id, 'scorm', 'trk: '.substr(trim($scorm->name), 0, 25).' at: '.$attempt, 'view.php?id='.$cm->id, "$element => $value", $cm->id);
}
}
}
Expand Down
111 changes: 57 additions & 54 deletions mod/scorm/datamodels/scorm_13.js.php
Expand Up @@ -266,6 +266,7 @@ function SCORMapi1_3() {
var Initialized = false;
var Terminated = false;
var diagnostic = "";
var errorCode = "0";

function Initialize (param) {
errorCode = "0";
Expand All @@ -275,7 +276,6 @@ function Initialize (param) {
errorCode = "0";
<?php
if (scorm_debugging($scorm)) {
// echo 'alert("Initialized SCORM 1.3");';
echo 'LogAPICall("Initialize", param, "", errorCode);';
}
?>
Expand All @@ -292,7 +292,6 @@ function Initialize (param) {
}
<?php
if (scorm_debugging($scorm)) {
// echo 'alert("Initialize: "+GetErrorString(errorCode));';
echo 'LogAPICall("Initialize", param, "", errorCode);';
}
?>
Expand All @@ -310,43 +309,53 @@ function Terminate (param) {
errorCode = "0";
if (param == "") {
if ((Initialized) && (!Terminated)) {
var AJAXResult = StoreData(cmi,true);
<?php
if (scorm_debugging($scorm)) {
// echo 'alert("Terminated SCORM 1.3");';
echo 'LogAPICall("Terminate", param, "", 0);';
echo 'LogAPICall("Terminate", "AJAXResult", AJAXResult, 0);';
}
?>
Initialized = false;
Terminated = true;
var result = StoreData(cmi,true);
if (adl.nav.request != '_none_') {
switch (adl.nav.request) {
case 'continue':
result = ('true' == AJAXResult) ? 'true' : 'false';
errorCode = ('true' == result)? '0' : '101'; // General exception for any AJAX fault
<?php
if (scorm_debugging($scorm)) {
echo 'LogAPICall("Terminate", "result", result, errorCode);';
}
?>
if ('true' == result) {
Initialized = false;
Terminated = true;
if (adl.nav.request != '_none_') {
switch (adl.nav.request) {
case 'continue':
setTimeout('scorm_get_next();',500);
break;
case 'previous':
setTimeout('scorm_get_prev();',500);
break;
case 'choice':
break;
case 'exit':
break;
case 'exitAll':
break;
case 'abandon':
break;
case 'abandonAll':
break;
}
} else {
if (<?php echo $scorm->auto ?> == 1) {
setTimeout('scorm_get_next();',500);
break;
case 'previous':
setTimeout('scorm_get_prev();',500);
break;
case 'choice':
break;
case 'exit':
break;
case 'exitAll':
break;
case 'abandon':
break;
case 'abandonAll':
break;
}
}
// trigger TOC update
var sURL = "<?php echo $CFG->wwwroot; ?>" + "/mod/scorm/prereqs.php?a=<?php echo $scorm->id ?>&scoid=<?php echo $scoid ?>&attempt=<?php echo $attempt ?>&mode=<?php echo $mode ?>&currentorg=<?php echo $currentorg ?>&sesskey=<?php echo sesskey(); ?>";
YAHOO.util.Connect.asyncRequest('GET', sURL, this.connectPrereqCallback, null);
} else {
if (<?php echo $scorm->auto ?> == 1) {
setTimeout('scorm_get_next();',500);
}
diagnostic = "Failure calling the Terminate remote callback: the server replied with HTTP Status " + AJAXResult;
}
// trigger TOC update
var sURL = "<?php echo $CFG->wwwroot; ?>" + "/mod/scorm/prereqs.php?a=<?php echo $scorm->id ?>&scoid=<?php echo $scoid ?>&attempt=<?php echo $attempt ?>&mode=<?php echo $mode ?>&currentorg=<?php echo $currentorg ?>&sesskey=<?php echo sesskey(); ?>";
YAHOO.util.Connect.asyncRequest('GET', sURL, this.connectPrereqCallback, null);
return "true";
return result;
} else {
if (Terminated) {
errorCode = "113";
Expand All @@ -359,7 +368,7 @@ function Terminate (param) {
}
<?php
if (scorm_debugging($scorm)) {
echo 'alert("Terminate: "+GetErrorString(errorCode));';
echo 'LogAPICall("Terminate", param, "", errorCode);';
}
?>
return "false";
Expand Down Expand Up @@ -391,7 +400,6 @@ function GetValue (element) {
errorCode = "0";
<?php
if (scorm_debugging($scorm)) {
// echo 'alert("GetValue("+element+") -> "+eval(element));';
echo 'LogAPICall("GetValue", element, eval(element), 0);';
}
?>
Expand Down Expand Up @@ -457,7 +465,6 @@ function GetValue (element) {
}
<?php
if (scorm_debugging($scorm)) {
// echo 'alert("GetValue("+element+") -> "+GetErrorString(errorCode));';
echo 'LogAPICall("GetValue", element, "", errorCode);';
}
?>
Expand Down Expand Up @@ -754,7 +761,6 @@ function SetValue (element,value) {
errorCode = "0";
<?php
if (scorm_debugging($scorm)) {
// echo 'alert("SetValue("+element+","+value+") -> OK");';
echo 'LogAPICall("SetValue", element, value, errorCode);';
}
?>
Expand All @@ -770,7 +776,6 @@ function SetValue (element,value) {
errorCode = "0";
<?php
if (scorm_debugging($scorm)) {
// echo 'alert("SetValue("+element+","+value+") -> OK");';
echo 'LogAPICall("SetValue", element, value, errorCode);';
}
?>
Expand Down Expand Up @@ -922,14 +927,23 @@ function Commit (param) {
errorCode = "0";
if (param == "") {
if ((Initialized) && (!Terminated)) {
result = StoreData(cmi,false);
var AJAXResult = StoreData(cmi,false);
<?php
if (scorm_debugging($scorm)) {
echo 'LogAPICall("Commit", param, "", 0);';
//echo 'alert("Data Commited");';
echo 'LogAPICall("Commit", "AJAXResult", AJAXResult, 0);';
}
?>
return "true";
var result = ('true' == AJAXResult) ? 'true' : 'false';
errorCode = ('true' == result)? '0' : '101'; // General exception for any AJAX fault
<?php
if (scorm_debugging($scorm)) {
echo 'LogAPICall("Commit", "result", result, errorCode);';
}
?>
if ('false' == result) {
diagnostic = "Failure calling the Commit remote callback: the server replied with HTTP Status " + AJAXResult;
}
return result;
} else {
if (Terminated) {
errorCode = "143";
Expand All @@ -942,15 +956,14 @@ function Commit (param) {
}
<?php
if (scorm_debugging($scorm)) {
echo 'LogAPICall("Commit", param, "", 0);';
// echo 'alert("Commit: "+GetErrorString(errorCode));';
echo 'LogAPICall("Commit", param, "", errorCode);';
}
?>
return "false";
}

function GetLastError () {
<?php
<?php
if (scorm_debugging($scorm)) {
echo 'LogAPICall("GetLastError", "", "", errorCode);';
}
Expand Down Expand Up @@ -1241,18 +1254,8 @@ function StoreData(data,storetotaltime) {
datastring += navrequest;
datastring += '&attempt=<?php echo $attempt ?>';
datastring += '&scoid=<?php echo $scoid ?>';
<?php
// if (scorm_debugging($scorm)) {
// echo 'popupwin(datastring);';
// }
?>
var myRequest = NewHttpReq();
var result = DoRequest(myRequest,"<?php p($CFG->wwwroot) ?>/mod/scorm/datamodel.php","id=<?php p($id) ?>&sesskey=<?php echo sesskey() ?>"+datastring);
<?php
// if (scorm_debugging($scorm)) {
// echo 'popupwin(result);';
// }
?>
var result = DoRequest(myRequest,"<?php p($CFG->wwwroot) ?>/mod/scorm/datamodel.php","id=<?php p($id) ?>&a=<?php p($a) ?>&sesskey=<?php echo sesskey() ?>"+datastring);
var results = String(result).split('\n');
if ((results.length > 2) && (navrequest != '')) {
eval(results[2]);
Expand Down

0 comments on commit 489c6ef

Please sign in to comment.