diff --git a/mod/quiz/report/analysis/report.php b/mod/quiz/report/analysis/report.php index 559f02255da..8fd38e1f8e2 100644 --- a/mod/quiz/report/analysis/report.php +++ b/mod/quiz/report/analysis/report.php @@ -471,22 +471,18 @@ class quiz_report extends quiz_default_report { function Export_Excel(&$questions, $filename) { global $CFG; - require_once("$CFG->libdir/excel/Worksheet.php"); - require_once("$CFG->libdir/excel/Workbook.php"); - - $filename .= ".xls"; - header("Content-Type: application/vnd.ms-excel"); - header("Content-Disposition: attachment; filename=\"$filename\""); - header("Expires: 0"); - header("Cache-Control: must-revalidate,post-check=0,pre-check=0"); - header("Pragma: public"); - header("Content-Transfer-Encoding: binary"); + require_once("$CFG->libdir/excellib.class.php"); - $workbook = new Workbook("-"); - // Creating the first worksheet + /// Calculate file name + $filename .= ".xls"; + /// Creating a workbook + $workbook = new MoodleExcelWorkbook("-"); + /// Sending HTTP headers + $workbook->send($filename); + /// Creating the first worksheet $sheettitle = get_string('reportanalysis','quiz_analysis'); $myxls =& $workbook->add_worksheet($sheettitle); - /// format types + /// format types $format =& $workbook->add_format(); $format->set_bold(0); $formatbc =& $workbook->add_format(); @@ -516,7 +512,7 @@ class quiz_report extends quiz_default_report { $formatblue->set_bold(1); $formatblue->set_color('blue'); $formatblue->set_align('center'); - // Here starts workshhet headers + /// Here starts workshhet headers $myxls->write_string(0,0,$sheettitle,$formatb); $headers = array(get_string('qidtitle','quiz_analysis'), get_string('qtypetitle','quiz_analysis'), @@ -545,7 +541,9 @@ class quiz_report extends quiz_default_report { $row++; } } + /// Close the workbook $workbook->close(); + exit; } diff --git a/mod/quiz/report/overview/report.php b/mod/quiz/report/overview/report.php index da942c239f5..6c31144cd07 100644 --- a/mod/quiz/report/overview/report.php +++ b/mod/quiz/report/overview/report.php @@ -162,19 +162,14 @@ class quiz_report extends quiz_default_report { // Start working -- this is necessary as soon as the niceties are over $table->setup(); } elseif ($download =='Excel') { - require_once("$CFG->libdir/excel/Worksheet.php"); - require_once("$CFG->libdir/excel/Workbook.php"); + require_once("$CFG->libdir/excellib.class.php"); $filename .= ".xls"; - header("Content-Type: application/vnd.ms-excel"); - header("Content-Disposition: attachment; filename=\"$filename\""); - header("Expires: 0"); - header("Cache-Control: must-revalidate,post-check=0,pre-check=0"); - header("Pragma: public"); - header("Content-Transfer-Encoding: binary"); - - $workbook = new Workbook("-"); - // Creating the first worksheet + /// Creating a workbook + $workbook = new MoodleExcelWorkbook("-"); + /// Sending HTTP headers + $workbook->send($filename); + /// Creating the first worksheet $sheettitle = get_string('reportresponses','quiz_responses'); $myxls =& $workbook->add_worksheet($sheettitle); /// format types diff --git a/mod/quiz/report/responses/report.php b/mod/quiz/report/responses/report.php index a25ef00040a..961d411a345 100644 --- a/mod/quiz/report/responses/report.php +++ b/mod/quiz/report/responses/report.php @@ -203,19 +203,15 @@ class quiz_report extends quiz_default_report { $pagelimit = ''; } } elseif ($download =='Excel') { - require_once("$CFG->libdir/excel/Worksheet.php"); - require_once("$CFG->libdir/excel/Workbook.php"); - - $filename .= ".xls"; - header("Content-Type: application/vnd.ms-excel"); - header("Content-Disposition: attachment; filename=\"$filename\""); - header("Expires: 0"); - header("Cache-Control: must-revalidate,post-check=0,pre-check=0"); - header("Pragma: public"); - header("Content-Transfer-Encoding: binary"); + require_once("$CFG->libdir/excellib.class.php"); - $workbook = new Workbook("-"); - // Creating the first worksheet + /// Calculate file name + $filename .= ".xls"; + /// Creating a workbook + $workbook = new MoodleExcelWorkbook("-"); + /// Sending HTTP headers + $workbook->send($filename); + /// Creating the first worksheet $sheettitle = get_string('reportresponses','quiz_responses'); $myxls =& $workbook->add_worksheet($sheettitle); /// format types @@ -275,6 +271,9 @@ class quiz_report extends quiz_default_report { } /// Fetch the attempts + if (empty($sort)) { + $sort=''; + } $attempts = get_records_sql($select.$from.$where.$sort.$pagelimit); /// Build table rows