| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233 |
- <?php
- require_once 'config.php';
- require_once 'db_config.php';
- $msg = "";
- // --- LOGIK: STATUS AKTUALISIEREN (INKL. BUNDLE-LOGIK) ---
- if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['update_status'])) {
- $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();
- $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";
- $alleSpieleRaw = $pdo->query($sqlSpiele)->fetchAll();
- $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;
- }
- }
- // Hilfsfunktion für Bild-URL
- function getImgPath($url) {
- if (empty($url)) return 'https://via.placeholder.com/150x150?text=Kein+Bild';
- return (strpos($url, 'http') === 0) ? $url : IMG_URL . $url;
- }
- ?>
- <!DOCTYPE html>
- <html lang="de">
- <head>
- <meta charset="UTF-8">
- <title>EXIT - Bestand & Besitz</title>
- <style>
- :root {
- --bg: #f4f7f6; --card: #ffffff; --text: #333; --border: #ddd; --accent: #e67e22;
- --reihe-bg: #2c3e50; --child-bg: #fdf2e9;
- }
- .dark-theme {
- --bg: #121212; --card: #1e1e1e; --text: #e0e0e0; --border: #333;
- --reihe-bg: #000000; --child-bg: #252525;
- }
-
- 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: visible; table-layout: fixed; }
- th, td { padding: 12px; border-bottom: 1px solid var(--border); text-align: left; }
- th:first-child, td:first-child { width: 35%; position: relative; }
- .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; }
- .is-child td:first-child::before {
- content: "↳"; position: absolute; left: 20px; color: var(--accent); font-weight: 900; font-size: 1.2em;
- }
-
- /* HOVER PREVIEW LOGIK */
- .preview-trigger { cursor: help; border-bottom: 1px dotted var(--accent); position: relative; display: inline-block; }
- .preview-box {
- display: none; position: absolute; left: 100%; top: 0; z-index: 1000;
- width: 150px; height: 150px; background: #000; border: 2px solid var(--accent);
- border-radius: 8px; box-shadow: 0 10px 25px rgba(0,0,0,0.3); overflow: hidden;
- margin-left: 15px; pointer-events: none;
- }
- .preview-box img { width: 100%; height: 100%; object-fit: cover; }
- .preview-trigger:hover .preview-box { display: block; }
- .child-label { font-size: 0.95em; font-weight: 500; }
- small { display: block; line-height: 1.2; margin-top: 2px; opacity: 0.6; }
- </style>
- </head>
- <body>
- <div class="container">
- <header>
- <h1>📦 Bestand & Besitz</h1>
- <div style="display: flex; gap: 15px;">
- <button onclick="toggleTheme()" id="theme-icon" style="background:none; border:none; cursor:pointer; font-size:1.2rem;">🌙</button>
- <a href="index.php" class="btn-nav">Dashboard</a>
- </div>
- </header>
- <table>
- <thead>
- <tr>
- <th>Spiel / Abenteuer</th>
- <?php foreach ($spieler as $s): ?><th><?= htmlspecialchars($s['name']) ?></th><?php endforeach; ?>
- </tr>
- </thead>
- <tbody>
- <?php foreach ($spieleBaum as $reiheName => $hauptSpiele): ?>
- <tr>
- <td colspan="<?= count($spieler) + 1 ?>" class="reihe-divider">
- 📁 <?= htmlspecialchars($reiheName) ?>
- </td>
- </tr>
-
- <?php foreach ($hauptSpiele as $sp): ?>
- <tr class="is-parent">
- <td>
- <div class="preview-trigger">
- <strong><?= htmlspecialchars($sp['titel']) ?></strong>
- <div class="preview-box">
- <img src="<?= getImgPath($sp['bild_url']) ?>" alt="Cover">
- </div>
- </div>
- <small><?= 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>
- <div class="preview-trigger">
- <span class="child-label"><?= htmlspecialchars($child['titel']) ?></span>
- <div class="preview-box">
- <img src="<?= getImgPath($child['bild_url']) ?>" alt="Cover">
- </div>
- </div>
- <small><?= 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; ?>
- <?php endforeach; ?>
- </tbody>
- </table>
- </div>
- <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 = '☀️';
- }
- </script>
- </body>
- </html>
|