index.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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 = 'Plant Tissue Analysis';
  10. $siteName = 'Crop Monitor';
  11. include __DIR__ . '/../../../layouts/header.php';
  12. include __DIR__ . '/../../../layouts/navbar.php';
  13. ?>
  14. <div id="layoutSidenav">
  15. <div id="layoutSidenav_nav">
  16. <?php include __DIR__ . '/../../../layouts/sidebar.php'; ?>
  17. </div>
  18. <div id="layoutSidenav_content">
  19. <main>
  20. <div class="container-fluid px-4">
  21. <h1 class="mt-4"><?= htmlspecialchars($pageTitle, ENT_QUOTES, 'UTF-8') ?></h1>
  22. <ol class="breadcrumb mb-4">
  23. <li class="breadcrumb-item"><a href="/dashboard/dashboard.php">Dashboard</a></li>
  24. <li class="breadcrumb-item active">Plant Test Data</li>
  25. </ol>
  26. <div class="row">
  27. <div class="container">
  28. <h3>Plant Tissue Test Details</h3>
  29. <span class="text-danger small">* required fields.</span>
  30. <?php include __DIR__ . '/../../../components/clientDetailsForm.php'; ?>
  31. <form method="post" action="/controllers/plantTestSubmit.php" id="PlantcsvForm" class="needs-validation" novalidate>
  32. <input type="hidden" name="csrf_token" value="<?= htmlspecialchars(generateCsrfToken(), ENT_QUOTES, 'UTF-8') ?>">
  33. <hr>
  34. <div class="row">
  35. <div class="col">
  36. <small class="form-text text-muted">Lab No</small>
  37. <input type="text" class="form-control form-control-sm" name="lab_no" id="lab_no" placeholder="Lab No">
  38. </div>
  39. <div class="col">
  40. <small class="form-text text-muted">Batch No</small>
  41. <input type="text" class="form-control form-control-sm" name="batch_no" id="batch_no" placeholder="Batch No">
  42. </div>
  43. <div class="col">
  44. <small class="form-text text-muted">Date Sampled</small>
  45. <input type="date" class="form-control form-control-sm" name="date_sampled" id="date_sampled">
  46. </div>
  47. <div class="col">
  48. <small class="form-text text-muted">Sample ID <span class="text-danger">*</span></small>
  49. <input type="text" class="form-control form-control-sm" name="sample_id" id="sample_id" placeholder="Sample ID" required>
  50. </div>
  51. <div class="col">
  52. <small class="form-text text-muted">Site ID</small>
  53. <input type="text" class="form-control form-control-sm" name="site_id" id="site_id" placeholder="Paddock ID">
  54. </div>
  55. <div class="col">
  56. <small class="form-text text-muted">Crop Type</small>
  57. <input type="text" class="form-control form-control-sm" name="crop_type" id="crop_type" placeholder="Crop Type">
  58. </div>
  59. </div>
  60. <hr>
  61. <label><b>Major Elements (% dry weight)</b></label>
  62. <div class="row mt-2">
  63. <div class="col-md-2">
  64. <small class="form-text text-muted">Nitrogen (N) %</small>
  65. <input type="text" class="form-control form-control-sm" name="n" id="n" placeholder="0.00">
  66. </div>
  67. <div class="col-md-2">
  68. <small class="form-text text-muted">Phosphorus (P) %</small>
  69. <input type="text" class="form-control form-control-sm" name="p" id="p" placeholder="0.00">
  70. </div>
  71. <div class="col-md-2">
  72. <small class="form-text text-muted">Potassium (K) %</small>
  73. <input type="text" class="form-control form-control-sm" name="k" id="k" placeholder="0.00">
  74. </div>
  75. <div class="col-md-2">
  76. <small class="form-text text-muted">Sulphur (S) %</small>
  77. <input type="text" class="form-control form-control-sm" name="s" id="s" placeholder="0.00">
  78. </div>
  79. <div class="col-md-2">
  80. <small class="form-text text-muted">Magnesium (Mg) %</small>
  81. <input type="text" class="form-control form-control-sm" name="mg" id="mg" placeholder="0.00">
  82. </div>
  83. <div class="col-md-2">
  84. <small class="form-text text-muted">Calcium (Ca) %</small>
  85. <input type="text" class="form-control form-control-sm" name="ca" id="ca" placeholder="0.00">
  86. </div>
  87. </div>
  88. <div class="row mt-2">
  89. <div class="col-md-2">
  90. <small class="form-text text-muted">Sodium (Na) %</small>
  91. <input type="text" class="form-control form-control-sm" name="na" id="na" placeholder="0.00">
  92. </div>
  93. </div>
  94. <hr>
  95. <label><b>Trace Elements (ppm)</b></label>
  96. <div class="row mt-2">
  97. <div class="col-md-2">
  98. <small class="form-text text-muted">Iron (Fe) ppm</small>
  99. <input type="text" class="form-control form-control-sm" name="fe" id="fe" placeholder="0.0">
  100. </div>
  101. <div class="col-md-2">
  102. <small class="form-text text-muted">Manganese (Mn) ppm</small>
  103. <input type="text" class="form-control form-control-sm" name="mn" id="mn" placeholder="0.0">
  104. </div>
  105. <div class="col-md-2">
  106. <small class="form-text text-muted">Zinc (Zn) ppm</small>
  107. <input type="text" class="form-control form-control-sm" name="zn" id="zn" placeholder="0.0">
  108. </div>
  109. <div class="col-md-2">
  110. <small class="form-text text-muted">Copper (Cu) ppm</small>
  111. <input type="text" class="form-control form-control-sm" name="cu" id="cu" placeholder="0.0">
  112. </div>
  113. <div class="col-md-2">
  114. <small class="form-text text-muted">Boron (B) ppm</small>
  115. <input type="text" class="form-control form-control-sm" name="b" id="b" placeholder="0.0">
  116. </div>
  117. </div>
  118. <hr>
  119. <label><b>Other Elements (ppm)</b></label>
  120. <div class="row mt-2">
  121. <div class="col-md-2">
  122. <small class="form-text text-muted">Molybdenum (Mo) ppm</small>
  123. <input type="text" class="form-control form-control-sm" name="m" id="m" placeholder="0.00">
  124. </div>
  125. <div class="col-md-2">
  126. <small class="form-text text-muted">Cobalt (Co) ppm</small>
  127. <input type="text" class="form-control form-control-sm" name="co" id="co" placeholder="0.00">
  128. </div>
  129. <div class="col-md-2">
  130. <small class="form-text text-muted">Selenium (Se) ppm</small>
  131. <input type="text" class="form-control form-control-sm" name="se" id="se" placeholder="0.00">
  132. </div>
  133. <div class="col-md-2">
  134. <small class="form-text text-muted">Chloride (Cl) ppm</small>
  135. <input type="text" class="form-control form-control-sm" name="cl" id="cl" placeholder="0.00">
  136. </div>
  137. </div>
  138. <hr>
  139. <button form="PlantcsvForm" type="submit" name="PlantcsvForm" class="btn btn-success">
  140. Submit
  141. </button>
  142. </form>
  143. <?php include __DIR__ . '/../../../components/newClientModal.php'; ?>
  144. <hr>
  145. <div class="card mt-3">
  146. <div class="card-body">
  147. <h5 class="card-title">CSV Upload / Download</h5>
  148. <p class="card-text text-muted">Download a CSV template or upload a filled CSV to pre-populate the form.</p>
  149. <div class="input-group mt-2">
  150. <input type="file" class="form-control form-control-sm" id="csvUpload" accept=".csv">
  151. <button class="btn btn-success btn-sm" type="button" id="csvDownload">Download Template</button>
  152. </div>
  153. </div>
  154. </div>
  155. </div>
  156. </div>
  157. </div>
  158. </main>
  159. <?php include __DIR__ . '/../../../layouts/footer.php'; ?>
  160. </div>
  161. </div>
  162. <script>
  163. (function () {
  164. 'use strict';
  165. window.addEventListener('load', function () {
  166. var forms = document.getElementsByClassName('needs-validation');
  167. Array.prototype.forEach.call(forms, function (form) {
  168. form.addEventListener('submit', function (event) {
  169. if (!form.checkValidity()) {
  170. event.preventDefault();
  171. event.stopPropagation();
  172. }
  173. form.classList.add('was-validated');
  174. }, false);
  175. });
  176. }, false);
  177. })();
  178. document.getElementById('csvUpload').addEventListener('change', function (e) {
  179. var file = e.target.files[0];
  180. if (!file) return;
  181. var reader = new FileReader();
  182. reader.onload = function (ev) {
  183. var rows = ev.target.result.split('\n');
  184. rows.forEach(function (row, i) {
  185. if (i === 0) return;
  186. var cols = row.split(',');
  187. if (cols.length >= 2) {
  188. var el = document.getElementById(cols[0].trim());
  189. if (el) el.value = cols[1].trim();
  190. }
  191. });
  192. };
  193. reader.readAsText(file);
  194. });
  195. document.getElementById('csvDownload').addEventListener('click', function () {
  196. var fields = ['lab_no','batch_no','date_sampled','sample_id','site_id','crop_type',
  197. 'n','p','k','s','mg','ca','na','fe','mn','zn','cu','b','m','co','se','cl'];
  198. var rows = [['id','value']];
  199. fields.forEach(function (id) {
  200. var el = document.getElementById(id);
  201. rows.push([id, el ? el.value : '']);
  202. });
  203. var csv = rows.map(function (r) { return r.join(','); }).join('\n');
  204. var a = document.createElement('a');
  205. a.href = 'data:text/csv;charset=utf-8,' + encodeURIComponent(csv);
  206. a.download = 'plant-tissue-analysis.csv';
  207. a.click();
  208. });
  209. </script>