index.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. <?php
  2. require_once 'db_config.php';
  3. // --- LOGIK: NEUEN SPIELER HINZUFÜGEN ---
  4. if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['add_player'])) {
  5. $sql = "INSERT IGNORE INTO spieler (name) VALUES (?)";
  6. $stmt = $pdo->prepare($sql);
  7. $stmt->execute([$_POST['neuer_spieler_name']]);
  8. header("Location: " . $_SERVER['PHP_SELF']);
  9. exit;
  10. }
  11. // --- LOGIK: SCORE HINZUFÜGEN ---
  12. if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['add_score'])) {
  13. $sql = "INSERT INTO scores (spieler_id, spiel_id, zeit, hilfe, sterne) VALUES (?, ?, ?, ?, ?)";
  14. $stmt = $pdo->prepare($sql);
  15. $stmt->execute([
  16. $_POST['spieler_id'],
  17. $_POST['spiel_id'],
  18. (int)$_POST['zeit'],
  19. (int)$_POST['hilfe'],
  20. (int)$_POST['sterne']
  21. ]);
  22. header("Location: " . $_SERVER['PHP_SELF']);
  23. exit;
  24. }
  25. // --- DATEN ABFRAGEN ---
  26. $stmtGames = $pdo->query("SELECT * FROM spiele ORDER BY id DESC");
  27. $exitGames = $stmtGames->fetchAll(PDO::FETCH_ASSOC);
  28. $stmtAllPlayers = $pdo->query("SELECT * FROM spieler ORDER BY name ASC");
  29. $playersList = $stmtAllPlayers->fetchAll();
  30. $sqlScores = "SELECT s.*, p.name as spieler_name
  31. FROM scores s
  32. JOIN spieler p ON s.spieler_id = p.id
  33. ORDER BY s.sterne DESC, s.zeit ASC";
  34. $allScores = $pdo->query($sqlScores)->fetchAll();
  35. ?>
  36. <!DOCTYPE html>
  37. <html lang="de">
  38. <head>
  39. <meta charset="UTF-8">
  40. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  41. <title>EXIT - Dashboard</title>
  42. <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/swiper@11/swiper-bundle.min.css" />
  43. <style>
  44. /* THEME VARIABLEN */
  45. :root {
  46. --bg: #f4f7f6; --card: #ffffff; --text: #333; --border: #ddd; --accent: #e67e22;
  47. --input-bg: #fff; --footer-bg: #f1f1f1;
  48. }
  49. .dark-theme {
  50. --bg: #121212; --card: #1e1e1e; --text: #e0e0e0; --border: #333;
  51. --input-bg: #2a2a2a; --footer-bg: #1a1a1a;
  52. }
  53. body { font-family: 'Segoe UI', sans-serif; background: var(--bg); color: var(--text); margin: 0; padding-bottom: 120px; transition: 0.3s; }
  54. .container { max-width: 1200px; margin: auto; padding: 20px; }
  55. /* HEADER FIX */
  56. header {
  57. display: flex;
  58. justify-content: space-between;
  59. align-items: center;
  60. margin-bottom: 25px;
  61. border-bottom: 1px solid var(--border);
  62. padding-bottom: 15px;
  63. }
  64. h1 { color: var(--accent); margin: 0; font-size: 1.6em; }
  65. /* KOMPAKTER THEME-TOGGLE (Identisch zu den anderen Seiten) */
  66. .theme-toggle {
  67. background: var(--card);
  68. border: 1px solid var(--border);
  69. color: var(--text);
  70. width: 42px; /* Feste Breite */
  71. height: 34px; /* Feste Höhe */
  72. padding: 0;
  73. border-radius: 10px;
  74. cursor: pointer;
  75. font-size: 1.1rem;
  76. display: flex;
  77. align-items: center;
  78. justify-content: center;
  79. transition: 0.3s;
  80. flex-shrink: 0; /* Verhindert Aufblähen */
  81. }
  82. .theme-toggle:hover { border-color: var(--accent); }
  83. /* Swiper & Cards */
  84. .swiper { width: 100%; padding-bottom: 40px; }
  85. .swiper-slide { width: 320px; height: auto; }
  86. .card { background: var(--card); border-radius: 12px; border: 1px solid var(--border); overflow: hidden; height: 100%; box-shadow: 0 4px 15px rgba(0,0,0,0.1); }
  87. .card img { width: 100%; height: 180px; object-fit: cover; opacity: 0.9; }
  88. .content { padding: 15px; }
  89. h2 { color: var(--accent); margin-top: 0; font-size: 1.1em; }
  90. .stats { width: 100%; border-collapse: collapse; font-size: 0.85em; }
  91. .stats td { padding: 6px 0; border-bottom: 1px solid var(--border); }
  92. .badge { padding: 4px 8px; border-radius: 4px; font-size: 0.7em; font-weight: bold; text-transform: uppercase; color: white; display: inline-block; margin-bottom: 5px; }
  93. .level-Einsteiger { background: #27ae60; }
  94. .level-Profi { background: #c0392b; }
  95. .level-Fortgeschrittene { background: #2980b9; }
  96. .level-unknown { background: #f39c12; }
  97. /* Formulare & Layout */
  98. .bottom-section { display: grid; grid-template-columns: 1fr 2fr; gap: 20px; margin-top: 20px; }
  99. @media (max-width: 768px) { .bottom-section { grid-template-columns: 1fr; } }
  100. .form-section, .info-section { background: var(--card); padding: 20px; border-radius: 12px; border: 1px solid var(--border); }
  101. .highlight-border { border-color: var(--accent); }
  102. input, select { width: 100%; padding: 10px; background: var(--input-bg); border: 1px solid var(--border); color: var(--text); border-radius: 5px; box-sizing: border-box; margin-bottom: 10px; }
  103. button { background: var(--accent); color: white; border: none; padding: 12px; border-radius: 5px; cursor: pointer; font-weight: bold; width: 100%; }
  104. /* Footer Nav */
  105. .footer-nav { position: fixed; bottom: 0; left: 0; width: 100%; background: var(--footer-bg); border-top: 2px solid var(--accent); padding: 15px 0; display: flex; justify-content: center; gap: 20px; z-index: 1000; flex-wrap: wrap; }
  106. .footer-nav a { color: var(--accent); text-decoration: none; font-weight: bold; font-size: 0.8em; padding: 5px 10px; border: 1px solid transparent; transition: 0.3s; }
  107. .footer-nav a:hover { border-color: var(--accent); border-radius: 5px; }
  108. .info-section a { color: var(--accent); text-decoration: none; display: block; padding: 10px; border: 1px dashed var(--border); border-radius: 8px; text-align: center; }
  109. /* Modal */
  110. #playerModal { display: none; position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); background: var(--card); padding: 30px; border-radius: 12px; border: 1px solid var(--accent); z-index: 2000; box-shadow: 0 0 50px rgba(0,0,0,0.5); color: var(--text); }
  111. .overlay { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.7); z-index: 1500; }
  112. </style>
  113. <script>
  114. if (localStorage.getItem('theme') === 'dark') document.documentElement.classList.add('dark-theme');
  115. </script>
  116. </head>
  117. <body>
  118. <div class="container">
  119. <header>
  120. <h1>🏆 EXIT Highscores</h1>
  121. <button onclick="toggleTheme()" class="theme-toggle" id="theme-icon">🌙</button>
  122. </header>
  123. <div class="swiper mySwiper">
  124. <div class="swiper-wrapper">
  125. <?php foreach ($exitGames as $game):
  126. $lvl_class = (empty($game['level']) || strtolower($game['level']) == 'unknown') ? 'unknown' : $game['level'];
  127. $lvl_display = ($lvl_class == 'unknown') ? 'Unbekannt' : $game['level'];
  128. ?>
  129. <div class="swiper-slide">
  130. <div class="card">
  131. <img src="<?= htmlspecialchars($game['bild_url']) ?>" alt="Cover" onerror="this.src='https://via.placeholder.com/320x180?text=Kein+Bild'">
  132. <div class="content">
  133. <span class="badge level-<?= $lvl_class ?>"><?= htmlspecialchars($lvl_display) ?></span>
  134. <h2><?= htmlspecialchars($game['titel']) ?></h2>
  135. <table class="stats">
  136. <?php
  137. $found = false;
  138. foreach ($allScores as $entry):
  139. if ($entry['spiel_id'] == $game['id']): $found = true; ?>
  140. <tr>
  141. <td><strong><?= htmlspecialchars($entry['spieler_name']) ?></strong></td>
  142. <td><?= $entry['zeit'] ?>'</td>
  143. <td style="color:#f1c40f"><?= $entry['sterne'] ?>★</td>
  144. </tr>
  145. <?php endif; endforeach;
  146. if (!$found) echo "<tr><td colspan='3' style='opacity:0.5'>Noch keine Scores.</td></tr>";
  147. ?>
  148. </table>
  149. </div>
  150. </div>
  151. </div>
  152. <?php endforeach; ?>
  153. </div>
  154. <div class="swiper-pagination"></div>
  155. </div>
  156. <div class="bottom-section">
  157. <div class="info-section">
  158. <h2>📜 Archiv</h2>
  159. <p style="font-size: 0.8em; opacity: 0.6;">Bereits gelöste Abenteuer einsehen.</p>
  160. <a href="gespielte_spiele.php">📂 Übersicht gespielte Spiele</a>
  161. </div>
  162. <div class="form-section highlight-border">
  163. <h2>🎯 Ergebnis eintragen</h2>
  164. <form method="POST">
  165. <select name="spiel_id" required>
  166. <?php foreach ($exitGames as $game): ?>
  167. <option value="<?= $game['id'] ?>"><?= htmlspecialchars($game['titel']) ?></option>
  168. <?php endforeach; ?>
  169. </select>
  170. <select name="spieler_id" required>
  171. <option value="">-- Wer hat gespielt? --</option>
  172. <?php foreach ($playersList as $p): ?>
  173. <option value="<?= $p['id'] ?>"><?= htmlspecialchars($p['name']) ?></option>
  174. <?php endforeach; ?>
  175. </select>
  176. <div style="display: flex; gap: 10px;">
  177. <input type="number" name="zeit" placeholder="Min" required>
  178. <input type="number" name="sterne" min="1" max="10" placeholder="Sterne">
  179. <input type="number" name="hilfe" placeholder="Hilfe">
  180. </div>
  181. <button type="submit" name="add_score">Score speichern</button>
  182. </form>
  183. </div>
  184. </div>
  185. </div>
  186. <div class="footer-nav">
  187. <a href="javascript:void(0)" onclick="toggleModal()">👤 NEUER SPIELER</a>
  188. <a href="besitz.php">📦 BESTAND</a>
  189. <a href="gesamtliste.php">📝 GESAMTÜBERSICHT</a>
  190. <a href="admin.php">🛠 ADMIN</a>
  191. </div>
  192. <div class="overlay" id="overlay" onclick="toggleModal()"></div>
  193. <div id="playerModal">
  194. <h2>👤 Team/Spieler anlegen</h2>
  195. <form method="POST">
  196. <input type="text" name="neuer_spieler_name" placeholder="Name (z.B. Die Füchse)" required>
  197. <button type="submit" name="add_player">Anlegen</button>
  198. <button type="button" onclick="toggleModal()" style="background: #666; margin-top: 10px;">Abbrechen</button>
  199. </form>
  200. </div>
  201. <script src="https://cdn.jsdelivr.net/npm/swiper@11/swiper-bundle.min.js"></script>
  202. <script>
  203. // Theme-Logik
  204. function toggleTheme() {
  205. const isDark = document.documentElement.classList.toggle('dark-theme');
  206. localStorage.setItem('theme', isDark ? 'dark' : 'light');
  207. updateIcon(isDark);
  208. }
  209. function updateIcon(isDark) {
  210. document.getElementById('theme-icon').innerText = isDark ? '☀️' : '🌙';
  211. }
  212. if (localStorage.getItem('theme') === 'dark') updateIcon(true);
  213. // Swiper
  214. const swiper = new Swiper(".mySwiper", {
  215. slidesPerView: "auto",
  216. spaceBetween: 20,
  217. centeredSlides: false,
  218. grabCursor: true,
  219. pagination: { el: ".swiper-pagination", clickable: true },
  220. });
  221. // Modal
  222. function toggleModal() {
  223. const modal = document.getElementById('playerModal');
  224. const overlay = document.getElementById('overlay');
  225. const isVisible = modal.style.display === 'block';
  226. modal.style.display = isVisible ? 'none' : 'block';
  227. overlay.style.display = isVisible ? 'none' : 'block';
  228. }
  229. </script>
  230. </body>
  231. </html>