besitz.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. <?php
  2. require_once 'config.php';
  3. require_once 'db_config.php';
  4. $msg = "";
  5. // --- LOGIK: STATUS AKTUALISIEREN (INKL. BUNDLE-LOGIK) ---
  6. if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['update_status'])) {
  7. $spieler_id = (int)$_POST['spieler_id'];
  8. $spiel_id = (int)$_POST['spiel_id'];
  9. $status = $_POST['status'];
  10. try {
  11. $pdo->beginTransaction();
  12. $stmt = $pdo->prepare("INSERT INTO besitz_status (spieler_id, spiel_id, status)
  13. VALUES (?, ?, ?)
  14. ON DUPLICATE KEY UPDATE status = VALUES(status)");
  15. $stmt->execute([$spieler_id, $spiel_id, $status]);
  16. $stmtChildren = $pdo->prepare("SELECT id FROM spiele WHERE parent_id = ?");
  17. $stmtChildren->execute([$spiel_id]);
  18. $children = $stmtChildren->fetchAll();
  19. if ($children) {
  20. $stmtChildStatus = $pdo->prepare("INSERT INTO besitz_status (spieler_id, spiel_id, status)
  21. VALUES (?, ?, ?)
  22. ON DUPLICATE KEY UPDATE status = VALUES(status)");
  23. foreach ($children as $child) {
  24. $stmtChildStatus->execute([$spieler_id, $child['id'], $status]);
  25. }
  26. }
  27. $pdo->commit();
  28. $msg = "Status aktualisiert!";
  29. } catch (Exception $e) {
  30. $pdo->rollBack();
  31. $msg = "Fehler: " . $e->getMessage();
  32. }
  33. }
  34. // --- DATEN LADEN ---
  35. $spieler = $pdo->query("SELECT * FROM spieler ORDER BY name ASC")->fetchAll();
  36. $sqlSpiele = "SELECT s.*, r.name as reihe_name, t.bezeichnung as typ_name
  37. FROM spiele s
  38. LEFT JOIN game_reihe r ON s.game_reihe_id = r.id
  39. LEFT JOIN game_typ t ON s.game_typ_id = t.id
  40. ORDER BY r.name ASC, s.titel ASC";
  41. $alleSpieleRaw = $pdo->query($sqlSpiele)->fetchAll();
  42. $statusMapping = [];
  43. $statusData = $pdo->query("SELECT spieler_id, spiel_id, status FROM besitz_status")->fetchAll();
  44. foreach ($statusData as $row) {
  45. $statusMapping[$row['spiel_id']][$row['spieler_id']] = $row['status'];
  46. }
  47. // --- HIERARCHIE AUFBAUEN ---
  48. $spieleBaum = [];
  49. $childrenMap = [];
  50. foreach ($alleSpieleRaw as $s) {
  51. if ($s['parent_id']) {
  52. $childrenMap[$s['parent_id']][] = $s;
  53. } else {
  54. $reihe = $s['reihe_name'] ?: 'Sonstige';
  55. $spieleBaum[$reihe][] = $s;
  56. }
  57. }
  58. // Hilfsfunktion für Bild-URL
  59. function getImgPath($url) {
  60. if (empty($url)) return 'https://via.placeholder.com/150x150?text=Kein+Bild';
  61. return (strpos($url, 'http') === 0) ? $url : IMG_URL . $url;
  62. }
  63. ?>
  64. <!DOCTYPE html>
  65. <html lang="de">
  66. <head>
  67. <meta charset="UTF-8">
  68. <title>EXIT - Bestand & Besitz</title>
  69. <style>
  70. :root {
  71. --bg: #f4f7f6; --card: #ffffff; --text: #333; --border: #ddd; --accent: #e67e22;
  72. --reihe-bg: #2c3e50; --child-bg: #fdf2e9;
  73. }
  74. .dark-theme {
  75. --bg: #121212; --card: #1e1e1e; --text: #e0e0e0; --border: #333;
  76. --reihe-bg: #000000; --child-bg: #252525;
  77. }
  78. body { font-family: 'Segoe UI', sans-serif; background: var(--bg); color: var(--text); padding: 20px; transition: 0.3s; }
  79. .container { max-width: 1200px; margin: auto; }
  80. header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
  81. .btn-nav { background: var(--accent); color: white; padding: 10px 15px; border-radius: 6px; text-decoration: none; font-weight: bold; }
  82. table { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--border); border-radius: 8px; overflow: visible; table-layout: fixed; }
  83. th, td { padding: 12px; border-bottom: 1px solid var(--border); text-align: left; }
  84. th:first-child, td:first-child { width: 35%; position: relative; }
  85. .reihe-divider { background: var(--reihe-bg); color: #fff; font-weight: bold; text-transform: uppercase; letter-spacing: 1px; font-size: 0.85em; }
  86. 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; }
  87. select[data-status="besitzt"] { background: #27ae60 !important; color: white !important; font-weight: bold; }
  88. select[data-status="verkauft"] { background: #e67e22 !important; color: white !important; font-weight: bold; }
  89. select[data-status="nicht besitzt"] { opacity: 0.6; }
  90. /* UNTERPUNKTE */
  91. .is-child { background-color: var(--child-bg) !important; }
  92. .is-child td:first-child { padding-left: 45px; }
  93. .is-child td:first-child::before {
  94. content: "↳"; position: absolute; left: 20px; color: var(--accent); font-weight: 900; font-size: 1.2em;
  95. }
  96. /* HOVER PREVIEW LOGIK */
  97. .preview-trigger { cursor: help; border-bottom: 1px dotted var(--accent); position: relative; display: inline-block; }
  98. .preview-box {
  99. display: none; position: absolute; left: 100%; top: 0; z-index: 1000;
  100. width: 150px; height: 150px; background: #000; border: 2px solid var(--accent);
  101. border-radius: 8px; box-shadow: 0 10px 25px rgba(0,0,0,0.3); overflow: hidden;
  102. margin-left: 15px; pointer-events: none;
  103. }
  104. .preview-box img { width: 100%; height: 100%; object-fit: cover; }
  105. .preview-trigger:hover .preview-box { display: block; }
  106. .child-label { font-size: 0.95em; font-weight: 500; }
  107. small { display: block; line-height: 1.2; margin-top: 2px; opacity: 0.6; }
  108. </style>
  109. </head>
  110. <body>
  111. <div class="container">
  112. <header>
  113. <h1>📦 Bestand & Besitz</h1>
  114. <div style="display: flex; gap: 15px;">
  115. <button onclick="toggleTheme()" id="theme-icon" style="background:none; border:none; cursor:pointer; font-size:1.2rem;">🌙</button>
  116. <a href="index.php" class="btn-nav">Dashboard</a>
  117. </div>
  118. </header>
  119. <table>
  120. <thead>
  121. <tr>
  122. <th>Spiel / Abenteuer</th>
  123. <?php foreach ($spieler as $s): ?><th><?= htmlspecialchars($s['name']) ?></th><?php endforeach; ?>
  124. </tr>
  125. </thead>
  126. <tbody>
  127. <?php foreach ($spieleBaum as $reiheName => $hauptSpiele): ?>
  128. <tr>
  129. <td colspan="<?= count($spieler) + 1 ?>" class="reihe-divider">
  130. 📁 <?= htmlspecialchars($reiheName) ?>
  131. </td>
  132. </tr>
  133. <?php foreach ($hauptSpiele as $sp): ?>
  134. <tr class="is-parent">
  135. <td>
  136. <div class="preview-trigger">
  137. <strong><?= htmlspecialchars($sp['titel']) ?></strong>
  138. <div class="preview-box">
  139. <img src="<?= getImgPath($sp['bild_url']) ?>" alt="Cover">
  140. </div>
  141. </div>
  142. <small><?= htmlspecialchars($sp['typ_name']) ?></small>
  143. </td>
  144. <?php foreach ($spieler as $s):
  145. $curr = $statusMapping[$sp['id']][$s['id']] ?? 'nicht besitzt';
  146. ?>
  147. <td>
  148. <form method="POST">
  149. <input type="hidden" name="update_status" value="1">
  150. <input type="hidden" name="spieler_id" value="<?= $s['id'] ?>">
  151. <input type="hidden" name="spiel_id" value="<?= $sp['id'] ?>">
  152. <select name="status" onchange="this.form.submit()" data-status="<?= $curr ?>">
  153. <option value="besitzt" <?= $curr=='besitzt'?'selected':'' ?>>Besitzt</option>
  154. <option value="nicht besitzt" <?= $curr=='nicht besitzt'?'selected':'' ?>>Nicht</option>
  155. <option value="verkauft" <?= $curr=='verkauft'?'selected':'' ?>>Verkauft</option>
  156. </select>
  157. </form>
  158. </td>
  159. <?php endforeach; ?>
  160. </tr>
  161. <?php if (isset($childrenMap[$sp['id']])): ?>
  162. <?php foreach ($childrenMap[$sp['id']] as $child): ?>
  163. <tr class="is-child">
  164. <td>
  165. <div class="preview-trigger">
  166. <span class="child-label"><?= htmlspecialchars($child['titel']) ?></span>
  167. <div class="preview-box">
  168. <img src="<?= getImgPath($child['bild_url']) ?>" alt="Cover">
  169. </div>
  170. </div>
  171. <small><?= htmlspecialchars($child['typ_name']) ?></small>
  172. </td>
  173. <?php foreach ($spieler as $s):
  174. $curr = $statusMapping[$child['id']][$s['id']] ?? 'nicht besitzt';
  175. ?>
  176. <td>
  177. <form method="POST">
  178. <input type="hidden" name="update_status" value="1">
  179. <input type="hidden" name="spieler_id" value="<?= $s['id'] ?>">
  180. <input type="hidden" name="spiel_id" value="<?= $child['id'] ?>">
  181. <select name="status" onchange="this.form.submit()" data-status="<?= $curr ?>">
  182. <option value="besitzt" <?= $curr=='besitzt'?'selected':'' ?>>Besitzt</option>
  183. <option value="nicht besitzt" <?= $curr=='nicht besitzt'?'selected':'' ?>>Nicht</option>
  184. <option value="verkauft" <?= $curr=='verkauft'?'selected':'' ?>>Verkauft</option>
  185. </select>
  186. </form>
  187. </td>
  188. <?php endforeach; ?>
  189. </tr>
  190. <?php endforeach; ?>
  191. <?php endif; ?>
  192. <?php endforeach; ?>
  193. <?php endforeach; ?>
  194. </tbody>
  195. </table>
  196. </div>
  197. <script>
  198. function toggleTheme() {
  199. const isDark = document.documentElement.classList.toggle('dark-theme');
  200. localStorage.setItem('theme', isDark ? 'dark' : 'light');
  201. document.getElementById('theme-icon').innerText = isDark ? '☀️' : '🌙';
  202. }
  203. if (localStorage.getItem('theme') === 'dark') {
  204. document.documentElement.classList.add('dark-theme');
  205. document.getElementById('theme-icon').innerText = '☀️';
  206. }
  207. </script>
  208. </body>
  209. </html>