MDL-40259 - For SCORM reports limit fields returned from
[moodle.git] / mod / scorm / report / interactions / report.php
CommitLineData
8fb40a45
AKA
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.
13//
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/>.
16/**
17 * Core Report class of basic reporting plugin
b2f5ce35
AKA
18 * @package scormreport
19 * @subpackage interactions
8fb40a45
AKA
20 * @author Dan Marsden and Ankit Kumar Agarwal
21 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
22 */
23
24defined('MOODLE_INTERNAL') || die();
25
26require_once($CFG->dirroot.'/mod/scorm/report/interactions/responsessettings_form.php');
27
28class scorm_interactions_report extends scorm_default_report {
29 /**
30 * displays the full report
31 * @param stdClass $scorm full SCORM object
32 * @param stdClass $cm - full course_module object
33 * @param stdClass $course - full course object
34 * @param string $download - type of download being requested
35 */
36 function display($scorm, $cm, $course, $download) {
37 global $CFG, $DB, $OUTPUT, $PAGE;
2ceaefb4 38
b2f5ce35 39 $contextmodule = get_context_instance(CONTEXT_MODULE, $cm->id);
8fb40a45 40 $action = optional_param('action', '', PARAM_ALPHA);
f9ab70a9 41 $attemptids = optional_param_array('attemptid', array(), PARAM_RAW);
b27917ee
DM
42 $attemptsmode = optional_param('attemptsmode', SCORM_REPORT_ATTEMPTS_ALL_STUDENTS, PARAM_INT);
43 $PAGE->set_url(new moodle_url($PAGE->url, array('attemptsmode' => $attemptsmode)));
8fb40a45
AKA
44
45 if ($action == 'delete' && has_capability('mod/scorm:deleteresponses', $contextmodule) && confirm_sesskey()) {
46 if (scorm_delete_responses($attemptids, $scorm)) { //delete responses.
47 add_to_log($course->id, 'scorm', 'delete attempts', 'report.php?id=' . $cm->id, implode(",", $attemptids), $cm->id);
48 echo $OUTPUT->notification(get_string('scormresponsedeleted', 'scorm'), 'notifysuccess');
49 }
50 }
6073fcbe
AKA
51 // find out current groups mode
52 $currentgroup = groups_get_activity_group($cm, true);
8fb40a45
AKA
53
54 // detailed report
55 $mform = new mod_scorm_report_interactions_settings($PAGE->url, compact('currentgroup'));
56 if ($fromform = $mform->get_data()) {
8fb40a45
AKA
57 $pagesize = $fromform->pagesize;
58 $includeqtext = $fromform->qtext;
59 $includeresp = $fromform->resp;
60 $includeright = $fromform->right;
8fb40a45
AKA
61 set_user_preference('scorm_report_pagesize', $pagesize);
62 set_user_preference('scorm_report_interactions_qtext', $includeqtext);
63 set_user_preference('scorm_report_interactions_resp', $includeresp);
64 set_user_preference('scorm_report_interactions_right', $includeright);
65 } else {
8fb40a45 66 $pagesize = get_user_preferences('scorm_report_pagesize', 0);
8fb40a45
AKA
67 $includeqtext = get_user_preferences('scorm_report_interactions_qtext', 0);
68 $includeresp = get_user_preferences('scorm_report_interactions_resp', 1);
69 $includeright = get_user_preferences('scorm_report_interactions_right', 0);
70 }
71 if ($pagesize < 1) {
72 $pagesize = SCORM_REPORT_DEFAULT_PAGE_SIZE;
73 }
74
75 // select group menu
76 $displayoptions = array();
77 $displayoptions['attemptsmode'] = $attemptsmode;
78 $displayoptions['qtext'] = $includeqtext;
79 $displayoptions['resp'] = $includeresp;
80 $displayoptions['right'] = $includeright;
3297bb1a 81
11359796 82 $mform->set_data($displayoptions + array('pagesize' => $pagesize));
8fb40a45
AKA
83 if ($groupmode = groups_get_activity_groupmode($cm)) { // Groups are being used
84 if (!$download) {
85 groups_print_activity_menu($cm, new moodle_url($PAGE->url, $displayoptions));
86 }
87 }
b2f5ce35 88 $formattextoptions = array('context' => get_context_instance(CONTEXT_COURSE, $course->id));
8fb40a45
AKA
89
90 // We only want to show the checkbox to delete attempts
91 // if the user has permissions and if the report mode is showing attempts.
92 $candelete = has_capability('mod/scorm:deleteresponses', $contextmodule)
b2f5ce35 93 && ($attemptsmode != SCORM_REPORT_ATTEMPTS_STUDENTS_WITH_NO);
8fb40a45
AKA
94 // select the students
95 $nostudents = false;
96
97 if (empty($currentgroup)) {
98 // all users who can attempt scoes
66d00225 99 if (!$students = get_users_by_capability($contextmodule, 'mod/scorm:savetrack', 'u.id', '', '', '', '', '', false)) {
8fb40a45
AKA
100 echo $OUTPUT->notification(get_string('nostudentsyet'));
101 $nostudents = true;
102 $allowedlist = '';
103 } else {
7def307d 104 $allowedlist = array_keys($students);
8fb40a45 105 }
66d00225 106 unset($students);
8fb40a45
AKA
107 } else {
108 // all users who can attempt scoes and who are in the currently selected group
66d00225 109 if (!$groupstudents = get_users_by_capability($contextmodule, 'mod/scorm:savetrack', 'u.id', '', '', '', $currentgroup, '', false)) {
8fb40a45
AKA
110 echo $OUTPUT->notification(get_string('nostudentsingroup'));
111 $nostudents = true;
112 $groupstudents = array();
113 }
6073fcbe 114 $allowedlist = array_keys($groupstudents);
66d00225 115 unset($groupstudents);
8fb40a45 116 }
8fb40a45
AKA
117 if ( !$nostudents ) {
118 // Now check if asked download of data
63480434 119 $coursecontext = context_course::instance($course->id);
8fb40a45 120 if ($download) {
35540ec5 121 $filename = clean_filename("$course->shortname ".format_string($scorm->name, true,$formattextoptions));
8fb40a45
AKA
122 }
123
124 // Define table columns
125 $columns = array();
126 $headers = array();
127 if (!$download && $candelete) {
b2f5ce35
AKA
128 $columns[] = 'checkbox';
129 $headers[] = null;
8fb40a45
AKA
130 }
131 if (!$download && $CFG->grade_report_showuserimage) {
b2f5ce35
AKA
132 $columns[] = 'picture';
133 $headers[] = '';
8fb40a45 134 }
b2f5ce35
AKA
135 $columns[] = 'fullname';
136 $headers[] = get_string('name');
63480434
AKA
137
138 $extrafields = get_extra_user_fields($coursecontext);
139 foreach ($extrafields as $field) {
140 $columns[] = $field;
141 $headers[] = get_user_field_name($field);
8fb40a45 142 }
b2f5ce35
AKA
143 $columns[] = 'attempt';
144 $headers[] = get_string('attempt', 'scorm');
145 $columns[] = 'start';
146 $headers[] = get_string('started', 'scorm');
147 $columns[] = 'finish';
148 $headers[] = get_string('last', 'scorm');
149 $columns[] = 'score';
150 $headers[] = get_string('score', 'scorm');
151 $scoes = $DB->get_records('scorm_scoes', array("scorm"=>$scorm->id), 'id');
152 foreach ($scoes as $sco) {
153 if ($sco->launch != '') {
154 $columns[] = 'scograde'.$sco->id;
155 $headers[] = format_string($sco->title,'',$formattextoptions);
8fb40a45 156 }
8fb40a45 157 }
b2f5ce35 158
7def307d 159 $params = array();
bbe5bad5 160 list($usql, $params) = $DB->get_in_or_equal($allowedlist, SQL_PARAMS_NAMED);
c03d2b75
AKA
161 // Construct the SQL
162 $select = 'SELECT DISTINCT '.$DB->sql_concat('u.id', '\'#\'', 'COALESCE(st.attempt, 0)').' AS uniqueid, ';
163 $select .= 'st.scormid AS scormid, st.attempt AS attempt, ' .
63480434 164 'u.id AS userid, u.idnumber, u.firstname, u.lastname, u.picture, u.imagealt, u.email'.
2ceaefb4 165 get_extra_user_fields_sql($coursecontext, 'u', '', array('email', 'idnumber')) . ' ';
c03d2b75
AKA
166
167 // This part is the same for all cases - join users and scorm_scoes_track tables
168 $from = 'FROM {user} u ';
169 $from .= 'LEFT JOIN {scorm_scoes_track} st ON st.userid = u.id AND st.scormid = '.$scorm->id;
170 switch ($attemptsmode) {
171 case SCORM_REPORT_ATTEMPTS_STUDENTS_WITH:
172 // Show only students with attempts
7def307d 173 $where = ' WHERE u.id ' .$usql. ' AND st.userid IS NOT NULL';
c03d2b75
AKA
174 break;
175 case SCORM_REPORT_ATTEMPTS_STUDENTS_WITH_NO:
176 // Show only students without attempts
7def307d 177 $where = ' WHERE u.id ' .$usql. ' AND st.userid IS NULL';
c03d2b75
AKA
178 break;
179 case SCORM_REPORT_ATTEMPTS_ALL_STUDENTS:
180 // Show all students with or without attempts
7def307d 181 $where = ' WHERE u.id ' .$usql. ' AND (st.userid IS NOT NULL OR st.userid IS NULL)';
c03d2b75
AKA
182 break;
183 }
184
185 $countsql = 'SELECT COUNT(DISTINCT('.$DB->sql_concat('u.id', '\'#\'', 'COALESCE(st.attempt, 0)').')) AS nbresults, ';
186 $countsql .= 'COUNT(DISTINCT('.$DB->sql_concat('u.id', '\'#\'', 'st.attempt').')) AS nbattempts, ';
187 $countsql .= 'COUNT(DISTINCT(u.id)) AS nbusers ';
188 $countsql .= $from.$where;
3ab853fa 189 $questioncount = get_scorm_question_count($scorm->id);
65ab8112 190 $nbmaincolumns = count($columns);
b2f5ce35 191 for($id = 0; $id < $questioncount; $id++) {
8fb40a45
AKA
192 if ($displayoptions['qtext']) {
193 $columns[] = 'question' . $id;
194 $headers[] = get_string('questionx', 'scormreport_interactions', $id);
195 }
196 if ($displayoptions['resp']) {
197 $columns[] = 'response' . $id;
198 $headers[] = get_string('responsex', 'scormreport_interactions', $id);
199 }
200 if ($displayoptions['right']) {
201 $columns[] = 'right' . $id;
202 $headers[] = get_string('rightanswerx', 'scormreport_interactions', $id);
203 }
204 }
205
206 if (!$download) {
207 $table = new flexible_table('mod-scorm-report');
208
209 $table->define_columns($columns);
210 $table->define_headers($headers);
211 $table->define_baseurl($PAGE->url);
212
213 $table->sortable(true);
214 $table->collapsible(true);
215
e12459ba 216 // This is done to prevent redundant data, when a user has multiple attempts
8fb40a45
AKA
217 $table->column_suppress('picture');
218 $table->column_suppress('fullname');
63480434
AKA
219 foreach ($extrafields as $field) {
220 $table->column_suppress($field);
221 }
8fb40a45
AKA
222
223 $table->no_sorting('start');
224 $table->no_sorting('finish');
225 $table->no_sorting('score');
e7ec46fc 226
8119fbd7
AA
227 for($id = 0; $id < $questioncount; $id++) {
228 if ($displayoptions['qtext']) {
229 $table->no_sorting('question'.$id);
230 }
231 if ($displayoptions['resp']) {
232 $table->no_sorting('response'.$id);
233 }
234 if ($displayoptions['right']) {
235 $table->no_sorting('right'.$id);
236 }
237 }
238
b2f5ce35
AKA
239 foreach ($scoes as $sco) {
240 if ($sco->launch != '') {
241 $table->no_sorting('scograde'.$sco->id);
8fb40a45
AKA
242 }
243 }
244
245 $table->column_class('picture', 'picture');
246 $table->column_class('fullname', 'bold');
247 $table->column_class('score', 'bold');
248
249 $table->set_attribute('cellspacing', '0');
250 $table->set_attribute('id', 'attempts');
251 $table->set_attribute('class', 'generaltable generalbox');
252
253 // Start working -- this is necessary as soon as the niceties are over
254 $table->setup();
b2f5ce35 255 } else if ($download == 'ODS') {
8fb40a45
AKA
256 require_once("$CFG->libdir/odslib.class.php");
257
258 $filename .= ".ods";
259 // Creating a workbook
260 $workbook = new MoodleODSWorkbook("-");
261 // Sending HTTP headers
262 $workbook->send($filename);
263 // Creating the first worksheet
264 $sheettitle = get_string('report', 'scorm');
a530b69d 265 $myxls = $workbook->add_worksheet($sheettitle);
8fb40a45 266 // format types
a530b69d 267 $format = $workbook->add_format();
8fb40a45 268 $format->set_bold(0);
a530b69d 269 $formatbc = $workbook->add_format();
8fb40a45
AKA
270 $formatbc->set_bold(1);
271 $formatbc->set_align('center');
a530b69d 272 $formatb = $workbook->add_format();
8fb40a45 273 $formatb->set_bold(1);
a530b69d 274 $formaty = $workbook->add_format();
8fb40a45 275 $formaty->set_bg_color('yellow');
a530b69d 276 $formatc = $workbook->add_format();
8fb40a45 277 $formatc->set_align('center');
a530b69d 278 $formatr = $workbook->add_format();
8fb40a45
AKA
279 $formatr->set_bold(1);
280 $formatr->set_color('red');
281 $formatr->set_align('center');
a530b69d 282 $formatg = $workbook->add_format();
8fb40a45
AKA
283 $formatg->set_bold(1);
284 $formatg->set_color('green');
285 $formatg->set_align('center');
286 // Here starts workshhet headers
287
288 $colnum = 0;
289 foreach ($headers as $item) {
290 $myxls->write(0, $colnum, $item, $formatbc);
291 $colnum++;
292 }
b2f5ce35 293 $rownum = 1;
8fb40a45
AKA
294 } else if ($download =='Excel') {
295 require_once("$CFG->libdir/excellib.class.php");
296
297 $filename .= ".xls";
298 // Creating a workbook
299 $workbook = new MoodleExcelWorkbook("-");
300 // Sending HTTP headers
301 $workbook->send($filename);
302 // Creating the first worksheet
303 $sheettitle = get_string('report', 'scorm');
a530b69d 304 $myxls = $workbook->add_worksheet($sheettitle);
8fb40a45 305 // format types
a530b69d 306 $format = $workbook->add_format();
8fb40a45 307 $format->set_bold(0);
a530b69d 308 $formatbc = $workbook->add_format();
8fb40a45
AKA
309 $formatbc->set_bold(1);
310 $formatbc->set_align('center');
a530b69d 311 $formatb = $workbook->add_format();
8fb40a45 312 $formatb->set_bold(1);
a530b69d 313 $formaty = $workbook->add_format();
8fb40a45 314 $formaty->set_bg_color('yellow');
a530b69d 315 $formatc = $workbook->add_format();
8fb40a45 316 $formatc->set_align('center');
a530b69d 317 $formatr = $workbook->add_format();
8fb40a45
AKA
318 $formatr->set_bold(1);
319 $formatr->set_color('red');
320 $formatr->set_align('center');
a530b69d 321 $formatg = $workbook->add_format();
8fb40a45
AKA
322 $formatg->set_bold(1);
323 $formatg->set_color('green');
324 $formatg->set_align('center');
325
326 $colnum = 0;
327 foreach ($headers as $item) {
328 $myxls->write(0, $colnum, $item, $formatbc);
329 $colnum++;
330 }
b2f5ce35
AKA
331 $rownum = 1;
332 } else if ($download == 'CSV') {
8fb40a45
AKA
333 $filename .= ".txt";
334 header("Content-Type: application/download\n");
335 header("Content-Disposition: attachment; filename=\"$filename\"");
336 header("Expires: 0");
337 header("Cache-Control: must-revalidate,post-check=0,pre-check=0");
338 header("Pragma: public");
339 echo implode("\t", $headers)." \n";
340 }
8fb40a45
AKA
341
342 if (!$download) {
343 $sort = $table->get_sql_sort();
344 } else {
345 $sort = '';
346 }
347 // Fix some wired sorting
348 if (empty($sort)) {
349 $sort = ' ORDER BY uniqueid';
350 } else {
351 $sort = ' ORDER BY '.$sort;
352 }
353
354 if (!$download) {
355 // Add extra limits due to initials bar
356 list($twhere, $tparams) = $table->get_sql_where();
357 if ($twhere) {
358 $where .= ' AND '.$twhere; //initial bar
359 $params = array_merge($params, $tparams);
360 }
361
362 if (!empty($countsql)) {
7def307d 363 $count = $DB->get_record_sql($countsql,$params);
8fb40a45
AKA
364 $totalinitials = $count->nbresults;
365 if ($twhere) {
366 $countsql .= ' AND '.$twhere;
367 }
368 $count = $DB->get_record_sql($countsql, $params);
369 $total = $count->nbresults;
370 }
371
372 $table->pagesize($pagesize, $total);
373
374 echo '<div class="quizattemptcounts">';
375 if ( $count->nbresults == $count->nbattempts ) {
376 echo get_string('reportcountattempts', 'scorm', $count);
377 } else if ( $count->nbattempts>0 ) {
378 echo get_string('reportcountallattempts', 'scorm', $count);
379 } else {
380 echo $count->nbusers.' '.get_string('users');
381 }
382 echo '</div>';
383 }
384
385 // Fetch the attempts
386 if (!$download) {
387 $attempts = $DB->get_records_sql($select.$from.$where.$sort, $params,
388 $table->get_page_start(), $table->get_page_size());
389 echo '<div id="scormtablecontainer">';
390 if ($candelete) {
391 // Start form
392 $strreallydel = addslashes_js(get_string('deleteattemptcheck', 'scorm'));
393 echo '<form id="attemptsform" method="post" action="' . $PAGE->url->out(false) .
394 '" onsubmit="return confirm(\''.$strreallydel.'\');">';
395 echo '<input type="hidden" name="action" value="delete"/>';
396 echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
397 echo '<div style="display: none;">';
398 echo html_writer::input_hidden_params($PAGE->url);
399 echo '</div>';
400 echo '<div>';
401 }
402 $table->initialbars($totalinitials>20); // Build table rows
403 } else {
404 $attempts = $DB->get_records_sql($select.$from.$where.$sort, $params);
405 }
8fb40a45
AKA
406 if ($attempts) {
407 foreach ($attempts as $scouser) {
408 $row = array();
409 if (!empty($scouser->attempt)) {
410 $timetracks = scorm_get_sco_runtime($scorm->id, false, $scouser->userid, $scouser->attempt);
49ff0cf3
DM
411 } else {
412 $timetracks = '';
8fb40a45
AKA
413 }
414 if (in_array('checkbox', $columns)) {
415 if ($candelete && !empty($timetracks->start)) {
416 $row[] = '<input type="checkbox" name="attemptid[]" value="'. $scouser->userid . ':' . $scouser->attempt . '" />';
417 } else if ($candelete) {
418 $row[] = '';
419 }
420 }
421 if (in_array('picture', $columns)) {
422 $user = (object)array(
423 'id'=>$scouser->userid,
424 'picture'=>$scouser->picture,
425 'imagealt'=>$scouser->imagealt,
426 'email'=>$scouser->email,
427 'firstname'=>$scouser->firstname,
428 'lastname'=>$scouser->lastname);
429 $row[] = $OUTPUT->user_picture($user, array('courseid'=>$course->id));
430 }
431 if (!$download) {
432 $row[] = '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$scouser->userid.'&amp;course='.$course->id.'">'.fullname($scouser).'</a>';
433 } else {
434 $row[] = fullname($scouser);
435 }
63480434
AKA
436 foreach ($extrafields as $field) {
437 $row[] = s($scouser->{$field});
8fb40a45
AKA
438 }
439 if (empty($timetracks->start)) {
440 $row[] = '-';
441 $row[] = '-';
442 $row[] = '-';
443 $row[] = '-';
444 } else {
445 if (!$download) {
446 $row[] = '<a href="userreport.php?a='.$scorm->id.'&amp;user='.$scouser->userid.'&amp;attempt='.$scouser->attempt.'">'.$scouser->attempt.'</a>';
447 } else {
448 $row[] = $scouser->attempt;
449 }
450 if ($download =='ODS' || $download =='Excel' ) {
451 $row[] = userdate($timetracks->start, get_string("strftimedatetime", "langconfig"));
452 } else {
453 $row[] = userdate($timetracks->start);
454 }
455 if ($download =='ODS' || $download =='Excel' ) {
456 $row[] = userdate($timetracks->finish, get_string('strftimedatetime', 'langconfig'));
457 } else {
458 $row[] = userdate($timetracks->finish);
459 }
460 $row[] = scorm_grade_user_attempt($scorm, $scouser->userid, $scouser->attempt);
461 }
b2f5ce35
AKA
462 // print out all scores of attempt
463 foreach ($scoes as $sco) {
464 if ($sco->launch != '') {
465 if ($trackdata = scorm_get_tracks($sco->id, $scouser->userid, $scouser->attempt)) {
466 if ($trackdata->status == '') {
467 $trackdata->status = 'notattempted';
468 }
469 $strstatus = get_string($trackdata->status, 'scorm');
470 // if raw score exists, print it
471 if ($trackdata->score_raw != '') {
472 $score = $trackdata->score_raw;
473 // add max score if it exists
474 if ($scorm->version == 'SCORM_1.3') {
475 $maxkey = 'cmi.score.max';
8fb40a45 476 } else {
b2f5ce35 477 $maxkey = 'cmi.core.score.max';
8fb40a45 478 }
b2f5ce35
AKA
479 if (isset($trackdata->$maxkey)) {
480 $score .= '/'.$trackdata->$maxkey;
8fb40a45 481 }
b2f5ce35
AKA
482 // else print out status
483 } else {
484 $score = $strstatus;
485 }
486 if (!$download) {
487 $row[] = '<img src="'.$OUTPUT->pix_url($trackdata->status, 'scorm').'" alt="'.$strstatus.'" title="'.$strstatus.'" /><br/>
488 <a href="userreport.php?b='.$sco->id.'&amp;user='.$scouser->userid.'&amp;attempt='.$scouser->attempt.
489 '" title="'.get_string('details', 'scorm').'">'.$score.'</a>';
490 } else {
491 $row[] = $score;
492 }
493 // interaction data
65ab8112 494 for ($i=0; $i < $questioncount; $i++) {
b2f5ce35
AKA
495 if ($displayoptions['qtext']) {
496 $element='cmi.interactions_'.$i.'.id';
497 if (isset($trackdata->$element)) {
498 $row[] = s($trackdata->$element);
499 } else {
500 $row[] = '&nbsp;';
11359796 501 }
b2f5ce35
AKA
502 }
503 if ($displayoptions['resp']) {
504 $element='cmi.interactions_'.$i.'.student_response';
505 if (isset($trackdata->$element)) {
506 $row[] = s($trackdata->$element);
507 } else {
508 $row[] = '&nbsp;';
11359796 509 }
b2f5ce35
AKA
510 }
511 if ($displayoptions['right']) {
512 $j=0;
513 $element = 'cmi.interactions_'.$i.'.correct_responses_'.$j.'.pattern';
514 $rightans = '';
515 if (isset($trackdata->$element)) {
516 while(isset($trackdata->$element)) {
517 if($j>0) {
518 $rightans .= ',';
11359796 519 }
b2f5ce35
AKA
520 $rightans .= s($trackdata->$element);
521 $j++;
522 $element = 'cmi.interactions_'.$i.'.correct_responses_'.$j.'.pattern';
11359796 523 }
b2f5ce35
AKA
524 $row[] = $rightans;
525 } else {
526 $row[] = '&nbsp;';
11359796 527 }
11359796 528 }
b2f5ce35
AKA
529 }
530 //---end of interaction data*/
531 } else {
532 // if we don't have track data, we haven't attempted yet
533 $strstatus = get_string('notattempted', 'scorm');
534 if (!$download) {
535 $row[] = '<img src="'.$OUTPUT->pix_url('notattempted', 'scorm').'" alt="'.$strstatus.'" title="'.$strstatus.'" /><br/>'.$strstatus;
8fb40a45 536 } else {
b2f5ce35 537 $row[] = $strstatus;
8fb40a45 538 }
65ab8112
GPL
539 // complete the empty cells
540 for ($i=0; $i < count($columns) - $nbmaincolumns; $i++) {
541 $row[] = '&nbsp;';
542 }
8fb40a45
AKA
543 }
544 }
545 }
546
547 if (!$download) {
548 $table->add_data($row);
549 } else if ($download == 'Excel' or $download == 'ODS') {
550 $colnum = 0;
551 foreach ($row as $item) {
552 $myxls->write($rownum, $colnum, $item, $format);
553 $colnum++;
554 }
555 $rownum++;
b2f5ce35 556 } else if ($download == 'CSV') {
8fb40a45
AKA
557 $text = implode("\t", $row);
558 echo $text." \n";
559 }
560 }
561 if (!$download) {
562 $table->finish_output();
563 if ($candelete) {
564 echo '<table id="commands">';
565 echo '<tr><td>';
566 echo '<a href="javascript:select_all_in(\'DIV\', null, \'scormtablecontainer\');">'.
567 get_string('selectall', 'scorm').'</a> / ';
568 echo '<a href="javascript:deselect_all_in(\'DIV\', null, \'scormtablecontainer\');">'.
569 get_string('selectnone', 'scorm').'</a> ';
570 echo '&nbsp;&nbsp;';
571 echo '<input type="submit" value="'.get_string('deleteselected', 'quiz_overview').'"/>';
572 echo '</td></tr></table>';
573 // Close form
574 echo '</div>';
575 echo '</form>';
576 }
577 echo '</div>';
578 if (!empty($attempts)) {
579 echo '<table class="boxaligncenter"><tr>';
580 echo '<td>';
581 echo $OUTPUT->single_button(new moodle_url($PAGE->url,
582 array('download'=>'ODS') + $displayoptions),
583 get_string('downloadods'));
584 echo "</td>\n";
585 echo '<td>';
586 echo $OUTPUT->single_button(new moodle_url($PAGE->url,
587 array('download'=>'Excel') + $displayoptions),
588 get_string('downloadexcel'));
589 echo "</td>\n";
590 echo '<td>';
591 echo $OUTPUT->single_button(new moodle_url($PAGE->url,
592 array('download'=>'CSV') + $displayoptions),
593 get_string('downloadtext'));
594 echo "</td>\n";
595 echo "<td>";
596 echo "</td>\n";
597 echo '</tr></table>';
598 }
599 }
8fb40a45 600 } else {
769a621d
AKA
601 if ($candelete && !$download) {
602 echo '</div>';
603 echo '</form>';
85e976e5 604 $table->finish_output();
769a621d
AKA
605 }
606 echo '</div>';
85e976e5
AKA
607 }
608 // Show preferences form irrespective of attempts are there to report or not
609 if (!$download) {
610 $mform->set_data(compact('detailedrep', 'pagesize', 'attemptsmode'));
611 $mform->display();
8fb40a45
AKA
612 }
613 if ($download == 'Excel' or $download == 'ODS') {
614 $workbook->close();
615 exit;
616 } else if ($download == 'CSV') {
617 exit;
618 }
619 } else {
620 echo $OUTPUT->notification(get_string('noactivity', 'scorm'));
621 }
622 }// function ends
623}