soil-print-combined.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. /**
  3. * soil-print-combined.php
  4. *
  5. * Combined print/PDF page: Soil Analysis + Soil Report in one document.
  6. * Uses two iframes pointing at the existing individual pages to avoid
  7. * duplicating any rendering logic.
  8. *
  9. * Accessed by headlessChrome_pdf.php (type=soil) — never directly by users.
  10. * Auth is via the shared ptoken written by the generator.
  11. *
  12. * Both child iframes receive the same ptoken. authenticatePrintPage() does
  13. * not delete the token file, so multiple requests with the same token work.
  14. */
  15. require_once __DIR__ . '/../../../config/database.php';
  16. require_once __DIR__ . '/../../../lib/auth.php';
  17. require_once __DIR__ . '/../../../lib/print_auth.php';
  18. if (session_status() === PHP_SESSION_NONE) {
  19. session_start();
  20. }
  21. $recordId = (int) ($_GET['rid'] ?? 0);
  22. $randId = trim( $_GET['rand'] ?? '');
  23. $clientId = (int) ($_GET['cid'] ?? 0);
  24. $stid = trim( $_GET['stid'] ?? '');
  25. $ptoken = trim( $_GET['ptoken'] ?? '');
  26. authenticatePrintPage($recordId, $randId);
  27. // Build child page URLs — pass the same ptoken so each iframe can auth
  28. $analysisUrl = '/dashboard/crop-analysis/soil-test-data/soil-analysis.php?'
  29. . http_build_query([
  30. 'rid' => $recordId,
  31. 'rand' => $randId,
  32. 'cid' => $clientId,
  33. 'stid' => $stid,
  34. 'ptoken' => $ptoken,
  35. 'print' => '1',
  36. ]);
  37. $reportUrl = '/dashboard/crop-analysis/soil-test-data/soil-report-pdf.php?'
  38. . http_build_query([
  39. 'rid' => $recordId,
  40. 'rand' => $randId,
  41. 'ptoken' => $ptoken,
  42. ]);
  43. function h(string $v): string {
  44. return htmlspecialchars($v, ENT_QUOTES, 'UTF-8');
  45. }
  46. ?>
  47. <!doctype html>
  48. <html lang="en">
  49. <head>
  50. <meta charset="UTF-8">
  51. <title>Soil Analysis &amp; Report</title>
  52. <style>
  53. * { margin: 0; padding: 0; box-sizing: border-box; }
  54. body { background: #fff; }
  55. iframe {
  56. width: 100%;
  57. border: none;
  58. display: block;
  59. min-height: 200px;
  60. }
  61. .page-section {
  62. page-break-after: always;
  63. }
  64. .page-section:last-child {
  65. page-break-after: avoid;
  66. }
  67. @media print {
  68. @page { size: A4 portrait; margin: 0; }
  69. }
  70. </style>
  71. </head>
  72. <body>
  73. <div class="page-section">
  74. <iframe id="frame-analysis" src="<?= h($analysisUrl) ?>" scrolling="no"></iframe>
  75. </div>
  76. <div class="page-section">
  77. <iframe id="frame-report" src="<?= h($reportUrl) ?>" scrolling="no"></iframe>
  78. </div>
  79. <script>
  80. (function () {
  81. function resizeFrame(iframe) {
  82. try {
  83. var h = iframe.contentDocument.documentElement.scrollHeight;
  84. if (h > 0) iframe.style.height = h + 'px';
  85. } catch (e) {
  86. iframe.style.height = '2970px'; // A4 height fallback (~297mm at 96dpi)
  87. }
  88. }
  89. ['frame-analysis', 'frame-report'].forEach(function (id) {
  90. var el = document.getElementById(id);
  91. el.addEventListener('load', function () { resizeFrame(el); });
  92. });
  93. })();
  94. </script>
  95. </body>
  96. </html>