MDL-68784 scorm: Removed limit on allowed scorm users in report
[moodle.git] / mod / scorm / report / basic / classes / report.php
CommitLineData
62b82cbc
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
5e85f7b5
PS
18 * @package scormreport
19 * @subpackage basic
20 * @author Dan Marsden and Ankit Kumar Agarwal
21 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
62b82cbc
AKA
22 */
23
2eca9a23
AA
24namespace scormreport_basic;
25
b2614417 26defined('MOODLE_INTERNAL') || die();
4d26f274 27require_once($CFG->libdir . '/csvlib.class.php');
b2614417 28
2eca9a23 29class report extends \mod_scorm\report {
62b82cbc 30 /**
b2614417 31 * displays the full report
2eca9a23
AA
32 * @param \stdClass $scorm full SCORM object
33 * @param \stdClass $cm - full course_module object
34 * @param \stdClass $course - full course object
b2614417 35 * @param string $download - type of download being requested
62b82cbc 36 */
27b8872c 37 public function display($scorm, $cm, $course, $download) {
b2614417 38 global $CFG, $DB, $OUTPUT, $PAGE;
f1e31687 39
2eca9a23 40 $contextmodule = \context_module::instance($cm->id);
b2614417 41 $action = optional_param('action', '', PARAM_ALPHA);
18bd7573 42 $attemptids = optional_param_array('attemptid', array(), PARAM_RAW);
b27917ee 43 $attemptsmode = optional_param('attemptsmode', SCORM_REPORT_ATTEMPTS_ALL_STUDENTS, PARAM_INT);
2eca9a23 44 $PAGE->set_url(new \moodle_url($PAGE->url, array('attemptsmode' => $attemptsmode)));
62b82cbc 45
b2614417 46 if ($action == 'delete' && has_capability('mod/scorm:deleteresponses', $contextmodule) && confirm_sesskey()) {
27b8872c 47 if (scorm_delete_responses($attemptids, $scorm)) { // Delete responses.
b2614417
DM
48 echo $OUTPUT->notification(get_string('scormresponsedeleted', 'scorm'), 'notifysuccess');
49 }
50 }
27b8872c 51 // Find out current groups mode.
6073fcbe 52 $currentgroup = groups_get_activity_group($cm, true);
62b82cbc 53
27b8872c 54 // Detailed report.
2eca9a23 55 $mform = new \mod_scorm_report_settings($PAGE->url, compact('currentgroup'));
62b82cbc
AKA
56 if ($fromform = $mform->get_data()) {
57 $detailedrep = $fromform->detailedrep;
58 $pagesize = $fromform->pagesize;
62b82cbc
AKA
59 set_user_preference('scorm_report_detailed', $detailedrep);
60 set_user_preference('scorm_report_pagesize', $pagesize);
61 } else {
62 $detailedrep = get_user_preferences('scorm_report_detailed', false);
63 $pagesize = get_user_preferences('scorm_report_pagesize', 0);
62b82cbc
AKA
64 }
65 if ($pagesize < 1) {
66 $pagesize = SCORM_REPORT_DEFAULT_PAGE_SIZE;
67 }
68
27b8872c 69 // Select group menu.
5e3014df
DM
70 $displayoptions = array();
71 $displayoptions['attemptsmode'] = $attemptsmode;
27b8872c 72 if ($groupmode = groups_get_activity_groupmode($cm)) { // Groups are being used.
62b82cbc 73 if (!$download) {
2eca9a23 74 groups_print_activity_menu($cm, new \moodle_url($PAGE->url, $displayoptions));
62b82cbc
AKA
75 }
76 }
77
78 // We only want to show the checkbox to delete attempts
79 // if the user has permissions and if the report mode is showing attempts.
80 $candelete = has_capability('mod/scorm:deleteresponses', $contextmodule)
27b8872c
N
81 && ($attemptsmode != SCORM_REPORT_ATTEMPTS_STUDENTS_WITH_NO);
82 // Select the students.
62b82cbc 83 $nostudents = false;
91f26b58 84 list($allowedlistsql, $params) = get_enrolled_sql($contextmodule, 'mod/scorm:savetrack', (int) $currentgroup);
62b82cbc 85 if (empty($currentgroup)) {
27b8872c 86 // All users who can attempt scoes.
91f26b58 87 if (!$DB->record_exists_sql($allowedlistsql, $params)) {
62b82cbc
AKA
88 echo $OUTPUT->notification(get_string('nostudentsyet'));
89 $nostudents = true;
62b82cbc
AKA
90 }
91 } else {
27b8872c 92 // All users who can attempt scoes and who are in the currently selected group.
91f26b58 93 if (!$DB->record_exists_sql($allowedlistsql, $params)) {
62b82cbc
AKA
94 echo $OUTPUT->notification(get_string('nostudentsingroup'));
95 $nostudents = true;
62b82cbc 96 }
62b82cbc
AKA
97 }
98
99 if ( !$nostudents ) {
27b8872c 100 // Now check if asked download of data.
2eca9a23 101 $coursecontext = \context_course::instance($course->id);
62b82cbc 102 if ($download) {
8ebbb06a
SH
103 $shortname = format_string($course->shortname, true, array('context' => $coursecontext));
104 $filename = clean_filename("$shortname ".format_string($scorm->name, true));
62b82cbc
AKA
105 }
106
27b8872c 107 // Define table columns.
62b82cbc
AKA
108 $columns = array();
109 $headers = array();
110 if (!$download && $candelete) {
27b8872c 111 $columns[] = 'checkbox';
0b88a8bc 112 $headers[] = $this->generate_master_checkbox();
62b82cbc
AKA
113 }
114 if (!$download && $CFG->grade_report_showuserimage) {
27b8872c
N
115 $columns[] = 'picture';
116 $headers[] = '';
62b82cbc 117 }
27b8872c
N
118 $columns[] = 'fullname';
119 $headers[] = get_string('name');
e4aec5be 120 $extrafields = get_extra_user_fields($coursecontext);
121 foreach ($extrafields as $field) {
122 $columns[] = $field;
123 $headers[] = get_user_field_name($field);
62b82cbc 124 }
e4aec5be 125
27b8872c
N
126 $columns[] = 'attempt';
127 $headers[] = get_string('attempt', 'scorm');
128 $columns[] = 'start';
129 $headers[] = get_string('started', 'scorm');
130 $columns[] = 'finish';
131 $headers[] = get_string('last', 'scorm');
132 $columns[] = 'score';
133 $headers[] = get_string('score', 'scorm');
134 if ($detailedrep && $scoes = $DB->get_records('scorm_scoes', array("scorm" => $scorm->id), 'sortorder, id')) {
62b82cbc 135 foreach ($scoes as $sco) {
27b8872c
N
136 if ($sco->launch != '') {
137 $columns[] = 'scograde'.$sco->id;
138 $headers[] = format_string($sco->title);
62b82cbc
AKA
139 }
140 }
141 } else {
142 $scoes = null;
143 }
144
145 if (!$download) {
2eca9a23 146 $table = new \flexible_table('mod-scorm-report');
62b82cbc
AKA
147
148 $table->define_columns($columns);
149 $table->define_headers($headers);
b2614417 150 $table->define_baseurl($PAGE->url);
62b82cbc
AKA
151
152 $table->sortable(true);
153 $table->collapsible(true);
154
27b8872c 155 // This is done to prevent redundant data, when a user has multiple attempts.
62b82cbc
AKA
156 $table->column_suppress('picture');
157 $table->column_suppress('fullname');
e4aec5be 158 foreach ($extrafields as $field) {
159 $table->column_suppress($field);
160 }
62b82cbc
AKA
161
162 $table->no_sorting('start');
163 $table->no_sorting('finish');
164 $table->no_sorting('score');
e205a159
SC
165 $table->no_sorting('checkbox');
166 $table->no_sorting('picture');
167
62b82cbc
AKA
168 if ( $scoes ) {
169 foreach ($scoes as $sco) {
27b8872c 170 if ($sco->launch != '') {
62b82cbc
AKA
171 $table->no_sorting('scograde'.$sco->id);
172 }
173 }
174 }
175
176 $table->column_class('picture', 'picture');
177 $table->column_class('fullname', 'bold');
178 $table->column_class('score', 'bold');
179
180 $table->set_attribute('cellspacing', '0');
181 $table->set_attribute('id', 'attempts');
182 $table->set_attribute('class', 'generaltable generalbox');
183
27b8872c 184 // Start working -- this is necessary as soon as the niceties are over.
62b82cbc 185 $table->setup();
27b8872c 186 } else if ($download == 'ODS') {
62b82cbc
AKA
187 require_once("$CFG->libdir/odslib.class.php");
188
189 $filename .= ".ods";
27b8872c 190 // Creating a workbook.
2eca9a23 191 $workbook = new \MoodleODSWorkbook("-");
27b8872c 192 // Sending HTTP headers.
62b82cbc 193 $workbook->send($filename);
27b8872c 194 // Creating the first worksheet.
62b82cbc 195 $sheettitle = get_string('report', 'scorm');
75427a82 196 $myxls = $workbook->add_worksheet($sheettitle);
27b8872c 197 // Format types.
75427a82 198 $format = $workbook->add_format();
62b82cbc 199 $format->set_bold(0);
75427a82 200 $formatbc = $workbook->add_format();
62b82cbc
AKA
201 $formatbc->set_bold(1);
202 $formatbc->set_align('center');
75427a82 203 $formatb = $workbook->add_format();
62b82cbc 204 $formatb->set_bold(1);
75427a82 205 $formaty = $workbook->add_format();
62b82cbc 206 $formaty->set_bg_color('yellow');
75427a82 207 $formatc = $workbook->add_format();
62b82cbc 208 $formatc->set_align('center');
75427a82 209 $formatr = $workbook->add_format();
62b82cbc
AKA
210 $formatr->set_bold(1);
211 $formatr->set_color('red');
212 $formatr->set_align('center');
75427a82 213 $formatg = $workbook->add_format();
62b82cbc
AKA
214 $formatg->set_bold(1);
215 $formatg->set_color('green');
216 $formatg->set_align('center');
27b8872c 217 // Here starts workshhet headers.
62b82cbc
AKA
218
219 $colnum = 0;
220 foreach ($headers as $item) {
221 $myxls->write(0, $colnum, $item, $formatbc);
222 $colnum++;
223 }
27b8872c
N
224 $rownum = 1;
225 } else if ($download == 'Excel') {
62b82cbc
AKA
226 require_once("$CFG->libdir/excellib.class.php");
227
228 $filename .= ".xls";
27b8872c 229 // Creating a workbook.
2eca9a23 230 $workbook = new \MoodleExcelWorkbook("-");
27b8872c 231 // Sending HTTP headers.
62b82cbc 232 $workbook->send($filename);
27b8872c 233 // Creating the first worksheet.
62b82cbc 234 $sheettitle = get_string('report', 'scorm');
75427a82 235 $myxls = $workbook->add_worksheet($sheettitle);
27b8872c 236 // Format types.
75427a82 237 $format = $workbook->add_format();
62b82cbc 238 $format->set_bold(0);
75427a82 239 $formatbc = $workbook->add_format();
62b82cbc
AKA
240 $formatbc->set_bold(1);
241 $formatbc->set_align('center');
75427a82 242 $formatb = $workbook->add_format();
62b82cbc 243 $formatb->set_bold(1);
75427a82 244 $formaty = $workbook->add_format();
62b82cbc 245 $formaty->set_bg_color('yellow');
75427a82 246 $formatc = $workbook->add_format();
62b82cbc 247 $formatc->set_align('center');
75427a82 248 $formatr = $workbook->add_format();
62b82cbc
AKA
249 $formatr->set_bold(1);
250 $formatr->set_color('red');
251 $formatr->set_align('center');
75427a82 252 $formatg = $workbook->add_format();
62b82cbc
AKA
253 $formatg->set_bold(1);
254 $formatg->set_color('green');
255 $formatg->set_align('center');
256
257 $colnum = 0;
258 foreach ($headers as $item) {
259 $myxls->write(0, $colnum, $item, $formatbc);
260 $colnum++;
261 }
27b8872c
N
262 $rownum = 1;
263 } else if ($download == 'CSV') {
2eca9a23 264 $csvexport = new \csv_export_writer("tab");
4d26f274
AA
265 $csvexport->set_filename($filename, ".txt");
266 $csvexport->add_data($headers);
62b82cbc 267 }
27b8872c 268 // Construct the SQL.
62b82cbc
AKA
269 $select = 'SELECT DISTINCT '.$DB->sql_concat('u.id', '\'#\'', 'COALESCE(st.attempt, 0)').' AS uniqueid, ';
270 $select .= 'st.scormid AS scormid, st.attempt AS attempt, ' .
2eca9a23 271 \user_picture::fields('u', array('idnumber'), 'userid') .
f1e31687 272 get_extra_user_fields_sql($coursecontext, 'u', '', array('email', 'idnumber')) . ' ';
62b82cbc 273
27b8872c 274 // This part is the same for all cases - join users and scorm_scoes_track tables.
62b82cbc
AKA
275 $from = 'FROM {user} u ';
276 $from .= 'LEFT JOIN {scorm_scoes_track} st ON st.userid = u.id AND st.scormid = '.$scorm->id;
277 switch ($attemptsmode) {
278 case SCORM_REPORT_ATTEMPTS_STUDENTS_WITH:
27b8872c 279 // Show only students with attempts.
91f26b58 280 $where = " WHERE u.id IN ({$allowedlistsql}) AND st.userid IS NOT NULL";
62b82cbc
AKA
281 break;
282 case SCORM_REPORT_ATTEMPTS_STUDENTS_WITH_NO:
27b8872c 283 // Show only students without attempts.
91f26b58 284 $where = " WHERE u.id IN ({$allowedlistsql}) AND st.userid IS NULL";
62b82cbc
AKA
285 break;
286 case SCORM_REPORT_ATTEMPTS_ALL_STUDENTS:
27b8872c 287 // Show all students with or without attempts.
91f26b58 288 $where = " WHERE u.id IN ({$allowedlistsql}) AND (st.userid IS NOT NULL OR st.userid IS NULL)";
62b82cbc
AKA
289 break;
290 }
291
292 $countsql = 'SELECT COUNT(DISTINCT('.$DB->sql_concat('u.id', '\'#\'', 'COALESCE(st.attempt, 0)').')) AS nbresults, ';
293 $countsql .= 'COUNT(DISTINCT('.$DB->sql_concat('u.id', '\'#\'', 'st.attempt').')) AS nbattempts, ';
294 $countsql .= 'COUNT(DISTINCT(u.id)) AS nbusers ';
295 $countsql .= $from.$where;
62b82cbc
AKA
296
297 if (!$download) {
298 $sort = $table->get_sql_sort();
299 } else {
300 $sort = '';
301 }
27b8872c 302 // Fix some wired sorting.
62b82cbc
AKA
303 if (empty($sort)) {
304 $sort = ' ORDER BY uniqueid';
305 } else {
306 $sort = ' ORDER BY '.$sort;
307 }
308
309 if (!$download) {
27b8872c 310 // Add extra limits due to initials bar.
62b82cbc
AKA
311 list($twhere, $tparams) = $table->get_sql_where();
312 if ($twhere) {
27b8872c 313 $where .= ' AND '.$twhere; // Initial bar.
62b82cbc
AKA
314 $params = array_merge($params, $tparams);
315 }
316
317 if (!empty($countsql)) {
f17d78ca 318 $count = $DB->get_record_sql($countsql, $params);
62b82cbc
AKA
319 $totalinitials = $count->nbresults;
320 if ($twhere) {
321 $countsql .= ' AND '.$twhere;
322 }
323 $count = $DB->get_record_sql($countsql, $params);
324 $total = $count->nbresults;
325 }
326
327 $table->pagesize($pagesize, $total);
328
2eca9a23 329 echo \html_writer::start_div('scormattemptcounts');
62b82cbc
AKA
330 if ( $count->nbresults == $count->nbattempts ) {
331 echo get_string('reportcountattempts', 'scorm', $count);
27b8872c 332 } else if ( $count->nbattempts > 0 ) {
62b82cbc
AKA
333 echo get_string('reportcountallattempts', 'scorm', $count);
334 } else {
335 echo $count->nbusers.' '.get_string('users');
336 }
2eca9a23 337 echo \html_writer::end_div();
62b82cbc
AKA
338 }
339
27b8872c 340 // Fetch the attempts.
62b82cbc
AKA
341 if (!$download) {
342 $attempts = $DB->get_records_sql($select.$from.$where.$sort, $params,
343 $table->get_page_start(), $table->get_page_size());
2eca9a23 344 echo \html_writer::start_div('', array('id' => 'scormtablecontainer'));
62b82cbc 345 if ($candelete) {
27b8872c 346 // Start form.
62b82cbc 347 $strreallydel = addslashes_js(get_string('deleteattemptcheck', 'scorm'));
2eca9a23 348 echo \html_writer::start_tag('form', array('id' => 'attemptsform', 'method' => 'post',
27b8872c
N
349 'action' => $PAGE->url->out(false),
350 'onsubmit' => 'return confirm("'.$strreallydel.'");'));
2eca9a23
AA
351 echo \html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'action', 'value' => 'delete'));
352 echo \html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey()));
353 echo \html_writer::start_div('', array('style' => 'display: none;'));
354 echo \html_writer::input_hidden_params($PAGE->url);
355 echo \html_writer::end_div();
356 echo \html_writer::start_div();
62b82cbc 357 }
27b8872c 358 $table->initialbars($totalinitials > 20); // Build table rows.
62b82cbc
AKA
359 } else {
360 $attempts = $DB->get_records_sql($select.$from.$where.$sort, $params);
361 }
362
363 if ($attempts) {
364 foreach ($attempts as $scouser) {
365 $row = array();
366 if (!empty($scouser->attempt)) {
367 $timetracks = scorm_get_sco_runtime($scorm->id, false, $scouser->userid, $scouser->attempt);
503dfba8
DM
368 } else {
369 $timetracks = '';
62b82cbc
AKA
370 }
371 if (in_array('checkbox', $columns)) {
372 if ($candelete && !empty($timetracks->start)) {
0b88a8bc 373 $row[] = $this->generate_row_checkbox('attemptid[]', "{$scouser->userid}:{$scouser->attempt}");
62b82cbc
AKA
374 } else if ($candelete) {
375 $row[] = '';
376 }
377 }
378 if (in_array('picture', $columns)) {
2eca9a23
AA
379 $user = new \stdClass();
380 $additionalfields = explode(',', \user_picture::fields());
5b1944bb 381 $user = username_load_fields_from_object($user, $scouser, null, $additionalfields);
e351bed5 382 $user->id = $scouser->userid;
27b8872c 383 $row[] = $OUTPUT->user_picture($user, array('courseid' => $course->id));
62b82cbc
AKA
384 }
385 if (!$download) {
2eca9a23
AA
386 $url = new \moodle_url('/user/view.php', array('id' => $scouser->userid, 'course' => $course->id));
387 $row[] = \html_writer::link($url, fullname($scouser));
62b82cbc
AKA
388 } else {
389 $row[] = fullname($scouser);
390 }
e4aec5be 391 foreach ($extrafields as $field) {
392 $row[] = s($scouser->{$field});
62b82cbc
AKA
393 }
394 if (empty($timetracks->start)) {
395 $row[] = '-';
396 $row[] = '-';
397 $row[] = '-';
398 $row[] = '-';
399 } else {
400 if (!$download) {
2eca9a23
AA
401 $url = new \moodle_url('/mod/scorm/report/userreport.php', array('id' => $cm->id,
402 'user' => $scouser->userid, 'attempt' => $scouser->attempt));
403 $row[] = \html_writer::link($url, $scouser->attempt);
62b82cbc
AKA
404 } else {
405 $row[] = $scouser->attempt;
406 }
27b8872c 407 if ($download == 'ODS' || $download == 'Excel' ) {
62b82cbc
AKA
408 $row[] = userdate($timetracks->start, get_string("strftimedatetime", "langconfig"));
409 } else {
410 $row[] = userdate($timetracks->start);
411 }
27b8872c 412 if ($download == 'ODS' || $download == 'Excel' ) {
62b82cbc
AKA
413 $row[] = userdate($timetracks->finish, get_string('strftimedatetime', 'langconfig'));
414 } else {
415 $row[] = userdate($timetracks->finish);
416 }
417 $row[] = scorm_grade_user_attempt($scorm, $scouser->userid, $scouser->attempt);
418 }
27b8872c 419 // Print out all scores of attempt.
62b82cbc
AKA
420 if ($scoes) {
421 foreach ($scoes as $sco) {
27b8872c 422 if ($sco->launch != '') {
62b82cbc
AKA
423 if ($trackdata = scorm_get_tracks($sco->id, $scouser->userid, $scouser->attempt)) {
424 if ($trackdata->status == '') {
425 $trackdata->status = 'notattempted';
426 }
427 $strstatus = get_string($trackdata->status, 'scorm');
27b8872c 428 // If raw score exists, print it.
62b82cbc
AKA
429 if ($trackdata->score_raw != '') {
430 $score = $trackdata->score_raw;
27b8872c 431 // Add max score if it exists.
e6402b54 432 if (scorm_version_check($scorm->version, SCORM_13)) {
62b82cbc
AKA
433 $maxkey = 'cmi.score.max';
434 } else {
435 $maxkey = 'cmi.core.score.max';
436 }
437 if (isset($trackdata->$maxkey)) {
438 $score .= '/'.$trackdata->$maxkey;
439 }
27b8872c 440 // Else print out status.
62b82cbc
AKA
441 } else {
442 $score = $strstatus;
443 }
444 if (!$download) {
2eca9a23 445 $url = new \moodle_url('/mod/scorm/report/userreporttracks.php', array('id' => $cm->id,
e2cd4f5b 446 'scoid' => $sco->id, 'user' => $scouser->userid, 'attempt' => $scouser->attempt));
663640f5 447 $row[] = $OUTPUT->pix_icon($trackdata->status, $strstatus, 'scorm') . '<br>' .
2eca9a23 448 \html_writer::link($url, $score, array('title' => get_string('details', 'scorm')));
62b82cbc
AKA
449 } else {
450 $row[] = $score;
451 }
452 } else {
27b8872c 453 // If we don't have track data, we haven't attempted yet.
62b82cbc
AKA
454 $strstatus = get_string('notattempted', 'scorm');
455 if (!$download) {
663640f5 456 $row[] = $OUTPUT->pix_icon('notattempted', $strstatus, 'scorm') . '<br>' . $strstatus;
62b82cbc
AKA
457 } else {
458 $row[] = $strstatus;
459 }
460 }
461 }
462 }
463 }
464
465 if (!$download) {
466 $table->add_data($row);
467 } else if ($download == 'Excel' or $download == 'ODS') {
468 $colnum = 0;
469 foreach ($row as $item) {
470 $myxls->write($rownum, $colnum, $item, $format);
471 $colnum++;
472 }
473 $rownum++;
4d26f274
AA
474 } else if ($download == 'CSV') {
475 $csvexport->add_data($row);
62b82cbc
AKA
476 }
477 }
478 if (!$download) {
479 $table->finish_output();
480 if ($candelete) {
2eca9a23
AA
481 echo \html_writer::start_tag('table', array('id' => 'commands'));
482 echo \html_writer::start_tag('tr').\html_writer::start_tag('td');
0b88a8bc 483 echo $this->generate_delete_selected_button();
2eca9a23 484 echo \html_writer::end_tag('td').\html_writer::end_tag('tr').\html_writer::end_tag('table');
27b8872c 485 // Close form.
2eca9a23
AA
486 echo \html_writer::end_tag('div');
487 echo \html_writer::end_tag('form');
62b82cbc 488 }
2eca9a23 489 echo \html_writer::end_div();
62b82cbc 490 if (!empty($attempts)) {
2eca9a23
AA
491 echo \html_writer::start_tag('table', array('class' => 'boxaligncenter')).\html_writer::start_tag('tr');
492 echo \html_writer::start_tag('td');
493 echo $OUTPUT->single_button(new \moodle_url($PAGE->url,
27b8872c 494 array('download' => 'ODS') + $displayoptions),
5e3014df 495 get_string('downloadods'));
2eca9a23
AA
496 echo \html_writer::end_tag('td');
497 echo \html_writer::start_tag('td');
498 echo $OUTPUT->single_button(new \moodle_url($PAGE->url,
27b8872c 499 array('download' => 'Excel') + $displayoptions),
5e3014df 500 get_string('downloadexcel'));
2eca9a23
AA
501 echo \html_writer::end_tag('td');
502 echo \html_writer::start_tag('td');
503 echo $OUTPUT->single_button(new \moodle_url($PAGE->url,
27b8872c 504 array('download' => 'CSV') + $displayoptions),
5e3014df 505 get_string('downloadtext'));
2eca9a23
AA
506 echo \html_writer::end_tag('td');
507 echo \html_writer::start_tag('td');
508 echo \html_writer::end_tag('td');
509 echo \html_writer::end_tag('tr').\html_writer::end_tag('table');
62b82cbc
AKA
510 }
511 }
62b82cbc 512 } else {
59666dae 513 if ($candelete && !$download) {
2eca9a23
AA
514 echo \html_writer::end_div();
515 echo \html_writer::end_tag('form');
2af0e472 516 $table->finish_output();
59666dae 517 }
2eca9a23 518 echo \html_writer::end_div();
2af0e472 519 }
27b8872c 520 // Show preferences form irrespective of attempts are there to report or not.
2af0e472
AKA
521 if (!$download) {
522 $mform->set_data(compact('detailedrep', 'pagesize', 'attemptsmode'));
523 $mform->display();
62b82cbc
AKA
524 }
525 if ($download == 'Excel' or $download == 'ODS') {
526 $workbook->close();
527 exit;
528 } else if ($download == 'CSV') {
4d26f274 529 $csvexport->download_file();
62b82cbc
AKA
530 exit;
531 }
532 } else {
533 echo $OUTPUT->notification(get_string('noactivity', 'scorm'));
534 }
27b8872c 535 }// Function ends.
62b82cbc 536}