Add Debug HTML button to discharge template editor
This commit is contained in:
parent
e353e5afdc
commit
4835d34e0e
|
|
@ -7250,44 +7250,60 @@ class Ipd_discharge extends BaseController
|
||||||
$templateTokenVars = $this->buildDischargeTemplateTokenVars($panelData, $content);
|
$templateTokenVars = $this->buildDischargeTemplateTokenVars($panelData, $content);
|
||||||
$templateTokenVars['TEMPLATE_NAME'] = esc($templateName);
|
$templateTokenVars['TEMPLATE_NAME'] = esc($templateName);
|
||||||
|
|
||||||
// DEBUG MODE: Output HTML directly if requested via ?html=1
|
// DEBUG MODE: show the exact HTML string WriteHTML() receives.
|
||||||
$htmlDebugMode = (int) ($this->request->getGet('html') ?? 0) === 1;
|
$htmlDebugMode = (int) ($this->request->getGet('html') ?? 0) === 1;
|
||||||
if ($htmlDebugMode) {
|
if ($htmlDebugMode) {
|
||||||
$dbgHeaderHtml = '';
|
$dbgHeaderHtml = '';
|
||||||
if ($withHeader) {
|
if ($withHeader) {
|
||||||
$dbgConfiguredHeader = $this->applyDischargeTemplateTokens(
|
$dbgHeader = $this->applyDischargeTemplateTokens(
|
||||||
trim((string) ($templateSettings['header_html'] ?? '')),
|
trim((string) ($templateSettings['header_html'] ?? '')), $templateTokenVars
|
||||||
$templateTokenVars
|
|
||||||
);
|
);
|
||||||
$dbgHeaderHtml = $this->sanitizeDischargePdfHtml($dbgConfiguredHeader, false);
|
$dbgHeaderHtml = $this->sanitizeDischargePdfHtml($dbgHeader, false);
|
||||||
}
|
}
|
||||||
$dbgFooterHtml = $this->sanitizeDischargePdfHtml(
|
$dbgFooterHtml = $this->sanitizeDischargePdfHtml(
|
||||||
$this->applyDischargeTemplateTokens(trim((string) ($templateSettings['footer_html'] ?? '')), $templateTokenVars),
|
$this->applyDischargeTemplateTokens(
|
||||||
false
|
trim((string) ($templateSettings['footer_html'] ?? '')), $templateTokenVars
|
||||||
|
), false
|
||||||
);
|
);
|
||||||
$dbgPrefixHtml = '';
|
$dbgHeaderCm = (float) ($templateSettings['margin_header_cm'] ?? 0.5);
|
||||||
if ($withHeader && $dbgHeaderHtml !== '') {
|
$dbgFooterCm = (float) ($templateSettings['margin_footer_cm'] ?? 0.5);
|
||||||
$dbgPrefixHtml .= '<htmlpageheader name="myHeader">' . "\n" . $dbgHeaderHtml . "\n" . '</htmlpageheader>' . "\n";
|
$dbgPageBlock = '<style>@page {' . "\n"
|
||||||
|
. 'margin-top: ' . (float) ($templateSettings['page_margin_top_cm'] ?? 0.8) . 'cm;' . "\n"
|
||||||
|
. 'margin-bottom: ' . (float) ($templateSettings['page_margin_bottom_cm'] ?? 0.8) . 'cm;' . "\n"
|
||||||
|
. 'margin-left: ' . (float) ($templateSettings['page_margin_left_cm'] ?? 0.8) . 'cm;' . "\n"
|
||||||
|
. 'margin-right: ' . (float) ($templateSettings['page_margin_right_cm'] ?? 0.8) . 'cm;' . "\n"
|
||||||
|
. 'margin-header: ' . $dbgHeaderCm . 'cm;' . "\n"
|
||||||
|
. 'margin-footer: ' . $dbgFooterCm . 'cm;' . "\n"
|
||||||
|
. ($dbgHeaderHtml !== '' ? 'header: html_myHeader;' . "\n" : '')
|
||||||
|
. ($dbgFooterHtml !== '' ? 'footer: html_myFooter;' . "\n" : '')
|
||||||
|
. '}</style>' . "\n";
|
||||||
|
$dbgNamedBlocks = '';
|
||||||
|
if ($dbgHeaderHtml !== '') {
|
||||||
|
$dbgNamedBlocks .= '<htmlpageheader name="myHeader">' . "\n" . $dbgHeaderHtml . "\n" . '</htmlpageheader>' . "\n";
|
||||||
}
|
}
|
||||||
if ($dbgFooterHtml !== '') {
|
if ($dbgFooterHtml !== '') {
|
||||||
$dbgPrefixHtml .= '<htmlpagefooter name="myFooter">' . "\n" . $dbgFooterHtml . "\n" . '</htmlpagefooter>' . "\n";
|
$dbgNamedBlocks .= '<htmlpagefooter name="myFooter">' . "\n" . $dbgFooterHtml . "\n" . '</htmlpagefooter>' . "\n";
|
||||||
}
|
}
|
||||||
$pdfHtml = $this->buildDischargePdfHtml($panelData, $renderedHtml, $withHeader, $templateName);
|
$dbgCss = trim((string) ($templateSettings['template_css'] ?? ''));
|
||||||
$fullDebugSource = ($dbgPrefixHtml !== '' ? $dbgPrefixHtml . "\n" : '') . $pdfHtml;
|
$dbgBody = $this->buildDischargePdfHtml($panelData, $renderedHtml, $withHeader, $templateName);
|
||||||
|
$fullHtml = $dbgPageBlock . $dbgNamedBlocks
|
||||||
|
. ($dbgCss !== '' ? '<style>' . $dbgCss . '</style>' . "\n" : '')
|
||||||
|
. $dbgBody;
|
||||||
|
|
||||||
return $this->response
|
return $this->response
|
||||||
->setContentType('text/html')
|
->setContentType('text/html')
|
||||||
->setBody(
|
->setBody(
|
||||||
'<!DOCTYPE html><html><head><meta charset="utf-8">' .
|
'<!DOCTYPE html><html><head><meta charset="utf-8">' .
|
||||||
'<title>Discharge HTML Debug - IPD ' . $ipdId . '</title>' .
|
'<title>mPDF Debug HTML – IPD ' . $ipdId . '</title>' .
|
||||||
'<style>body{font-family:Arial,sans-serif;margin:20px;background:#f5f5f5;} ' .
|
'<style>body{font-family:monospace;margin:20px;background:#f5f5f5;}' .
|
||||||
'pre{background:#fff;padding:15px;border:1px solid #ddd;white-space:pre-wrap;word-break:break-all;} ' .
|
'pre{background:#fff;padding:16px;border:1px solid #d1d5db;white-space:pre-wrap;word-break:break-word;}' .
|
||||||
'.info{background:#fff;padding:15px;border:2px solid #16a34a;margin-bottom:16px;}</style>' .
|
'.info{background:#fff;padding:12px;border:2px solid #2563eb;margin-bottom:12px;font-family:sans-serif;}' .
|
||||||
'</head><body>' .
|
'</style></head><body>' .
|
||||||
'<div class="info"><strong>IPD:</strong> ' . $ipdId . ' | <strong>Template:</strong> ' . esc($templateName) .
|
'<div class="info"><strong>IPD:</strong> ' . $ipdId .
|
||||||
' | <strong>header_html raw:</strong> ' . esc((string) ($templateSettings['header_html'] ?? '(empty)')) .
|
' | <strong>Template:</strong> ' . esc($templateName) .
|
||||||
' | <strong>sanitized header:</strong> ' . esc($dbgHeaderHtml) . '</div>' .
|
' | <strong>header_html:</strong> ' . esc((string) ($templateSettings['header_html'] ?? '(empty)')) .
|
||||||
'<pre>' . htmlspecialchars($fullDebugSource, ENT_QUOTES, 'UTF-8') . '</pre>' .
|
' | <strong>With Header:</strong> ' . ($withHeader ? 'Yes' : 'No') . '</div>' .
|
||||||
|
'<pre>' . htmlspecialchars($fullHtml, ENT_QUOTES, 'UTF-8') . '</pre>' .
|
||||||
'</body></html>'
|
'</body></html>'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -156,6 +156,7 @@ $placeholders = [
|
||||||
<input type="number" min="1" class="form-control form-control-sm d-inline-block" id="preview_ipd_id" style="width:100px;" placeholder="IPD ID">
|
<input type="number" min="1" class="form-control form-control-sm d-inline-block" id="preview_ipd_id" style="width:100px;" placeholder="IPD ID">
|
||||||
<button type="button" class="btn btn-outline-primary btn-sm" id="btn_preview">Preview</button>
|
<button type="button" class="btn btn-outline-primary btn-sm" id="btn_preview">Preview</button>
|
||||||
<button type="button" class="btn btn-outline-danger btn-sm" id="btn_pdf">PDF</button>
|
<button type="button" class="btn btn-outline-danger btn-sm" id="btn_pdf">PDF</button>
|
||||||
|
<button type="button" class="btn btn-outline-secondary btn-sm" id="btn_debug_html" title="Show raw HTML sent to mPDF">Debug HTML</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -260,6 +261,12 @@ $placeholders = [
|
||||||
window.open('<?= base_url('Ipd_discharge/show_discharge') ?>/' + ipdId + '/1' + (editId > 0 ? '?tpl=' + editId : ''), '_blank');
|
window.open('<?= base_url('Ipd_discharge/show_discharge') ?>/' + ipdId + '/1' + (editId > 0 ? '?tpl=' + editId : ''), '_blank');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
document.getElementById('btn_debug_html').addEventListener('click', function () {
|
||||||
|
var ipdId = parseInt(val('preview_ipd_id'), 10);
|
||||||
|
if (!ipdId) { alert('Enter IPD ID to see mPDF debug HTML.'); return; }
|
||||||
|
window.open('<?= base_url('Ipd_discharge/show_discharge') ?>/' + ipdId + '/1?html=1' + (editId > 0 ? '&tpl=' + editId : ''), '_blank');
|
||||||
|
});
|
||||||
|
|
||||||
/* Placeholder click-to-copy */
|
/* Placeholder click-to-copy */
|
||||||
document.querySelectorAll('.ph-chip').forEach(function (chip) {
|
document.querySelectorAll('.ph-chip').forEach(function (chip) {
|
||||||
chip.addEventListener('click', function () {
|
chip.addEventListener('click', function () {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user