water-print-combined.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. /**
  3. * water-print-combined.php
  4. *
  5. * Combined print/PDF page: Water Analysis + Water Report in one document.
  6. * Accessed by headlessChrome_pdf.php (type=water) — never directly by users.
  7. * Auth is via the shared ptoken written by the generator.
  8. */
  9. require_once __DIR__ . '/../../../config/database.php';
  10. require_once __DIR__ . '/../../../lib/auth.php';
  11. require_once __DIR__ . '/../../../lib/print_auth.php';
  12. if (session_status() === PHP_SESSION_NONE) {
  13. session_start();
  14. }
  15. $recordId = (int) ($_GET['rid'] ?? 0);
  16. $randId = trim( $_GET['rand'] ?? '');
  17. $clientId = (int) ($_GET['cid'] ?? 0);
  18. $ptoken = trim( $_GET['ptoken'] ?? '');
  19. authenticatePrintPage($recordId, $randId);
  20. $coverpageUrl = '/dashboard/crop-analysis/coverpage.php?'
  21. . http_build_query([
  22. 'type' => 'water',
  23. 'rid' => $recordId,
  24. 'rand' => $randId,
  25. 'cid' => $clientId,
  26. 'ptoken' => $ptoken,
  27. 'print' => '1',
  28. ]);
  29. $analysisUrl = '/dashboard/crop-analysis/water-test-data/water-analysis-pdf.php?'
  30. . http_build_query([
  31. 'rid' => $recordId,
  32. 'rand' => $randId,
  33. 'cid' => $clientId,
  34. 'ptoken' => $ptoken,
  35. 'print' => '1',
  36. ]);
  37. $reportUrl = '/dashboard/crop-analysis/water-test-data/water-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>Water 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 { page-break-after: always; }
  62. .page-section:last-child { page-break-after: avoid; }
  63. @media print {
  64. @page { size: A4 portrait; margin: 0; }
  65. html, body { margin: 0; padding: 0; background: #fff; }
  66. body { min-width: 1030px !important; font-size: 0.75em; }
  67. .container { min-width: 1030px !important; }
  68. .report-textarea { border: none; }
  69. }
  70. </style>
  71. </head>
  72. <body>
  73. <div class="page-section page">
  74. <iframe id="frame-coverpage" src="<?= h($coverpageUrl) ?>" scrolling="no"></iframe>
  75. </div>
  76. <div class="page-section page">
  77. <iframe id="frame-analysis" src="<?= h($analysisUrl) ?>" scrolling="no"></iframe>
  78. </div>
  79. <div class="page-section page">
  80. <iframe id="frame-report" src="<?= h($reportUrl) ?>" scrolling="no"></iframe>
  81. </div>
  82. <script>
  83. (function () {
  84. function resizeFrame(iframe) {
  85. try {
  86. var h = iframe.contentDocument.documentElement.scrollHeight;
  87. if (h > 0) iframe.style.height = h + 'px';
  88. } catch (e) {
  89. iframe.style.height = '2970px';
  90. }
  91. }
  92. var cover = document.getElementById('frame-coverpage');
  93. if (cover) cover.style.height = '1457px';
  94. ['frame-analysis', 'frame-report'].forEach(function (id) {
  95. var el = document.getElementById(id);
  96. el.addEventListener('load', function () { resizeFrame(el); });
  97. });
  98. })();
  99. </script>
  100. </body>
  101. </html>