First step to SCORM2004, new communication subsystem
[moodle.git] / mod / scorm / api.php
CommitLineData
2a0407b7 1<?php
2
3 require_once("../../config.php");
4
5 optional_variable($id); // Course Module ID, or
6 optional_variable($a); // scorm ID
7
8 if ($id) {
9 if (! $cm = get_record("course_modules", "id", $id)) {
10 error("Course Module ID was incorrect");
11 }
12
13 if (! $course = get_record("course", "id", $cm->course)) {
14 error("Course is misconfigured");
15 }
16
17 if (! $scorm = get_record("scorm", "id", $cm->instance)) {
18 error("Course module is incorrect");
19 }
20
21 } else {
22 if (! $scorm = get_record("scorm", "id", $a)) {
23 error("Course module is incorrect");
24 }
25 if (! $course = get_record("course", "id", $scorm->course)) {
26 error("Course is misconfigured");
27 }
28 if (! $cm = get_coursemodule_from_instance("scorm", $scorm->id, $course->id)) {
29 error("Course Module ID was incorrect");
30 }
31 }
32
33 require_login($course->id, false, $cm);
34?>
35
36function SCOFinish(){
37 /*if (typeof API != "undefined") {
38 API.SaveTotalTime();
39 } */
40}
41
42function closeMain() {
43 if (document.all) {
44 document.cookie = "SCORMpopup=" + escape(",top="+top.main.screenTop+",left="+top.main.screenLeft);
45 } else {
46 document.cookie = "SCORMpopup=" + escape(",top="+top.main.screenY+",left="+top.main.screenX);
47 }
48 top.main.close();
49}
50
51//
52// SCORM API Implementation Call
53//
54var errorCode = "0";
55
56function SCORM_Call (call,param,value) {
92a489eb 57 if (arguments.length < 2) {
2a0407b7 58 alert ("Invalid SCORM_Call function call: too few arguments.\nYou need pass at least 2 parameters");
92a489eb 59 } else if (arguments.length == 3) {
2a0407b7 60 param = param.concat("&value=",value);
61 }
62 var myRequest = NewHttpReq();
92a489eb 63 result = DoRequest(myRequest,"<?php p($CFG->wwwroot) ?>/mod/scorm/datamodel.php?id=<?php p($id) ?>&sesskey=<?php p($USER->sesskey) ?>&call="+call+"&param="+param);
2a0407b7 64 results = result.split('\n');
65
66 errorCode = results[1];
67 return results[0];
68}
69
70//
71// SCORM 1.2 API Implementation
72//
73function SCORMapi1_2() {
74
75 function LMSInitialize (param) {
76 return SCORM_Call('LMSInitialize',param);
77 }
78
79 function LMSFinish (param) {
80 return SCORM_Call('LMSGetValue',param);
81 }
82
83 function LMSGetValue (element) {
84 return SCORM_Call('LMSGetValue',element);
85 }
86
87 function LMSSetValue (element,value) {
88 return SCORM_Call('LMSGetValue',element,value);
89 }
90
91 function LMSCommit (param) {
92 return SCORM_Call('LMSGetValue',param);
93 }
94
95 function LMSGetLastError () {
96 return errorCode;
97 }
98
99 function LMSGetErrorString (param) {
100 var errorString = new Array();
101 errorString["0"] = "No error";
102 errorString["101"] = "General exception";
103 errorString["201"] = "Invalid argument error";
104 errorString["202"] = "Element cannot have children";
105 errorString["203"] = "Element not an array - cannot have count";
106 errorString["301"] = "Not initialized";
107 errorString["401"] = "Not implemented error";
108 errorString["402"] = "Invalid set value, element is a keyword";
109 errorString["403"] = "Element is read only";
110 errorString["404"] = "Element is write only";
111 errorString["405"] = "Incorrect data type";
112 return errorString[param];
113 }
114
115 function LMSGetDiagnostic (param) {
116 return param;
117 }
118
119 this.LMSInitialize = LMSInitialize;
120 this.LMSFinish = LMSFinish;
121 this.LMSGetValue = LMSGetValue;
122 this.LMSSetValue = LMSSetValue;
123 this.LMSCommit = LMSCommit;
124 this.LMSGetLastError = LMSGetLastError;
125 this.LMSGetErrorString = LMSGetErrorString;
126 this.LMSGetDiagnostic = LMSGetDiagnostic;
127}
128
129var API = new SCORMapi1_2();
130
131//
132// SCORM 2004 API Implementation
133//
134function SCORMapi2004() {
135
136 function Initialize (param) {
137 return SCORM_Call('Initialize',param);
138 }
139
140 function Terminate (param) {
141 return SCORM_Call('Terminate',param);
142 }
143
144 function GetValue (element) {
145 return SCORM_Call('GetValue',element);
146 }
147
148 function SetValue (element, value) {
149 return SCORM_Call('SetValue',element,value);
150 }
151
152 function Commit (param) {
153 return SCORM_Call('Commit',param);
154 }
155
156 function GetLastError () {
157 return errorCode;
158 }
159
160 function GetErrorString (param) {
161 var errorString = new Array();
162 errorString["0"] = "No error";
163 errorString["101"] = "General exception";
164 errorString["102"] = "General Inizialization Failure";
165 errorString["103"] = "Already Initialized";
166 errorString["104"] = "Content Instance Terminated";
167 errorString["111"] = "General Termination Failure";
168 errorString["112"] = "Termination Before Inizialization";
169 errorString["113"] = "Termination After Termination";
170 errorString["122"] = "Retrieve Data Before Initialization";
171 errorString["123"] = "Retrieve Data After Termination";
172 errorString["132"] = "Store Data Before Inizialization";
173 errorString["133"] = "Store Data After Termination";
174 errorString["142"] = "Commit Before Inizialization";
175 errorString["143"] = "Commit After Termination";
176 errorString["201"] = "General Argument Error";
177 errorString["301"] = "General Get Failure";
178 errorString["351"] = "General Set Failure";
179 errorString["391"] = "General Commit Failure";
180 errorString["401"] = "Undefinited Data Model";
181 errorString["402"] = "Unimplemented Data Model Element";
182 errorString["403"] = "Data Model Element Value Not Initialized";
92a489eb 183 errorString["404"] = "Data Model Element Is Read Only";
2a0407b7 184 errorString["405"] = "Data Model Element Is Write Only";
185 errorString["406"] = "Data Model Element Type Mismatch";
186 errorString["407"] = "Data Model Element Value Out Of Range";
187 errorString["408"] = "Data Model Dependency Not Established";
188 return errorString[param];
189 }
190
191 function GetDiagnostic (param) {
192 return SCORM_Call('GetDiagnostic',param);
193 }
194
195 this.Initialize = Initialize;
196 this.Terminate = Terminate;
197 this.GetValue = GetValue;
198 this.SetValue = SetValue;
199 this.Commit = Commit;
200 this.GetLastError = GetLastError;
201 this.GetErrorString = GetErrorString;
202 this.GetDiagnostic = GetDiagnostic;
203}
204
205var API_1484_11 = new SCORMapi2004();