soil-recommendations.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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 = 'Soil Recommendations';
  10. $siteName = 'Crop Monitor';
  11. $pdo = getDBConnection();
  12. $userId = getCurrentUserId();
  13. $errors = [];
  14. $success = false;
  15. $h = fn($v) => htmlspecialchars((string) $v, ENT_QUOTES, 'UTF-8');
  16. // Load fertiliser_specifications for this user
  17. $stmt = $pdo->prepare('SELECT * FROM fertiliser_specifications WHERE modx_user_id = ? ORDER BY id DESC');
  18. $stmt->execute([$userId]);
  19. $products = $stmt->fetchAll();
  20. include __DIR__ . '/../../layouts/header.php';
  21. include __DIR__ . '/../../layouts/navbar.php';
  22. ?>
  23. <div id="layoutSidenav">
  24. <div id="layoutSidenav_nav">
  25. <?php include __DIR__ . '/../../layouts/sidebar.php'; ?>
  26. </div>
  27. <div id="layoutSidenav_content">
  28. <main>
  29. <div class="container-fluid px-4">
  30. <h1 class="mt-4"><?= $h($pageTitle) ?></h1>
  31. <ol class="breadcrumb mb-4">
  32. <li class="breadcrumb-item"><a href="/dashboard/dashboard.php">Dashboard</a></li>
  33. <li class="breadcrumb-item active">Soil Recommendations</li>
  34. </ol>
  35. <?php foreach ($errors as $err): ?>
  36. <div class="alert alert-danger"><?= $h($err) ?></div>
  37. <?php endforeach; ?>
  38. <?php if ($success): ?>
  39. <div class="alert alert-success">Product added successfully.</div>
  40. <?php endif; ?>
  41. <div class="row">
  42. <div class="col-12">
  43. <h5>Soil Analysis</h5>
  44. <p class="text-muted">Variables used in Soil Analysis recommendation programs.</p>
  45. <button type="button" class="btn btn-warning mb-3"
  46. data-bs-toggle="modal" data-bs-target="#addProductModal">
  47. Add Soil Recommendation
  48. </button>
  49. <?php if (empty($products)): ?>
  50. <p class="text-muted">No products found. Add one using the button above.</p>
  51. <?php else: ?>
  52. <div class="table-responsive">
  53. <table class="table table-sm table-striped table-hover table-bordered">
  54. <thead class="table-dark">
  55. <tr>
  56. <th>Product</th>
  57. <th>Chemical</th>
  58. <th>N</th><th>P</th><th>K</th><th>Na</th>
  59. <th>Ca</th><th>Mg</th><th>B</th><th>Zn</th>
  60. <th>Cu</th><th>Mn</th><th>Fe</th><th>Co</th><th>Mo</th>
  61. </tr>
  62. </thead>
  63. <tbody>
  64. <?php foreach ($products as $prod): ?>
  65. <tr>
  66. <td><?= $h($prod['name'] ?? '') ?></td>
  67. <td><?= $h($prod['chemical'] ?? '') ?></td>
  68. <td><?= $h($prod['N'] ?? '0') ?></td>
  69. <td><?= $h($prod['P'] ?? '0') ?></td>
  70. <td><?= $h($prod['K'] ?? '0') ?></td>
  71. <td><?= $h($prod['Na'] ?? '0') ?></td>
  72. <td><?= $h($prod['Ca'] ?? '0') ?></td>
  73. <td><?= $h($prod['Mg'] ?? '0') ?></td>
  74. <td><?= $h($prod['B'] ?? '0') ?></td>
  75. <td><?= $h($prod['Zn'] ?? '0') ?></td>
  76. <td><?= $h($prod['Cu'] ?? '0') ?></td>
  77. <td><?= $h($prod['Mn'] ?? '0') ?></td>
  78. <td><?= $h($prod['Fe'] ?? '0') ?></td>
  79. <td><?= $h($prod['Co'] ?? '0') ?></td>
  80. <td><?= $h($prod['Mo'] ?? '0') ?></td>
  81. </tr>
  82. <?php endforeach; ?>
  83. </tbody>
  84. </table>
  85. </div>
  86. <?php endif; ?>
  87. </div>
  88. </div>
  89. </div>
  90. </main>
  91. <?php include __DIR__ . '/../../layouts/footer.php'; ?>
  92. </div>
  93. </div>
  94. <!-- Add Product Modal -->
  95. <div class="modal fade" id="addProductModal" tabindex="-1" aria-labelledby="addProductModalLabel" aria-hidden="true">
  96. <div class="modal-dialog">
  97. <div class="modal-content">
  98. <div class="modal-header">
  99. <h5 class="modal-title" id="addProductModalLabel">Add New Product</h5>
  100. <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
  101. </div>
  102. <form method="post" action="/controllers/newProductSubmit.php">
  103. <input type="hidden" name="csrf_token" value="<?= $h(generateCsrfToken()) ?>">
  104. <div class="modal-body">
  105. <div class="row mb-2">
  106. <div class="col">
  107. <label class="form-label">Product Name</label>
  108. <input type="text" class="form-control form-control-sm" name="name" placeholder="Product Name" required>
  109. </div>
  110. <div class="col">
  111. <label class="form-label">Chemical Symbol</label>
  112. <input type="text" class="form-control form-control-sm" name="chemical" placeholder="Chemical">
  113. </div>
  114. </div>
  115. <div class="row mb-2">
  116. <div class="col">
  117. <label class="form-label">Nitrogen (N)</label>
  118. <input type="text" class="form-control form-control-sm" name="N" placeholder="0" required>
  119. </div>
  120. <div class="col">
  121. <label class="form-label">Phosphorus (P)</label>
  122. <input type="text" class="form-control form-control-sm" name="P" placeholder="0">
  123. </div>
  124. </div>
  125. <div class="row mb-2">
  126. <div class="col">
  127. <label class="form-label">Potassium (K)</label>
  128. <input type="text" class="form-control form-control-sm" name="K" placeholder="0">
  129. </div>
  130. <div class="col">
  131. <label class="form-label">Sodium (Na)</label>
  132. <input type="text" class="form-control form-control-sm" name="Na" placeholder="0">
  133. </div>
  134. </div>
  135. <div class="row mb-2">
  136. <div class="col">
  137. <label class="form-label">Calcium (Ca)</label>
  138. <input type="text" class="form-control form-control-sm" name="Ca" placeholder="0" required>
  139. </div>
  140. <div class="col">
  141. <label class="form-label">Magnesium (Mg)</label>
  142. <input type="text" class="form-control form-control-sm" name="Mg" placeholder="0" required>
  143. </div>
  144. </div>
  145. <div class="row mb-2">
  146. <div class="col">
  147. <label class="form-label">Boron (B)</label>
  148. <input type="text" class="form-control form-control-sm" name="B" placeholder="0">
  149. </div>
  150. <div class="col">
  151. <label class="form-label">Zinc (Zn)</label>
  152. <input type="text" class="form-control form-control-sm" name="Zn" placeholder="0">
  153. </div>
  154. </div>
  155. <div class="row mb-2">
  156. <div class="col">
  157. <label class="form-label">Copper (Cu)</label>
  158. <input type="text" class="form-control form-control-sm" name="Cu" placeholder="0">
  159. </div>
  160. <div class="col">
  161. <label class="form-label">Manganese (Mn)</label>
  162. <input type="text" class="form-control form-control-sm" name="Mn" placeholder="0">
  163. </div>
  164. </div>
  165. <div class="row mb-2">
  166. <div class="col">
  167. <label class="form-label">Iron (Fe)</label>
  168. <input type="text" class="form-control form-control-sm" name="Fe" placeholder="0">
  169. </div>
  170. <div class="col">
  171. <label class="form-label">Cobalt (Co)</label>
  172. <input type="text" class="form-control form-control-sm" name="Co" placeholder="0">
  173. </div>
  174. </div>
  175. <div class="row mb-2">
  176. <div class="col-6">
  177. <label class="form-label">Molybdenum (Mo)</label>
  178. <input type="text" class="form-control form-control-sm" name="Mo" placeholder="0">
  179. </div>
  180. </div>
  181. </div>
  182. <div class="modal-footer">
  183. <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
  184. <button type="submit" class="btn btn-primary">Save Product</button>
  185. </div>
  186. </form>
  187. </div>
  188. </div>
  189. </div>