plant-rec-update.php 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. /**
  3. * plant-rec-update.php
  4. *
  5. * Renders the plant specifications reference table for a given plant type.
  6. * Included by plant analysis pages — not a standalone page.
  7. * Requires auth.php and database.php to already be included.
  8. */
  9. if (!function_exists('isLoggedIn')) {
  10. require_once __DIR__ . '/../../../lib/auth.php';
  11. }
  12. if (!function_exists('getDBConnection')) {
  13. require_once __DIR__ . '/../../../config/database.php';
  14. }
  15. requireLogin();
  16. $pdo = getDBConnection();
  17. $userId = getCurrentUserId();
  18. $plantType = trim($_REQUEST['empid'] ?? '');
  19. if ($plantType === '') {
  20. echo '<p class="text-muted">No plant type specified.</p>';
  21. return;
  22. }
  23. // ── Plant specifications table ────────────────────────────────────────────
  24. $stmt = $pdo->prepare('
  25. SELECT plant_stage,
  26. n_min, n_max, P_min, P_max, K_min, K_max, S_min, S_max,
  27. Ca_min, Ca_max, Mg_min, Mg_max, Na_min, Na_max,
  28. Cu_min, Cu_max, Zn_min, Zn_max, Mn_min, Mn_max,
  29. B_min, B_max, Fe_min, Fe_max,
  30. M_Min, M_Max, Co_min, Co_max, se_min, se_max, cl_min, cl_max
  31. FROM plant_specifications
  32. WHERE modx_user_id = ? AND plant_type = ?
  33. ');
  34. $stmt->execute([$userId, $plantType]);
  35. $specs = $stmt->fetchAll();
  36. $h = fn($v) => htmlspecialchars((string) $v, ENT_QUOTES, 'UTF-8');
  37. if (empty($specs)) {
  38. echo '<p class="text-muted">No specifications found for plant type: ' . $h($plantType) . '</p>';
  39. } else {
  40. echo '<div class="table-responsive text-nowrap">';
  41. echo '<table class="table table-sm table-striped table-hover table-bordered">';
  42. echo '<thead><tr>';
  43. $cols = array_keys($specs[0]);
  44. foreach ($cols as $col) {
  45. $label = ucwords(str_replace('_', ' ', $col));
  46. echo '<th class="text-center text-capitalize">' . $h($label) . '</th>';
  47. }
  48. echo '</tr></thead><tbody>';
  49. foreach ($specs as $row) {
  50. echo '<tr>';
  51. foreach ($row as $key => $val) {
  52. $display = ($val === '' || $val === null) ? '0.0'
  53. : (is_numeric($val) ? number_format((float) $val, 2, '.', '') : $h($val));
  54. echo '<td class="text-center">' . $display . '</td>';
  55. }
  56. echo '</tr>';
  57. }
  58. echo '</tbody></table></div>';
  59. }
  60. // ── Plant images gallery ──────────────────────────────────────────────────
  61. $imgStmt = $pdo->prepare('SELECT id, name FROM plant_images ORDER BY id DESC LIMIT 20');
  62. $imgStmt->execute();
  63. $images = $imgStmt->fetchAll();
  64. if (!empty($images)) {
  65. echo '<div class="row mt-2">';
  66. foreach ($images as $img) {
  67. echo '<div class="col-auto">';
  68. echo '<img src="data:image/jpeg;base64,' . base64_encode($img['name']) . '" '
  69. . 'class="img-thumbnail border-success" style="max-width:120px;" alt="">';
  70. echo '</div>';
  71. }
  72. echo '</div>';
  73. }
  74. // ── Image upload form ─────────────────────────────────────────────────────
  75. ?>
  76. <form method="post" enctype="multipart/form-data" class="mt-3">
  77. <div class="mb-2">
  78. <input type="file" class="form-control form-control-sm" name="image" id="image" accept="image/*">
  79. </div>
  80. <button type="submit" name="insert" id="insert" value="Insert" class="btn btn-info btn-sm">
  81. Upload Image
  82. </button>
  83. </form>