Merge branch 'MDL-45339-master' of git://github.com/xow/moodle
[moodle.git] / mod / scorm / datamodels / scorm_13.js
1 // This file is part of Moodle - http://moodle.org/
2 //
3 // Moodle is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
7 //
8 // Moodle is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16 // Used need to debug cmi content (if you uncomment this, you must comment the definition inside SCORMapi1_3)
17 //var cmi = new Object();
19 //
20 // SCORM 1.3 API Implementation
21 //
22 function SCORMapi1_3(def, cmiobj, cmiint, cmicommentsuser, cmicommentslms, scormdebugging, scormauto, scormid, cfgwwwroot, sesskey, scoid, attempt, viewmode, cmid, currentorg) {
24     var prerequrl = cfgwwwroot + "/mod/scorm/prereqs.php?a="+scormid+"&scoid="+scoid+"&attempt="+attempt+"&mode="+viewmode+"&currentorg="+currentorg+"&sesskey="+sesskey;
25     var datamodelurl = cfgwwwroot + "/mod/scorm/datamodel.php";
26     var datamodelurlparams = "id="+cmid+"&a="+scormid+"&sesskey="+sesskey+"&attempt="+attempt+"&scoid="+scoid;
28     // Standard Data Type Definition
30     // language key has to be checked for language dependent strings
31     var validLanguages = {'aa':'aa', 'ab':'ab', 'ae':'ae', 'af':'af', 'ak':'ak', 'am':'am', 'an':'an', 'ar':'ar', 'as':'as', 'av':'av', 'ay':'ay', 'az':'az',
32                           'ba':'ba', 'be':'be', 'bg':'bg', 'bh':'bh', 'bi':'bi', 'bm':'bm', 'bn':'bn', 'bo':'bo', 'br':'br', 'bs':'bs',
33                           'ca':'ca', 'ce':'ce', 'ch':'ch', 'co':'co', 'cr':'cr', 'cs':'cs', 'cu':'cu', 'cv':'cv', 'cy':'cy',
34                           'da':'da', 'de':'de', 'dv':'dv', 'dz':'dz', 'ee':'ee', 'el':'el', 'en':'en', 'eo':'eo', 'es':'es', 'et':'et', 'eu':'eu',
35                           'fa':'fa', 'ff':'ff', 'fi':'fi', 'fj':'fj', 'fo':'fo', 'fr':'fr', 'fy':'fy', 'ga':'ga', 'gd':'gd', 'gl':'gl', 'gn':'gn', 'gu':'gu', 'gv':'gv',
36                           'ha':'ha', 'he':'he', 'hi':'hi', 'ho':'ho', 'hr':'hr', 'ht':'ht', 'hu':'hu', 'hy':'hy', 'hz':'hz',
37                           'ia':'ia', 'id':'id', 'ie':'ie', 'ig':'ig', 'ii':'ii', 'ik':'ik', 'io':'io', 'is':'is', 'it':'it', 'iu':'iu',
38                           'ja':'ja', 'jv':'jv', 'ka':'ka', 'kg':'kg', 'ki':'ki', 'kj':'kj', 'kk':'kk', 'kl':'kl', 'km':'km', 'kn':'kn', 'ko':'ko', 'kr':'kr', 'ks':'ks', 'ku':'ku', 'kv':'kv', 'kw':'kw', 'ky':'ky',
39                           'la':'la', 'lb':'lb', 'lg':'lg', 'li':'li', 'ln':'ln', 'lo':'lo', 'lt':'lt', 'lu':'lu', 'lv':'lv',
40                           'mg':'mg', 'mh':'mh', 'mi':'mi', 'mk':'mk', 'ml':'ml', 'mn':'mn', 'mo':'mo', 'mr':'mr', 'ms':'ms', 'mt':'mt', 'my':'my',
41                           'na':'na', 'nb':'nb', 'nd':'nd', 'ne':'ne', 'ng':'ng', 'nl':'nl', 'nn':'nn', 'no':'no', 'nr':'nr', 'nv':'nv', 'ny':'ny',
42                           'oc':'oc', 'oj':'oj', 'om':'om', 'or':'or', 'os':'os', 'pa':'pa', 'pi':'pi', 'pl':'pl', 'ps':'ps', 'pt':'pt',
43                           'qu':'qu', 'rm':'rm', 'rn':'rn', 'ro':'ro', 'ru':'ru', 'rw':'rw',
44                           'sa':'sa', 'sc':'sc', 'sd':'sd', 'se':'se', 'sg':'sg', 'sh':'sh', 'si':'si', 'sk':'sk', 'sl':'sl', 'sm':'sm', 'sn':'sn', 'so':'so', 'sq':'sq', 'sr':'sr', 'ss':'ss', 'st':'st', 'su':'su', 'sv':'sv', 'sw':'sw',
45                           'ta':'ta', 'te':'te', 'tg':'tg', 'th':'th', 'ti':'ti', 'tk':'tk', 'tl':'tl', 'tn':'tn', 'to':'to', 'tr':'tr', 'ts':'ts', 'tt':'tt', 'tw':'tw', 'ty':'ty',
46                           'ug':'ug', 'uk':'uk', 'ur':'ur', 'uz':'uz', 've':'ve', 'vi':'vi', 'vo':'vo',
47                           'wa':'wa', 'wo':'wo', 'xh':'xh', 'yi':'yi', 'yo':'yo', 'za':'za', 'zh':'zh', 'zu':'zu',
48                           'aar':'aar', 'abk':'abk', 'ave':'ave', 'afr':'afr', 'aka':'aka', 'amh':'amh', 'arg':'arg', 'ara':'ara', 'asm':'asm', 'ava':'ava', 'aym':'aym', 'aze':'aze',
49                           'bak':'bak', 'bel':'bel', 'bul':'bul', 'bih':'bih', 'bis':'bis', 'bam':'bam', 'ben':'ben', 'tib':'tib', 'bod':'bod', 'bre':'bre', 'bos':'bos',
50                           'cat':'cat', 'che':'che', 'cha':'cha', 'cos':'cos', 'cre':'cre', 'cze':'cze', 'ces':'ces', 'chu':'chu', 'chv':'chv', 'wel':'wel', 'cym':'cym',
51                           'dan':'dan', 'ger':'ger', 'deu':'deu', 'div':'div', 'dzo':'dzo', 'ewe':'ewe', 'gre':'gre', 'ell':'ell', 'eng':'eng', 'epo':'epo', 'spa':'spa', 'est':'est', 'baq':'baq', 'eus':'eus', 'per':'per',
52                           'fas':'fas', 'ful':'ful', 'fin':'fin', 'fij':'fij', 'fao':'fao', 'fre':'fre', 'fra':'fra', 'fry':'fry', 'gle':'gle', 'gla':'gla', 'glg':'glg', 'grn':'grn', 'guj':'guj', 'glv':'glv',
53                           'hau':'hau', 'heb':'heb', 'hin':'hin', 'hmo':'hmo', 'hrv':'hrv', 'hat':'hat', 'hun':'hun', 'arm':'arm', 'hye':'hye', 'her':'her',
54                           'ina':'ina', 'ind':'ind', 'ile':'ile', 'ibo':'ibo', 'iii':'iii', 'ipk':'ipk', 'ido':'ido', 'ice':'ice', 'isl':'isl', 'ita':'ita', 'iku':'iku',
55                           'jpn':'jpn', 'jav':'jav', 'geo':'geo', 'kat':'kat', 'kon':'kon', 'kik':'kik', 'kua':'kua', 'kaz':'kaz', 'kal':'kal', 'khm':'khm', 'kan':'kan', 'kor':'kor', 'kau':'kau', 'kas':'kas', 'kur':'kur', 'kom':'kom', 'cor':'cor', 'kir':'kir',
56                           'lat':'lat', 'ltz':'ltz', 'lug':'lug', 'lim':'lim', 'lin':'lin', 'lao':'lao', 'lit':'lit', 'lub':'lub', 'lav':'lav',
57                           'mlg':'mlg', 'mah':'mah', 'mao':'mao', 'mri':'mri', 'mac':'mac', 'mkd':'mkd', 'mal':'mal', 'mon':'mon', 'mol':'mol', 'mar':'mar', 'may':'may', 'msa':'msa', 'mlt':'mlt', 'bur':'bur', 'mya':'mya',
58                           'nau':'nau', 'nob':'nob', 'nde':'nde', 'nep':'nep', 'ndo':'ndo', 'dut':'dut', 'nld':'nld', 'nno':'nno', 'nor':'nor', 'nbl':'nbl', 'nav':'nav', 'nya':'nya',
59                           'oci':'oci', 'oji':'oji', 'orm':'orm', 'ori':'ori', 'oss':'oss', 'pan':'pan', 'pli':'pli', 'pol':'pol', 'pus':'pus', 'por':'por', 'que':'que',
60                           'roh':'roh', 'run':'run', 'rum':'rum', 'ron':'ron', 'rus':'rus', 'kin':'kin', 'san':'san', 'srd':'srd', 'snd':'snd', 'sme':'sme', 'sag':'sag', 'slo':'slo', 'sin':'sin', 'slk':'slk', 'slv':'slv', 'smo':'smo', 'sna':'sna', 'som':'som', 'alb':'alb', 'sqi':'sqi', 'srp':'srp', 'ssw':'ssw', 'sot':'sot', 'sun':'sun', 'swe':'swe', 'swa':'swa',
61                           'tam':'tam', 'tel':'tel', 'tgk':'tgk', 'tha':'tha', 'tir':'tir', 'tuk':'tuk', 'tgl':'tgl', 'tsn':'tsn', 'ton':'ton', 'tur':'tur', 'tso':'tso', 'tat':'tat', 'twi':'twi', 'tah':'tah',
62                           'uig':'uig', 'ukr':'ukr', 'urd':'urd', 'uzb':'uzb', 'ven':'ven', 'vie':'vie', 'vol':'vol', 'wln':'wln', 'wol':'wol', 'xho':'xho', 'yid':'yid', 'yor':'yor', 'zha':'zha', 'chi':'chi', 'zho':'zho', 'zul':'zul'};
64     var CMIString200 = '^[\\u0000-\\uFFFF]{0,200}$';
65     var CMIString250 = '^[\\u0000-\\uFFFF]{0,250}$';
66     var CMIString1000 = '^[\\u0000-\\uFFFF]{0,1000}$';
67     var CMIString4000 = '^[\\u0000-\\uFFFF]{0,4000}$';
68     var CMIString64000 = '^[\\u0000-\\uFFFF]{0,64000}$';
69     var CMILang = '^([a-zA-Z]{2,3}|i|x)(\-[a-zA-Z0-9\-]{2,8})?$|^$';
70     var CMILangString250 = '^(\{lang=([a-zA-Z]{2,3}|i|x)(\-[a-zA-Z0-9\-]{2,8})?\})?([^\{].{0,250}$)?';
71     var CMILangcr = '^((\{lang=([a-zA-Z]{2,3}|i|x)?(\-[a-zA-Z0-9\-]{2,8})?\}))(.*?)$';
72     var CMILangString250cr = '^((\{lang=([a-zA-Z]{2,3}|i|x)?(\-[a-zA-Z0-9\-]{2,8})?\})?(.{0,250})?)?$';
73     var CMILangString4000 = '^(\{lang=([a-zA-Z]{2,3}|i|x)(\-[a-zA-Z0-9\-]{2,8})?\})?([^\{].{0,4000}$)?';
74     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})?)?)?)?)?)?)?)?$';
75     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))))?$';
76     var CMIInteger = '^\\d+$';
77     var CMISInteger = '^-?([0-9]+)$';
78     var CMIDecimal = '^-?([0-9]{1,5})(\\.[0-9]{1,18})?$';
79     var CMIIdentifier = '^\\S{1,250}[a-zA-Z0-9]$';
80     var CMIShortIdentifier = '^[\\w\.]{1,250}$';
81     var CMILongIdentifier = '^(?:(?!urn:)\\S{1,4000}|urn:[A-Za-z0-9-]{1,31}:\\S{1,4000})$';
82     var CMIFeedback = '^.*$'; // This must be redefined
83     var CMIIndex = '[._](\\d+).';
84     var CMIIndexStore = '.N(\\d+).';
85     // Vocabulary Data Type Definition
86     var CMICStatus = '^completed$|^incomplete$|^not attempted$|^unknown$';
87     var CMISStatus = '^passed$|^failed$|^unknown$';
88     var CMIExit = '^time-out$|^suspend$|^logout$|^normal$|^$';
89     var CMIType = '^true-false$|^choice$|^(long-)?fill-in$|^matching$|^performance$|^sequencing$|^likert$|^numeric$|^other$';
90     var CMIResult = '^correct$|^incorrect$|^unanticipated$|^neutral$|^-?([0-9]{1,4})(\\.[0-9]{1,18})?$';
91     var NAVEvent = '^previous$|^continue$|^exit$|^exitAll$|^abandon$|^abandonAll$|^suspendAll$|^\{target=\\S{0,200}[a-zA-Z0-9]\}choice|jump$';
92     var NAVBoolean = '^unknown$|^true$|^false$';
93     var NAVTarget = '^previous$|^continue$|^choice.{target=\\S{0,200}[a-zA-Z0-9]}$'
94     // Children lists
95     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';
96     var comments_children = 'comment,timestamp,location';
97     var score_children = 'max,raw,scaled,min';
98     var objectives_children = 'progress_measure,completion_status,success_status,description,score,id';
99     var correct_responses_children = 'pattern';
100     var student_data_children = 'mastery_score,max_time_allowed,time_limit_action';
101     var student_preference_children = 'audio_level,audio_captioning,delivery_speed,language';
102     var interactions_children = 'id,type,objectives,timestamp,correct_responses,weighting,learner_response,result,latency,description';
103     // Data ranges
104     var scaled_range = '-1#1';
105     var audio_range = '0#*';
106     var speed_range = '0#*';
107     var text_range = '-1#1';
108     var progress_range = '0#1';
109     var learner_response = {
110         'true-false':{'format':'^true$|^false$', 'max':1, 'delimiter':'', 'unique':false},
111         'choice':{'format':CMIShortIdentifier, 'max':36, 'delimiter':'[,]', 'unique':true},
112         'fill-in':{'format':CMILangString250, 'max':10, 'delimiter':'[,]', 'unique':false},
113         'long-fill-in':{'format':CMILangString4000, 'max':1, 'delimiter':'', 'unique':false},
114         'matching':{'format':CMIShortIdentifier, 'format2':CMIShortIdentifier, 'max':36, 'delimiter':'[,]', 'delimiter2':'[.]', 'unique':false},
115         'performance':{'format':'^$|'+CMIShortIdentifier, 'format2':CMIDecimal+'|^$|'+CMIShortIdentifier, 'max':250, 'delimiter':'[,]', 'delimiter2':'[.]', 'unique':false},
116         'sequencing':{'format':CMIShortIdentifier, 'max':36, 'delimiter':'[,]', 'unique':false},
117         'likert':{'format':CMIShortIdentifier, 'max':1, 'delimiter':'', 'unique':false},
118         'numeric':{'format':CMIDecimal, 'max':1, 'delimiter':'', 'unique':false},
119         'other':{'format':CMIString4000, 'max':1, 'delimiter':'', 'unique':false}
120     }
122     var correct_responses = {
123         'true-false':{'pre':'', 'max':1, 'delimiter':'', 'unique':false, 'duplicate':false,
124                       'format':'^true$|^false$',
125                       'limit':1},
126         'choice':{'pre':'', 'max':36, 'delimiter':'[,]', 'unique':true, 'duplicate':false,
127                   'format':CMIShortIdentifier},
128 //        'fill-in':{'pre':'^(((\{case_matters=(true|false)\})(\{order_matters=(true|false)\})?)|((\{order_matters=(true|false)\})(\{case_matters=(true|false)\})?))(.*?)$',
129         'fill-in':{'pre':'',
130                    'max':10, 'delimiter':'[,]', 'unique':false, 'duplicate':false,
131                    'format':CMILangString250cr},
132         'long-fill-in':{'pre':'^(\{case_matters=(true|false)\})?', 'max':1, 'delimiter':'', 'unique':false, 'duplicate':true,
133                         'format':CMILangString4000},
134         'matching':{'pre':'', 'max':36, 'delimiter':'[,]', 'delimiter2':'[.]', 'unique':false, 'duplicate':false,
135                     'format':CMIShortIdentifier, 'format2':CMIShortIdentifier},
136         'performance':{'pre':'^(\{order_matters=(true|false)\})?',
137                        'max':250, 'delimiter':'[,]', 'delimiter2':'[.]', 'unique':false, 'duplicate':false,
138                        'format':'^$|'+CMIShortIdentifier, 'format2':CMIDecimal+'|^$|'+CMIShortIdentifier},
139         'sequencing':{'pre':'', 'max':36, 'delimiter':'[,]', 'unique':false, 'duplicate':false,
140                       'format':CMIShortIdentifier},
141         'likert':{'pre':'', 'max':1, 'delimiter':'', 'unique':false, 'duplicate':false,
142                   'format':CMIShortIdentifier,
143                   'limit':1},
144         'numeric':{'pre':'', 'max':2, 'delimiter':'[:]', 'unique':false, 'duplicate':false,
145                    'format':CMIDecimal,
146                    'limit':1},
147         'other':{'pre':'', 'max':1, 'delimiter':'', 'unique':false, 'duplicate':false,
148                  'format':CMIString4000,
149                  'limit':1}
150     }
152     // The SCORM 1.3 data model
153     var datamodel =  {
154         'cmi._children':{'defaultvalue':cmi_children, 'mod':'r'},
155         'cmi._version':{'defaultvalue':'1.0', 'mod':'r'},
156         'cmi.comments_from_learner._children':{'defaultvalue':comments_children, 'mod':'r'},
157         'cmi.comments_from_learner._count':{'mod':'r', 'defaultvalue':'0'},
158         'cmi.comments_from_learner.n.comment':{'format':CMILangString4000, 'mod':'rw'},
159         'cmi.comments_from_learner.n.location':{'format':CMIString250, 'mod':'rw'},
160         'cmi.comments_from_learner.n.timestamp':{'format':CMITime, 'mod':'rw'},
161         'cmi.comments_from_lms._children':{'defaultvalue':comments_children, 'mod':'r'},
162         'cmi.comments_from_lms._count':{'mod':'r', 'defaultvalue':'0'},
163         'cmi.comments_from_lms.n.comment':{'format':CMILangString4000, 'mod':'r'},
164         'cmi.comments_from_lms.n.location':{'format':CMIString250, 'mod':'r'},
165         'cmi.comments_from_lms.n.timestamp':{'format':CMITime, 'mod':'r'},
166         'cmi.completion_status':{'defaultvalue':def['cmi.completion_status'], 'format':CMICStatus, 'mod':'rw'},
167         'cmi.completion_threshold':{'defaultvalue':def['cmi.completion_threshold'], 'mod':'r'},
168         'cmi.credit':{'defaultvalue':def['cmi.credit'], 'mod':'r'},
169         'cmi.entry':{'defaultvalue':def['cmi.entry'], 'mod':'r'},
170         'cmi.exit':{'defaultvalue':def['cmi.exit'], 'format':CMIExit, 'mod':'w'},
171         'cmi.interactions._children':{'defaultvalue':interactions_children, 'mod':'r'},
172         'cmi.interactions._count':{'mod':'r', 'defaultvalue':'0'},
173         'cmi.interactions.n.id':{'pattern':CMIIndex, 'format':CMILongIdentifier, 'mod':'rw'},
174         'cmi.interactions.n.type':{'pattern':CMIIndex, 'format':CMIType, 'mod':'rw'},
175         'cmi.interactions.n.objectives._count':{'pattern':CMIIndex, 'mod':'r', 'defaultvalue':'0'},
176         'cmi.interactions.n.objectives.n.id':{'pattern':CMIIndex, 'format':CMILongIdentifier, 'mod':'rw'},
177         'cmi.interactions.n.timestamp':{'pattern':CMIIndex, 'format':CMITime, 'mod':'rw'},
178         'cmi.interactions.n.correct_responses._count':{'defaultvalue':'0', 'pattern':CMIIndex, 'mod':'r'},
179         'cmi.interactions.n.correct_responses.n.pattern':{'pattern':CMIIndex, 'format':'CMIFeedback', 'mod':'rw'},
180         'cmi.interactions.n.weighting':{'pattern':CMIIndex, 'format':CMIDecimal, 'mod':'rw'},
181         'cmi.interactions.n.learner_response':{'pattern':CMIIndex, 'format':'CMIFeedback', 'mod':'rw'},
182         'cmi.interactions.n.result':{'pattern':CMIIndex, 'format':CMIResult, 'mod':'rw'},
183         'cmi.interactions.n.latency':{'pattern':CMIIndex, 'format':CMITimespan, 'mod':'rw'},
184         'cmi.interactions.n.description':{'pattern':CMIIndex, 'format':CMILangString250, 'mod':'rw'},
185         'cmi.launch_data':{'defaultvalue':def['cmi.exit'], 'mod':'r'},
186         'cmi.learner_id':{'defaultvalue':def['cmi.learner_id'], 'mod':'r'},
187         'cmi.learner_name':{'defaultvalue':def['cmi.learner_name'], 'mod':'r'},
188         'cmi.learner_preference._children':{'defaultvalue':student_preference_children, 'mod':'r'},
189         'cmi.learner_preference.audio_level':{'defaultvalue':def['cmi.learner_preference.audio_level'], 'format':CMIDecimal, 'range':audio_range, 'mod':'rw'},
190         'cmi.learner_preference.language':{'defaultvalue':def['cmi.learner_preference.language'], 'format':CMILang, 'mod':'rw'},
191         'cmi.learner_preference.delivery_speed':{'defaultvalue':def['cmi.learner_preference.delivery_speed'], 'format':CMIDecimal, 'range':speed_range, 'mod':'rw'},
192         'cmi.learner_preference.audio_captioning':{'defaultvalue':def['cmi.learner_preference.audio_captioning'], 'format':CMISInteger, 'range':text_range, 'mod':'rw'},
193         'cmi.location':{'defaultvalue':def['cmi.location'], 'format':CMIString1000, 'mod':'rw'},
194         'cmi.max_time_allowed':{'defaultvalue':def['cmi.max_time_allowed'], 'mod':'r'},
195         'cmi.mode':{'defaultvalue':def['cmi.mode'], 'mod':'r'},
196         'cmi.objectives._children':{'defaultvalue':objectives_children, 'mod':'r'},
197         'cmi.objectives._count':{'mod':'r', 'defaultvalue':'0'},
198         'cmi.objectives.n.id':{'pattern':CMIIndex, 'format':CMILongIdentifier, 'mod':'rw'},
199         'cmi.objectives.n.score._children':{'defaultvalue':score_children, 'pattern':CMIIndex, 'mod':'r'},
200         'cmi.objectives.n.score.scaled':{'defaultvalue':null, 'pattern':CMIIndex, 'format':CMIDecimal, 'range':scaled_range, 'mod':'rw'},
201         'cmi.objectives.n.score.raw':{'defaultvalue':null, 'pattern':CMIIndex, 'format':CMIDecimal, 'mod':'rw'},
202         'cmi.objectives.n.score.min':{'defaultvalue':null, 'pattern':CMIIndex, 'format':CMIDecimal, 'mod':'rw'},
203         'cmi.objectives.n.score.max':{'defaultvalue':null, 'pattern':CMIIndex, 'format':CMIDecimal, 'mod':'rw'},
204         'cmi.objectives.n.success_status':{'defaultvalue':'unknown', 'pattern':CMIIndex, 'format':CMISStatus, 'mod':'rw'},
205         'cmi.objectives.n.completion_status':{'defaultvalue':'unknown', 'pattern':CMIIndex, 'format':CMICStatus, 'mod':'rw'},
206         'cmi.objectives.n.progress_measure':{'defaultvalue':null, 'format':CMIDecimal, 'range':progress_range, 'mod':'rw'},
207         'cmi.objectives.n.description':{'pattern':CMIIndex, 'format':CMILangString250, 'mod':'rw'},
208         'cmi.progress_measure':{'defaultvalue':def['cmi.progress_measure'], 'format':CMIDecimal, 'range':progress_range, 'mod':'rw'},
209         'cmi.scaled_passing_score':{'defaultvalue':def['cmi.scaled_passing_score'], 'format':CMIDecimal, 'range':scaled_range, 'mod':'r'},
210         'cmi.score._children':{'defaultvalue':score_children, 'mod':'r'},
211         'cmi.score.scaled':{'defaultvalue':def['cmi.score.scaled'], 'format':CMIDecimal, 'range':scaled_range, 'mod':'rw'},
212         'cmi.score.raw':{'defaultvalue':def['cmi.score.raw'], 'format':CMIDecimal, 'mod':'rw'},
213         'cmi.score.min':{'defaultvalue':def['cmi.score.min'], 'format':CMIDecimal, 'mod':'rw'},
214         'cmi.score.max':{'defaultvalue':def['cmi.score.max'], 'format':CMIDecimal, 'mod':'rw'},
215         'cmi.session_time':{'format':CMITimespan, 'mod':'w', 'defaultvalue':'PT0H0M0S'},
216         'cmi.success_status':{'defaultvalue':def['cmi.success_status'], 'format':CMISStatus, 'mod':'rw'},
217         'cmi.suspend_data':{'defaultvalue':def['cmi.suspend_data'], 'format':CMIString64000, 'mod':'rw'},
218         'cmi.time_limit_action':{'defaultvalue':def['cmi.time_limit_action'], 'mod':'r'},
219         'cmi.total_time':{'defaultvalue':def['cmi.total_time'], 'mod':'r'},
220         'adl.nav.request':{'defaultvalue':'_none_', 'format':NAVEvent, 'mod':'rw'}
221     };
222     //
223     // Datamodel inizialization
224     //
225         var cmi = new Object();
226         cmi.comments_from_learner = new Object();
227         cmi.comments_from_learner._count = 0;
228         cmi.comments_from_lms = new Object();
229         cmi.comments_from_lms._count = 0;
230         cmi.interactions = new Object();
231         cmi.interactions._count = 0;
232         cmi.learner_preference = new Object();
233         cmi.objectives = new Object();
234         cmi.objectives._count = 0;
235         cmi.score = new Object();
237     // Navigation Object
238     var adl = new Object();
239         adl.nav = new Object();
240         adl.nav.request_valid = new Array();
242     for (element in datamodel) {
243         if (element.match(/\.n\./) == null) {
244             if ((typeof eval('datamodel["'+element+'"].defaultvalue')) != 'undefined') {
245                 eval(element+' = datamodel["'+element+'"].defaultvalue;');
246             } else {
247                 eval(element+' = "";');
248             }
249         }
250     }
252     eval(cmiobj);
253     eval(cmiint);
254     eval(cmicommentsuser);
255     eval(cmicommentslms);
257     if (cmi.completion_status == '') {
258         cmi.completion_status = 'not attempted';
259     }
261     //
262     // API Methods definition
263     //
264     var Initialized = false;
265     var Terminated = false;
266     var diagnostic = "";
267     var errorCode = "0";
269     function Initialize (param) {
270         errorCode = "0";
271         if (param == "") {
272             if ((!Initialized) && (!Terminated)) {
273                 Initialized = true;
274                 errorCode = "0";
275                 if (scormdebugging) {
276                     LogAPICall("Initialize", param, "", errorCode);
277                 }
278                 return "true";
279             } else {
280                 if (Initialized) {
281                     errorCode = "103";
282                 } else {
283                     errorCode = "104";
284                 }
285             }
286         } else {
287             errorCode = "201";
288         }
289         if (scormdebugging) {
290             LogAPICall("Initialize", param, "", errorCode);
291         }
292         return "false";
293     }
295     function Terminate (param) {
296         errorCode = "0";
297         if (param == "") {
298             if ((Initialized) && (!Terminated)) {
299                 var AJAXResult = StoreData(cmi,true);
300                 if (scormdebugging) {
301                     LogAPICall("Terminate", "AJAXResult", AJAXResult, 0);
302                 }
303                 result = ('true' == AJAXResult) ? 'true' : 'false';
304                 errorCode = ('true' == result)? '0' : '101'; // General exception for any AJAX fault
305                 if (scormdebugging) {
306                     LogAPICall("Terminate", "result", result, errorCode);
307                 }
308                 if ('true' == result) {
309                     Initialized = false;
310                     Terminated = true;
311                     if (adl.nav.request != '_none_') {
312                         switch (adl.nav.request) {
313                             case 'continue':
314                                 setTimeout('mod_scorm_launch_next_sco();',500);
315                             break;
316                             case 'previous':
317                                 setTimeout('mod_scorm_launch_prev_sco();',500);
318                             break;
319                             case 'choice':
320                             break;
321                             case 'exit':
322                             break;
323                             case 'exitAll':
324                             break;
325                             case 'abandon':
326                             break;
327                             case 'abandonAll':
328                             break;
329                         }
330                     } else {
331                         if (scormauto == 1) {
332                             setTimeout('mod_scorm_launch_next_sco();',500);
333                         }
334                     }
335                     // trigger TOC update
336                     var callback = M.mod_scorm.connectPrereqCallback;
337                     YUI().use('io-base', function(Y) {
338                         Y.on('io:complete', callback.success, Y);
339                         Y.io(prerequrl);
340                     });
341                 } else {
342                     diagnostic = "Failure calling the Terminate remote callback: the server replied with HTTP Status " + AJAXResult;
343                 }
344                 return result;
345             } else {
346                 if (Terminated) {
347                     errorCode = "113";
348                 } else {
349                     errorCode = "112";
350                 }
351             }
352         } else {
353             errorCode = "201";
354         }
355         if (scormdebugging) {
356             LogAPICall("Terminate", param, "", errorCode);
357         }
358         return "false";
359     }
361     function GetValue (element) {
362         errorCode = "0";
363         diagnostic = "";
364         if ((Initialized) && (!Terminated)) {
365             if (element !="") {
366                 var expression = new RegExp(CMIIndex,'g');
367                 var elementmodel = String(element).replace(expression,'.n.');
368                 if ((typeof eval('datamodel["'+elementmodel+'"]')) != "undefined") {
369                     if (eval('datamodel["'+elementmodel+'"].mod') != 'w') {
371                         element = String(element).replace(/\.(\d+)\./, ".N$1.");
372                         element = element.replace(/\.(\d+)\./, ".N$1.");
374                         var elementIndexes = element.split('.');
375                         var subelement = element.substr(0,3);
376                         var i = 1;
377                         while ((i < elementIndexes.length) && (typeof eval(subelement) != "undefined")) {
378                             subelement += '.'+elementIndexes[i++];
379                         }
381                         if (subelement == element) {
383                             if ((typeof eval(subelement) != "undefined") && (eval(subelement) != null)) {
384                                 errorCode = "0";
385                                 if (scormdebugging) {
386                                     LogAPICall("GetValue", element, eval(element), 0);
387                                 }
388                                 return eval(element);
389                             } else {
390                                 errorCode = "403";
391                             }
392                         } else {
393                             errorCode = "301";
394                         }
395                     } else {
396                         //errorCode = eval('datamodel["'+elementmodel+'"].readerror');
397                         errorCode = "405";
398                     }
399                 } else {
400                     var childrenstr = '._children';
401                     var countstr = '._count';
402                     var parentmodel = '';
403                     if (elementmodel.substr(elementmodel.length-childrenstr.length,elementmodel.length) == childrenstr) {
404                         parentmodel = elementmodel.substr(0,elementmodel.length-childrenstr.length);
405                         if ((typeof eval('datamodel["'+parentmodel+'"]')) != "undefined") {
406                             errorCode = "301";
407                             diagnostic = "Data Model Element Does Not Have Children";
408                         } else {
409                             errorCode = "401";
410                         }
411                     } else if (elementmodel.substr(elementmodel.length-countstr.length,elementmodel.length) == countstr) {
412                         parentmodel = elementmodel.substr(0,elementmodel.length-countstr.length);
413                         if ((typeof eval('datamodel["'+parentmodel+'"]')) != "undefined") {
414                             errorCode = "301";
415                             diagnostic = "Data Model Element Cannot Have Count";
416                         } else {
417                             errorCode = "401";
418                         }
419                     } else {
420                         parentmodel = 'adl.nav.request_valid.';
421                         if (element.substr(0,parentmodel.length) == parentmodel) {
422                             if (element.substr(parentmodel.length).match(NAVTarget) == null) {
423                                 errorCode = "301";
424                             } else {
425                                 if (adl.nav.request == element.substr(parentmodel.length)) {
426                                     return "true";
427                                 } else if (adl.nav.request == '_none_') {
428                                     return "unknown";
429                                 } else {
430                                     return "false";
431                                 }
432                             }
433                         } else {
434                             errorCode = "401";
435                         }
436                     }
437                 }
438             } else {
439                 errorCode = "301";
440             }
441         } else {
442             if (Terminated) {
443                 errorCode = "123";
444             } else {
445                 errorCode = "122";
446             }
447         }
448         if (scormdebugging) {
449             LogAPICall("GetValue", element, "", errorCode);
450         }
451         return "";
452     }
454     function SetValue (element,value) {
455         errorCode = "0";
456         diagnostic = "";
457         if ((Initialized) && (!Terminated)) {
458             if (element != "") {
459                 var expression = new RegExp(CMIIndex,'g');
460                 var elementmodel = String(element).replace(expression,'.n.');
461                 if ((typeof eval('datamodel["'+elementmodel+'"]')) != "undefined") {
462                     if (eval('datamodel["'+elementmodel+'"].mod') != 'r') {
463                         if (eval('datamodel["'+elementmodel+'"].format') != 'CMIFeedback') {
464                             expression = new RegExp(eval('datamodel["'+elementmodel+'"].format'));
465                         } else {
466                             // cmi.interactions.n.type depending format accept everything at this stage
467                             expression = new RegExp(CMIFeedback);
468                         }
469                         value = value+'';
470                         var matches = value.match(expression);
471                         if ((matches != null) && ((matches.join('').length > 0) || (value.length == 0))) {
472                             // Value match dataelement format
474                             if (element != elementmodel) {
475                                 //This is a dynamic datamodel element
477                                 var elementIndexes = element.split('.');
478                                 var subelement = 'cmi';
479                                 var parentelement = 'cmi';
480                                 for (var i=1;(i < elementIndexes.length-1) && (errorCode=="0");i++) {
481                                     var elementIndex = elementIndexes[i];
482                                     if (elementIndexes[i+1].match(/^\d+$/)) {
483                                         if ((parseInt(elementIndexes[i+1]) > 0) && (elementIndexes[i+1].charAt(0) == 0)) {
484                                             // Index has a leading 0 (zero), this is not a number
485                                             errorCode = "351";
486                                         }
487                                         parentelement = subelement+'.'+elementIndex;
488                                         if ((typeof eval(parentelement) == "undefined") || (typeof eval(parentelement+'._count') == "undefined")) {
489                                             errorCode="408";
490                                         } else {
491                                             if (elementIndexes[i+1] > eval(parentelement+'._count')) {
492                                                 errorCode = "351";
493                                                 diagnostic = "Data Model Element Collection Set Out Of Order";
494                                             }
495                                             subelement = subelement.concat('.'+elementIndex+'.N'+elementIndexes[i+1]);
496                                             i++;
498                                             if (((typeof eval(subelement)) == "undefined") && (i < elementIndexes.length-2)) {
499                                                 errorCode="408";
500                                             }
501                                         }
502                                     } else {
503                                         subelement = subelement.concat('.'+elementIndex);
504                                     }
505                                 }
507                                 if (errorCode == "0") {
508                                     // Till now it's a real datamodel element
510                                     element = subelement.concat('.'+elementIndexes[elementIndexes.length-1]);
512                                     if ((typeof eval(subelement)) == "undefined") {
513                                         switch (elementmodel) {
514                                             case 'cmi.objectives.n.id':
515                                                 if (!duplicatedID(element,parentelement,value)) {
516                                                     if (elementIndexes[elementIndexes.length-2] == eval(parentelement+'._count')) {
517                                                         eval(parentelement+'._count++;');
518                                                         eval(subelement+' = new Object();');
519                                                         var subobject = eval(subelement);
520                                                         subobject.success_status = datamodel["cmi.objectives.n.success_status"].defaultvalue;
521                                                         subobject.completion_status = datamodel["cmi.objectives.n.completion_status"].defaultvalue;
522                                                         subobject.progress_measure = datamodel["cmi.objectives.n.progress_measure"].defaultvalue;
523                                                         subobject.score = new Object();
524                                                         subobject.score._children = score_children;
525                                                         subobject.score.scaled = datamodel["cmi.objectives.n.score.scaled"].defaultvalue;
526                                                         subobject.score.raw = datamodel["cmi.objectives.n.score.raw"].defaultvalue;
527                                                         subobject.score.min = datamodel["cmi.objectives.n.score.min"].defaultvalue;
528                                                         subobject.score.max = datamodel["cmi.objectives.n.score.max"].defaultvalue;
529                                                     }
530                                                 } else {
531                                                     errorCode="351";
532                                                     diagnostic = "Data Model Element ID Already Exists";
533                                                 }
534                                             break;
535                                             case 'cmi.interactions.n.id':
536                                                 if (elementIndexes[elementIndexes.length-2] == eval(parentelement+'._count')) {
537                                                     eval(parentelement+'._count++;');
538                                                     eval(subelement+' = new Object();');
539                                                     var subobject = eval(subelement);
540                                                     subobject.objectives = new Object();
541                                                     subobject.objectives._count = 0;
542                                                 }
543                                             break;
544                                             case 'cmi.interactions.n.objectives.n.id':
545                                                 if (typeof eval(parentelement) != "undefined") {
546                                                     if (!duplicatedID(element,parentelement,value)) {
547                                                         if (elementIndexes[elementIndexes.length-2] == eval(parentelement+'._count')) {
548                                                             eval(parentelement+'._count++;');
549                                                             eval(subelement+' = new Object();');
550                                                         }
551                                                     } else {
552                                                         errorCode="351";
553                                                         diagnostic = "Data Model Element ID Already Exists";
554                                                     }
555                                                 } else {
556                                                     errorCode="408";
557                                                 }
558                                             break;
559                                             case 'cmi.interactions.n.correct_responses.n.pattern':
560                                                 if (typeof eval(parentelement) != "undefined") {
561                                                     // Use cmi.interactions.n.type value to check the right dataelement format
562                                                     if (elementIndexes[elementIndexes.length-2] == eval(parentelement+'._count')) {
563                                                         var interactiontype = eval(String(parentelement).replace('correct_responses','type'));
564                                                         var interactioncount = eval(parentelement+'._count');
565                                                         // trap duplicate values, which is not allowed for type choice
566                                                         if (interactiontype == 'choice') {
567                                                             for (var i=0; (i < interactioncount) && (errorCode=="0"); i++) {
568                                                                if (eval(parentelement+'.N'+i+'.pattern') == value) {
569                                                                    errorCode = "351";
570                                                                }
571                                                             }
572                                                         }
573                                                         if ((typeof correct_responses[interactiontype].limit == 'undefined') ||
574                                                             (eval(parentelement+'._count') < correct_responses[interactiontype].limit)) {
575                                                             var nodes = new Array();
576                                                             if (correct_responses[interactiontype].delimiter != '') {
577                                                                 nodes = value.split(correct_responses[interactiontype].delimiter);
578                                                             } else {
579                                                                 nodes[0] = value;
580                                                             }
581                                                             if ((nodes.length > 0) && (nodes.length <= correct_responses[interactiontype].max)) {
582                                                                 errorCode = CRcheckValueNodes (element, interactiontype, nodes, value, errorCode);
583                                                             } else if (nodes.length > correct_responses[interactiontype].max) {
584                                                                 errorCode = "351";
585                                                                 diagnostic = "Data Model Element Pattern Too Long";
586                                                             }
587                                                             if ((errorCode == "0") && ((correct_responses[interactiontype].duplicate == false) ||
588                                                                (!duplicatedPA(element,parentelement,value))) || (errorCode == "0" && value == "")) {
589                                                                eval(parentelement+'._count++;');
590                                                                eval(subelement+' = new Object();');
591                                                             } else {
592                                                                 if (errorCode == "0") {
593                                                                     errorCode="351";
594                                                                     diagnostic = "Data Model Element Pattern Already Exists";
595                                                                 }
596                                                             }
597                                                         } else {
598                                                             errorCode="351";
599                                                             diagnostic = "Data Model Element Collection Limit Reached";
600                                                         }
601                                                     } else {
602                                                         errorCode="351";
603                                                         diagnostic = "Data Model Element Collection Set Out Of Order";
604                                                     }
605                                                 } else {
606                                                     errorCode="408";
607                                                 }
608                                             break;
609                                             default:
610                                                 if ((parentelement != 'cmi.objectives') && (parentelement != 'cmi.interactions') && (typeof eval(parentelement) != "undefined")) {
611                                                     if (elementIndexes[elementIndexes.length-2] == eval(parentelement+'._count')) {
612                                                         eval(parentelement+'._count++;');
613                                                         eval(subelement+' = new Object();');
614                                                     } else {
615                                                         errorCode="351";
616                                                         diagnostic = "Data Model Element Collection Set Out Of Order";
617                                                     }
618                                                 } else {
619                                                     errorCode="408";
620                                                 }
621                                             break;
622                                         }
623                                     } else {
624                                         switch (elementmodel) {
625                                             case 'cmi.objectives.n.id':
626                                                 if (eval(element) != value) {
627                                                     errorCode = "351";
628                                                     diagnostic = "Write Once Violation";
629                                                 }
630                                             break;
631                                             case 'cmi.interactions.n.objectives.n.id':
632                                                 if (duplicatedID(element,parentelement,value)) {
633                                                     errorCode = "351";
634                                                     diagnostic = "Data Model Element ID Already Exists";
635                                                 }
636                                             break;
637                                             case 'cmi.interactions.n.type':
638                                                 var subobject = eval(subelement);
639                                                 subobject.correct_responses = new Object();
640                                                 subobject.correct_responses._count = 0;
641                                             break;
642                                             case 'cmi.interactions.n.learner_response':
643                                                 if (typeof eval(subelement+'.type') == "undefined") {
644                                                     errorCode="408";
645                                                 } else {
646                                                     // Use cmi.interactions.n.type value to check the right dataelement format
647                                                     interactiontype = eval(subelement+'.type');
648                                                     var nodes = new Array();
649                                                     if (learner_response[interactiontype].delimiter != '') {
650                                                         nodes = value.split(learner_response[interactiontype].delimiter);
651                                                     } else {
652                                                         nodes[0] = value;
653                                                     }
654                                                     if ((nodes.length > 0) && (nodes.length <= learner_response[interactiontype].max)) {
655                                                         expression = new RegExp(learner_response[interactiontype].format);
656                                                         for (var i=0; (i < nodes.length) && (errorCode=="0"); i++) {
657                                                             if (typeof learner_response[interactiontype].delimiter2 != 'undefined') {
658                                                                 values = nodes[i].split(learner_response[interactiontype].delimiter2);
659                                                                 if (values.length == 2) {
660                                                                     matches = values[0].match(expression);
661                                                                     if (matches == null) {
662                                                                         errorCode = "406";
663                                                                     } else {
664                                                                         var expression2 = new RegExp(learner_response[interactiontype].format2);
665                                                                         matches = values[1].match(expression2);
666                                                                         if (matches == null) {
667                                                                             errorCode = "406";
668                                                                         }
669                                                                     }
670                                                                 } else {
671                                                                     errorCode = "406";
672                                                                 }
673                                                             } else {
674                                                                 matches = nodes[i].match(expression);
675                                                                 if (matches == null) {
676                                                                     errorCode = "406";
677                                                                 } else {
678                                                                     if ((nodes[i] != '') && (learner_response[interactiontype].unique)) {
679                                                                         for (var j=0; (j<i) && (errorCode=="0"); j++) {
680                                                                             if (nodes[i] == nodes[j]) {
681                                                                                 errorCode = "406";
682                                                                             }
683                                                                         }
684                                                                     }
685                                                                 }
686                                                             }
687                                                         }
688                                                     } else if (nodes.length > learner_response[interactiontype].max) {
689                                                         errorCode = "351";
690                                                         diagnostic = "Data Model Element Pattern Too Long";
691                                                     }
692                                                 }
693                                              break;
694                                          case 'cmi.interactions.n.correct_responses.n.pattern':
695                                            subel= subelement.split('.');
696                                              subel1= 'cmi.interactions.'+subel[2];
698                                                 if (typeof eval(subel1+'.type') == "undefined") {
699                                                     errorCode="408";
700                                                 } else {
701                                                     // Use cmi.interactions.n.type value to check the right //dataelement format
702                                                     var interactiontype = eval(subel1+'.type');
703                                                     var interactioncount = eval(parentelement+'._count');
704                                                     // trap duplicate values, which is not allowed for type choice
705                                                     if (interactiontype == 'choice') {
706                                                         for (var i=0; (i < interactioncount) && (errorCode=="0"); i++) {
707                                                            if (eval(parentelement+'.N'+i+'.pattern') == value) {
708                                                                errorCode = "351";
709                                                            }
710                                                         }
711                                                     }
712                                                     var nodes = new Array();
713                                                     if (correct_responses[interactiontype].delimiter != '') {
714                                                         nodes = value.split(correct_responses[interactiontype].delimiter);
715                                                     } else {
716                                                         nodes[0] = value;
717                                                     }
719                                                     if ((nodes.length > 0) && (nodes.length <= correct_responses[interactiontype].max)) {
720                                                         errorCode = CRcheckValueNodes (element, interactiontype, nodes, value, errorCode);
721                                                     } else if (nodes.length > correct_responses[interactiontype].max) {
722                                                         errorCode = "351";
723                                                         diagnostic = "Data Model Element Pattern Too Long";
724                                                     }
725                                                 }
726                                              break;
727                                         }
728                                     }
729                                 }
730                             }
731                             //Store data
732                             if (errorCode == "0") {
734                                 if ((typeof eval('datamodel["'+elementmodel+'"].range')) != "undefined") {
735                                     range = eval('datamodel["'+elementmodel+'"].range');
736                                     ranges = range.split('#');
737                                     value = value*1.0;
738                                     if (value >= ranges[0]) {
739                                         if ((ranges[1] == '*') || (value <= ranges[1])) {
740                                             eval(element+'=value;');
741                                             errorCode = "0";
742                                             if (scormdebugging) {
743                                                 LogAPICall("SetValue", element, value, errorCode);
744                                             }
745                                             return "true";
746                                         } else {
747                                             errorCode = '407';
748                                         }
749                                     } else {
750                                         errorCode = '407';
751                                     }
752                                 } else {
753                                     eval(element+'=value;');
754                                     errorCode = "0";
755                                     if (scormdebugging) {
756                                         LogAPICall("SetValue", element, value, errorCode);
757                                     }
758                                     return "true";
759                                 }
760                             }
761                         } else {
762                             errorCode = "406";
763                         }
764                     } else {
765                         errorCode = "404";
766                     }
767                 } else {
768                     errorCode = "401"
769                 }
770             } else {
771                 errorCode = "351";
772             }
773         } else {
774             if (Terminated) {
775                 errorCode = "133";
776             } else {
777                 errorCode = "132";
778             }
779         }
780         if (scormdebugging) {
781             LogAPICall("SetValue", element, value, errorCode);
782         }
783         return "false";
784     }
787     function CRremovePrefixes (node) {
788         // check for prefixes lang, case, order
789         // case and then order
790         var seenOrder = false;
791         var seenCase = false;
792         var seenLang = false;
793         var errorCode = "0";
794         while (matches = node.match('^(\{(lang|case_matters|order_matters)=([^\}]+)\})')) {
795             switch (matches[2]) {
796                 case 'lang':
797                     // check for language prefix on each node
798                     langmatches = node.match(CMILangcr);
799                     if (langmatches != null) {
800                         lang = langmatches[3];
801                         // check that language string definition is valid
802                         if (lang.length > 0 && lang != undefined) {
803                             if (validLanguages[lang.toLowerCase()] == undefined) {
804                                 errorCode = "406";
805                             }
806                         }
807                     }
808                     seenLang = true;
809                 break;
811                 case 'case_matters':
812                     // check for correct case answer
813                     if (! seenLang && ! seenOrder && ! seenCase) {
814                         if (matches[3] != 'true' && matches[3] != 'false') {
815                             errorCode = "406";
816                         }
817                     }
818                     seenCase = true;
819                 break;
821                 case 'order_matters':
822                     // check for correct case answer
823                     if (! seenCase && ! seenLang && ! seenOrder) {
824                         if (matches[3] != 'true' && matches[3] != 'false') {
825                             errorCode = "406";
826                         }
827                     }
828                     seenOrder = true;
829                 break;
831                 default:
832                 break;
833             }
834             node = node.substr(matches[1].length);
835         }
836         return {'errorCode': errorCode, 'node': node};
837     }
840     function CRcheckValueNodes(element, interactiontype, nodes, value, errorCode) {
841         expression = new RegExp(correct_responses[interactiontype].format);
842         for (var i=0; (i < nodes.length) && (errorCode=="0"); i++) {
843             if (interactiontype.match('^(fill-in|long-fill-in|matching|performance|sequencing)$')) {
844                 result = CRremovePrefixes(nodes[i]);
845                 errorCode = result.errorCode;
846                 nodes[i] = result.node;
847             }
849             // check for prefix on each node
850             if (correct_responses[interactiontype].pre != '') {
851                 matches = nodes[i].match(correct_responses[interactiontype].pre);
852                 if (matches != null) {
853                     nodes[i] = nodes[i].substr(matches[1].length);
854                 }
855             }
857             if (correct_responses[interactiontype].delimiter2 != undefined) {
858                 values = nodes[i].split(correct_responses[interactiontype].delimiter2);
859                 if (values.length == 2) {
860                     matches = values[0].match(expression);
861                     if (matches == null) {
862                         errorCode = "406";
863                     } else {
864                         var expression2 = new RegExp(correct_responses[interactiontype].format2);
865                         matches = values[1].match(expression2);
866                         if (matches == null) {
867                             errorCode = "406";
868                         }
869                     }
870                 } else {
871                      errorCode = "406";
872                 }
873             } else {
874                 matches = nodes[i].match(expression);
875                 //if ((matches == null) || (matches.join('').length == 0)) {
876                 if ((matches == null && value != "")||(matches == null && interactiontype=="true-false")){
877                     errorCode = "406";
878                 } else {
879                     // numeric range - left must be <= right
880                     if (interactiontype == 'numeric' && nodes.length > 1) {
881                         if (parseFloat(nodes[0]) > parseFloat(nodes[1])) {
882                             errorCode = "406";
883                         }
884                     } else {
885                         if ((nodes[i] != '') && (correct_responses[interactiontype].unique)) {
886                             for (var j=0; (j < i) && (errorCode=="0"); j++) {
887                                 if (nodes[i] == nodes[j]) {
888                                     errorCode = "406";
889                                 }
890                             }
891                         }
892                     }
893                 }
894             }
895         } // end of for each nodes
896         return errorCode;
897     }
900     function Commit (param) {
901         errorCode = "0";
902         if (param == "") {
903             if ((Initialized) && (!Terminated)) {
904                 var AJAXResult = StoreData(cmi,false);
905                 if (scormdebugging) {
906                     LogAPICall("Commit", "AJAXResult", AJAXResult, 0);
907                 }
908                 var result = ('true' == AJAXResult) ? 'true' : 'false';
909                 errorCode = ('true' == result)? '0' : '101'; // General exception for any AJAX fault
910                 if (scormdebugging) {
911                     LogAPICall("Commit", "result", result, errorCode);
912                 }
913                 if ('false' == result) {
914                     diagnostic = "Failure calling the Commit remote callback: the server replied with HTTP Status " + AJAXResult;
915                 }
916                 return result;
917             } else {
918                 if (Terminated) {
919                     errorCode = "143";
920                 } else {
921                     errorCode = "142";
922                 }
923             }
924         } else {
925             errorCode = "201";
926         }
927         if (scormdebugging) {
928             LogAPICall("Commit", param, "", errorCode);
929         }
930         return "false";
931     }
933     function GetLastError () {
934         if (scormdebugging) {
935             LogAPICall("GetLastError", "", "", errorCode);
936         }
937         return errorCode;
938     }
940     function GetErrorString (param) {
941         if (param != "") {
942             var errorString = "";
943             switch(param) {
944                 case "0":
945                     errorString = "No error";
946                 break;
947                 case "101":
948                     errorString = "General exception";
949                 break;
950                 case "102":
951                     errorString = "General Inizialization Failure";
952                 break;
953                 case "103":
954                     errorString = "Already Initialized";
955                 break;
956                 case "104":
957                     errorString = "Content Instance Terminated";
958                 break;
959                 case "111":
960                     errorString = "General Termination Failure";
961                 break;
962                 case "112":
963                     errorString = "Termination Before Inizialization";
964                 break;
965                 case "113":
966                     errorString = "Termination After Termination";
967                 break;
968                 case "122":
969                     errorString = "Retrieve Data Before Initialization";
970                 break;
971                 case "123":
972                     errorString = "Retrieve Data After Termination";
973                 break;
974                 case "132":
975                     errorString = "Store Data Before Inizialization";
976                 break;
977                 case "133":
978                     errorString = "Store Data After Termination";
979                 break;
980                 case "142":
981                     errorString = "Commit Before Inizialization";
982                 break;
983                 case "143":
984                     errorString = "Commit After Termination";
985                 break;
986                 case "201":
987                     errorString = "General Argument Error";
988                 break;
989                 case "301":
990                     errorString = "General Get Failure";
991                 break;
992                 case "351":
993                     errorString = "General Set Failure";
994                 break;
995                 case "391":
996                     errorString = "General Commit Failure";
997                 break;
998                 case "401":
999                     errorString = "Undefinited Data Model";
1000                 break;
1001                 case "402":
1002                     errorString = "Unimplemented Data Model Element";
1003                 break;
1004                 case "403":
1005                     errorString = "Data Model Element Value Not Initialized";
1006                 break;
1007                 case "404":
1008                     errorString = "Data Model Element Is Read Only";
1009                 break;
1010                 case "405":
1011                     errorString = "Data Model Element Is Write Only";
1012                 break;
1013                 case "406":
1014                     errorString = "Data Model Element Type Mismatch";
1015                 break;
1016                 case "407":
1017                     errorString = "Data Model Element Value Out Of Range";
1018                 break;
1019                 case "408":
1020                     errorString = "Data Model Dependency Not Established";
1021                 break;
1022             }
1023             if (scormdebugging) {
1024                 LogAPICall("GetErrorString", param,  errorString, 0);
1025             }
1026             return errorString;
1027         } else {
1028             if (scormdebugging) {
1029                 LogAPICall("GetErrorString", param,  "No error string found!", 0);
1030             }
1031             return "";
1032         }
1033     }
1035     function GetDiagnostic (param) {
1036         if (diagnostic != "") {
1037             if (scormdebugging) {
1038                 LogAPICall("GetDiagnostic", param, diagnostic, 0);
1039             }
1040             return diagnostic;
1041         }
1042         if (scormdebugging) {
1043             LogAPICall("GetDiagnostic", param, param, 0);
1044         }
1045         return param;
1046     }
1048     function duplicatedID (element, parent, value) {
1049         var found = false;
1050         var elements = eval(parent+'._count');
1051         for (var n=0;(n < elements) && (!found);n++) {
1052             if ((parent+'.N'+n+'.id' != element) && (eval(parent+'.N'+n+'.id') == value)) {
1053                 found = true;
1054             }
1055         }
1056         return found;
1057     }
1059     function duplicatedPA (element, parent, value) {
1060         var found = false;
1061         var elements = eval(parent+'._count');
1062         for (var n=0;(n < elements) && (!found);n++) {
1063             if ((parent+'.N'+n+'.pattern' != element) && (eval(parent+'.N'+n+'.pattern') == value)) {
1064                 found = true;
1065             }
1066         }
1067         return found;
1068     }
1070     function getElementModel(element) {
1071         if (typeof datamodel[element] != "undefined") {
1072             return element;
1073         } else {
1074             var expression = new RegExp(CMIIndex,'g');
1075             var elementmodel = String(element).replace(expression,'.n.');
1076             if (typeof datamodel[elementmodel] != "undefined") {
1077                 return elementmodel;
1078             }
1079         }
1080         return false;
1081     }
1083     function AddTime (first, second) {
1084         var timestring = 'P';
1085         var matchexpr = /^P((\d+)Y)?((\d+)M)?((\d+)D)?(T((\d+)H)?((\d+)M)?((\d+(\.\d{1,2})?)S)?)?$/;
1086         var firstarray = first.match(matchexpr);
1087         var secondarray = second.match(matchexpr);
1088         if ((firstarray != null) && (secondarray != null)) {
1089             var firstsecs=0;
1090             if(parseFloat(firstarray[13],10)>0){ firstsecs=parseFloat(firstarray[13],10); }
1091             var secondsecs=0;
1092             if(parseFloat(secondarray[13],10)>0){ secondsecs=parseFloat(secondarray[13],10); }
1093             var secs = firstsecs+secondsecs;  //Seconds
1094             var change = Math.floor(secs/60);
1095             secs = Math.round((secs-(change*60))*100)/100;
1096             var firstmins=0;
1097             if(parseInt(firstarray[11],10)>0){ firstmins=parseInt(firstarray[11],10); }
1098             var secondmins=0;
1099             if(parseInt(secondarray[11],10)>0){ secondmins=parseInt(secondarray[11],10); }
1100             var mins = firstmins+secondmins+change;   //Minutes
1101             change = Math.floor(mins / 60);
1102             mins = Math.round(mins-(change*60));
1103             var firsthours=0;
1104             if(parseInt(firstarray[9],10)>0){ firsthours=parseInt(firstarray[9],10); }
1105             var secondhours=0;
1106             if(parseInt(secondarray[9],10)>0){ secondhours=parseInt(secondarray[9],10); }
1107             var hours = firsthours+secondhours+change; //Hours
1108             change = Math.floor(hours/24);
1109             hours = Math.round(hours-(change*24));
1110             var firstdays=0;
1111             if(parseInt(firstarray[6],10)>0){ firstdays=parseInt(firstarray[6],10); }
1112             var seconddays=0;
1113             if(parseInt(secondarray[6],10)>0){ firstdays=parseInt(secondarray[6],10); }
1114             var days = Math.round(firstdays+seconddays+change); // Days
1115             var firstmonths=0;
1116             if(parseInt(firstarray[4],10)>0){ firstmonths=parseInt(firstarray[4],10); }
1117             var secondmonths=0;
1118             if(parseInt(secondarray[4],10)>0){ secondmonths=parseInt(secondarray[4],10); }
1119             var months = Math.round(firstmonths+secondmonths);
1120             var firstyears=0;
1121             if(parseInt(firstarray[2],10)>0){ firstyears=parseInt(firstarray[2],10); }
1122             var secondyears=0;
1123             if(parseInt(secondarray[2],10)>0){ secondyears=parseInt(secondarray[2],10); }
1124             var years = Math.round(firstyears+secondyears);
1125         }
1126         if (years > 0) {
1127             timestring += years + 'Y';
1128         }
1129         if (months > 0) {
1130             timestring += months + 'M';
1131         }
1132         if (days > 0) {
1133             timestring += days + 'D';
1134         }
1135         if ((hours > 0) || (mins > 0) || (secs > 0)) {
1136             timestring += 'T';
1137             if (hours > 0) {
1138                 timestring += hours + 'H';
1139             }
1140             if (mins > 0) {
1141                 timestring += mins + 'M';
1142             }
1143             if (secs > 0) {
1144                 timestring += secs + 'S';
1145             }
1146         }
1147         return timestring;
1148     }
1150     function TotalTime() {
1151         var total_time = AddTime(cmi.total_time, cmi.session_time);
1152         return '&'+underscore('cmi.total_time')+'='+encodeURIComponent(total_time);
1153     }
1155     function CollectData(data,parent) {
1156         var datastring = '';
1157         for (property in data) {
1158             if (typeof data[property] == 'object') {
1159                 datastring += CollectData(data[property],parent+'.'+property);
1160             } else {
1161                 var element = parent+'.'+property;
1162                 var expression = new RegExp(CMIIndexStore,'g');
1163                 var elementmodel = String(element).replace(expression,'.n.');
1164                 if ((typeof eval('datamodel["'+elementmodel+'"]')) != "undefined") {
1165                     if (eval('datamodel["'+elementmodel+'"].mod') != 'r') {
1166                         var elementstring = '&'+underscore(element)+'='+encodeURIComponent(data[property]);
1167                         if ((typeof eval('datamodel["'+elementmodel+'"].defaultvalue')) != "undefined") {
1168                             if (eval('datamodel["'+elementmodel+'"].defaultvalue') != data[property] || eval('typeof(datamodel["'+elementmodel+'"].defaultvalue)') != typeof(data[property])) {
1169                                 datastring += elementstring;
1170                             }
1171                         } else {
1172                             datastring += elementstring;
1173                         }
1174                     }
1175                 }
1176             }
1177         }
1178         return datastring;
1179     }
1181     function StoreData(data,storetotaltime) {
1182         var datastring = '';
1183         if (storetotaltime) {
1184             if (cmi.mode == 'normal') {
1185                 if (cmi.credit == 'credit') {
1186                     if ((cmi.completion_threshold != null) && (cmi.progress_measure != null)) {
1187                         if (cmi.progress_measure >= cmi.completion_threshold) {
1188                             cmi.completion_status = 'completed';
1189                         } else {
1190                             cmi.completion_status = 'incomplete';
1191                         }
1192                     }
1193                     if ((cmi.scaled_passed_score != null) && (cmi.score.scaled != '')) {
1194                         if (cmi.score.scaled >= cmi.scaled_passed_score) {
1195                             cmi.success_status = 'passed';
1196                         } else {
1197                             cmi.success_status = 'failed';
1198                         }
1199                     }
1200                 }
1201             }
1202             datastring += TotalTime();
1203         }
1204         datastring += CollectData(data,'cmi');
1205         var element = 'adl.nav.request';
1206         var navrequest = eval(element) != datamodel[element].defaultvalue ? '&'+underscore(element)+'='+encodeURIComponent(eval(element)) : '';
1207         datastring += navrequest;
1209         var myRequest = NewHttpReq();
1210         result = DoRequest(myRequest,datamodelurl,datamodelurlparams+datastring);
1212         var results = String(result).split('\n');
1213         if ((results.length > 2) && (navrequest != '')) {
1214             eval(results[2]);
1215         }
1216         errorCode = results[1];
1217         return results[0];
1218     }
1220     this.Initialize = Initialize;
1221     this.Terminate = Terminate;
1222     this.GetValue = GetValue;
1223     this.SetValue = SetValue;
1224     this.Commit = Commit;
1225     this.GetLastError = GetLastError;
1226     this.GetErrorString = GetErrorString;
1227     this.GetDiagnostic = GetDiagnostic;
1228     this.version = '1.0';
1231 M.scorm_api = {};
1233 M.scorm_api.init = function(Y, def, cmiobj, cmiint, cmicommentsuser, cmicommentslms, scormdebugging, scormauto, scormid, cfgwwwroot, sesskey, scoid, attempt, viewmode, cmid, currentorg) {
1234     window.API_1484_11 = new SCORMapi1_3(def, cmiobj, cmiint, cmicommentsuser, cmicommentslms, scormdebugging, scormauto, scormid, cfgwwwroot, sesskey, scoid, attempt, viewmode, cmid, currentorg);