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