MDL-11517 reserved word MOD used in table alias in questions backup code
[moodle-pu.git] / mod / scorm / datamodels / aicc.js.php
blobe141af7c30bc7a4591ee370dda49353dc7a31b5c
1 <?php
2 if (isset($userdata->status)) {
3 if ($userdata->status == '') {
4 $userdata->entry = 'ab-initio';
5 } else {
6 if (isset($userdata->{'cmi.core.exit'}) && ($userdata->{'cmi.core.exit'} == 'suspend')) {
7 $userdata->entry = 'resume';
8 } else {
9 $userdata->entry = '';
15 // SCORM 1.2 API Implementation
17 function AICCapi() {
18 // Standard Data Type Definition
19 CMIString256 = '^.{0,255}$';
20 //CMIString4096 = '^[.|\\n|\\r]{0,4095}$';
21 CMIString4096 = '^.{0,4096}$';
22 CMITime = '^([0-2]{1}[0-9]{1}):([0-5]{1}[0-9]{1}):([0-5]{1}[0-9]{1})(\.[0-9]{1,2})?$';
23 CMITimespan = '^([0-9]{2,4}):([0-9]{2}):([0-9]{2})(\.[0-9]{1,2})?$';
24 CMIInteger = '^\\d+$';
25 CMISInteger = '^-?([0-9]+)$';
26 CMIDecimal = '^-?([0-9]{0,3})(\.[0-9]{1,2})?$';
27 CMIIdentifier = '^\\w{1,255}$';
28 CMIFeedback = CMIString256; // This must be redefined
29 CMIIndex = '[._](\\d+).';
30 // Vocabulary Data Type Definition
31 CMIStatus = '^passed$|^completed$|^failed$|^incomplete$|^browsed$';
32 CMIStatus2 = '^passed$|^completed$|^failed$|^incomplete$|^browsed$|^not attempted$';
33 CMIExit = '^time-out$|^suspend$|^logout$|^$';
34 CMIType = '^true-false$|^choice$|^fill-in$|^matching$|^performance$|^sequencing$|^likert$|^numeric$';
35 CMIResult = '^correct$|^wrong$|^unanticipated$|^neutral$|^([0-9]{0,3})?(\.[0-9]{1,2})?$';
36 NAVEvent = '^previous$|^continue$';
37 // Children lists
38 cmi_children = 'core, suspend_data, launch_data, comments, objectives, student_data, student_preference, interactions';
39 core_children = 'student_id, student_name, lesson_location, credit, lesson_status, entry, score, total_time, lesson_mode, exit, session_time';
40 score_children = 'raw, min, max';
41 comments_children = 'content, location, time';
42 objectives_children = 'id, score, status';
43 student_data_children = 'attempt_number, tries, mastery_score, max_time_allowed, time_limit_action';
44 student_preference_children = 'audio, language, speed, text';
45 interactions_children = 'id, objectives, time, type, correct_responses, weighting, student_response, result, latency';
46 // Data ranges
47 score_range = '0#100';
48 audio_range = '-1#100';
49 speed_range = '-100#100';
50 weighting_range = '-100#100';
51 text_range = '-1#1';
52 // The AICC data model
53 var datamodel = {
54 'cmi._children':{'defaultvalue':cmi_children, 'mod':'r', 'writeerror':'402'},
55 'cmi._version':{'defaultvalue':'3.4', 'mod':'r', 'writeerror':'402'},
56 'cmi.core._children':{'defaultvalue':core_children, 'mod':'r', 'writeerror':'402'},
57 'cmi.core.student_id':{'defaultvalue':'<?php echo $userdata->student_id ?>', 'mod':'r', 'writeerror':'403'},
58 'cmi.core.student_name':{'defaultvalue':'<?php echo $userdata->student_name ?>', 'mod':'r', 'writeerror':'403'},
59 'cmi.core.lesson_location':{'defaultvalue':'<?php echo isset($userdata->{'cmi.core.lesson_location'})?$userdata->{'cmi.core.lesson_location'}:'' ?>', 'format':CMIString256, 'mod':'rw', 'writeerror':'405'},
60 'cmi.core.credit':{'defaultvalue':'<?php echo $userdata->credit ?>', 'mod':'r', 'writeerror':'403'},
61 'cmi.core.lesson_status':{'defaultvalue':'<?php echo isset($userdata->{'cmi.core.lesson_status'})?$userdata->{'cmi.core.lesson_status'}:'' ?>', 'format':CMIStatus, 'mod':'rw', 'writeerror':'405'},
62 'cmi.core.exit':{'defaultvalue':'<?php echo isset($userdata->{'cmi.core.exit'})?$userdata->{'cmi.core.exit'}:'' ?>', 'format':CMIExit, 'mod':'w', 'readerror':'404', 'writeerror':'405'},
63 'cmi.core.entry':{'defaultvalue':'<?php echo $userdata->entry ?>', 'mod':'r', 'writeerror':'403'},
64 'cmi.core.score._children':{'defaultvalue':score_children, 'mod':'r', 'writeerror':'402'},
65 'cmi.core.score.raw':{'defaultvalue':'<?php echo isset($userdata->{'cmi.core.score.raw'})?$userdata->{'cmi.core.score.raw'}:'' ?>', 'format':CMIDecimal, 'range':score_range, 'mod':'rw', 'writeerror':'405'},
66 'cmi.core.score.max':{'defaultvalue':'<?php echo isset($userdata->{'cmi.core.score.max'})?$userdata->{'cmi.core.score.max'}:'' ?>', 'format':CMIDecimal, 'range':score_range, 'mod':'rw', 'writeerror':'405'},
67 'cmi.core.score.min':{'defaultvalue':'<?php echo isset($userdata->{'cmi.core.score.min'})?$userdata->{'cmi.core.score.min'}:'' ?>', 'format':CMIDecimal, 'range':score_range, 'mod':'rw', 'writeerror':'405'},
68 'cmi.core.session_time':{'format':CMITimespan, 'mod':'w', 'defaultvalue':'00:00:00', 'readerror':'404', 'writeerror':'405'},
69 'cmi.core.total_time':{'defaultvalue':'<?php echo isset($userdata->{'cmi.core.total_time'})?$userdata->{'cmi.core.total_time'}:'00:00:00' ?>', 'mod':'r', 'writeerror':'403'},
70 'cmi.core.lesson_mode':{'defaultvalue':'<?php echo $userdata->mode ?>', 'mod':'r', 'writeerror':'403'},
71 'cmi.suspend_data':{'defaultvalue':'<?php echo isset($userdata->{'cmi.suspend_data'})?$userdata->{'cmi.suspend_data'}:'' ?>', 'format':CMIString4096, 'mod':'rw', 'writeerror':'405'},
72 'cmi.launch_data':{'defaultvalue':'<?php echo $userdata->datafromlms ?>', 'mod':'r', 'writeerror':'403'},
73 'cmi.comments':{'defaultvalue':'<?php echo isset($userdata->{'cmi.comments'})?$userdata->{'cmi.comments'}:'' ?>', 'format':CMIString4096, 'mod':'rw', 'writeerror':'405'},
74 'cmi.evaluation.comments._count':{'defaultvalue':'0', 'mod':'r', 'writeerror':'402'},
75 'cmi.evaluation.comments._children':{'defaultvalue':comments_children, 'mod':'r', 'writeerror':'402'},
76 'cmi.evaluation.comments.n.content':{'defaultvalue':'', 'pattern':CMIIndex, 'format':CMIString256, 'mod':'rw', 'writeerror':'405'},
77 'cmi.evaluation.comments.n.location':{'defaultvalue':'', 'pattern':CMIIndex, 'format':CMIString256, 'mod':'rw', 'writeerror':'405'},
78 'cmi.evaluation.comments.n.time':{'defaultvalue':'', 'pattern':CMIIndex, 'format':CMITime, 'mod':'rw', 'writeerror':'405'},
79 'cmi.comments_from_lms':{'mod':'r', 'writeerror':'403'},
80 'cmi.objectives._children':{'defaultvalue':objectives_children, 'mod':'r', 'writeerror':'402'},
81 'cmi.objectives._count':{'mod':'r', 'defaultvalue':'0', 'writeerror':'402'},
82 'cmi.objectives.n.id':{'pattern':CMIIndex, 'format':CMIIdentifier, 'mod':'rw', 'writeerror':'405'},
83 'cmi.objectives.n.score._children':{'pattern':CMIIndex, 'mod':'r', 'writeerror':'402'},
84 'cmi.objectives.n.score.raw':{'defaultvalue':'', 'pattern':CMIIndex, 'format':CMIDecimal, 'range':score_range, 'mod':'rw', 'writeerror':'405'},
85 'cmi.objectives.n.score.min':{'defaultvalue':'', 'pattern':CMIIndex, 'format':CMIDecimal, 'range':score_range, 'mod':'rw', 'writeerror':'405'},
86 'cmi.objectives.n.score.max':{'defaultvalue':'', 'pattern':CMIIndex, 'format':CMIDecimal, 'range':score_range, 'mod':'rw', 'writeerror':'405'},
87 'cmi.objectives.n.status':{'pattern':CMIIndex, 'format':CMIStatus2, 'mod':'rw', 'writeerror':'405'},
88 'cmi.student_data._children':{'defaultvalue':student_data_children, 'mod':'r', 'writeerror':'402'},
89 'cmi.student_data.attempt_number':{'defaultvalue':'<?php echo isset($userdata->{'cmi.student_data.attempt_number'})?$userdata->{'cmi.student_data.attempt_number'}:'' ?>', 'mod':'r', 'writeerror':'402'},
90 'cmi.student_data.tries.n.score.raw':{'defaultvalue':'', 'pattern':CMIIndex, 'format':CMIDecimal, 'range':score_range, 'mod':'rw', 'writeerror':'405'},
91 'cmi.student_data.tries.n.score.min':{'defaultvalue':'', 'pattern':CMIIndex, 'format':CMIDecimal, 'range':score_range, 'mod':'rw', 'writeerror':'405'},
92 'cmi.student_data.tries.n.score.max':{'defaultvalue':'', 'pattern':CMIIndex, 'format':CMIDecimal, 'range':score_range, 'mod':'rw', 'writeerror':'405'},
93 'cmi.student_data.tries.n.status':{'pattern':CMIIndex, 'format':CMIStatus2, 'mod':'rw', 'writeerror':'405'},
94 'cmi.student_data.tries.n.time':{'pattern':CMIIndex, 'format':CMITime, 'mod':'rw', 'writeerror':'405'},
95 'cmi.student_data.mastery_score':{'defaultvalue':'<?php echo $userdata->masteryscore ?>', 'mod':'r', 'writeerror':'403'},
96 'cmi.student_data.max_time_allowed':{'defaultvalue':'<?php echo $userdata->maxtimeallowed ?>', 'mod':'r', 'writeerror':'403'},
97 'cmi.student_data.time_limit_action':{'defaultvalue':'<?php echo $userdata->timelimitaction ?>', 'mod':'r', 'writeerror':'403'},
98 'cmi.student_data.tries_during_lesson':{'defaultvalue':'<?php echo isset($userdata->{'cmi.student_data.tries_during_lesson'})?$userdata->{'cmi.student_data.tries_during_lesson'}:'' ?>', 'mod':'r', 'writeerror':'402'},
99 'cmi.student_preference._children':{'defaultvalue':student_preference_children, 'mod':'r', 'writeerror':'402'},
100 'cmi.student_preference.audio':{'defaultvalue':'0', 'format':CMISInteger, 'range':audio_range, 'mod':'rw', 'writeerror':'405'},
101 'cmi.student_preference.language':{'defaultvalue':'', 'format':CMIString256, 'mod':'rw', 'writeerror':'405'},
102 'cmi.student_preference.speed':{'defaultvalue':'0', 'format':CMISInteger, 'range':speed_range, 'mod':'rw', 'writeerror':'405'},
103 'cmi.student_preference.text':{'defaultvalue':'0', 'format':CMISInteger, 'range':text_range, 'mod':'rw', 'writeerror':'405'},
104 'cmi.interactions._children':{'defaultvalue':interactions_children, 'mod':'r', 'writeerror':'402'},
105 'cmi.interactions._count':{'mod':'r', 'defaultvalue':'0', 'writeerror':'402'},
106 'cmi.interactions.n.id':{'pattern':CMIIndex, 'format':CMIIdentifier, 'mod':'w', 'readerror':'404', 'writeerror':'405'},
107 'cmi.interactions.n.objectives._count':{'pattern':CMIIndex, 'mod':'r', 'defaultvalue':'0', 'writeerror':'402'},
108 'cmi.interactions.n.objectives.n.id':{'pattern':CMIIndex, 'format':CMIIdentifier, 'mod':'w', 'readerror':'404', 'writeerror':'405'},
109 'cmi.interactions.n.time':{'pattern':CMIIndex, 'format':CMITime, 'mod':'w', 'readerror':'404', 'writeerror':'405'},
110 'cmi.interactions.n.type':{'pattern':CMIIndex, 'format':CMIType, 'mod':'w', 'readerror':'404', 'writeerror':'405'},
111 'cmi.interactions.n.correct_responses._count':{'pattern':CMIIndex, 'mod':'r', 'defaultvalue':'0', 'writeerror':'402'},
112 'cmi.interactions.n.correct_responses.n.pattern':{'pattern':CMIIndex, 'format':CMIFeedback, 'mod':'w', 'readerror':'404', 'writeerror':'405'},
113 'cmi.interactions.n.weighting':{'pattern':CMIIndex, 'format':CMIDecimal, 'range':weighting_range, 'mod':'w', 'readerror':'404', 'writeerror':'405'},
114 'cmi.interactions.n.student_response':{'pattern':CMIIndex, 'format':CMIFeedback, 'mod':'w', 'readerror':'404', 'writeerror':'405'},
115 'cmi.interactions.n.result':{'pattern':CMIIndex, 'format':CMIResult, 'mod':'w', 'readerror':'404', 'writeerror':'405'},
116 'cmi.interactions.n.latency':{'pattern':CMIIndex, 'format':CMITimespan, 'mod':'w', 'readerror':'404', 'writeerror':'405'},
117 'nav.event':{'defaultvalue':'', 'format':NAVEvent, 'mod':'w', 'readerror':'404', 'writeerror':'405'}
120 // Datamodel inizialization
122 var cmi = new Object();
123 cmi.core = new Object();
124 cmi.core.score = new Object();
125 cmi.objectives = new Object();
126 cmi.student_data = new Object();
127 cmi.student_preference = new Object();
128 cmi.interactions = new Object();
130 // Navigation Object
131 var nav = new Object();
133 for (element in datamodel) {
134 if (element.match(/\.n\./) == null) {
135 if ((typeof eval('datamodel["'+element+'"].defaultvalue')) != 'undefined') {
136 eval(element+' = datamodel["'+element+'"].defaultvalue;');
137 } else {
138 eval(element+' = "";');
143 <?php
144 $count = 0;
145 $objectives = '';
146 foreach($userdata as $element => $value){
147 if (substr($element,0,14) == 'cmi.objectives') {
148 preg_match('/.(\d+)./',$element,$matches);
149 $element = preg_replace('/.(\d+)./',"_\$1.",$element);
150 if ($matches[1] == $count) {
151 $count++;
152 $end = strpos($element,$matches[1])+strlen($matches[1]);
153 $subelement = substr($element,0,$end);
154 echo ' '.$subelement." = new Object();\n";
155 echo ' '.$subelement.".score = new Object();\n";
156 echo ' '.$subelement.".score._children = score_children;\n";
157 echo ' '.$subelement.".score.raw = '';\n";
158 echo ' '.$subelement.".score.min = '';\n";
159 echo ' '.$subelement.".score.max = '';\n";
161 echo ' '.$element.' = \''.$value."';\n";
164 if ($count > 0) {
165 echo ' cmi.objectives._count = '.$count.";\n";
169 if (cmi.core.lesson_status == '') {
170 cmi.core.lesson_status = 'not attempted';
174 // API Methods definition
176 var Initialized = false;
178 function LMSInitialize (param) {
179 errorCode = "0";
180 if (param == "") {
181 if (!Initialized) {
182 Initialized = true;
183 errorCode = "0";
184 return "true";
185 } else {
186 errorCode = "101";
188 } else {
189 errorCode = "201";
191 return "false";
194 function LMSFinish (param) {
195 errorCode = "0";
196 if (param == "") {
197 if (Initialized) {
198 Initialized = false;
199 result = StoreData(cmi,true);
200 if (nav.event != '') {
201 if (nav.event == 'continue') {
202 setTimeout('top.nextSCO();',500);
203 } else {
204 setTimeout('top.prevSCO();',500);
206 } else {
207 if (<?php echo $scorm->auto ?> == 1) {
208 setTimeout('top.nextSCO();',500);
211 return "true";
212 } else {
213 errorCode = "301";
215 } else {
216 errorCode = "201";
218 return "false";
221 function LMSGetValue (element) {
222 errorCode = "0";
223 if (Initialized) {
224 if (element !="") {
225 expression = new RegExp(CMIIndex,'g');
226 elementmodel = element.replace(expression,'.n.');
227 if ((typeof eval('datamodel["'+elementmodel+'"]')) != "undefined") {
228 if (eval('datamodel["'+elementmodel+'"].mod') != 'w') {
229 element = element.replace(expression, "_$1.");
230 elementIndexes = element.split('.');
231 subelement = 'cmi';
232 i = 1;
233 while ((i < elementIndexes.length) && (typeof eval(subelement) != "undefined")) {
234 subelement += '.'+elementIndexes[i++];
236 if (subelement == element) {
237 errorCode = "0";
238 return eval(element);
239 } else {
240 errorCode = "0"; // Need to check if it is the right errorCode
242 } else {
243 errorCode = eval('datamodel["'+elementmodel+'"].readerror');
245 } else {
246 childrenstr = '._children';
247 countstr = '._count';
248 if (elementmodel.substr(elementmodel.length-childrenstr.length,elementmodel.length) == childrenstr) {
249 parentmodel = elementmodel.substr(0,elementmodel.length-childrenstr.length);
250 if ((typeof eval('datamodel["'+parentmodel+'"]')) != "undefined") {
251 errorCode = "202";
252 } else {
253 errorCode = "201";
255 } else if (elementmodel.substr(elementmodel.length-countstr.length,elementmodel.length) == countstr) {
256 parentmodel = elementmodel.substr(0,elementmodel.length-countstr.length);
257 if ((typeof eval('datamodel["'+parentmodel+'"]')) != "undefined") {
258 errorCode = "203";
259 } else {
260 errorCode = "201";
262 } else {
263 errorCode = "201";
266 } else {
267 errorCode = "201";
269 } else {
270 errorCode = "301";
272 return "";
275 function LMSSetValue (element,value) {
276 errorCode = "0";
277 if (Initialized) {
278 if (element != "") {
279 expression = new RegExp(CMIIndex,'g');
280 elementmodel = element.replace(expression,'.n.');
281 if ((typeof eval('datamodel["'+elementmodel+'"]')) != "undefined") {
282 if (eval('datamodel["'+elementmodel+'"].mod') != 'r') {
283 expression = new RegExp(eval('datamodel["'+elementmodel+'"].format'));
284 value = value+'';
285 matches = value.match(expression);
286 if (matches != null) {
287 //Create dynamic data model element
288 if (element != elementmodel) {
289 elementIndexes = element.split('.');
290 subelement = 'cmi';
291 for (i=1;i < elementIndexes.length-1;i++) {
292 elementIndex = elementIndexes[i];
293 if (elementIndexes[i+1].match(/^\d+$/)) {
294 if ((typeof eval(subelement+'.'+elementIndex)) == "undefined") {
295 eval(subelement+'.'+elementIndex+' = new Object();');
296 eval(subelement+'.'+elementIndex+'._count = 0;');
298 if (elementIndexes[i+1] == eval(subelement+'.'+elementIndex+'._count')) {
299 eval(subelement+'.'+elementIndex+'._count++;');
301 if (elementIndexes[i+1] > eval(subelement+'.'+elementIndex+'._count')) {
302 errorCode = "201";
304 subelement = subelement.concat('.'+elementIndex+'_'+elementIndexes[i+1]);
305 i++;
306 } else {
307 subelement = subelement.concat('.'+elementIndex);
309 if ((typeof eval(subelement)) == "undefined") {
310 eval(subelement+' = new Object();');
311 if (subelement.substr(0,14) == 'cmi.objectives') {
312 eval(subelement+'.score = new Object();');
313 eval(subelement+'.score._children = score_children;');
314 eval(subelement+'.score.raw = "";');
315 eval(subelement+'.score.min = "";');
316 eval(subelement+'.score.max = "";');
318 if (subelement.substr(0,16) == 'cmi.interactions') {
319 eval(subelement+'.objectives = new Object();');
320 eval(subelement+'.objectives._count = 0;');
321 eval(subelement+'.correct_responses = new Object();');
322 eval(subelement+'.correct_responses._count = 0;');
326 element = subelement.concat('.'+elementIndexes[elementIndexes.length-1]);
328 //Store data
329 if (errorCode == "0") {
330 if ((typeof eval('datamodel["'+elementmodel+'"].range')) != "undefined") {
331 range = eval('datamodel["'+elementmodel+'"].range');
332 ranges = range.split('#');
333 value = value*1.0;
334 if ((value >= ranges[0]) && (value <= ranges[1])) {
335 eval(element+'="'+value+'";');
336 errorCode = "0";
337 return "true";
338 } else {
339 errorCode = eval('datamodel["'+elementmodel+'"].writeerror');
341 } else {
342 if (element == 'cmi.comments') {
343 eval(element+'+="'+value+'";');
344 } else {
345 eval(element+'="'+value+'";');
347 errorCode = "0";
348 return "true";
351 } else {
352 errorCode = eval('datamodel["'+elementmodel+'"].writeerror');
354 } else {
355 errorCode = eval('datamodel["'+elementmodel+'"].writeerror');
357 } else {
358 errorCode = "201"
360 } else {
361 errorCode = "201";
363 } else {
364 errorCode = "301";
366 return "false";
369 function LMSCommit (param) {
370 errorCode = "0";
371 if (param == "") {
372 if (Initialized) {
373 result = StoreData(cmi,false);
374 return "true";
375 } else {
376 errorCode = "301";
378 } else {
379 errorCode = "201";
381 return "false";
384 function LMSGetLastError () {
385 return errorCode;
388 function LMSGetErrorString (param) {
389 if (param != "") {
390 var errorString = new Array();
391 errorString["0"] = "No error";
392 errorString["101"] = "General exception";
393 errorString["201"] = "Invalid argument error";
394 errorString["202"] = "Element cannot have children";
395 errorString["203"] = "Element not an array - cannot have count";
396 errorString["301"] = "Not initialized";
397 errorString["401"] = "Not implemented error";
398 errorString["402"] = "Invalid set value, element is a keyword";
399 errorString["403"] = "Element is read only";
400 errorString["404"] = "Element is write only";
401 errorString["405"] = "Incorrect data type";
402 return errorString[param];
403 } else {
404 return "";
408 function LMSGetDiagnostic (param) {
409 if (param == "") {
410 param = errorCode;
412 return param;
415 function AddTime (first, second) {
416 var sFirst = first.split(":");
417 var sSecond = second.split(":");
418 var cFirst = sFirst[2].split(".");
419 var cSecond = sSecond[2].split(".");
420 var change = 0;
422 FirstCents = 0; //Cents
423 if (cFirst.length > 1) {
424 FirstCents = parseInt(cFirst[1],10);
426 SecondCents = 0;
427 if (cSecond.length > 1) {
428 SecondCents = parseInt(cSecond[1],10);
430 var cents = FirstCents + SecondCents;
431 change = Math.floor(cents / 100);
432 cents = cents - (change * 100);
433 if (Math.floor(cents) < 10) {
434 cents = "0" + cents.toString();
437 var secs = parseInt(cFirst[0],10)+parseInt(cSecond[0],10)+change; //Seconds
438 change = Math.floor(secs / 60);
439 secs = secs - (change * 60);
440 if (Math.floor(secs) < 10) {
441 secs = "0" + secs.toString();
444 mins = parseInt(sFirst[1],10)+parseInt(sSecond[1],10)+change; //Minutes
445 change = Math.floor(mins / 60);
446 mins = mins - (change * 60);
447 if (mins < 10) {
448 mins = "0" + mins.toString();
451 hours = parseInt(sFirst[0],10)+parseInt(sSecond[0],10)+change; //Hours
452 if (hours < 10) {
453 hours = "0" + hours.toString();
456 if (cents != '0') {
457 return hours + ":" + mins + ":" + secs + '.' + cents;
458 } else {
459 return hours + ":" + mins + ":" + secs;
463 function TotalTime() {
464 total_time = AddTime(cmi.core.total_time, cmi.core.session_time);
465 return '&'+underscore('cmi.core.total_time')+'='+escape(total_time);
468 function CollectData(data,parent) {
469 var datastring = '';
470 for (property in data) {
471 if (typeof data[property] == 'object') {
472 datastring += CollectData(data[property],parent+'.'+property);
473 } else {
474 element = parent+'.'+property;
475 expression = new RegExp(CMIIndex,'g');
476 elementmodel = element.replace(expression,'.n.');
477 if ((typeof eval('datamodel["'+elementmodel+'"]')) != "undefined") {
478 if (eval('datamodel["'+elementmodel+'"].mod') != 'r') {
479 elementstring = '&'+underscore(element)+'='+escape(data[property]);
480 if ((typeof eval('datamodel["'+elementmodel+'"].defaultvalue')) != "undefined") {
481 if (eval('datamodel["'+elementmodel+'"].defaultvalue') != data[property]) {
482 datastring += elementstring;
484 } else {
485 datastring += elementstring;
491 return datastring;
494 function StoreData(data,storetotaltime) {
495 if (storetotaltime) {
496 if (cmi.core.lesson_mode == 'normal') {
497 if (cmi.core.credit == 'credit') {
498 cmi.core.lesson_status = 'completed';
499 if (cmi.student_data.mastery_score != '') {
500 if (cmi.core.score.raw >= cmi.student_data.mastery_score) {
501 cmi.core.lesson_status = 'passed';
502 } else {
503 cmi.core.lesson_status = 'failed';
508 if (cmi.core.lesson_mode == 'browse') {
509 if (datamodel['cmi.core.lesson_status'].defaultvalue == '') {
510 cmi.core.lesson_status = 'browsed';
513 datastring = CollectData(data,'cmi');
514 datastring += TotalTime();
515 } else {
516 datastring = CollectData(data,'cmi');
518 //popupwin(datastring);
519 var myRequest = NewHttpReq();
520 result = DoRequest(myRequest,"<?php p($CFG->wwwroot) ?>/mod/scorm/datamodel.php","id=<?php p($id) ?>&sesskey=<?php p($USER->sesskey) ?>"+datastring);
521 results = result.split('\n');
522 errorCode = results[1];
523 return results[0];
526 this.LMSInitialize = LMSInitialize;
527 this.LMSFinish = LMSFinish;
528 this.LMSGetValue = LMSGetValue;
529 this.LMSSetValue = LMSSetValue;
530 this.LMSCommit = LMSCommit;
531 this.LMSGetLastError = LMSGetLastError;
532 this.LMSGetErrorString = LMSGetErrorString;
533 this.LMSGetDiagnostic = LMSGetDiagnostic;
536 var API = new AICCapi();