index.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. <?php
  2. require_once __DIR__ . '/../../../config/database.php';
  3. require_once __DIR__ . '/../../../lib/auth.php';
  4. require_once __DIR__ . '/../../../lib/csrf.php';
  5. if (session_status() === PHP_SESSION_NONE) {
  6. session_start();
  7. }
  8. requireLogin();
  9. $pageTitle = 'Animal Dietary Balance';
  10. $siteName = 'Crop Monitor';
  11. include __DIR__ . '/../../../layouts/header.php';
  12. include __DIR__ . '/../../../layouts/navbar.php';
  13. ?>
  14. <style>
  15. .btn-append {
  16. color: #495057;
  17. background-color: #e9ecef;
  18. border: 1px solid #ced4da;
  19. }
  20. </style>
  21. <div id="layoutSidenav">
  22. <div id="layoutSidenav_nav">
  23. <?php include __DIR__ . '/../../../layouts/sidebar.php'; ?>
  24. </div>
  25. <div id="layoutSidenav_content">
  26. <main>
  27. <div class="container-fluid px-4">
  28. <h1 class="mt-4"><?= htmlspecialchars($pageTitle, ENT_QUOTES, 'UTF-8') ?></h1>
  29. <ol class="breadcrumb mb-4">
  30. <li class="breadcrumb-item"><a href="/dashboard/dashboard.php">Dashboard</a></li>
  31. <li class="breadcrumb-item active">Animal Dietary Balance</li>
  32. </ol>
  33. <div class="row">
  34. <div class="container">
  35. <h3>Animal Dietary Balance Entry</h3>
  36. <span class="text-danger small">* required fields.</span>
  37. <?php include __DIR__ . '/../../../components/clientDetailsForm.php'; ?>
  38. <form method="post" action="/controllers/animalTestSubmit.php" id="csvForm">
  39. <input type="hidden" name="csrf_token" value="<?= htmlspecialchars(generateCsrfToken(), ENT_QUOTES, 'UTF-8') ?>">
  40. <hr>
  41. <label class="col"><b>Animal Detail</b></label>
  42. <div class="row">
  43. <div class="col-md-3">
  44. <small class="form-text text-muted">Dry Matter Intake Per Day</small>
  45. <div class="input-group input-group-sm mb-3">
  46. <input type="text" class="form-control" name="dry_matter_kg" id="dry_matter_kg" placeholder="Dry Matter">
  47. <span class="input-group-text">kg</span>
  48. </div>
  49. </div>
  50. <div class="col-md-3">
  51. <small class="form-text text-muted">Animal Weight</small>
  52. <div class="input-group input-group-sm mb-3">
  53. <input type="text" class="form-control" name="animal_weight_kg" id="animal_weight_kg" placeholder="Animal Weight">
  54. <span class="input-group-text">kg</span>
  55. </div>
  56. </div>
  57. <div class="col-md-3">
  58. <small class="form-text text-muted">Calving Month</small>
  59. <input class="form-control form-control-sm" name="calving_month" id="calving_month" placeholder="mm/yyyy" type="month">
  60. </div>
  61. <div class="col-md-3">
  62. <small class="form-text text-muted">Lactation Period <span class="text-danger">*</span></small>
  63. <select name="lactation_period" id="lactation_period" class="form-control form-control-sm" required>
  64. <option value="">Select the Lactation Period...</option>
  65. <option value="peak">Peak Lactation</option>
  66. <option value="mid">Mid Lactation</option>
  67. <option value="late">Late Lactation</option>
  68. </select>
  69. </div>
  70. </div>
  71. <div class="row">
  72. <div class="col-md-3">
  73. <small class="form-text text-muted">Analysis Type <span class="text-danger">*</span></small>
  74. <select name="analysis_type" id="analysis_type" class="form-control form-control-sm" required>
  75. <option value="">Select the type of Analysis...</option>
  76. <option value="ash">Dry Ash Test</option>
  77. <option value="sap">Sap Analysis</option>
  78. <option value="field">Field Test</option>
  79. </select>
  80. </div>
  81. <div class="col-md-3">
  82. <small class="form-text text-muted">Lab No</small>
  83. <input type="text" class="form-control form-control-sm" name="lab_no" id="lab_no" placeholder="Lab No">
  84. </div>
  85. <div class="col-md-3">
  86. <small class="form-text text-muted">Batch No</small>
  87. <input type="text" class="form-control form-control-sm" name="batch_no" id="batch_no" placeholder="Batch No">
  88. </div>
  89. <div class="col-md-3">
  90. <small class="form-text text-muted">Date Sampled</small>
  91. <input type="date" class="form-control form-control-sm" name="date_sampled" id="date_sampled" placeholder="Date Sampled">
  92. </div>
  93. </div>
  94. <div class="row">
  95. <div class="col-md-4">
  96. <small class="form-text text-muted">Sample ID <span class="text-danger">*</span></small>
  97. <input type="text" class="form-control form-control-sm" name="sample_id" id="sample_id" placeholder="Sample Id" required>
  98. </div>
  99. <div class="col-md-4">
  100. <small class="form-text text-muted">Site ID</small>
  101. <input type="text" class="form-control form-control-sm" name="site_id" id="site_id" placeholder="Paddock Id">
  102. </div>
  103. <div class="col-md-4">
  104. <small class="form-text text-muted">Crop Type</small>
  105. <input type="text" class="form-control form-control-sm" name="crop_type" id="crop_type" placeholder="Crop / Pasture Type">
  106. </div>
  107. </div>
  108. <hr class="my-2">
  109. <label class="col mb-0"><b>Analysis Inputs</b></label>
  110. <div class="row mt-2">
  111. <?php
  112. $elements = [
  113. ['ca', 'Calcium', 10000],
  114. ['p', 'Phosphorus', 10000],
  115. ['mg', 'Magnesium', 10000],
  116. ['k', 'Potassium', 10000],
  117. ['n', 'Nitrogen', 10000],
  118. ['s', 'Sulphur', 10000],
  119. ];
  120. foreach ($elements as [$id, $label, $factor]): ?>
  121. <div class="col-md-2">
  122. <small class="form-text text-muted"><?= htmlspecialchars($label, ENT_QUOTES, 'UTF-8') ?></small>
  123. <div class="input-group input-group-sm mb-0">
  124. <input type="text" class="form-control form-control-sm"
  125. name="<?= $id ?>" id="<?= $id ?>"
  126. placeholder="<?= htmlspecialchars($id . ' - ' . $label, ENT_QUOTES, 'UTF-8') ?>">
  127. <input class="btn btn-append" type="button"
  128. id="btn_<?= $id ?>" value="ppm"
  129. onclick="conversion(this, document.getElementById('btn_<?= $id ?>'), document.getElementById('<?= $id ?>'), <?= $factor ?>)">
  130. </div>
  131. </div>
  132. <?php endforeach; ?>
  133. </div>
  134. <div class="row mt-2">
  135. <?php
  136. $elements2 = [
  137. ['na', 'Sodium', 10000],
  138. ['b', 'Boron', 10000],
  139. ['zn', 'Zinc', 10000],
  140. ['cu', 'Copper', 10000],
  141. ['mn', 'Manganese', 10000],
  142. ['fe', 'Iron', 10000],
  143. ];
  144. foreach ($elements2 as [$id, $label, $factor]): ?>
  145. <div class="col-md-2">
  146. <small class="form-text text-muted"><?= htmlspecialchars($label, ENT_QUOTES, 'UTF-8') ?></small>
  147. <div class="input-group input-group-sm mb-0">
  148. <input type="text" class="form-control form-control-sm"
  149. name="<?= $id ?>" id="<?= $id ?>"
  150. placeholder="<?= htmlspecialchars($id . ' - ' . $label, ENT_QUOTES, 'UTF-8') ?>">
  151. <input class="btn btn-append" type="button"
  152. id="btn_<?= $id ?>" value="ppm"
  153. onclick="conversion(this, document.getElementById('btn_<?= $id ?>'), document.getElementById('<?= $id ?>'), <?= $factor ?>)">
  154. </div>
  155. </div>
  156. <?php endforeach; ?>
  157. </div>
  158. <div class="row mt-2">
  159. <?php
  160. $elements3 = [
  161. ['m', 'Molybdenum', 10000],
  162. ['co', 'Cobalt', 10000],
  163. ['se', 'Selenium', 10000],
  164. ['ch', 'Chloride', 10000],
  165. ];
  166. foreach ($elements3 as [$id, $label, $factor]): ?>
  167. <div class="col-md-2">
  168. <small class="form-text text-muted"><?= htmlspecialchars($label, ENT_QUOTES, 'UTF-8') ?></small>
  169. <div class="input-group input-group-sm mb-0">
  170. <input type="text" class="form-control form-control-sm"
  171. name="<?= $id ?>" id="<?= $id ?>"
  172. placeholder="<?= htmlspecialchars($id . ' - ' . $label, ENT_QUOTES, 'UTF-8') ?>">
  173. <input class="btn btn-append" type="button"
  174. id="btn_<?= $id ?>" value="ppm"
  175. onclick="conversion(this, document.getElementById('btn_<?= $id ?>'), document.getElementById('<?= $id ?>'), <?= $factor ?>)">
  176. </div>
  177. </div>
  178. <?php endforeach; ?>
  179. </div>
  180. <div class="mt-3">
  181. <button type="submit" class="btn btn-success">Submit</button>
  182. </div>
  183. </form>
  184. <?php include __DIR__ . '/../../../components/newClientModal.php'; ?>
  185. <hr>
  186. <div class="card mt-3">
  187. <div class="card-body">
  188. <h5 class="card-title">Excel/CSV Upload</h5>
  189. <p class="card-text">Download a CSV of this form for easy filling or upload a filled form to pre-populate.</p>
  190. <div class="input-group mt-3">
  191. <input type="file" class="form-control" id="CM-upload">
  192. <button class="btn btn-outline-secondary" type="button" id="CM-download">Download</button>
  193. </div>
  194. </div>
  195. </div>
  196. </div>
  197. </div>
  198. </div>
  199. </main>
  200. <?php include __DIR__ . '/../../../layouts/footer.php'; ?>
  201. </div>
  202. </div>
  203. <script>
  204. function conversion(btnEl, input, element, factor) {
  205. var val = parseFloat(element.value) || 0;
  206. if (btnEl.value === 'ppm') {
  207. btnEl.value = '%';
  208. element.value = (val / factor).toFixed(4);
  209. } else {
  210. btnEl.value = 'ppm';
  211. element.value = (val * factor).toFixed(2);
  212. }
  213. }
  214. </script>