diff --git a/main/newscorm/scorm_api.php b/main/newscorm/scorm_api.php index 8423638160..9800d27392 100644 --- a/main/newscorm/scorm_api.php +++ b/main/newscorm/scorm_api.php @@ -1,9 +1,9 @@ -1) { + G_LastError = G_InvalidArgumentError; + G_LastErrorMessage = G_InvalidArgumentErrorMessage; + logit_scorm('Error '+ G_InvalidArgumentError + G_InvalidArgumentErrorMessage, 0); + return('false'); + } else { + logit_scorm('LMSInitialise()',0); + lms_initialized=1; + return('true'); + } } -function Initialize() { //this is the initialize function of all APIobjects - return LMSInitialize(); +function Initialize() +{ //this is the initialize function of all APIobjects + return LMSInitialize(); } - -function LMSGetValue(param) { +function LMSGetValue(param) +{ //logit_scorm("LMSGetValue('"+param+"')",1); G_LastError = G_NoError ; G_LastErrorMessage = 'No error'; - var result=''; + var result=''; + + // the LMSInitialize is missing + if (lms_initialized == 0) { + G_LastError = G_NotInitialized; + G_LastErrorMessage = G_NotInitializedMessage; + logit_scorm('Error '+ G_NotInitialized + ' ' +G_NotInitializedMessage, 0); + return ''; + } + + //Dokeos does not support this SCO object properties + + if (param == 'cmi.student_preference.text' || + param == 'cmi.student_preference.language' || + param == 'cmi.student_preference.speed' || + param == 'cmi.student_preference.audio' || + param == 'cmi.student_preference._children' || + param == 'cmi.student_data.time_limit_action' || + param == 'cmi.comments' || + param == 'cmi.comments_from_lms' ) { + // the value is not supported + G_lastError = G_NotImplementedError ; + G_lastErrorString = G_NotImplementedErrorMessage; + logit_scorm("LMSGetValue ('"+param+"') Error '"+G_NotImplementedErrorMessage+"'",1); + result = ''; + return result; + } + // ---- cmi.core._children - if(param=='cmi.core._children' || param=='cmi.core_children'){ + if(param=='cmi.core._children' || param=='cmi.core_children') { result='entry, exit, lesson_status, student_id, student_name, lesson_location, total_time, credit, lesson_mode, score, session_time'; - }else if(param == 'cmi.core.entry'){ + } else if(param == 'cmi.core.entry'){ // ---- cmi.core.entry - if(lms_item_core_exit=='none') - { + if(lms_item_core_exit=='none') { result='ab-initio'; - } - else if(lms_item_core_exit=='suspend') - { + } else if(lms_item_core_exit=='suspend') { result='resume'; - } - else - { + } else { result=''; } - }else if(param == 'cmi.core.exit'){ - // ---- cmi.core.exit + } else if(param == 'cmi.core.exit'){ + // ---- cmi.core.exit result=''; G_LastError = G_ElementIsWriteOnly; + }else if(param == 'cmi.core.session_time'){ + result=''; + G_LastError = G_ElementIsWriteOnly; }else if(param == 'cmi.core.lesson_status'){ // ---- cmi.core.lesson_status if(lesson_status != '') { result=lesson_status; - } - else{ + } else { result='not attempted'; } - }else if(param == 'cmi.core.student_id'){ + } else if(param == 'cmi.core.student_id'){ // ---- cmi.core.student_id result=''; - }else if(param == 'cmi.core.student_name'){ + } else if(param == 'cmi.core.student_name'){ // ---- cmi.core.student_name - }else if(param == 'cmi.core.lesson_location'){ + } else if(param == 'cmi.core.lesson_location'){ // ---- cmi.core.lesson_location result=lesson_location; - }else if(param == 'cmi.core.total_time'){ + } else if(param == 'cmi.core.total_time'){ // ---- cmi.core.total_time result=total_time; - }else if(param == 'cmi.core.score._children'){ + } else if(param == 'cmi.core.score._children'){ // ---- cmi.core.score._children result='raw,min,max'; - }else if(param == 'cmi.core.score.raw'){ + } else if(param == 'cmi.core.score.raw'){ // ---- cmi.core.score.raw result=score; - }else if(param == 'cmi.core.score.max'){ + } else if(param == 'cmi.core.score.max'){ // ---- cmi.core.score.max result=max; - }else if(param == 'cmi.core.score.min'){ + } else if(param == 'cmi.core.score.min'){ // ---- cmi.core.score.min result=min; - }else if(param == 'cmi.core.score'){ + } else if(param == 'cmi.core.score'){ // ---- cmi.core.score -- non-standard item, provided as cmi.core.score.raw just in case result=score; }else if(param == 'cmi.core.credit'){ @@ -370,25 +419,28 @@ function LMSGetValue(param) { } } }else if(param == 'cmi.student_data._children'){ - // ---- cmi.student_data._children + // ---- cmi.student_data._children result = 'mastery_score,max_time_allowed'; }else if(param == 'cmi.student_data.mastery_score'){ - // ---- cmi.student_data.mastery_score + // ---- cmi.student_data.mastery_score result = mastery_score; }else if(param == 'cmi.student_data.max_time_allowed'){ - // ---- cmi.student_data.max_time_allowed + // ---- cmi.student_data.max_time_allowed result = max_time_allowed; }else if(param == 'cmi.interactions._count'){ - // ---- cmi.interactions._count + // ---- cmi.interactions._count result = interactions.length; }else if(param == 'cmi.interactions._children'){ - // ---- cmi.interactions._children + // ---- cmi.interactions._children result = 'id,time,type,correct_responses,weighting,student_response,result,latency'; - }else{ - // ---- anything else + } else { + // ---- anything else + // Invalid argument error + G_lastError = G_InvalidArgumentError ; + G_lastErrorString = G_InvalidArgumentErrorMessage; + logit_scorm("LMSGetValue ('"+param+"') Error '"+G_InvalidArgumentErrorMessage+"'",1); result = ''; - G_lastError = G_NotImplementedError; - G_lastErrorString = 'Not implemented yet'; + return result; } logit_scorm("LMSGetValue\n\t('"+param+"') returned '"+result+"'",1); return result; @@ -399,56 +451,77 @@ function GetValue(param) { } function LMSSetValue(param, val) { + logit_scorm("LMSSetValue\n\t('"+param+"','"+val+"')",0); commit = true; //value has changed, need to re-commit G_LastError = G_NoError ; G_LastErrorMessage = 'No error'; return_value = 'false'; - if( param == "cmi.core.score.raw" ) - { - score= val; return_value='true'; + if( param == "cmi.core.score.raw" ) { + score= val; + return_value='true'; } else if ( param == "cmi.core.score.max" ) { - max = val;return_value='true'; + max = val; + return_value='true'; } else if ( param == "cmi.core.score.min" ) { - min = val;return_value='true'; + min = val; + return_value='true'; } else if ( param == "cmi.core.lesson_location" ) { - lesson_location = val;return_value='true'; + lesson_location = val; + return_value='true'; } else if ( param == "cmi.core.lesson_status" ) { saved_lesson_status = lesson_status; lesson_status = val; return_value='true'; } else if ( param == "cmi.completion_status" ) { - lesson_status = val;return_value='true'; //1.3 + lesson_status = val; + return_value='true'; //1.3 } else if ( param == "cmi.core.session_time" ) { - session_time = val;return_value='true'; + session_time = val; + return_value='true'; } else if ( param == "cmi.score.scaled") { //1.3 - if(val<=1 && val>=-1) - { + if(val<=1 && val>=-1) { score = val ; return_value='true'; - } - else - { + } else { return_value='false'; } } else if ( param == "cmi.success_status" ) { - success_status = val;return_value='true'; //1.3 + success_status = val; + return_value='true'; //1.3 } else if ( param == "cmi.suspend_data" ) { - suspend_data = val;return_value='true'; + suspend_data = val; + return_value='true'; } else if ( param == "cmi.core.exit" ) { - lms_item_core_exit = val;return_value='true'; + lms_item_core_exit = val; + return_value='true'; + } else if ( param == "cmi.core.student_id" ) { + G_LastError = G_ElementIsReadOnly; + } else if ( param == "cmi.core.student_name" ) { + G_LastError = G_ElementIsReadOnly; + } else if ( param == "cmi.core.credit" ) { + G_LastError = G_ElementIsReadOnly; } else if ( param == "cmi.core.entry" ) { - G_LastError = G_ElementIsReadOnly - } else if ( param == "cmi.student_data.mastery_score" ) { G_LastError = G_ElementIsReadOnly; + } else if ( param == "cmi.core.total_time" ) { + G_LastError = G_ElementIsReadOnly; + } else if ( param == "cmi.core.lesson_mode" ) { + G_LastError = G_ElementIsReadOnly; + } else if ( param == "cmi.comments_from_lms" ) { + G_LastError = G_ElementIsReadOnly; + } else if ( param == "cmi.student_data.time_limit_action" ) { + G_LastError = G_ElementIsReadOnly; + } else if ( param == "cmi.student_data.mastery_score" ) { + G_LastError = G_ElementIsReadOnly; } else if ( param == "cmi.student_data.max_time_allowed" ) { G_LastError = G_ElementIsReadOnly; + } else if ( param == "cmi.student_preference._children" ) { + G_LastError = G_ElementIsReadOnly; } else if ( param == "cmi.launch_data" ) { G_LastError = G_ElementIsReadOnly; } else { var myres = new Array(); - if(myres = param.match(/cmi.interactions.(\d+).(id|time|type|correct_responses|weighting|student_response|result|latency)(.*)/)) - { + if(myres = param.match(/cmi.interactions.(\d+).(id|time|type|correct_responses|weighting|student_response|result|latency)(.*)/)) { elem_id = myres[1]; if(elem_id > interactions.length) //interactions setting should start at 0 { @@ -458,9 +531,8 @@ function LMSSetValue(param, val) { return_value = false; */ interactions[0] = ['0','','','','','','','']; - } - - if(interactions[elem_id] == null){ + } + if(interactions[elem_id] == null) { interactions[elem_id] = ['','','','','','','','']; //id(0), type(1), time(2), weighting(3),correct_responses(4),student_response(5),result(6),latency(7) interactions[elem_id][4] = new Array(); @@ -512,7 +584,7 @@ function LMSSetValue(param, val) { G_lastError = G_NotImplementedError; G_lastErrorString = 'Not implemented yet'; } - }else if(param.substring(0,15)== 'cmi.objectives.'){ + } else if(param.substring(0,15)== 'cmi.objectives.'){ var myres = ''; if(myres = param.match(/cmi.objectives.(\d+).(id|score|status)(.*)/)) { @@ -574,9 +646,9 @@ function LMSSetValue(param, val) { } } } - }else{ + } else { G_lastError = G_NotImplementedError; - G_lastErrorString = 'Not implemented yet'; + G_lastErrorString = G_NotImplementedErrorMessage; } } =0) && (score >= mastery_score)) - { - lesson_status = 'passed'; - } - else if( (mastery_score < 0) && (lms_lp_type != '2') && ( lesson_status == 'incomplete') && (score >= (0.8*max) ) ) - { //the status cannot be modified automatically by the LMS under SCORM 1.2's rules - +function savedata(origin) +{ + //origin can be 'commit', 'finish' or 'terminate' + if ((lesson_status != 'completed') && (lesson_status != 'passed') && (mastery_score >=0) && (score >= mastery_score)) { + lesson_status = 'passed'; + } else if( (mastery_score < 0) && (lms_lp_type != '2') && ( lesson_status == 'incomplete') && (score >= (0.8*max) ) ) { + //the status cannot be modified automatically by the LMS under SCORM 1.2's rules + lesson_status = 'completed'; - - ; + + ; + } else { + if (origin== 'finish') { + /* + The SCORM1.2 Runtime object document says for the "cmi.core.lesson_status" variable: + Upon receiving the LMSFinish() call or the user navigates away, + the LMS should set the cmi.core.lesson_status for the SCO to 'completed' + */ + + /* + if (mastery_score!= '' && score != '') { + if (score >= mastery_score) { + lesson_status = 'passed'; + } else { + lesson_status = 'failed'; + } + } else if (mastery_score!= '') { + lesson_status = 'completed'; + } + */ + } } + logit_lms('saving data (status='+lesson_status+' - interactions: '+ interactions.length +')',1); xajax_save_item(lms_lp_id, lms_user_id, lms_view_id, lms_item_id, score, max, min, lesson_status, session_time, suspend_data, lesson_location, interactions, lms_item_core_exit); if(item_objectives.length>0) @@ -613,12 +705,12 @@ function savedata(origin) { //origin can be 'commit', 'finish' or 'terminate' } function LMSCommit(val) { - logit_scorm('LMSCommit()',0); - G_LastError = G_NoError ; - G_LastErrorMessage = 'No error'; - savedata('commit'); - commit = false ; //now changes have been commited, no need to update until next SetValue() - return('true'); + logit_scorm('LMSCommit()',0); + G_LastError = G_NoError ; + G_LastErrorMessage = 'No error'; + savedata('commit'); + commit = false ; //now changes have been commited, no need to update until next SetValue() + return('true'); } function Commit(val) { @@ -626,17 +718,18 @@ function Commit(val) { } function LMSFinish(val) { - G_LastError = G_NoError ; - G_LastErrorMessage = 'No error'; - if (( commit == false )) { - logit_scorm('LMSFinish() (no LMSCommit())',1); - } - if ( commit == true ) { - logit_scorm('LMSFinish() called',1); - savedata('finish'); - commit = false ; - } - return('true'); + G_LastError = G_NoError ; + G_LastErrorMessage = 'No error'; + // why commit==false? + if (( commit == false )) { + logit_scorm('LMSFinish() (no LMSCommit())',1); + } + if ( commit == true ) { + logit_scorm('LMSFinish() called',1); + savedata('finish'); + commit = false ; + } + return('true'); } function Finish(val) { @@ -670,13 +763,21 @@ function GetDiagnostic(errCode){ return LMSGetDiagnostic(errCode); } -function Terminate(){ - logit_scorm('Terminate()',0); - G_LastError = G_NoError ; - G_LastErrorMessage = 'No error'; - commit = true; - savedata('terminate'); - return (true); +function Terminate() +{ + if (lms_initialized == 0) { + G_LastError = G_NotInitialized; + G_LastErrorMessage = G_NotInitializedMessage; + logit_scorm('Error '+ G_NotInitialized + G_NotInitializedMessage, 0); + return('false'); + } else { + logit_scorm('Terminate()',0); + G_LastError = G_NoError ; + G_LastErrorMessage = 'No error'; + commit = true; + savedata('terminate'); + return (true); + } }