2 if (isset($userdata->status
)) {
3 //if ($userdata->status == ''&& (!(($userdata->{'cmi.exit'} == 'suspend') || ($userdata->{'cmi.exit'} == 'logout'))&& !($userdata->{'adl.nav.request'} == 'suspendAll'))||($userdata->{'cmi.exit'} == 'normal')) { //antes solo llegaba esta lĂnea hasta el &&
4 if (!isset($userdata->{'cmi.exit'}) ||
(($userdata->{'cmi.exit'} == 'time-out') ||
($userdata->{'cmi.exit'} == 'normal'))) {
5 $userdata->entry
= 'ab-initio';
7 //if ((isset($userdata->{'cmi.exit'}) && (($userdata->{'cmi.exit'} == 'suspend') || ($userdata->{'cmi.exit'} == 'logout')))||(($userdata->{'adl.nav.request'} == 'suspendAll')&& isset($userdata->{'adl.nav.request'}) )) {
8 if (isset($userdata->{'cmi.exit'}) && (($userdata->{'cmi.exit'} == 'suspend') ||
($userdata->{'cmi.exit'} == 'logout'))) {
9 $userdata->entry
= 'resume';
11 $userdata->entry
= '';
17 // Used need to debug cmi content (if you uncomment this, you must comment the definition inside SCORMapi1_3)
18 //var cmi = new Object();
21 // SCORM 1.3 API Implementation
23 function SCORMapi1_3() {
24 // Standard Data Type Definition
25 var CMIString200
= '^.{0,200}$';
26 var CMIString250
= '^.{0,250}$';
27 var CMIString1000
= '^.{0,1500}$';
28 var CMIString4000
= '^.{0,4000}$';
29 var CMIString64000
= '^.{0,64000}$';
30 var CMILang
= '^([a-zA-Z]{2,3}|i|x)(\-[a-zA-Z0-9\-]{2,8})?$|^$';
31 var CMILangString250
= '^(\{lang=([a-zA-Z]{2,3}|i|x)(\-[a-zA-Z0-9\-]{2,8})?\})?([^\{].{0,250}$)?';
32 var CMILangString4000
= '^(\{lang=([a-zA-Z]{2,3}|i|x)(\-[a-zA-Z0-9\-]{2,8})?\})?([^\{].{0,4000}$)?';
33 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})?)?)?)?)?)?)?)?$';
34 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))))?$';
35 var CMIInteger
= '^\\d+$';
36 var CMISInteger
= '^-?([0-9]+)$';
37 var CMIDecimal
= '^-?([0-9]{1,4})(\\.[0-9]{1,18})?$';
38 var CMIIdentifier
= '^\\S{0,250}[a-zA-Z0-9]$';
39 var CMIShortIdentifier
= '^[\\w\.]{1,250}$';
40 var CMILongIdentifier
= '^\\S{0,4000}[a-zA-Z0-9]$';
41 var CMIFeedback
= '^.*$'; // This must be redefined
42 var CMIIndex
= '[._](\\d+).';
43 var CMIIndexStore
= '.N(\\d+).';
44 // Vocabulary Data Type Definition
45 var CMICStatus
= '^completed$|^incomplete$|^not attempted$|^unknown$';
46 var CMISStatus
= '^passed$|^failed$|^unknown$';
47 var CMIExit
= '^time-out$|^suspend$|^logout$|^normal$|^$';
48 var CMIType
= '^true-false$|^choice$|^(long-)?fill-in$|^matching$|^performance$|^sequencing$|^likert$|^numeric$|^other$';
49 var CMIResult
= '^correct$|^incorrect$|^unanticipated$|^neutral$|^-?([0-9]{1,4})(\\.[0-9]{1,18})?$';
50 var NAVEvent
= '^previous$|^continue$|^exit$|^exitAll$|^abandon$|^abandonAll$|^suspendAll$|^{target=\\S{0,200}[a-zA-Z0-9]}choice$';
51 var NAVBoolean
= '^unknown$|^true$|^false$';
52 var NAVTarget
= '^previous$|^continue$|^choice.{target=\\S{0,200}[a-zA-Z0-9]}$'
54 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';
55 var comments_children
= 'comment, timestamp, location';
56 var score_children
= 'max, raw, scaled, min';
57 var objectives_children
= 'progress_measure, completion_status, success_status, description, score, id';
58 var student_data_children
= 'mastery_score, max_time_allowed, time_limit_action';
59 var student_preference_children
= 'audio_level, audio_captioning, delivery_speed, language';
60 var interactions_children
= 'id, type, objectives, timestamp, correct_responses, weighting, learner_response, result, latency, description';
62 var scaled_range
= '-1#1';
63 var audio_range
= '0#*';
64 var speed_range
= '0#*';
65 var text_range
= '-1#1';
66 var progress_range
= '0#1';
67 var learner_response
= {
68 'true-false':{'format':'^true$|^false$', 'max':1, 'delimiter':'', 'unique':false},
69 'choice':{'format':CMIIdentifier
, 'max':36, 'delimiter':'[,]', 'unique':true},
70 'fill-in':{'format':CMILangString250
, 'max':10, 'delimiter':'[,]', 'unique':false},
71 'long-fill-in':{'format':CMILangString4000
, 'max':1, 'delimiter':'', 'unique':false},
72 'matching':{'format':CMIShortIdentifier
, 'format2':CMIShortIdentifier
, 'max':36, 'delimiter':'[,]', 'delimiter2':'[.]', 'unique':false},
73 'performance':{'format':'^$|'+CMIShortIdentifier
, 'format2':CMIDecimal+
'|^$|'+CMIShortIdentifier
, 'max':250, 'delimiter':'[,]', 'delimiter2':'[.]', 'unique':false},
74 'sequencing':{'format':CMIShortIdentifier
, 'max':36, 'delimiter':'[,]', 'unique':false},
75 'likert':{'format':CMIShortIdentifier
, 'max':1, 'delimiter':'', 'unique':false},
76 'numeric':{'format':CMIDecimal
, 'max':1, 'delimiter':'', 'unique':false},
77 'other':{'format':CMIString4000
, 'max':1, 'delimiter':'', 'unique':false}
79 var correct_responses
= {
80 'true-false':{'pre':'', 'max':1, 'delimiter':'', 'unique':false, 'duplicate':false,
81 'format':'^true$|^false$',
83 'choice':{'pre':'', 'max':36, 'delimiter':'[,]', 'unique':true, 'duplicate':false,
84 'format':CMIIdentifier
},
85 'fill-in':{'pre':'^(\{case_matters=(true|false)\})(\{order_matters=(true|false)\})?|^(\{order_matters=(true|false)\})(\{case_matters=(true|false)\})?',
86 'max':10, 'delimiter':'[,]', 'unique':false, 'duplicate':false,
87 'format':CMILangString250
},
88 'long-fill-in':{'pre':'^(\{case_matters=(true|false)\})?', 'max':1, 'delimiter':'', 'unique':false, 'duplicate':true,
89 'format':CMILangString4000
},
90 'matching':{'pre':'', 'max':36, 'delimiter':'[,]', 'delimiter2':'[.]', 'unique':false, 'duplicate':true,
91 'format':CMIShortIdentifier
, 'format2':CMIShortIdentifier
},
92 'performance':{'pre':'^(\{order_matters=(true|false)\})?',
93 'max':250, 'delimiter':'[,]', 'delimiter2':'[.]', 'unique':false, 'duplicate':true,
94 'format':'^$|'+CMIShortIdentifier
, 'format2':CMIDecimal+
'|^$|'+CMIShortIdentifier
},
95 'sequencing':{'pre':'', 'max':36, 'delimiter':'[,]', 'unique':false, 'duplicate':false,
96 'format':CMIShortIdentifier
},
97 'likert':{'pre':'', 'max':1, 'delimiter':'', 'unique':false, 'duplicate':false,
98 'format':CMIShortIdentifier
,
100 'numeric':{'pre':'', 'max':1, 'delimiter':'', 'unique':false, 'duplicate':false,
103 'other':{'pre':'', 'max':1, 'delimiter':'', 'unique':false, 'duplicate':false,
104 'format':CMIString4000
,
108 // The SCORM 1.3 data model
110 'cmi._children':{'defaultvalue':cmi_children
, 'mod':'r'},
111 'cmi._version':{'defaultvalue':'1.0', 'mod':'r'},
112 'cmi.comments_from_learner._children':{'defaultvalue':comments_children
, 'mod':'r'},
113 'cmi.comments_from_learner._count':{'mod':'r', 'defaultvalue':'0'},
114 'cmi.comments_from_learner.n.comment':{'format':CMILangString4000
, 'mod':'rw'},
115 'cmi.comments_from_learner.n.location':{'format':CMIString250
, 'mod':'rw'},
116 'cmi.comments_from_learner.n.timestamp':{'format':CMITime
, 'mod':'rw'},
117 'cmi.comments_from_lms._children':{'defaultvalue':comments_children
, 'mod':'r'},
118 'cmi.comments_from_lms._count':{'mod':'r', 'defaultvalue':'0'},
119 'cmi.comments_from_lms.n.comment':{'format':CMILangString4000
, 'mod':'r'},
120 'cmi.comments_from_lms.n.location':{'format':CMIString250
, 'mod':'r'},
121 'cmi.comments_from_lms.n.timestamp':{'format':CMITime
, 'mod':'r'},
122 'cmi.completion_status':{'defaultvalue':'<?php echo isset($userdata->{'cmi
.completion_status
'})?$userdata->{'cmi
.completion_status
'}:'unknown
' ?>', 'format':CMICStatus
, 'mod':'rw'},
123 'cmi.completion_threshold':{'defaultvalue':<?php
echo isset($userdata->threshold
)?
'\''.$userdata->threshold
.'\'':'null' ?
>, 'mod':'r'},
124 'cmi.credit':{'defaultvalue':'<?php echo isset($userdata->credit)?$userdata->credit:'' ?>', 'mod':'r'},
125 'cmi.entry':{'defaultvalue':'<?php echo $userdata->entry ?>', 'mod':'r'},
126 'cmi.exit':{'defaultvalue':'<?php echo isset($userdata->{'cmi
.exit'})?$userdata->{'cmi
.exit'}:'' ?>', 'format':CMIExit
, 'mod':'w'},
127 'cmi.interactions._children':{'defaultvalue':interactions_children
, 'mod':'r'},
128 'cmi.interactions._count':{'mod':'r', 'defaultvalue':'0'},
129 'cmi.interactions.n.id':{'pattern':CMIIndex
, 'format':CMILongIdentifier
, 'mod':'rw'},
130 'cmi.interactions.n.type':{'pattern':CMIIndex
, 'format':CMIType
, 'mod':'rw'},
131 'cmi.interactions.n.objectives._count':{'pattern':CMIIndex
, 'mod':'r', 'defaultvalue':'0'},
132 'cmi.interactions.n.objectives.n.id':{'pattern':CMIIndex
, 'format':CMILongIdentifier
, 'mod':'rw'},
133 'cmi.interactions.n.timestamp':{'pattern':CMIIndex
, 'format':CMITime
, 'mod':'rw'},
134 'cmi.interactions.n.correct_responses._count':{'defaultvalue':'0', 'pattern':CMIIndex
, 'mod':'r'},
135 'cmi.interactions.n.correct_responses.n.pattern':{'pattern':CMIIndex
, 'format':'CMIFeedback', 'mod':'rw'},
136 'cmi.interactions.n.weighting':{'pattern':CMIIndex
, 'format':CMIDecimal
, 'mod':'rw'},
137 'cmi.interactions.n.learner_response':{'pattern':CMIIndex
, 'format':'CMIFeedback', 'mod':'rw'},
138 'cmi.interactions.n.result':{'pattern':CMIIndex
, 'format':CMIResult
, 'mod':'rw'},
139 'cmi.interactions.n.latency':{'pattern':CMIIndex
, 'format':CMITimespan
, 'mod':'rw'},
140 'cmi.interactions.n.description':{'pattern':CMIIndex
, 'format':CMILangString250
, 'mod':'rw'},
141 'cmi.launch_data':{'defaultvalue':<?php
echo isset($userdata->datafromlms
)?
'\''.$userdata->datafromlms
.'\'':'null' ?
>, 'mod':'r'},
142 'cmi.learner_id':{'defaultvalue':'<?php echo $userdata->student_id ?>', 'mod':'r'},
143 'cmi.learner_name':{'defaultvalue':'<?php echo addslashes($userdata->student_name) ?>', 'mod':'r'},
144 'cmi.learner_preference._children':{'defaultvalue':student_preference_children
, 'mod':'r'},
145 'cmi.learner_preference.audio_level':{'defaultvalue':'1', 'format':CMIDecimal
, 'range':audio_range
, 'mod':'rw'},
146 'cmi.learner_preference.language':{'defaultvalue':'', 'format':CMILang
, 'mod':'rw'},
147 'cmi.learner_preference.delivery_speed':{'defaultvalue':'1', 'format':CMIDecimal
, 'range':speed_range
, 'mod':'rw'},
148 'cmi.learner_preference.audio_captioning':{'defaultvalue':'0', 'format':CMISInteger
, 'range':text_range
, 'mod':'rw'},
149 'cmi.location':{'defaultvalue':<?php
echo isset($userdata->{'cmi.location'})?
'\''.$userdata->{'cmi.location'}.'\'':'null' ?
>, 'format':CMIString1000
, 'mod':'rw'},
150 'cmi.max_time_allowed':{'defaultvalue':<?php
echo isset($userdata->maxtimeallowed
)?
'\''.$userdata->maxtimeallowed
.'\'':'null' ?
>, 'mod':'r'},
151 'cmi.mode':{'defaultvalue':'<?php echo $userdata->mode ?>', 'mod':'r'},
152 'cmi.objectives._children':{'defaultvalue':objectives_children
, 'mod':'r'},
153 'cmi.objectives._count':{'mod':'r', 'defaultvalue':'0'},
154 'cmi.objectives.n.id':{'pattern':CMIIndex
, 'format':CMILongIdentifier
, 'mod':'rw'},
155 'cmi.objectives.n.score._children':{'defaultvalue':score_children
, 'pattern':CMIIndex
, 'mod':'r'},
156 'cmi.objectives.n.score.scaled':{'defaultvalue':null, 'pattern':CMIIndex
, 'format':CMIDecimal
, 'range':scaled_range
, 'mod':'rw'},
157 'cmi.objectives.n.score.raw':{'defaultvalue':null, 'pattern':CMIIndex
, 'format':CMIDecimal
, 'mod':'rw'},
158 'cmi.objectives.n.score.min':{'defaultvalue':null, 'pattern':CMIIndex
, 'format':CMIDecimal
, 'mod':'rw'},
159 'cmi.objectives.n.score.max':{'defaultvalue':null, 'pattern':CMIIndex
, 'format':CMIDecimal
, 'mod':'rw'},
160 'cmi.objectives.n.success_status':{'defaultvalue':'unknown', 'pattern':CMIIndex
, 'format':CMISStatus
, 'mod':'rw'},
161 'cmi.objectives.n.completion_status':{'defaultvalue':'unknown', 'pattern':CMIIndex
, 'format':CMICStatus
, 'mod':'rw'},
162 'cmi.objectives.n.progress_measure':{'defaultvalue':null, 'format':CMIDecimal
, 'range':progress_range
, 'mod':'rw'},
163 'cmi.objectives.n.description':{'pattern':CMIIndex
, 'format':CMILangString250
, 'mod':'rw'},
164 'cmi.progress_measure':{'defaultvalue':<?php
echo isset($userdata->{'cmi.progess_measure'})?
'\''.$userdata->{'cmi.progress_measure'}.'\'':'null' ?
>, 'format':CMIDecimal
, 'range':progress_range
, 'mod':'rw'},
165 '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'},
166 'cmi.score._children':{'defaultvalue':score_children
, 'mod':'r'},
167 'cmi.score.scaled':{'defaultvalue':<?php
echo isset($userdata->{'cmi.score.scaled'})?
'\''.$userdata->{'cmi.score.scaled'}.'\'':'null' ?
>, 'format':CMIDecimal
, 'range':scaled_range
, 'mod':'rw'},
168 'cmi.score.raw':{'defaultvalue':<?php
echo isset($userdata->{'cmi.score.raw'})?
'\''.$userdata->{'cmi.score.raw'}.'\'':'null' ?
>, 'format':CMIDecimal
, 'mod':'rw'},
169 'cmi.score.min':{'defaultvalue':<?php
echo isset($userdata->{'cmi.score.min'})?
'\''.$userdata->{'cmi.score.min'}.'\'':'null' ?
>, 'format':CMIDecimal
, 'mod':'rw'},
170 'cmi.score.max':{'defaultvalue':<?php
echo isset($userdata->{'cmi.score.max'})?
'\''.$userdata->{'cmi.score.max'}.'\'':'null' ?
>, 'format':CMIDecimal
, 'mod':'rw'},
171 'cmi.session_time':{'format':CMITimespan
, 'mod':'w', 'defaultvalue':'PT0H0M0S'},
172 'cmi.success_status':{'defaultvalue':'<?php echo isset($userdata->{'cmi
.success_status
'})?$userdata->{'cmi
.success_status
'}:'unknown
' ?>', 'format':CMISStatus
, 'mod':'rw'},
173 'cmi.suspend_data':{'defaultvalue':<?php
echo isset($userdata->{'cmi.suspend_data'})?
'\''.$userdata->{'cmi.suspend_data'}.'\'':'null' ?
>, 'format':CMIString64000
, 'mod':'rw'},
174 'cmi.time_limit_action':{'defaultvalue':<?php
echo isset($userdata->timelimitaction
)?
'\''.$userdata->timelimitaction
.'\'':'null' ?
>, 'mod':'r'},
175 'cmi.total_time':{'defaultvalue':'<?php echo isset($userdata->{'cmi
.total_time
'})?$userdata->{'cmi
.total_time
'}:'PT0H0M0S
' ?>', 'mod':'r'},
176 'adl.nav.request':{'defaultvalue':'_none_', 'format':NAVEvent
, 'mod':'rw'}
179 // Datamodel inizialization
181 var cmi
= new Object();
182 cmi
.comments_from_learner
= new Object();
183 cmi
.comments_from_learner
._count
= 0;
184 cmi
.comments_from_lms
= new Object();
185 cmi
.comments_from_lms
._count
= 0;
186 cmi
.interactions
= new Object();
187 cmi
.interactions
._count
= 0;
188 cmi
.learner_preference
= new Object();
189 cmi
.objectives
= new Object();
190 cmi
.objectives
._count
= 0;
191 cmi
.score
= new Object();
194 var adl
= new Object();
195 adl
.nav
= new Object();
196 adl
.nav
.request_valid
= new Array();
198 for (element in datamodel
) {
199 if (element
.match(/\
.n\
./) == null) {
200 if ((typeof
eval('datamodel["'+element+
'"].defaultvalue')) != 'undefined') {
201 eval(element+
' = datamodel["'+element+
'"].defaultvalue;');
203 eval(element+
' = "";');
211 foreach($userdata as $element => $value){
212 if (substr($element,0,14) == 'cmi.objectives') {
213 preg_match('/\.(\d+)\./',$element,$matches);
214 $element = preg_replace('/\.(\d+)\./',".N\$1.",$element);
215 if ($matches[1] == $count) {
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
)) {
247 if (debugging('',DEBUG_DEVELOPER
)) {
248 echo 'alert("Initialized SCORM 1.3");';
265 if (debugging('',DEBUG_DEVELOPER
)) {
266 echo 'alert("Initialize: "+GetErrorString(errorCode));';
272 function Terminate (param
) {
275 if ((Initialized
) && (!Terminated
)) {
277 if (debugging('',DEBUG_DEVELOPER
)) {
278 echo 'alert("Terminated SCORM 1.3");';
283 var result
= StoreData(cmi
,true);
284 if (adl
.nav
.request
!= '_none_') {
285 switch (adl
.nav
.request
) {
287 setTimeout('top.nextSCO();',500);
290 setTimeout('top.prevSCO();',500);
304 if (<?php
echo $scorm->auto ?
> == 1) {
305 setTimeout('top.nextSCO();',500);
320 if (debugging('',DEBUG_DEVELOPER
)) {
321 echo 'alert("Terminate: "+GetErrorString(errorCode));';
327 function GetValue (element
) {
330 if ((Initialized
) && (!Terminated
)) {
332 var expression
= new RegExp(CMIIndex
,'g');
333 var elementmodel
= element
.replace(expression
,'.n.');
335 if ((typeof
eval('datamodel["'+elementmodel+
'"]')) != "undefined") {
336 if (eval('datamodel["'+elementmodel+
'"].mod') != 'w') {
338 element
= element
.replace(/\
.(\d+
)\
./, ".N$1.");
339 element
= element
.replace(/\
.(\d+
)\
./, ".N$1.");
341 var elementIndexes
= element
.split('.');
342 var subelement
= element
.substr(0,3);
345 while ((i
< elementIndexes
.length
) && (typeof
eval(subelement
) != "undefined")) {
346 subelement +
= '.'+elementIndexes
[i++
];
349 if (subelement
== element
) {
351 if ((typeof
eval(subelement
) != "undefined") && (eval(subelement
) != null)) {
354 if (debugging('',DEBUG_DEVELOPER
)) {
355 echo 'alert("GetValue("+element+") -> "+eval(element));';
358 return eval(element
);
366 //errorCode = eval('datamodel["'+elementmodel+'"].readerror');
370 var childrenstr
= '._children';
371 var countstr
= '._count';
372 var parentmodel
= '';
373 if (elementmodel
.substr(elementmodel
.length
-childrenstr
.length
,elementmodel
.length
) == childrenstr
) {
374 parentmodel
= elementmodel
.substr(0,elementmodel
.length
-childrenstr
.length
);
375 if ((typeof
eval('datamodel["'+parentmodel+
'"]')) != "undefined") {
377 diagnostic
= "Data Model Element Does Not Have Children";
381 } else if (elementmodel
.substr(elementmodel
.length
-countstr
.length
,elementmodel
.length
) == countstr
) {
382 parentmodel
= elementmodel
.substr(0,elementmodel
.length
-countstr
.length
);
383 if ((typeof
eval('datamodel["'+parentmodel+
'"]')) != "undefined") {
385 diagnostic
= "Data Model Element Cannot Have Count";
390 parentmodel
= 'adl.nav.request_valid.';
391 if (element
.substr(0,parentmodel
.length
) == parentmodel
) {
392 if (element
.substr(parentmodel
.length
).match(NAVTarget
) == null) {
395 if (adl
.nav
.request
== element
.substr(parentmodel
.length
)) {
397 } else if (adl
.nav
.request
== '_none_') {
419 if (debugging('',DEBUG_DEVELOPER
)) {
420 echo 'alert("GetValue("+element+") -> "+GetErrorString(errorCode));';
426 function SetValue (element
,value
) {
429 if ((Initialized
) && (!Terminated
)) {
431 var expression
= new RegExp(CMIIndex
,'g');
432 var elementmodel
= element
.replace(expression
,'.n.');
433 if ((typeof
eval('datamodel["'+elementmodel+
'"]')) != "undefined") {
434 if (eval('datamodel["'+elementmodel+
'"].mod') != 'r') {
435 if (eval('datamodel["'+elementmodel+
'"].format') != 'CMIFeedback') {
436 expression
= new RegExp(eval('datamodel["'+elementmodel+
'"].format'));
438 // cmi.interactions.n.type depending format accept everything at this stage
439 expression
= new RegExp(CMIFeedback
);
442 var matches
= value
.match(expression
);
443 if ((matches
!= null) && ((matches
.join('').length
> 0) ||
(value
.length
== 0))) {
444 // Value match dataelement format
446 if (element
!= elementmodel
) {
447 //This is a dynamic datamodel element
449 var elementIndexes
= element
.split('.');
450 var subelement
= 'cmi';
451 var parentelement
= 'cmi';
452 for (var i
=1;(i
< elementIndexes
.length
-1) && (errorCode
=="0");i++
) {
453 var elementIndex
= elementIndexes
[i
];
454 if (elementIndexes
[i+
1].match(/^\d+$
/)) {
455 if ((parseInt(elementIndexes
[i+
1]) > 0) && (elementIndexes
[i+
1].charAt(0) == 0)) {
456 // Index has a leading 0 (zero), this is not a number
459 parentelement
= subelement+
'.'+elementIndex
;
460 if ((typeof
eval(parentelement
) == "undefined") ||
(typeof
eval(parentelement+
'._count') == "undefined")) {
463 if (elementIndexes
[i+
1] > eval(parentelement+
'._count')) {
465 diagnostic
= "Data Model Element Collection Set Out Of Order";
467 subelement
= subelement
.concat('.'+elementIndex+
'.N'+elementIndexes
[i+
1]);
470 if (((typeof
eval(subelement
)) == "undefined") && (i
< elementIndexes
.length
-2)) {
475 subelement
= subelement
.concat('.'+elementIndex
);
479 if (errorCode
== "0") {
480 // Till now it's a real datamodel element
482 element
= subelement
.concat('.'+elementIndexes
[elementIndexes
.length
-1]);
484 if ((typeof
eval(subelement
)) == "undefined") {
485 switch (elementmodel
) {
486 case 'cmi.objectives.n.id':
487 if (!duplicatedID(element
,parentelement
,value
)) {
488 if (elementIndexes
[elementIndexes
.length
-2] == eval(parentelement+
'._count')) {
489 eval(parentelement+
'._count++;');
490 eval(subelement+
' = new Object();');
491 var subobject
= eval(subelement
);
492 subobject
.success_status
= datamodel
["cmi.objectives.n.success_status"].defaultvalue
;
493 subobject
.completion_status
= datamodel
["cmi.objectives.n.completion_status"].defaultvalue
;
494 subobject
.progress_measure
= datamodel
["cmi.objectives.n.progress_measure"].defaultvalue
;
495 subobject
.score
= new Object();
496 subobject
.score
._children
= score_children
;
497 subobject
.score
.scaled
= datamodel
["cmi.objectives.n.score.scaled"].defaultvalue
;
498 subobject
.score
.raw
= datamodel
["cmi.objectives.n.score.raw"].defaultvalue
;
499 subobject
.score
.min
= datamodel
["cmi.objectives.n.score.min"].defaultvalue
;
500 subobject
.score
.max
= datamodel
["cmi.objectives.n.score.max"].defaultvalue
;
504 diagnostic
= "Data Model Element ID Already Exists";
507 case 'cmi.interactions.n.id':
508 if (elementIndexes
[elementIndexes
.length
-2] == eval(parentelement+
'._count')) {
509 eval(parentelement+
'._count++;');
510 eval(subelement+
' = new Object();');
511 var subobject
= eval(subelement
);
512 subobject
.objectives
= new Object();
513 subobject
.objectives
._count
= 0;
516 case 'cmi.interactions.n.objectives.n.id':
517 if (typeof
eval(parentelement
) != "undefined") {
518 if (!duplicatedID(element
,parentelement
,value
)) {
519 if (elementIndexes
[elementIndexes
.length
-2] == eval(parentelement+
'._count')) {
520 eval(parentelement+
'._count++;');
521 eval(subelement+
' = new Object();');
525 diagnostic
= "Data Model Element ID Already Exists";
531 case 'cmi.interactions.n.correct_responses.n.pattern':
532 if (typeof
eval(parentelement
) != "undefined") {
534 // Use cmi.interactions.n.type value to check the right dataelement format
535 if (elementIndexes
[elementIndexes
.length
-2] == eval(parentelement+
'._count')) {
536 var interactiontype
= eval(parentelement
.replace('correct_responses','type'));
537 if ((typeof correct_responses
[interactiontype
].limit
== 'undefined') ||
538 (eval(parentelement+
'._count') < correct_responses
[interactiontype
].limit
)) {
539 if (correct_responses
[interactiontype
].pre
!= '') {
540 matches
= value
.match(correct_responses
[interactiontype
].pre
);
541 if (matches
!= null) {
542 value
= value
.substr(0,matches
[1].length
);
545 var nodes
= new Array();
546 if (correct_responses
[interactiontype
].delimiter
!= '') {
547 nodes
= value
.split(correct_responses
[interactiontype
].delimiter
);
551 if ((nodes
.length
> 0) && (nodes
.length
<= correct_responses
[interactiontype
].max
)) {
552 expression
= new RegExp(correct_responses
[interactiontype
].format
);
553 for (var i
=0; (i
<nodes
.length
) && (errorCode
=="0"); i++
) {
554 if (typeof correct_responses
[interactiontype
].delimiter2
!= 'undefined') {
555 values
= nodes
[i
].split(correct_responses
[interactiontype
].delimiter2
);
556 if (values
.length
== 2) {
557 matches
= values
[0].match(expression
);
558 if (matches
== null) {
561 var expression2
= new RegExp(correct_responses
[interactiontype
].format2
);
562 matches
= values
[1].match(expression2
);
563 if ((matches
== null) ||
(matches
.join('').length
== 0)) {
571 matches
= nodes
[i
].match(expression
);
572 if (matches
== null) {
575 if ((nodes
[i
] != '') && (correct_responses
[interactiontype
].unique
)) {
576 for (var j
=0; (j
<i
) && (errorCode
=="0"); j++
) {
577 if (nodes
[i
] == nodes
[j
]) {
585 } else if (nodes
.length
> correct_responses
[interactiontype
].max
) {
587 diagnostic
= "Data Model Element Pattern Too Long";
589 if ((errorCode
== "0") &&
590 ((correct_responses
[interactiontype
].duplicate
== false) ||
591 (!duplicatedPA(element
,parentelement
,value
)))) {
592 eval(parentelement+
'._count++;');
593 eval(subelement+
' = new Object();');
596 diagnostic
= "Data Model Element Pattern Already Exists";
600 diagnostic
= "Data Model Element Collection Limit Reached";
604 diagnostic
= "Data Model Element Collection Set Out Of Order";
611 if ((parentelement
!= 'cmi.objectives') && (parentelement
!= 'cmi.interactions') && (typeof
eval(parentelement
) != "undefined")) {
612 if (elementIndexes
[elementIndexes
.length
-2] == eval(parentelement+
'._count')) {
613 eval(parentelement+
'._count++;');
614 eval(subelement+
' = new Object();');
617 diagnostic
= "Data Model Element Collection Set Out Of Order";
625 switch (elementmodel
) {
626 case 'cmi.objectives.n.id':
627 if (eval(element
) != value
) {
629 diagnostic
= "Write Once Violation";
632 case 'cmi.interactions.n.objectives.n.id':
633 if (duplicatedID(element
,parentelement
,value
)) {
635 diagnostic
= "Data Model Element ID Already Exists";
638 case 'cmi.interactions.n.type':
639 var subobject
= eval(subelement
);
640 subobject
.correct_responses
= new Object();
641 subobject
.correct_responses
._count
= 0;
643 case 'cmi.interactions.n.learner_response':
644 if (typeof
eval(subelement+
'.type') == "undefined") {
647 // Use cmi.interactions.n.type value to check the right dataelement format
648 interactiontype
= eval(subelement+
'.type');
649 var nodes
= new Array();
650 if (learner_response
[interactiontype
].delimiter
!= '') {
651 nodes
= value
.split(learner_response
[interactiontype
].delimiter
);
655 if ((nodes
.length
> 0) && (nodes
.length
<= learner_response
[interactiontype
].max
)) {
656 expression
= new RegExp(learner_response
[interactiontype
].format
);
657 for (var i
=0; (i
<nodes
.length
) && (errorCode
=="0"); i++
) {
658 if (typeof learner_response
[interactiontype
].delimiter2
!= 'undefined') {
659 values
= nodes
[i
].split(learner_response
[interactiontype
].delimiter2
);
660 if (values
.length
== 2) {
661 matches
= values
[0].match(expression
);
662 if (matches
== null) {
665 var expression2
= new RegExp(learner_response
[interactiontype
].format2
);
666 matches
= values
[1].match(expression2
);
667 if (matches
== null) {
675 matches
= nodes
[i
].match(expression
);
676 if (matches
== null) {
679 if ((nodes
[i
] != '') && (learner_response
[interactiontype
].unique
)) {
680 for (var j
=0; (j
<i
) && (errorCode
=="0"); j++
) {
681 if (nodes
[i
] == nodes
[j
]) {
689 } else if (nodes
.length
> learner_response
[interactiontype
].max
) {
691 diagnostic
= "Data Model Element Pattern Too Long";
695 case 'cmi.interactions.n.correct_responses.n.pattern':
696 subel
= subelement
.split('.');
697 subel1
= 'cmi.interactions.'+subel
[2];
700 if (typeof
eval(subel1+
'.type') == "undefined") {
706 // Use cmi.interactions.n.type value to check the right //dataelement format
707 interactiontype
= eval(subel1+
'.type');
708 var nodes
= new Array();
709 if (correct_responses
[interactiontype
].delimiter
!= '') {
710 nodes
= value
.split(correct_responses
[interactiontype
].delimiter
);
721 if ((nodes
.length
> 0) && (nodes
.length
<= correct_responses
[interactiontype
].max
)) {
722 expression
= new RegExp(correct_responses
[interactiontype
].format
);
723 for (var i
=0; (i
<nodes
.length
) && (errorCode
=="0"); i++
) {
724 if (typeof correct_responses
[interactiontype
].delimiter2
!= 'undefined') {
727 values
= nodes
[i
].split(correct_responses
[interactiontype
].delimiter2
);
728 if (values
.length
== 2) {
730 matches
= values
[0].match(expression
);
731 if (matches
== null) {
736 var expression2
= new RegExp(correct_responses
[interactiontype
].format2
);
737 matches
= values
[1].match(expression2
);
738 if (matches
== null) {
748 matches
= nodes
[i
].match(expression
);
749 //if ((matches == null) || (matches.join('').length == 0)) {
750 if ((matches
== null && value
!= "")||
(matches
== null && interactiontype
=="true-false")){
755 if ((nodes
[i
] != '') && (correct_responses
[interactiontype
].unique
)) {
756 for (var j
=0; (j
<i
) && (errorCode
=="0"); j++
) {
757 if (nodes
[i
] == nodes
[j
]) {
766 } else if (nodes
.length
> correct_responses
[interactiontype
].max
) {
769 diagnostic
= "Data Model Element Pattern Too Long";
779 if (errorCode
== "0") {
781 if ((typeof
eval('datamodel["'+elementmodel+
'"].range')) != "undefined") {
782 range
= eval('datamodel["'+elementmodel+
'"].range');
783 ranges
= range
.split('#');
785 if (value
>= ranges
[0]) {
786 if ((ranges
[1] == '*') ||
(value
<= ranges
[1])) {
787 eval(element+
'=value;');
790 if (debugging('',DEBUG_DEVELOPER
)) {
791 echo 'alert("SetValue("+element+","+value+") -> OK");';
802 eval(element+
'=value;');
805 if (debugging('',DEBUG_DEVELOPER
)) {
806 echo 'alert("SetValue("+element+","+value+") -> OK");';
832 if (debugging('',DEBUG_DEVELOPER
)) {
833 echo 'alert("SetValue("+element+","+value+") -> "+GetErrorString(errorCode));';
839 function Commit (param
) {
842 if ((Initialized
) && (!Terminated
)) {
843 result
= StoreData(cmi
,false);
845 if (debugging('',DEBUG_DEVELOPER
)) {
846 echo 'alert("Data Commited");';
861 if (debugging('',DEBUG_DEVELOPER
)) {
862 echo 'alert("Commit: "+GetErrorString(errorCode));';
868 function GetLastError () {
872 function GetErrorString (param
) {
874 var errorString
= "";
877 errorString
= "No error";
880 errorString
= "General exception";
883 errorString
= "General Inizialization Failure";
886 errorString
= "Already Initialized";
889 errorString
= "Content Instance Terminated";
892 errorString
= "General Termination Failure";
895 errorString
= "Termination Before Inizialization";
898 errorString
= "Termination After Termination";
901 errorString
= "Retrieve Data Before Initialization";
904 errorString
= "Retrieve Data After Termination";
907 errorString
= "Store Data Before Inizialization";
910 errorString
= "Store Data After Termination";
913 errorString
= "Commit Before Inizialization";
916 errorString
= "Commit After Termination";
919 errorString
= "General Argument Error";
922 errorString
= "General Get Failure";
925 errorString
= "General Set Failure";
928 errorString
= "General Commit Failure";
931 errorString
= "Undefinited Data Model";
934 errorString
= "Unimplemented Data Model Element";
937 errorString
= "Data Model Element Value Not Initialized";
940 errorString
= "Data Model Element Is Read Only";
943 errorString
= "Data Model Element Is Write Only";
946 errorString
= "Data Model Element Type Mismatch";
949 errorString
= "Data Model Element Value Out Of Range";
952 errorString
= "Data Model Dependency Not Established";
961 function GetDiagnostic (param
) {
962 if (diagnostic
!= "") {
968 function duplicatedID (element
, parent
, value
) {
970 var elements
= eval(parent+
'._count');
971 for (var n
=0;(n
<elements
) && (!found
);n++
) {
972 if ((parent+
'.N'+n+
'.id' != element
) && (eval(parent+
'.N'+n+
'.id') == value
)) {
979 function duplicatedPA (element
, parent
, value
) {
981 var elements
= eval(parent+
'._count');
982 for (var n
=0;(n
<elements
) && (!found
);n++
) {
983 if ((parent+
'.N'+n+
'.pattern' != element
) && (eval(parent+
'.N'+n+
'.pattern') == value
)) {
990 function getElementModel(element
) {
991 if (typeof datamodel
[element
] != "undefined") {
994 var expression
= new RegExp(CMIIndex
,'g');
995 var elementmodel
= element
.replace(expression
,'.n.');
996 if (typeof datamodel
[elementmodel
] != "undefined") {
1003 function AddTime (first
, second
) {
1005 if (debugging('',DEBUG_DEVELOPER
)) {
1006 echo 'alert("AddTime: "+first+" + "+second);';
1009 var timestring
= 'P';
1010 var matchexpr
= /^
P((\d+
)Y
)?
((\d+
)M
)?
((\d+
)D
)?
(T((\d+
)H
)?
((\d+
)M
)?
((\d+
(\
.\d
{1,2})?
)S
)?
)?$
/;
1011 var firstarray
= first
.match(matchexpr
);
1012 var secondarray
= second
.match(matchexpr
);
1013 if ((firstarray
!= null) && (secondarray
!= null)) {
1014 var secs
= parseFloat(firstarray
[13],10)+
parseFloat(secondarray
[13],10); //Seconds
1015 var change
= Math
.floor(secs
/ 60);
1016 secs
= secs
- (change
* 60);
1017 var mins
= parseInt(firstarray
[11],10)+
parseInt(secondarray
[11],10)+change
; //Minutes
1018 change
= Math
.floor(mins
/ 60);
1019 mins
= mins
- (change
* 60);
1020 var hours
= parseInt(firstarray
[10],10)+
parseInt(secondarray
[10],10)+change
; //Hours
1021 change
= Math
.floor(hours
/ 24);
1022 hours
= hours
- (change
* 24);
1023 var days
= parseInt(firstarray
[6],10)+
parseInt(secondarray
[6],10)+change
; // Days
1024 var months
= parseInt(firstarray
[4],10)+
parseInt(secondarray
[4],10)
1025 var years
= parseInt(firstarray
[2],10)+
parseInt(secondarray
[2],10)
1028 timestring +
= years +
'Y';
1031 timestring +
= months +
'M';
1034 timestring +
= days +
'D';
1036 if ((hours
> 0) ||
(mins
> 0) ||
(secs
> 0)) {
1039 timestring +
= hours +
'H';
1042 timestring +
= mins +
'M';
1045 timestring +
= secs +
'S';
1051 function TotalTime() {
1052 var total_time
= AddTime(cmi
.total_time
, cmi
.session_time
);
1053 return '&'+
underscore('cmi.total_time')+
'='+
encodeURIComponent(total_time
);
1056 function CollectData(data
,parent
) {
1057 var datastring
= '';
1058 for (property in data
) {
1059 if (typeof data
[property
] == 'object') {
1060 datastring +
= CollectData(data
[property
],parent+
'.'+property
);
1062 var element
= parent+
'.'+property
;
1063 var expression
= new RegExp(CMIIndexStore
,'g');
1064 var elementmodel
= element
.replace(expression
,'.n.');
1065 if ((typeof
eval('datamodel["'+elementmodel+
'"]')) != "undefined") {
1066 if (eval('datamodel["'+elementmodel+
'"].mod') != 'r') {
1067 var elementstring
= '&'+
underscore(element
)+
'='+
encodeURIComponent(data
[property
]);
1068 if ((typeof
eval('datamodel["'+elementmodel+
'"].defaultvalue')) != "undefined") {
1069 if (eval('datamodel["'+elementmodel+
'"].defaultvalue') != data
[property
]) {
1070 datastring +
= elementstring
;
1073 datastring +
= elementstring
;
1082 function StoreData(data
,storetotaltime
) {
1083 var datastring
= '';
1084 if (storetotaltime
) {
1085 if (cmi
.mode
== 'normal') {
1086 if (cmi
.credit
== 'credit') {
1087 if ((cmi
.completion_threshold
!= null) && (cmi
.progress_measure
!= null)) {
1088 if (cmi
.progress_measure
>= cmi
.completion_threshold
) {
1089 cmi
.completion_status
= 'completed';
1091 cmi
.completion_status
= 'incomplete';
1094 if ((cmi
.scaled_passed_score
!= null) && (cmi
.score
.scaled
!= '')) {
1095 if (cmi
.score
.scaled
>= cmi
.scaled_passed_score
) {
1096 cmi
.success_status
= 'passed';
1098 cmi
.success_status
= 'failed';
1103 datastring +
= TotalTime();
1105 datastring +
= CollectData(data
,'cmi');
1106 var element
= 'adl.nav.request';
1107 var navrequest
= eval(element
) != datamodel
[element
].defaultvalue ?
'&'+
underscore(element
)+
'='+
encodeURIComponent(eval(element
)) : '';
1108 datastring +
= navrequest
;
1109 datastring +
= '&attempt=<?php echo $attempt ?>';
1110 datastring +
= '&scoid=<?php echo $scoid ?>';
1112 if (debugging('',DEBUG_DEVELOPER
)) {
1113 echo 'popupwin(datastring);';
1116 var myRequest
= NewHttpReq();
1117 var result
= DoRequest(myRequest
,"<?php p($CFG->wwwroot) ?>/mod/scorm/datamodel.php","id=<?php p($id) ?>&sesskey=<?php p($USER->sesskey) ?>"+datastring
);
1119 if (debugging('',DEBUG_DEVELOPER
)) {
1120 echo 'popupwin(result);';
1123 var results
= result
.split('\n');
1124 if ((results
.length
> 2) && (navrequest
!= '')) {
1127 errorCode
= results
[1];
1131 this
.Initialize
= Initialize
;
1132 this
.Terminate
= Terminate
;
1133 this
.GetValue
= GetValue
;
1134 this
.SetValue
= SetValue
;
1135 this
.Commit
= Commit
;
1136 this
.GetLastError
= GetLastError
;
1137 this
.GetErrorString
= GetErrorString
;
1138 this
.GetDiagnostic
= GetDiagnostic
;
1139 this
.version
= '1.0';
1142 var API_1484_11
= new SCORMapi1_3();