2 if (isset($userdata->status
)) {
3 if (!isset($userdata->{'cmi.exit'}) ||
(($userdata->{'cmi.exit'} == 'time-out') ||
($userdata->{'cmi.exit'} == 'normal'))) {
4 $userdata->entry
= 'ab-initio';
6 if (isset($userdata->{'cmi.exit'}) && (($userdata->{'cmi.exit'} == 'suspend') ||
($userdata->{'cmi.exit'} == 'logout'))) {
7 $userdata->entry
= 'resume';
15 // Used need to debug cmi content (if you uncomment this, you must comment the definition inside SCORMapi1_3)
16 //var cmi = new Object();
19 // SCORM 1.3 API Implementation
21 function SCORMapi1_3() {
22 // Standard Data Type Definition
23 var CMIString200
= '^.{0,200}$';
24 var CMIString250
= '^.{0,250}$';
25 var CMIString1000
= '^.{0,1500}$';
26 var CMIString4000
= '^.{0,4000}$';
27 var CMIString64000
= '^.{0,64000}$';
28 var CMILang
= '^([a-zA-Z]{2,3}|i|x)(\-[a-zA-Z0-9\-]{2,8})?$|^$';
29 var CMILangString250
= '^(\{lang=([a-zA-Z]{2,3}|i|x)(\-[a-zA-Z0-9\-]{2,8})?\})?([^\{].{0,250}$)?';
30 var CMILangString4000
= '^(\{lang=([a-zA-Z]{2,3}|i|x)(\-[a-zA-Z0-9\-]{2,8})?\})?([^\{].{0,4000}$)?';
31 var CMITime
= '^(19[7-9]{1}[0-9]{1}|20[0-2]{1}[0-9]{1}|203[0-8]{1})((-(0[1-9]{1}|1[0-2]{1}))((-(0[1-9]{1}|[1-2]{1}[0-9]{1}|3[0-1]{1}))(T([0-1]{1}[0-9]{1}|2[0-3]{1})((:[0-5]{1}[0-9]{1})((:[0-5]{1}[0-9]{1})((\\.[0-9]{1,2})((Z|([+|-]([0-1]{1}[0-9]{1}|2[0-3]{1})))(:[0-5]{1}[0-9]{1})?)?)?)?)?)?)?)?$';
32 var CMITimespan
= '^P(\\d+Y)?(\\d+M)?(\\d+D)?(T(((\\d+H)(\\d+M)?(\\d+(\.\\d{1,2})?S)?)|((\\d+M)(\\d+(\.\\d{1,2})?S)?)|((\\d+(\.\\d{1,2})?S))))?$';
33 var CMIInteger
= '^\\d+$';
34 var CMISInteger
= '^-?([0-9]+)$';
35 var CMIDecimal
= '^-?([0-9]{1,4})(\\.[0-9]{1,18})?$';
36 var CMIIdentifier
= '^\\S{0,250}[a-zA-Z0-9]$';
37 var CMIShortIdentifier
= '^[\\w\.]{1,250}$';
38 var CMILongIdentifier
= '^\\S{0,4000}[a-zA-Z0-9]$';
39 var CMIFeedback
= '^.*$'; // This must be redefined
40 var CMIIndex
= '[._](\\d+).';
41 var CMIIndexStore
= '.N(\\d+).';
42 // Vocabulary Data Type Definition
43 var CMICStatus
= '^completed$|^incomplete$|^not attempted$|^unknown$';
44 var CMISStatus
= '^passed$|^failed$|^unknown$';
45 var CMIExit
= '^time-out$|^suspend$|^logout$|^normal$|^$';
46 var CMIType
= '^true-false$|^choice$|^(long-)?fill-in$|^matching$|^performance$|^sequencing$|^likert$|^numeric$|^other$';
47 var CMIResult
= '^correct$|^incorrect$|^unanticipated$|^neutral$|^-?([0-9]{1,4})(\\.[0-9]{1,18})?$';
48 var NAVEvent
= '^previous$|^continue$|^exit$|^exitAll$|^abandon$|^abandonAll$|^suspendAll$|^{target=\\S{0,200}[a-zA-Z0-9]}choice$';
49 var NAVBoolean
= '^unknown$|^true$|^false$';
50 var NAVTarget
= '^previous$|^continue$|^choice.{target=\\S{0,200}[a-zA-Z0-9]}$'
52 var cmi_children
= '_version, comments_from_learner, comments_from_lms, completion_status, credit, entry, exit, interactions, launch_data, learner_id, learner_name, learner_preference, location, max_time_allowed, mode, objectives, progress_measure, scaled_passing_score, score, session_time, success_status, suspend_data, time_limit_action, total_time';
53 var comments_children
= 'comment, timestamp, location';
54 var score_children
= 'max, raw, scaled, min';
55 var objectives_children
= 'progress_measure, completion_status, success_status, description, score, id';
56 var student_data_children
= 'mastery_score, max_time_allowed, time_limit_action';
57 var student_preference_children
= 'audio_level, audio_captioning, delivery_speed, language';
58 var interactions_children
= 'id, type, objectives, timestamp, correct_responses, weighting, learner_response, result, latency, description';
60 var scaled_range
= '-1#1';
61 var audio_range
= '0#*';
62 var speed_range
= '0#*';
63 var text_range
= '-1#1';
64 var progress_range
= '0#1';
65 var learner_response
= {
66 'true-false':{'format':'^true$|^false$', 'max':1, 'delimiter':'', 'unique':false},
67 'choice':{'format':CMIIdentifier
, 'max':36, 'delimiter':'[,]', 'unique':true},
68 'fill-in':{'format':CMILangString250
, 'max':10, 'delimiter':'[,]', 'unique':false},
69 'long-fill-in':{'format':CMILangString4000
, 'max':1, 'delimiter':'', 'unique':false},
70 'matching':{'format':CMIShortIdentifier
, 'format2':CMIShortIdentifier
, 'max':36, 'delimiter':'[,]', 'delimiter2':'[.]', 'unique':false},
71 'performance':{'format':'^$|'+CMIShortIdentifier
, 'format2':CMIDecimal+
'|^$|'+CMIShortIdentifier
, 'max':250, 'delimiter':'[,]', 'delimiter2':'[.]', 'unique':false},
72 'sequencing':{'format':CMIShortIdentifier
, 'max':36, 'delimiter':'[,]', 'unique':false},
73 'likert':{'format':CMIShortIdentifier
, 'max':1, 'delimiter':'', 'unique':false},
74 'numeric':{'format':CMIDecimal
, 'max':1, 'delimiter':'', 'unique':false},
75 'other':{'format':CMIString4000
, 'max':1, 'delimiter':'', 'unique':false}
77 var correct_responses
= {
78 'true-false':{'pre':'', 'max':1, 'delimiter':'', 'unique':false, 'duplicate':false,
79 'format':'^true$|^false$',
81 'choice':{'pre':'', 'max':36, 'delimiter':'[,]', 'unique':true, 'duplicate':false,
82 'format':CMIIdentifier
},
83 'fill-in':{'pre':'^(\{case_matters=(true|false)\})(\{order_matters=(true|false)\})?|^(\{order_matters=(true|false)\})(\{case_matters=(true|false)\})?',
84 'max':10, 'delimiter':'[,]', 'unique':false, 'duplicate':false,
85 'format':CMILangString250
},
86 'long-fill-in':{'pre':'^(\{case_matters=(true|false)\})?', 'max':1, 'delimiter':'', 'unique':false, 'duplicate':true,
87 'format':CMILangString4000
},
88 'matching':{'pre':'', 'max':36, 'delimiter':'[,]', 'delimiter2':'[.]', 'unique':false, 'duplicate':true,
89 'format':CMIShortIdentifier
, 'format2':CMIShortIdentifier
},
90 'performance':{'pre':'^(\{order_matters=(true|false)\})?',
91 'max':250, 'delimiter':'[,]', 'delimiter2':'[.]', 'unique':false, 'duplicate':true,
92 'format':'^$|'+CMIShortIdentifier
, 'format2':CMIDecimal+
'|^$|'+CMIShortIdentifier
},
93 'sequencing':{'pre':'', 'max':36, 'delimiter':'[,]', 'unique':false, 'duplicate':false,
94 'format':CMIShortIdentifier
},
95 'likert':{'pre':'', 'max':1, 'delimiter':'', 'unique':false, 'duplicate':false,
96 'format':CMIShortIdentifier
,
98 'numeric':{'pre':'', 'max':1, 'delimiter':'', 'unique':false, 'duplicate':false,
101 'other':{'pre':'', 'max':1, 'delimiter':'', 'unique':false, 'duplicate':false,
102 'format':CMIString4000
,
106 // The SCORM 1.3 data model
108 'cmi._children':{'defaultvalue':cmi_children
, 'mod':'r'},
109 'cmi._version':{'defaultvalue':'1.0', 'mod':'r'},
110 'cmi.comments_from_learner._children':{'defaultvalue':comments_children
, 'mod':'r'},
111 'cmi.comments_from_learner._count':{'mod':'r', 'defaultvalue':'0'},
112 'cmi.comments_from_learner.n.comment':{'format':CMILangString4000
, 'mod':'rw'},
113 'cmi.comments_from_learner.n.location':{'format':CMIString250
, 'mod':'rw'},
114 'cmi.comments_from_learner.n.timestamp':{'format':CMITime
, 'mod':'rw'},
115 'cmi.comments_from_lms._children':{'defaultvalue':comments_children
, 'mod':'r'},
116 'cmi.comments_from_lms._count':{'mod':'r', 'defaultvalue':'0'},
117 'cmi.comments_from_lms.n.comment':{'format':CMILangString4000
, 'mod':'r'},
118 'cmi.comments_from_lms.n.location':{'format':CMIString250
, 'mod':'r'},
119 'cmi.comments_from_lms.n.timestamp':{'format':CMITime
, 'mod':'r'},
120 'cmi.completion_status':{'defaultvalue':'<?php echo isset($userdata->{'cmi
.completion_status
'})?$userdata->{'cmi
.completion_status
'}:'unknown
' ?>', 'format':CMICStatus
, 'mod':'rw'},
121 'cmi.completion_threshold':{'defaultvalue':<?php
echo isset($userdata->threshold
)?
'\''.$userdata->threshold
.'\'':'null' ?
>, 'mod':'r'},
122 'cmi.credit':{'defaultvalue':'<?php echo isset($userdata->credit)?$userdata->credit:'' ?>', 'mod':'r'},
123 'cmi.entry':{'defaultvalue':'<?php echo $userdata->entry ?>', 'mod':'r'},
124 'cmi.exit':{'defaultvalue':'<?php echo isset($userdata->{'cmi
.exit'})?$userdata->{'cmi
.exit'}:'' ?>', 'format':CMIExit
, 'mod':'w'},
125 'cmi.interactions._children':{'defaultvalue':interactions_children
, 'mod':'r'},
126 'cmi.interactions._count':{'mod':'r', 'defaultvalue':'0'},
127 'cmi.interactions.n.id':{'pattern':CMIIndex
, 'format':CMILongIdentifier
, 'mod':'rw'},
128 'cmi.interactions.n.type':{'pattern':CMIIndex
, 'format':CMIType
, 'mod':'rw'},
129 'cmi.interactions.n.objectives._count':{'pattern':CMIIndex
, 'mod':'r', 'defaultvalue':'0'},
130 'cmi.interactions.n.objectives.n.id':{'pattern':CMIIndex
, 'format':CMILongIdentifier
, 'mod':'rw'},
131 'cmi.interactions.n.timestamp':{'pattern':CMIIndex
, 'format':CMITime
, 'mod':'rw'},
132 'cmi.interactions.n.correct_responses._count':{'defaultvalue':'0', 'pattern':CMIIndex
, 'mod':'r'},
133 'cmi.interactions.n.correct_responses.n.pattern':{'pattern':CMIIndex
, 'format':'CMIFeedback', 'mod':'rw'},
134 'cmi.interactions.n.weighting':{'pattern':CMIIndex
, 'format':CMIDecimal
, 'mod':'rw'},
135 'cmi.interactions.n.learner_response':{'pattern':CMIIndex
, 'format':'CMIFeedback', 'mod':'rw'},
136 'cmi.interactions.n.result':{'pattern':CMIIndex
, 'format':CMIResult
, 'mod':'rw'},
137 'cmi.interactions.n.latency':{'pattern':CMIIndex
, 'format':CMITimespan
, 'mod':'rw'},
138 'cmi.interactions.n.description':{'pattern':CMIIndex
, 'format':CMILangString250
, 'mod':'rw'},
139 'cmi.launch_data':{'defaultvalue':<?php
echo isset($userdata->datafromlms
)?
'\''.$userdata->datafromlms
.'\'':'null' ?
>, 'mod':'r'},
140 'cmi.learner_id':{'defaultvalue':'<?php echo $userdata->student_id ?>', 'mod':'r'},
141 'cmi.learner_name':{'defaultvalue':'<?php echo $userdata->student_name ?>', 'mod':'r'},
142 'cmi.learner_preference._children':{'defaultvalue':student_preference_children
, 'mod':'r'},
143 'cmi.learner_preference.audio_level':{'defaultvalue':'1', 'format':CMIDecimal
, 'range':audio_range
, 'mod':'rw'},
144 'cmi.learner_preference.language':{'defaultvalue':'', 'format':CMILang
, 'mod':'rw'},
145 'cmi.learner_preference.delivery_speed':{'defaultvalue':'1', 'format':CMIDecimal
, 'range':speed_range
, 'mod':'rw'},
146 'cmi.learner_preference.audio_captioning':{'defaultvalue':'0', 'format':CMISInteger
, 'range':text_range
, 'mod':'rw'},
147 'cmi.location':{'defaultvalue':<?php
echo isset($userdata->{'cmi.location'})?
'\''.$userdata->{'cmi.location'}.'\'':'null' ?
>, 'format':CMIString1000
, 'mod':'rw'},
148 'cmi.max_time_allowed':{'defaultvalue':<?php
echo isset($userdata->maxtimeallowed
)?
'\''.$userdata->maxtimeallowed
.'\'':'null' ?
>, 'mod':'r'},
149 'cmi.mode':{'defaultvalue':'<?php echo $userdata->mode ?>', 'mod':'r'},
150 'cmi.objectives._children':{'defaultvalue':objectives_children
, 'mod':'r'},
151 'cmi.objectives._count':{'mod':'r', 'defaultvalue':'0'},
152 'cmi.objectives.n.id':{'pattern':CMIIndex
, 'format':CMILongIdentifier
, 'mod':'rw'},
153 'cmi.objectives.n.score._children':{'defaultvalue':score_children
, 'pattern':CMIIndex
, 'mod':'r'},
154 'cmi.objectives.n.score.scaled':{'defaultvalue':null, 'pattern':CMIIndex
, 'format':CMIDecimal
, 'range':scaled_range
, 'mod':'rw'},
155 'cmi.objectives.n.score.raw':{'defaultvalue':null, 'pattern':CMIIndex
, 'format':CMIDecimal
, 'mod':'rw'},
156 'cmi.objectives.n.score.min':{'defaultvalue':null, 'pattern':CMIIndex
, 'format':CMIDecimal
, 'mod':'rw'},
157 'cmi.objectives.n.score.max':{'defaultvalue':null, 'pattern':CMIIndex
, 'format':CMIDecimal
, 'mod':'rw'},
158 'cmi.objectives.n.success_status':{'defaultvalue':'unknown', 'pattern':CMIIndex
, 'format':CMISStatus
, 'mod':'rw'},
159 'cmi.objectives.n.completion_status':{'defaultvalue':'unknown', 'pattern':CMIIndex
, 'format':CMICStatus
, 'mod':'rw'},
160 'cmi.objectives.n.progress_measure':{'defaultvalue':null, 'format':CMIDecimal
, 'range':progress_range
, 'mod':'rw'},
161 'cmi.objectives.n.description':{'pattern':CMIIndex
, 'format':CMILangString250
, 'mod':'rw'},
162 'cmi.progress_measure':{'defaultvalue':<?php
echo isset($userdata->{'cmi.progess_measure'})?
'\''.$userdata->{'cmi.progress_measure'}.'\'':'null' ?
>, 'format':CMIDecimal
, 'range':progress_range
, 'mod':'rw'},
163 'cmi.scaled_passing_score':{'defaultvalue':<?php
echo isset($userdata->{'cmi.scaled_passing_score'})?
'\''.$userdata->{'cmi.scaled_passing_score'}.'\'':'null' ?
>, 'format':CMIDecimal
, 'range':scaled_range
, 'mod':'r'},
164 'cmi.score._children':{'defaultvalue':score_children
, 'mod':'r'},
165 'cmi.score.scaled':{'defaultvalue':<?php
echo isset($userdata->{'cmi.score.scaled'})?
'\''.$userdata->{'cmi.score.scaled'}.'\'':'null' ?
>, 'format':CMIDecimal
, 'range':scaled_range
, 'mod':'rw'},
166 'cmi.score.raw':{'defaultvalue':<?php
echo isset($userdata->{'cmi.score.raw'})?
'\''.$userdata->{'cmi.score.raw'}.'\'':'null' ?
>, 'format':CMIDecimal
, 'mod':'rw'},
167 'cmi.score.min':{'defaultvalue':<?php
echo isset($userdata->{'cmi.score.min'})?
'\''.$userdata->{'cmi.score.min'}.'\'':'null' ?
>, 'format':CMIDecimal
, 'mod':'rw'},
168 'cmi.score.max':{'defaultvalue':<?php
echo isset($userdata->{'cmi.score.max'})?
'\''.$userdata->{'cmi.score.max'}.'\'':'null' ?
>, 'format':CMIDecimal
, 'mod':'rw'},
169 'cmi.session_time':{'format':CMITimespan
, 'mod':'w', 'defaultvalue':'PT0H0M0S'},
170 'cmi.success_status':{'defaultvalue':'<?php echo isset($userdata->{'cmi
.success_status
'})?$userdata->{'cmi
.success_status
'}:'unknown
' ?>', 'format':CMISStatus
, 'mod':'rw'},
171 'cmi.suspend_data':{'defaultvalue':<?php
echo isset($userdata->{'cmi.suspend_data'})?
'\''.$userdata->{'cmi.suspend_data'}.'\'':'null' ?
>, 'format':CMIString64000
, 'mod':'rw'},
172 'cmi.time_limit_action':{'defaultvalue':<?php
echo isset($userdata->timelimitaction
)?
'\''.$userdata->timelimitaction
.'\'':'null' ?
>, 'mod':'r'},
173 'cmi.total_time':{'defaultvalue':'<?php echo isset($userdata->{'cmi
.total_time
'})?$userdata->{'cmi
.total_time
'}:'PT0H0M0S
' ?>', 'mod':'r'},
174 'adl.nav.request':{'defaultvalue':'_none_', 'format':NAVEvent
, 'mod':'rw'}
177 // Datamodel inizialization
179 var cmi
= new Object();
180 cmi
.comments_from_learner
= new Object();
181 cmi
.comments_from_learner
._count
= 0;
182 cmi
.comments_from_lms
= new Object();
183 cmi
.comments_from_lms
._count
= 0;
184 cmi
.interactions
= new Object();
185 cmi
.interactions
._count
= 0;
186 cmi
.learner_preference
= new Object();
187 cmi
.objectives
= new Object();
188 cmi
.objectives
._count
= 0;
189 cmi
.score
= new Object();
192 var adl
= new Object();
193 adl
.nav
= new Object();
194 adl
.nav
.request_valid
= new Array();
196 for (element in datamodel
) {
197 if (element
.match(/\
.n\
./) == null) {
198 if ((typeof
eval('datamodel["'+element+
'"].defaultvalue')) != 'undefined') {
199 eval(element+
' = datamodel["'+element+
'"].defaultvalue;');
201 eval(element+
' = "";');
207 $current_objective = '';
210 foreach($userdata as $element => $value){
211 if (substr($element,0,14) == 'cmi.objectives') {
212 $element = preg_replace('/\.(\d+)\./', "_\$1.", $element);
213 preg_match('/\_(\d+)\./', $element, $matches);
214 if (count($matches) > 0 && $current_objective != $matches[1]) {
215 $current_objective = $matches[1];
217 $end = strpos($element,$matches[1])+
strlen($matches[1]);
218 $subelement = substr($element,0,$end);
219 echo ' '.$subelement." = new Object();\n";
220 echo ' '.$subelement.".score = new Object();\n";
221 echo ' '.$subelement.".score._children = score_children;\n";
223 echo ' '.$element.' = \''.$value."';\n";
227 echo ' cmi.objectives._count = '.$count.";\n";
231 if (cmi
.completion_status
== '') {
232 cmi
.completion_status
= 'not attempted';
236 // API Methods definition
238 var Initialized
= false;
239 var Terminated
= false;
242 function Initialize (param
) {
245 if ((!Initialized
) && (!Terminated
)) {
249 if (debugging('',DEBUG_DEVELOPER
)) {
250 // echo 'alert("Initialized SCORM 1.3");';
251 echo 'LogAPICall("Initialize", param, "", errorCode);';
266 if (debugging('',DEBUG_DEVELOPER
)) {
267 // echo 'alert("Initialize: "+GetErrorString(errorCode));';
268 echo 'LogAPICall("Initialize", param, "", errorCode);';
274 function Terminate (param
) {
277 if ((Initialized
) && (!Terminated
)) {
279 if (debugging('',DEBUG_DEVELOPER
)) {
280 // echo 'alert("Terminated SCORM 1.3");';
281 echo 'LogAPICall("Terminate", param, "", 0);';
286 var result
= StoreData(cmi
,true);
287 if (adl
.nav
.request
!= '_none_') {
288 switch (adl
.nav
.request
) {
290 setTimeout('top.nextSCO();',500);
293 setTimeout('top.prevSCO();',500);
307 if (<?php
echo $scorm->auto ?
> == 1) {
308 setTimeout('top.nextSCO();',500);
323 if (debugging('',DEBUG_DEVELOPER
)) {
324 echo 'alert("Terminate: "+GetErrorString(errorCode));';
330 function GetValue (element
) {
333 if ((Initialized
) && (!Terminated
)) {
335 var expression
= new RegExp(CMIIndex
,'g');
336 var elementmodel
= String(element
).replace(expression
,'.n.');
338 if ((typeof
eval('datamodel["'+elementmodel+
'"]')) != "undefined") {
339 if (eval('datamodel["'+elementmodel+
'"].mod') != 'w') {
341 element
= String(element
).replace(/\
.(\d+
)\
./, ".N$1.");
342 element
= element
.replace(/\
.(\d+
)\
./, ".N$1.");
344 var elementIndexes
= element
.split('.');
345 var subelement
= element
.substr(0,3);
348 while ((i
< elementIndexes
.length
) && (typeof
eval(subelement
) != "undefined")) {
349 subelement +
= '.'+elementIndexes
[i++
];
352 if (subelement
== element
) {
354 if ((typeof
eval(subelement
) != "undefined") && (eval(subelement
) != null)) {
357 if (debugging('',DEBUG_DEVELOPER
)) {
358 // echo 'alert("GetValue("+element+") -> "+eval(element));';
359 echo 'LogAPICall("GetValue", element, eval(element), 0);';
362 return eval(element
);
370 //errorCode = eval('datamodel["'+elementmodel+'"].readerror');
374 var childrenstr
= '._children';
375 var countstr
= '._count';
376 var parentmodel
= '';
377 if (elementmodel
.substr(elementmodel
.length
-childrenstr
.length
,elementmodel
.length
) == childrenstr
) {
378 parentmodel
= elementmodel
.substr(0,elementmodel
.length
-childrenstr
.length
);
379 if ((typeof
eval('datamodel["'+parentmodel+
'"]')) != "undefined") {
381 diagnostic
= "Data Model Element Does Not Have Children";
385 } else if (elementmodel
.substr(elementmodel
.length
-countstr
.length
,elementmodel
.length
) == countstr
) {
386 parentmodel
= elementmodel
.substr(0,elementmodel
.length
-countstr
.length
);
387 if ((typeof
eval('datamodel["'+parentmodel+
'"]')) != "undefined") {
389 diagnostic
= "Data Model Element Cannot Have Count";
394 parentmodel
= 'adl.nav.request_valid.';
395 if (element
.substr(0,parentmodel
.length
) == parentmodel
) {
396 if (element
.substr(parentmodel
.length
).match(NAVTarget
) == null) {
399 if (adl
.nav
.request
== element
.substr(parentmodel
.length
)) {
401 } else if (adl
.nav
.request
== '_none_') {
423 if (debugging('',DEBUG_DEVELOPER
)) {
424 // echo 'alert("GetValue("+element+") -> "+GetErrorString(errorCode));';
425 echo 'LogAPICall("GetValue", element, "", errorCode);';
431 function SetValue (element
,value
) {
434 if ((Initialized
) && (!Terminated
)) {
436 var expression
= new RegExp(CMIIndex
,'g');
437 var elementmodel
= String(element
).replace(expression
,'.n.');
438 if ((typeof
eval('datamodel["'+elementmodel+
'"]')) != "undefined") {
439 if (eval('datamodel["'+elementmodel+
'"].mod') != 'r') {
440 if (eval('datamodel["'+elementmodel+
'"].format') != 'CMIFeedback') {
441 expression
= new RegExp(eval('datamodel["'+elementmodel+
'"].format'));
443 // cmi.interactions.n.type depending format accept everything at this stage
444 expression
= new RegExp(CMIFeedback
);
447 var matches
= value
.match(expression
);
448 if ((matches
!= null) && ((matches
.join('').length
> 0) ||
(value
.length
== 0))) {
449 // Value match dataelement format
451 if (element
!= elementmodel
) {
452 //This is a dynamic datamodel element
454 var elementIndexes
= element
.split('.');
455 var subelement
= 'cmi';
456 var parentelement
= 'cmi';
457 for (var i
=1;(i
< elementIndexes
.length
-1) && (errorCode
=="0");i++
) {
458 var elementIndex
= elementIndexes
[i
];
459 if (elementIndexes
[i+
1].match(/^\d+$
/)) {
460 if ((parseInt(elementIndexes
[i+
1]) > 0) && (elementIndexes
[i+
1].charAt(0) == 0)) {
461 // Index has a leading 0 (zero), this is not a number
464 parentelement
= subelement+
'.'+elementIndex
;
465 if ((typeof
eval(parentelement
) == "undefined") ||
(typeof
eval(parentelement+
'._count') == "undefined")) {
468 if (elementIndexes
[i+
1] > eval(parentelement+
'._count')) {
470 diagnostic
= "Data Model Element Collection Set Out Of Order";
472 subelement
= subelement
.concat('.'+elementIndex+
'.N'+elementIndexes
[i+
1]);
475 if (((typeof
eval(subelement
)) == "undefined") && (i
< elementIndexes
.length
-2)) {
480 subelement
= subelement
.concat('.'+elementIndex
);
484 if (errorCode
== "0") {
485 // Till now it's a real datamodel element
487 element
= subelement
.concat('.'+elementIndexes
[elementIndexes
.length
-1]);
489 if ((typeof
eval(subelement
)) == "undefined") {
490 switch (elementmodel
) {
491 case 'cmi.objectives.n.id':
492 if (!duplicatedID(element
,parentelement
,value
)) {
493 if (elementIndexes
[elementIndexes
.length
-2] == eval(parentelement+
'._count')) {
494 eval(parentelement+
'._count++;');
495 eval(subelement+
' = new Object();');
496 var subobject
= eval(subelement
);
497 subobject
.success_status
= datamodel
["cmi.objectives.n.success_status"].defaultvalue
;
498 subobject
.completion_status
= datamodel
["cmi.objectives.n.completion_status"].defaultvalue
;
499 subobject
.progress_measure
= datamodel
["cmi.objectives.n.progress_measure"].defaultvalue
;
500 subobject
.score
= new Object();
501 subobject
.score
._children
= score_children
;
502 subobject
.score
.scaled
= datamodel
["cmi.objectives.n.score.scaled"].defaultvalue
;
503 subobject
.score
.raw
= datamodel
["cmi.objectives.n.score.raw"].defaultvalue
;
504 subobject
.score
.min
= datamodel
["cmi.objectives.n.score.min"].defaultvalue
;
505 subobject
.score
.max
= datamodel
["cmi.objectives.n.score.max"].defaultvalue
;
509 diagnostic
= "Data Model Element ID Already Exists";
512 case 'cmi.interactions.n.id':
513 if (elementIndexes
[elementIndexes
.length
-2] == eval(parentelement+
'._count')) {
514 eval(parentelement+
'._count++;');
515 eval(subelement+
' = new Object();');
516 var subobject
= eval(subelement
);
517 subobject
.objectives
= new Object();
518 subobject
.objectives
._count
= 0;
521 case 'cmi.interactions.n.objectives.n.id':
522 if (typeof
eval(parentelement
) != "undefined") {
523 if (!duplicatedID(element
,parentelement
,value
)) {
524 if (elementIndexes
[elementIndexes
.length
-2] == eval(parentelement+
'._count')) {
525 eval(parentelement+
'._count++;');
526 eval(subelement+
' = new Object();');
530 diagnostic
= "Data Model Element ID Already Exists";
536 case 'cmi.interactions.n.correct_responses.n.pattern':
537 if (typeof
eval(parentelement
) != "undefined") {
539 // Use cmi.interactions.n.type value to check the right dataelement format
540 if (elementIndexes
[elementIndexes
.length
-2] == eval(parentelement+
'._count')) {
541 var interactiontype
= eval(String(parentelement
).replace('correct_responses','type'));
542 if ((typeof correct_responses
[interactiontype
].limit
== 'undefined') ||
543 (eval(parentelement+
'._count') < correct_responses
[interactiontype
].limit
)) {
544 if (correct_responses
[interactiontype
].pre
!= '') {
545 matches
= value
.match(correct_responses
[interactiontype
].pre
);
546 if (matches
!= null) {
547 value
= value
.substr(0,matches
[1].length
);
550 var nodes
= new Array();
551 if (correct_responses
[interactiontype
].delimiter
!= '') {
552 nodes
= value
.split(correct_responses
[interactiontype
].delimiter
);
556 if ((nodes
.length
> 0) && (nodes
.length
<= correct_responses
[interactiontype
].max
)) {
557 expression
= new RegExp(correct_responses
[interactiontype
].format
);
558 for (var i
=0; (i
< nodes
.length
) && (errorCode
=="0"); i++
) {
559 if (typeof correct_responses
[interactiontype
].delimiter2
!= 'undefined') {
560 values
= nodes
[i
].split(correct_responses
[interactiontype
].delimiter2
);
561 if (values
.length
== 2) {
562 matches
= values
[0].match(expression
);
563 if (matches
== null) {
566 var expression2
= new RegExp(correct_responses
[interactiontype
].format2
);
567 matches
= values
[1].match(expression2
);
568 if ((matches
== null) ||
(matches
.join('').length
== 0)) {
576 matches
= nodes
[i
].match(expression
);
577 if (matches
== null) {
580 if ((nodes
[i
] != '') && (correct_responses
[interactiontype
].unique
)) {
581 for (var j
=0; (j
<i
) && (errorCode
=="0"); j++
) {
582 if (nodes
[i
] == nodes
[j
]) {
590 } else if (nodes
.length
> correct_responses
[interactiontype
].max
) {
592 diagnostic
= "Data Model Element Pattern Too Long";
594 if ((errorCode
== "0") &&
595 ((correct_responses
[interactiontype
].duplicate
== false) ||
596 (!duplicatedPA(element
,parentelement
,value
)))) {
597 eval(parentelement+
'._count++;');
598 eval(subelement+
' = new Object();');
601 diagnostic
= "Data Model Element Pattern Already Exists";
605 diagnostic
= "Data Model Element Collection Limit Reached";
609 diagnostic
= "Data Model Element Collection Set Out Of Order";
616 if ((parentelement
!= 'cmi.objectives') && (parentelement
!= 'cmi.interactions') && (typeof
eval(parentelement
) != "undefined")) {
617 if (elementIndexes
[elementIndexes
.length
-2] == eval(parentelement+
'._count')) {
618 eval(parentelement+
'._count++;');
619 eval(subelement+
' = new Object();');
622 diagnostic
= "Data Model Element Collection Set Out Of Order";
630 switch (elementmodel
) {
631 case 'cmi.objectives.n.id':
632 if (eval(element
) != value
) {
634 diagnostic
= "Write Once Violation";
637 case 'cmi.interactions.n.objectives.n.id':
638 if (duplicatedID(element
,parentelement
,value
)) {
640 diagnostic
= "Data Model Element ID Already Exists";
643 case 'cmi.interactions.n.type':
644 var subobject
= eval(subelement
);
645 subobject
.correct_responses
= new Object();
646 subobject
.correct_responses
._count
= 0;
648 case 'cmi.interactions.n.learner_response':
649 if (typeof
eval(subelement+
'.type') == "undefined") {
652 // Use cmi.interactions.n.type value to check the right dataelement format
653 interactiontype
= eval(subelement+
'.type');
654 var nodes
= new Array();
655 if (learner_response
[interactiontype
].delimiter
!= '') {
656 nodes
= value
.split(learner_response
[interactiontype
].delimiter
);
660 if ((nodes
.length
> 0) && (nodes
.length
<= learner_response
[interactiontype
].max
)) {
661 expression
= new RegExp(learner_response
[interactiontype
].format
);
662 for (var i
=0; (i
< nodes
.length
) && (errorCode
=="0"); i++
) {
663 if (typeof learner_response
[interactiontype
].delimiter2
!= 'undefined') {
664 values
= nodes
[i
].split(learner_response
[interactiontype
].delimiter2
);
665 if (values
.length
== 2) {
666 matches
= values
[0].match(expression
);
667 if (matches
== null) {
670 var expression2
= new RegExp(learner_response
[interactiontype
].format2
);
671 matches
= values
[1].match(expression2
);
672 if (matches
== null) {
680 matches
= nodes
[i
].match(expression
);
681 if (matches
== null) {
684 if ((nodes
[i
] != '') && (learner_response
[interactiontype
].unique
)) {
685 for (var j
=0; (j
<i
) && (errorCode
=="0"); j++
) {
686 if (nodes
[i
] == nodes
[j
]) {
694 } else if (nodes
.length
> learner_response
[interactiontype
].max
) {
696 diagnostic
= "Data Model Element Pattern Too Long";
700 case 'cmi.interactions.n.correct_responses.n.pattern':
701 subel
= subelement
.split('.');
702 subel1
= 'cmi.interactions.'+subel
[2];
705 if (typeof
eval(subel1+
'.type') == "undefined") {
711 // Use cmi.interactions.n.type value to check the right //dataelement format
712 interactiontype
= eval(subel1+
'.type');
713 var nodes
= new Array();
714 if (correct_responses
[interactiontype
].delimiter
!= '') {
715 nodes
= value
.split(correct_responses
[interactiontype
].delimiter
);
720 if ((nodes
.length
> 0) && (nodes
.length
<= correct_responses
[interactiontype
].max
)) {
721 expression
= new RegExp(correct_responses
[interactiontype
].format
);
722 for (var i
=0; (i
< nodes
.length
) && (errorCode
=="0"); i++
) {
723 if (typeof correct_responses
[interactiontype
].delimiter2
!= 'undefined') {
726 values
= nodes
[i
].split(correct_responses
[interactiontype
].delimiter2
);
727 if (values
.length
== 2) {
729 matches
= values
[0].match(expression
);
730 if (matches
== null) {
735 var expression2
= new RegExp(correct_responses
[interactiontype
].format2
);
736 matches
= values
[1].match(expression2
);
737 if (matches
== null) {
747 matches
= nodes
[i
].match(expression
);
748 //if ((matches == null) || (matches.join('').length == 0)) {
749 if ((matches
== null && value
!= "")||
(matches
== null && interactiontype
=="true-false")){
754 if ((nodes
[i
] != '') && (correct_responses
[interactiontype
].unique
)) {
755 for (var j
=0; (j
<i
) && (errorCode
=="0"); j++
) {
756 if (nodes
[i
] == nodes
[j
]) {
765 } else if (nodes
.length
> correct_responses
[interactiontype
].max
) {
768 diagnostic
= "Data Model Element Pattern Too Long";
778 if (errorCode
== "0") {
780 if ((typeof
eval('datamodel["'+elementmodel+
'"].range')) != "undefined") {
781 range
= eval('datamodel["'+elementmodel+
'"].range');
782 ranges
= range
.split('#');
784 if (value
>= ranges
[0]) {
785 if ((ranges
[1] == '*') ||
(value
<= ranges
[1])) {
786 eval(element+
'=value;');
789 if (debugging('',DEBUG_DEVELOPER
)) {
790 // echo 'alert("SetValue("+element+","+value+") -> OK");';
791 echo 'LogAPICall("SetValue", element, value, errorCode);';
802 eval(element+
'=value;');
805 if (debugging('',DEBUG_DEVELOPER
)) {
806 // echo 'alert("SetValue("+element+","+value+") -> OK");';
807 echo 'LogAPICall("SetValue", element, value, errorCode);';
833 if (debugging('',DEBUG_DEVELOPER
)) {
834 echo 'LogAPICall("SetValue", element, value, errorCode);';
840 function Commit (param
) {
843 if ((Initialized
) && (!Terminated
)) {
844 result
= StoreData(cmi
,false);
846 if (debugging('',DEBUG_DEVELOPER
)) {
847 echo 'LogAPICall("Commit", param, "", 0);';
848 //echo 'alert("Data Commited");';
863 if (debugging('',DEBUG_DEVELOPER
)) {
864 echo 'LogAPICall("Commit", param, "", 0);';
865 // echo 'alert("Commit: "+GetErrorString(errorCode));';
871 function GetLastError () {
873 if (debugging('',DEBUG_DEVELOPER
)) {
874 echo 'LogAPICall("GetLastError", "", "", errorCode);';
880 function GetErrorString (param
) {
882 var errorString
= "";
885 errorString
= "No error";
888 errorString
= "General exception";
891 errorString
= "General Inizialization Failure";
894 errorString
= "Already Initialized";
897 errorString
= "Content Instance Terminated";
900 errorString
= "General Termination Failure";
903 errorString
= "Termination Before Inizialization";
906 errorString
= "Termination After Termination";
909 errorString
= "Retrieve Data Before Initialization";
912 errorString
= "Retrieve Data After Termination";
915 errorString
= "Store Data Before Inizialization";
918 errorString
= "Store Data After Termination";
921 errorString
= "Commit Before Inizialization";
924 errorString
= "Commit After Termination";
927 errorString
= "General Argument Error";
930 errorString
= "General Get Failure";
933 errorString
= "General Set Failure";
936 errorString
= "General Commit Failure";
939 errorString
= "Undefinited Data Model";
942 errorString
= "Unimplemented Data Model Element";
945 errorString
= "Data Model Element Value Not Initialized";
948 errorString
= "Data Model Element Is Read Only";
951 errorString
= "Data Model Element Is Write Only";
954 errorString
= "Data Model Element Type Mismatch";
957 errorString
= "Data Model Element Value Out Of Range";
960 errorString
= "Data Model Dependency Not Established";
964 if (debugging('',DEBUG_DEVELOPER
)) {
965 echo 'LogAPICall("GetErrorString", param, errorString, 0);';
971 if (debugging('',DEBUG_DEVELOPER
)) {
972 echo 'LogAPICall("GetErrorString", param, "No error string found!", 0);';
979 function GetDiagnostic (param
) {
980 if (diagnostic
!= "") {
982 if (debugging('',DEBUG_DEVELOPER
)) {
983 echo 'LogAPICall("GetDiagnostic", param, diagnostic, 0);';
989 if (debugging('',DEBUG_DEVELOPER
)) {
990 echo 'LogAPICall("GetDiagnostic", param, param, 0);';
996 function duplicatedID (element
, parent
, value
) {
998 var elements
= eval(parent+
'._count');
999 for (var n
=0;(n
< elements
) && (!found
);n++
) {
1000 if ((parent+
'.N'+n+
'.id' != element
) && (eval(parent+
'.N'+n+
'.id') == value
)) {
1007 function duplicatedPA (element
, parent
, value
) {
1009 var elements
= eval(parent+
'._count');
1010 for (var n
=0;(n
< elements
) && (!found
);n++
) {
1011 if ((parent+
'.N'+n+
'.pattern' != element
) && (eval(parent+
'.N'+n+
'.pattern') == value
)) {
1018 function getElementModel(element
) {
1019 if (typeof datamodel
[element
] != "undefined") {
1022 var expression
= new RegExp(CMIIndex
,'g');
1023 var elementmodel
= String(element
).replace(expression
,'.n.');
1024 if (typeof datamodel
[elementmodel
] != "undefined") {
1025 return elementmodel
;
1031 function AddTime (first
, second
) {
1033 // if (debugging('',DEBUG_DEVELOPER)) {
1034 // echo 'alert("AddTime: "+first+" + "+second);';
1037 var timestring
= 'P';
1038 var matchexpr
= /^
P((\d+
)Y
)?
((\d+
)M
)?
((\d+
)D
)?
(T((\d+
)H
)?
((\d+
)M
)?
((\d+
(\
.\d
{1,2})?
)S
)?
)?$
/;
1039 var firstarray
= first
.match(matchexpr
);
1040 var secondarray
= second
.match(matchexpr
);
1041 if ((firstarray
!= null) && (secondarray
!= null)) {
1042 var secs
= parseFloat(firstarray
[13],10)+
parseFloat(secondarray
[13],10); //Seconds
1043 var change
= Math
.floor(secs
/ 60);
1044 secs
= secs
- (change
* 60);
1045 var mins
= parseInt(firstarray
[11],10)+
parseInt(secondarray
[11],10)+change
; //Minutes
1046 change
= Math
.floor(mins
/ 60);
1047 mins
= mins
- (change
* 60);
1048 var hours
= parseInt(firstarray
[9],10)+
parseInt(secondarray
[9],10)+change
; //Hours
1049 change
= Math
.floor(hours
/ 24);
1050 hours
= hours
- (change
* 24);
1051 var days
= parseInt(firstarray
[6],10)+
parseInt(secondarray
[6],10)+change
; // Days
1052 var months
= parseInt(firstarray
[4],10)+
parseInt(secondarray
[4],10)
1053 var years
= parseInt(firstarray
[2],10)+
parseInt(secondarray
[2],10)
1056 timestring +
= years +
'Y';
1059 timestring +
= months +
'M';
1062 timestring +
= days +
'D';
1064 if ((hours
> 0) ||
(mins
> 0) ||
(secs
> 0)) {
1067 timestring +
= hours +
'H';
1070 timestring +
= mins +
'M';
1073 timestring +
= secs +
'S';
1079 function TotalTime() {
1080 var total_time
= AddTime(cmi
.total_time
, cmi
.session_time
);
1081 return '&'+
underscore('cmi.total_time')+
'='+
encodeURIComponent(total_time
);
1084 function CollectData(data
,parent
) {
1085 var datastring
= '';
1086 for (property in data
) {
1087 if (typeof data
[property
] == 'object') {
1088 datastring +
= CollectData(data
[property
],parent+
'.'+property
);
1090 var element
= parent+
'.'+property
;
1091 var expression
= new RegExp(CMIIndexStore
,'g');
1092 var elementmodel
= String(element
).replace(expression
,'.n.');
1093 if ((typeof
eval('datamodel["'+elementmodel+
'"]')) != "undefined") {
1094 if (eval('datamodel["'+elementmodel+
'"].mod') != 'r') {
1095 var elementstring
= '&'+
underscore(element
)+
'='+
encodeURIComponent(data
[property
]);
1096 if ((typeof
eval('datamodel["'+elementmodel+
'"].defaultvalue')) != "undefined") {
1097 if (eval('datamodel["'+elementmodel+
'"].defaultvalue') != data
[property
]) {
1098 datastring +
= elementstring
;
1101 datastring +
= elementstring
;
1110 function StoreData(data
,storetotaltime
) {
1111 var datastring
= '';
1112 if (storetotaltime
) {
1113 if (cmi
.mode
== 'normal') {
1114 if (cmi
.credit
== 'credit') {
1115 if ((cmi
.completion_threshold
!= null) && (cmi
.progress_measure
!= null)) {
1116 if (cmi
.progress_measure
>= cmi
.completion_threshold
) {
1117 cmi
.completion_status
= 'completed';
1119 cmi
.completion_status
= 'incomplete';
1122 if ((cmi
.scaled_passed_score
!= null) && (cmi
.score
.scaled
!= '')) {
1123 if (cmi
.score
.scaled
>= cmi
.scaled_passed_score
) {
1124 cmi
.success_status
= 'passed';
1126 cmi
.success_status
= 'failed';
1131 datastring +
= TotalTime();
1133 datastring +
= CollectData(data
,'cmi');
1134 var element
= 'adl.nav.request';
1135 var navrequest
= eval(element
) != datamodel
[element
].defaultvalue ?
'&'+
underscore(element
)+
'='+
encodeURIComponent(eval(element
)) : '';
1136 datastring +
= navrequest
;
1137 datastring +
= '&attempt=<?php echo $attempt ?>';
1138 datastring +
= '&scoid=<?php echo $scoid ?>';
1140 // if (debugging('',DEBUG_DEVELOPER)) {
1141 // echo 'popupwin(datastring);';
1144 var myRequest
= NewHttpReq();
1145 var result
= DoRequest(myRequest
,"<?php p($CFG->wwwroot) ?>/mod/scorm/datamodel.php","id=<?php p($id) ?>&sesskey=<?php p($USER->sesskey) ?>"+datastring
);
1147 // if (debugging('',DEBUG_DEVELOPER)) {
1148 // echo 'popupwin(result);';
1151 var results
= String(result
).split('\n');
1152 if ((results
.length
> 2) && (navrequest
!= '')) {
1155 errorCode
= results
[1];
1159 this
.Initialize
= Initialize
;
1160 this
.Terminate
= Terminate
;
1161 this
.GetValue
= GetValue
;
1162 this
.SetValue
= SetValue
;
1163 this
.Commit
= Commit
;
1164 this
.GetLastError
= GetLastError
;
1165 this
.GetErrorString
= GetErrorString
;
1166 this
.GetDiagnostic
= GetDiagnostic
;
1167 this
.version
= '1.0';
1170 var API_1484_11
= new SCORMapi1_3();
1173 // pull in the debugging utilities
1174 if (debugging('',DEBUG_DEVELOPER
)) {
1175 include_once($CFG->dirroot
.'/mod/scorm/datamodels/debug.js.php');
1176 echo 'AppendToLog("Moodle SCORM 1.3 API Loaded, Activity: '.$scorm->name
.', SCO: '.$sco->identifier
.'", 0);';