| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- <?php
- /**
- * soil-print-combined.php
- *
- * Combined print/PDF page: Soil Analysis + Soil Report in one document.
- * Uses two iframes pointing at the existing individual pages to avoid
- * duplicating any rendering logic.
- *
- * Accessed by headlessChrome_pdf.php (type=soil) — never directly by users.
- * Auth is via the shared ptoken written by the generator.
- *
- * Both child iframes receive the same ptoken. authenticatePrintPage() does
- * not delete the token file, so multiple requests with the same token work.
- */
- require_once __DIR__ . '/../../../config/database.php';
- require_once __DIR__ . '/../../../lib/auth.php';
- require_once __DIR__ . '/../../../lib/print_auth.php';
- if (session_status() === PHP_SESSION_NONE) {
- session_start();
- }
- $recordId = (int) ($_GET['rid'] ?? 0);
- $randId = trim( $_GET['rand'] ?? '');
- $clientId = (int) ($_GET['cid'] ?? 0);
- $stid = trim( $_GET['stid'] ?? '');
- $ptoken = trim( $_GET['ptoken'] ?? '');
- authenticatePrintPage($recordId, $randId);
- // Build child page URLs — pass the same ptoken so each iframe can auth
- $coverpageUrl = '/dashboard/crop-analysis/coverpage.php?'
- . http_build_query([
- 'type' => 'soil',
- 'rid' => $recordId,
- 'rand' => $randId,
- 'cid' => $clientId,
- 'stid' => $stid,
- 'ptoken' => $ptoken,
- 'print' => '1',
- ]);
- // Build child page URLs — pass the same ptoken so each iframe can auth
- $analysisUrl = '/dashboard/crop-analysis/soil-test-data/soil-analysis.php?'
- . http_build_query([
- 'rid' => $recordId,
- 'rand' => $randId,
- 'cid' => $clientId,
- 'stid' => $stid,
- 'ptoken' => $ptoken,
- 'print' => '1',
- ]);
- $reportUrl = '/dashboard/crop-analysis/soil-test-data/soil-report-pdf.php?'
- . http_build_query([
- 'rid' => $recordId,
- 'rand' => $randId,
- 'ptoken' => $ptoken,
- ]);
- function h(string $v): string {
- return htmlspecialchars($v, ENT_QUOTES, 'UTF-8');
- }
- ?>
- <!doctype html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>Soil Analysis & Report</title>
- <style>
- * { margin: 0; padding: 0; box-sizing: border-box; }
- body { background: #fff; }
- iframe {
- width: 100%;
- border: none;
- display: block;
- min-height: 200px;
- }
- .page-section {
- page-break-after: always;
- }
- .page-section:last-child {
- page-break-after: avoid;
- }
- @media print {
- @page {
- size: A4 portrait;
- margin: 0;
- }
- html, body {
- margin: 0;
- padding: 0;
- background: #fff;
- }
- .page {
- padding: 0;
- box-sizing: border-box;
- }
- body {
- min-width: 1030px !important;
- font-size: 0.75em;
- }
- .container {
- min-width: 1030px !important;
- }
- .report-textarea {
- border:none;
- }
- }
- </style>
- </head>
- <body>
- <div class="page-section page">
- <iframe id="frame-coverpage" src="<?= h($coverpageUrl) ?>" scrolling="no"></iframe>
- </div>
- <div class="page-section page">
- <iframe id="frame-analysis" src="<?= h($analysisUrl) ?>" scrolling="no"></iframe>
- </div>
- <div class="page-section page">
- <iframe id="frame-report" src="<?= h($reportUrl) ?>" scrolling="no"></iframe>
- </div>
- <script>
- (function () {
- function resizeFrame(iframe) {
- try {
- var h = iframe.contentDocument.documentElement.scrollHeight;
- if (h > 0) iframe.style.height = h + 'px';
- } catch (e) {
- iframe.style.height = '2970px'; // A4 height fallback (~297mm at 96dpi)
- }
- }
- // Cover page is always exactly one A4 page.
- // The combined viewport is 1030px wide; Chrome scales it to 210mm for print.
- // Height must be 1030 * (297/210) = 1457px so it fills the full A4 height after scaling.
- var cover = document.getElementById('frame-coverpage');
- if (cover) cover.style.height = '1457px';
- ['frame-analysis', 'frame-report'].forEach(function (id) {
- var el = document.getElementById(id);
- el.addEventListener('load', function () { resizeFrame(el); });
- });
- })();
- </script>
- </body>
- </html>
|