changed all the POST with option/required_param functions
[moodle.git] / mod / scorm / aicc.php
CommitLineData
ba5a7c6c 1<?php
2 require_once('../../config.php');
3 require_once('lib.php');
4
7b873234 5 $command = required_param('command', '', PARAM_ALPHA);
6 $sessionid = required_param('session_id', '', PARAM_ALPHA);
7
8 require_login($course->id, false, $cm);
ba5a7c6c 9
7b873234 10 if (!empty($command) && confirm_sesskey($sessionid)) {
11 $command = strtolower($command);
9633a423 12
13 if (isset($SESSION->scorm_scoid)) {
14 $scoid = $SESSION->scorm_scoid;
15 } else {
16 error('Invalid script call');
17 }
18 $mode = 'normal';
19 if (isset($SESSION->scorm_mode)) {
20 $mode = $SESSION->scorm_mode;
21 }
d475f685 22 $status = 'Not Initialized';
23 if (isset($SESSION->scorm_status)) {
24 $status = $SESSION->scorm_status;
25 }
9633a423 26 if ($sco = get_record('scorm_scoes','id',$scoid)) {
27 if (!$scorm = get_record('scorm','id',$sco->scorm)) {
28 error('Invalid script call');
29 }
30 } else {
31 error('Invalid script call');
32 }
d475f685 33
9633a423 34 if ($scorm = get_record('scorm','id',$sco->scorm)) {
d475f685 35 switch ($command) {
36 case 'getparam':
37 if ($status == 'Not Initialized') {
38 $SESSION->scorm_status = 'Running';
39 $status = 'Running';
9633a423 40 }
d475f685 41 if ($status != 'Running') {
42 echo "error = 101\nerror_text = Terminated\n";
43 } else {
44 if ($usertrack=scorm_get_tracks($scoid,$USER->id)) {
45 $userdata = $usertrack;
46 } else {
47 $userdata->status = '';
7f2f2b2d 48 $userdata->score_raw = '';
d475f685 49 }
50 $userdata->student_id = $USER->username;
51 $userdata->student_name = $USER->lastname .', '. $USER->firstname;
52 $userdata->mode = $mode;
9633a423 53
d475f685 54 if ($sco = get_record('scorm_scoes','id',$scoid)) {
b5127f1e 55 $userdata->course_id = $sco->identifier;
d475f685 56 $userdata->datafromlms = $sco->datafromlms;
57 $userdata->masteryscore = $sco->masteryscore;
58 $userdata->maxtimeallowed = $sco->maxtimeallowed;
59 $userdata->timelimitaction = $sco->timelimitaction;
60 if (!empty($sco->masteryscore)) {
61 $userdata->credit = 'credit';
62 } else {
63 $userdata->credit = 'no-credit';
64 }
65 echo "error = 0\nerror_text = Successful\naicc_data=\n";
66 echo "[Core]\n";
67 echo 'Student_ID = '.$userdata->student_id."\n";
68 echo 'Student_Name = '.$userdata->student_name."\n";
69 if (isset($userdata->{'cmi.core.lesson_location'})) {
70 echo 'Lesson_Location = '.$userdata->{'cmi.core.lesson_location'}."\n";
71 } else {
72 echo 'Lesson_Location = '."\n";
73 }
74 echo 'Credit = '.$userdata->credit."\n";
75 if (isset($userdata->{'cmi.core.lesson_status'})) {
76 echo 'Lesson_Status = '.$userdata->{'cmi.core.lesson_status'}."\n";
77 } else {
78 echo 'Lesson_Status = '."\n";
79 }
80 if (isset($userdata->{'cmi.core.score.raw'})) {
81 echo 'Score = '.$userdata->{'cmi.core.score.raw'}."\n";
82 } else {
83 echo 'Score = '."\n";
84 }
85 if (isset($userdata->{'cmi.core.total_time'})) {
86 echo 'Time = '.$userdata->{'cmi.core.total_time'}."\n";
87 } else {
88 echo 'Time = '.'00:00:00'."\n";
89 }
90 if (isset($userdata->{'cmi.suspend_data'})) {
91 echo "[Core_Lesson]\n".$userdata->{'cmi.suspend_data'}."\n";
92 } else {
93 echo "[Core_Lesson]\n"."\n";
94 }
95 echo "[Core_Vendor]\n".$userdata->datafromlms."\n";
b5127f1e 96 echo "[Evaluation]\nCourse_ID = {".$userdata->course_id."}\n";
9633a423 97 } else {
d475f685 98 error('Sco not found');
99 }
100 }
101 break;
102 case 'putparam':
103 if ($status == 'Running') {
d475f685 104 echo "error = 0\nerror_text = Successful\n";
b5127f1e 105 } else if ($status == 'Terminated') {
106 echo "error = 1\nerror_text = Terminated\n";
107 } else {
108 echo "error = 1\nerror_text = Not Initialized\n";
d475f685 109 }
110 break;
111 case 'putcomments':
112 if ($status == 'Running') {
d475f685 113 echo "error = 0\nerror_text = Successful\n";
b5127f1e 114 } else if ($status == 'Terminated') {
115 echo "error = 1\nerror_text = Terminated\n";
116 } else {
117 echo "error = 1\nerror_text = Not Initialized\n";
9633a423 118 }
d475f685 119 break;
120 case 'putinteractions':
121 if ($status == 'Running') {
d475f685 122 echo "error = 0\nerror_text = Successful\n";
b5127f1e 123 } else if ($status == 'Terminated') {
124 echo "error = 1\nerror_text = Terminated\n";
125 } else {
126 echo "error = 1\nerror_text = Not Initialized\n";
d475f685 127 }
128 break;
129 case 'putobjectives':
130 if ($status == 'Running') {
d475f685 131 echo "error = 0\nerror_text = Successful\n";
b5127f1e 132 } else if ($status == 'Terminated') {
133 echo "error = 1\nerror_text = Terminated\n";
134 } else {
135 echo "error = 1\nerror_text = Not Initialized\n";
d475f685 136 }
137 break;
138 case 'putpath':
139 if ($status == 'Running') {
d475f685 140 echo "error = 0\nerror_text = Successful\n";
b5127f1e 141 } else if ($status == 'Terminated') {
142 echo "error = 1\nerror_text = Terminated\n";
143 } else {
144 echo "error = 1\nerror_text = Not Initialized\n";
d475f685 145 }
146 break;
147 case 'putperformance':
148 if ($status == 'Running') {
d475f685 149 echo "error = 0\nerror_text = Successful\n";
b5127f1e 150 } else if ($status == 'Terminated') {
151 echo "error = 1\nerror_text = Terminated\n";
152 } else {
153 echo "error = 1\nerror_text = Not Initialized\n";
d475f685 154 }
155 break;
156 case 'exitau':
157 if ($status == 'Running') {
158 $SESSION->scorm_status = 'Terminated';
159 echo "error = 0\nerror_text = Successful\n";
b5127f1e 160 } else if ($status == 'Terminated') {
161 echo "error = 1\nerror_text = Terminated\n";
162 } else {
163 echo "error = 1\nerror_text = Not Initialized\n";
d475f685 164 }
165 break;
b5127f1e 166 default:
167 echo "error = 1\nerror_text = Invalid Command\n";
168 break;
d475f685 169 }
9633a423 170 }
b5127f1e 171 } else {
172 if (empty($command)) {
173 echo "error = 1\nerror_text = Invalid Command\n";
174 } else {
175 echo "error = 3\nerror_text = Invalid Session ID\n";
176 }
ba5a7c6c 177 }
d475f685 178?>