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 = scorm_get_sco($scoid, SCO_ONLY
)) {
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 = scorm_get_sco($scoid)) {
67 $userdata->course_id
= $sco->identifier
;
68 $userdata->datafromlms
= isset($sco->datafromlms
)?
$sco->datafromlms
:'';
69 $userdata->masteryscore
= isset($sco->masteryscore
)?
$sco->masteryscore
:'';
70 $userdata->maxtimeallowed
= isset($sco->maxtimeallowed
)?
$sco->maxtimeallowed
:'';
71 $userdata->timelimitaction
= isset($sco->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 (! $cm = get_coursemodule_from_instance("scorm", $scorm->id
, $scorm->course
)) {
139 echo "error = 1\nerror_text = Unknown\n"; // No one must see this error message if not hacked
141 if (!empty($aiccdata) && has_capability('mod/scorm:savetrack', get_context_instance(CONTEXT_MODULE
, $cm->id
))) {
142 $initlessonstatus = 'not attempted';
143 $lessonstatus = 'not attempted';
144 if (isset($SESSION->scorm_lessonstatus
)) {
145 $initlessonstatus = $SESSION->scorm_lessonstatus
;
148 $datamodel['lesson_location'] = 'cmi.core.lesson_location';
149 $datamodel['lesson_status'] = 'cmi.core.lesson_status';
150 $datamodel['score'] = 'cmi.core.score.raw';
151 $datamodel['time'] = 'cmi.core.session_time';
152 $datamodel['[core_lesson]'] = 'cmi.suspend_data';
153 $datamodel['[comments]'] = 'cmi.comments';
154 $datarows = explode("\n",$aiccdata);
156 while ((list(,$datarow) = each($datarows)) !== false) {
157 if (($equal = strpos($datarow, '=')) !== false) {
158 $element = strtolower(trim(substr($datarow,0,$equal)));
159 $value = trim(substr($datarow,$equal+
1));
160 if (isset($datamodel[$element])) {
161 $element = $datamodel[$element];
163 case 'cmi.core.lesson_location':
164 $id = scorm_insert_track($USER->id
, $scorm->id
, $sco->id
, $attempt, $element, $value);
166 case 'cmi.core.lesson_status':
168 'passed' => 'passed',
169 'completed' => 'completed',
170 'failed' => 'failed',
171 'incomplete' => 'incomplete',
172 'browsed' => 'browsed',
173 'not attempted' => 'not attempted',
179 'n' => 'not attempted'
182 'logout' => 'logout',
183 'time-out' => 'time-out',
184 'suspend' => 'suspend',
189 $values = explode(',',$value);
191 if (count($values) > 1) {
192 $value = trim(strtolower($values[1]));
193 if (isset($exites[$value])) {
194 $value = $exites[$value];
197 if (empty($value) ||
isset($exites[$value])) {
198 $subelement = 'cmi.core.exit';
199 $id = scorm_insert_track($USER->id
, $scorm->id
, $sco->id
, $attempt, $subelement, $value);
201 $value = trim(strtolower($values[0]));
202 if (isset($statuses[$value]) && ($mode == 'normal')) {
203 $value = $statuses[$value];
204 $id = scorm_insert_track($USER->id
, $scorm->id
, $sco->id
, $attempt, $element, $value);
206 $lessonstatus = $value;
208 case 'cmi.core.score.raw':
209 $values = explode(',',$value);
210 if ((count($values) > 1) && ($values[1] >= $values[0]) && is_numeric($values[1])) {
211 $subelement = 'cmi.core.score.max';
212 $value = trim($values[1]);
213 $id = scorm_insert_track($USER->id
, $scorm->id
, $sco->id
, $attempt, $subelement, $value);
214 if ((count($values) == 3) && ($values[2] <= $values[0]) && is_numeric($values[2])) {
215 $subelement = 'cmi.core.score.min';
216 $value = trim($values[2]);
217 $id = scorm_insert_track($USER->id
, $scorm->id
, $sco->id
, $attempt, $subelement, $value);
222 if (is_numeric($values[0])) {
223 $value = trim($values[0]);
224 $id = scorm_insert_track($USER->id
, $scorm->id
, $sco->id
, $attempt, $element, $value);
228 case 'cmi.core.session_time':
229 $SESSION->scorm_session_time
= $value;
234 if (isset($datamodel[strtolower(trim($datarow))])) {
235 $element = $datamodel[strtolower(trim($datarow))];
237 while ((($datarow = current($datarows)) !== false) && (substr($datarow,0,1) != '[')) {
241 $id = scorm_insert_track($USER->id
, $scorm->id
, $sco->id
, $attempt, $element, $value);
245 if (($mode == 'browse') && ($initlessonstatus == 'not attempted')){
246 $lessonstatus = 'browsed';
247 $id = scorm_insert_track($USER->id
, $scorm->id
, $sco->id
, $attempt, 'cmi.core.lesson_status', 'browsed');
249 if ($mode == 'normal') {
250 if ($lessonstatus == 'completed') {
251 if (!empty($sco->masteryscore
) && !empty($score) && ($score >= $sco->masteryscore
)) {
252 $lessonstatus = 'passed';
254 $lessonstatus = 'failed';
256 $id = scorm_insert_track($USER->id
, $scorm->id
, $sco->id
, $attempt, 'cmi.core.lesson_status', $lessonstatus);
260 echo "error = 0\nerror_text = Successful\n";
261 } else if ($status == 'Terminated') {
262 echo "error = 1\nerror_text = Terminated\n";
264 echo "error = 1\nerror_text = Not Initialized\n";
268 if ($status == 'Running') {
269 echo "error = 0\nerror_text = Successful\n";
270 } else if ($status == 'Terminated') {
271 echo "error = 1\nerror_text = Terminated\n";
273 echo "error = 1\nerror_text = Not Initialized\n";
276 case 'putinteractions':
277 if ($status == 'Running') {
278 echo "error = 0\nerror_text = Successful\n";
279 } else if ($status == 'Terminated') {
280 echo "error = 1\nerror_text = Terminated\n";
282 echo "error = 1\nerror_text = Not Initialized\n";
285 case 'putobjectives':
286 if ($status == 'Running') {
287 echo "error = 0\nerror_text = Successful\n";
288 } else if ($status == 'Terminated') {
289 echo "error = 1\nerror_text = Terminated\n";
291 echo "error = 1\nerror_text = Not Initialized\n";
295 if ($status == 'Running') {
296 echo "error = 0\nerror_text = Successful\n";
297 } else if ($status == 'Terminated') {
298 echo "error = 1\nerror_text = Terminated\n";
300 echo "error = 1\nerror_text = Not Initialized\n";
303 case 'putperformance':
304 if ($status == 'Running') {
305 echo "error = 0\nerror_text = Successful\n";
306 } else if ($status == 'Terminated') {
307 echo "error = 1\nerror_text = Terminated\n";
309 echo "error = 1\nerror_text = Not Initialized\n";
313 if ($status == 'Running') {
314 if (isset($SESSION->scorm_session_time
) && ($SESSION->scorm_session_time
!= '')) {
315 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'")) {
316 // Add session_time to total_time
317 $value = scorm_add_time($track->value
, $SESSION->scorm_session_time
);
318 $track->value
= $value;
319 $track->timemodified
= time();
320 update_record('scorm_scoes_track',$track);
323 $track = new object();
324 $track->userid
= $USER->id
;
325 $track->scormid
= $scorm->id
;
326 $track->scoid
= $sco->id
;
327 $track->element
= 'cmi.core.total_time';
328 $track->value
= $SESSION->scorm_session_time
;
329 $track->timemodified
= time();
330 $id = insert_record('scorm_scoes_track',$track);
332 scorm_update_grades($scorm, $USER->id
);
335 $SESSION->scorm_status
= 'Terminated';
336 $SESSION->scorm_session_time
= '';
337 echo "error = 0\nerror_text = Successful\n";
338 } else if ($status == 'Terminated') {
339 echo "error = 1\nerror_text = Terminated\n";
341 echo "error = 1\nerror_text = Not Initialized\n";
345 echo "error = 1\nerror_text = Invalid Command\n";
350 if (empty($command)) {
351 echo "error = 1\nerror_text = Invalid Command\n";
353 echo "error = 3\nerror_text = Invalid Session ID\n";