besitz.php 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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. ?>
  59. <!DOCTYPE html>
  60. <html lang="de">
  61. <head>
  62. <meta charset="UTF-8">
  63. <title>EXIT - Bestand & Besitz</title>
  64. <style>
  65. :root {
  66. --bg: #f4f7f6;
  67. --card: #ffffff;
  68. --text: #333;
  69. --border: #ddd;
  70. --accent: #e67e22;
  71. --reihe-bg: #2c3e50; /* Dunkel für starken Kontrast */
  72. --child-bg: #fdf2e9; /* Deutliches Hell-Orange/Beige */
  73. }
  74. .dark-theme {
  75. --bg: #121212;
  76. --card: #1e1e1e;
  77. --text: #e0e0e0;
  78. --border: #333;
  79. --reihe-bg: #000000;
  80. --child-bg: #252525; /* Deutlich heller als der Standard-Hintergrund */
  81. }
  82. body { font-family: 'Segoe UI', sans-serif; background: var(--bg); color: var(--text); padding: 20px; transition: 0.3s; }
  83. .container { max-width: 1200px; margin: auto; }
  84. header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
  85. .btn-nav { background: var(--accent); color: white; padding: 10px 15px; border-radius: 6px; text-decoration: none; font-weight: bold; }
  86. table { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; table-layout: fixed; }
  87. th, td { padding: 12px; border-bottom: 1px solid var(--border); text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  88. th:first-child, td:first-child { width: 35%; white-space: normal; }
  89. /* Kategorien-Trenner */
  90. .reihe-divider { background: var(--reihe-bg); color: #fff; font-weight: bold; text-transform: uppercase; letter-spacing: 1px; font-size: 0.85em; }
  91. 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; }
  92. select[data-status="besitzt"] { background: #27ae60 !important; color: white !important; font-weight: bold; }
  93. select[data-status="verkauft"] { background: #e67e22 !important; color: white !important; font-weight: bold; }
  94. select[data-status="nicht besitzt"] { opacity: 0.6; }
  95. /* UNTERPUNKTE */
  96. .is-child { background-color: var(--child-bg) !important; }
  97. .is-child td:first-child { padding-left: 45px; position: relative; }
  98. .is-child td:first-child::before {
  99. content: "↳";
  100. position: absolute;
  101. left: 20px;
  102. color: var(--accent);
  103. font-weight: 900;
  104. font-size: 1.2em;
  105. }
  106. .child-label { font-size: 0.95em; font-weight: 500; }
  107. small { display: block; line-height: 1.2; margin-top: 2px; }
  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. <strong><?= htmlspecialchars($sp['titel']) ?></strong>
  137. <small style="opacity:0.6"><?= htmlspecialchars($sp['typ_name']) ?></small>
  138. </td>
  139. <?php foreach ($spieler as $s):
  140. $curr = $statusMapping[$sp['id']][$s['id']] ?? 'nicht besitzt';
  141. ?>
  142. <td>
  143. <form method="POST">
  144. <input type="hidden" name="update_status" value="1">
  145. <input type="hidden" name="spieler_id" value="<?= $s['id'] ?>">
  146. <input type="hidden" name="spiel_id" value="<?= $sp['id'] ?>">
  147. <select name="status" onchange="this.form.submit()" data-status="<?= $curr ?>">
  148. <option value="besitzt" <?= $curr=='besitzt'?'selected':'' ?>>Besitzt</option>
  149. <option value="nicht besitzt" <?= $curr=='nicht besitzt'?'selected':'' ?>>Nicht</option>
  150. <option value="verkauft" <?= $curr=='verkauft'?'selected':'' ?>>Verkauft</option>
  151. </select>
  152. </form>
  153. </td>
  154. <?php endforeach; ?>
  155. </tr>
  156. <?php if (isset($childrenMap[$sp['id']])): ?>
  157. <?php foreach ($childrenMap[$sp['id']] as $child): ?>
  158. <tr class="is-child">
  159. <td>
  160. <span class="child-label"><?= htmlspecialchars($child['titel']) ?></span>
  161. <small style="opacity:0.5"><?= htmlspecialchars($child['typ_name']) ?></small>
  162. </td>
  163. <?php foreach ($spieler as $s):
  164. $curr = $statusMapping[$child['id']][$s['id']] ?? 'nicht besitzt';
  165. ?>
  166. <td>
  167. <form method="POST">
  168. <input type="hidden" name="update_status" value="1">
  169. <input type="hidden" name="spieler_id" value="<?= $s['id'] ?>">
  170. <input type="hidden" name="spiel_id" value="<?= $child['id'] ?>">
  171. <select name="status" onchange="this.form.submit()" data-status="<?= $curr ?>">
  172. <option value="besitzt" <?= $curr=='besitzt'?'selected':'' ?>>Besitzt</option>
  173. <option value="nicht besitzt" <?= $curr=='nicht besitzt'?'selected':'' ?>>Nicht</option>
  174. <option value="verkauft" <?= $curr=='verkauft'?'selected':'' ?>>Verkauft</option>
  175. </select>
  176. </form>
  177. </td>
  178. <?php endforeach; ?>
  179. </tr>
  180. <?php endforeach; ?>
  181. <?php endif; ?>
  182. <?php endforeach; ?>
  183. <?php endforeach; ?>
  184. </tbody>
  185. </table>
  186. </div>
  187. <script>
  188. function toggleTheme() {
  189. const isDark = document.documentElement.classList.toggle('dark-theme');
  190. localStorage.setItem('theme', isDark ? 'dark' : 'light');
  191. document.getElementById('theme-icon').innerText = isDark ? '☀️' : '🌙';
  192. }
  193. if (localStorage.getItem('theme') === 'dark') {
  194. document.documentElement.classList.add('dark-theme');
  195. document.getElementById('theme-icon').innerText = '☀️';
  196. }
  197. </script>
  198. </body>
  199. </html>