MDL-40258: Fixed invalid json string error in file-picker
[moodle.git] / mod / scorm / userreport.php
blob3633b0411c02ddfad0182d27c76f9064d62967cb
1 <?php
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
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17 /**
18 * This page displays the user data from a single attempt
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
26 require_once("../../config.php");
27 require_once($CFG->dirroot.'/mod/scorm/locallib.php');
29 $user = required_param('user', PARAM_INT); // User ID
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
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);
40 if ($attempt !== '1') {
41 $url->param('attempt', $attempt);
44 if (!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 $selsco = $DB->get_record('scorm_scoes', array('id' => $b), '*', MUST_EXIST);
53 $a = $selsco->scorm;
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);
62 $PAGE->set_url($url);
63 //END of url setting + data buildup
65 // checking login +logging +getting context
66 require_login($course, false, $cm);
67 $contextmodule = get_context_instance(CONTEXT_MODULE, $cm->id);
68 require_capability('mod/scorm:viewreport', $contextmodule);
70 add_to_log($course->id, 'scorm', 'userreport', 'userreport.php?id='.$cm->id, $scorm->id, $cm->id);
71 $userdata = scorm_get_user_data($user);
73 // Print the page header
74 $strreport = get_string('report', 'scorm');
75 $strattempt = get_string('attempt', 'scorm');
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)));
81 if (empty($b)) {
82 if (!empty($a)) {
83 $PAGE->navbar->add("$strattempt $attempt - ".fullname($userdata));
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($selsco->title);
89 echo $OUTPUT->header();
90 echo $OUTPUT->heading(format_string($scorm->name));
91 // End of Print the page header
93 //Parameter Checking
94 if (empty ($userdata)) {
95 print_error('missingparameter');
98 //printing user details
99 echo $OUTPUT->box_start('generalbox boxaligncenter');
100 echo '<div class="mdl-align">'."\n";
101 echo $OUTPUT->user_picture($userdata, array('courseid'=>$course->id));
102 echo "<a href=\"$CFG->wwwroot/user/view.php?id=$user&amp;course=$course->id\">".
103 "$userdata->firstname $userdata->lastname</a><br />";
104 echo get_string('attempt', 'scorm').': '.$attempt;
105 echo '</div>'."\n";
106 echo $OUTPUT->box_end();
108 if ($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(
112 get_string('title', 'scorm'),
113 get_string('status', 'scorm'),
114 get_string('time', 'scorm'),
115 get_string('score', 'scorm'),
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;
129 if ($trackdata->status == '') {
130 $trackdata->status = 'notattempted';
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;';
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;');
149 $table->data[] = $row;
151 echo html_writer::table($table);
154 if (!empty($b)) {
155 echo $OUTPUT->box_start('generalbox boxaligncenter');
156 echo $OUTPUT->heading('<a href="'.$CFG->wwwroot.'/mod/scorm/player.php?a='.$scorm->id.'&amp;mode=browse&amp;scoid='.$selsco->id.'" target="_new">'.format_string($selsco->title).'</a>');
157 echo '<div class="mdl-align">'."\n";
158 $scoreview = '';
159 if ($trackdata = scorm_get_tracks($selsco->id, $user, $attempt)) {
160 if ($trackdata->score_raw != '') {
161 $scoreview = get_string('score', 'scorm').':&nbsp;'.$trackdata->score_raw;
163 if ($trackdata->status == '') {
164 $trackdata->status = 'notattempted';
166 } else {
167 $trackdata->status = 'notattempted';
168 $trackdata->total_time = '';
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;
183 if (scorm_version_check($scorm->version, SCORM_13)) {
184 $elements = array(
185 'raw' => 'cmi.score.raw',
186 'min' => 'cmi.score.min',
187 'max' => 'cmi.score.max',
188 'status' => 'cmi.completion_status',
189 'time' => 'cmi.total_time');
190 } else {
191 $elements = array(
192 'raw' => 'cmi.core.score.raw',
193 'min' => 'cmi.core.score.min',
194 'max' => 'cmi.core.score.max',
195 'status' => 'cmi.core.lesson_status',
196 'time' => 'cmi.core.total_time');
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 $row[] = s($trackdata->$element);
214 break;
216 $table->data[] = $row;
219 if ($existelements) {
220 echo '<h3>'.get_string('general', 'scorm').'</h3>';
221 echo html_writer::table($table);
223 // Print Interactions data
224 $table = new html_table();
225 $table->head = array(
226 get_string('identifier', 'scorm'),
227 get_string('type', 'scorm'),
228 get_string('result', 'scorm'),
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';
238 while (isset($trackdata->$interactionid)) {
239 $existinteraction = true;
240 $printedelements[]=$interactionid;
241 $elements = array(
242 $interactionid,
243 'cmi.interactions.'.$i.'.type',
244 'cmi.interactions.'.$i.'.result',
245 'cmi.interactions.'.$i.'.learner_response');
246 $row = array();
247 foreach ($elements as $element) {
248 if (isset($trackdata->$element)) {
249 $row[] = s($trackdata->$element);
250 $printedelements[]=$element;
251 } else {
252 $row[] = '&nbsp;';
255 $table->data[] = $row;
256 $i++;
257 $interactionid = 'cmi.interactions.'.$i.'.id';
259 if ($existinteraction) {
260 echo '<h3>'.get_string('interactions', 'scorm').'</h3>';
261 echo html_writer::table($table);
264 // Print Objectives data
265 $table = new html_table();
266 $table->head = array(
267 get_string('identifier', 'scorm'),
268 get_string('status', 'scorm'),
269 get_string('raw', 'scorm'),
270 get_string('min', 'scorm'),
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;
278 $i = 0;
279 $objectiveid = 'cmi.objectives.'.$i.'.id';
281 while (isset($trackdata->$objectiveid)) {
282 $existobjective = true;
283 $printedelements[]=$objectiveid;
284 $elements = array(
285 $objectiveid,
286 'cmi.objectives.'.$i.'.status',
287 'cmi.objectives.'.$i.'.score.raw',
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;';
299 $table->data[] = $row;
301 $i++;
302 $objectiveid = 'cmi.objectives.'.$i.'.id';
304 if ($existobjective) {
305 echo '<h3>'.get_string('objectives', 'scorm').'</h3>';
306 echo html_writer::table($table);
308 $table = new html_table();
309 $table->head = array(get_string('element', 'scorm'), get_string('elementdefinition', '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('*', '*');
315 $existelements = false;
317 foreach ($trackdata as $element => $value) {
318 if (substr($element, 0, 3) == 'cmi') {
319 if (!(in_array ($element, $printedelements))) {
320 $existelements = true;
321 $row = array();
322 $string=false;
323 if (stristr($element, '.id') !== false) {
324 $string="interactionsid";
325 } else if (stristr($element, '.result') !== false) {
326 $string="interactionsresult";
327 } else if (stristr($element, '.student_response') !== false) {
328 $string="interactionsresponse";
329 } else if (stristr($element, '.type') !== false) {
330 $string="interactionstype";
331 } else if (stristr($element, '.weighting') !== false) {
332 $string="interactionsweight";
333 } else if (stristr($element, '.time') !== false) {
334 $string="interactionstime";
335 } else if (stristr($element, '.correct_responses._count') !== false) {
336 $string="interactionscorrectcount";
337 } else if (stristr($element, '.learner_response') !== false) {
338 $string="interactionslearnerresponse";
339 } else if (stristr($element, '.score.min') !== false) {
340 $string="interactionsscoremin";
341 } else if (stristr($element, '.score.max') !== false) {
342 $string="interactionsscoremax";
343 } else if (stristr($element, '.score.raw') !== false) {
344 $string="interactionsscoreraw";
345 } else if (stristr($element, '.latency') !== false) {
346 $string="interactionslatency";
347 } else if (stristr($element, '.pattern') !== false) {
348 $string="interactionspattern";
349 } else if (stristr($element, '.suspend_data') !== false) {
350 $string="interactionssuspenddata";
352 $row[]=$element;
353 if (empty($string)) {
354 $row[]=null;
355 } else {
356 $row[] = get_string($string, 'scorm');
358 if (strpos($element, '_time') === false) {
359 $row[] = s($value);
360 } else {
361 $row[] = s(scorm_format_duration($value));
363 $table->data[] = $row;
367 if ($existelements) {
368 echo '<h3>'.get_string('othertracks', 'scorm').'</h3>';
369 echo html_writer::table($table);
371 echo $OUTPUT->box_end();
373 // Print footer
375 echo $OUTPUT->footer();