index.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  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: index.php?success=player");
  9. exit;
  10. }
  11. // --- LOGIK: SCORE HINZUFÜGEN ---
  12. if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['add_score'])) {
  13. $unbekannt = isset($_POST['ergebnis_unbekannt']);
  14. // Wenn unbekannt, werden 0-Werte gespeichert
  15. $zeit = $unbekannt ? 0 : (int)$_POST['zeit'];
  16. $hilfe = $unbekannt ? 0 : (int)$_POST['hilfe'];
  17. $sterne = $unbekannt ? 0 : (int)$_POST['sterne'];
  18. $sql = "INSERT INTO scores (spieler_id, spiel_id, zeit, hilfe, sterne) VALUES (?, ?, ?, ?, ?)";
  19. $stmt = $pdo->prepare($sql);
  20. $stmt->execute([
  21. $_POST['spieler_id'],
  22. $_POST['spiel_id'],
  23. $zeit,
  24. $hilfe,
  25. $sterne
  26. ]);
  27. header("Location: index.php?success=score");
  28. exit;
  29. }
  30. // --- DATEN ABFRAGEN ---
  31. $sqlGames = "SELECT s.*, t.bezeichnung as typ_name
  32. FROM spiele s
  33. LEFT JOIN game_typen t ON s.typ_id = t.id
  34. ORDER BY s.titel ASC";
  35. $stmtGames = $pdo->query($sqlGames);
  36. $exitGames = $stmtGames->fetchAll(PDO::FETCH_ASSOC);
  37. $stmtAllPlayers = $pdo->query("SELECT * FROM spieler ORDER BY name ASC");
  38. $playersList = $stmtAllPlayers->fetchAll();
  39. $sqlScores = "SELECT s.*, p.name as spieler_name
  40. FROM scores s
  41. JOIN spieler p ON s.spieler_id = p.id
  42. ORDER BY s.sterne DESC, s.zeit ASC";
  43. $allScores = $pdo->query($sqlScores)->fetchAll();
  44. ?>
  45. <!DOCTYPE html>
  46. <html lang="de">
  47. <head>
  48. <meta charset="UTF-8">
  49. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  50. <title>EXIT - Dashboard</title>
  51. <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/swiper@11/swiper-bundle.min.css" />
  52. <style>
  53. :root {
  54. --bg: #f4f7f6; --card: #ffffff; --text: #333; --border: #ddd; --accent: #e67e22;
  55. --input-bg: #fff; --footer-bg: #f1f1f1; --success: #27ae60;
  56. }
  57. .dark-theme {
  58. --bg: #121212cf; --card: #1e1e1e; --text: #e0e0e0; --border: #333;
  59. --input-bg: #2a2a2a; --footer-bg: #1a1a1a;
  60. }
  61. body { font-family: 'Segoe UI', sans-serif; background: var(--bg); color: var(--text); margin: 0; padding-bottom: 120px; transition: 0.3s; }
  62. .container { max-width: 1200px; margin: auto; padding: 20px; }
  63. .alert {
  64. background: var(--success); color: white; padding: 15px; border-radius: 8px;
  65. margin-bottom: 20px; text-align: center; font-weight: bold;
  66. animation: fadeOut 1s forwards; animation-delay: 3s;
  67. }
  68. @keyframes fadeOut { from {opacity: 1;} to {opacity: 0; visibility: hidden;} }
  69. header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 25px; border-bottom: 1px solid var(--border); padding-bottom: 15px; }
  70. h1 { color: var(--accent); margin: 0; font-size: 1.6em; }
  71. .theme-toggle { background: var(--card); border: 1px solid var(--border); color: var(--text); width: 42px; height: 34px; border-radius: 10px; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: 0.3s; }
  72. .swiper-outer-wrapper {
  73. position: relative;
  74. width: 100%;
  75. padding: 0 50px;
  76. box-sizing: border-box;
  77. margin-bottom: 40px;
  78. }
  79. .swiper { width: 100%; padding-top: 10px; }
  80. .swiper-slide { width: 320px; height: auto; }
  81. .swiper-pagination-progressbar { background: var(--border) !important; height: 4px !important; top: 0 !important; }
  82. .swiper-pagination-progressbar-fill { background: var(--accent) !important; }
  83. .swiper-button-next, .swiper-button-prev {
  84. color: var(--text);
  85. background: none;
  86. width: auto;
  87. height: auto;
  88. box-shadow: none;
  89. border: none;
  90. position: absolute;
  91. top: 50%;
  92. transform: translateY(-50%);
  93. z-index: 10;
  94. opacity: 0.5;
  95. transition: all 0.3s ease;
  96. }
  97. .swiper-button-next:hover, .swiper-button-prev:hover {
  98. color: var(--accent);
  99. opacity: 1;
  100. transform: translateY(-50%) scale(1.1);
  101. }
  102. .swiper-button-prev { left: 10px; }
  103. .swiper-button-next { right: 10px; }
  104. .swiper-button-next:after, .swiper-button-prev:after {
  105. font-size: 40px;
  106. font-weight: bold;
  107. }
  108. @media (max-width: 768px) {
  109. .swiper-outer-wrapper { padding: 0 10px; }
  110. .swiper-button-next, .swiper-button-prev { display: none; }
  111. }
  112. .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); }
  113. .card img { width: 100%; height: 180px; object-fit: cover; opacity: 0.9; }
  114. .content { padding: 15px; }
  115. h2 { color: var(--accent); margin-top: 0; font-size: 1.1em; }
  116. .stats { width: 100%; border-collapse: collapse; font-size: 0.85em; }
  117. .stats td { padding: 6px 0; border-bottom: 1px solid var(--border); }
  118. .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; }
  119. .level-Einsteiger { background: #27ae60; }
  120. .level-Profi { background: #c0392b; }
  121. .level-Fortgeschrittene { background: #2980b9; }
  122. .level-unknown { background: #f39c12; }
  123. .bottom-section { display: grid; grid-template-columns: 1fr 2fr; gap: 20px; margin-top: 20px; }
  124. @media (max-width: 768px) { .bottom-section { grid-template-columns: 1fr; } }
  125. .form-section, .info-section { background: var(--card); padding: 20px; border-radius: 12px; border: 1px solid var(--border); }
  126. .highlight-border { border-color: var(--accent); }
  127. .info-section a { color: var(--accent); text-decoration: none; display: block; padding: 10px; border: 1px dashed var(--border); border-radius: 8px; text-align: center; transition: 0.2s; }
  128. .info-section a:hover { background: var(--bg); border-color: var(--accent); }
  129. input, select { width: 100%; padding: 10px; background: var(--input-bg); border: 1px solid var(--border); color: var(--text); border-radius: 5px; margin-bottom: 10px; box-sizing: border-box; }
  130. button { background: var(--accent); color: white; border: none; padding: 12px; border-radius: 5px; cursor: pointer; font-weight: bold; width: 100%; }
  131. .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; }
  132. .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; }
  133. .footer-nav a:hover { border-color: var(--accent); border-radius: 5px; }
  134. #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; color: var(--text); box-shadow: 0 0 50px rgba(0,0,0,0.5); }
  135. .overlay { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.7); z-index: 1500; }
  136. .unknown-box { margin-bottom: 15px; display: flex; align-items: center; gap: 8px; font-size: 0.9em; }
  137. .unknown-box input { width: auto; margin: 0; cursor: pointer; }
  138. </style>
  139. <script>
  140. if (localStorage.getItem('theme') === 'dark') document.documentElement.classList.add('dark-theme');
  141. </script>
  142. </head>
  143. <body>
  144. <div class="container">
  145. <?php if (isset($_GET['success'])): ?>
  146. <div class="alert" id="success-alert">
  147. <?= $_GET['success'] === 'score' ? '✅ Score erfolgreich gespeichert!' : '👤 Neuer Spieler angelegt!' ?>
  148. </div>
  149. <?php endif; ?>
  150. <header>
  151. <h1>🏆 EXIT Highscores</h1>
  152. <button onclick="toggleTheme()" class="theme-toggle" id="theme-icon">🌙</button>
  153. </header>
  154. <div class="swiper-outer-wrapper">
  155. <div class="swiper mySwiper">
  156. <div class="swiper-pagination"></div>
  157. <div class="swiper-wrapper">
  158. <?php foreach ($exitGames as $game):
  159. $lvl_class = (empty($game['level']) || strtolower($game['level']) == 'unknown') ? 'unknown' : $game['level'];
  160. ?>
  161. <div class="swiper-slide">
  162. <div class="card">
  163. <img src="<?= htmlspecialchars($game['bild_url']) ?>" alt="Cover" onerror="this.src='https://via.placeholder.com/320x180?text=Kein+Bild'">
  164. <div class="content">
  165. <span class="badge level-<?= $lvl_class ?>"><?= htmlspecialchars($game['level'] ?: 'Unbekannt') ?></span>
  166. <h2><?= htmlspecialchars($game['titel']) ?></h2>
  167. <table class="stats">
  168. <?php
  169. $found = false;
  170. foreach ($allScores as $entry):
  171. if ($entry['spiel_id'] == $game['id']): $found = true; ?>
  172. <tr>
  173. <td><strong><?= htmlspecialchars($entry['spieler_name']) ?></strong></td>
  174. <td><?= $entry['zeit'] > 0 ? $entry['zeit']."'" : '?' ?></td>
  175. <td style="color:#f1c40f"><?= $entry['sterne'] > 0 ? $entry['sterne']."★" : "gespielt" ?></td>
  176. </tr>
  177. <?php endif; endforeach;
  178. if (!$found) echo "<tr><td colspan='3' style='opacity:0.5'>Noch keine Scores.</td></tr>";
  179. ?>
  180. </table>
  181. </div>
  182. </div>
  183. </div>
  184. <?php endforeach; ?>
  185. </div>
  186. </div>
  187. <div class="swiper-button-prev"></div>
  188. <div class="swiper-button-next"></div>
  189. </div>
  190. <div class="bottom-section">
  191. <div class="info-section">
  192. <h2>📜 Archiv</h2>
  193. <p style="font-size: 0.8em; opacity: 0.6; margin-bottom: 15px;">Bereits gelöste Abenteuer einsehen.</p>
  194. <a href="gespielte_spiele.php">📂 Übersicht gespielte Spiele</a>
  195. </div>
  196. <div class="form-section highlight-border">
  197. <h2>🎯 Ergebnis eintragen</h2>
  198. <form method="POST" action="index.php">
  199. <select name="spiel_id" required>
  200. <option value="">-- Spiel wählen --</option>
  201. <?php foreach ($exitGames as $game):
  202. $display_typ = $game['typ_name'] ?: 'Unbekannt';
  203. ?>
  204. <option value="<?= $game['id'] ?>">
  205. <?= htmlspecialchars($game['titel']) ?> (<?= htmlspecialchars($display_typ) ?>)
  206. </option>
  207. <?php endforeach; ?>
  208. </select>
  209. <select name="spieler_id" required>
  210. <option value="">-- Wer hat gespielt? --</option>
  211. <?php foreach ($playersList as $p): ?>
  212. <option value="<?= $p['id'] ?>"><?= htmlspecialchars($p['name']) ?></option>
  213. <?php endforeach; ?>
  214. </select>
  215. <div class="unknown-box">
  216. <input type="checkbox" name="ergebnis_unbekannt" id="ergebnis_unbekannt" onchange="toggleInputs()">
  217. <label for="ergebnis_unbekannt">Ergebnisse unbekannt</label>
  218. </div>
  219. <div id="input-fields" style="display: flex; gap: 10px;">
  220. <input type="number" name="zeit" id="zeit" placeholder="Min" required>
  221. <input type="number" name="sterne" id="sterne" min="1" max="10" placeholder="Sterne">
  222. <input type="number" name="hilfe" id="hilfe" placeholder="Hilfe">
  223. </div>
  224. <button type="submit" name="add_score">Score speichern</button>
  225. </form>
  226. </div>
  227. </div>
  228. </div>
  229. <div class="footer-nav">
  230. <a href="javascript:void(0)" onclick="toggleModal()">👤 NEUER SPIELER</a>
  231. <a href="besitz.php">📦 BESTAND</a>
  232. <a href="gesamtliste.php">📝 GESAMTÜBERSICHT</a>
  233. <a href="admin.php">🛠 ADMIN</a>
  234. </div>
  235. <div class="overlay" id="overlay" onclick="toggleModal()"></div>
  236. <div id="playerModal">
  237. <h2>👤 Team/Spieler anlegen</h2>
  238. <form method="POST" action="index.php">
  239. <input type="text" name="neuer_spieler_name" placeholder="Name" required>
  240. <button type="submit" name="add_player">Anlegen</button>
  241. <button type="button" onclick="toggleModal()" style="background: #666; margin-top: 10px;">Abbrechen</button>
  242. </form>
  243. </div>
  244. <script src="https://cdn.jsdelivr.net/npm/swiper@11/swiper-bundle.min.js"></script>
  245. <script>
  246. const themeIcon = document.getElementById('theme-icon');
  247. function toggleTheme() {
  248. const isDark = document.documentElement.classList.toggle('dark-theme');
  249. localStorage.setItem('theme', isDark ? 'dark' : 'light');
  250. themeIcon.innerText = isDark ? '☀️' : '🌙';
  251. }
  252. if (localStorage.getItem('theme') === 'dark') themeIcon.innerText = '☀️';
  253. function toggleInputs() {
  254. const check = document.getElementById('ergebnis_unbekannt');
  255. const fields = ['zeit', 'sterne', 'hilfe'];
  256. fields.forEach(id => {
  257. const el = document.getElementById(id);
  258. el.disabled = check.checked;
  259. if (check.checked) el.value = '';
  260. if (id === 'zeit') el.required = !check.checked;
  261. });
  262. document.getElementById('input-fields').style.opacity = check.checked ? '0.5' : '1';
  263. }
  264. new Swiper(".mySwiper", {
  265. slidesPerView: "auto",
  266. spaceBetween: 20,
  267. grabCursor: true,
  268. pagination: {
  269. el: ".swiper-pagination",
  270. type: "progressbar"
  271. },
  272. navigation: {
  273. nextEl: ".swiper-button-next",
  274. prevEl: ".swiper-button-prev",
  275. },
  276. });
  277. function toggleModal() {
  278. const m = document.getElementById('playerModal');
  279. const o = document.getElementById('overlay');
  280. const vis = m.style.display === 'block';
  281. m.style.display = vis ? 'none' : 'block';
  282. o.style.display = vis ? 'none' : 'block';
  283. }
  284. </script>
  285. </body>
  286. </html>