navbar.php 4.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. if ($navbarTableExists && $navbarHasEntries) {
  3. // Fetch navbar items from the database and render them for nicht behindertes navbar ohni js <3
  4. $navbarItems = [];
  5. $navbarResult = $db->query("SELECT * FROM navbar ORDER BY id");
  6. while ($row = $navbarResult->fetchArray(SQLITE3_ASSOC)) {
  7. $navbarItems[] = $row;
  8. }
  9. // Function to render the navbar items im grosse navbar für normali mensche
  10. function render_navbar($items, $currentPage) {
  11. $leftItems = array_filter($items, fn($item) => $item['align'] === 'left');
  12. $centerItems = array_filter($items, fn($item) => $item['align'] === 'center');
  13. $rightItems = array_filter($items, fn($item) => $item['align'] === 'right');
  14. echo '<div class="navbar-left">';
  15. render_navbar_items($leftItems, $currentPage);
  16. echo '</div>';
  17. echo '<div class="navbar-center">';
  18. render_navbar_items($centerItems, $currentPage);
  19. echo '</div>';
  20. echo '<div class="navbar-right">';
  21. render_navbar_items($rightItems, $currentPage);
  22. echo '</div>';
  23. }
  24. function render_navbar_items($items, $currentPage) {
  25. foreach ($items as $item) {
  26. $activeClass = ($item['link'] == "?page=$currentPage") ? ' class="active"' : '';
  27. switch ($item['type']) {
  28. case 'title':
  29. echo '<span class="navbar-title">' . htmlspecialchars($item['name']) . '</span>';
  30. break;
  31. case 'link':
  32. echo '<a href="' . htmlspecialchars($item['link']) . '"' . $activeClass . '>' . htmlspecialchars($item['name']) . '</a>';
  33. break;
  34. case 'drop down':
  35. echo '<div class="navbar-dropdown">';
  36. echo '<a class="navbar-dropbtn" href="#">' . htmlspecialchars($item['name']) . '</a>';
  37. echo '<div class="navbar-dropdown-content">';
  38. foreach ($items as $dropdownItem) {
  39. if ($dropdownItem['type'] === 'drop down entry' && $dropdownItem['name'] === $item['name']) {
  40. echo '<a href="' . htmlspecialchars($dropdownItem['link']) . '">' . htmlspecialchars($dropdownItem['link_text']) . '</a>';
  41. }
  42. }
  43. echo '</div>';
  44. echo '</div>';
  45. break;
  46. case 'text field':
  47. echo '<input type="text" placeholder="' . htmlspecialchars($item['name']) . '">';
  48. break;
  49. case 'button':
  50. echo '<button onclick="location.href=\'' . htmlspecialchars($item['link']) . '\'">' . htmlspecialchars($item['name']) . '</button>';
  51. break;
  52. case 'custom':
  53. echo $item['link_text'];
  54. break;
  55. case 'logo':
  56. echo '<img src="' . htmlspecialchars($item['link']) . '" alt="' . htmlspecialchars($item['name']) . '" class="navbar-logo">';
  57. break;
  58. case 'search':
  59. echo '<input type="search" placeholder="' . htmlspecialchars($item['name']) . '">';
  60. break;
  61. }
  62. }
  63. }
  64. // Function to render the mobile navbar für behindertes hamburger menu
  65. function render_mobile_navbar($items, $menuExpanded) {
  66. echo '<div class="mobile-navbar-panel">';
  67. echo '<div class="navbar-header">';
  68. foreach ($items as $item) {
  69. if ($item['type'] === 'logo') {
  70. echo '<img src="' . htmlspecialchars($item['link']) . '" alt="' . htmlspecialchars($item['name']) . '" class="navbar-logo">';
  71. }
  72. if ($item['type'] === 'title') {
  73. echo '<span class="navbar-title">' . htmlspecialchars($item['name']) . '</span>';
  74. }
  75. }
  76. $toggleState = $menuExpanded ? 0 : 1;
  77. echo '<form method="get" action="" style="display:inline;">';
  78. echo '<input type="hidden" name="menu" value="' . $toggleState . '">';
  79. echo '<button type="submit" class="navbar-toggle">' . ($menuExpanded ? 'Collapse' : 'Expand') . '</button>';
  80. echo '</form>';
  81. echo '</div>';
  82. echo '</div>';
  83. // Separate the menu from the navbar panel will mir ned ganz normali mensche sind und euses menu mit post uf und zue gaht
  84. if ($menuExpanded) {
  85. echo '<div class="mobile-navbar-menu">';
  86. render_navbar_items(array_filter($items, fn($item) => $item['type'] !== 'logo' && $item['type'] !== 'title'), '');
  87. echo '</div>';
  88. }
  89. }
  90. }
  91. ?>