1 // This file is part of Moodle - http://moodle.org/
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.
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.
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();
20 // SCORM 1.3 API Implementation
22 function SCORMapi1_3(def, cmiobj, cmiint, cmicommentsuser, cmicommentslms, scormdebugging, scormauto, scormid, cfgwwwroot, sesskey, scoid, attempt, viewmode, cmid, currentorg, autocommit) {
24 var prerequrl = cfgwwwroot + "/mod/scorm/prereqs.php?a=" + scormid + "&scoid=" + scoid + "&attempt=" + attempt + "&mode=" + viewmode + "¤torg=" + 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]}$'
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';
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}
122 var correct_responses = {
123 'true-false':{'max':1, 'delimiter':'', 'unique':false, 'duplicate':false,
124 'format':'^true$|^false$',
126 'choice':{'max':36, 'delimiter':'[,]', 'unique':true, 'duplicate':false,
127 'format':CMIShortIdentifier},
128 'fill-in':{'max':10, 'delimiter':'[,]', 'unique':false, 'duplicate':false,
129 'format':CMILangString250cr},
130 'long-fill-in':{'max':1, 'delimiter':'', 'unique':false, 'duplicate':true,
131 'format':CMILangString4000},
132 'matching':{'max':36, 'delimiter':'[,]', 'delimiter2':'[.]', 'unique':false, 'duplicate':false,
133 'format':CMIShortIdentifier, 'format2':CMIShortIdentifier},
134 'performance':{'max':250, 'delimiter':'[,]', 'delimiter2':'[.]', 'unique':false, 'duplicate':false,
135 'format':'^$|' + CMIShortIdentifier, 'format2':CMIDecimal + '|^$|' + CMIShortIdentifier},
136 'sequencing':{'max':36, 'delimiter':'[,]', 'unique':false, 'duplicate':false,
137 'format':CMIShortIdentifier},
138 'likert':{'max':1, 'delimiter':'', 'unique':false, 'duplicate':false,
139 'format':CMIShortIdentifier,
141 'numeric':{'max':2, 'delimiter':'[:]', 'unique':false, 'duplicate':false,
144 'other':{'max':1, 'delimiter':'', 'unique':false, 'duplicate':false,
145 'format':CMIString4000,
149 // The SCORM 1.3 data model
150 // Set up data model for each sco
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[scoid]['cmi.completion_status'], 'format':CMICStatus, 'mod':'rw'},
167 'cmi.completion_threshold':{'defaultvalue':def[scoid]['cmi.completion_threshold'], 'mod':'r'},
168 'cmi.credit':{'defaultvalue':def[scoid]['cmi.credit'], 'mod':'r'},
169 'cmi.entry':{'defaultvalue':def[scoid]['cmi.entry'], 'mod':'r'},
170 'cmi.exit':{'defaultvalue':def[scoid]['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[scoid]['cmi.launch_data'], 'mod':'r'},
186 'cmi.learner_id':{'defaultvalue':def[scoid]['cmi.learner_id'], 'mod':'r'},
187 'cmi.learner_name':{'defaultvalue':def[scoid]['cmi.learner_name'], 'mod':'r'},
188 'cmi.learner_preference._children':{'defaultvalue':student_preference_children, 'mod':'r'},
189 'cmi.learner_preference.audio_level':{'defaultvalue':def[scoid]['cmi.learner_preference.audio_level'], 'format':CMIDecimal, 'range':audio_range, 'mod':'rw'},
190 'cmi.learner_preference.language':{'defaultvalue':def[scoid]['cmi.learner_preference.language'], 'format':CMILang, 'mod':'rw'},
191 'cmi.learner_preference.delivery_speed':{'defaultvalue':def[scoid]['cmi.learner_preference.delivery_speed'], 'format':CMIDecimal, 'range':speed_range, 'mod':'rw'},
192 'cmi.learner_preference.audio_captioning':{'defaultvalue':def[scoid]['cmi.learner_preference.audio_captioning'], 'format':CMISInteger, 'range':text_range, 'mod':'rw'},
193 'cmi.location':{'defaultvalue':def[scoid]['cmi.location'], 'format':CMIString1000, 'mod':'rw'},
194 'cmi.max_time_allowed':{'defaultvalue':def[scoid]['cmi.max_time_allowed'], 'mod':'r'},
195 'cmi.mode':{'defaultvalue':def[scoid]['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[scoid]['cmi.progress_measure'], 'format':CMIDecimal, 'range':progress_range, 'mod':'rw'},
209 'cmi.scaled_passing_score':{'defaultvalue':def[scoid]['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[scoid]['cmi.score.scaled'], 'format':CMIDecimal, 'range':scaled_range, 'mod':'rw'},
212 'cmi.score.raw':{'defaultvalue':def[scoid]['cmi.score.raw'], 'format':CMIDecimal, 'mod':'rw'},
213 'cmi.score.min':{'defaultvalue':def[scoid]['cmi.score.min'], 'format':CMIDecimal, 'mod':'rw'},
214 'cmi.score.max':{'defaultvalue':def[scoid]['cmi.score.max'], 'format':CMIDecimal, 'mod':'rw'},
215 'cmi.session_time':{'format':CMITimespan, 'mod':'w', 'defaultvalue':'PT0H0M0S'},
216 'cmi.success_status':{'defaultvalue':def[scoid]['cmi.success_status'], 'format':CMISStatus, 'mod':'rw'},
217 'cmi.suspend_data':{'defaultvalue':def[scoid]['cmi.suspend_data'], 'format':CMIString64000, 'mod':'rw'},
218 'cmi.time_limit_action':{'defaultvalue':def[scoid]['cmi.time_limit_action'], 'mod':'r'},
219 'cmi.total_time':{'defaultvalue':def[scoid]['cmi.total_time'], 'mod':'r'},
220 'adl.nav.request':{'defaultvalue':'_none_', 'format':NAVEvent, 'mod':'rw'}
225 function initdatamodel(scoid){
227 prerequrl = cfgwwwroot + "/mod/scorm/prereqs.php?a=" + scormid + "&scoid=" + scoid + "&attempt=" + attempt + "&mode=" + viewmode + "¤torg=" + currentorg + "&sesskey=" + sesskey;
228 datamodelurlparams = "id=" + cmid + "&a=" + scormid + "&sesskey=" + sesskey + "&attempt=" + attempt + "&scoid=" + scoid;
231 // Datamodel inizialization
234 cmi.comments_from_learner = new Object();
235 cmi.comments_from_learner._count = 0;
236 cmi.comments_from_lms = new Object();
237 cmi.comments_from_lms._count = 0;
238 cmi.interactions = new Object();
239 cmi.interactions._count = 0;
240 cmi.learner_preference = new Object();
241 cmi.objectives = new Object();
242 cmi.objectives._count = 0;
243 cmi.score = new Object();
247 adl.nav = new Object();
248 adl.nav.request_valid = new Array();
250 for (element in datamodel[scoid]) {
251 if (element.match(/\.n\./) == null) {
252 if (typeof datamodel[scoid][element].defaultvalue != 'undefined') {
253 eval(element + ' = datamodel["' + scoid + '"]["' + element + '"].defaultvalue;');
255 eval(element + ' = "";');
262 eval(cmicommentsuser[scoid]);
263 eval(cmicommentslms[scoid]);
265 if (cmi.completion_status == '') {
266 cmi.completion_status = 'not attempted';
271 // API Methods definition
273 var Initialized = false;
274 var Terminated = false;
278 function Initialize (param) {
279 scoid = scorm_current_node ? scorm_current_node.scoid : scoid;
280 initdatamodel(scoid);
284 if ((!Initialized) && (!Terminated)) {
287 if (scormdebugging) {
288 LogAPICall("Initialize", param, "", errorCode);
301 if (scormdebugging) {
302 LogAPICall("Initialize", param, "", errorCode);
307 function Terminate (param) {
310 if ((Initialized) && (!Terminated)) {
311 var AJAXResult = StoreData(cmi,true);
312 if (scormdebugging) {
313 LogAPICall("Terminate", "AJAXResult", AJAXResult, 0);
315 result = ('true' == AJAXResult) ? 'true' : 'false';
316 errorCode = ('true' == result) ? '0' : '101'; // General exception for any AJAX fault.
317 if (scormdebugging) {
318 LogAPICall("Terminate", "result", result, errorCode);
320 if ('true' == result) {
323 if (adl.nav.request != '_none_') {
324 switch (adl.nav.request) {
326 setTimeout('mod_scorm_launch_next_sco();',500);
329 setTimeout('mod_scorm_launch_prev_sco();',500);
343 if (scormauto == 1) {
344 setTimeout('mod_scorm_launch_next_sco();',500);
347 // trigger TOC update
348 var callback = M.mod_scorm.connectPrereqCallback;
349 YUI().use('io-base', function(Y) {
350 Y.on('io:complete', callback.success, Y);
354 diagnostic = "Failure calling the Terminate remote callback: the server replied with HTTP Status " + AJAXResult;
367 if (scormdebugging) {
368 LogAPICall("Terminate", param, "", errorCode);
373 function GetValue (element) {
376 if ((Initialized) && (!Terminated)) {
378 var expression = new RegExp(CMIIndex,'g');
379 var elementmodel = String(element).replace(expression,'.n.');
380 if (typeof datamodel[scoid][elementmodel] != "undefined") {
381 if (datamodel[scoid][elementmodel].mod != 'w') {
383 element = String(element).replace(/\.(\d+)\./, ".N$1.");
384 element = element.replace(/\.(\d+)\./, ".N$1.");
386 var elementIndexes = element.split('.');
387 var subelement = element.substr(0,3);
389 while ((i < elementIndexes.length) && (typeof eval(subelement) != "undefined")) {
390 subelement += '.' + elementIndexes[i++];
393 if (subelement == element) {
395 if ((typeof eval(subelement) != "undefined") && (eval(subelement) != null)) {
397 if (scormdebugging) {
398 LogAPICall("GetValue", element, eval(element), 0);
400 return eval(element);
408 //errorCode = eval('datamodel["' + scoid + '"]["' + elementmodel + '"].readerror');
412 var childrenstr = '._children';
413 var countstr = '._count';
414 var parentmodel = '';
415 if (elementmodel.substr(elementmodel.length - childrenstr.length,elementmodel.length) == childrenstr) {
416 parentmodel = elementmodel.substr(0,elementmodel.length - childrenstr.length);
417 if (datamodel[scoid][parentmodel] != "undefined") {
419 diagnostic = "Data Model Element Does Not Have Children";
423 } else if (elementmodel.substr(elementmodel.length - countstr.length,elementmodel.length) == countstr) {
424 parentmodel = elementmodel.substr(0,elementmodel.length - countstr.length);
425 if (typeof datamodel[scoid][parentmodel] != "undefined") {
427 diagnostic = "Data Model Element Cannot Have Count";
432 parentmodel = 'adl.nav.request_valid.';
433 if (element.substr(0,parentmodel.length) == parentmodel) {
434 if (element.substr(parentmodel.length).match(NAVTarget) == null) {
437 if (adl.nav.request == element.substr(parentmodel.length)) {
439 } else if (adl.nav.request == '_none_') {
460 if (scormdebugging) {
461 LogAPICall("GetValue", element, "", errorCode);
466 function SetValue (element,value) {
469 if ((Initialized) && (!Terminated)) {
471 var expression = new RegExp(CMIIndex,'g');
472 var elementmodel = String(element).replace(expression,'.n.');
473 if (typeof datamodel[scoid][elementmodel] != "undefined") {
474 if (datamodel[scoid][elementmodel].mod != 'r') {
475 if (datamodel[scoid][elementmodel].format != 'CMIFeedback') {
476 expression = new RegExp(datamodel[scoid][elementmodel].format);
478 // cmi.interactions.n.type depending format accept everything at this stage
479 expression = new RegExp(CMIFeedback);
482 var matches = value.match(expression);
483 if ((matches != null) && ((matches.join('').length > 0) || (value.length == 0))) {
484 // Value match dataelement format
486 if (element != elementmodel) {
487 //This is a dynamic datamodel element
489 var elementIndexes = element.split('.');
490 var subelement = 'cmi';
491 var parentelement = 'cmi';
492 for (var i = 1; (i < elementIndexes.length - 1) && (errorCode == "0"); i++) {
493 var elementIndex = elementIndexes[i];
494 if (elementIndexes[i + 1].match(/^\d+$/)) {
495 if ((parseInt(elementIndexes[i + 1]) > 0) && (elementIndexes[i + 1].charAt(0) == 0)) {
496 // Index has a leading 0 (zero), this is not a number
499 parentelement = subelement + '.' + elementIndex;
500 if ((typeof eval(parentelement) == "undefined") || (typeof eval(parentelement + '._count') == "undefined")) {
503 if (elementIndexes[i + 1] > eval(parentelement + '._count')) {
505 diagnostic = "Data Model Element Collection Set Out Of Order";
507 subelement = subelement.concat('.' + elementIndex + '.N' + elementIndexes[i + 1]);
510 if (((typeof eval(subelement)) == "undefined") && (i < elementIndexes.length - 2)) {
515 subelement = subelement.concat('.' + elementIndex);
519 if (errorCode == "0") {
520 // Till now it's a real datamodel element
522 element = subelement.concat('.' + elementIndexes[elementIndexes.length - 1]);
524 if ((typeof eval(subelement)) == "undefined") {
525 switch (elementmodel) {
526 case 'cmi.objectives.n.id':
527 if (!duplicatedID(element,parentelement,value)) {
528 if (elementIndexes[elementIndexes.length - 2] == eval(parentelement + '._count')) {
529 eval(parentelement + '._count++;');
530 eval(subelement + ' = new Object();');
531 var subobject = eval(subelement);
532 subobject.success_status = datamodel[scoid]["cmi.objectives.n.success_status"].defaultvalue;
533 subobject.completion_status = datamodel[scoid]["cmi.objectives.n.completion_status"].defaultvalue;
534 subobject.progress_measure = datamodel[scoid]["cmi.objectives.n.progress_measure"].defaultvalue;
535 subobject.score = new Object();
536 subobject.score._children = score_children;
537 subobject.score.scaled = datamodel[scoid]["cmi.objectives.n.score.scaled"].defaultvalue;
538 subobject.score.raw = datamodel[scoid]["cmi.objectives.n.score.raw"].defaultvalue;
539 subobject.score.min = datamodel[scoid]["cmi.objectives.n.score.min"].defaultvalue;
540 subobject.score.max = datamodel[scoid]["cmi.objectives.n.score.max"].defaultvalue;
544 diagnostic = "Data Model Element ID Already Exists";
547 case 'cmi.interactions.n.id':
548 if (elementIndexes[elementIndexes.length - 2] == eval(parentelement + '._count')) {
549 eval(parentelement + '._count++;');
550 eval(subelement + ' = new Object();');
551 var subobject = eval(subelement);
552 subobject.objectives = new Object();
553 subobject.objectives._count = 0;
556 case 'cmi.interactions.n.objectives.n.id':
557 if (typeof eval(parentelement) != "undefined") {
558 if (!duplicatedID(element,parentelement,value)) {
559 if (elementIndexes[elementIndexes.length - 2] == eval(parentelement + '._count')) {
560 eval(parentelement + '._count++;');
561 eval(subelement + ' = new Object();');
565 diagnostic = "Data Model Element ID Already Exists";
571 case 'cmi.interactions.n.correct_responses.n.pattern':
572 if (typeof eval(parentelement) != "undefined") {
573 // Use cmi.interactions.n.type value to check the right dataelement format
574 if (elementIndexes[elementIndexes.length - 2] == eval(parentelement + '._count')) {
575 var interactiontype = eval(String(parentelement).replace('correct_responses','type'));
576 var interactioncount = eval(parentelement + '._count');
577 // trap duplicate values, which is not allowed for type choice
578 if (interactiontype == 'choice') {
579 for (var i = 0; (i < interactioncount) && (errorCode == "0"); i++) {
580 if (eval(parentelement + '.N' + i + '.pattern') == value) {
585 if ((typeof correct_responses[interactiontype].limit == 'undefined') ||
586 (eval(parentelement + '._count') < correct_responses[interactiontype].limit)) {
587 var nodes = new Array();
588 if (correct_responses[interactiontype].delimiter != '') {
589 nodes = value.split(correct_responses[interactiontype].delimiter);
593 if ((nodes.length > 0) && (nodes.length <= correct_responses[interactiontype].max)) {
594 errorCode = CRcheckValueNodes (element, interactiontype, nodes, value, errorCode);
595 } else if (nodes.length > correct_responses[interactiontype].max) {
597 diagnostic = "Data Model Element Pattern Too Long";
599 if ((errorCode == "0") && ((correct_responses[interactiontype].duplicate == false) ||
600 (!duplicatedPA(element,parentelement,value))) || (errorCode == "0" && value == "")) {
601 eval(parentelement + '._count++;');
602 eval(subelement + ' = new Object();');
604 if (errorCode == "0") {
606 diagnostic = "Data Model Element Pattern Already Exists";
611 diagnostic = "Data Model Element Collection Limit Reached";
615 diagnostic = "Data Model Element Collection Set Out Of Order";
622 if ((parentelement != 'cmi.objectives') && (parentelement != 'cmi.interactions') && (typeof eval(parentelement) != "undefined")) {
623 if (elementIndexes[elementIndexes.length - 2] == eval(parentelement + '._count')) {
624 eval(parentelement + '._count++;');
625 eval(subelement + ' = new Object();');
628 diagnostic = "Data Model Element Collection Set Out Of Order";
636 switch (elementmodel) {
637 case 'cmi.objectives.n.id':
638 if (eval(element) != value) {
640 diagnostic = "Write Once Violation";
643 case 'cmi.interactions.n.objectives.n.id':
644 if (duplicatedID(element,parentelement,value)) {
646 diagnostic = "Data Model Element ID Already Exists";
649 case 'cmi.interactions.n.type':
650 var subobject = eval(subelement);
651 subobject.correct_responses = new Object();
652 subobject.correct_responses._count = 0;
654 case 'cmi.interactions.n.learner_response':
655 if (typeof eval(subelement + '.type') == "undefined") {
658 // Use cmi.interactions.n.type value to check the right dataelement format
659 interactiontype = eval(subelement + '.type');
660 var nodes = new Array();
661 if (learner_response[interactiontype].delimiter != '') {
662 nodes = value.split(learner_response[interactiontype].delimiter);
666 if ((nodes.length > 0) && (nodes.length <= learner_response[interactiontype].max)) {
667 expression = new RegExp(learner_response[interactiontype].format);
668 for (var i = 0; (i < nodes.length) && (errorCode == "0"); i++) {
669 if (typeof learner_response[interactiontype].delimiter2 != 'undefined') {
670 values = nodes[i].split(learner_response[interactiontype].delimiter2);
671 if (values.length == 2) {
672 matches = values[0].match(expression);
673 if (matches == null) {
676 var expression2 = new RegExp(learner_response[interactiontype].format2);
677 matches = values[1].match(expression2);
678 if (matches == null) {
686 matches = nodes[i].match(expression);
687 if (matches == null) {
690 if ((nodes[i] != '') && (learner_response[interactiontype].unique)) {
691 for (var j = 0; (j < i) && (errorCode == "0"); j++) {
692 if (nodes[i] == nodes[j]) {
700 } else if (nodes.length > learner_response[interactiontype].max) {
702 diagnostic = "Data Model Element Pattern Too Long";
706 case 'cmi.interactions.n.correct_responses.n.pattern':
707 subel = subelement.split('.');
708 subel1 = 'cmi.interactions.' + subel[2];
710 if (typeof eval(subel1 + '.type') == "undefined") {
713 // Use cmi.interactions.n.type value to check the right //dataelement format
714 var interactiontype = eval(subel1 + '.type');
715 var interactioncount = eval(parentelement + '._count');
716 // trap duplicate values, which is not allowed for type choice
717 if (interactiontype == 'choice') {
718 for (var i = 0; (i < interactioncount) && (errorCode == "0"); i++) {
719 if (eval(parentelement + '.N' + i + '.pattern') == value) {
724 var nodes = new Array();
725 if (correct_responses[interactiontype].delimiter != '') {
726 nodes = value.split(correct_responses[interactiontype].delimiter);
731 if ((nodes.length > 0) && (nodes.length <= correct_responses[interactiontype].max)) {
732 errorCode = CRcheckValueNodes (element, interactiontype, nodes, value, errorCode);
733 } else if (nodes.length > correct_responses[interactiontype].max) {
735 diagnostic = "Data Model Element Pattern Too Long";
744 if (errorCode == "0") {
745 if (autocommit && !(SCORMapi1_3.timeout)) {
746 SCORMapi1_3.timeout = Y.later(60000, API_1484_11, 'Commit', [""], false);
749 if (typeof datamodel[scoid][elementmodel].range != "undefined") {
750 range = datamodel[scoid][elementmodel].range;
751 ranges = range.split('#');
753 if (value >= ranges[0]) {
754 if ((ranges[1] == '*') || (value <= ranges[1])) {
755 eval(element + '=value;');
757 if (scormdebugging) {
758 LogAPICall("SetValue", element, value, errorCode);
768 eval(element + '=value;');
770 if (scormdebugging) {
771 LogAPICall("SetValue", element, value, errorCode);
795 if (scormdebugging) {
796 LogAPICall("SetValue", element, value, errorCode);
801 function CRremovePrefixes (node) {
802 // check for prefixes lang, case, order
803 // case and then order
804 var seenOrder = false;
805 var seenCase = false;
806 var seenLang = false;
808 while (matches = node.match('^(\{(lang|case_matters|order_matters)=([^\}]+)\})')) {
809 switch (matches[2]) {
811 // check for language prefix on each node
812 langmatches = node.match(CMILangcr);
813 if (langmatches != null) {
814 lang = langmatches[3];
815 // check that language string definition is valid
816 if (lang.length > 0 && lang != undefined) {
817 if (validLanguages[lang.toLowerCase()] == undefined) {
826 // check for correct case answer
827 if (! seenLang && ! seenOrder && ! seenCase) {
828 if (matches[3] != 'true' && matches[3] != 'false') {
835 case 'order_matters':
836 // check for correct case answer
837 if (! seenCase && ! seenLang && ! seenOrder) {
838 if (matches[3] != 'true' && matches[3] != 'false') {
848 node = node.substr(matches[1].length);
850 return {'errorCode': errorCode, 'node': node};
853 function CRcheckValueNodes(element, interactiontype, nodes, value, errorCode) {
854 expression = new RegExp(correct_responses[interactiontype].format);
855 for (var i = 0; (i < nodes.length) && (errorCode == "0"); i++) {
856 if (interactiontype.match('^(fill-in|long-fill-in|matching|performance|sequencing)$')) {
857 result = CRremovePrefixes(nodes[i]);
858 errorCode = result.errorCode;
859 nodes[i] = result.node;
862 if (correct_responses[interactiontype].delimiter2 != undefined) {
863 values = nodes[i].split(correct_responses[interactiontype].delimiter2);
864 if (values.length == 2) {
865 matches = values[0].match(expression);
866 if (matches == null) {
869 var expression2 = new RegExp(correct_responses[interactiontype].format2);
870 matches = values[1].match(expression2);
871 if (matches == null) {
879 matches = nodes[i].match(expression);
880 //if ((matches == null) || (matches.join('').length == 0)) {
881 if ((matches == null && value != "") || (matches == null && interactiontype == "true-false")){
884 // numeric range - left must be <= right
885 if (interactiontype == 'numeric' && nodes.length > 1) {
886 if (parseFloat(nodes[0]) > parseFloat(nodes[1])) {
890 if ((nodes[i] != '') && (correct_responses[interactiontype].unique)) {
891 for (var j = 0; (j < i) && (errorCode == "0"); j++) {
892 if (nodes[i] == nodes[j]) {
900 } // end of for each nodes
904 function Commit (param) {
905 if (SCORMapi1_3.timeout) {
906 SCORMapi1_3.timeout.cancel();
907 SCORMapi1_3.timeout = null;
911 if ((Initialized) && (!Terminated)) {
912 var AJAXResult = StoreData(cmi,false);
913 if (scormdebugging) {
914 LogAPICall("Commit", "AJAXResult", AJAXResult, 0);
916 var result = ('true' == AJAXResult) ? 'true' : 'false';
917 errorCode = ('true' == result) ? '0' : '101'; // General exception for any AJAX fault
918 if (scormdebugging) {
919 LogAPICall("Commit", "result", result, errorCode);
921 if ('false' == result) {
922 diagnostic = "Failure calling the Commit remote callback: the server replied with HTTP Status " + AJAXResult;
935 if (scormdebugging) {
936 LogAPICall("Commit", param, "", errorCode);
941 function GetLastError () {
942 if (scormdebugging) {
943 LogAPICall("GetLastError", "", "", errorCode);
948 function GetErrorString (param) {
950 var errorString = "";
953 errorString = "No error";
956 errorString = "General exception";
959 errorString = "General Inizialization Failure";
962 errorString = "Already Initialized";
965 errorString = "Content Instance Terminated";
968 errorString = "General Termination Failure";
971 errorString = "Termination Before Inizialization";
974 errorString = "Termination After Termination";
977 errorString = "Retrieve Data Before Initialization";
980 errorString = "Retrieve Data After Termination";
983 errorString = "Store Data Before Inizialization";
986 errorString = "Store Data After Termination";
989 errorString = "Commit Before Inizialization";
992 errorString = "Commit After Termination";
995 errorString = "General Argument Error";
998 errorString = "General Get Failure";
1001 errorString = "General Set Failure";
1004 errorString = "General Commit Failure";
1007 errorString = "Undefinited Data Model";
1010 errorString = "Unimplemented Data Model Element";
1013 errorString = "Data Model Element Value Not Initialized";
1016 errorString = "Data Model Element Is Read Only";
1019 errorString = "Data Model Element Is Write Only";
1022 errorString = "Data Model Element Type Mismatch";
1025 errorString = "Data Model Element Value Out Of Range";
1028 errorString = "Data Model Dependency Not Established";
1031 if (scormdebugging) {
1032 LogAPICall("GetErrorString", param, errorString, 0);
1036 if (scormdebugging) {
1037 LogAPICall("GetErrorString", param, "No error string found!", 0);
1043 function GetDiagnostic (param) {
1044 if (diagnostic != "") {
1045 if (scormdebugging) {
1046 LogAPICall("GetDiagnostic", param, diagnostic, 0);
1050 if (scormdebugging) {
1051 LogAPICall("GetDiagnostic", param, param, 0);
1056 function duplicatedID (element, parent, value) {
1058 var elements = eval(parent + '._count');
1059 for (var n = 0; (n < elements) && (!found); n++) {
1060 if ((parent + '.N' + n + '.id' != element) && (eval(parent + '.N' + n + '.id') == value)) {
1067 function duplicatedPA (element, parent, value) {
1069 var elements = eval(parent + '._count');
1070 for (var n = 0; (n < elements) && (!found); n++) {
1071 if ((parent + '.N' + n + '.pattern' != element) && (eval(parent + '.N' + n + '.pattern') == value)) {
1078 function getElementModel(element) {
1079 if (typeof datamodel[scoid][element] != "undefined") {
1082 var expression = new RegExp(CMIIndex,'g');
1083 var elementmodel = String(element).replace(expression,'.n.');
1084 if (typeof datamodel[scoid][elementmodel] != "undefined") {
1085 return elementmodel;
1091 function AddTime (first, second) {
1092 var timestring = 'P';
1093 var matchexpr = /^P((\d+)Y)?((\d+)M)?((\d+)D)?(T((\d+)H)?((\d+)M)?((\d+(\.\d{1,2})?)S)?)?$/;
1094 var firstarray = first.match(matchexpr);
1095 var secondarray = second.match(matchexpr);
1096 if ((firstarray != null) && (secondarray != null)) {
1098 if(parseFloat(firstarray[13],10) > 0){ firstsecs = parseFloat(firstarray[13],10); }
1100 if(parseFloat(secondarray[13],10) > 0){ secondsecs = parseFloat(secondarray[13],10); }
1101 var secs = firstsecs + secondsecs; //Seconds
1102 var change = Math.floor(secs / 60);
1103 secs = Math.round((secs - (change * 60)) * 100) / 100;
1105 if(parseInt(firstarray[11],10) > 0){ firstmins = parseInt(firstarray[11],10); }
1107 if(parseInt(secondarray[11],10) > 0){ secondmins = parseInt(secondarray[11],10); }
1108 var mins = firstmins + secondmins + change; //Minutes
1109 change = Math.floor(mins / 60);
1110 mins = Math.round(mins - (change * 60));
1112 if(parseInt(firstarray[9],10) > 0){ firsthours = parseInt(firstarray[9],10); }
1113 var secondhours = 0;
1114 if(parseInt(secondarray[9],10) > 0){ secondhours = parseInt(secondarray[9],10); }
1115 var hours = firsthours + secondhours + change; //Hours
1116 change = Math.floor(hours / 24);
1117 hours = Math.round(hours - (change * 24));
1119 if(parseInt(firstarray[6],10) > 0){ firstdays = parseInt(firstarray[6],10); }
1121 if(parseInt(secondarray[6],10) > 0){ firstdays = parseInt(secondarray[6],10); }
1122 var days = Math.round(firstdays + seconddays + change); // Days
1123 var firstmonths = 0;
1124 if(parseInt(firstarray[4],10) > 0){ firstmonths = parseInt(firstarray[4],10); }
1125 var secondmonths = 0;
1126 if(parseInt(secondarray[4],10) > 0){ secondmonths = parseInt(secondarray[4],10); }
1127 var months = Math.round(firstmonths + secondmonths);
1129 if(parseInt(firstarray[2],10) > 0){ firstyears = parseInt(firstarray[2],10); }
1130 var secondyears = 0;
1131 if(parseInt(secondarray[2],10) > 0){ secondyears = parseInt(secondarray[2],10); }
1132 var years = Math.round(firstyears + secondyears);
1135 timestring += years + 'Y';
1138 timestring += months + 'M';
1141 timestring += days + 'D';
1143 if ((hours > 0) || (mins > 0) || (secs > 0)) {
1146 timestring += hours + 'H';
1149 timestring += mins + 'M';
1152 timestring += secs + 'S';
1158 function TotalTime() {
1159 var total_time = AddTime(cmi.total_time, cmi.session_time);
1160 return '&' + underscore('cmi.total_time') + '=' + encodeURIComponent(total_time);
1163 function CollectData(data,parent) {
1164 var datastring = '';
1165 for (property in data) {
1166 if (typeof data[property] == 'object') {
1167 datastring += CollectData(data[property],parent + '.' + property);
1169 var element = parent + '.' + property;
1170 var expression = new RegExp(CMIIndexStore,'g');
1171 var elementmodel = String(element).replace(expression,'.n.');
1172 if (typeof datamodel[scoid][elementmodel] != "undefined") {
1173 if (datamodel[scoid][elementmodel].mod != 'r') {
1174 var elementstring = '&' + underscore(element) + '=' + encodeURIComponent(data[property]);
1175 if (typeof datamodel[scoid][elementmodel].defaultvalue != "undefined") {
1176 if (datamodel[scoid][elementmodel].defaultvalue != data[property] ||
1177 typeof datamodel[scoid][elementmodel].defaultvalue != typeof data[property]) {
1178 datastring += elementstring;
1181 datastring += elementstring;
1190 function StoreData(data,storetotaltime) {
1191 var datastring = '';
1192 if (storetotaltime) {
1193 if (cmi.mode == 'normal') {
1194 if (cmi.credit == 'credit') {
1195 if ((cmi.completion_threshold) && (cmi.progress_measure)) {
1196 if (cmi.progress_measure >= cmi.completion_threshold) {
1197 cmi.completion_status = 'completed';
1199 cmi.completion_status = 'incomplete';
1202 if ((cmi.scaled_passed_score != null) && (cmi.score.scaled != '')) {
1203 if (cmi.score.scaled >= cmi.scaled_passed_score) {
1204 cmi.success_status = 'passed';
1206 cmi.success_status = 'failed';
1211 datastring += TotalTime();
1213 datastring += CollectData(data,'cmi');
1214 var element = 'adl.nav.request';
1215 var navrequest = eval(element) != datamodel[scoid][element].defaultvalue ? '&' + underscore(element) + '=' + encodeURIComponent(eval(element)) : '';
1216 datastring += navrequest;
1218 var myRequest = NewHttpReq();
1219 result = DoRequest(myRequest, datamodelurl, datamodelurlparams + datastring);
1221 var results = String(result).split('\n');
1222 if ((results.length > 2) && (navrequest != '')) {
1225 errorCode = results[1];
1229 this.Initialize = Initialize;
1230 this.Terminate = Terminate;
1231 this.GetValue = GetValue;
1232 this.SetValue = SetValue;
1233 this.Commit = Commit;
1234 this.GetLastError = GetLastError;
1235 this.GetErrorString = GetErrorString;
1236 this.GetDiagnostic = GetDiagnostic;
1237 this.version = '1.0';
1242 M.scorm_api.init = function(Y, def, cmiobj, cmiint, cmicommentsuser, cmicommentslms, scormdebugging, scormauto, scormid, cfgwwwroot, sesskey, scoid, attempt, viewmode, cmid, currentorg, autocommit) {
1243 window.API_1484_11 = new SCORMapi1_3(def, cmiobj, cmiint, cmicommentsuser, cmicommentslms, scormdebugging, scormauto, scormid, cfgwwwroot, sesskey, scoid, attempt, viewmode, cmid, currentorg, autocommit);