diff --git a/app/Controllers/Ipd_discharge.php b/app/Controllers/Ipd_discharge.php index 2fc977e..1bded86 100644 --- a/app/Controllers/Ipd_discharge.php +++ b/app/Controllers/Ipd_discharge.php @@ -7258,25 +7258,41 @@ class Ipd_discharge extends BaseController // DEBUG MODE: Output HTML directly if requested via ?html=1 $htmlDebugMode = (int) ($this->request->getGet('html') ?? 0) === 1; if ($htmlDebugMode) { + $dbgHeaderHtml = ''; + if ($withHeader) { + $dbgConfiguredHeader = $this->applyDischargeTemplateTokens( + trim((string) ($templateSettings['header_html'] ?? '')), + $templateTokenVars + ); + $dbgHeaderHtml = $this->sanitizeDischargePdfHtml($dbgConfiguredHeader, false); + } + $dbgFooterHtml = $this->sanitizeDischargePdfHtml( + $this->applyDischargeTemplateTokens(trim((string) ($templateSettings['footer_html'] ?? '')), $templateTokenVars), + false + ); + $dbgPrefixHtml = ''; + if ($withHeader && $dbgHeaderHtml !== '') { + $dbgPrefixHtml .= '' . "\n" . $dbgHeaderHtml . "\n" . '' . "\n"; + } + if ($dbgFooterHtml !== '') { + $dbgPrefixHtml .= '' . "\n" . $dbgFooterHtml . "\n" . '' . "\n"; + } $pdfHtml = $this->buildDischargePdfHtml($panelData, $renderedHtml, $withHeader, $templateName); + $fullDebugSource = ($dbgPrefixHtml !== '' ? $dbgPrefixHtml . "\n" : '') . $pdfHtml; return $this->response ->setContentType('text/html') ->setBody( '' . - 'Discharge Summary HTML Debug - IPD ' . $ipdId . '' . + 'Discharge HTML Debug - IPD ' . $ipdId . '' . '' . + 'pre{background:#fff;padding:15px;border:1px solid #ddd;white-space:pre-wrap;word-break:break-all;} ' . + '.info{background:#fff;padding:15px;border:2px solid #16a34a;margin-bottom:16px;}' . '' . - '

✅ HTML Debug Mode Active

' . - '

IPD ID: ' . $ipdId . '

' . - '

Template: ' . esc($templateName) . '

' . - '

Content Length: ' . strlen($content) . ' chars

' . - '

Rendered HTML Length: ' . strlen($renderedHtml) . ' chars

' . - '

Generate PDF | Regenerate Content

' . - '
' . - '
' . $pdfHtml . '
' . + '
IPD: ' . $ipdId . ' | Template: ' . esc($templateName) . + ' | header_html raw: ' . esc((string) ($templateSettings['header_html'] ?? '(empty)')) . + ' | sanitized header: ' . esc($dbgHeaderHtml) . '
' . + '
' . htmlspecialchars($fullDebugSource, ENT_QUOTES, 'UTF-8') . '
' . '' ); } @@ -7366,9 +7382,11 @@ class Ipd_discharge extends BaseController $namedBlocks .= '' . "\n" . $footerHtml . "\n" . '' . "\n"; } - $prefixHtml = $pageBlock . $namedBlocks; + $prefixHtml = $namedBlocks; $pdfHtml = $this->buildDischargePdfHtml($panelData, $renderedHtml, $withHeader, $templateName); + // Prepend @page CSS to body so mPDF applies named header/footer on every page. + $pdfHtml = str_replace('', $pageBlock . '', $pdfHtml); $pdfHtml = mpdf_normalize_font_weight_css($pdfHtml); $pdfBinary = $this->runMpdfWithTolerantWarnings(static function () use ($mpdf, $prefixHtml, $pdfHtml, $fileName): string { if ($prefixHtml !== '') {