changed all the POST with option/required_param functions
[moodle.git] / mod / scorm / aicc.php
1 <?php
2     require_once('../../config.php');
3     require_once('lib.php');
5     $command = required_param('command', '', PARAM_ALPHA);
6     $sessionid = required_param('session_id', '', PARAM_ALPHA);
8     require_login($course->id, false, $cm);
9     
10     if (!empty($command) && confirm_sesskey($sessionid)) {
11         $command = strtolower($command);
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         }
22         $status = 'Not Initialized';
23         if (isset($SESSION->scorm_status)) {
24             $status = $SESSION->scorm_status;
25         }
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         }
34         if ($scorm = get_record('scorm','id',$sco->scorm)) {
35             switch ($command) {
36                 case 'getparam':
37                     if ($status == 'Not Initialized') {
38                         $SESSION->scorm_status = 'Running';
39                         $status = 'Running';
40                     }
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 = '';
48                             $userdata->score_raw = '';
49                         }
50                         $userdata->student_id = $USER->username;
51                         $userdata->student_name = $USER->lastname .', '. $USER->firstname;
52                         $userdata->mode = $mode;
53                 
54                         if ($sco = get_record('scorm_scoes','id',$scoid)) {
55                             $userdata->course_id = $sco->identifier;
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";
96                             echo "[Evaluation]\nCourse_ID = {".$userdata->course_id."}\n";
97                         } else {
98                             error('Sco not found');
99                         }
100                     }
101                 break;
102                 case 'putparam':
103                     if ($status == 'Running') {
104                         echo "error = 0\nerror_text = Successful\n";
105                     } else if ($status == 'Terminated') {
106                         echo "error = 1\nerror_text = Terminated\n";
107                     } else {
108                         echo "error = 1\nerror_text = Not Initialized\n";
109                     }
110                 break;
111                 case 'putcomments':
112                     if ($status == 'Running') {
113                         echo "error = 0\nerror_text = Successful\n";
114                     } else if ($status == 'Terminated') {
115                         echo "error = 1\nerror_text = Terminated\n";
116                     } else {
117                         echo "error = 1\nerror_text = Not Initialized\n";
118                     }
119                 break;
120                 case 'putinteractions':
121                     if ($status == 'Running') {
122                         echo "error = 0\nerror_text = Successful\n";
123                     } else if ($status == 'Terminated') {
124                         echo "error = 1\nerror_text = Terminated\n";
125                     } else {
126                         echo "error = 1\nerror_text = Not Initialized\n";
127                     }
128                 break;
129                 case 'putobjectives':
130                     if ($status == 'Running') {
131                         echo "error = 0\nerror_text = Successful\n";
132                     } else if ($status == 'Terminated') {
133                         echo "error = 1\nerror_text = Terminated\n";
134                     } else {
135                         echo "error = 1\nerror_text = Not Initialized\n";
136                     }
137                 break;
138                 case 'putpath':
139                     if ($status == 'Running') {
140                         echo "error = 0\nerror_text = Successful\n";
141                     } else if ($status == 'Terminated') {
142                         echo "error = 1\nerror_text = Terminated\n";
143                     } else {
144                         echo "error = 1\nerror_text = Not Initialized\n";
145                     }
146                 break;
147                 case 'putperformance':
148                     if ($status == 'Running') {
149                         echo "error = 0\nerror_text = Successful\n";
150                     } else if ($status == 'Terminated') {
151                         echo "error = 1\nerror_text = Terminated\n";
152                     } else {
153                         echo "error = 1\nerror_text = Not Initialized\n";
154                     }
155                 break;
156                 case 'exitau':
157                     if ($status == 'Running') {
158                         $SESSION->scorm_status = 'Terminated';                  
159                         echo "error = 0\nerror_text = Successful\n";
160                     } else if ($status == 'Terminated') {
161                         echo "error = 1\nerror_text = Terminated\n";
162                     } else {
163                         echo "error = 1\nerror_text = Not Initialized\n";
164                     }
165                 break;
166                 default:
167                     echo "error = 1\nerror_text = Invalid Command\n";
168                 break;
169             }
170         }
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         }
177     }
178 ?>