| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285 |
- <?php
- session_start();
- require_once 'config.php'; // Enthält ADMIN_PASSWORD und DB-Konstanten
- // --- 1. LOGOUT LOGIK ---
- if (isset($_GET['logout'])) {
- session_destroy();
- header("Location: admin.php");
- exit;
- }
- // --- 2. LOGIN SCHUTZ ---
- $show_login = true;
- if (isset($_SESSION['admin_auth']) && $_SESSION['admin_auth'] === true) {
- $show_login = false;
- }
- if (isset($_POST['login_auth'])) {
- if ($_POST['pw'] === ADMIN_PASSWORD) {
- $_SESSION['admin_auth'] = true;
- $show_login = false;
- } else {
- $login_error = "Falsches Passwort!";
- }
- }
- if ($show_login):
- ?>
- <!DOCTYPE html>
- <html lang="de">
- <head>
- <meta charset="UTF-8">
- <title>Admin Login</title>
- <style>
- body { font-family: 'Segoe UI', sans-serif; background: #121212; color: white; display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0; }
- .login-box { background: #1e1e1e; padding: 40px; border-radius: 12px; border: 1px solid #e67e22; text-align: center; box-shadow: 0 10px 30px rgba(0,0,0,0.5); width: 300px; }
- input { width: 100%; padding: 12px; margin: 15px 0; border-radius: 5px; border: 1px solid #444; background: #2a2a2a; color: white; box-sizing: border-box; }
- button { background: #e67e22; color: white; border: none; padding: 12px; border-radius: 5px; cursor: pointer; width: 100%; font-weight: bold; }
- .error { color: #e74c3c; margin-bottom: 10px; font-size: 0.9em; }
- a { color: #888; text-decoration: none; font-size: 0.8em; margin-top: 15px; display: inline-block; }
- </style>
- </head>
- <body>
- <div class="login-box">
- <h2>🔐 Admin Login</h2>
- <?php if(isset($login_error)) echo "<div class='error'>$login_error</div>"; ?>
- <form method="POST">
- <input type="password" name="pw" placeholder="Passwort" autofocus required>
- <button type="submit" name="login_auth">Einloggen</button>
- </form>
- <a href="index.php"> Zurück zum Dashboard</a>
- </div>
- </body>
- </html>
- <?php
- exit;
- endif;
- // --- 3. HAUPT-LOGIK (NUR ERREICHBAR WENN EINGELOGGT) ---
- require_once 'db_config.php';
- $msg = "";
- // Bild-Download Hilfsfunktion
- function downloadGameImage($ean, $url) {
- if (!empty($ean) && filter_var($url, FILTER_VALIDATE_URL)) {
- $content = @file_get_contents($url);
- if ($content) {
- if (!is_dir('img')) mkdir('img', 0777, true);
- $path = "img/" . $ean . ".jpg";
- file_put_contents($path, $content);
- return $path;
- }
- }
- return null;
- }
- // SPIEL HINZUFÜGEN
- if (isset($_POST['add_new_game'])) {
- $ean = $_POST['new_ean'];
- $bild_url = "https://via.placeholder.com/60";
- if (!empty($_POST['new_bild_quelle'])) {
- $downloaded = downloadGameImage($ean, $_POST['new_bild_quelle']);
- if ($downloaded) $bild_url = $downloaded;
- }
- $stmt = $pdo->prepare("INSERT INTO spiele (titel, typ_id, ean, level, bild_url) VALUES (?, ?, ?, ?, ?)");
- $stmt->execute([$_POST['new_titel'], (int)$_POST['new_typ_id'], $ean, $_POST['new_level'], $bild_url]);
- $msg = "Spiel erfolgreich angelegt!";
- }
- // SPIEL AKTUALISIEREN
- if (isset($_POST['update_game'])) {
- $spiel_id = (int)$_POST['spiel_id'];
- $ean = $_POST['ean'];
- if (!empty($_POST['update_bild_quelle'])) {
- $new_path = downloadGameImage($ean, $_POST['update_bild_quelle']);
- if ($new_path) $pdo->prepare("UPDATE spiele SET bild_url = ? WHERE id = ?")->execute([$new_path, $spiel_id]);
- }
- $stmt = $pdo->prepare("UPDATE spiele SET titel = ?, typ_id = ?, ean = ?, level = ? WHERE id = ?");
- $stmt->execute([$_POST['titel'], (int)$_POST['typ_id'], $ean, $_POST['level'], $spiel_id]);
- $msg = "Änderungen gespeichert!";
- }
- // SPIEL LÖSCHEN
- if (isset($_POST['delete_game'])) {
- $pdo->prepare("DELETE FROM spiele WHERE id = ?")->execute([(int)$_POST['spiel_id']]);
- $msg = "Spiel wurde gelöscht!";
- }
- // GRUPPEN & TYPEN LOGIK
- if (isset($_POST['add_player'])) { $pdo->prepare("INSERT INTO spieler (name) VALUES (?)")->execute([$_POST['player_name']]); }
- if (isset($_POST['delete_player'])) { $pdo->prepare("DELETE FROM spieler WHERE id = ?")->execute([(int)$_POST['player_id']]); }
- if (isset($_POST['add_type'])) { $pdo->prepare("INSERT INTO game_typen (bezeichnung) VALUES (?)")->execute([$_POST['type_name']]); }
- if (isset($_POST['delete_type'])) { $pdo->prepare("DELETE FROM game_typen WHERE id = ?")->execute([(int)$_POST['type_id']]); }
- // DATEN LADEN
- $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.id DESC")->fetchAll();
- $spieler = $pdo->query("SELECT * FROM spieler ORDER BY id ASC")->fetchAll();
- $typen = $pdo->query("SELECT * FROM game_typen ORDER BY bezeichnung ASC")->fetchAll();
- ?>
- <!DOCTYPE html>
- <html lang="de">
- <head>
- <meta charset="UTF-8">
- <title>EXIT Admin - Verwaltung</title>
- <style>
- body { font-family: 'Segoe UI', sans-serif; background: #f4f7f6; padding: 20px; color: #333; }
- .container { max-width: 1200px; margin: 0 auto; }
- .header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
- .alert { background: #27ae60; color: white; padding: 15px; border-radius: 8px; margin-bottom: 20px; text-align: center; font-weight: bold; }
-
- .tabs { display: flex; gap: 5px; }
- .tab-button { padding: 12px 25px; cursor: pointer; background: #ddd; border: none; border-radius: 8px 8px 0 0; font-weight: bold; transition: 0.3s; }
- .tab-button.active { background: #fff; border-top: 4px solid #e67e22; color: #e67e22; }
-
- .tab-content { background: #fff; padding: 25px; border-radius: 0 8px 8px 8px; box-shadow: 0 4px 15px rgba(0,0,0,0.05); display: none; }
- .tab-content.active { display: block; }
- table { width: 100%; border-collapse: collapse; margin-top: 15px; }
- th, td { padding: 12px; border-bottom: 1px solid #eee; text-align: left; }
- input, select { padding: 8px; border: 1px solid #ddd; border-radius: 5px; width: 100%; box-sizing: border-box; }
-
- .btn { padding: 8px 15px; border: none; border-radius: 5px; color: white; cursor: pointer; font-weight: bold; text-decoration: none; display: inline-block; }
- .btn-add { background: #27ae60; }
- .btn-save { background: #2980b9; }
- .btn-del { background: #e74c3c; }
- .logout { background: #c0392b; font-size: 0.8em; }
- </style>
- </head>
- <body>
- <div class="container">
- <div class="header">
- <h1>🛠 Stammdaten</h1>
- <div>
- <a href="index.php" class="btn btn-save">Dashboard</a>
- <a href="admin.php?logout=1" class="btn logout">Abmelden 🚪</a>
- </div>
- </div>
- <?php if ($msg): ?><div class="alert" id="msg-box"><?= $msg ?></div><?php endif; ?>
- <div class="tabs">
- <button class="tab-button active" onclick="openTab(event, 'tab-spiele')">🎮 Spiele</button>
- <button class="tab-button" onclick="openTab(event, 'tab-gruppen')">👥 Gruppen</button>
- <button class="tab-button" onclick="openTab(event, 'tab-typen')">🏷 Typen</button>
- </div>
- <div id="tab-spiele" class="tab-content active">
- <div style="background:#f9f9f9; padding:20px; border-radius:8px; border:1px solid #eee; margin-bottom:30px;">
- <h3>🆕 Neues Spiel erfassen</h3>
- <form method="POST">
- <div style="display:grid; grid-template-columns: 2fr 1fr 1fr 1fr 2fr; gap:10px;">
- <input type="text" name="new_titel" placeholder="Spieltitel" required>
- <select name="new_typ_id">
- <?php foreach($typen as $t): ?><option value="<?= $t['id'] ?>"><?= htmlspecialchars($t['bezeichnung']) ?></option><?php endforeach; ?>
- </select>
- <input type="text" name="new_ean" placeholder="EAN" required>
- <select name="new_level">
- <option value="Einsteiger">Einsteiger</option>
- <option value="Fortgeschrittene">Fortgeschrittene</option>
- <option value="Profi">Profi</option>
- </select>
- <input type="text" name="new_bild_quelle" placeholder="Bild-URL (Download)">
- </div>
- <button type="submit" name="add_new_game" class="btn btn-add" style="margin-top:15px; width:100%;">Spiel in Datenbank speichern</button>
- </form>
- </div>
- <table>
- <thead><tr><th>Bild</th><th>Titel & Typ</th><th>EAN</th><th>Level</th><th>Aktion</th></tr></thead>
- <tbody>
- <?php foreach ($spiele as $sp): ?>
- <tr>
- <form method="POST">
- <input type="hidden" name="spiel_id" value="<?= $sp['id'] ?>">
- <td width="60"><img src="<?= $sp['bild_url'] ?>" width="50" style="border-radius:4px;"></td>
- <td>
- <input type="text" name="titel" value="<?= htmlspecialchars($sp['titel']) ?>" style="margin-bottom:5px;">
- <select name="typ_id">
- <?php foreach($typen as $t): ?>
- <option value="<?= $t['id'] ?>" <?= $sp['typ_id']==$t['id']?'selected':'' ?>><?= htmlspecialchars($t['bezeichnung']) ?></option>
- <?php endforeach; ?>
- </select>
- </td>
- <td><input type="text" name="ean" value="<?= htmlspecialchars($sp['ean']) ?>"></td>
- <td>
- <select name="level">
- <option value="Einsteiger" <?= $sp['level']=='Einsteiger'?'selected':'' ?>>Einsteiger</option>
- <option value="Fortgeschrittene" <?= $sp['level']=='Fortgeschrittene'?'selected':'' ?>>Fortgeschrittene</option>
- <option value="Profi" <?= $sp['level']=='Profi'?'selected':'' ?>>Profi</option>
- </select>
- </td>
- <td style="white-space:nowrap;">
- <button type="submit" name="update_game" class="btn btn-save" title="Speichern">💾</button>
- <button type="submit" name="delete_game" class="btn btn-del" onclick="return confirm('Wirklich löschen?')" title="Löschen">🗑</button>
- </td>
- </form>
- </tr>
- <?php endforeach; ?>
- </tbody>
- </table>
- </div>
- <div id="tab-gruppen" class="tab-content">
- <h3>👥 Teams / Spieler</h3>
- <form method="POST" style="display:flex; gap:10px; margin-bottom:20px;">
- <input type="text" name="player_name" placeholder="Name der Gruppe" required>
- <button type="submit" name="add_player" class="btn btn-add">Anlegen</button>
- </form>
- <table>
- <?php foreach ($spieler as $s): ?>
- <tr>
- <td><?= htmlspecialchars($s['name']) ?></td>
- <td width="50">
- <form method="POST">
- <input type="hidden" name="player_id" value="<?= $s['id'] ?>">
- <button type="submit" name="delete_player" class="btn btn-del">🗑</button>
- </form>
- </td>
- </tr>
- <?php endforeach; ?>
- </table>
- </div>
- <div id="tab-typen" class="tab-content">
- <h3>🏷 Spiel-Typen (z.B. EXIT, Adventure Games)</h3>
- <form method="POST" style="display:flex; gap:10px; margin-bottom:20px;">
- <input type="text" name="type_name" placeholder="Typ-Bezeichnung" required>
- <button type="submit" name="add_type" class="btn btn-add">Anlegen</button>
- </form>
- <table>
- <?php foreach ($typen as $t): ?>
- <tr>
- <td><?= htmlspecialchars($t['bezeichnung']) ?></td>
- <td width="50">
- <form method="POST">
- <input type="hidden" name="type_id" value="<?= $t['id'] ?>">
- <button type="submit" name="delete_type" class="btn btn-del">🗑</button>
- </form>
- </td>
- </tr>
- <?php endforeach; ?>
- </table>
- </div>
- </div>
- <script>
- function openTab(evt, tabName) {
- var i, tabcontent, tablinks;
- tabcontent = document.getElementsByClassName("tab-content");
- for (i = 0; i < tabcontent.length; i++) { tabcontent[i].style.display = "none"; }
- tablinks = document.getElementsByClassName("tab-button");
- for (i = 0; i < tablinks.length; i++) { tablinks[i].className = tablinks[i].className.replace(" active", ""); }
- document.getElementById(tabName).style.display = "block";
- evt.currentTarget.className += " active";
- }
- setTimeout(function() {
- var msg = document.getElementById('msg-box');
- if(msg) msg.style.display = 'none';
- }, 3000);
- </script>
- </body>
- </html>
|