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