From 1ddb7f4efc193e62cd8a7e484ca459df67cffc2d Mon Sep 17 00:00:00 2001 From: gustav_delius Date: Fri, 20 May 2005 08:52:33 +0000 Subject: [PATCH] Printing of header moved into plugins themselves to allow them to provide export functionality which does not want a header printed. Thanks to Enrique for doing this. --- mod/quiz/report.php | 3 ++ mod/quiz/report/analysis/report.php | 74 +++++++++++++++++++++------ mod/quiz/report/fullstat/report.php | 48 +++++++++++++++-- mod/quiz/report/simplestat/report.php | 44 ++++++++++++++-- 4 files changed, 146 insertions(+), 23 deletions(-) diff --git a/mod/quiz/report.php b/mod/quiz/report.php index 4151f0488a2..abe9d9475b2 100644 --- a/mod/quiz/report.php +++ b/mod/quiz/report.php @@ -48,6 +48,8 @@ add_to_log($course->id, "quiz", "report", "report.php?id=$cm->id", "$quiz->id", "$cm->id"); + +/* Code moved into each plugin report.php /// Define some strings $strquizzes = get_string("modulenameplural", "quiz"); @@ -64,6 +66,7 @@ $currenttab = 'reports'; include('tabs.php'); +*/ /// Open the selected quiz report and display it diff --git a/mod/quiz/report/analysis/report.php b/mod/quiz/report/analysis/report.php index 5138986933b..090bee13935 100644 --- a/mod/quiz/report/analysis/report.php +++ b/mod/quiz/report/analysis/report.php @@ -201,27 +201,47 @@ class quiz_report extends quiz_default_report { } unset($attemptscores); unset($statstable); - + /// Now check if asked download of data if ($download = optional_param('download', NULL)) { - $dir = make_upload_directory($course->id."/quiz_reports"); + //$dir = make_upload_directory($course->id."/quiz_reports"); $filename = clean_filename("$course->shortname ".format_string($quiz->name,true)); switch ($download) { case "Excel" : $downloadfilename = $filename.".xls"; - $this->Export_Excel($questions, $dir."/".$downloadfilename); + $this->Export_Excel($questions, $downloadfilename); break; case "OOo": - $downloadfilename = $filename; - $this->Export_OOo($questions, $dir."/".$downloadfilename); + $downloadfilename = $filename.".sxw"; + $this->Export_OOo($questions, $downloadfilename); break; case "CSV": $downloadfilename = $filename.".txt"; - $this->Export_CSV($questions, $dir."/".$downloadfilename); + $this->Export_CSV($questions, $downloadfilename); break; } } + /// Define some strings + + $strquizzes = get_string("modulenameplural", "quiz"); + $strquiz = get_string("modulename", "quiz"); + + /// Print the page header + + print_header_simple(format_string($quiz->name), "", + "id\">$strquizzes + -> ".format_string($quiz->name), + "", "", true, update_module_button($cm->id, $course->id, $strquiz), navmenu($course, $cm)); + + /// Print the tabs + + $currenttab = 'reports'; + $mode = 'anaylis'; + include('tabs.php'); + + /// Construct the table for this particular report + $tablecolumns = array('id', 'qname', 'answers', 'credits', 'rcounts', 'rpercent', 'facility', 'sd','discrimination_index', 'discrimination_coeff'); $tableheaders = array(get_string('qidtitle','quiz_analysis'), get_string('qtexttitle','quiz_analysis'), get_string('responsestitle','quiz_analysis'), get_string('rfractiontitle','quiz_analysis'), @@ -357,10 +377,12 @@ class quiz_report extends quiz_default_report { $this->print_options_form($quiz, $cm, $attemptselection, $lowmarklimit, $pagesize); +/* if ($download) { echo ""; } +*/ return true; } @@ -470,7 +492,14 @@ class quiz_report extends quiz_default_report { global $CFG; require_once("$CFG->libdir/excel/Worksheet.php"); require_once("$CFG->libdir/excel/Workbook.php"); - + + 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($filename); // Creating the first worksheet $sheettitle = get_string('reportanalysis','quiz_analysis'); @@ -542,7 +571,14 @@ class quiz_report extends quiz_default_report { function Export_OOo(&$questions, $filename) { global $CFG; - + + header("Content-Type: application/download\n"); + 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/phpdocwriter/lib/include.php"); import('phpdocwriter.pdw_document'); $filename = substr($filename, 0, -4); @@ -578,13 +614,11 @@ class quiz_report extends quiz_default_report { } } $sxw->Table($headers,$data); - $sxw->Output("F"); + $sxw->Output(); } function Export_CSV(&$questions, $filename) { - $file = fopen($filename,"wb"); - $headers = array(get_string('qidtitle','quiz_analysis'), get_string('qtypetitle','quiz_analysis'), get_string('qnametitle','quiz_analysis'), get_string('qtexttitle','quiz_analysis'), get_string('responsestitle','quiz_analysis'), get_string('rfractiontitle','quiz_analysis'), @@ -592,19 +626,25 @@ class quiz_report extends quiz_default_report { get_string('qcounttitle','quiz_analysis'), get_string('facilitytitle','quiz_analysis'), get_string('stddevtitle','quiz_analysis'), get_string('dicsindextitle','quiz_analysis'), get_string('disccoefftitle','quiz_analysis')); - - $text = implode(", ", $headers)." \n"; - //echo $text." \n"; - fwrite($file, $text); + + $text = implode("\t", $headers)." \n"; + + header("Content-Type: application/download\n"); + header("Content-Disposition: attachment; filename=\"$filename\""); + header("Expires: 0"); + header("Cache-Control: must-revalidate,post-check=0,pre-check=0"); + header("Pragma: public"); + + echo $text; foreach($questions as $q) { $rows = $this->print_row_stats_data(&$q); foreach($rows as $row){ $text = implode("\t", $row); - fwrite($file, $text." \n"); + echo $text." \n"; } } - fclose($file); + exit; } function print_row_stats_data(&$q) { diff --git a/mod/quiz/report/fullstat/report.php b/mod/quiz/report/fullstat/report.php index 2d5ad801585..fd2b99d4d93 100755 --- a/mod/quiz/report/fullstat/report.php +++ b/mod/quiz/report/fullstat/report.php @@ -9,14 +9,34 @@ class quiz_report extends quiz_default_report { function display($quiz, $cm, $course) { /// This function just displays the report - print_heading('Not yet implemented'); - return true; + /// These lines MUST be removed when putting this plugin into action + /// Define some strings + + $strquizzes = get_string("modulenameplural", "quiz"); + $strquiz = get_string("modulename", "quiz"); + + /// Print the page header + + print_header_simple(format_string($quiz->name), "", + "id\">$strquizzes + -> ".format_string($quiz->name), + "", "", true, update_module_button($cm->id, $course->id, $strquiz), navmenu($course, $cm)); + + /// Print the tabs + + $currenttab = 'reports'; + $mode = 'fullstat'; + include('tabs.php'); + + /// end here while the plugin is not revised. + print_heading('Not yet implemented'); + return true; global $CFG; global $download, $quests,$qtally,$table_colcount,$max_choices, $analysis,$qs_in_order,$total_user_count,$match_number, $thismin,$thismax,$myxls,$match_qs,$formatbc,$workbook,$strquestion,$showtext,$debug; optional_variable($download, ""); optional_variable($debug, ""); -//$debug = 1; + $strindivresp = get_string('indivresp', 'quiz'); @@ -659,6 +679,28 @@ class quiz_report extends quiz_default_report { exit; } ////////--------------------------- If it falls through both of the $download choices, print on screen + + /// Define some strings + + $strquizzes = get_string("modulenameplural", "quiz"); + $strquiz = get_string("modulename", "quiz"); + + /// Print the page header + + print_header_simple(format_string($quiz->name), "", + "id\">$strquizzes + -> ".format_string($quiz->name), + "", "", true, update_module_button($cm->id, $course->id, $strquiz), navmenu($course, $cm)); + + /// Print the tabs + + $currenttab = 'reports'; + $mode = 'fullstat'; + include('tabs.php'); + + /// end here while the plugin is not revised. + print_heading('Not yet implemented'); + //Print user responses print ("\n"); $totcolcount = $table_colcount+2; diff --git a/mod/quiz/report/simplestat/report.php b/mod/quiz/report/simplestat/report.php index c3871ef5255..4770de7fd4e 100644 --- a/mod/quiz/report/simplestat/report.php +++ b/mod/quiz/report/simplestat/report.php @@ -448,6 +448,27 @@ class quiz_report extends quiz_default_report { global $CFG; global $download; + + /// These lines MUST be removed when putting this plugin into action + /// Define some strings + + $strquizzes = get_string("modulenameplural", "quiz"); + $strquiz = get_string("modulename", "quiz"); + + /// Print the page header + + print_header_simple(format_string($quiz->name), "", + "id\">$strquizzes + -> ".format_string($quiz->name), + "", "", true, update_module_button($cm->id, $course->id, $strquiz), navmenu($course, $cm)); + + /// Print the tabs + + $currenttab = 'reports'; + $mode = 'simplestat'; + include('tabs.php'); + + /// end here while the plugin is not revised. print_heading('Not yet implemented'); return true; @@ -646,11 +667,28 @@ class quiz_report extends quiz_default_report { exit; } + /// Otherwise, display the table + /// First the page header and tabs + /// Define some strings + + $strquizzes = get_string("modulenameplural", "quiz"); + $strquiz = get_string("modulename", "quiz"); + + /// Print the page header + + print_header_simple(format_string($quiz->name), "", + "id\">$strquizzes + -> ".format_string($quiz->name), + "", "", true, update_module_button($cm->id, $course->id, $strquiz), navmenu($course, $cm)); + + /// Print the tabs + + $currenttab = 'reports'; + $mode = 'simplestat'; + include('tabs.php'); - - /// Otherwise, display the table as HTML - + /// Now we can display the table as HTML echo "
"; echo ""; echo "";