gespielte_spiele.php 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <?php
  2. include 'db_config.php';
  3. // --- 1. DATEN LADEN ---
  4. $allTeams = $pdo->query("SELECT * FROM spieler ORDER BY name ASC")->fetchAll();
  5. $teamFilter = isset($_GET['team_id']) ? (int)$_GET['team_id'] : 0;
  6. // Neue SQL-Struktur mit Joins für Reihe und Typ
  7. $sql = "SELECT sp.*,
  8. sc.zeit, sc.hilfe, sc.sterne,
  9. s.name as team_name,
  10. r.name as reihe_name,
  11. t.bezeichnung as typ_name
  12. FROM spiele sp
  13. JOIN scores sc ON sp.id = sc.spiel_id
  14. JOIN spieler s ON sc.spieler_id = s.id
  15. LEFT JOIN game_reihe r ON sp.game_reihe_id = r.id
  16. LEFT JOIN game_typ t ON sp.game_typ_id = t.id";
  17. if ($teamFilter > 0) {
  18. $sql .= " WHERE s.id = $teamFilter";
  19. }
  20. // Sortierung nach Reihenname, Spieltitel und dann Score-Zeit
  21. $sql .= " ORDER BY r.name ASC, sp.titel ASC, sc.zeit ASC";
  22. $stmt = $pdo->query($sql);
  23. $results = $stmt->fetchAll();
  24. // --- 2. GRUPPIERUNG NACH REIHE UND SPIEL ---
  25. $groupedData = [];
  26. foreach ($results as $row) {
  27. $reihe = !empty($row['reihe_name']) ? $row['reihe_name'] : 'Sonstige';
  28. $gameId = $row['id']; // ID als Key nutzen, falls Titel doppelt vorkommen könnten
  29. if (!isset($groupedData[$reihe][$gameId])) {
  30. $groupedData[$reihe][$gameId] = [
  31. 'titel' => $row['titel'],
  32. 'bild_url' => $row['bild_url'],
  33. 'typ_name' => $row['typ_name'],
  34. 'teams' => []
  35. ];
  36. }
  37. $groupedData[$reihe][$gameId]['teams'][] = [
  38. 'name' => $row['team_name'],
  39. 'zeit' => (int)$row['zeit'],
  40. 'hilfe' => (int)$row['hilfe'],
  41. 'sterne' => (int)$row['sterne']
  42. ];
  43. }
  44. ?>
  45. <!DOCTYPE html>
  46. <html lang="de">
  47. <head>
  48. <meta charset="UTF-8">
  49. <title>EXIT Log - Gelöste Abenteuer</title>
  50. <style>
  51. :root {
  52. --bg: #f4f7f6; --card: #ffffff; --text: #333; --border: #ddd; --accent: #e67e22;
  53. --muted: #888; --reihe-bg: #2c3e50;
  54. }
  55. .dark-theme {
  56. --bg: #121212; --card: #1e1e1e; --text: #ffffff; --border: #333; --muted: #aaa;
  57. }
  58. body { font-family: 'Segoe UI', sans-serif; background: var(--bg); color: var(--text); padding: 20px; transition: 0.3s; }
  59. .container { max-width: 1200px; margin: 0 auto; }
  60. header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 30px; border-bottom: 2px solid var(--accent); padding-bottom: 10px; }
  61. h1 { color: var(--accent); margin: 0; font-size: 1.8rem; }
  62. .btn-nav { background: var(--accent); color: white; text-decoration: none; padding: 10px 15px; border-radius: 8px; font-weight: bold; font-size: 0.9em; display: inline-block; }
  63. .theme-toggle { background: none; border: none; font-size: 1.5rem; cursor: pointer; padding: 0; line-height: 1; }
  64. .filter-bar { background: var(--card); padding: 15px; border-radius: 12px; border: 1px solid var(--border); margin-bottom: 25px; display: flex; align-items: center; gap: 15px; box-shadow: 0 4px 15px rgba(0,0,0,0.05); }
  65. select { padding: 8px 15px; border-radius: 6px; border: 1px solid var(--border); background: var(--bg); color: var(--text); cursor: pointer; }
  66. .reihe-divider { grid-column: 1 / -1; margin: 40px 0 20px; padding: 12px 20px; background: var(--reihe-bg); color: white; border-radius: 8px; font-size: 1.1rem; font-weight: bold; text-transform: uppercase; letter-spacing: 2px; box-shadow: 0 4px 10px rgba(0,0,0,0.1); }
  67. .reihe-divider:first-of-type { margin-top: 0; }
  68. .grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 25px; }
  69. .item { background: var(--card); border-radius: 12px; border: 1px solid var(--border); box-shadow: 0 4px 15px rgba(0,0,0,0.1); overflow: hidden; display: flex; flex-direction: column; }
  70. .item img { width: 100%; height: 200px; object-fit: cover; background: #2a2a2a; border-bottom: 1px solid var(--border); }
  71. .stats { padding: 15px; flex-grow: 1; }
  72. .game-title { font-weight: bold; display: block; margin-bottom: 5px; font-size: 1.2em; color: var(--accent); text-align: center; line-height: 1.2; }
  73. .game-subtitle { display: block; text-align: center; font-size: 0.75em; opacity: 0.6; margin-bottom: 15px; text-transform: uppercase; }
  74. .team-section-label { font-size: 0.7em; color: var(--muted); display: block; text-transform: uppercase; letter-spacing: 1px; margin-bottom: 10px; border-bottom: 1px solid var(--border); padding-bottom: 5px; }
  75. .team-entry { margin-bottom: 12px; padding-bottom: 12px; border-bottom: 1px dashed var(--border); }
  76. .team-entry:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }
  77. .team-name-text { font-size: 0.95em; font-weight: bold; display: block; margin-bottom: 5px; }
  78. .result-row { display: flex; justify-content: space-between; font-size: 0.8em; }
  79. .res-item span { opacity: 0.6; margin-right: 4px; }
  80. .res-item b { color: var(--accent); }
  81. .res-only-solved { font-size: 0.8em; color: var(--muted); font-style: italic; }
  82. @media (max-width: 600px) {
  83. header { flex-direction: column; gap: 15px; text-align: center; }
  84. .filter-bar { flex-direction: column; align-items: stretch; }
  85. .grid { grid-template-columns: 1fr; }
  86. }
  87. </style>
  88. </head>
  89. <body>
  90. <div class="container">
  91. <header>
  92. <h1>📂 Gelöste Abenteuer</h1>
  93. <div style="display: flex; align-items: center; gap: 15px;">
  94. <button onclick="toggleTheme()" class="theme-toggle" id="theme-icon">🌙</button>
  95. <a href="index.php" class="btn-nav">Dashboard</a>
  96. </div>
  97. </header>
  98. <div class="filter-bar">
  99. <strong>Filter nach Team:</strong>
  100. <form id="filterForm" method="GET">
  101. <select name="team_id" onchange="this.form.submit()">
  102. <option value="0">-- Alle Teams --</option>
  103. <?php foreach ($allTeams as $t): ?>
  104. <option value="<?= $t['id'] ?>" <?= $teamFilter == $t['id'] ? 'selected' : '' ?>>
  105. <?= htmlspecialchars($t['name']) ?>
  106. </option>
  107. <?php endforeach; ?>
  108. </select>
  109. </form>
  110. </div>
  111. <div class="grid">
  112. <?php foreach ($groupedData as $reiheName => $games): ?>
  113. <div class="reihe-divider"><?= htmlspecialchars($reiheName) ?></div>
  114. <?php foreach ($games as $gameId => $data): ?>
  115. <div class="item">
  116. <img src="<?= htmlspecialchars($data['bild_url']) ?>" onerror="this.src='https://via.placeholder.com/300x200?text=Escape+Spiel'">
  117. <div class="stats">
  118. <span class="game-title"><?= htmlspecialchars($data['titel']) ?></span>
  119. <span class="game-subtitle"><?= htmlspecialchars($data['typ_name'] ?: '') ?></span>
  120. <span class="team-section-label">Gelöst von</span>
  121. <?php foreach ($data['teams'] as $team): ?>
  122. <div class="team-entry">
  123. <span class="team-name-text">👥 <?= htmlspecialchars($team['name']) ?></span>
  124. <?php if ($team['zeit'] === 0 && $team['hilfe'] === 0 && $team['sterne'] === 0): ?>
  125. <div class="res-only-solved">✅ Erfolgreich gelöst (Archiv)</div>
  126. <?php else: ?>
  127. <div class="result-row">
  128. <div class="res-item"><span>Zeit:</span><b><?= $team['zeit'] ?> Min.</b></div>
  129. <div class="res-item"><span>Hilfe:</span><b><?= $team['hilfe'] ?></b></div>
  130. <div class="res-item"><b>⭐ <?= $team['sterne'] ?></b></div>
  131. </div>
  132. <?php endif; ?>
  133. </div>
  134. <?php endforeach; ?>
  135. </div>
  136. </div>
  137. <?php endforeach; ?>
  138. <?php endforeach; ?>
  139. </div>
  140. </div>
  141. <script>
  142. const themeIcon = document.getElementById('theme-icon');
  143. function toggleTheme() {
  144. const isDark = document.documentElement.classList.toggle('dark-theme');
  145. localStorage.setItem('theme', isDark ? 'dark' : 'light');
  146. themeIcon.innerText = isDark ? '☀️' : '🌙';
  147. }
  148. if (localStorage.getItem('theme') === 'dark') {
  149. document.documentElement.classList.add('dark-theme');
  150. themeIcon.innerText = '☀️';
  151. }
  152. </script>
  153. </body>
  154. </html>