besitz.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. require_once 'db_config.php';
  3. $msg = "";
  4. if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['update_status'])) {
  5. $stmt = $pdo->prepare("INSERT INTO besitzstatus (spieler_id, spiel_id, status) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE status = VALUES(status)");
  6. $stmt->execute([(int)$_POST['spieler_id'], (int)$_POST['spiel_id'], $_POST['status']]);
  7. $msg = "Status aktualisiert!";
  8. }
  9. $spieler = $pdo->query("SELECT * FROM spieler ORDER BY name ASC")->fetchAll();
  10. $spiele = $pdo->query("SELECT s.*, t.bezeichnung as typ_name FROM spiele s LEFT JOIN game_typen t ON s.typ_id = t.id ORDER BY s.titel ASC")->fetchAll();
  11. ?>
  12. <!DOCTYPE html>
  13. <html lang="de">
  14. <head>
  15. <meta charset="UTF-8">
  16. <title>EXIT - Bestand</title>
  17. <style>
  18. :root { --bg: #f4f7f6; --card: #ffffff; --text: #333; --border: #ddd; --accent: #e67e22; }
  19. .dark-theme { --bg: #121212; --card: #1e1e1e; --text: #e0e0e0; --border: #333; }
  20. body { font-family: 'Segoe UI', sans-serif; background: var(--bg); color: var(--text); padding: 20px; transition: 0.3s; }
  21. .container { max-width: 1200px; margin: auto; }
  22. /* DASHBOARD BUTTON DESIGN AUS ADMIN.PHP */
  23. .btn-nav {
  24. background: var(--accent);
  25. color: white;
  26. padding: 10px 15px;
  27. border-radius: 6px;
  28. text-decoration: none;
  29. font-weight: bold;
  30. display: inline-block;
  31. font-size: 0.9em;
  32. transition: 0.2s;
  33. border: none;
  34. cursor: pointer;
  35. }
  36. .btn-nav:hover { opacity: 0.8; transform: translateY(-1px); }
  37. table { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--border); }
  38. th, td { padding: 12px; border-bottom: 1px solid var(--border); text-align: left; }
  39. /* Status Einfärbung Logik */
  40. select { padding: 5px; border-radius: 4px; border: 1px solid var(--border); background: var(--card); color: var(--text); }
  41. select[data-status="besitzt"] { background: #d4edda !important; color: #155724 !important; }
  42. select[data-status="nicht besitzt"] { background: #f8d7da !important; color: #721c24 !important; }
  43. select[data-status="verkauft"] { background: #fff3e0 !important; color: #e67e22 !important; }
  44. </style>
  45. </head>
  46. <body>
  47. <div class="container">
  48. <header style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px;">
  49. <h1>📦 Bestand / Besitz</h1>
  50. <div style="display: flex; gap: 15px; align-items: center;">
  51. <button onclick="toggleTheme()" id="theme-icon" style="background:none; border:none; cursor:pointer; font-size:1.2rem;">🌙</button>
  52. <a href="index.php" class="btn-nav">Dashboard</a>
  53. </div>
  54. </header>
  55. <table>
  56. <thead>
  57. <tr>
  58. <th>Spiel</th>
  59. <?php foreach ($spieler as $s): ?><th><?= htmlspecialchars($s['name']) ?></th><?php endforeach; ?>
  60. </tr>
  61. </thead>
  62. <tbody>
  63. <?php foreach ($spiele as $sp): ?>
  64. <tr>
  65. <td><strong><?= htmlspecialchars($sp['titel']) ?></strong></td>
  66. <?php foreach ($spieler as $s):
  67. $st_stmt = $pdo->prepare("SELECT status FROM besitzstatus WHERE spieler_id = ? AND spiel_id = ?");
  68. $st_stmt->execute([$s['id'], $sp['id']]);
  69. $curr = $st_stmt->fetchColumn() ?: 'nicht besitzt';
  70. ?>
  71. <td>
  72. <form method="POST">
  73. <input type="hidden" name="update_status" value="1">
  74. <input type="hidden" name="spieler_id" value="<?= $s['id'] ?>">
  75. <input type="hidden" name="spiel_id" value="<?= $sp['id'] ?>">
  76. <select name="status" onchange="this.form.submit()" data-status="<?= $curr ?>">
  77. <option value="besitzt" <?= $curr=='besitzt'?'selected':'' ?>>Besitzt</option>
  78. <option value="nicht besitzt" <?= $curr=='nicht besitzt'?'selected':'' ?>>Nicht</option>
  79. <option value="verkauft" <?= $curr=='verkauft'?'selected':'' ?>>Verkauft</option>
  80. </select>
  81. </form>
  82. </td>
  83. <?php endforeach; ?>
  84. </tr>
  85. <?php endforeach; ?>
  86. </tbody>
  87. </table>
  88. </div>
  89. <script>
  90. function toggleTheme() {
  91. const isDark = document.documentElement.classList.toggle('dark-theme');
  92. localStorage.setItem('theme', isDark ? 'dark' : 'light');
  93. document.getElementById('theme-icon').innerText = isDark ? '☀️' : '🌙';
  94. }
  95. if (localStorage.getItem('theme') === 'dark') {
  96. document.documentElement.classList.add('dark-theme');
  97. document.getElementById('theme-icon').innerText = '☀️';
  98. }
  99. </script>
  100. </body>
  101. </html>