plant-recommendations.php 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. require_once __DIR__ . '/../../../config/database.php';
  3. require_once __DIR__ . '/../../../lib/auth.php';
  4. if (session_status() === PHP_SESSION_NONE) {
  5. session_start();
  6. }
  7. requireLogin();
  8. $pageTitle = 'Plant Recommendations';
  9. $siteName = 'Crop Monitor';
  10. $pdo = getDBConnection();
  11. $userId = getCurrentUserId();
  12. // Handle image upload
  13. if (isset($_POST['insert']) && isset($_FILES['image'])) {
  14. $file = file_get_contents($_FILES['image']['tmp_name']);
  15. if ($file !== false) {
  16. $stmt = $pdo->prepare('INSERT INTO plant_images (name) VALUES (?)');
  17. $stmt->execute([$file]);
  18. }
  19. }
  20. // Fetch distinct plant types for this user
  21. $stmt = $pdo->prepare(
  22. 'SELECT DISTINCT plant_type FROM plant_specifications WHERE modx_user_id = ? ORDER BY plant_type ASC'
  23. );
  24. $stmt->execute([$userId]);
  25. $plantTypes = $stmt->fetchAll(\PDO::FETCH_COLUMN);
  26. $h = fn($v) => htmlspecialchars((string) $v, ENT_QUOTES, 'UTF-8');
  27. include __DIR__ . '/../../../layouts/header.php';
  28. include __DIR__ . '/../../../layouts/navbar.php';
  29. ?>
  30. <div id="layoutSidenav">
  31. <div id="layoutSidenav_nav">
  32. <?php include __DIR__ . '/../../../layouts/sidebar.php'; ?>
  33. </div>
  34. <div id="layoutSidenav_content">
  35. <main>
  36. <div class="container-fluid px-4">
  37. <h1 class="mt-4"><?= $h($pageTitle) ?></h1>
  38. <ol class="breadcrumb mb-4">
  39. <li class="breadcrumb-item"><a href="/dashboard/dashboard.php">Dashboard</a></li>
  40. <li class="breadcrumb-item active">Plant Recommendations</li>
  41. </ol>
  42. <div class="row">
  43. <div class="col-12">
  44. <h5>Plant Analysis</h5>
  45. <p class="text-muted">Variables used in Plant Analysis recommendation programs.</p>
  46. <div class="row mb-3">
  47. <div class="col-md-4">
  48. <select id="plantType" class="form-select">
  49. <option value="" selected>Select Plant Type</option>
  50. <?php foreach ($plantTypes as $pt): ?>
  51. <option value="<?= $h($pt) ?>"><?= $h($pt) ?></option>
  52. <?php endforeach; ?>
  53. </select>
  54. </div>
  55. </div>
  56. <div id="plantSpecsDisplay"></div>
  57. <hr>
  58. <p class="text-muted small">To add plant specification ranges, please contact your administrator or use the database management tools.</p>
  59. </div>
  60. </div>
  61. </div>
  62. </main>
  63. <?php include __DIR__ . '/../../../layouts/footer.php'; ?>
  64. </div>
  65. </div>
  66. <script>
  67. document.getElementById('plantType').addEventListener('change', function () {
  68. var plant = this.value;
  69. if (!plant) {
  70. document.getElementById('plantSpecsDisplay').innerHTML = '';
  71. return;
  72. }
  73. fetch('/dashboard/crop-analysis/plant-test-data/plant-rec-update.php', {
  74. method: 'POST',
  75. headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
  76. body: 'empid=' + encodeURIComponent(plant)
  77. })
  78. .then(function (r) { return r.text(); })
  79. .then(function (html) {
  80. document.getElementById('plantSpecsDisplay').innerHTML = html;
  81. });
  82. });
  83. </script>