From 8238fab8b7096810d1e2b8801bd39b02aaa85ade Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wiesner=20Andr=C3=A1s?= Date: Fri, 27 Sep 2024 13:52:11 +0200 Subject: [PATCH] - switchable report output type --- interface.php | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/interface.php b/interface.php index 64bc8b3..79e3384 100644 --- a/interface.php +++ b/interface.php @@ -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";