2 if (isset($userdata->status
)) {
3 if ($userdata->status
== '') {
4 $userdata->entry
= 'ab-initio';
6 if (isset($userdata->{'cmi.core.exit'}) && ($userdata->{'cmi.core.exit'} == 'suspend')) {
7 $userdata->entry
= 'resume';
15 // SCORM 1.2 API Implementation
17 function SCORMapi1_2() {
18 // Standard Data Type Definition
19 CMIString256
= '^[\\u0000-\\uffff]{0,255}$';
20 CMIString4096
= '^[\\u0000-\\uffff]{0,4096}$';
21 CMITime
= '^([0-2]{1}[0-9]{1}):([0-5]{1}[0-9]{1}):([0-5]{1}[0-9]{1})(\.[0-9]{1,2})?$';
22 CMITimespan
= '^([0-9]{2,4}):([0-9]{2}):([0-9]{2})(\.[0-9]{1,2})?$';
23 CMIInteger
= '^\\d+$';
24 CMISInteger
= '^-?([0-9]+)$';
25 CMIDecimal
= '^-?([0-9]{0,3})(\.[0-9]{1,2})?$';
26 CMIIdentifier
= '^\\w{1,255}$';
27 CMIFeedback
= CMIString256
; // This must be redefined
28 CMIIndex
= '[._](\\d+).';
29 // Vocabulary Data Type Definition
30 CMIStatus
= '^passed$|^completed$|^failed$|^incomplete$|^browsed$';
31 CMIStatus2
= '^passed$|^completed$|^failed$|^incomplete$|^browsed$|^not attempted$';
32 CMIExit
= '^time-out$|^suspend$|^logout$|^$';
33 CMIType
= '^true-false$|^choice$|^fill-in$|^matching$|^performance$|^sequencing$|^likert$|^numeric$';
34 CMIResult
= '^correct$|^wrong$|^unanticipated$|^neutral$|^([0-9]{0,3})?(\.[0-9]{1,2})?$';
35 NAVEvent
= '^previous$|^continue$';
37 cmi_children
= 'core, suspend_data, launch_data, comments, objectives, student_data, student_preference, interactions';
38 core_children
= 'student_id, student_name, lesson_location, credit, lesson_status, entry, score, total_time, lesson_mode, exit, session_time';
39 score_children
= 'raw, min, max';
40 comments_children
= 'content, location, time';
41 objectives_children
= 'id, score, status';
42 student_data_children
= 'mastery_score, max_time_allowed, time_limit_action';
43 student_preference_children
= 'audio, language, speed, text';
44 interactions_children
= 'id, objectives, time, type, correct_responses, weighting, student_response, result, latency';
46 score_range
= '0#100';
47 audio_range
= '-1#100';
48 speed_range
= '-100#100';
49 weighting_range
= '-100#100';
51 // The SCORM 1.2 data model
53 'cmi._children':{'defaultvalue':cmi_children
, 'mod':'r', 'writeerror':'402'},
54 'cmi._version':{'defaultvalue':'3.4', 'mod':'r', 'writeerror':'402'},
55 'cmi.core._children':{'defaultvalue':core_children
, 'mod':'r', 'writeerror':'402'},
56 'cmi.core.student_id':{'defaultvalue':'<?php echo $userdata->student_id ?>', 'mod':'r', 'writeerror':'403'},
57 'cmi.core.student_name':{'defaultvalue':'<?php echo $userdata->student_name ?>', 'mod':'r', 'writeerror':'403'},
58 'cmi.core.lesson_location':{'defaultvalue':'<?php echo isset($userdata->{'cmi
.core
.lesson_location
'})?$userdata->{'cmi
.core
.lesson_location
'}:'' ?>', 'format':CMIString256
, 'mod':'rw', 'writeerror':'405'},
59 'cmi.core.credit':{'defaultvalue':'<?php echo $userdata->credit ?>', 'mod':'r', 'writeerror':'403'},
60 'cmi.core.lesson_status':{'defaultvalue':'<?php echo isset($userdata->{'cmi
.core
.lesson_status
'})?$userdata->{'cmi
.core
.lesson_status
'}:'' ?>', 'format':CMIStatus
, 'mod':'rw', 'writeerror':'405'},
61 'cmi.core.entry':{'defaultvalue':'<?php echo $userdata->entry ?>', 'mod':'r', 'writeerror':'403'},
62 'cmi.core.score._children':{'defaultvalue':score_children
, 'mod':'r', 'writeerror':'402'},
63 'cmi.core.score.raw':{'defaultvalue':'<?php echo isset($userdata->{'cmi
.core
.score
.raw
'})?$userdata->{'cmi
.core
.score
.raw
'}:'' ?>', 'format':CMIDecimal
, 'range':score_range
, 'mod':'rw', 'writeerror':'405'},
64 'cmi.core.score.max':{'defaultvalue':'<?php echo isset($userdata->{'cmi
.core
.score
.max
'})?$userdata->{'cmi
.core
.score
.max
'}:'' ?>', 'format':CMIDecimal
, 'range':score_range
, 'mod':'rw', 'writeerror':'405'},
65 'cmi.core.score.min':{'defaultvalue':'<?php echo isset($userdata->{'cmi
.core
.score
.min
'})?$userdata->{'cmi
.core
.score
.min
'}:'' ?>', 'format':CMIDecimal
, 'range':score_range
, 'mod':'rw', 'writeerror':'405'},
66 'cmi.core.total_time':{'defaultvalue':'<?php echo isset($userdata->{'cmi
.core
.total_time
'})?$userdata->{'cmi
.core
.total_time
'}:'00:00:00' ?>', 'mod':'r', 'writeerror':'403'},
67 'cmi.core.lesson_mode':{'defaultvalue':'<?php echo $userdata->mode ?>', 'mod':'r', 'writeerror':'403'},
68 'cmi.core.exit':{'defaultvalue':'<?php echo isset($userdata->{'cmi
.core
.exit'})?$userdata->{'cmi
.core
.exit'}:'' ?>', 'format':CMIExit
, 'mod':'w', 'readerror':'404', 'writeerror':'405'},
69 'cmi.core.session_time':{'format':CMITimespan
, 'mod':'w', 'defaultvalue':'00:00:00', 'readerror':'404', 'writeerror':'405'},
70 'cmi.suspend_data':{'defaultvalue':'<?php echo isset($userdata->{'cmi
.suspend_data
'})?$userdata->{'cmi
.suspend_data
'}:'' ?>', 'format':CMIString4096
, 'mod':'rw', 'writeerror':'405'},
71 'cmi.launch_data':{'defaultvalue':'<?php echo isset($userdata->datafromlms)?$userdata->datafromlms:'' ?>', 'mod':'r', 'writeerror':'403'},
72 'cmi.comments':{'defaultvalue':'<?php echo isset($userdata->{'cmi
.comments
'})?$userdata->{'cmi
.comments
'}:'' ?>', 'format':CMIString4096
, 'mod':'rw', 'writeerror':'405'},
73 // deprecated evaluation attributes
74 'cmi.evaluation.comments._count':{'defaultvalue':'0', 'mod':'r', 'writeerror':'402'},
75 'cmi.evaluation.comments._children':{'defaultvalue':comments_children
, 'mod':'r', 'writeerror':'402'},
76 'cmi.evaluation.comments.n.content':{'defaultvalue':'', 'pattern':CMIIndex
, 'format':CMIString256
, 'mod':'rw', 'writeerror':'405'},
77 'cmi.evaluation.comments.n.location':{'defaultvalue':'', 'pattern':CMIIndex
, 'format':CMIString256
, 'mod':'rw', 'writeerror':'405'},
78 'cmi.evaluation.comments.n.time':{'defaultvalue':'', 'pattern':CMIIndex
, 'format':CMITime
, 'mod':'rw', 'writeerror':'405'},
79 'cmi.comments_from_lms':{'mod':'r', 'writeerror':'403'},
80 'cmi.objectives._children':{'defaultvalue':objectives_children
, 'mod':'r', 'writeerror':'402'},
81 'cmi.objectives._count':{'mod':'r', 'defaultvalue':'0', 'writeerror':'402'},
82 'cmi.objectives.n.id':{'pattern':CMIIndex
, 'format':CMIIdentifier
, 'mod':'rw', 'writeerror':'405'},
83 'cmi.objectives.n.score._children':{'pattern':CMIIndex
, 'mod':'r', 'writeerror':'402'},
84 'cmi.objectives.n.score.raw':{'defaultvalue':'', 'pattern':CMIIndex
, 'format':CMIDecimal
, 'range':score_range
, 'mod':'rw', 'writeerror':'405'},
85 'cmi.objectives.n.score.min':{'defaultvalue':'', 'pattern':CMIIndex
, 'format':CMIDecimal
, 'range':score_range
, 'mod':'rw', 'writeerror':'405'},
86 'cmi.objectives.n.score.max':{'defaultvalue':'', 'pattern':CMIIndex
, 'format':CMIDecimal
, 'range':score_range
, 'mod':'rw', 'writeerror':'405'},
87 'cmi.objectives.n.status':{'pattern':CMIIndex
, 'format':CMIStatus2
, 'mod':'rw', 'writeerror':'405'},
88 'cmi.student_data._children':{'defaultvalue':student_data_children
, 'mod':'r', 'writeerror':'402'},
89 'cmi.student_data.mastery_score':{'defaultvalue':'<?php echo isset($userdata->masteryscore)?$userdata->masteryscore:'' ?>', 'mod':'r', 'writeerror':'403'},
90 'cmi.student_data.max_time_allowed':{'defaultvalue':'<?php echo isset($userdata->maxtimeallowed)?$userdata->maxtimeallowed:'' ?>', 'mod':'r', 'writeerror':'403'},
91 'cmi.student_data.time_limit_action':{'defaultvalue':'<?php echo isset($userdata->timelimitaction)?$userdata->timelimitaction:'' ?>', 'mod':'r', 'writeerror':'403'},
92 'cmi.student_preference._children':{'defaultvalue':student_preference_children
, 'mod':'r', 'writeerror':'402'},
93 'cmi.student_preference.audio':{'defaultvalue':'0', 'format':CMISInteger
, 'range':audio_range
, 'mod':'rw', 'writeerror':'405'},
94 'cmi.student_preference.language':{'defaultvalue':'', 'format':CMIString256
, 'mod':'rw', 'writeerror':'405'},
95 'cmi.student_preference.speed':{'defaultvalue':'0', 'format':CMISInteger
, 'range':speed_range
, 'mod':'rw', 'writeerror':'405'},
96 'cmi.student_preference.text':{'defaultvalue':'0', 'format':CMISInteger
, 'range':text_range
, 'mod':'rw', 'writeerror':'405'},
97 'cmi.interactions._children':{'defaultvalue':interactions_children
, 'mod':'r', 'writeerror':'402'},
98 'cmi.interactions._count':{'mod':'r', 'defaultvalue':'0', 'writeerror':'402'},
99 'cmi.interactions.n.id':{'pattern':CMIIndex
, 'format':CMIIdentifier
, 'mod':'w', 'readerror':'404', 'writeerror':'405'},
100 'cmi.interactions.n.objectives._count':{'pattern':CMIIndex
, 'mod':'r', 'defaultvalue':'0', 'writeerror':'402'},
101 'cmi.interactions.n.objectives.n.id':{'pattern':CMIIndex
, 'format':CMIIdentifier
, 'mod':'w', 'readerror':'404', 'writeerror':'405'},
102 'cmi.interactions.n.time':{'pattern':CMIIndex
, 'format':CMITime
, 'mod':'w', 'readerror':'404', 'writeerror':'405'},
103 'cmi.interactions.n.type':{'pattern':CMIIndex
, 'format':CMIType
, 'mod':'w', 'readerror':'404', 'writeerror':'405'},
104 'cmi.interactions.n.correct_responses._count':{'pattern':CMIIndex
, 'mod':'r', 'defaultvalue':'0', 'writeerror':'402'},
105 'cmi.interactions.n.correct_responses.n.pattern':{'pattern':CMIIndex
, 'format':CMIFeedback
, 'mod':'w', 'readerror':'404', 'writeerror':'405'},
106 'cmi.interactions.n.weighting':{'pattern':CMIIndex
, 'format':CMIDecimal
, 'range':weighting_range
, 'mod':'w', 'readerror':'404', 'writeerror':'405'},
107 'cmi.interactions.n.student_response':{'pattern':CMIIndex
, 'format':CMIFeedback
, 'mod':'w', 'readerror':'404', 'writeerror':'405'},
108 'cmi.interactions.n.result':{'pattern':CMIIndex
, 'format':CMIResult
, 'mod':'w', 'readerror':'404', 'writeerror':'405'},
109 'cmi.interactions.n.latency':{'pattern':CMIIndex
, 'format':CMITimespan
, 'mod':'w', 'readerror':'404', 'writeerror':'405'},
110 'nav.event':{'defaultvalue':'', 'format':NAVEvent
, 'mod':'w', 'readerror':'404', 'writeerror':'405'}
114 // Datamodel inizialization
116 var cmi
= new Object();
117 cmi
.core
= new Object();
118 cmi
.core
.score
= new Object();
119 cmi
.objectives
= new Object();
120 cmi
.student_data
= new Object();
121 cmi
.student_preference
= new Object();
122 cmi
.interactions
= new Object();
123 // deprecated evaluation attributes
124 cmi
.evaluation
= new Object();
125 cmi
.evaluation
.comments
= new Object();
128 var nav
= new Object();
130 for (element in datamodel
) {
131 if (element
.match(/\
.n\
./) == null) {
132 if ((typeof
eval('datamodel["'+element+
'"].defaultvalue')) != 'undefined') {
133 eval(element+
' = datamodel["'+element+
'"].defaultvalue;');
135 eval(element+
' = "";');
141 $current_objective = '';
144 foreach($userdata as $element => $value){
145 if (substr($element,0,14) == 'cmi.objectives') {
146 $element = preg_replace('/\.(\d+)\./', "_\$1.", $element);
147 preg_match('/\_(\d+)\./', $element, $matches);
148 if (count($matches) > 0 && $current_objective != $matches[1]) {
149 $current_objective = $matches[1];
151 $end = strpos($element,$matches[1])+
strlen($matches[1]);
152 $subelement = substr($element,0,$end);
153 echo ' '.$subelement." = new Object();\n";
154 echo ' '.$subelement.".score = new Object();\n";
155 echo ' '.$subelement.".score._children = score_children;\n";
156 echo ' '.$subelement.".score.raw = '';\n";
157 echo ' '.$subelement.".score.min = '';\n";
158 echo ' '.$subelement.".score.max = '';\n";
160 echo ' '.$element.' = \''.$value."';\n";
164 echo ' cmi.objectives._count = '.$count.";\n";
168 if (cmi
.core
.lesson_status
== '') {
169 cmi
.core
.lesson_status
= 'not attempted';
173 // API Methods definition
175 var Initialized
= false;
177 function LMSInitialize (param
) {
184 if (debugging('',DEBUG_DEVELOPER
)) {
185 //echo 'alert("Initialized SCORM 1.2");';
186 echo 'LogAPICall("LMSInitialize", param, "", errorCode);';
197 if (debugging('',DEBUG_DEVELOPER
)) {
198 echo 'LogAPICall("LMSInitialize", param, "", errorCode);';
204 function LMSFinish (param
) {
209 result
= StoreData(cmi
,true);
210 if (nav
.event
!= '') {
211 if (nav
.event
== 'continue') {
212 setTimeout('top.document.location=top.next;',500);
214 setTimeout('top.document.location=top.prev;',500);
217 if (<?php
echo $scorm->auto ?
> == 1) {
218 setTimeout('top.document.location=top.next;',500);
222 if (debugging('',DEBUG_DEVELOPER
)) {
223 //echo 'alert("Finished SCORM 1.2");';
224 echo 'LogAPICall("LMSFinish", param, "", 0);';
235 if (debugging('',DEBUG_DEVELOPER
)) {
236 echo 'LogAPICall("LMSFinish", param, "", errorCode);';
242 function LMSGetValue (element
) {
246 expression
= new RegExp(CMIIndex
,'g');
247 elementmodel
= String(element
).replace(expression
,'.n.');
248 if ((typeof
eval('datamodel["'+elementmodel+
'"]')) != "undefined") {
249 if (eval('datamodel["'+elementmodel+
'"].mod') != 'w') {
250 element
= String(element
).replace(expression
, "_$1.");
251 elementIndexes
= element
.split('.');
254 while ((i
< elementIndexes
.length
) && (typeof
eval(subelement
) != "undefined")) {
255 subelement +
= '.'+elementIndexes
[i++
];
257 if (subelement
== element
) {
260 if (debugging('',DEBUG_DEVELOPER
)) {
261 //echo 'alert(element+": "+eval(element));';
262 echo 'LogAPICall("LMSGetValue", element, eval(element), 0);';
265 return eval(element
);
267 errorCode
= "0"; // Need to check if it is the right errorCode
270 errorCode
= eval('datamodel["'+elementmodel+
'"].readerror');
273 childrenstr
= '._children';
274 countstr
= '._count';
275 if (elementmodel
.substr(elementmodel
.length
-childrenstr
.length
,elementmodel
.length
) == childrenstr
) {
276 parentmodel
= elementmodel
.substr(0,elementmodel
.length
-childrenstr
.length
);
277 if ((typeof
eval('datamodel["'+parentmodel+
'"]')) != "undefined") {
282 } else if (elementmodel
.substr(elementmodel
.length
-countstr
.length
,elementmodel
.length
) == countstr
) {
283 parentmodel
= elementmodel
.substr(0,elementmodel
.length
-countstr
.length
);
284 if ((typeof
eval('datamodel["'+parentmodel+
'"]')) != "undefined") {
300 if (debugging('',DEBUG_DEVELOPER
)) {
301 echo 'LogAPICall("LMSGetValue", element, "", errorCode);';
307 function LMSSetValue (element
,value
) {
311 expression
= new RegExp(CMIIndex
,'g');
312 elementmodel
= String(element
).replace(expression
,'.n.');
313 if ((typeof
eval('datamodel["'+elementmodel+
'"]')) != "undefined") {
314 if (eval('datamodel["'+elementmodel+
'"].mod') != 'r') {
315 expression
= new RegExp(eval('datamodel["'+elementmodel+
'"].format'));
317 matches
= value
.match(expression
);
318 if (matches
!= null) {
319 //Create dynamic data model element
320 if (element
!= elementmodel
) {
321 elementIndexes
= element
.split('.');
323 for (i
=1;i
< elementIndexes
.length
-1;i++
) {
324 elementIndex
= elementIndexes
[i
];
325 if (elementIndexes
[i+
1].match(/^\d+$
/)) {
326 if ((typeof
eval(subelement+
'.'+elementIndex
)) == "undefined") {
327 eval(subelement+
'.'+elementIndex+
' = new Object();');
328 eval(subelement+
'.'+elementIndex+
'._count = 0;');
330 if (elementIndexes
[i+
1] == eval(subelement+
'.'+elementIndex+
'._count')) {
331 eval(subelement+
'.'+elementIndex+
'._count++;');
333 if (elementIndexes
[i+
1] > eval(subelement+
'.'+elementIndex+
'._count')) {
336 subelement
= subelement
.concat('.'+elementIndex+
'_'+elementIndexes
[i+
1]);
339 subelement
= subelement
.concat('.'+elementIndex
);
341 if ((typeof
eval(subelement
)) == "undefined") {
342 eval(subelement+
' = new Object();');
343 if (subelement
.substr(0,14) == 'cmi.objectives') {
344 eval(subelement+
'.score = new Object();');
345 eval(subelement+
'.score._children = score_children;');
346 eval(subelement+
'.score.raw = "";');
347 eval(subelement+
'.score.min = "";');
348 eval(subelement+
'.score.max = "";');
350 if (subelement
.substr(0,16) == 'cmi.interactions') {
351 eval(subelement+
'.objectives = new Object();');
352 eval(subelement+
'.objectives._count = 0;');
353 eval(subelement+
'.correct_responses = new Object();');
354 eval(subelement+
'.correct_responses._count = 0;');
358 element
= subelement
.concat('.'+elementIndexes
[elementIndexes
.length
-1]);
361 if (errorCode
== "0") {
362 if ((typeof
eval('datamodel["'+elementmodel+
'"].range')) != "undefined") {
363 range
= eval('datamodel["'+elementmodel+
'"].range');
364 ranges
= range
.split('#');
366 if ((value
>= ranges
[0]) && (value
<= ranges
[1])) {
367 eval(element+
'=value;');
370 if (debugging('',DEBUG_DEVELOPER
)) {
371 echo 'LogAPICall("LMSSetValue", element, value, errorCode);';
372 //echo 'alert(element+":= "+value);';
377 errorCode
= eval('datamodel["'+elementmodel+
'"].writeerror');
380 if (element
== 'cmi.comments') {
381 cmi
.comments
= cmi
.comments + value
;
383 eval(element+
'=value;');
387 if (debugging('',DEBUG_DEVELOPER
)) {
388 echo 'LogAPICall("LMSSetValue", element, value, errorCode);';
389 //echo 'alert(element+":= "+value);';
396 errorCode
= eval('datamodel["'+elementmodel+
'"].writeerror');
399 errorCode
= eval('datamodel["'+elementmodel+
'"].writeerror');
411 if (debugging('',DEBUG_DEVELOPER
)) {
412 echo 'LogAPICall("LMSSetValue", element, value, errorCode);';
418 function LMSCommit (param
) {
422 result
= StoreData(cmi
,false);
424 if (debugging('',DEBUG_DEVELOPER
)) {
425 echo 'LogAPICall("Commit", param, "", 0);';
426 //echo 'alert("Data Commited");';
437 if (debugging('',DEBUG_DEVELOPER
)) {
438 echo 'LogAPICall("LMSCommit", param, "", 0);';
444 function LMSGetLastError () {
446 if (debugging('',DEBUG_DEVELOPER
)) {
447 echo 'LogAPICall("LMSGetLastError", "", "", errorCode);';
453 function LMSGetErrorString (param
) {
455 var errorString
= new Array();
456 errorString
["0"] = "No error";
457 errorString
["101"] = "General exception";
458 errorString
["201"] = "Invalid argument error";
459 errorString
["202"] = "Element cannot have children";
460 errorString
["203"] = "Element not an array - cannot have count";
461 errorString
["301"] = "Not initialized";
462 errorString
["401"] = "Not implemented error";
463 errorString
["402"] = "Invalid set value, element is a keyword";
464 errorString
["403"] = "Element is read only";
465 errorString
["404"] = "Element is write only";
466 errorString
["405"] = "Incorrect data type";
468 if (debugging('',DEBUG_DEVELOPER
)) {
469 echo 'LogAPICall("LMSGetErrorString", param, errorString[param], 0);';
472 return errorString
[param
];
475 if (debugging('',DEBUG_DEVELOPER
)) {
476 echo 'LogAPICall("LMSGetErrorString", param, "No error string found!", 0);';
483 function LMSGetDiagnostic (param
) {
488 if (debugging('',DEBUG_DEVELOPER
)) {
489 echo 'LogAPICall("LMSGetDiagnostic", param, param, 0);';
495 function AddTime (first
, second
) {
496 var sFirst
= first
.split(":");
497 var sSecond
= second
.split(":");
498 var cFirst
= sFirst
[2].split(".");
499 var cSecond
= sSecond
[2].split(".");
502 FirstCents
= 0; //Cents
503 if (cFirst
.length
> 1) {
504 FirstCents
= parseInt(cFirst
[1],10);
507 if (cSecond
.length
> 1) {
508 SecondCents
= parseInt(cSecond
[1],10);
510 var cents
= FirstCents + SecondCents
;
511 change
= Math
.floor(cents
/ 100);
512 cents
= cents
- (change
* 100);
513 if (Math
.floor(cents
) < 10) {
514 cents
= "0" + cents
.toString();
517 var secs
= parseInt(cFirst
[0],10)+
parseInt(cSecond
[0],10)+change
; //Seconds
518 change
= Math
.floor(secs
/ 60);
519 secs
= secs
- (change
* 60);
520 if (Math
.floor(secs
) < 10) {
521 secs
= "0" + secs
.toString();
524 mins
= parseInt(sFirst
[1],10)+
parseInt(sSecond
[1],10)+change
; //Minutes
525 change
= Math
.floor(mins
/ 60);
526 mins
= mins
- (change
* 60);
528 mins
= "0" + mins
.toString();
531 hours
= parseInt(sFirst
[0],10)+
parseInt(sSecond
[0],10)+change
; //Hours
533 hours
= "0" + hours
.toString();
537 return hours +
":" + mins +
":" + secs +
'.' + cents
;
539 return hours +
":" + mins +
":" + secs
;
543 function TotalTime() {
544 total_time
= AddTime(cmi
.core
.total_time
, cmi
.core
.session_time
);
545 return '&'+
underscore('cmi.core.total_time')+
'='+
encodeURIComponent(total_time
);
548 function CollectData(data
,parent
) {
550 for (property in data
) {
551 if (typeof data
[property
] == 'object') {
552 datastring +
= CollectData(data
[property
],parent+
'.'+property
);
554 element
= parent+
'.'+property
;
555 expression
= new RegExp(CMIIndex
,'g');
556 elementmodel
= String(element
).replace(expression
,'.n.');
557 if (elementmodel
!= "cmi.core.session_time") {
558 if ((typeof
eval('datamodel["'+elementmodel+
'"]')) != "undefined") {
559 if (eval('datamodel["'+elementmodel+
'"].mod') != 'r') {
560 elementstring
= '&'+
underscore(element
)+
'='+
encodeURIComponent(data
[property
]);
561 if ((typeof
eval('datamodel["'+elementmodel+
'"].defaultvalue')) != "undefined") {
562 if (eval('datamodel["'+elementmodel+
'"].defaultvalue') != data
[property
]) {
563 datastring +
= elementstring
;
566 datastring +
= elementstring
;
576 function StoreData(data
,storetotaltime
) {
577 if (storetotaltime
) {
578 if (cmi
.core
.lesson_status
== 'not attempted') {
579 cmi
.core
.lesson_status
= 'completed';
581 if (cmi
.core
.lesson_mode
== 'normal') {
582 if (cmi
.core
.credit
== 'credit') {
583 if (cmi
.core
.lesson_status
== 'completed') {
584 if (cmi
.student_data
.mastery_score
!= '' && cmi
.core
.score
.raw
!= '') {
585 if (parseFloat(cmi
.core
.score
.raw
) >= parseFloat(cmi
.student_data
.mastery_score
)) {
586 cmi
.core
.lesson_status
= 'passed';
588 cmi
.core
.lesson_status
= 'failed';
594 if (cmi
.core
.lesson_mode
== 'browse') {
595 if (datamodel
['cmi.core.lesson_status'].defaultvalue
== '') {
596 cmi
.core
.lesson_status
= 'browsed';
599 datastring
= CollectData(data
,'cmi');
600 datastring +
= TotalTime();
602 datastring
= CollectData(data
,'cmi');
604 datastring +
= '&attempt=<?php echo $attempt ?>';
605 datastring +
= '&scoid=<?php echo $scoid ?>';
607 var myRequest
= NewHttpReq();
608 result
= DoRequest(myRequest
,"<?php p($CFG->wwwroot) ?>/mod/scorm/datamodel.php","id=<?php p($id) ?>&sesskey=<?php p($USER->sesskey) ?>"+datastring
);
609 results
= String(result
).split('\n');
610 errorCode
= results
[1];
614 this
.LMSInitialize
= LMSInitialize
;
615 this
.LMSFinish
= LMSFinish
;
616 this
.LMSGetValue
= LMSGetValue
;
617 this
.LMSSetValue
= LMSSetValue
;
618 this
.LMSCommit
= LMSCommit
;
619 this
.LMSGetLastError
= LMSGetLastError
;
620 this
.LMSGetErrorString
= LMSGetErrorString
;
621 this
.LMSGetDiagnostic
= LMSGetDiagnostic
;
624 var API
= new SCORMapi1_2();
627 // pull in the debugging utilities
628 if (debugging('',DEBUG_DEVELOPER
)) {
629 include_once($CFG->dirroot
.'/mod/scorm/datamodels/debug.js.php');
630 echo 'AppendToLog("Moodle SCORM 1.2 API Loaded, Activity: '.$scorm->name
.', SCO: '.$sco->identifier
.'", 0);';