- switchable report output type

This commit is contained in:
Wiesner András 2024-09-27 13:52:11 +02:00
parent 1e6590f6bb
commit 8238fab8b7

View File

@ -534,6 +534,7 @@ function generate_report_by_groups(ReqHandler &$rh, array $params): string
$gameid = trim($params["gameid"]);
$filter = trim($params["filter"] ?? "");
$groups = explode_list(trim($params["groups"])); // TODO: lehessen több csoportra is
$outtype = trim($params["outtype"] ?? "pdf");
$game = $gameMgr->getGame($gameid);
@ -552,24 +553,33 @@ function generate_report_by_groups(ReqHandler &$rh, array $params): string
// generate latex
$report_dir = "report";
$report->saveTeX($report_dir . DIRECTORY_SEPARATOR . "stats");
$content_dir = $report_dir . DIRECTORY_SEPARATOR . "stats";
$report->saveTeX($content_dir);
// run LuaLaTeX twice
chdir($report_dir);
$tex_cmd = "lualatex -interaction=nonstopmode report.tex";
exec($tex_cmd);
exec($tex_cmd);
$output = "";
$contentType = "";
if ($outtype === "pdf") {
// run LuaLaTeX twice
chdir($report_dir);
$tex_cmd = "lualatex -interaction=nonstopmode report.tex";
exec($tex_cmd);
exec($tex_cmd);
$output = "report.pdf";
$output = "report.pdf";
$contentType = "application/pdf";
} else {
$output = $content_dir . DIRECTORY_SEPARATOR . "content.tex";
$contentType = "text/plain";
}
header("Content-Type: application/pdf");
header("Content-Type: ${contentType}");
header("Content-Length: " . filesize($output));
// deploy the generated PDF
$pdf = fopen($output, "r");
if ($pdf !== false) {
fpassthru($pdf);
fclose($pdf);
$f = fopen($output, "r");
if ($f !== false) {
fpassthru($f);
fclose($f);
}
return "OK";