animal-dietary-balance.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <?php
  2. /**
  3. * dashboard/crop-analysis/animal-dietary-balance/animal-dietary-balance.php
  4. *
  5. * Animal dietary balance results display page.
  6. * Supports normal browser access (session login) and headless Chrome (ptoken).
  7. */
  8. require_once __DIR__ . '/../../../config/database.php';
  9. require_once __DIR__ . '/../../../lib/auth.php';
  10. require_once __DIR__ . '/../../../lib/print_auth.php';
  11. if (session_status() === PHP_SESSION_NONE) {
  12. session_start();
  13. }
  14. $recordId = (int) ($_GET['rid'] ?? 0);
  15. $randId = trim( $_GET['rand'] ?? '');
  16. $clientId = (int) ($_GET['cid'] ?? 0);
  17. $printMode = isset($_GET['print']) || isset($_GET['ptoken']);
  18. if (!$recordId || $randId === '') {
  19. http_response_code(400);
  20. die('Invalid request parameters');
  21. }
  22. $chromeAccess = authenticatePrintPage($recordId, $randId);
  23. $pdo = getDBConnection();
  24. $userId = $chromeAccess ? null : getCurrentUserId();
  25. $row = null;
  26. $stmt = $pdo->prepare('SELECT * FROM animal_records WHERE id = ? AND rand = ? LIMIT 1');
  27. $stmt->execute([$recordId, $randId]);
  28. $row = $stmt->fetch(PDO::FETCH_ASSOC);
  29. $h = fn($v) => htmlspecialchars((string)($v ?? ''), ENT_QUOTES, 'UTF-8');
  30. $today = date('jS F Y');
  31. $pageTitle = 'Animal Dietary Balance' . (!empty($row['client_name']) ? ' — ' . $row['client_name'] : '');
  32. $siteName = 'Crop Monitor';
  33. if (!$printMode) {
  34. include __DIR__ . '/../../../layouts/header.php';
  35. }
  36. ?>
  37. <link rel="stylesheet" href="/client-assets/home/css/graphPrint.css" media="print">
  38. <style>
  39. @media print {
  40. @page { size: A4 portrait; }
  41. body { min-width: 992px !important; }
  42. .container { min-width: 992px !important; }
  43. }
  44. .progress { border-radius: 0 !important; }
  45. </style>
  46. <div class="container" id="content">
  47. <?php if (!$row): ?>
  48. <div class="alert alert-danger mt-4">Record not found or access denied.</div>
  49. <?php else: ?>
  50. <!-- ── Header ──────────────────────────────────────────────────────────── -->
  51. <div class="row mb-2 mt-3">
  52. <div class="col-md-3">
  53. <img class="img-fluid" src="/client-assets/images/crop-monitor.png" alt="Crop Monitor">
  54. </div>
  55. </div>
  56. <table class="title w-100 mb-3 small">
  57. <tbody>
  58. <tr>
  59. <td class="text-end fw-bold text-nowrap">DATE:</td>
  60. <td><?= $h($today) ?></td>
  61. <td></td>
  62. <td class="text-end fw-bold text-nowrap">SAMPLE ID:</td>
  63. <td><?= $h($row['sample_id']) ?></td>
  64. </tr>
  65. <tr>
  66. <td class="text-end fw-bold text-nowrap">CLIENT:</td>
  67. <td><?= $h($row['client_name']) ?></td>
  68. <td></td>
  69. <td class="text-end fw-bold text-nowrap">DATE SAMPLED:</td>
  70. <td><?= $h($row['date_sampled']) ?></td>
  71. </tr>
  72. <tr>
  73. <td class="text-end fw-bold text-nowrap">LAB NO:</td>
  74. <td><?= $h($row['lab_no']) ?></td>
  75. <td></td>
  76. <td class="text-end fw-bold text-nowrap">SITE ID:</td>
  77. <td><?= $h($row['site_id']) ?></td>
  78. </tr>
  79. <tr>
  80. <td class="text-end fw-bold text-nowrap">ANALYSIS TYPE:</td>
  81. <td><?= $h($row['analysis_type'] ?? '') ?></td>
  82. <td></td>
  83. <td></td>
  84. <td></td>
  85. </tr>
  86. </tbody>
  87. </table>
  88. <!-- ── Action buttons ──────────────────────────────────────────────────── -->
  89. <?php if (!$printMode): ?>
  90. <div class="d-print-none mb-3 d-flex gap-2 flex-wrap">
  91. <a href="/dashboard/crop-analysis/animal-dietary-balance/animal-report.php?rid=<?= $recordId ?>&rand=<?= urlencode($randId) ?>&cid=<?= $clientId ?>"
  92. class="btn btn-outline-primary btn-sm">
  93. <i class="fas fa-file-alt me-1"></i>View Report
  94. </a>
  95. <a href="/pdf-files/headlessChrome_pdf.php?type=animal-analysis&rid=<?= $recordId ?>&rand=<?= urlencode($randId) ?>&cid=<?= $clientId ?>"
  96. class="btn btn-outline-secondary btn-sm">
  97. <i class="fas fa-file-pdf me-1"></i>PDF — Analysis
  98. </a>
  99. <a href="/pdf-files/headlessChrome_pdf.php?type=animal&rid=<?= $recordId ?>&rand=<?= urlencode($randId) ?>&cid=<?= $clientId ?>"
  100. class="btn btn-success btn-sm">
  101. <i class="fas fa-file-pdf me-1"></i>PDF — Analysis &amp; Report
  102. </a>
  103. </div>
  104. <?php endif; ?>
  105. <div class="row">
  106. <div class="col-md-12 text-center fw-bold h4">ANIMAL DIETARY MINERAL BALANCE</div>
  107. </div>
  108. <hr class="p-1 m-1">
  109. <!-- Analysis calculation rows — pending PHP migration of animalAnalysisCalcs -->
  110. <div class="alert alert-info mt-3">
  111. <i class="fas fa-info-circle me-1"></i>
  112. Animal dietary analysis calculation display is pending full PHP migration.
  113. </div>
  114. <p>Note: The above assessment is for individual nutrient levels. The influence of nutrient interactions is not considered above.</p>
  115. <p><b>References:</b></p>
  116. <ul>
  117. <li>AFIA Laboratory Methods Manual v7 Appendix 2.2R(1), p93</li>
  118. <li>NRC Nutrient Requirements of Dairy Cattle. National Academy Press, Washington DC. 7th Revised Edition, 2001</li>
  119. <li>Milk Production from Pasture – Principles and Practices. Massey University, NZ, 2002</li>
  120. </ul>
  121. <?php endif; ?>
  122. </div><!-- /.container -->