* ou via une ressource dédiée avec ce snippet. * * Propriétés : * &booking_url = `https://cal.com/augustin.podvin/decouvrir-les-opportunites-suite-a-mon-audit` * * Envoie directement les headers PDF + contenu binaire, puis exit. */ declare(strict_types=1); $corePath = $modx->getOption('ae.core_path', null, $modx->getOption('core_path') . 'components/audit_express/'); $modx->addPackage('audit_express', $corePath . 'model/'); require_once $corePath . 'src/PackRepository.php'; require_once $corePath . 'src/PdfRenderer.php'; $bookingUrl = $scriptProperties['booking_url'] ?? $modx->getOption('ae.booking_url', null, ''); $auditUid = trim($_GET['audit'] ?? ''); if (!$auditUid) { http_response_code(400); echo json_encode(['error' => 'audit_uid manquant']); return ''; } /** @var AuditRequest|null $auditReq */ $auditReq = $modx->getObject('AuditRequest', ['audit_uid' => $auditUid]); if (!$auditReq || $auditReq->get('status') === 'draft') { http_response_code(404); echo json_encode(['error' => 'Audit non trouvé ou non terminé']); return ''; } try { $packId = $auditReq->get('pack_id'); $repo = new \AuditExpress\PackRepository($corePath . 'config/'); $pack = $repo->getPack($packId); $result = $auditReq->getResultArray(); $renderer = new \AuditExpress\PdfRenderer( $corePath . 'templates/pdf_a4.php', $corePath . '../vendor/autoload.php' ); $pdfBytes = $renderer->render($pack, $result, $bookingUrl); $filename = 'controle-technique-' . preg_replace('/[^a-z0-9\-]/', '', $packId) . '.pdf'; header('Content-Type: application/pdf'); header('Content-Disposition: attachment; filename="' . $filename . '"'); header('Content-Length: ' . strlen($pdfBytes)); header('Cache-Control: no-store'); echo $pdfBytes; exit; } catch (\Throwable $e) { http_response_code(500); $modx->log(xPDO::LOG_LEVEL_ERROR, '[AuditExpress] PDF: ' . $e->getMessage()); echo json_encode(['error' => 'Erreur génération PDF']); return ''; }