manilla_folder.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <?php
  2. /* -------------------------------------------------------------------------- */
  3. /* CONFIGURATION */
  4. /* -------------------------------------------------------------------------- */
  5. date_default_timezone_set("Australia/Hobart");
  6. error_reporting(E_ALL);
  7. ini_set('display_errors', '0');
  8. ini_set('log_errors', '1');
  9. require_once 'connection.php';
  10. include_once "dompdf/vendor/autoload.php";
  11. use Dompdf\Dompdf;
  12. use Dompdf\Options;
  13. if (session_status() !== PHP_SESSION_ACTIVE) session_start();
  14. if (empty($_SESSION['csrf'])) $_SESSION['csrf'] = bin2hex(random_bytes(16));
  15. $csrf = $_SESSION['csrf'];
  16. #$enquiry_date = date("l dS M 'y");
  17. $drg = $_GET['drg'] ?? '';
  18. if (!empty($_GET['drg'])) {
  19. include "table.php";
  20. }
  21. /* New: toggle PDF mode */
  22. $asPdf = isset($_GET['pdf']);
  23. /* If we are about to generate a PDF, start buffering the HTML now */
  24. if ($asPdf) {
  25. ob_start();
  26. }
  27. ?>
  28. <!doctype html>
  29. <html lang="en">
  30. <head>
  31. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  32. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  33. <title><?= htmlspecialchars($drg) ?> - Manilla Folder Label</title>
  34. <link rel="shortcut icon" href="images/blueprint.ico" type="image/x-icon">
  35. <!-- normal view keeps external CSS -->
  36. <?php if (!$asPdf): ?>
  37. <link href="css/bootstrap.css" rel="stylesheet">
  38. <link href="css/blueprint.css" rel="stylesheet">
  39. <link href="css/print.css" rel="stylesheet" media="print">
  40. <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.5/font/bootstrap-icons.css">
  41. <?php else: ?>
  42. <style>
  43. <?php
  44. // Inline local CSS so Dompdf reads it from disk
  45. foreach (['css/bootstrap.css', 'css/blueprint.css', 'css/print.css'] as $file) {
  46. $path = __DIR__ . '/' . $file;
  47. if (is_readable($path)) {
  48. echo "/* $file */\n" . file_get_contents($path) . "\n";
  49. }
  50. }
  51. ?>
  52. /* PDF-only fallbacks for Bootstrap bits Dompdf struggles with */
  53. .container-fluid { width: 100%; padding: 0 12px; color: #000; }
  54. .row { display: block; margin: 0; }
  55. .col-md-12 { width: 100%; padding: 0; }
  56. .fw-bold { font-weight: 700; }
  57. .small { font-size: 0.875rem; }
  58. .mb-0 {margin-bottom:0cm;line-height:0.9rem;}
  59. h3 {font-size: 1.75rem;}
  60. .h4 {font-size: 1.5rem;}
  61. @page { size: 320mm 243mm; margin: 0.08cm 0.25cm 0.25cm 0.25cm; }
  62. </style>
  63. <?php endif; ?>
  64. </head>
  65. <body style="background-color:#fff !important;">
  66. <?php if (!$asPdf): ?>
  67. <nav class="navbar bg-brown-dark brown-light border-bottom border-body d-print-none" data-bs-theme="dark">
  68. <div class="container-fluid">
  69. <a class="navbar-brand brown-light" href="dashboard.php">
  70. <img src="images/blueprint-logo-light.png" alt="Logo" width="30" height="24" class="d-inline-block align-text-top">
  71. Modulos Design
  72. </a>
  73. <div class="ms-auto d-flex gap-2">
  74. <a href="dashboard.php" class="btn btn-sm btn-outline-light"><i class="bi bi-grid-fill"></i> Dashboard</a>
  75. <?php if (!empty($drg)): ?><a href="client-brief.php?drg=<?= (int)$drg ?>" class="btn btn-sm btn-outline-light"><i class="bi bi-person-fill"></i> Client Brief</a><?php endif; ?>
  76. <a class="btn btn-sm btn-outline-light" href="?drg=<?= urlencode($drg) ?>&pdf=1"><i class="bi bi-file-earmark-arrow-down"></i> Download PDF</a>
  77. </div>
  78. </div>
  79. </nav>
  80. <?php endif; ?>
  81. <div class="container-fluid">
  82. <div class="row ms-3 mx-auto p-0 plaque">
  83. <div class="plate pt-0 px-0">
  84. <div class="col-md-12 mb-5">
  85. <p><span class="fw-bold"><?= htmlspecialchars($drg) ?></span> - <?= htmlspecialchars($site_address ?? '') ?></p>
  86. </div>
  87. <div class="col-md-12 mb-0">
  88. <h3><span class="fw-bold"><?= htmlspecialchars($drg) ?></span> - <?= htmlspecialchars($joint_name ?? '') ?></h3>
  89. </div>
  90. <div class="col-md-12 ms-5 mt-3 mb-0 small">
  91. <p class="mb-0 fw-bold">CLIENT:</p>
  92. <p class="mb-0"><?= htmlspecialchars(($firstname ?? '') . ' ' . ($lastname ?? '')) ?></p>
  93. <p class="mb-0"><?= htmlspecialchars($joint_name ?? '') ?></p>
  94. <p class="mb-0"><b>MOB:</b> <?= htmlspecialchars($client_mobile ?? '') ?></p>
  95. <p class="mb-0"><b>EMAIL:</b> <?= htmlspecialchars($client_email ?? '') ?></p><br>
  96. <p class="mb-0 fw-bold">SITE DETAILS:</p>
  97. <p class="mb-0"><?= htmlspecialchars($site_address ?? '') ?></p>
  98. <p class="mb-0"><b>TITLE:</b> <?= htmlspecialchars($title_id ?? '') ?> <b>PID:</b> <?= htmlspecialchars($property_id ?? '') ?></p>
  99. <p class="mb-0"><b>Planning Zone:</b> <?= htmlspecialchars($planning_zones ?? '') ?></p>
  100. <p class="h4 mt-3 mb-0"><b>Date:</b> <?= htmlspecialchars(date('M Y',strtotime($enquiry_date)) ?? date("M Y")) ?></p>
  101. </div>
  102. </div>
  103. </div>
  104. </div>
  105. </body>
  106. </html>
  107. <?php
  108. /* If PDF requested, capture the HTML and stream a PDF */
  109. if ($asPdf) {
  110. $html = ob_get_clean();
  111. $options = new Options();
  112. $options->set('isRemoteEnabled', true); // allow CDN CSS and images
  113. $options->set('isHtml5ParserEnabled', true);
  114. $options->setChroot(__DIR__);
  115. $dompdf = new Dompdf($options);
  116. $dompdf->loadHtml($html, 'UTF-8');
  117. // Custom paper size in points. 1 mm = 2.83465 pt
  118. $MM = 2.83465;
  119. $widthPt = 320 * $MM;
  120. $heightPt = 239 * $MM;
  121. $dompdf->setPaper([0, 0, $widthPt, $heightPt], 'landscape');
  122. $dompdf->render();
  123. // Nice filename fallback if pieces are missing
  124. $file = trim(($drg ?? 'label')) . ' - Manilla Folder Label.pdf';
  125. // true => force download. set to false to open in browser
  126. $dompdf->stream($file, ['Attachment' => true]);
  127. exit;
  128. }
  129. ?>