sidebar.php 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. <?php
  2. /**
  3. * layouts/sidebar.php
  4. *
  5. * Left sidebar navigation — matches original modX Wayfinder output.
  6. * Active state is detected automatically from the current request URI.
  7. * Collapsible sections restore open state via Bootstrap accordion.
  8. *
  9. * Requires lib/auth.php to already be included (for getCurrentUser()).
  10. */
  11. $currentUser = getCurrentUser() ?? ['fullname' => ''];
  12. // Detect current path for active-link highlighting
  13. $currentPath = parse_url($_SERVER['REQUEST_URI'] ?? '', PHP_URL_PATH);
  14. /**
  15. * Return 'active' if $href matches the current path, else ''.
  16. */
  17. $isActive = fn(string $href): string =>
  18. str_starts_with($currentPath, $href) ? ' active' : '';
  19. /**
  20. * Return true if any child href matches the current path.
  21. */
  22. $groupActive = function (array $children) use ($currentPath): bool {
  23. foreach ($children as $child) {
  24. if (str_starts_with($currentPath, $child)) return true;
  25. }
  26. return false;
  27. };
  28. // Child paths per collapsible group — used to keep the right group open
  29. $consultantChildren = ['/dashboard/consultant/'];
  30. $weatherChildren = ['/dashboard/weather/'];
  31. $cropChildren = [
  32. '/dashboard/crop-analysis/soil-test-data/',
  33. '/dashboard/crop-analysis/plant-test-data/',
  34. '/dashboard/crop-analysis/water-test-data/',
  35. '/dashboard/crop-analysis/animal-dietary-balance/',
  36. '/dashboard/crop-analysis/compost-test-data/',
  37. ];
  38. $settingsChildren = [
  39. '/dashboard/client-settings/soil-recommendations.php',
  40. '/dashboard/client-settings/product-list.php',
  41. '/dashboard/client-settings/update-details.php',
  42. ];
  43. ?>
  44. <nav id="sidenavAccordion" class="sb-sidenav accordion sb-sidenav-dark">
  45. <div class="sb-sidenav-menu">
  46. <div class="nav">
  47. <!-- Planning Calendar -->
  48. <a href="/dashboard/planning-calendar.php"
  49. class="nav-link<?= $isActive('/dashboard/planning-calendar.php') ?>">
  50. <div class="sb-nav-link-icon">
  51. <i class="fa fa-map-marker nav_icon"></i>
  52. </div>
  53. Planning Calendar
  54. </a>
  55. <!-- Report History / Inbox -->
  56. <a href="/dashboard/report.php"
  57. class="nav-link<?= $isActive('/dashboard/report.php') ?>">
  58. <div class="sb-nav-link-icon">
  59. <i class="fa fa-inbox nav_icon"></i>
  60. </div>
  61. Report History
  62. </a>
  63. <!-- Weather (collapsible) -->
  64. <a class="nav-link<?= $groupActive($weatherChildren) ? '' : ' collapsed' ?>"
  65. href="#"
  66. data-bs-toggle="collapse"
  67. data-bs-target="#collapseWeather"
  68. aria-expanded="<?= $groupActive($weatherChildren) ? 'true' : 'false' ?>"
  69. aria-controls="collapseWeather">
  70. <div class="sb-nav-link-icon">
  71. <i class="fa fa-cloud nav_icon"></i>
  72. </div>
  73. Weather
  74. <div class="sb-sidenav-collapse-arrow">
  75. <i class="fas fa-angle-down"></i>
  76. </div>
  77. </a>
  78. <div class="collapse<?= $groupActive($weatherChildren) ? ' show' : '' ?>"
  79. id="collapseWeather"
  80. data-bs-parent="#sidenavAccordion">
  81. <nav class="sb-sidenav-menu-nested nav">
  82. <a class="nav-link<?= $isActive('/dashboard/weather/moisture-sensor-setup.php') ?>"
  83. href="/dashboard/weather/moisture-sensor-setup.php">
  84. <i class="fa fa-eye-dropper nav_icon"></i>&nbsp;Moisture Sensor Setup
  85. </a>
  86. <a class="nav-link<?= $isActive('/dashboard/weather/weather-monitoring.php') ?>"
  87. href="/dashboard/weather/weather-monitoring.php">
  88. <i class="fas fa-cloud-sun nav_icon"></i>&nbsp;Weather Monitoring
  89. </a>
  90. <a class="nav-link<?= $isActive('/dashboard/weather/moisture-monitoring.php') ?>"
  91. href="/dashboard/weather/moisture-monitoring.php">
  92. <i class="fas fa-tint nav_icon"></i>&nbsp;Moisture Monitoring
  93. </a>
  94. </nav>
  95. </div>
  96. <!-- Pesticide -->
  97. <a href="/dashboard/pesticide.php"
  98. class="nav-link<?= $isActive('/dashboard/pesticide.php') ?>">
  99. <div class="sb-nav-link-icon">
  100. <i class="fa fa-bug nav_icon"></i>
  101. </div>
  102. Pesticide
  103. </a>
  104. <!-- Crop Analysis (collapsible) -->
  105. <a class="nav-link<?= $groupActive($cropChildren) ? '' : ' collapsed' ?>"
  106. href="#"
  107. data-bs-toggle="collapse"
  108. data-bs-target="#collapseCropAnalysis"
  109. aria-expanded="<?= $groupActive($cropChildren) ? 'true' : 'false' ?>"
  110. aria-controls="collapseCropAnalysis">
  111. <div class="sb-nav-link-icon">
  112. <i class="fa fa-tree nav_icon"></i>
  113. </div>
  114. Crop Analysis
  115. <div class="sb-sidenav-collapse-arrow">
  116. <i class="fas fa-angle-down"></i>
  117. </div>
  118. </a>
  119. <div class="collapse<?= $groupActive($cropChildren) ? ' show' : '' ?>"
  120. id="collapseCropAnalysis"
  121. data-bs-parent="#sidenavAccordion">
  122. <nav class="sb-sidenav-menu-nested nav">
  123. <a class="nav-link<?= $isActive('/dashboard/crop-analysis/soil-test-data/') ?>"
  124. href="/dashboard/crop-analysis/soil-test-data/index.php">
  125. <i class="fas fa-globe-asia nav_icon"></i>&nbsp;Soil Test Data
  126. </a>
  127. <a class="nav-link<?= $isActive('/dashboard/crop-analysis/plant-test-data/') ?>"
  128. href="/dashboard/crop-analysis/plant-test-data/index.php">
  129. <i class="fab fa-pagelines nav_icon"></i>&nbsp;Plant Test Data
  130. </a>
  131. <a class="nav-link<?= $isActive('/dashboard/crop-analysis/water-test-data/') ?>"
  132. href="/dashboard/crop-analysis/water-test-data/index.php">
  133. <i class="fa fa-tint nav_icon"></i>&nbsp;Water Test Data
  134. </a>
  135. <a class="nav-link<?= $isActive('/dashboard/crop-analysis/animal-dietary-balance/') ?>"
  136. href="/dashboard/crop-analysis/animal-dietary-balance/index.php">
  137. <i class="fas fa-dog nav_icon"></i>&nbsp;Animal Dietary Balance
  138. </a>
  139. <a class="nav-link<?= $isActive('/dashboard/crop-analysis/compost-test-data/') ?>"
  140. href="/dashboard/crop-analysis/compost-test-data/index.php">
  141. <i class="fas fa-cloud nav_icon"></i>&nbsp;Compost Test Data
  142. </a>
  143. </nav>s
  144. </div>
  145. <!-- Irrigation Controller -->
  146. <a href="/dashboard/irrigation/"
  147. class="nav-link<?= $isActive('/dashboard/irrigation/') ?>">
  148. <div class="sb-nav-link-icon">
  149. <i class="fas fa-cloud-sun-rain nav_icon"></i>
  150. </div>
  151. Irrigation Controller
  152. </a>
  153. <!-- Client Settings (collapsible) -->
  154. <a class="nav-link<?= $groupActive($settingsChildren) ? '' : ' collapsed' ?>"
  155. href="#"
  156. data-bs-toggle="collapse"
  157. data-bs-target="#collapseSettings"
  158. aria-expanded="<?= $groupActive($settingsChildren) ? 'true' : 'false' ?>"
  159. aria-controls="collapseSettings">
  160. <div class="sb-nav-link-icon">
  161. <i class="fa fa-cog nav_icon"></i>
  162. </div>
  163. Client Settings
  164. <div class="sb-sidenav-collapse-arrow">
  165. <i class="fas fa-angle-down"></i>
  166. </div>
  167. </a>
  168. <div class="collapse<?= $groupActive($settingsChildren) ? ' show' : '' ?>"
  169. id="collapseSettings"
  170. data-bs-parent="#sidenavAccordion">
  171. <nav class="sb-sidenav-menu-nested nav">
  172. <a class="nav-link<?= $isActive('/dashboard/client-settings/soil-recommendations.php') ?>"
  173. href="/dashboard/client-settings/soil-recommendations.php">
  174. <i class="fa fa-cog nav_icon"></i>&nbsp;Soil Recommendations
  175. </a>
  176. <a class="nav-link<?= $isActive('/dashboard/client-settings/product-list.php') ?>"
  177. href="/dashboard/client-settings/product-list.php">
  178. <i class="fa fa-cog nav_icon"></i>&nbsp;Product List
  179. </a>
  180. <a class="nav-link<?= $isActive('/dashboard/client-settings/update-details.php') ?>"
  181. href="/dashboard/client-settings/update-details.php">
  182. <i class="fa fa-cog nav_icon"></i>&nbsp;Update Details
  183. </a>
  184. </nav>
  185. </div>
  186. <!-- Crop Cards -->
  187. <a href="/dashboard/crop-cards/"
  188. class="nav-link<?= $isActive('/dashboard/crop-cards/') ?>">
  189. <div class="sb-nav-link-icon">
  190. <i class="fa fa-tree nav_icon"></i>
  191. </div>
  192. Crop Cards
  193. </a>
  194. </div>
  195. </div>
  196. <!-- Footer: logged-in user -->
  197. <div class="sb-sidenav-footer">
  198. <div class="small">Logged in as:</div>
  199. <?= htmlspecialchars($currentUser['fullname'], ENT_QUOTES, 'UTF-8') ?>
  200. </div>
  201. </nav>