animal-dietary-balance.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. /**
  3. * Animal Dietary Balance results display page.
  4. * Loads a single animal_records row by rid + rand params.
  5. */
  6. require_once __DIR__ . '/../../../config/database.php';
  7. require_once __DIR__ . '/../../../lib/auth.php';
  8. if (session_status() === PHP_SESSION_NONE) {
  9. session_start();
  10. }
  11. requireLogin();
  12. $pdo = getDBConnection();
  13. $userId = getCurrentUserId();
  14. $recordId = (int) ($_GET['rid'] ?? 0);
  15. $randId = (float) ($_GET['rand'] ?? 0);
  16. $row = null;
  17. if ($recordId > 0) {
  18. $stmt = $pdo->prepare('SELECT * FROM animal_records WHERE id = ? AND rand = ? LIMIT 1');
  19. $stmt->execute([$recordId, $randId]);
  20. $row = $stmt->fetch();
  21. }
  22. $h = fn($v) => htmlspecialchars((string) $v, ENT_QUOTES, 'UTF-8');
  23. ?>
  24. <!doctype html>
  25. <html lang="en">
  26. <head>
  27. <meta charset="UTF-8">
  28. <meta name="viewport" content="width=device-width, initial-scale=1">
  29. <title>Animal Dietary Balance | Crop Monitor</title>
  30. <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.0/dist/css/bootstrap.min.css" rel="stylesheet" crossorigin="anonymous">
  31. <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.9.0/css/all.css" crossorigin="anonymous" rel="stylesheet">
  32. <link href="/client-assets/css/dashboard.css" rel="stylesheet">
  33. <script src="https://cdnjs.cloudflare.com/ajax/libs/html2pdf.js/0.9.3/html2pdf.bundle.min.js" crossorigin="anonymous"></script>
  34. <style>
  35. @media print {
  36. @page { size: A4 portrait; margin: 0.5cm; }
  37. .d-print-none { display: none !important; }
  38. }
  39. .progress { border-radius: 0 !important; }
  40. </style>
  41. </head>
  42. <body>
  43. <div class="container" id="content">
  44. <?php if (!$row): ?>
  45. <div class="alert alert-danger mt-4">Record not found or access denied.</div>
  46. <?php else: ?>
  47. <div class="row mb-3">
  48. <div class="col-md-3">
  49. <img class="img-fluid" src="/client-assets/images/crop-monitor.png" alt="Crop Monitor">
  50. </div>
  51. </div>
  52. <div class="d-print-none mb-3">
  53. <button class="btn btn-success btn-sm downloadPDF">
  54. <i class="fas fa-download me-1"></i>Download PDF
  55. </button>
  56. </div>
  57. <div class="row">
  58. <div class="col-md-12 text-center fw-bold h4">ANIMAL DIETARY MINERAL BALANCE</div>
  59. </div>
  60. <hr class="p-1 m-1">
  61. <table class="table table-bordered table-sm">
  62. <tbody>
  63. <tr>
  64. <td class="fw-bold text-end">Client:</td>
  65. <td><?= $h($row['client_name'] ?? '') ?></td>
  66. <td class="fw-bold text-end">Sample ID:</td>
  67. <td><?= $h($row['sample_id'] ?? '') ?></td>
  68. </tr>
  69. <tr>
  70. <td class="fw-bold text-end">Lab No:</td>
  71. <td><?= $h($row['lab_no'] ?? '') ?></td>
  72. <td class="fw-bold text-end">Date Sampled:</td>
  73. <td><?= $h($row['date_sampled'] ?? '') ?></td>
  74. </tr>
  75. <tr>
  76. <td class="fw-bold text-end">Analysis Type:</td>
  77. <td><?= $h($row['analysis_type'] ?? '') ?></td>
  78. <td class="fw-bold text-end">Site ID:</td>
  79. <td><?= $h($row['site_id'] ?? '') ?></td>
  80. </tr>
  81. </tbody>
  82. </table>
  83. <!-- Analysis calculation rows — pending PHP migration of animalAnalysisCalcs -->
  84. <div class="alert alert-info mt-3">
  85. <i class="fas fa-info-circle me-1"></i>
  86. Animal dietary analysis calculation display is pending full PHP migration.
  87. </div>
  88. <p>Note: The above assessment is for individual nutrient levels. The influence of nutrient interactions is not considered above.</p>
  89. <p><b>References:</b></p>
  90. <ul>
  91. <li>AFIA Laboratory Methods Manual v7 Appendix 2.2R(1), p93</li>
  92. <li>NRC Nutrient Requirements of Dairy Cattle. National Academy Press, Washington DC. 7th Revised Edition, 2001</li>
  93. <li>Milk Production from Pasture – Principles and Practices. Massey University, NZ, 2002</li>
  94. </ul>
  95. <?php endif; ?>
  96. </div>
  97. <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.0/dist/js/bootstrap.bundle.min.js" crossorigin="anonymous"></script>
  98. <script>
  99. document.querySelector('.downloadPDF') && document.querySelector('.downloadPDF').addEventListener('click', function () {
  100. var opt = {
  101. margin: 3,
  102. filename: 'animal-dietary-balance.pdf',
  103. image: { type: 'jpeg', quality: 1.0 },
  104. html2canvas: { scale: 2, letterRendering: true, windowWidth: 1024 },
  105. jsPDF: { orientation: 'portrait', unit: 'mm', format: 'a4' }
  106. };
  107. html2pdf().from(document.getElementById('content')).set(opt).save();
  108. });
  109. </script>
  110. </body>
  111. </html>