| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325 |
- <?php
- require_once 'config.php';
- require_once 'db_config.php';
- // --- 1. DATEN LADEN (REIHEN FÜR DEN FILTER) ---
- $reihen = $pdo->query("SELECT * FROM game_reihe ORDER BY name ASC")->fetchAll();
- // --- 2. LOGIK: NEUEN SPIELER HINZUFÜGEN ---
- if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['add_player'])) {
- $sql = "INSERT IGNORE INTO spieler (name) VALUES (?)";
- $stmt = $pdo->prepare($sql);
- $stmt->execute([$_POST['neuer_spieler_name']]);
- header("Location: index.php?success=player");
- exit;
- }
- // --- 3. LOGIK: SCORE HINZUFÜGEN (INKL. BUNDLE-LOGIK) ---
- if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['add_score'])) {
- $unbekannt = isset($_POST['ergebnis_unbekannt']);
- $zeit = $unbekannt ? 0 : (int)$_POST['zeit'];
- $hilfe = $unbekannt ? 0 : (int)$_POST['hilfe'];
- $sterne = $unbekannt ? 0 : (int)$_POST['sterne'];
- $spieler_id = $_POST['spieler_id'];
- $spiel_id = $_POST['spiel_id'];
- try {
- $pdo->beginTransaction();
- // 1. Den Haupt-Score speichern
- $sql = "INSERT INTO scores (spieler_id, spiel_id, zeit, hilfe, sterne) VALUES (?, ?, ?, ?, ?)";
- $stmt = $pdo->prepare($sql);
- $stmt->execute([$spieler_id, $spiel_id, $zeit, $hilfe, $sterne]);
- // 2. AUTOMATIK: Prüfen, ob dieses Spiel Unter-Abenteuer hat (Bundles)
- $stmtChildren = $pdo->prepare("SELECT id FROM spiele WHERE parent_id = ?");
- $stmtChildren->execute([$spiel_id]);
- $children = $stmtChildren->fetchAll();
- if ($children) {
- $sqlChildScore = "INSERT INTO scores (spieler_id, spiel_id, zeit, hilfe, sterne) VALUES (?, ?, ?, ?, ?)";
- $stmtChildScore = $pdo->prepare($sqlChildScore);
- foreach ($children as $child) {
- $stmtChildScore->execute([$spieler_id, $child['id'], $zeit, $hilfe, $sterne]);
- }
- }
- $pdo->commit();
- header("Location: index.php?success=score");
- exit;
- } catch (Exception $e) {
- $pdo->rollBack();
- die("Fehler beim Speichern: " . $e->getMessage());
- }
- }
- // --- 4. DATEN ABFRAGEN (NEUE STRUKTUR MIT JOINS) ---
- $sqlGames = "SELECT s.*,
- r.name as reihe_name,
- t.bezeichnung as typ_name,
- l.bezeichnung as level_name
- FROM spiele s
- LEFT JOIN game_reihe r ON s.game_reihe_id = r.id
- LEFT JOIN game_typ t ON s.game_typ_id = t.id
- LEFT JOIN game_level l ON s.game_level_id = l.id
- ORDER BY r.name ASC, s.titel ASC";
- $exitGames = $pdo->query($sqlGames)->fetchAll(PDO::FETCH_ASSOC);
- $playersList = $pdo->query("SELECT * FROM spieler ORDER BY name ASC")->fetchAll();
- $sqlScores = "SELECT s.*, p.name as spieler_name
- FROM scores s
- JOIN spieler p ON s.spieler_id = p.id
- ORDER BY s.id DESC";
- $allScores = $pdo->query($sqlScores)->fetchAll();
- // Hilfsfunktion Sterne (Zahlen zu ★)
- function getStarRating($val) {
- if (!is_numeric($val)) return htmlspecialchars($val);
- $n = (int)$val; $out = "";
- for($i=1; $i<=5; $i++) { $out .= ($i <= $n) ? "★" : "☆"; }
- return $out;
- }
- ?>
- <!DOCTYPE html>
- <html lang="de">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>EXIT - Dashboard</title>
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/swiper@11/swiper-bundle.min.css" />
- <style>
- :root {
- --bg: #f4f7f6; --card: #ffffff; --text: #333; --border: #ddd; --accent: #e67e22;
- --input-bg: #fff; --footer-bg: #f1f1f1; --success: #27ae60;
- }
- .dark-theme {
- --bg: #121212; --card: #1e1e1e; --text: #e0e0e0; --border: #333;
- --input-bg: #2a2a2a; --footer-bg: #1a1a1a;
- }
- body { font-family: 'Segoe UI', sans-serif; background: var(--bg); color: var(--text); margin: 0; padding-bottom: 120px; transition: 0.3s; }
- .container { max-width: 1200px; margin: auto; padding: 20px; }
-
- .alert { background: var(--success); color: white; padding: 15px; border-radius: 8px; margin-bottom: 20px; text-align: center; font-weight: bold; }
- header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 25px; border-bottom: 1px solid var(--border); padding-bottom: 15px; }
- h1 { color: var(--accent); margin: 0; font-size: 1.6em; }
- .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; }
- .swiper-outer-wrapper { position: relative; width: 100%; padding: 0 40px; box-sizing: border-box; margin-bottom: 40px; }
- .swiper-slide { width: 300px; height: auto; }
-
- .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); display: flex; flex-direction: column; }
- .card img { width: 100%; height: 160px; object-fit: cover; }
- .content { padding: 15px; flex-grow: 1; }
-
- h2 { color: var(--accent); margin: 0 0 5px 0; font-size: 1.1em; }
- .reihe-label { font-size: 0.75em; opacity: 0.7; text-transform: uppercase; display: block; margin-bottom: 2px; }
- .stats { width: 100%; border-collapse: collapse; font-size: 0.85em; margin-top: 10px; }
- .stats td { padding: 6px 0; border-bottom: 1px solid var(--border); }
-
- .badge { padding: 3px 7px; border-radius: 4px; font-size: 0.65em; font-weight: bold; text-transform: uppercase; color: white; display: inline-block; margin-bottom: 5px; margin-right: 3px; }
- .level-badge { background: #7f8c8d; }
- .type-badge { background: transparent; border: 1px solid var(--accent); color: var(--accent); }
- .bottom-section { display: grid; grid-template-columns: 1fr 2fr; gap: 20px; margin-top: 20px; }
- @media (max-width: 768px) { .bottom-section { grid-template-columns: 1fr; } .swiper-outer-wrapper { padding: 0 10px; } }
- .form-section, .info-section { background: var(--card); padding: 20px; border-radius: 12px; border: 1px solid var(--border); }
- .highlight-border { border-color: var(--accent); border-width: 2px; }
-
- input, select { width: 100%; padding: 10px; background: var(--input-bg); border: 1px solid var(--border); color: var(--text); border-radius: 5px; margin-bottom: 10px; }
- button { background: var(--accent); color: white; border: none; padding: 12px; border-radius: 5px; cursor: pointer; font-weight: bold; width: 100%; }
- .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; }
- .footer-nav a { color: var(--accent); text-decoration: none; font-weight: bold; font-size: 0.85em; }
- #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; }
- .overlay { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.7); z-index: 1500; }
- </style>
- </head>
- <body>
- <div class="container">
- <?php if (isset($_GET['success'])): ?>
- <div class="alert" id="success-alert">
- <?= $_GET['success'] === 'score' ? '✅ Score gespeichert!' : '👤 Spieler angelegt!' ?>
- </div>
- <?php endif; ?>
- <header>
- <h1>🏆 EXIT Highscores</h1>
- <button onclick="toggleTheme()" class="theme-toggle" id="theme-icon">🌙</button>
- </header>
- <div class="swiper-outer-wrapper">
- <div class="swiper mySwiper">
- <div class="swiper-wrapper">
- <?php foreach ($exitGames as $game): ?>
- <div class="swiper-slide">
- <div class="card">
- <?php
- $b = $game['bild_url'];
- $imgSrc = (empty($b)) ? 'https://via.placeholder.com/300x160?text=Kein+Cover' : (strpos($b, 'http') === 0 ? $b : IMG_URL . $b);
- ?>
- <img src="<?= htmlspecialchars($imgSrc) ?>" onerror="this.src='https://via.placeholder.com/300x160?text=Kein+Cover'">
- <div class="content">
- <span class="reihe-label"><?= htmlspecialchars($game['reihe_name']) ?></span>
- <h2><?= htmlspecialchars($game['titel']) ?></h2>
- <span class="badge type-badge"><?= htmlspecialchars($game['typ_name'] ?: 'Basis') ?></span>
- <span class="badge level-badge"><?= getStarRating($game['level_name'] ?: '---') ?></span>
- <table class="stats">
- <?php
- $found = false;
- foreach ($allScores as $entry):
- if ($entry['spiel_id'] == $game['id']): $found = true; ?>
- <tr>
- <td><strong><?= htmlspecialchars($entry['spieler_name']) ?></strong></td>
- <td><?= $entry['zeit'] > 0 ? $entry['zeit']." Min" : '?' ?></td>
- <td style="color:#f1c40f; text-align:right;"><?= $entry['sterne'] > 0 ? $entry['sterne']."★" : "✔" ?></td>
- </tr>
- <?php endif; endforeach;
- if (!$found) echo "<tr><td colspan='3' style='opacity:0.4'>Noch ungelöst...</td></tr>";
- ?>
- </table>
- </div>
- </div>
- </div>
- <?php endforeach; ?>
- </div>
- <div class="swiper-pagination"></div>
- </div>
- </div>
- <div class="bottom-section">
- <div class="info-section">
- <h2>📜 Archiv</h2>
- <p style="font-size: 0.8em; opacity: 0.6;">Alle Spielergebnisse einsehen.</p>
- <a href="gespielte_spiele.php" style="color: var(--accent); font-weight:bold; text-decoration:none;">📂 Zur Übersicht</a>
- </div>
- <div class="form-section highlight-border">
- <h2>🎯 Score eintragen</h2>
- <form method="POST">
- <select id="filter_reihe" onchange="filterGamesByReihe()">
- <option value="">-- Alle Reihen --</option>
- <?php foreach ($reihen as $r): ?>
- <option value="<?= $r['id'] ?>"><?= htmlspecialchars($r['name']) ?></option>
- <?php endforeach; ?>
- </select>
- <select name="spiel_id" id="spiel_select" required>
- <option value="">-- Spiel wählen --</option>
- <?php foreach ($exitGames as $game): ?>
- <option value="<?= $game['id'] ?>" data-reihe="<?= $game['game_reihe_id'] ?>">
- <?= htmlspecialchars($game['reihe_name']) ?>: <?= htmlspecialchars($game['titel']) ?>
- </option>
- <?php endforeach; ?>
- </select>
- <select name="spieler_id" required>
- <option value="">-- Wer hat gespielt? --</option>
- <?php foreach ($playersList as $p): ?>
- <option value="<?= $p['id'] ?>"><?= htmlspecialchars($p['name']) ?></option>
- <?php endforeach; ?>
- </select>
-
- <div style="display: flex; align-items: center; gap: 8px; margin-bottom:10px; font-size:0.9em;">
- <input type="checkbox" name="ergebnis_unbekannt" id="ergebnis_unbekannt" onchange="toggleInputs()" style="width:auto; margin:0;">
- <label for="ergebnis_unbekannt">Ergebnis unbekannt (nur Archivierung)</label>
- </div>
- <div id="input-fields" style="display: flex; gap: 10px;">
- <input type="number" name="zeit" id="zeit" placeholder="Min" required>
- <input type="number" name="sterne" id="sterne" min="1" max="10" placeholder="Sterne">
- <input type="number" name="hilfe" id="hilfe" placeholder="Hilfe">
- </div>
- <button type="submit" name="add_score">Score speichern</button>
- </form>
- </div>
- </div>
- </div>
- <div class="footer-nav">
- <a href="javascript:void(0)" onclick="toggleModal()">👤 NEUER SPIELER</a>
- <a href="besitz.php">📦 BESTAND</a>
- <a href="gesamtliste.php">📝 LISTE</a>
- <a href="admin.php">🛠 ADMIN</a>
- </div>
- <div class="overlay" id="overlay" onclick="toggleModal()"></div>
- <div id="playerModal">
- <h2 style="color:var(--accent); margin-top:0;">👤 Team/Spieler</h2>
- <form method="POST">
- <input type="text" name="neuer_spieler_name" placeholder="Name" required>
- <button type="submit" name="add_player">Anlegen</button>
- <button type="button" onclick="toggleModal()" style="background: #666; margin-top: 8px;">Abbrechen</button>
- </form>
- </div>
- <script src="https://cdn.jsdelivr.net/npm/swiper@11/swiper-bundle.min.js"></script>
- <script>
- function toggleTheme() {
- const isDark = document.documentElement.classList.toggle('dark-theme');
- localStorage.setItem('theme', isDark ? 'dark' : 'light');
- document.getElementById('theme-icon').innerText = isDark ? '☀️' : '🌙';
- }
- if (localStorage.getItem('theme') === 'dark') {
- document.documentElement.classList.add('dark-theme');
- document.getElementById('theme-icon').innerText = '☀️';
- }
- function filterGamesByReihe() {
- const reihenId = document.getElementById('filter_reihe').value;
- const select = document.getElementById('spiel_select');
- const options = select.querySelectorAll('option');
- options.forEach(opt => {
- const rId = opt.getAttribute('data-reihe');
- if (reihenId === "" || rId === reihenId || !rId) {
- opt.style.display = "block";
- } else {
- opt.style.display = "none";
- }
- });
- select.value = "";
- }
- function toggleInputs() {
- const check = document.getElementById('ergebnis_unbekannt');
- const ids = ['zeit', 'sterne', 'hilfe'];
- ids.forEach(id => {
- const el = document.getElementById(id);
- el.disabled = check.checked;
- if (check.checked) el.value = '';
- if (id === 'zeit') el.required = !check.checked;
- });
- document.getElementById('input-fields').style.opacity = check.checked ? '0.5' : '1';
- }
- function toggleModal() {
- const m = document.getElementById('playerModal');
- const o = document.getElementById('overlay');
- const vis = m.style.display === 'block';
- m.style.display = vis ? 'none' : 'block';
- o.style.display = vis ? 'none' : 'block';
- }
- new Swiper(".mySwiper", {
- slidesPerView: "auto",
- spaceBetween: 20,
- pagination: { el: ".swiper-pagination", type: "progressbar" },
- });
- setTimeout(() => {
- const a = document.getElementById('success-alert');
- if(a) a.style.display = 'none';
- }, 3000);
- </script>
- </body>
- </html>
|