* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ /** * \file netdiag/api/pdf.php * \ingroup netdiag * \brief API-Endpunkt: Protokoll-PDF streamen (GET ?id=&jwt=). */ require_once __DIR__.'/netdiag_api.lib.php'; netdiag_api_bootstrap(); /** * @var DoliDB $db * @var Translate $langs */ $user = netdiag_api_authenticate($db); require_once __DIR__.'/../class/netdiagprotocol.class.php'; require_once __DIR__.'/../lib/netdiag.lib.php'; require_once __DIR__.'/../lib/netdiag_pdf.lib.php'; $id = isset($_GET['id']) ? (int) $_GET['id'] : 0; if ($id <= 0) { netdiag_api_error('Parameter id fehlt', 400); } $protocol = new NetDiagProtocol($db); if ($protocol->fetch($id) <= 0) { netdiag_api_error('Protokoll nicht gefunden', 404); } $file = netdiagGetOutputDir().'/'.dol_sanitizeFileName($protocol->ref).'/'.dol_sanitizeFileName($protocol->ref).'.pdf'; // PDF erzeugen, wenn noch nicht vorhanden oder Neuerzeugung verlangt if (!dol_is_file($file) || !empty($_GET['regenerate'])) { if (netdiagGeneratePdf($db, $protocol, $langs) <= 0) { netdiag_api_error('PDF-Erzeugung fehlgeschlagen', 500); } } if (!dol_is_file($file)) { netdiag_api_error('PDF nicht gefunden', 404); } // PDF ausliefern header('Content-Type: application/pdf'); header('Content-Disposition: inline; filename="'.dol_sanitizeFileName($protocol->ref).'.pdf"'); header('Content-Length: '.dol_filesize($file)); header('Cache-Control: private, max-age=0'); readfile($file); exit;