diff --git a/app/Controllers/Ipd_discharge.php b/app/Controllers/Ipd_discharge.php index 484e30c..abc5516 100644 --- a/app/Controllers/Ipd_discharge.php +++ b/app/Controllers/Ipd_discharge.php @@ -5409,6 +5409,27 @@ class Ipd_discharge extends BaseController $templatePack = $this->applyDischargeTemplate($content, $panelData); $renderedHtml = (string) ($templatePack['rendered_html'] ?? $content); + $templateSettings = is_array($templatePack['selected_template_settings'] ?? null) + ? $templatePack['selected_template_settings'] + : $this->defaultDischargeTemplateSettings(); + $templateTokenVars = $this->buildDischargeTemplateTokenVars($panelData, $content); + $templateCss = trim((string) ($templateSettings['template_css'] ?? '')); + $headerHtml = $this->applyDischargeTemplateTokens( + trim((string) ($templateSettings['header_html'] ?? '')), + $templateTokenVars + ); + $footerHtml = $this->applyDischargeTemplateTokens( + trim((string) ($templateSettings['footer_html'] ?? '')), + $templateTokenVars + ); + if ($templateCss !== '') { + $headerHtml = $headerHtml !== '' ? '' . $headerHtml : ''; + $footerHtml = $footerHtml !== '' ? '' . $footerHtml : ''; + $renderedHtml = '' . $renderedHtml; + } + $headerHtml = $this->sanitizeDischargePdfHtml($headerHtml, false); + $footerHtml = $this->sanitizeDischargePdfHtml($footerHtml, false); + $renderedHtml = $this->sanitizeDischargePdfHtml($renderedHtml); // Show HTML with syntax highlighting return $this->response @@ -5420,6 +5441,13 @@ class Ipd_discharge extends BaseController 'pre{background:#fff;padding:20px;border:1px solid #ddd;overflow:auto;white-space:pre-wrap;word-wrap:break-word;} ' . '' . '

Discharge Summary HTML Source (IPD ID: ' . $ipdId . ')

' . + '

Header Preview

' . + '
' . ($headerHtml !== '' ? $headerHtml : '(empty header_html)') . '
' . + '

Footer Preview

' . + '
' . ($footerHtml !== '' ? $footerHtml : '(empty footer_html)') . '
' . + '

Rendered Body Preview

' . + '
' . $renderedHtml . '
' . + '

Rendered Body Source

' . '
' . htmlspecialchars($renderedHtml, ENT_QUOTES, 'UTF-8') . '
' . '' );