MDL-28933 SCORM use a global function to check SCORM version to make sure all methods...
[moodle.git] / mod / scorm / userreport.php
CommitLineData
b4baa7fa 1<?php
2875714e
DM
2// This file is part of Moodle - http://moodle.org/
3//
4// Moodle is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// Moodle is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
62b82cbc 11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2875714e
DM
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
62b82cbc 15// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
2875714e
DM
16
17/**
62b82cbc
AKA
18* This page displays the user data from a single attempt
19*
20* @package mod
21* @subpackage scorm
22* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
23* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24*/
b4baa7fa
AKA
25
26require_once("../../config.php");
27require_once($CFG->dirroot.'/mod/scorm/locallib.php');
28
29$user = required_param('user', PARAM_INT); // User ID
30
31$id = optional_param('id', '', PARAM_INT); // Course Module ID, or
32$a = optional_param('a', '', PARAM_INT); // SCORM ID
33$b = optional_param('b', '', PARAM_INT); // SCO ID
34$attempt = optional_param('attempt', '1', PARAM_INT); // attempt number
35
b4baa7fa
AKA
36// Building the url to use for links.+ data details buildup
37$url = new moodle_url('/mod/scorm/userreport.php');
38$url->param('user', $user);
39
40if ($attempt !== '1') {
41 $url->param('attempt', $attempt);
42}
43
b4baa7fa
AKA
44if (!empty($id)) {
45 $url->param('id', $id);
46 $cm = get_coursemodule_from_id('scorm', $id, 0, false, MUST_EXIST);
47 $course = $DB->get_record('course', array('id'=>$cm->course), '*', MUST_EXIST);
48 $scorm = $DB->get_record('scorm', array('id'=>$cm->instance), '*', MUST_EXIST);
49} else {
50 if (!empty($b)) {
51 $url->param('b', $b);
52 $sco = $DB->get_record('scorm_scoes', array('id'=>$b), '*', MUST_EXIST);
53 $a = $sco->scorm;
54 }
55 if (!empty($a)) {
56 $url->param('a', $a);
57 $scorm = $DB->get_record('scorm', array('id'=>$a), '*', MUST_EXIST);
58 $course = $DB->get_record('course', array('id'=>$scorm->course), '*', MUST_EXIST);
59 $cm = get_coursemodule_from_instance('scorm', $scorm->id, $course->id, false, MUST_EXIST);
60 }
61}
62$PAGE->set_url($url);
63//END of url setting + data buildup
64
65// checking login +logging +getting context
66require_login($course->id, false, $cm);
2875714e
DM
67$contextmodule = get_context_instance(CONTEXT_MODULE, $cm->id);
68require_capability('mod/scorm:viewreport', $contextmodule);
69
b4baa7fa
AKA
70add_to_log($course->id, 'scorm', 'userreport', 'userreport.php?id='.$cm->id, $scorm->id, $cm->id);
71$userdata = scorm_get_user_data($user);
b4baa7fa
AKA
72
73// Print the page header
74$strreport = get_string('report', 'scorm');
75$strattempt = get_string('attempt', 'scorm');
76
b4baa7fa
AKA
77$PAGE->set_title("$course->shortname: ".format_string($scorm->name));
78$PAGE->set_heading($course->fullname);
79$PAGE->navbar->add($strreport, new moodle_url('/mod/scorm/report.php', array('id'=>$cm->id)));
80
81if (empty($b)) {
82 if (!empty($a)) {
83 $PAGE->navbar->add("$strattempt $attempt - ".fullname($userdata));
84 }
85} else {
86 $PAGE->navbar->add("$strattempt $attempt - ".fullname($userdata), new moodle_url('/mod/scorm/userreport.php', array('a'=>$a, 'user'=>$user, 'attempt'=>$attempt)));
87 $PAGE->navbar->add($sco->title);
88}
89echo $OUTPUT->header();
90echo $OUTPUT->heading(format_string($scorm->name));
91// End of Print the page header
92
2875714e 93//Parameter Checking
b4baa7fa
AKA
94if (empty ($userdata)) {
95 print_error('missingparameter');
96}
b4baa7fa
AKA
97
98//printing user details
99echo $OUTPUT->box_start('generalbox boxaligncenter');
100echo '<div class="mdl-align">'."\n";
101echo $OUTPUT->user_picture($userdata, array('courseid'=>$course->id));
102echo "<a href=\"$CFG->wwwroot/user/view.php?id=$user&amp;course=$course->id\">".
103 "$userdata->firstname $userdata->lastname</a><br />";
104echo get_string('attempt', 'scorm').': '.$attempt;
105echo '</div>'."\n";
106echo $OUTPUT->box_end();
107
b4baa7fa
AKA
108if ($scoes = $DB->get_records_select('scorm_scoes', "scorm=? ORDER BY id", array($scorm->id))) {
109 // Print general score data
110 $table = new html_table();
111 $table->head = array(
269c173e
EL
112 get_string('title', 'scorm'),
113 get_string('status', 'scorm'),
114 get_string('time', 'scorm'),
115 get_string('score', 'scorm'),
b4baa7fa
AKA
116 '');
117 $table->align = array('left', 'center', 'center', 'right', 'left');
118 $table->wrap = array('nowrap', 'nowrap', 'nowrap', 'nowrap', 'nowrap');
119 $table->width = '80%';
120 $table->size = array('*', '*', '*', '*', '*');
121 foreach ($scoes as $sco) {
122 if ($sco->launch!='') {
123 $row = array();
124 $score = '&nbsp;';
125 if ($trackdata = scorm_get_tracks($sco->id, $user, $attempt)) {
126 if ($trackdata->score_raw != '') {
127 $score = $trackdata->score_raw;
128 }
129 if ($trackdata->status == '') {
130 $trackdata->status = 'notattempted';
131 }
132 $detailslink = '<a href="userreport.php?b='.$sco->id.'&amp;user='.$user.'&amp;attempt='.$attempt.'" title="'.
133 get_string('details', 'scorm').'">'.get_string('details', 'scorm').'</a>';
134 } else {
135 $trackdata->status = 'notattempted';
136 $trackdata->total_time = '&nbsp;';
137 $detailslink = '&nbsp;';
138 }
139 $strstatus = get_string($trackdata->status, 'scorm');
140 $row[] = '<img src="'.$OUTPUT->pix_url($trackdata->status, 'scorm').'" alt="'.$strstatus.'" title="'.
141 $strstatus.'" />&nbsp;'.format_string($sco->title);
142 $row[] = get_string($trackdata->status, 'scorm');
143 $row[] = scorm_format_duration($trackdata->total_time);
144 $row[] = $score;
145 $row[] = $detailslink;
146 } else {
147 $row = array(format_string($sco->title), '&nbsp;', '&nbsp;', '&nbsp;', '&nbsp;');
148 }
149 $table->data[] = $row;
150 }
151 echo html_writer::table($table);
152}
153
154if (!empty($b)) {
155 echo $OUTPUT->box_start('generalbox boxaligncenter');
b4baa7fa
AKA
156 echo $OUTPUT->heading('<a href="'.$CFG->wwwroot.'/mod/scorm/player.php?a='.$scorm->id.'&amp;mode=browse&amp;scoid='.$sco->id.'" target="_new">'.format_string($sco->title).'</a>');
157 echo '<div class="mdl-align">'."\n";
158 $scoreview = '';
159 if ($trackdata = scorm_get_tracks($sco->id, $user, $attempt)) {
160 if ($trackdata->score_raw != '') {
161 $scoreview = get_string('score', 'scorm').':&nbsp;'.$trackdata->score_raw;
162 }
163 if ($trackdata->status == '') {
164 $trackdata->status = 'notattempted';
165 }
166 } else {
167 $trackdata->status = 'notattempted';
168 $trackdata->total_time = '';
169 }
170 $strstatus = get_string($trackdata->status, 'scorm');
171 echo '<img src="'.$OUTPUT->pix_url($trackdata->status, 'scorm').'" alt="'.$strstatus.'" title="'.
172 $strstatus.'" />&nbsp;'.scorm_format_duration($trackdata->total_time).'<br />'.$scoreview.'<br />';
173 echo '</div>'."\n";
174 echo '<hr /><h2>'.get_string('details', 'scorm').'</h2>';
175 // Print general score data
176 $table = new html_table();
177 $table->head = array(get_string('element', 'scorm'), get_string('value', 'scorm'));
178 $table->align = array('left', 'left');
179 $table->wrap = array('nowrap', 'nowrap');
180 $table->width = '100%';
181 $table->size = array('*', '*');
182 $existelements = false;
e6402b54 183 if (scorm_version_check($scorm->version, SCORM_13)) {
b4baa7fa 184 $elements = array(
269c173e
EL
185 'raw' => 'cmi.score.raw',
186 'min' => 'cmi.score.min',
187 'max' => 'cmi.score.max',
188 'status' => 'cmi.completion_status',
b4baa7fa
AKA
189 'time' => 'cmi.total_time');
190 } else {
191 $elements = array(
269c173e
EL
192 'raw' => 'cmi.core.score.raw',
193 'min' => 'cmi.core.score.min',
194 'max' => 'cmi.core.score.max',
195 'status' => 'cmi.core.lesson_status',
b4baa7fa
AKA
196 'time' => 'cmi.core.total_time');
197 }
198 $printedelements = array();
199 foreach ($elements as $key => $element) {
200 if (isset($trackdata->$element)) {
201 $existelements = true;
202 $printedelements[]=$element;
203 $row = array();
204 $row[] = get_string($key, 'scorm');
205 switch ($key) {
206 case 'status':
207 $row[] = $strstatus;
208 break;
209 case 'time':
210 $row[] = s(scorm_format_duration($trackdata->$element));
211 break;
212 default:
213 s($trackdata->$element);
214 break;
215 }
216 $table->data[] = $row;
217 }
218 }
219 if ($existelements) {
220 echo '<h3>'.get_string('general', 'scorm').'</h3>';
221 echo html_writer::table($table);
222 }
223 // Print Interactions data
224 $table = new html_table();
225 $table->head = array(
269c173e
EL
226 get_string('identifier', 'scorm'),
227 get_string('type', 'scorm'),
228 get_string('result', 'scorm'),
b4baa7fa
AKA
229 get_string('student_response', 'scorm'));
230 $table->align = array('center', 'center', 'center', 'center');
231 $table->wrap = array('nowrap', 'nowrap', 'nowrap', 'nowrap');
232 $table->width = '100%';
233 $table->size = array('*', '*', '*', '*', '*');
234 $existinteraction = false;
235 $i = 0;
236 $interactionid = 'cmi.interactions.'.$i.'.id';
237
238 while (isset($trackdata->$interactionid)) {
239 $existinteraction = true;
240 $printedelements[]=$interactionid;
241 $elements = array(
269c173e
EL
242 $interactionid,
243 'cmi.interactions.'.$i.'.type',
244 'cmi.interactions.'.$i.'.result',
b4baa7fa
AKA
245 'cmi.interactions.'.$i.'.learner_response');
246 $row = array();
247 foreach ($elements as $element) {
f7b5c6aa 248 if (isset($trackdata->$element)) {
b4baa7fa
AKA
249 $row[] = s($trackdata->$element);
250 $printedelements[]=$element;
251 } else {
252 $row[] = '&nbsp;';
253 }
254 }
255 $table->data[] = $row;
256 $i++;
257 $interactionid = 'cmi.interactions.'.$i.'.id';
258 }
259 if ($existinteraction) {
260 echo '<h3>'.get_string('interactions', 'scorm').'</h3>';
261 echo html_writer::table($table);
262 }
263
264 // Print Objectives data
265 $table = new html_table();
266 $table->head = array(
269c173e
EL
267 get_string('identifier', 'scorm'),
268 get_string('status', 'scorm'),
269 get_string('raw', 'scorm'),
270 get_string('min', 'scorm'),
b4baa7fa
AKA
271 get_string('max', 'scorm'));
272 $table->align = array('center', 'center', 'center', 'center', 'center');
273 $table->wrap = array('nowrap', 'nowrap', 'nowrap', 'nowrap', 'nowrap');
274 $table->width = '100%';
275 $table->size = array('*', '*', '*', '*', '*');
276 $existobjective = false;
277
278 $i = 0;
279 $objectiveid = 'cmi.objectives.'.$i.'.id';
280
281 while (isset($trackdata->$objectiveid)) {
282 $existobjective = true;
283 $printedelements[]=$objectiveid;
284 $elements = array(
269c173e
EL
285 $objectiveid,
286 'cmi.objectives.'.$i.'.status',
287 'cmi.objectives.'.$i.'.score.raw',
b4baa7fa
AKA
288 'cmi.objectives.'.$i.'.score.min',
289 'cmi.objectives.'.$i.'.score.max');
290 $row = array();
291 foreach ($elements as $element) {
292 if (isset($trackdata->$element)) {
293 $row[] = s($trackdata->$element);
294 $printedelements[]=$element;
295 } else {
296 $row[] = '&nbsp;';
297 }
298 }
299 $table->data[] = $row;
300
301 $i++;
302 $objectiveid = 'cmi.objectives.'.$i.'.id';
303 }
304 if ($existobjective) {
305 echo '<h3>'.get_string('objectives', 'scorm').'</h3>';
306 echo html_writer::table($table);
307 }
308 $table = new html_table();
309 $table->head = array(get_string('element', 'scorm'), get_string('value', 'scorm'));
310 $table->align = array('left', 'left');
311 $table->wrap = array('nowrap', 'wrap');
312 $table->width = '100%';
313 $table->size = array('*', '*');
314
315 $existelements = false;
316
f7b5c6aa 317 foreach ($trackdata as $element => $value) {
b4baa7fa
AKA
318 if (substr($element, 0, 3) == 'cmi') {
319 if (!(in_array ($element, $printedelements))) {
320 $existelements = true;
321 $row = array();
322 $row[] = get_string($element, 'scorm') != '[['.$element.']]' ? get_string($element, 'scorm') : $element;
323 if (strpos($element, '_time') === false) {
324 $row[] = s($value);
325 } else {
326 $row[] = s(scorm_format_duration($value));
327 }
328 $table->data[] = $row;
329 }
330 }
331 }
332 if ($existelements) {
333 echo '<h3>'.get_string('othertracks', 'scorm').'</h3>';
334 echo html_writer::table($table);
335 }
336 echo $OUTPUT->box_end();
337}
338// Print footer
339
269c173e 340echo $OUTPUT->footer();