navbarjs.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. function render_navbar_js($db) {
  3. // Fetch navbar items from the database and render them for behindertes dreckiges js navbar ... ich bin mal fullstack php dev gsi vor 5 jahr und jetzt machi das hier... 🤡
  4. $navbarQuery = $db->query("SELECT * FROM navbar ORDER BY id");
  5. $navbarItems = [];
  6. while ($row = $navbarQuery->fetchArray(SQLITE3_ASSOC)) {
  7. $navbarItems[] = $row;
  8. }
  9. echo '<nav class="navbar">';
  10. echo '<div class="navbar-container">';
  11. echo '<div class="navbar-left">';
  12. foreach ($navbarItems as $item) {
  13. $link = htmlspecialchars($item['link'] ?? '', ENT_QUOTES, 'UTF-8');
  14. $name = htmlspecialchars($item['name'] ?? '', ENT_QUOTES, 'UTF-8');
  15. if ($item['type'] === 'logo') {
  16. echo '<img class="navbar-logo" src="' . $link . '" alt="' . $name . '">';
  17. } elseif ($item['type'] === 'title') {
  18. echo '<a href="index.php" class="navbar-title">' . $name . '</a>';
  19. } elseif ($item['align'] === 'left' && $item['type'] === 'link') {
  20. echo '<a class="navbar-link" href="' . $link . '">' . $name . '</a>';
  21. } elseif ($item['align'] === 'left' && $item['type'] === 'button') {
  22. echo '<button class="buttonify" onclick="location.href=\'' . $link . '\'">' . $name . '</button>';
  23. } elseif ($item['align'] === 'left' && $item['type'] === 'text field') {
  24. echo '<input type="text" placeholder="' . $name . '">';
  25. } elseif ($item['align'] === 'left' && $item['type'] === 'search') {
  26. echo '<input type="search" placeholder="' . $name . '">';
  27. } elseif ($item['align'] === 'left' && $item['type'] === 'drop down') {
  28. echo '<div class="navbar-dropdown">';
  29. echo '<button class="navbar-dropbtn" onclick="location.href=\'' . $link . '\'">' . $name . '</button>';
  30. echo '<div class="navbar-dropdown-content">';
  31. foreach ($navbarItems as $dropdownItem) {
  32. if ($dropdownItem['type'] === 'drop down entry' && $dropdownItem['name'] === $item['name']) {
  33. $dropdownLink = htmlspecialchars($dropdownItem['link'] ?? '', ENT_QUOTES, 'UTF-8');
  34. $dropdownLinkText = htmlspecialchars($dropdownItem['link_text'] ?? '', ENT_QUOTES, 'UTF-8');
  35. echo '<a class="dropdown-link" href="' . $dropdownLink . '">' . $dropdownLinkText . '</a>';
  36. }
  37. }
  38. echo '</div>';
  39. echo '</div>';
  40. }
  41. }
  42. echo '</div>';
  43. echo '<div class="navbar-center">';
  44. foreach ($navbarItems as $item) {
  45. $link = htmlspecialchars($item['link'] ?? '', ENT_QUOTES, 'UTF-8');
  46. $name = htmlspecialchars($item['name'] ?? '', ENT_QUOTES, 'UTF-8');
  47. if ($item['align'] === 'center') {
  48. if ($item['type'] === 'link') {
  49. echo '<a class="navbar-link" href="' . $link . '">' . $name . '</a>';
  50. } elseif ($item['type'] === 'button') {
  51. echo '<button class="buttonify" onclick="location.href=\'' . $link . '\'">' . $name . '</button>';
  52. } elseif ($item['type'] === 'text field') {
  53. echo '<input type="text" placeholder="' . $name . '">';
  54. } elseif ($item['type'] === 'search') {
  55. echo '<input type="search" placeholder="' . $name . '">';
  56. } elseif ($item['type'] === 'drop down') {
  57. echo '<div class="navbar-dropdown">';
  58. echo '<button class="navbar-dropbtn" onclick="location.href=\'' . $link . '\'">' . $name . '</button>';
  59. echo '<div class="navbar-dropdown-content">';
  60. foreach ($navbarItems as $dropdownItem) {
  61. if ($dropdownItem['type'] === 'drop down entry' && $dropdownItem['name'] === $item['name']) {
  62. $dropdownLink = htmlspecialchars($dropdownItem['link'] ?? '', ENT_QUOTES, 'UTF-8');
  63. $dropdownLinkText = htmlspecialchars($dropdownItem['link_text'] ?? '', ENT_QUOTES, 'UTF-8');
  64. echo '<a class="dropdown-link" href="' . $dropdownLink . '">' . $dropdownLinkText . '</a>';
  65. }
  66. }
  67. echo '</div>';
  68. echo '</div>';
  69. }
  70. }
  71. }
  72. echo '</div>';
  73. echo '<div class="navbar-right">';
  74. foreach ($navbarItems as $item) {
  75. $link = htmlspecialchars($item['link'] ?? '', ENT_QUOTES, 'UTF-8');
  76. $name = htmlspecialchars($item['name'] ?? '', ENT_QUOTES, 'UTF-8');
  77. if ($item['align'] === 'right') {
  78. if ($item['type'] === 'link') {
  79. echo '<a class="navbar-link" href="' . $link . '">' . $name . '</a>';
  80. } elseif ($item['type'] === 'button') {
  81. echo '<button class="buttonify" onclick="location.href=\'' . $link . '\'">' . $name . '</button>';
  82. } elseif ($item['type'] === 'text field') {
  83. echo '<input type="text" placeholder="' . $name . '">';
  84. } elseif ($item['type'] === 'search') {
  85. echo '<input type="search" placeholder="' . $name . '">';
  86. } elseif ($item['type'] === 'drop down') {
  87. echo '<div class="navbar-dropdown">';
  88. echo '<button class="navbar-dropbtn" onclick="location.href=\'' . $link . '\'">' . $name . '</button>';
  89. echo '<div class="navbar-dropdown-content">';
  90. foreach ($navbarItems as $dropdownItem) {
  91. if ($dropdownItem['type'] === 'drop down entry' && $dropdownItem['name'] === $item['name']) {
  92. $dropdownLink = htmlspecialchars($dropdownItem['link'] ?? '', ENT_QUOTES, 'UTF-8');
  93. $dropdownLinkText = htmlspecialchars($dropdownItem['link_text'] ?? '', ENT_QUOTES, 'UTF-8');
  94. echo '<a class="dropdown-link" href="' . $dropdownLink . '">' . $dropdownLinkText . '</a>';
  95. }
  96. }
  97. echo '</div>';
  98. echo '</div>';
  99. }
  100. }
  101. }
  102. echo '</div>';
  103. echo '</div>';
  104. echo '<div class="navbar-mobile">';
  105. echo '<div class="navbar-left">';
  106. foreach ($navbarItems as $item) {
  107. $link = htmlspecialchars($item['link'] ?? '', ENT_QUOTES, 'UTF-8');
  108. $name = htmlspecialchars($item['name'] ?? '', ENT_QUOTES, 'UTF-8');
  109. if ($item['type'] === 'logo') {
  110. echo '<img class="navbar-logo" src="' . $link . '" alt="' . $name . '">';
  111. } elseif ($item['type'] === 'title') {
  112. echo '<a href="index.php" class="navbar-title">' . $name . '</a>';
  113. }
  114. }
  115. echo '</div>';
  116. echo '<button class="navbar-toggle" onclick="toggleNavbar()">☰</button>';
  117. echo '</div>';
  118. echo '<div class="mobile-navbar-menu">';
  119. foreach ($navbarItems as $item) {
  120. $link = htmlspecialchars($item['link'] ?? '', ENT_QUOTES, 'UTF-8');
  121. $name = htmlspecialchars($item['name'] ?? '', ENT_QUOTES, 'UTF-8');
  122. if ($item['type'] === 'link') {
  123. echo '<a class="navbar-link bruh-why" href="' . $link . '">' . $name . '</a>';
  124. } elseif ($item['type'] === 'drop down') {
  125. echo '<span class="mobile-navbar-dropdown" onclick="location.href=\'' . $link . '\'">' . $name . '</span>';
  126. } elseif ($item['type'] === 'drop down entry') {
  127. $dropdownLink = htmlspecialchars($item['link'] ?? '', ENT_QUOTES, 'UTF-8');
  128. $dropdownLinkText = htmlspecialchars($item['link_text'] ?? '', ENT_QUOTES, 'UTF-8');
  129. echo '<a class="dropdown-link" href="' . $dropdownLink . '" class="mobile-dropdown-entry">↳ ' . $dropdownLinkText . '</a>';
  130. } elseif ($item['type'] === 'button') {
  131. echo '<button class="buttonify" onclick="location.href=\'' . $link . '\'">' . $name . '</button>';
  132. } elseif ($item['type'] === 'text field') {
  133. echo '<input type="text" placeholder="' . $name . '">';
  134. } elseif ($item['type'] === 'search') {
  135. echo '<input type="search" placeholder="' . $name . '">';
  136. }
  137. }
  138. echo '</div>';
  139. echo '</nav>';
  140. }
  141. ?>