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.
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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), "",
|
||||
"<a href=\"index.php?id=$course->id\">$strquizzes</a>
|
||||
-> ".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 "<script language='Javascript'> window.open('".$CFG->wwwroot."/files/index.php?id=".$course->id."&wdir=/".
|
||||
get_string('quizreportdir', 'quiz_analysis')."', '".get_string('reportanalysis', 'quiz_analysis')."'); \n</script>";
|
||||
}
|
||||
*/
|
||||
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) {
|
||||
|
||||
@@ -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), "",
|
||||
"<a href=\"index.php?id=$course->id\">$strquizzes</a>
|
||||
-> ".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), "",
|
||||
"<a href=\"index.php?id=$course->id\">$strquizzes</a>
|
||||
-> ".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 ("<table border=\"1\" align=\"center\" width=\"95%\" cellpadding=\"2\" cellspacing=\"0\">\n");
|
||||
$totcolcount = $table_colcount+2;
|
||||
|
||||
@@ -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), "",
|
||||
"<a href=\"index.php?id=$course->id\">$strquizzes</a>
|
||||
-> ".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), "",
|
||||
"<a href=\"index.php?id=$course->id\">$strquizzes</a>
|
||||
-> ".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 "<table border=\"1\" align=\"center\">";
|
||||
echo "<tr>";
|
||||
echo "<td> </td>";
|
||||
|
||||
Reference in New Issue
Block a user