2 require_once('../../config.php');
3 require_once('locallib.php');
5 $command = required_param('command', '', PARAM_ALPHA
);
6 $sessionid = required_param('session_id', '', PARAM_ALPHANUM
);
7 $aiccdata = optional_param('aicc_data', '', PARAM_RAW
);
11 if (!empty($command) && confirm_sesskey($sessionid)) {
12 $command = strtolower($command);
14 if (isset($SESSION->scorm_scoid
)) {
15 $scoid = $SESSION->scorm_scoid
;
17 error('Invalid script call');
20 if (isset($SESSION->scorm_mode
)) {
21 $mode = $SESSION->scorm_mode
;
23 $status = 'Not Initialized';
24 if (isset($SESSION->scorm_status
)) {
25 $status = $SESSION->scorm_status
;
27 if (isset($SESSION->attempt
)) {
28 $attempt = $SESSION->attempt
;
33 if ($sco = get_record('scorm_scoes','id',$scoid)) {
34 if (!$scorm = get_record('scorm','id',$sco->scorm
)) {
35 error('Invalid script call');
38 error('Invalid script call');
41 if ($scorm = get_record('scorm','id',$sco->scorm
)) {
44 if ($status == 'Not Initialized') {
45 $SESSION->scorm_status
= 'Running';
48 if ($status != 'Running') {
49 echo "error = 101\nerror_text = Terminated\n";
51 if ($usertrack=scorm_get_tracks($scoid,$USER->id
,$attempt)) {
52 $userdata = $usertrack;
54 $userdata->status
= '';
55 $userdata->score_raw
= '';
57 $userdata->student_id
= $USER->username
;
58 $userdata->student_name
= $USER->lastname
.', '. $USER->firstname
;
59 $userdata->mode
= $mode;
60 if ($userdata->mode
== 'normal') {
61 $userdata->credit
= 'credit';
63 $userdata->credit
= 'no-credit';
66 if ($sco = get_record('scorm_scoes','id',$scoid)) {
67 $userdata->course_id
= $sco->identifier
;
68 $userdata->datafromlms
= $sco->datafromlms
;
69 $userdata->masteryscore
= $sco->masteryscore
;
70 $userdata->maxtimeallowed
= $sco->maxtimeallowed
;
71 $userdata->timelimitaction
= $sco->timelimitaction
;
73 echo "error = 0\nerror_text = Successful\naicc_data=\n";
75 echo 'Student_ID = '.$userdata->student_id
."\n";
76 echo 'Student_Name = '.$userdata->student_name
."\n";
77 if (isset($userdata->{'cmi.core.lesson_location'})) {
78 echo 'Lesson_Location = '.$userdata->{'cmi.core.lesson_location'}."\n";
80 echo 'Lesson_Location = '."\n";
82 echo 'Credit = '.$userdata->credit
."\n";
83 if (isset($userdata->status
)) {
84 if ($userdata->status
== '') {
85 $userdata->entry
= ', ab-initio';
87 if (isset($userdata->{'cmi.core.exit'}) && ($userdata->{'cmi.core.exit'} == 'suspend')) {
88 $userdata->entry
= ', resume';
90 $userdata->entry
= '';
94 if (isset($userdata->{'cmi.core.lesson_status'})) {
95 echo 'Lesson_Status = '.$userdata->{'cmi.core.lesson_status'}.$userdata->entry
."\n";
96 $SESSION->scorm_lessonstatus
= $userdata->{'cmi.core.lesson_status'};
98 echo 'Lesson_Status = not attempted'.$userdata->entry
."\n";
99 $SESSION->scorm_lessonstatus
= 'not attempted';
101 if (isset($userdata->{'cmi.core.score.raw'})) {
104 if (isset($userdata->{'cmi.core.score.max'}) && !empty($userdata->{'cmi.core.score.max'})) {
105 $max = ', '.$userdata->{'cmi.core.score.max'};
106 if (isset($userdata->{'cmi.core.score.min'}) && !empty($userdata->{'cmi.core.score.min'})) {
107 $min = ', '.$userdata->{'cmi.core.score.min'};
110 echo 'Score = '.$userdata->{'cmi.core.score.raw'}.$max.$min."\n";
112 echo 'Score = '."\n";
114 if (isset($userdata->{'cmi.core.total_time'})) {
115 echo 'Time = '.$userdata->{'cmi.core.total_time'}."\n";
117 echo 'Time = '.'00:00:00'."\n";
119 echo 'Lesson_Mode = '.$userdata->mode
."\n";
120 if (isset($userdata->{'cmi.suspend_data'})) {
121 echo "[Core_Lesson]\n".$userdata->{'cmi.suspend_data'}."\n";
123 echo "[Core_Lesson]\n"."\n";
125 echo "[Core_Vendor]\n".$userdata->datafromlms
."\n";
126 echo "[Evaluation]\nCourse_ID = {".$userdata->course_id
."}\n";
127 echo "[Student_Data]\n";
128 echo 'Mastery_Score = '.$userdata->masteryscore
."\n";
129 echo 'Max_Time_Allowed = '.$userdata->maxtimeallowed
."\n";
130 echo 'Time_Limit_Action = '.$userdata->timelimitaction
."\n";
132 error('Sco not found');
137 if ($status == 'Running') {
138 if (!empty($aiccdata) && isstudent($scorm->course
)) {
139 $initlessonstatus = 'not attempted';
140 $lessonstatus = 'not attempted';
141 if (isset($SESSION->scorm_lessonstatus
)) {
142 $initlessonstatus = $SESSION->scorm_lessonstatus
;
145 $datamodel['lesson_location'] = 'cmi.core.lesson_location';
146 $datamodel['lesson_status'] = 'cmi.core.lesson_status';
147 $datamodel['score'] = 'cmi.core.score.raw';
148 $datamodel['time'] = 'cmi.core.session_time';
149 $datamodel['[core_lesson]'] = 'cmi.suspend_data';
150 $datamodel['[comments]'] = 'cmi.comments';
151 $datarows = explode("\n",$aiccdata);
153 while ((list(,$datarow) = each($datarows)) !== false) {
154 if (($equal = strpos($datarow, '=')) !== false) {
155 $element = strtolower(trim(substr($datarow,0,$equal)));
156 $value = trim(substr($datarow,$equal+
1));
157 if (isset($datamodel[$element])) {
158 $element = $datamodel[$element];
160 case 'cmi.core.lesson_location':
161 $id = scorm_insert_track($USER->id
, $scorm->id
, $sco->id
, $attempt, $element, $value);
163 case 'cmi.core.lesson_status':
165 'passed' => 'passed',
166 'completed' => 'completed',
167 'failed' => 'failed',
168 'incomplete' => 'incomplete',
169 'browsed' => 'browsed',
170 'not attempted' => 'not attempted',
176 'n' => 'not attempted'
179 'logout' => 'logout',
180 'time-out' => 'time-out',
181 'suspend' => 'suspend',
186 $values = explode(',',$value);
188 if (count($values) > 1) {
189 $value = trim(strtolower($values[1]));
190 if (isset($exites[$value])) {
191 $value = $exites[$value];
194 if (empty($value) ||
isset($exites[$value])) {
195 $subelement = 'cmi.core.exit';
196 $id = scorm_insert_track($USER->id
, $scorm->id
, $sco->id
, $attempt, $subelement, $value);
198 $value = trim(strtolower($values[0]));
199 if (isset($statuses[$value]) && ($mode == 'normal')) {
200 $value = $statuses[$value];
201 $id = scorm_insert_track($USER->id
, $scorm->id
, $sco->id
, $attempt, $element, $value);
203 $lessonstatus = $value;
205 case 'cmi.core.score.raw':
206 $values = explode(',',$value);
207 if ((count($values) > 1) && ($values[1] >= $values[0]) && is_numeric($values[1])) {
208 $subelement = 'cmi.core.score.max';
209 $value = trim($values[1]);
210 $id = scorm_insert_track($USER->id
, $scorm->id
, $sco->id
, $attempt, $subelement, $value);
211 if ((count($values) == 3) && ($values[2] <= $values[0]) && is_numeric($values[2])) {
212 $subelement = 'cmi.core.score.min';
213 $value = trim($values[2]);
214 $id = scorm_insert_track($USER->id
, $scorm->id
, $sco->id
, $attempt, $subelement, $value);
219 if (is_numeric($values[0])) {
220 $value = trim($values[0]);
221 $id = scorm_insert_track($USER->id
, $scorm->id
, $sco->id
, $attempt, $element, $value);
225 case 'cmi.core.session_time':
226 $SESSION->scorm_session_time
= $value;
231 if (isset($datamodel[strtolower(trim($datarow))])) {
232 $element = $datamodel[strtolower(trim($datarow))];
234 while ((($datarow = current($datarows)) !== false) && (substr($datarow,0,1) != '[')) {
238 $id = scorm_insert_track($USER->id
, $scorm->id
, $sco->id
, $attempt, $element, $value);
242 if (($mode == 'browse') && ($initlessonstatus == 'not attempted')){
243 $lessonstatus = 'browsed';
244 $id = scorm_insert_track($USER->id
, $scorm->id
, $sco->id
, $attempt, 'cmi.core.lesson_status', 'browsed');
246 if ($mode == 'normal') {
247 if ($lessonstatus == 'completed') {
248 if (!empty($sco->masteryscore
) && !empty($score) && ($score >= $sco->masteryscore
)) {
249 $lessonstatus = 'passed';
251 $lessonstatus = 'failed';
253 $id = scorm_insert_track($USER->id
, $scorm->id
, $sco->id
, $attempt, 'cmi.core.lesson_status', $lessonstatus);
257 echo "error = 0\nerror_text = Successful\n";
258 } else if ($status == 'Terminated') {
259 echo "error = 1\nerror_text = Terminated\n";
261 echo "error = 1\nerror_text = Not Initialized\n";
265 if ($status == 'Running') {
266 echo "error = 0\nerror_text = Successful\n";
267 } else if ($status == 'Terminated') {
268 echo "error = 1\nerror_text = Terminated\n";
270 echo "error = 1\nerror_text = Not Initialized\n";
273 case 'putinteractions':
274 if ($status == 'Running') {
275 echo "error = 0\nerror_text = Successful\n";
276 } else if ($status == 'Terminated') {
277 echo "error = 1\nerror_text = Terminated\n";
279 echo "error = 1\nerror_text = Not Initialized\n";
282 case 'putobjectives':
283 if ($status == 'Running') {
284 echo "error = 0\nerror_text = Successful\n";
285 } else if ($status == 'Terminated') {
286 echo "error = 1\nerror_text = Terminated\n";
288 echo "error = 1\nerror_text = Not Initialized\n";
292 if ($status == 'Running') {
293 echo "error = 0\nerror_text = Successful\n";
294 } else if ($status == 'Terminated') {
295 echo "error = 1\nerror_text = Terminated\n";
297 echo "error = 1\nerror_text = Not Initialized\n";
300 case 'putperformance':
301 if ($status == 'Running') {
302 echo "error = 0\nerror_text = Successful\n";
303 } else if ($status == 'Terminated') {
304 echo "error = 1\nerror_text = Terminated\n";
306 echo "error = 1\nerror_text = Not Initialized\n";
310 if ($status == 'Running') {
311 if (isset($SESSION->scorm_session_time
) && ($SESSION->scorm_session_time
!= '')) {
312 if ($track = get_record_select('scorm_scoes_track',"userid='$USER->id' AND scormid='$scorm->id' AND scoid='$sco->id' AND element='cmi.core.total_time'")) {
313 // Add session_time to total_time
314 $value = scorm_add_time($track->value
, $SESSION->scorm_session_time
);
315 $track->value
= $value;
316 $track->timemodified
= time();
317 $id = update_record('scorm_scoes_track',$track);
319 $track->userid
= $USER->id
;
320 $track->scormid
= $scorm->id
;
321 $track->scoid
= $sco->id
;
322 $track->element
= 'cmi.core.total_time';
323 $track->value
= $SESSION->scorm_session_time
;
324 $track->timemodified
= time();
325 $id = insert_record('scorm_scoes_track',$track);
329 $SESSION->scorm_status
= 'Terminated';
330 $SESSION->scorm_session_time
= '';
331 echo "error = 0\nerror_text = Successful\n";
332 } else if ($status == 'Terminated') {
333 echo "error = 1\nerror_text = Terminated\n";
335 echo "error = 1\nerror_text = Not Initialized\n";
339 echo "error = 1\nerror_text = Invalid Command\n";
344 if (empty($command)) {
345 echo "error = 1\nerror_text = Invalid Command\n";
347 echo "error = 3\nerror_text = Invalid Session ID\n";