besitz.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. require_once 'db_config.php';
  3. $msg = "";
  4. // Status-Update Logik
  5. if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['update_status'])) {
  6. $stmt = $pdo->prepare("INSERT INTO besitzstatus (spieler_id, spiel_id, status)
  7. VALUES (?, ?, ?)
  8. ON DUPLICATE KEY UPDATE status = VALUES(status)");
  9. $stmt->execute([(int)$_POST['spieler_id'], (int)$_POST['spiel_id'], $_POST['status']]);
  10. $msg = "Status aktualisiert!";
  11. }
  12. $spieler = $pdo->query("SELECT * FROM spieler ORDER BY name ASC")->fetchAll();
  13. $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();
  14. ?>
  15. <!DOCTYPE html>
  16. <html lang="de">
  17. <head>
  18. <meta charset="UTF-8">
  19. <title>EXIT - Bestandsverwaltung</title>
  20. <style>
  21. body { font-family: 'Segoe UI', sans-serif; background: #121212; color: #e0e0e0; padding: 20px; }
  22. .container { max-width: 1200px; margin: auto; }
  23. h1 { color: #e67e22; }
  24. .alert { background: #27ae60; color: white; padding: 10px; border-radius: 5px; margin-bottom: 20px; text-align: center; }
  25. table { width: 100%; border-collapse: collapse; background: #1e1e1e; border-radius: 8px; overflow: hidden; }
  26. th, td { padding: 12px; border-bottom: 1px solid #333; text-align: left; }
  27. th { background: #2a2a2a; color: #e67e22; text-transform: uppercase; font-size: 0.85em; }
  28. .game-info { display: flex; align-items: center; gap: 15px; }
  29. .game-info img { width: 40px; height: 40px; object-fit: cover; border-radius: 4px; border: 1px solid #444; }
  30. select { background: #2a2a2a; color: white; border: 1px solid #444; padding: 5px; border-radius: 4px; width: 100%; cursor: pointer; }
  31. select.besitzt { border-left: 4px solid #27ae60; }
  32. select.verkauft { border-left: 4px solid #f39c12; }
  33. select.nicht { border-left: 4px solid #7f8c8d; }
  34. .back-link { color: #e67e22; text-decoration: none; font-weight: bold; margin-bottom: 20px; display: inline-block; }
  35. </style>
  36. </head>
  37. <body>
  38. <div class="container">
  39. <a href="index.php" class="back-link">← Zurück zum Dashboard</a>
  40. <h1>📦 Bestandsverwaltung</h1>
  41. <?php if ($msg): ?><div class="alert" id="msg-box"><?= $msg ?></div><?php endif; ?>
  42. <table>
  43. <thead>
  44. <tr>
  45. <th>Spiel</th>
  46. <?php foreach ($spieler as $s): ?>
  47. <th><?= htmlspecialchars($s['name']) ?></th>
  48. <?php endforeach; ?>
  49. </tr>
  50. </thead>
  51. <tbody>
  52. <?php foreach ($spiele as $sp): ?>
  53. <tr>
  54. <td>
  55. <div class="game-info">
  56. <img src="<?= htmlspecialchars($sp['bild_url']) ?>">
  57. <div>
  58. <strong><?= htmlspecialchars($sp['titel']) ?></strong><br>
  59. <small style="color:#888"><?= htmlspecialchars($sp['typ_name']) ?></small>
  60. </div>
  61. </div>
  62. </td>
  63. <?php foreach ($spieler as $s):
  64. $st_stmt = $pdo->prepare("SELECT status FROM besitzstatus WHERE spieler_id = ? AND spiel_id = ?");
  65. $st_stmt->execute([$s['id'], $sp['id']]);
  66. $current = $st_stmt->fetchColumn() ?: 'nicht besitzt';
  67. $class = ($current == 'besitzt') ? 'besitzt' : (($current == 'verkauft') ? 'verkauft' : 'nicht');
  68. ?>
  69. <td>
  70. <form method="POST" style="margin:0;">
  71. <input type="hidden" name="update_status" value="1">
  72. <input type="hidden" name="spieler_id" value="<?= $s['id'] ?>">
  73. <input type="hidden" name="spiel_id" value="<?= $sp['id'] ?>">
  74. <select name="status" class="<?= $class ?>" onchange="this.form.submit()">
  75. <option value="besitzt" <?= $current == 'besitzt' ? 'selected' : '' ?>>Besitzt</option>
  76. <option value="nicht besitzt" <?= $current == 'nicht besitzt' ? 'selected' : '' ?>>Nicht</option>
  77. <option value="verkauft" <?= $current == 'verkauft' ? 'selected' : '' ?>>Verkauft</option>
  78. </select>
  79. </form>
  80. </td>
  81. <?php endforeach; ?>
  82. </tr>
  83. <?php endforeach; ?>
  84. </tbody>
  85. </table>
  86. </div>
  87. <script>
  88. setTimeout(function() {
  89. var msg = document.getElementById('msg-box');
  90. if(msg) msg.style.opacity = '0';
  91. }, 2000);
  92. </script>
  93. </body>
  94. </html>