index.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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 Test Analysis Report';
  10. $siteName = 'Crop Management Platform';
  11. $activeItem = 'Soil Analysis';
  12. include __DIR__ . '/../../../layouts/header.php';
  13. include __DIR__ . '/../../../layouts/navbar.php';
  14. ?>
  15. <div id="layoutSidenav">
  16. <div id="layoutSidenav_nav">
  17. <?php include __DIR__ . '/../../../layouts/sidebar.php'; ?>
  18. </div>
  19. <div id="layoutSidenav_content">
  20. <main>
  21. <div class="container-fluid px-4">
  22. <h1 class="mt-4"><?= htmlspecialchars($pageTitle, ENT_QUOTES, 'UTF-8') ?></h1>
  23. <ol class="breadcrumb mb-4"><!-- TODO: render breadcrumbs dynamically --></ol>
  24. <div class="row">
  25. <div class="container">
  26. <h3 id="forms-example">Soil Test Details</h3>
  27. <p class="text-muted">Complete the soil test form and submit.</p>
  28. <!-- Client Details Form Component -->
  29. <?php include __DIR__ . '/../../../components/clientDetailsForm.php'; ?>
  30. <!-- New Client Modal Component -->
  31. <?php include __DIR__ . '/../../../components/newClientModal.php'; ?>
  32. <form method="post" action="/controllers/soilTestSubmit.php" id="SoilcsvForm" class="needs-validation" novalidate>
  33. <input type="hidden" name="csrf_token" value="<?php echo generateCsrfToken(); ?>">
  34. <?php // Soil Analysis Form Component ?>
  35. <?php include __DIR__ . '/../../../components/soilAnalysisForm.php'; ?>
  36. <button form="SoilcsvForm" type="submit" name="SoilcsvForm" class="btn btn-success">Submit</button>
  37. </form>
  38. <hr />
  39. <!-- ── Lab File Import ────────────────────────────── -->
  40. <div class="card mb-4">
  41. <div class="card-header d-flex align-items-center gap-2">
  42. <svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" fill="currentColor" class="bi bi-file-earmark-spreadsheet text-success" viewBox="0 0 16 16">
  43. <path d="M14 14V4.5L9.5 0H4a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h8a2 2 0 0 0 2-2M9.5 3A1.5 1.5 0 0 0 11 4.5h3V9H2V2a1 1 0 0 1 1-1h5.5zM2 10h1v1H2zm2 0h1v1H4zm3 0h1v1H7zm2 0h1v1H9zm2 0h1v1h-1zm1 1h1v1h-1zm-9 1h1v1H2zm2 0h1v1H4zm3 0h1v1H7zm2 0h1v1H9zm2 0h1v1h-1z"/>
  44. </svg>
  45. <h5 class="mb-0">Import from Lab File</h5>
  46. </div>
  47. <div class="card-body">
  48. <p class="text-muted mb-3">
  49. Upload an XLS, XLSX, CSV, or ODS file from your soil testing laboratory.
  50. The system will use AI to automatically map the lab's column names to the
  51. form fields below — works with CSBP and other lab formats.
  52. </p>
  53. <div class="row g-2 align-items-end">
  54. <div class="col-md-8">
  55. <label for="lab-file-input" class="form-label fw-semibold">Select lab file</label>
  56. <input type="file"
  57. class="form-control"
  58. id="lab-file-input"
  59. accept=".xls,.xlsx,.csv,.ods">
  60. </div>
  61. <div class="col-md-4">
  62. <button class="btn btn-success w-100"
  63. type="button"
  64. id="lab-analyse-btn"
  65. disabled>
  66. <span class="spinner-border spinner-border-sm me-1 d-none" id="import-spinner" role="status"></span>
  67. Analyse &amp; Import
  68. </button>
  69. </div>
  70. </div>
  71. <!-- Progress indicator -->
  72. <div id="import-progress" class="mt-3 d-flex align-items-center gap-2 text-muted" hidden>
  73. <div class="spinner-border spinner-border-sm text-success" role="status"></div>
  74. <span class="progress-label">Processing…</span>
  75. </div>
  76. <!-- Status / result message -->
  77. <div id="import-status" class="alert mt-3" hidden></div>
  78. <!-- Sample picker (multi-sample files) -->
  79. <div id="sample-picker-panel" hidden class="mt-3">
  80. <h6 class="fw-semibold">Multiple samples found — choose one to import:</h6>
  81. <div class="table-responsive">
  82. <table id="sample-picker-table" class="table table-sm table-hover align-middle">
  83. <thead class="table-light">
  84. <tr>
  85. <th>Lab ID</th>
  86. <th>Client</th>
  87. <th>Site / Paddock</th>
  88. <th>Crop / Material</th>
  89. <th></th>
  90. </tr>
  91. </thead>
  92. <tbody></tbody>
  93. </table>
  94. </div>
  95. </div>
  96. <p class="text-muted small mt-3 mb-0">
  97. Fields highlighted in green were auto-populated. Always review values before submitting.
  98. </p>
  99. </div>
  100. </div>
  101. <?php // include __DIR__ . '/../../../controllers/soilTestSubmit.php'; ?>
  102. <!-- old modX placeholders: [[!clientDetailsFORM]], [[!soilformSubmit]], [[!newClientDetails]] -->
  103. </div>
  104. </div>
  105. </div>
  106. </main>
  107. </div>
  108. </div>
  109. <script src="/client-assets/js/soil-import.js"></script>
  110. <?php include __DIR__ . '/../../../layouts/footer.php'; ?>