Эх сурвалжийг харах

Elternspiele "Karton" eingebaut, kommt bei "Escape-Rooms das Spiel" zum tragen

erdo 1 сар өмнө
parent
commit
8fd94c80cf
4 өөрчлөгдсөн 270 нэмэгдсэн , 136 устгасан
  1. 82 72
      admin.php
  2. 145 48
      besitz.php
  3. 11 8
      gespielte_spiele.php
  4. 32 8
      index.php

+ 82 - 72
admin.php

@@ -18,7 +18,7 @@ if (!(isset($_SESSION['admin_auth']) && $_SESSION['admin_auth'] === true)):
 <?php exit; endif; ?>
 
 <?php
-// --- HELPER: STERNE RENDERER ---
+// --- HELPER ---
 function renderStars($val) {
     if (!is_numeric($val)) return htmlspecialchars($val);
     $n = (int)$val; $out = "";
@@ -29,81 +29,67 @@ function renderStars($val) {
 // --- 2. SQL AKTIONEN ---
 $msg = ""; $error = "";
 
-// SPIELE SPEICHERN
 if (isset($_POST['save_game'])) {
     $id = (int)($_POST['id'] ?? 0);
     $r_id = (int)$_POST['game_reihe_id'];
     $t_id = ($_POST['game_typ_id'] == '0') ? null : (int)$_POST['game_typ_id'];
     $l_id = ($_POST['game_level_id'] == '0') ? null : (int)$_POST['game_level_id'];
+    $p_id = (isset($_POST['parent_id']) && $_POST['parent_id'] != '0') ? (int)$_POST['parent_id'] : null;
     
-    // EAN BEREINIGUNG: NUR LEERZEICHEN ENTFERNEN
-    $eanRaw = $_POST['ean'] ?? '';
-    $eanClean = str_replace(' ', '', (string)$eanRaw);
+    $eanClean = str_replace(' ', '', (string)($_POST['ean'] ?? ''));
     $ean = ($eanClean === '') ? null : $eanClean;
-    
     $urlInput = trim($_POST['url']);
 
     try {
         $pdo->beginTransaction();
 
         if ($id > 0) {
-            $stmt = $pdo->prepare("UPDATE spiele SET game_reihe_id=?, titel=?, game_typ_id=?, game_level_id=?, ean=? WHERE id=?");
-            $stmt->execute([$r_id, $_POST['titel'], $t_id, $l_id, $ean, $id]);
+            $stmt = $pdo->prepare("UPDATE spiele SET game_reihe_id=?, titel=?, game_typ_id=?, game_level_id=?, ean=?, parent_id=? WHERE id=?");
+            $stmt->execute([$r_id, $_POST['titel'], $t_id, $l_id, $ean, $p_id, $id]);
             $spiel_id = $id;
         } else {
-            $stmt = $pdo->prepare("INSERT INTO spiele (game_reihe_id, titel, game_typ_id, game_level_id, ean) VALUES (?,?,?,?,?)");
-            $stmt->execute([$r_id, $_POST['titel'], $t_id, $l_id, $ean]);
+            $stmt = $pdo->prepare("INSERT INTO spiele (game_reihe_id, titel, game_typ_id, game_level_id, ean, parent_id) VALUES (?,?,?,?,?,?)");
+            $stmt->execute([$r_id, $_POST['titel'], $t_id, $l_id, $ean, $p_id]);
             $spiel_id = $pdo->lastInsertId();
         }
 
-        // BILD-DOWNLOAD LOGIK (Nur bei externen URLs)
         if (!empty($urlInput) && strpos($urlInput, 'http') === 0) {
             $ext = pathinfo(parse_url($urlInput, PHP_URL_PATH), PATHINFO_EXTENSION) ?: 'jpg';
-            // Dateiname basiert auf bereinigter EAN (oder ID)
             $fileName = (!empty($eanClean) ? $eanClean : "game_" . $spiel_id) . "." . $ext;
-            $destPath = IMG_PATH . $fileName;
-
-            $imgData = @file_get_contents($urlInput);
-            if ($imgData && file_put_contents($destPath, $imgData)) {
-                $pdo->prepare("UPDATE spiele SET bild_url=? WHERE id=?")->execute([$fileName, $spiel_id]);
+            if ($imgData = @file_get_contents($urlInput)) {
+                if (file_put_contents(IMG_PATH . $fileName, $imgData)) {
+                    $pdo->prepare("UPDATE spiele SET bild_url=? WHERE id=?")->execute([$fileName, $spiel_id]);
+                }
             }
         } elseif (!empty($urlInput)) {
-            // Falls bereits ein Dateiname oder lokaler Pfad übergeben wurde
             $pdo->prepare("UPDATE spiele SET bild_url=? WHERE id=?")->execute([$urlInput, $spiel_id]);
         }
 
         $pdo->commit();
-        $msg = ($id > 0) ? "Spiel aktualisiert!" : "Neues Spiel angelegt!";
-    } catch (PDOException $e) { 
-        $pdo->rollBack();
-        $error = "Fehler: " . $e->getMessage(); 
-    }
+        $msg = "Gespeichert!";
+    } catch (Exception $e) { $pdo->rollBack(); $error = $e->getMessage(); }
 }
 
-// STAMMDATEN LOGIK (Bleibt unverändert)
+// STAMMDATEN ADD LOGIK
 if (isset($_POST['add_reihe'])) {
-    $c = $pdo->prepare("SELECT id FROM game_reihe WHERE name=?"); $c->execute([$_POST['name']]);
-    if ($c->fetch()) { $error = "Reihe existiert bereits!"; }
-    else { $pdo->prepare("INSERT INTO game_reihe (name) VALUES (?)")->execute([$_POST['name']]); $msg="Reihe hinzugefügt!"; }
+    $pdo->prepare("INSERT INTO game_reihe (name) VALUES (?)")->execute([$_POST['name']]);
+    $msg="Reihe hinzugefügt!";
 }
 if (isset($_POST['add_typ'])) {
-    $c = $pdo->prepare("SELECT id FROM game_typ WHERE game_reihe_id=? AND bezeichnung=?"); $c->execute([$_POST['r_id'], $_POST['bez']]);
-    if ($c->fetch()) { $error = "Typ existiert bereits für diese Reihe!"; }
-    else { $pdo->prepare("INSERT INTO game_typ (game_reihe_id, bezeichnung) VALUES (?,?)")->execute([$_POST['r_id'], $_POST['bez']]); $msg="Typ hinzugefügt!"; }
+    $pdo->prepare("INSERT INTO game_typ (game_reihe_id, bezeichnung) VALUES (?,?)")->execute([$_POST['r_id'], $_POST['bez']]);
+    $msg="Typ hinzugefügt!";
 }
 if (isset($_POST['add_level'])) {
-    $c = $pdo->prepare("SELECT id FROM game_level WHERE game_reihe_id=? AND bezeichnung=?"); $c->execute([$_POST['r_id'], $_POST['bez']]);
-    if ($c->fetch()) { $error = "Level existiert bereits für diese Reihe!"; }
-    else { $pdo->prepare("INSERT INTO game_level (game_reihe_id, bezeichnung) VALUES (?,?)")->execute([$_POST['r_id'], $_POST['bez']]); $msg="Level hinzugefügt!"; }
+    $pdo->prepare("INSERT INTO game_level (game_reihe_id, bezeichnung) VALUES (?,?)")->execute([$_POST['r_id'], $_POST['bez']]);
+    $msg="Level hinzugefügt!";
 }
 if (isset($_POST['add_spieler'])) {
-    $c = $pdo->prepare("SELECT id FROM spieler WHERE name=?"); $c->execute([$_POST['name']]);
-    if ($c->fetch()) { $error = "Spieler existiert bereits!"; }
-    else { $pdo->prepare("INSERT INTO spieler (name) VALUES (?)")->execute([$_POST['name']]); $msg="Spieler hinzugefügt!"; }
+    $pdo->prepare("INSERT INTO spieler (name) VALUES (?)")->execute([$_POST['name']]);
+    $msg="Spieler hinzugefügt!";
 }
 
 // LÖSCHEN
-if (isset($_GET['del_t']) && isset($_GET['del_id'])) {
+if (isset($_GET['del_t'], $_GET['del_id'])) {
     if (in_array($_GET['del_t'], ['spiele', 'spieler', 'game_reihe', 'game_typ', 'game_level'])) {
         $pdo->prepare("DELETE FROM `".$_GET['del_t']."` WHERE id=?")->execute([(int)$_GET['del_id']]);
         header("Location: admin.php"); exit;
@@ -115,7 +101,11 @@ $reihen  = $pdo->query("SELECT * FROM game_reihe ORDER BY name")->fetchAll();
 $typen   = $pdo->query("SELECT t.*, r.name as r_name FROM game_typ t JOIN game_reihe r ON t.game_reihe_id = r.id ORDER BY r.name, t.bezeichnung")->fetchAll();
 $levels  = $pdo->query("SELECT l.*, r.name as r_name FROM game_level l JOIN game_reihe r ON l.game_reihe_id = r.id ORDER BY r.name, l.bezeichnung")->fetchAll();
 $spieler = $pdo->query("SELECT * FROM spieler ORDER BY name")->fetchAll();
-$spiele  = $pdo->query("SELECT s.*, r.name as r_name FROM spiele s LEFT JOIN game_reihe r ON s.game_reihe_id = r.id ORDER BY s.id DESC")->fetchAll();
+$spiele  = $pdo->query("SELECT s.*, r.name as r_name, p.titel as parent_titel 
+                        FROM spiele s 
+                        LEFT JOIN game_reihe r ON s.game_reihe_id = r.id 
+                        LEFT JOIN spiele p ON s.parent_id = p.id
+                        ORDER BY s.id DESC")->fetchAll();
 ?>
 
 <!DOCTYPE html>
@@ -127,71 +117,85 @@ $spiele  = $pdo->query("SELECT s.*, r.name as r_name FROM spiele s LEFT JOIN gam
         :root { --accent: #e67e22; --bg: #f4f7f6; --card: #fff; --text: #333; --border: #ddd; }
         body { font-family: 'Segoe UI', sans-serif; background: var(--bg); color: var(--text); margin: 0; padding: 20px; }
         .header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
-        .nav-tabs { display: flex; gap: 10px; margin-bottom: 20px; border-bottom: 2px solid var(--border); }
-        .t-btn { padding: 12px 20px; border: none; background: none; color: var(--text); cursor: pointer; font-weight: bold; }
-        .t-btn.active { border-bottom: 4px solid var(--accent); color: var(--accent); }
-        .tab { display: none; background: var(--card); padding: 20px; border-radius: 12px; border: 1px solid var(--border); }
+        
+        .nav-tabs { display: flex; gap: 5px; margin-bottom: 20px; border-bottom: 2px solid var(--border); }
+        .t-btn { padding: 12px 20px; border: none; background: none; color: var(--text); cursor: pointer; font-weight: bold; border-radius: 8px 8px 0 0; }
+        .t-btn:hover { background: #eee; }
+        .t-btn.active { background: var(--card); border: 1px solid var(--border); border-bottom: 3px solid var(--accent); color: var(--accent); }
+        
+        .tab { display: none; background: var(--card); padding: 20px; border-radius: 0 0 12px 12px; border: 1px solid var(--border); border-top: none; }
         .tab.active { display: block; }
-        table { width: 100%; border-collapse: collapse; font-size: 0.85em; }
-        th, td { padding: 8px; border-bottom: 1px solid var(--border); text-align: left; }
+        
+        table { width: 100%; border-collapse: collapse; font-size: 0.82em; }
+        th, td { padding: 10px; border-bottom: 1px solid var(--border); text-align: left; }
         input, select { padding: 6px; border: 1px solid var(--border); border-radius: 4px; background: var(--card); color: var(--text); width: 100%; box-sizing: border-box; }
-        .btn { padding: 6px 10px; border: none; border-radius: 4px; cursor: pointer; color: white; font-weight: bold; }
+        
+        .btn { padding: 6px 10px; border: none; border-radius: 4px; cursor: pointer; color: white; font-weight: bold; text-decoration: none; display: inline-block; }
         .btn-s { background: #2980b9; } .btn-d { background: #c0392b; } .btn-a { background: #27ae60; }
-        .img-preview { width: 45px; height: 45px; object-fit: cover; border-radius: 4px; }
+        .img-preview { width: 40px; height: 40px; object-fit: cover; border-radius: 4px; border: 1px solid #eee; }
+        .alert { padding: 10px; border-radius: 8px; margin-bottom: 20px; text-align: center; background: #d4edda; color: #155724; border: 1px solid #c3e6cb; }
         .scroll-area { max-height: 350px; overflow-y: auto; border: 1px solid var(--border); border-radius: 6px; padding: 5px; margin-top: 10px; }
         .badge { background: #eee; padding: 2px 5px; border-radius: 4px; font-size: 0.75em; color: #666; }
-        .alert { padding: 15px; border-radius: 8px; margin-bottom: 20px; text-align: center; background: #d4edda; color: #155724; }
-        .alert.error { background: #f8d7da; color: #721c24; }
     </style>
 </head>
 <body>
 
 <div class="header">
     <h1>🛠 Admin Panel</h1>
-    <div><a href="index.php" class="btn btn-s">Katalog</a> <a href="?logout=1" class="btn btn-d">Logout</a></div>
+    <div><a href="index.php" class="btn btn-s">Zum Katalog</a> <a href="?logout=1" class="btn btn-d">Logout</a></div>
 </div>
 
 <?php if($msg): ?><div class="alert"><?=$msg?></div><?php endif; ?>
-<?php if($error): ?><div class="alert error"><?=$error?></div><?php endif; ?>
+<?php if($error): ?><div class="alert error" style="background:#f8d7da; color:#721c24;"><?=$error?></div><?php endif; ?>
 
 <div class="nav-tabs">
-    <button class="t-btn active" onclick="openTab(event, 't-spiele')">🎮 Spiele</button>
+    <button class="t-btn active" onclick="openTab(event, 't-spiele')">🎮 Spiele & Abenteuer</button>
     <button class="t-btn" onclick="openTab(event, 't-spieler')">👥 Spieler</button>
     <button class="t-btn" onclick="openTab(event, 't-config')">⚙️ Stammdaten</button>
 </div>
 
 <div id="t-spiele" class="tab active">
-    <form method="POST" style="display:grid; grid-template-columns: 1fr 1.5fr 1fr 1fr 1fr 1.5fr auto; gap:5px; margin-bottom:20px; background:#f9f9f9; padding:10px; border-radius:8px; border:1px solid #eee;">
-        <select name="game_reihe_id" id="r_new" onchange="filter('new')" required><option value="">Reihe...</option><?php foreach($reihen as $r): ?><option value="<?=$r['id']?>"><?=$r['name']?></option><?php endforeach; ?></select>
-        <input type="text" name="titel" placeholder="Titel" required>
+    <form method="POST" style="display:grid; grid-template-columns: 1fr 1.5fr 1fr 1fr 1fr 1fr auto; gap:8px; margin-bottom:20px; background:#f9f9f9; padding:15px; border-radius:8px; border:1px solid #eee;">
+        <select name="game_reihe_id" id="r_new" onchange="filter('new')" required>
+            <option value="">Reihe wählen...</option>
+            <?php foreach($reihen as $r): ?><option value="<?=$r['id']?>"><?=$r['name']?></option><?php endforeach; ?>
+        </select>
+        <input type="text" name="titel" placeholder="Titel des Abenteuers" required>
+        <select name="parent_id">
+            <option value="0">Hauptbox (optional)...</option>
+            <?php foreach($spiele as $ps): if(!$ps['parent_id']): ?><option value="<?=$ps['id']?>"><?=$ps['titel']?></option><?php endif; endforeach; ?>
+        </select>
         <select name="game_typ_id" id="t_new"><option value="0" data-p="0">Typ...</option><?php foreach($typen as $t): ?><option data-p="<?=$t['game_reihe_id']?>" value="<?=$t['id']?>"><?=$t['bezeichnung']?></option><?php endforeach; ?></select>
         <select name="game_level_id" id="l_new"><option value="0" data-p="0">Level...</option><?php foreach($levels as $l): ?><option data-p="<?=$l['game_reihe_id']?>" value="<?=$l['id']?>"><?=$l['bezeichnung']?></option><?php endforeach; ?></select>
-        <input type="text" name="ean" placeholder="EAN">
         <input type="text" name="url" placeholder="Bild-URL">
-        <button type="submit" name="save_game" class="btn btn-a">Neu</button>
+        <button type="submit" name="save_game" class="btn btn-a">Hinzufügen</button>
     </form>
 
     <table>
-        <thead><tr><th>Bild</th><th>Reihe</th><th>Titel</th><th>Typ / Level</th><th>EAN</th><th>Bild / Link</th><th>Aktion</th></tr></thead>
+        <thead><tr><th>Bild</th><th>Reihe</th><th>Titel / Parent-Box</th><th>Typ / Level</th><th>EAN / Bildpfad</th><th>Aktion</th></tr></thead>
         <?php foreach($spiele as $s): ?>
         <tr>
             <form method="POST">
             <input type="hidden" name="id" value="<?=$s['id']?>">
+            <td><img src="<?= (strpos($s['bild_url'], 'http') === 0) ? $s['bild_url'] : IMG_URL . $s['bild_url'] ?>" class="img-preview" onerror="this.src='https://via.placeholder.com/45';"></td>
+            <td><select name="game_reihe_id" id="r_<?=$s['id']?>" onchange="filter(<?=$s['id']?>)"><?php foreach($reihen as $r): ?><option value="<?=$r['id']?>" <?=$s['game_reihe_id']==$r['id']?'selected':''?>><?=$r['name']?></option><?php endforeach; ?></select></td>
             <td>
-                <?php 
-                    $src = (strpos($s['bild_url'], 'http') === 0) ? $s['bild_url'] : IMG_URL . $s['bild_url'];
-                ?>
-                <img src="<?=htmlspecialchars($src)?>" class="img-preview" onerror="this.src='https://via.placeholder.com/45';">
+                <input type="text" name="titel" value="<?=htmlspecialchars($s['titel'])?>" style="margin-bottom:3px; font-weight:bold;">
+                <select name="parent_id" style="font-size:0.85em; color:#e67e22;">
+                    <option value="0">- Eigenständiges Spiel -</option>
+                    <?php foreach($spiele as $ps): if($ps['id'] != $s['id']): ?>
+                        <option value="<?=$ps['id']?>" <?=$s['parent_id']==$ps['id']?'selected':''?>>📦 Teil von: <?=$ps['titel']?></option>
+                    <?php endif; endforeach; ?>
+                </select>
             </td>
-            <td><select name="game_reihe_id" id="r_<?=$s['id']?>" onchange="filter(<?=$s['id']?>)"><?php foreach($reihen as $r): ?><option value="<?=$r['id']?>" <?=$s['game_reihe_id']==$r['id']?'selected':''?>><?=$r['name']?></option><?php endforeach; ?></select></td>
-            <td><input type="text" name="titel" value="<?=htmlspecialchars($s['titel'])?>"></td>
             <td>
                 <select name="game_typ_id" id="t_<?=$s['id']?>" style="margin-bottom:3px;"><option value="0" data-p="0">Typ...</option><?php foreach($typen as $t): ?><option data-p="<?=$t['game_reihe_id']?>" value="<?=$t['id']?>" <?=$s['game_typ_id']==$t['id']?'selected':''?>><?=$t['bezeichnung']?></option><?php endforeach; ?></select>
                 <select name="game_level_id" id="l_<?=$s['id']?>"><option value="0" data-p="0">Lvl...</option><?php foreach($levels as $l): ?><option data-p="<?=$l['game_reihe_id']?>" value="<?=$l['id']?>" <?=$s['game_level_id']==$l['id']?'selected':''?>><?=$l['bezeichnung']?></option><?php endforeach; ?></select>
-                <?php foreach($levels as $lx) if($lx['id'] == $s['game_level_id']) echo "<div style='margin-top:3px'>".renderStars($lx['bezeichnung'])."</div>"; ?>
             </td>
-            <td><input type="text" name="ean" value="<?=htmlspecialchars($s['ean'])?>"></td>
-            <td><input type="text" name="url" value="<?=htmlspecialchars($s['bild_url'])?>"></td>
+            <td>
+                <input type="text" name="ean" value="<?=htmlspecialchars($s['ean'])?>" placeholder="EAN" style="margin-bottom:3px;">
+                <input type="text" name="url" value="<?=htmlspecialchars($s['bild_url'])?>" placeholder="Bildpfad">
+            </td>
             <td><button type="submit" name="save_game" class="btn btn-s">💾</button> <a href="?del_t=spiele&del_id=<?=$s['id']?>" class="btn btn-d" onclick="return confirm('Löschen?')">🗑</a></td>
             </form>
         </tr>
@@ -201,7 +205,10 @@ $spiele  = $pdo->query("SELECT s.*, r.name as r_name FROM spiele s LEFT JOIN gam
 
 <div id="t-spieler" class="tab">
     <h3>Spieler Profile</h3>
-    <form method="POST" style="display:flex; gap:10px; margin-bottom:20px;"><input type="text" name="name" placeholder="Name" required><button type="submit" name="add_spieler" class="btn btn-a">Anlegen</button></form>
+    <form method="POST" style="display:flex; gap:10px; margin-bottom:20px;">
+        <input type="text" name="name" placeholder="Name" required style="width:300px;">
+        <button type="submit" name="add_spieler" class="btn btn-a">Anlegen</button>
+    </form>
     <table><?php foreach($spieler as $sl): ?><tr><td><?=$sl['name']?></td><td style="text-align:right;"><a href="?del_t=spieler&del_id=<?=$sl['id']?>" class="btn btn-d">Löschen</a></td></tr><?php endforeach; ?></table>
 </div>
 
@@ -210,7 +217,7 @@ $spiele  = $pdo->query("SELECT s.*, r.name as r_name FROM spiele s LEFT JOIN gam
         <div>
             <h4>1. Reihen</h4>
             <form method="POST" style="display:flex; gap:5px;"><input type="text" name="name" placeholder="z.B. EXIT" required><button type="submit" name="add_reihe" class="btn btn-a">+</button></form>
-            <div class="scroll-area"><?php foreach($reihen as $r): ?><div style="padding:8px; border-bottom:1px solid #eee;"><span><?=$r['name']?></span> <a href="?del_t=game_reihe&del_id=<?=$r['id']?>" style="float:right; color:red;">✕</a></div><?php endforeach; ?></div>
+            <div class="scroll-area"><?php foreach($reihen as $r): ?><div style="padding:8px; border-bottom:1px solid #eee;"><span><?=$r['name']?></span> <a href="?del_t=game_reihe&del_id=<?=$r['id']?>" style="float:right; color:red; text-decoration:none;">✕</a></div><?php endforeach; ?></div>
         </div>
         <div>
             <h4>2. Typen</h4>
@@ -218,15 +225,15 @@ $spiele  = $pdo->query("SELECT s.*, r.name as r_name FROM spiele s LEFT JOIN gam
                 <select name="r_id" style="margin-bottom:5px;"><?php foreach($reihen as $r): ?><option value="<?=$r['id']?>"><?=$r['name']?></option><?php endforeach; ?></select>
                 <div style="display:flex; gap:5px;"><input type="text" name="bez" placeholder="z.B. Spiel" required><button type="submit" name="add_typ" class="btn btn-a">+</button></div>
             </form>
-            <div class="scroll-area"><?php foreach($typen as $t): ?><div style="padding:8px; border-bottom:1px solid #eee;"><span><?=$t['bezeichnung']?> <span class="badge"><?=$t['r_name']?></span></span> <a href="?del_t=game_typ&del_id=<?=$t['id']?>" style="float:right; color:red;">✕</a></div><?php endforeach; ?></div>
+            <div class="scroll-area"><?php foreach($typen as $t): ?><div style="padding:8px; border-bottom:1px solid #eee;"><span><?=$t['bezeichnung']?> <span class="badge"><?=$t['r_name']?></span></span> <a href="?del_t=game_typ&del_id=<?=$t['id']?>" style="float:right; color:red; text-decoration:none;">✕</a></div><?php endforeach; ?></div>
         </div>
         <div>
             <h4>3. Level / Sterne</h4>
             <form method="POST">
                 <select name="r_id" style="margin-bottom:5px;"><?php foreach($reihen as $r): ?><option value="<?=$r['id']?>"><?=$r['name']?></option><?php endforeach; ?></select>
-                <div style="display:flex; gap:5px;"><input type="text" name="bez" placeholder="z.B. 3 oder Profis" required><button type="submit" name="add_level" class="btn btn-a">+</button></div>
+                <div style="display:flex; gap:5px;"><input type="text" name="bez" placeholder="z.B. 3" required><button type="submit" name="add_level" class="btn btn-a">+</button></div>
             </form>
-            <div class="scroll-area"><?php foreach($levels as $l): ?><div style="padding:8px; border-bottom:1px solid #eee;"><span><?=renderStars($l['bezeichnung'])?> <span class="badge"><?=$l['r_name']?></span></span> <a href="?del_t=game_level&del_id=<?=$l['id']?>" style="float:right; color:red;">✕</a></div><?php endforeach; ?></div>
+            <div class="scroll-area"><?php foreach($levels as $l): ?><div style="padding:8px; border-bottom:1px solid #eee;"><span><?=renderStars($l['bezeichnung'])?> <span class="badge"><?=$l['r_name']?></span></span> <a href="?del_t=game_level&del_id=<?=$l['id']?>" style="float:right; color:red; text-decoration:none;">✕</a></div><?php endforeach; ?></div>
         </div>
     </div>
 </div>
@@ -238,6 +245,7 @@ function openTab(evt, name) {
     document.getElementById(name).classList.add('active');
     evt.currentTarget.classList.add('active');
 }
+
 function filter(id) {
     let r_el = document.getElementById('r_'+id); if(!r_el) return;
     let r_val = r_el.value;
@@ -250,8 +258,10 @@ function filter(id) {
         if(sel.options[sel.selectedIndex].style.display == "none") sel.value = "0";
     });
 }
+
 document.addEventListener('DOMContentLoaded', () => { 
-    filter('new'); <?php foreach($spiele as $s): ?>filter(<?=$s['id']?>);<?php endforeach; ?> 
+    filter('new'); 
+    <?php foreach($spiele as $s): ?>filter(<?=$s['id']?>);<?php endforeach; ?> 
 });
 </script>
 </body>

+ 145 - 48
besitz.php

@@ -1,33 +1,71 @@
 <?php
+require_once 'config.php';
 require_once 'db_config.php';
 
 $msg = "";
-// --- LOGIK: STATUS AKTUALISIEREN ---
+// --- LOGIK: STATUS AKTUALISIEREN (INKL. BUNDLE-LOGIK) ---
 if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['update_status'])) {
-    $stmt = $pdo->prepare("INSERT INTO besitz_status (spieler_id, spiel_id, status) 
-                           VALUES (?, ?, ?) 
-                           ON DUPLICATE KEY UPDATE status = VALUES(status)");
-    $stmt->execute([(int)$_POST['spieler_id'], (int)$_POST['spiel_id'], $_POST['status']]);
-    $msg = "Status aktualisiert!";
+    $spieler_id = (int)$_POST['spieler_id'];
+    $spiel_id = (int)$_POST['spiel_id'];
+    $status = $_POST['status'];
+
+    try {
+        $pdo->beginTransaction();
+
+        $stmt = $pdo->prepare("INSERT INTO besitz_status (spieler_id, spiel_id, status) 
+                               VALUES (?, ?, ?) 
+                               ON DUPLICATE KEY UPDATE status = VALUES(status)");
+        $stmt->execute([$spieler_id, $spiel_id, $status]);
+
+        $stmtChildren = $pdo->prepare("SELECT id FROM spiele WHERE parent_id = ?");
+        $stmtChildren->execute([$spiel_id]);
+        $children = $stmtChildren->fetchAll();
+
+        if ($children) {
+            $stmtChildStatus = $pdo->prepare("INSERT INTO besitz_status (spieler_id, spiel_id, status) 
+                                              VALUES (?, ?, ?) 
+                                              ON DUPLICATE KEY UPDATE status = VALUES(status)");
+            foreach ($children as $child) {
+                $stmtChildStatus->execute([$spieler_id, $child['id'], $status]);
+            }
+        }
+
+        $pdo->commit();
+        $msg = "Status aktualisiert!";
+    } catch (Exception $e) {
+        $pdo->rollBack();
+        $msg = "Fehler: " . $e->getMessage();
+    }
 }
 
 // --- DATEN LADEN ---
 $spieler = $pdo->query("SELECT * FROM spieler ORDER BY name ASC")->fetchAll();
 
-// Spiele laden mit korrekten Joins laut deinem Dump
 $sqlSpiele = "SELECT s.*, r.name as reihe_name, t.bezeichnung as typ_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 
               ORDER BY r.name ASC, s.titel ASC";
-$spiele = $pdo->query($sqlSpiele)->fetchAll();
+$alleSpieleRaw = $pdo->query($sqlSpiele)->fetchAll();
 
-// Mapping aus der Tabelle MIT Unterstrich
 $statusMapping = [];
 $statusData = $pdo->query("SELECT spieler_id, spiel_id, status FROM besitz_status")->fetchAll();
 foreach ($statusData as $row) {
     $statusMapping[$row['spiel_id']][$row['spieler_id']] = $row['status'];
 }
+
+// --- HIERARCHIE AUFBAUEN ---
+$spieleBaum = [];
+$childrenMap = [];
+
+foreach ($alleSpieleRaw as $s) {
+    if ($s['parent_id']) {
+        $childrenMap[$s['parent_id']][] = $s;
+    } else {
+        $reihe = $s['reihe_name'] ?: 'Sonstige';
+        $spieleBaum[$reihe][] = $s;
+    }
+}
 ?>
 <!DOCTYPE html>
 <html lang="de">
@@ -35,21 +73,55 @@ foreach ($statusData as $row) {
     <meta charset="UTF-8">
     <title>EXIT - Bestand & Besitz</title>
     <style>
-        :root { --bg: #f4f7f6; --card: #ffffff; --text: #333; --border: #ddd; --accent: #e67e22; }
-        .dark-theme { --bg: #121212; --card: #1e1e1e; --text: #e0e0e0; --border: #333; }
+        :root { 
+            --bg: #f4f7f6; 
+            --card: #ffffff; 
+            --text: #333; 
+            --border: #ddd; 
+            --accent: #e67e22; 
+            --reihe-bg: #2c3e50; /* Dunkel für starken Kontrast */
+            --child-bg: #fdf2e9; /* Deutliches Hell-Orange/Beige */
+        }
+        .dark-theme { 
+            --bg: #121212; 
+            --card: #1e1e1e; 
+            --text: #e0e0e0; 
+            --border: #333; 
+            --reihe-bg: #000000; 
+            --child-bg: #252525; /* Deutlich heller als der Standard-Hintergrund */
+        }
+        
         body { font-family: 'Segoe UI', sans-serif; background: var(--bg); color: var(--text); padding: 20px; transition: 0.3s; }
         .container { max-width: 1200px; margin: auto; }
         header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
         .btn-nav { background: var(--accent); color: white; padding: 10px 15px; border-radius: 6px; text-decoration: none; font-weight: bold; }
         
-        table { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
-        th, td { padding: 12px; border-bottom: 1px solid var(--border); text-align: left; }
-        .reihe-divider { background: rgba(230, 126, 34, 0.1); font-weight: bold; color: var(--accent); }
+        table { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; table-layout: fixed; }
+        th, td { padding: 12px; border-bottom: 1px solid var(--border); text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
+        th:first-child, td:first-child { width: 35%; white-space: normal; }
+
+        /* Kategorien-Trenner */
+        .reihe-divider { background: var(--reihe-bg); color: #fff; font-weight: bold; text-transform: uppercase; letter-spacing: 1px; font-size: 0.85em; }
+        
+        select { padding: 6px; border-radius: 4px; border: 1px solid var(--border); background: var(--card); color: var(--text); width: 100%; cursor: pointer; font-size: 0.85em; }
+        select[data-status="besitzt"] { background: #27ae60 !important; color: white !important; font-weight: bold; }
+        select[data-status="verkauft"] { background: #e67e22 !important; color: white !important; font-weight: bold; }
+        select[data-status="nicht besitzt"] { opacity: 0.6; }
+
+        /* UNTERPUNKTE */
+        .is-child { background-color: var(--child-bg) !important; }
+        .is-child td:first-child { padding-left: 45px; position: relative; }
+        .is-child td:first-child::before { 
+            content: "↳"; 
+            position: absolute; 
+            left: 20px; 
+            color: var(--accent); 
+            font-weight: 900; 
+            font-size: 1.2em;
+        }
         
-        select { padding: 6px; border-radius: 4px; border: 1px solid var(--border); background: var(--card); color: var(--text); width: 100%; }
-        select[data-status="besitzt"] { background: #27ae60 !important; color: white !important; }
-        select[data-status="verkauft"] { background: #e67e22 !important; color: white !important; }
-        select[data-status="nicht besitzt"] { opacity: 0.5; }
+        .child-label { font-size: 0.95em; font-weight: 500; }
+        small { display: block; line-height: 1.2; margin-top: 2px; }
     </style>
 </head>
 <body>
@@ -65,45 +137,70 @@ foreach ($statusData as $row) {
     <table>
         <thead>
             <tr>
-                <th>Spiel</th>
+                <th>Spiel / Abenteuer</th>
                 <?php foreach ($spieler as $s): ?><th><?= htmlspecialchars($s['name']) ?></th><?php endforeach; ?>
             </tr>
         </thead>
         <tbody>
-            <?php 
-            $currentReihe = "";
-            foreach ($spiele as $sp): 
-                if ($currentReihe !== $sp['reihe_name']): 
-                    $currentReihe = $sp['reihe_name'];
-            ?>
+            <?php foreach ($spieleBaum as $reiheName => $hauptSpiele): ?>
                 <tr>
                     <td colspan="<?= count($spieler) + 1 ?>" class="reihe-divider">
-                        <?= htmlspecialchars($currentReihe ?: 'Sonstige') ?>
+                        📁 <?= htmlspecialchars($reiheName) ?>
                     </td>
                 </tr>
-            <?php endif; ?>
-            <tr>
-                <td>
-                    <strong><?= htmlspecialchars($sp['titel']) ?></strong><br>
-                    <small style="opacity:0.6"><?= htmlspecialchars($sp['typ_name']) ?></small>
-                </td>
-                <?php foreach ($spieler as $s): 
-                    $curr = $statusMapping[$sp['id']][$s['id']] ?? 'nicht besitzt';
-                ?>
-                <td>
-                    <form method="POST">
-                        <input type="hidden" name="update_status" value="1">
-                        <input type="hidden" name="spieler_id" value="<?= $s['id'] ?>">
-                        <input type="hidden" name="spiel_id" value="<?= $sp['id'] ?>">
-                        <select name="status" onchange="this.form.submit()" data-status="<?= $curr ?>">
-                            <option value="besitzt" <?= $curr=='besitzt'?'selected':'' ?>>Besitzt</option>
-                            <option value="nicht besitzt" <?= $curr=='nicht besitzt'?'selected':'' ?>>Nicht</option>
-                            <option value="verkauft" <?= $curr=='verkauft'?'selected':'' ?>>Verkauft</option>
-                        </select>
-                    </form>
-                </td>
+                
+                <?php foreach ($hauptSpiele as $sp): ?>
+                    <tr class="is-parent">
+                        <td>
+                            <strong><?= htmlspecialchars($sp['titel']) ?></strong>
+                            <small style="opacity:0.6"><?= htmlspecialchars($sp['typ_name']) ?></small>
+                        </td>
+                        <?php foreach ($spieler as $s): 
+                            $curr = $statusMapping[$sp['id']][$s['id']] ?? 'nicht besitzt';
+                        ?>
+                        <td>
+                            <form method="POST">
+                                <input type="hidden" name="update_status" value="1">
+                                <input type="hidden" name="spieler_id" value="<?= $s['id'] ?>">
+                                <input type="hidden" name="spiel_id" value="<?= $sp['id'] ?>">
+                                <select name="status" onchange="this.form.submit()" data-status="<?= $curr ?>">
+                                    <option value="besitzt" <?= $curr=='besitzt'?'selected':'' ?>>Besitzt</option>
+                                    <option value="nicht besitzt" <?= $curr=='nicht besitzt'?'selected':'' ?>>Nicht</option>
+                                    <option value="verkauft" <?= $curr=='verkauft'?'selected':'' ?>>Verkauft</option>
+                                </select>
+                            </form>
+                        </td>
+                        <?php endforeach; ?>
+                    </tr>
+
+                    <?php if (isset($childrenMap[$sp['id']])): ?>
+                        <?php foreach ($childrenMap[$sp['id']] as $child): ?>
+                            <tr class="is-child">
+                                <td>
+                                    <span class="child-label"><?= htmlspecialchars($child['titel']) ?></span>
+                                    <small style="opacity:0.5"><?= htmlspecialchars($child['typ_name']) ?></small>
+                                </td>
+                                <?php foreach ($spieler as $s): 
+                                    $curr = $statusMapping[$child['id']][$s['id']] ?? 'nicht besitzt';
+                                ?>
+                                <td>
+                                    <form method="POST">
+                                        <input type="hidden" name="update_status" value="1">
+                                        <input type="hidden" name="spieler_id" value="<?= $s['id'] ?>">
+                                        <input type="hidden" name="spiel_id" value="<?= $child['id'] ?>">
+                                        <select name="status" onchange="this.form.submit()" data-status="<?= $curr ?>">
+                                            <option value="besitzt" <?= $curr=='besitzt'?'selected':'' ?>>Besitzt</option>
+                                            <option value="nicht besitzt" <?= $curr=='nicht besitzt'?'selected':'' ?>>Nicht</option>
+                                            <option value="verkauft" <?= $curr=='verkauft'?'selected':'' ?>>Verkauft</option>
+                                        </select>
+                                    </form>
+                                </td>
+                                <?php endforeach; ?>
+                            </tr>
+                        <?php endforeach; ?>
+                    <?php endif; ?>
+
                 <?php endforeach; ?>
-            </tr>
             <?php endforeach; ?>
         </tbody>
     </table>

+ 11 - 8
gespielte_spiele.php

@@ -1,5 +1,5 @@
 <?php
-require_once 'config.php'; // NEU: Damit IMG_URL bekannt ist
+require_once 'config.php'; 
 require_once 'db_config.php'; 
 
 // --- 1. DATEN LADEN ---
@@ -38,12 +38,16 @@ foreach ($results as $row) {
             'teams' => []
         ];
     }
-    $groupedData[$reihe][$gameId]['teams'][] = [
-        'name' => $row['team_name'],
-        'zeit' => (int)$row['zeit'],
-        'hilfe' => (int)$row['hilfe'],
-        'sterne' => (int)$row['sterne']
-    ];
+    // Verhindert doppelte Teamanzeige bei Bundle-Einträgen
+    $teamKey = $row['team_name'] . '_' . $row['zeit']; 
+    if (!isset($groupedData[$reihe][$gameId]['teams'][$teamKey])) {
+        $groupedData[$reihe][$gameId]['teams'][$teamKey] = [
+            'name' => $row['team_name'],
+            'zeit' => (int)$row['zeit'],
+            'hilfe' => (int)$row['hilfe'],
+            'sterne' => (int)$row['sterne']
+        ];
+    }
 }
 ?>
 <!DOCTYPE html>
@@ -131,7 +135,6 @@ foreach ($results as $row) {
             <?php foreach ($games as $gameId => $data): ?>
                 <div class="item">
                     <?php 
-                        // BILD URL REPARIEREN
                         $b = $data['bild_url'];
                         $imgSrc = empty($b) ? 'https://via.placeholder.com/240x140?text=EXIT' : (strpos($b, 'http') === 0 ? $b : IMG_URL . $b);
                     ?>

+ 32 - 8
index.php

@@ -1,5 +1,5 @@
 <?php
-require_once 'config.php'; // NEU: Damit IMG_URL bekannt ist
+require_once 'config.php'; 
 require_once 'db_config.php';
 
 // --- 1. DATEN LADEN (REIHEN FÜR DEN FILTER) ---
@@ -14,18 +14,43 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['add_player'])) {
     exit;
 }
 
-// --- 3. LOGIK: SCORE HINZUFÜGEN ---
+// --- 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]);
+            }
+        }
 
-    $sql = "INSERT INTO scores (spieler_id, spiel_id, zeit, hilfe, sterne) VALUES (?, ?, ?, ?, ?)";
-    $stmt = $pdo->prepare($sql);
-    $stmt->execute([$_POST['spieler_id'], $_POST['spiel_id'], $zeit, $hilfe, $sterne]);
-    header("Location: index.php?success=score");
-    exit;
+        $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) ---
@@ -138,7 +163,6 @@ function getStarRating($val) {
                     <div class="swiper-slide">
                         <div class="card">
                             <?php 
-                                // ANPASSUNG: Pfadbereinigung
                                 $b = $game['bild_url'];
                                 $imgSrc = (empty($b)) ? 'https://via.placeholder.com/300x160?text=Kein+Cover' : (strpos($b, 'http') === 0 ? $b : IMG_URL . $b);
                             ?>