included plugins and HTML headers

included plugins and HTML headers

by Enrique Castro -
Number of replies: 0
Picture of Core developers Picture of Particularly helpful Moodlers
Hi,
While writing a new report plugin for the Quiz module, I have realized a problem.
I have added a couple of buttons to allow downloading of report table data as Excel/OpenOffice/CSV file. However, when testing I only get

Warning: Cannot modify header information - headers already sent

I am using the standard practice of having the button in a form that reloads the script. The "download" action drives to a function that actually fires downloading by sending appropriate HTML headers.
e. g. header("Content-Type: application/download\n");

But now Quiz report plugins work in a two-step manner. First /quiz/report.php gets loaded and then this one includes /quiz/"plugin"/report.php for custom report. The problem arises because /quiz/report.php already prints HTML headers and actual screen header for that report page. So, I do not see an easy way for the nested report to add a "download file" button.

Putting custom code in the first /quiz/report.php breaks the whole "plugin-extendable" concept.

I am sending the output to a file in the server, in moodledata. But this is a much more inconvenient form of work. Perhaps someone with more experience than me can imagine a way to easily allow downloading from a button in these cases.

- Enrique -
Average of ratings: -