adding some strings
[moodle-linuxchix.git] / mod / scorm / datamodels / scorm_13.js.php
blobfffd175ec4e27e7124a9b88abc8fa62a8796ba90
1 <?php
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';
6 } else {
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';
10 } else {
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]}$'
53 // Children lists
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';
61 // Data ranges
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$',
82 'limit':1},
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,
99 'limit':1},
100 'numeric':{'pre':'', 'max':1, 'delimiter':'', 'unique':false, 'duplicate':false,
101 'format':CMIDecimal,
102 'limit':1},
103 'other':{'pre':'', 'max':1, 'delimiter':'', 'unique':false, 'duplicate':false,
104 'format':CMIString4000,
105 'limit':1}
108 // The SCORM 1.3 data model
109 var datamodel = {
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();
193 // Navigation 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;');
202 } else {
203 eval(element+' = "";');
208 <?php
209 $count = 0;
210 $objectives = '';
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) {
216 $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";
226 if ($count > 0) {
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;
240 var diagnostic = "";
242 function Initialize (param) {
243 errorCode = "0";
244 if (param == "") {
245 if ((!Initialized) && (!Terminated)) {
246 <?php
247 if (debugging('',DEBUG_DEVELOPER)) {
248 echo 'alert("Initialized SCORM 1.3");';
251 Initialized = true;
252 errorCode = "0";
253 return "true";
254 } else {
255 if (Initialized) {
256 errorCode = "103";
257 } else {
258 errorCode = "104";
261 } else {
262 errorCode = "201";
264 <?php
265 if (debugging('',DEBUG_DEVELOPER)) {
266 echo 'alert("Initialize: "+GetErrorString(errorCode));';
269 return "false";
272 function Terminate (param) {
273 errorCode = "0";
274 if (param == "") {
275 if ((Initialized) && (!Terminated)) {
276 <?php
277 if (debugging('',DEBUG_DEVELOPER)) {
278 echo 'alert("Terminated SCORM 1.3");';
281 Initialized = false;
282 Terminated = true;
283 var result = StoreData(cmi,true);
284 if (adl.nav.request != '_none_') {
285 switch (adl.nav.request) {
286 case 'continue':
287 setTimeout('top.nextSCO();',500);
288 break;
289 case 'previous':
290 setTimeout('top.prevSCO();',500);
291 break;
292 case 'choice':
293 break;
294 case 'exit':
295 break;
296 case 'exitAll':
297 break;
298 case 'abandon':
299 break;
300 case 'abandonAll':
301 break;
303 } else {
304 if (<?php echo $scorm->auto ?> == 1) {
305 setTimeout('top.nextSCO();',500);
308 return "true";
309 } else {
310 if (Terminated) {
311 errorCode = "113";
312 } else {
313 errorCode = "112";
316 } else {
317 errorCode = "201";
319 <?php
320 if (debugging('',DEBUG_DEVELOPER)) {
321 echo 'alert("Terminate: "+GetErrorString(errorCode));';
324 return "false";
327 function GetValue (element) {
328 errorCode = "0";
329 diagnostic = "";
330 if ((Initialized) && (!Terminated)) {
331 if (element !="") {
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);
343 var i = 1;
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)) {
352 errorCode = "0";
353 <?php
354 if (debugging('',DEBUG_DEVELOPER)) {
355 echo 'alert("GetValue("+element+") -> "+eval(element));';
358 return eval(element);
359 } else {
360 errorCode = "403";
362 } else {
363 errorCode = "301";
365 } else {
366 //errorCode = eval('datamodel["'+elementmodel+'"].readerror');
367 errorCode = "405";
369 } else {
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") {
376 errorCode = "301";
377 diagnostic = "Data Model Element Does Not Have Children";
378 } else {
379 errorCode = "401";
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") {
384 errorCode = "301";
385 diagnostic = "Data Model Element Cannot Have Count";
386 } else {
387 errorCode = "401";
389 } else {
390 parentmodel = 'adl.nav.request_valid.';
391 if (element.substr(0,parentmodel.length) == parentmodel) {
392 if (element.substr(parentmodel.length).match(NAVTarget) == null) {
393 errorCode = "301";
394 } else {
395 if (adl.nav.request == element.substr(parentmodel.length)) {
396 return "true";
397 } else if (adl.nav.request == '_none_') {
398 return "unknown";
399 } else {
400 return "false";
403 } else {
404 errorCode = "401";
408 } else {
409 errorCode = "301";
411 } else {
412 if (Terminated) {
413 errorCode = "123";
414 } else {
415 errorCode = "122";
418 <?php
419 if (debugging('',DEBUG_DEVELOPER)) {
420 echo 'alert("GetValue("+element+") -> "+GetErrorString(errorCode));';
423 return "";
426 function SetValue (element,value) {
427 errorCode = "0";
428 diagnostic = "";
429 if ((Initialized) && (!Terminated)) {
430 if (element != "") {
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'));
437 } else {
438 // cmi.interactions.n.type depending format accept everything at this stage
439 expression = new RegExp(CMIFeedback);
441 value = value+'';
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
457 errorCode = "351";
459 parentelement = subelement+'.'+elementIndex;
460 if ((typeof eval(parentelement) == "undefined") || (typeof eval(parentelement+'._count') == "undefined")) {
461 errorCode="408";
462 } else {
463 if (elementIndexes[i+1] > eval(parentelement+'._count')) {
464 errorCode = "351";
465 diagnostic = "Data Model Element Collection Set Out Of Order";
467 subelement = subelement.concat('.'+elementIndex+'.N'+elementIndexes[i+1]);
468 i++;
470 if (((typeof eval(subelement)) == "undefined") && (i < elementIndexes.length-2)) {
471 errorCode="408";
474 } else {
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;
502 } else {
503 errorCode="351";
504 diagnostic = "Data Model Element ID Already Exists";
506 break;
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;
515 break;
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();');
523 } else {
524 errorCode="351";
525 diagnostic = "Data Model Element ID Already Exists";
527 } else {
528 errorCode="408";
530 break;
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);
548 } else {
549 nodes[0] = value;
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) {
559 errorCode = "406";
560 } else {
561 var expression2= new RegExp(correct_responses[interactiontype].format2);
562 matches = values[1].match(expression2);
563 if ((matches == null) || (matches.join('').length == 0)) {
564 errorCode = "406";
567 } else {
568 errorCode = "406";
570 } else {
571 matches = nodes[i].match(expression);
572 if (matches == null) {
573 errorCode = "406";
574 } else {
575 if ((nodes[i] != '') && (correct_responses[interactiontype].unique)) {
576 for (var j=0; (j<i) && (errorCode=="0"); j++) {
577 if (nodes[i] == nodes[j]) {
578 errorCode = "406";
585 } else if (nodes.length > correct_responses[interactiontype].max) {
586 errorCode = "351";
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();');
594 } else {
595 errorCode="351";
596 diagnostic = "Data Model Element Pattern Already Exists";
598 } else {
599 errorCode="351";
600 diagnostic = "Data Model Element Collection Limit Reached";
602 } else {
603 errorCode="351";
604 diagnostic = "Data Model Element Collection Set Out Of Order";
606 } else {
607 errorCode="408";
609 break;
610 default:
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();');
615 } else {
616 errorCode="351";
617 diagnostic = "Data Model Element Collection Set Out Of Order";
619 } else {
620 errorCode="408";
622 break;
624 } else {
625 switch (elementmodel) {
626 case 'cmi.objectives.n.id':
627 if (eval(element) != value) {
628 errorCode = "351";
629 diagnostic = "Write Once Violation";
631 break;
632 case 'cmi.interactions.n.objectives.n.id':
633 if (duplicatedID(element,parentelement,value)) {
634 errorCode = "351";
635 diagnostic = "Data Model Element ID Already Exists";
637 break;
638 case 'cmi.interactions.n.type':
639 var subobject = eval(subelement);
640 subobject.correct_responses = new Object();
641 subobject.correct_responses._count = 0;
642 break;
643 case 'cmi.interactions.n.learner_response':
644 if (typeof eval(subelement+'.type') == "undefined") {
645 errorCode="408";
646 } else {
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);
652 } else {
653 nodes[0] = value;
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) {
663 errorCode = "406";
664 } else {
665 var expression2 = new RegExp(learner_response[interactiontype].format2);
666 matches = values[1].match(expression2);
667 if (matches == null) {
668 errorCode = "406";
671 } else {
672 errorCode = "406";
674 } else {
675 matches = nodes[i].match(expression);
676 if (matches == null) {
677 errorCode = "406";
678 } else {
679 if ((nodes[i] != '') && (learner_response[interactiontype].unique)) {
680 for (var j=0; (j<i) && (errorCode=="0"); j++) {
681 if (nodes[i] == nodes[j]) {
682 errorCode = "406";
689 } else if (nodes.length > learner_response[interactiontype].max) {
690 errorCode = "351";
691 diagnostic = "Data Model Element Pattern Too Long";
694 break;
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") {
702 errorCode="408";
703 } else {
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);
711 } else {
712 nodes[0] = value;
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) {
733 errorCode = "406";
734 } else {
736 var expression2 = new RegExp(correct_responses[interactiontype].format2);
737 matches = values[1].match(expression2);
738 if (matches == null) {
740 errorCode = "406";
743 } else {
744 errorCode = "406";
746 } else {
748 matches = nodes[i].match(expression);
749 //if ((matches == null) || (matches.join('').length == 0)) {
750 if ((matches == null && value != "")||(matches == null && interactiontype=="true-false")){
752 errorCode = "406";
753 } else {
755 if ((nodes[i] != '') && (correct_responses[interactiontype].unique)) {
756 for (var j=0; (j<i) && (errorCode=="0"); j++) {
757 if (nodes[i] == nodes[j]) {
759 errorCode = "406";
766 } else if (nodes.length > correct_responses[interactiontype].max) {
768 errorCode = "351";
769 diagnostic = "Data Model Element Pattern Too Long";
773 break;
778 //Store data
779 if (errorCode == "0") {
781 if ((typeof eval('datamodel["'+elementmodel+'"].range')) != "undefined") {
782 range = eval('datamodel["'+elementmodel+'"].range');
783 ranges = range.split('#');
784 value = value*1.0;
785 if (value >= ranges[0]) {
786 if ((ranges[1] == '*') || (value <= ranges[1])) {
787 eval(element+'=value;');
788 errorCode = "0";
789 <?php
790 if (debugging('',DEBUG_DEVELOPER)) {
791 echo 'alert("SetValue("+element+","+value+") -> OK");';
794 return "true";
795 } else {
796 errorCode = '407';
798 } else {
799 errorCode = '407';
801 } else {
802 eval(element+'=value;');
803 errorCode = "0";
804 <?php
805 if (debugging('',DEBUG_DEVELOPER)) {
806 echo 'alert("SetValue("+element+","+value+") -> OK");';
809 return "true";
812 } else {
813 errorCode = "406";
815 } else {
816 errorCode = "404";
818 } else {
819 errorCode = "401"
821 } else {
822 errorCode = "351";
824 } else {
825 if (Terminated) {
826 errorCode = "133";
827 } else {
828 errorCode = "132";
831 <?php
832 if (debugging('',DEBUG_DEVELOPER)) {
833 echo 'alert("SetValue("+element+","+value+") -> "+GetErrorString(errorCode));';
836 return "false";
839 function Commit (param) {
840 errorCode = "0";
841 if (param == "") {
842 if ((Initialized) && (!Terminated)) {
843 result = StoreData(cmi,false);
844 <?php
845 if (debugging('',DEBUG_DEVELOPER)) {
846 echo 'alert("Data Commited");';
849 return "true";
850 } else {
851 if (Terminated) {
852 errorCode = "143";
853 } else {
854 errorCode = "142";
857 } else {
858 errorCode = "201";
860 <?php
861 if (debugging('',DEBUG_DEVELOPER)) {
862 echo 'alert("Commit: "+GetErrorString(errorCode));';
865 return "false";
868 function GetLastError () {
869 return errorCode;
872 function GetErrorString (param) {
873 if (param != "") {
874 var errorString = "";
875 switch(param) {
876 case "0":
877 errorString = "No error";
878 break;
879 case "101":
880 errorString = "General exception";
881 break;
882 case "102":
883 errorString = "General Inizialization Failure";
884 break;
885 case "103":
886 errorString = "Already Initialized";
887 break;
888 case "104":
889 errorString = "Content Instance Terminated";
890 break;
891 case "111":
892 errorString = "General Termination Failure";
893 break;
894 case "112":
895 errorString = "Termination Before Inizialization";
896 break;
897 case "113":
898 errorString = "Termination After Termination";
899 break;
900 case "122":
901 errorString = "Retrieve Data Before Initialization";
902 break;
903 case "123":
904 errorString = "Retrieve Data After Termination";
905 break;
906 case "132":
907 errorString = "Store Data Before Inizialization";
908 break;
909 case "133":
910 errorString = "Store Data After Termination";
911 break;
912 case "142":
913 errorString = "Commit Before Inizialization";
914 break;
915 case "143":
916 errorString = "Commit After Termination";
917 break;
918 case "201":
919 errorString = "General Argument Error";
920 break;
921 case "301":
922 errorString = "General Get Failure";
923 break;
924 case "351":
925 errorString = "General Set Failure";
926 break;
927 case "391":
928 errorString = "General Commit Failure";
929 break;
930 case "401":
931 errorString = "Undefinited Data Model";
932 break;
933 case "402":
934 errorString = "Unimplemented Data Model Element";
935 break;
936 case "403":
937 errorString = "Data Model Element Value Not Initialized";
938 break;
939 case "404":
940 errorString = "Data Model Element Is Read Only";
941 break;
942 case "405":
943 errorString = "Data Model Element Is Write Only";
944 break;
945 case "406":
946 errorString = "Data Model Element Type Mismatch";
947 break;
948 case "407":
949 errorString = "Data Model Element Value Out Of Range";
950 break;
951 case "408":
952 errorString = "Data Model Dependency Not Established";
953 break;
955 return errorString;
956 } else {
957 return "";
961 function GetDiagnostic (param) {
962 if (diagnostic != "") {
963 return diagnostic;
965 return param;
968 function duplicatedID (element, parent, value) {
969 var found = false;
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)) {
973 found = true;
976 return found;
979 function duplicatedPA (element, parent, value) {
980 var found = false;
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)) {
984 found = true;
987 return found;
990 function getElementModel(element) {
991 if (typeof datamodel[element] != "undefined") {
992 return element;
993 } else {
994 var expression = new RegExp(CMIIndex,'g');
995 var elementmodel = element.replace(expression,'.n.');
996 if (typeof datamodel[elementmodel] != "undefined") {
997 return elementmodel;
1000 return false;
1003 function AddTime (first, second) {
1004 <?php
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)
1027 if (years > 0) {
1028 timestring += years + 'Y';
1030 if (months > 0) {
1031 timestring += months + 'M';
1033 if (days > 0) {
1034 timestring += days + 'D';
1036 if ((hours > 0) || (mins > 0) || (secs > 0)) {
1037 timestring += 'T';
1038 if (hours > 0) {
1039 timestring += hours + 'H';
1041 if (mins > 0) {
1042 timestring += mins + 'M';
1044 if (secs > 0) {
1045 timestring += secs + 'S';
1048 return timestring;
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);
1061 } else {
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;
1072 } else {
1073 datastring += elementstring;
1079 return datastring;
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';
1090 } else {
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';
1097 } else {
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 ?>';
1111 <?php
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);
1118 <?php
1119 if (debugging('',DEBUG_DEVELOPER)) {
1120 echo 'popupwin(result);';
1123 var results = result.split('\n');
1124 if ((results.length > 2) && (navrequest != '')) {
1125 eval(results[2]);
1127 errorCode = results[1];
1128 return results[0];
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();