gespielte_spiele.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. $sql = "SELECT sp.*, sc.zeit, sc.hilfe, sc.sterne, s.name as team_name
  7. FROM spiele sp
  8. JOIN scores sc ON sp.id = sc.spiel_id
  9. JOIN spieler s ON sc.spieler_id = s.id";
  10. if ($teamFilter > 0) {
  11. $sql .= " WHERE s.id = $teamFilter";
  12. }
  13. $sql .= " ORDER BY sp.titel ASC, sc.zeit ASC";
  14. $stmt = $pdo->query($sql);
  15. $results = $stmt->fetchAll();
  16. // --- 2. GRUPPIERUNG NACH SPIEL ---
  17. $groupedGames = [];
  18. foreach ($results as $row) {
  19. $gameTitle = $row['titel'];
  20. if (!isset($groupedGames[$gameTitle])) {
  21. $groupedGames[$gameTitle] = [
  22. 'bild_url' => $row['bild_url'],
  23. 'teams' => []
  24. ];
  25. }
  26. $groupedGames[$gameTitle]['teams'][] = [
  27. 'name' => $row['team_name'],
  28. 'zeit' => (int)$row['zeit'],
  29. 'hilfe' => (int)$row['hilfe'],
  30. 'sterne' => (int)$row['sterne']
  31. ];
  32. }
  33. ?>
  34. <!DOCTYPE html>
  35. <html lang="de">
  36. <head>
  37. <meta charset="UTF-8">
  38. <title>EXIT - Gelöste Abenteuer</title>
  39. <style>
  40. :root {
  41. --bg: #f4f7f6; --card: #ffffff; --text: #333; --border: #ddd; --accent: #e67e22;
  42. --muted: #888;
  43. }
  44. .dark-theme {
  45. --bg: #121212cf; --card: #1e1e1e; --text: #ffffff; --border: #333; --muted: #aaa;
  46. }
  47. body { font-family: 'Segoe UI', sans-serif; background: var(--bg); color: var(--text); padding: 20px; transition: 0.3s; }
  48. .container { max-width: 1200px; margin: 0 auto; }
  49. header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 30px; border-bottom: 2px solid var(--accent); padding-bottom: 10px; }
  50. h1 { color: var(--accent); margin: 0; font-size: 1.8rem; }
  51. .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; border: none; }
  52. .theme-toggle { background: none; border: none; font-size: 1.5rem; cursor: pointer; padding: 0; line-height: 1; }
  53. .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); }
  54. select { padding: 8px 15px; border-radius: 6px; border: 1px solid var(--border); background: var(--bg); color: var(--text); cursor: pointer; }
  55. .grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 25px; }
  56. .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; }
  57. .item img { width: 100%; height: 200px; object-fit: cover; background: #2a2a2a; border-bottom: 1px solid var(--border); }
  58. .stats { padding: 15px; flex-grow: 1; }
  59. .game-title { font-weight: bold; display: block; margin-bottom: 15px; font-size: 1.2em; color: var(--accent); text-align: center; }
  60. .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; }
  61. .team-entry { margin-bottom: 12px; padding-bottom: 12px; border-bottom: 1px dashed var(--border); }
  62. .team-entry:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }
  63. .team-name-text { font-size: 0.95em; font-weight: bold; display: block; margin-bottom: 5px; }
  64. .result-row { display: flex; justify-content: space-between; font-size: 0.8em; }
  65. .res-item span { opacity: 0.6; margin-right: 4px; }
  66. .res-item b { color: var(--accent); }
  67. .res-only-solved { font-size: 0.8em; color: var(--muted); font-style: italic; }
  68. @media (max-width: 600px) {
  69. header { flex-direction: column; gap: 15px; text-align: center; }
  70. .filter-bar { flex-direction: column; align-items: stretch; }
  71. }
  72. </style>
  73. <script>
  74. if (localStorage.getItem('theme') === 'dark') document.documentElement.classList.add('dark-theme');
  75. </script>
  76. </head>
  77. <body>
  78. <div class="container">
  79. <header>
  80. <h1>📂 Gelöste Abenteuer</h1>
  81. <div style="display: flex; align-items: center; gap: 15px;">
  82. <button onclick="toggleTheme()" class="theme-toggle" id="theme-icon">🌙</button>
  83. <a href="index.php" class="btn-nav">Dashboard</a>
  84. </div>
  85. </header>
  86. <div class="filter-bar">
  87. <strong>Filter nach Team:</strong>
  88. <form id="filterForm" method="GET">
  89. <select name="team_id" onchange="this.form.submit()">
  90. <option value="0">-- Alle Teams --</option>
  91. <?php foreach ($allTeams as $t): ?>
  92. <option value="<?= $t['id'] ?>" <?= $teamFilter == $t['id'] ? 'selected' : '' ?>>
  93. <?= htmlspecialchars($t['name']) ?>
  94. </option>
  95. <?php endforeach; ?>
  96. </select>
  97. </form>
  98. </div>
  99. <div class="grid">
  100. <?php foreach ($groupedGames as $title => $data): ?>
  101. <div class="item">
  102. <img src="<?= htmlspecialchars($data['bild_url']) ?>" onerror="this.src='https://via.placeholder.com/300x200?text=EXIT+Spiel'">
  103. <div class="stats">
  104. <span class="game-title"><?= htmlspecialchars($title) ?></span>
  105. <span class="team-section-label">Gelöst von</span>
  106. <?php foreach ($data['teams'] as $team): ?>
  107. <div class="team-entry">
  108. <span class="team-name-text">👥 <?= htmlspecialchars($team['name']) ?></span>
  109. <?php if ($team['zeit'] === 0 && $team['hilfe'] === 0 && $team['sterne'] === 0): ?>
  110. <div class="res-only-solved">✅ Erfolgreich gelöst</div>
  111. <?php else: ?>
  112. <div class="result-row">
  113. <div class="res-item"><span>Zeit:</span><b><?= $team['zeit'] ?> Min.</b></div>
  114. <div class="res-item"><span>Hilfe:</span><b><?= $team['hilfe'] ?></b></div>
  115. <div class="res-item"><b>⭐ <?= $team['sterne'] ?></b></div>
  116. </div>
  117. <?php endif; ?>
  118. </div>
  119. <?php endforeach; ?>
  120. </div>
  121. </div>
  122. <?php endforeach; ?>
  123. </div>
  124. <?php if (empty($groupedGames)): ?>
  125. <p style="text-align: center; margin-top: 50px; opacity: 0.5;">Hier wurden noch keine Abenteuer gelöst.</p>
  126. <?php endif; ?>
  127. </div>
  128. <script>
  129. const themeIcon = document.getElementById('theme-icon');
  130. function toggleTheme() {
  131. const isDark = document.documentElement.classList.toggle('dark-theme');
  132. localStorage.setItem('theme', isDark ? 'dark' : 'light');
  133. themeIcon.innerText = isDark ? '☀️' : '🌙';
  134. }
  135. if (localStorage.getItem('theme') === 'dark') {
  136. themeIcon.innerText = '☀️';
  137. }
  138. </script>
  139. </body>
  140. </html>