403Webshell
Server IP : 202.61.199.114  /  Your IP : 216.73.217.139
Web Server : nginx/1.22.1
System : Linux de.arni-solutions.de 6.1.0-49-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.174-1 (2026-05-26) x86_64
User : web20 ( 1018)
PHP Version : 8.4.23
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /var/www/clients/client2/arni-solutions.de/web/slots/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/clients/client2/arni-solutions.de/web/slots/admin_bets.php
<?php
/**
 * Reel Royale · Wett-Administration
 *  Turniere/Teams/Spiele/Märkte/Quoten/Ergebnisse/Abrechnung/Wetten/Protokoll.
 *  Alle POSTs CSRF-geschützt, alle Eingriffe werden protokolliert (bet_admin_log).
 */
require_once __DIR__ . '/includes/bootstrap.php';
$admin  = require_admin();
$config = app_config();
$pdo    = db();
$svc    = betting();

function flash($type, $msg) { $_SESSION['bxadm_flash'] = [$type, $msg]; }
function redirect($url) { header('Location: ' . $url); exit; }
function num($v) { return (float)str_replace(',', '.', (string)$v); }

$self = 'admin_bets.php';

// ---------------- POST-Aktionen ----------------
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    if (!csrf_verify($_POST['csrf'] ?? null)) {
        flash('err', 'Sicherheitstoken ungültig.');
        redirect($self);
    }
    $action = (string)($_POST['action'] ?? '');
    $back   = (string)($_POST['back'] ?? $self);
    $aid    = (int)$admin['id']; $aname = (string)$admin['username'];
    try {
        switch ($action) {

            case 'create_tournament':
                $slug = strtolower(preg_replace('/[^a-z0-9]+/i', '-', trim((string)$_POST['slug'])));
                $pdo->prepare('INSERT INTO bet_tournaments (name, slug, description, emblem, status, starts_at, ends_at) VALUES (?,?,?,?,?,?,?)')
                    ->execute([trim((string)$_POST['name']), $slug, trim((string)$_POST['description']), trim((string)$_POST['emblem']) ?: '🏆',
                               (string)$_POST['status'], $_POST['starts_at'] ?: null, $_POST['ends_at'] ?: null]);
                $svc->logAdmin($aid, $aname, 'create_tournament', 'tournament', (int)$pdo->lastInsertId(), ['name' => $_POST['name']]);
                flash('ok', 'Turnier angelegt.');
                break;

            case 'set_tournament_status':
                $tid = (int)$_POST['tournament_id'];
                $pdo->prepare('UPDATE bet_tournaments SET status = ? WHERE id = ?')->execute([(string)$_POST['status'], $tid]);
                $svc->logAdmin($aid, $aname, 'tournament_status', 'tournament', $tid, ['status' => $_POST['status']]);
                flash('ok', 'Turnierstatus geändert.');
                break;

            case 'add_team':
                $tid = (int)$_POST['tournament_id'];
                $pdo->prepare('INSERT INTO bet_teams (tournament_id, name, short_name, flag, group_label) VALUES (?,?,?,?,?)')
                    ->execute([$tid, trim((string)$_POST['name']), trim((string)$_POST['short_name']) ?: null,
                               trim((string)$_POST['flag']) ?: null, trim((string)$_POST['group_label']) ?: null]);
                $svc->logAdmin($aid, $aname, 'add_team', 'team', (int)$pdo->lastInsertId(), ['name' => $_POST['name']]);
                flash('ok', 'Team hinzugefügt.');
                break;

            case 'delete_team':
                $pdo->prepare('DELETE FROM bet_teams WHERE id = ?')->execute([(int)$_POST['team_id']]);
                flash('ok', 'Team gelöscht.');
                break;

            case 'create_match':
                $tid = (int)$_POST['tournament_id'];
                $pdo->prepare('INSERT INTO bet_matches (tournament_id, home_team_id, away_team_id, stage, match_group, venue, kickoff_at, status) VALUES (?,?,?,?,?,?,?,?)')
                    ->execute([$tid, (int)$_POST['home_team_id'] ?: null, (int)$_POST['away_team_id'] ?: null,
                               (string)$_POST['stage'], trim((string)$_POST['match_group']) ?: null,
                               trim((string)$_POST['venue']) ?: null, (string)$_POST['kickoff_at'], 'scheduled']);
                $svc->logAdmin($aid, $aname, 'create_match', 'match', (int)$pdo->lastInsertId(), []);
                flash('ok', 'Spiel angelegt.');
                break;

            case 'update_match':
                $mid = (int)$_POST['match_id'];
                $pdo->prepare('UPDATE bet_matches SET kickoff_at = ?, status = ?, venue = ?, match_group = ? WHERE id = ?')
                    ->execute([(string)$_POST['kickoff_at'], (string)$_POST['status'], trim((string)$_POST['venue']) ?: null,
                               trim((string)$_POST['match_group']) ?: null, $mid]);
                $svc->logAdmin($aid, $aname, 'update_match', 'match', $mid, ['status' => $_POST['status']]);
                flash('ok', 'Spiel aktualisiert.');
                break;

            case 'set_result':
                $mid = (int)$_POST['match_id'];
                $r = $svc->setMatchResult($mid, (int)$_POST['home_score'], (int)$_POST['away_score'], isset($_POST['auto']), $aid, $aname);
                flash('ok', 'Ergebnis gespeichert. Automatisch abgerechnet: ' . count($r['settled']) . ' Markt/Märkte.');
                break;

            case 'create_market':
                $tid     = (int)$_POST['tournament_id'];
                $matchId = (int)$_POST['match_id'] ?: null;
                $pdo->prepare('INSERT INTO bet_markets (tournament_id, match_id, type, title, param, status, multi_winner, close_at, sort) VALUES (?,?,?,?,?,?,?,?,?)')
                    ->execute([$tid, $matchId, (string)$_POST['type'], trim((string)$_POST['title']),
                               trim((string)$_POST['param']) ?: null, 'open', isset($_POST['multi']) ? 1 : 0,
                               $_POST['close_at'] ?: null, (int)$_POST['sort']]);
                $svc->logAdmin($aid, $aname, 'create_market', 'market', (int)$pdo->lastInsertId(), ['title' => $_POST['title']]);
                flash('ok', 'Markt angelegt. Jetzt Optionen/Quoten hinzufügen.');
                break;

            case 'add_option':
                $marketId = (int)$_POST['market_id'];
                $pdo->prepare('INSERT INTO bet_options (market_id, code, label, odds, sort) VALUES (?,?,?,?,?)')
                    ->execute([$marketId, trim((string)$_POST['code']) ?: null, trim((string)$_POST['label']),
                               max(1.0, num($_POST['odds'])), (int)$_POST['sort']]);
                flash('ok', 'Option hinzugefügt.');
                break;

            case 'update_odds':
                // Mehrere Quoten gleichzeitig aktualisieren
                foreach (($_POST['odds'] ?? []) as $oid => $val) {
                    $pdo->prepare('UPDATE bet_options SET odds = ? WHERE id = ?')->execute([max(1.0, num($val)), (int)$oid]);
                }
                foreach (($_POST['olabel'] ?? []) as $oid => $val) {
                    $pdo->prepare('UPDATE bet_options SET label = ? WHERE id = ?')->execute([trim((string)$val), (int)$oid]);
                }
                $svc->logAdmin($aid, $aname, 'update_odds', 'market', (int)$_POST['market_id'], []);
                flash('ok', 'Quoten gespeichert.');
                break;

            case 'delete_option':
                $pdo->prepare('DELETE FROM bet_options WHERE id = ?')->execute([(int)$_POST['option_id']]);
                flash('ok', 'Option gelöscht.');
                break;

            case 'market_status':
                $svc->setMarketStatus((int)$_POST['market_id'], (string)$_POST['status'], $aid, $aname);
                flash('ok', 'Marktstatus geändert.');
                break;

            case 'settle_market':
                $winners = array_map('intval', (array)($_POST['winners'] ?? []));
                $r = $svc->settleMarket((int)$_POST['market_id'], $winners, $aid, $aname);
                flash('ok', "Abgerechnet: {$r['won']} gewonnen, {$r['lost']} verloren, {$r['paid']} Coins ausgezahlt.");
                break;

            case 'cancel_market':
                $r = $svc->cancelMarket((int)$_POST['market_id'], $aid, $aname);
                flash('ok', "Markt storniert. {$r['bets']} Wetten erstattet ({$r['refunded']} Coins).");
                break;

            case 'delete_market':
                $pdo->prepare('DELETE FROM bet_markets WHERE id = ?')->execute([(int)$_POST['market_id']]);
                flash('ok', 'Markt gelöscht.');
                break;

            case 'cancel_bet':
                $r = $svc->cancelBet((int)$_POST['bet_id'], $aid, $aname);
                flash('ok', "Wette storniert, {$r['refunded']} Coins erstattet.");
                break;

            case 'seed_wm':
                require __DIR__ . '/bin/seed_wm2026.php';
                exit;
        }
    } catch (Throwable $e) {
        flash('err', 'Fehler: ' . $e->getMessage());
    }
    redirect($back);
}

// ---------------- Daten für Anzeige ----------------
$flash = $_SESSION['bxadm_flash'] ?? null;
unset($_SESSION['bxadm_flash']);
$csrf  = csrf_token();
$tab   = (string)($_GET['tab'] ?? 'overview');

$tournaments = $svc->tournaments();
$curTid = (int)($_GET['t'] ?? 0);
if (!$curTid) {
    $act = $svc->activeTournament();
    $curTid = $act ? (int)$act['id'] : ((int)($tournaments[0]['id'] ?? 0));
}
$cur     = $curTid ? $svc->tournament($curTid) : null;
$teams   = $curTid ? $svc->teams($curTid) : [];
$matches = $curTid ? $svc->matchesWithMarkets($curTid, 'all') : [];

// Markt-Management-Auswahl
$selMatch   = (int)($_GET['match'] ?? 0);
$showSpecial = isset($_GET['special']);

function opt_sel($a, $b) { return (string)$a === (string)$b ? ' selected' : ''; }
function teamLabel($t) { return trim(($t['flag'] ? $t['flag'].' ' : '') . $t['name'] . ($t['group_label'] ? ' ('.$t['group_label'].')' : '')); }
?>
<!doctype html>
<html lang="de">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
    <title>Wett-Administration · <?= e($config['app']['name']) ?></title>
    <link href="https://fonts.googleapis.com/css2?family=Cinzel:wght@600;800&family=Inter:wght@400;600;800&display=swap" rel="stylesheet">
    <link href="css/core.css" rel="stylesheet">
    <style>
      .adm{max-width:1180px;margin:0 auto;padding:18px clamp(10px,3vw,24px) 80px}
      .adm-head{display:flex;align-items:center;justify-content:space-between;gap:12px;margin-bottom:14px;flex-wrap:wrap}
      .adm-head h1{font-size:1.5rem;color:var(--rr-gold);margin:0}
      .adm-tabs{display:flex;gap:6px;flex-wrap:wrap;margin-bottom:18px}
      .adm-tabs a{padding:8px 15px;border-radius:999px;background:var(--rr-panel);border:1px solid var(--rr-line);color:var(--rr-soft);text-decoration:none;font-weight:700;font-size:.85rem}
      .adm-tabs a.on{background:linear-gradient(180deg,var(--rr-gold),var(--rr-gold-2));color:#221504;border-color:transparent}
      .adm-card{background:var(--rr-panel);border:1px solid var(--rr-line);border-radius:16px;padding:16px;margin-bottom:16px;box-shadow:var(--rr-shadow)}
      .adm-card h2{font-size:1.05rem;color:var(--rr-acc);margin:0 0 12px}
      .adm-card h3{font-size:.92rem;color:var(--rr-text);margin:14px 0 8px}
      .adm-flash{padding:11px 16px;border-radius:12px;margin-bottom:16px;font-weight:600}
      .adm-flash.ok{background:rgba(74,217,145,.14);border:1px solid rgba(74,217,145,.4);color:#bdf5d6}
      .adm-flash.err{background:rgba(255,93,108,.14);border:1px solid rgba(255,93,108,.4);color:#ffc2c8}
      .adm-table{width:100%;border-collapse:collapse;font-size:.84rem}
      .adm-table th{text-align:left;font-size:.64rem;text-transform:uppercase;letter-spacing:.07em;color:var(--rr-soft);padding:7px;border-bottom:1px solid var(--rr-line)}
      .adm-table td{padding:9px 7px;border-bottom:1px solid rgba(255,255,255,.05);vertical-align:middle}
      label{font-size:.78rem;color:var(--rr-soft);display:block;margin-bottom:3px}
      input,select,textarea{padding:8px 10px;border-radius:9px;border:1px solid var(--rr-line-2);background:rgba(0,0,0,.35);color:#fff;font-size:.85rem;font-family:inherit}
      input[type=number]{width:90px}
      .grid{display:grid;gap:10px;grid-template-columns:repeat(auto-fit,minmax(140px,1fr));align-items:end}
      button{padding:8px 13px;border-radius:9px;border:1px solid var(--rr-line-2);background:rgba(255,255,255,.07);color:#fff;font-weight:700;cursor:pointer;font-size:.8rem}
      button:hover{background:rgba(255,255,255,.16)}
      .btn-gold{background:linear-gradient(180deg,var(--rr-gold),var(--rr-gold-2));color:#221504;border:0}
      .btn-green{background:rgba(74,217,145,.18);border-color:rgba(74,217,145,.4);color:#bdf5d6}
      .btn-red{background:rgba(255,93,108,.16);border-color:rgba(255,93,108,.45);color:#ffc2c8}
      .badge{display:inline-block;padding:2px 9px;border-radius:999px;font-size:.62rem;font-weight:800;text-transform:uppercase}
      .b-open{background:rgba(86,214,255,.16);color:var(--rr-cyan)} .b-settled{background:rgba(74,217,145,.18);color:#bdf5d6}
      .b-suspended{background:rgba(255,206,83,.18);color:var(--rr-acc)} .b-closed{background:rgba(255,255,255,.12);color:var(--rr-soft)}
      .b-cancelled{background:rgba(255,93,108,.16);color:#ffc2c8}
      .mk{border:1px solid var(--rr-line);border-radius:12px;padding:12px;margin-bottom:12px;background:rgba(255,255,255,.03)}
      .mk-head{display:flex;justify-content:space-between;align-items:center;gap:8px;flex-wrap:wrap;margin-bottom:10px}
      .mk-opts{display:flex;flex-direction:column;gap:6px}
      .mk-opt{display:flex;gap:8px;align-items:center;flex-wrap:wrap}
      .mk-opt input[type=text]{flex:1;min-width:120px}
      .inline{display:inline-flex;gap:6px;align-items:center}
      .muted{color:var(--rr-soft);font-size:.78rem}
      .row-actions{display:flex;gap:6px;flex-wrap:wrap}
      a.lnk{color:var(--rr-cyan);text-decoration:none}
      @media (max-width:760px){.adm-table thead{display:none}.adm-table td{display:block;border:0;padding:3px 7px}.adm-table tr{display:block;border:1px solid var(--rr-line);border-radius:12px;padding:8px;margin-bottom:10px}}
    </style>
</head>
<body class="rr-body">
<div class="adm">
    <div class="adm-head">
        <h1>🎯 Wett-Administration</h1>
        <div class="inline">
            <?php if ($cur): ?><span class="badge b-open"><?= e($cur['name']) ?></span><?php endif; ?>
            <a class="rr-btn rr-btn-ghost" href="wetten.php">Wettbereich</a>
            <a class="rr-btn rr-btn-ghost" href="admin.php">Casino-Admin</a>
        </div>
    </div>

    <?php if ($flash): ?><div class="adm-flash <?= $flash[0] === 'ok' ? 'ok' : 'err' ?>"><?= e($flash[1]) ?></div><?php endif; ?>

    <?php
    $tabUrl = function ($t) use ($self, $curTid) { return $self . '?tab=' . $t . '&t=' . $curTid; };
    $tabs = ['overview'=>'Turniere','teams'=>'Teams','matches'=>'Spiele','market'=>'Märkte & Quoten','bets'=>'Wetten','log'=>'Protokoll'];
    ?>
    <div class="adm-tabs">
        <?php foreach ($tabs as $k => $lbl): ?>
            <a href="<?= e($tabUrl($k)) ?>" class="<?= $tab === $k ? 'on' : '' ?>"><?= e($lbl) ?></a>
        <?php endforeach; ?>
    </div>

    <?php if (!$tournaments): ?>
        <div class="adm-card">
            <h2>Noch kein Turnier</h2>
            <p class="muted">Lege ein Turnier an oder importiere die WM-2026-Beispieldaten.</p>
            <form method="post" style="margin-top:10px"><input type="hidden" name="csrf" value="<?= e($csrf) ?>">
                <input type="hidden" name="action" value="seed_wm"><button class="btn-gold">WM 2026 Beispieldaten anlegen</button></form>
        </div>
    <?php endif; ?>

    <?php if ($tab === 'overview'): ?>
    <!-- ============ TURNIERE ============ -->
    <div class="adm-card">
        <h2>Turniere</h2>
        <table class="adm-table">
            <thead><tr><th>ID</th><th>Name</th><th>Slug</th><th>Status</th><th>Zeitraum</th><th></th></tr></thead>
            <tbody>
            <?php foreach ($tournaments as $t): ?>
                <tr>
                    <td>#<?= (int)$t['id'] ?></td>
                    <td><?= e($t['emblem']) ?> <strong><?= e($t['name']) ?></strong></td>
                    <td class="muted"><?= e($t['slug']) ?></td>
                    <td>
                        <form method="post" class="inline">
                            <input type="hidden" name="csrf" value="<?= e($csrf) ?>"><input type="hidden" name="action" value="set_tournament_status">
                            <input type="hidden" name="tournament_id" value="<?= (int)$t['id'] ?>">
                            <select name="status" onchange="this.form.submit()">
                                <?php foreach (['upcoming','active','finished','archived'] as $s): ?>
                                    <option value="<?= $s ?>"<?= opt_sel($s,$t['status']) ?>><?= $s ?></option>
                                <?php endforeach; ?>
                            </select>
                        </form>
                    </td>
                    <td class="muted"><?= e($t['starts_at'] ? date('d.m.y',strtotime($t['starts_at'])) : '—') ?> – <?= e($t['ends_at'] ? date('d.m.y',strtotime($t['ends_at'])) : '—') ?></td>
                    <td><a class="lnk" href="<?= e($self.'?tab=teams&t='.$t['id']) ?>">verwalten →</a></td>
                </tr>
            <?php endforeach; ?>
            </tbody>
        </table>
    </div>
    <div class="adm-card">
        <h2>Neues Turnier</h2>
        <form method="post">
            <input type="hidden" name="csrf" value="<?= e($csrf) ?>"><input type="hidden" name="action" value="create_tournament">
            <div class="grid">
                <div><label>Name</label><input name="name" required></div>
                <div><label>Slug</label><input name="slug" placeholder="em-2028"></div>
                <div><label>Emblem</label><input name="emblem" value="🏆" style="width:70px"></div>
                <div><label>Status</label><select name="status"><option value="active">active</option><option value="upcoming">upcoming</option></select></div>
                <div><label>Start</label><input type="datetime-local" name="starts_at"></div>
                <div><label>Ende</label><input type="datetime-local" name="ends_at"></div>
                <div style="grid-column:1/-1"><label>Beschreibung</label><input name="description" style="width:100%"></div>
            </div>
            <div style="margin-top:10px"><button class="btn-gold">Turnier anlegen</button></div>
        </form>
    </div>

    <?php elseif ($tab === 'teams' && $cur): ?>
    <!-- ============ TEAMS ============ -->
    <div class="adm-card">
        <h2>Teams – <?= e($cur['name']) ?> <span class="muted">(<?= count($teams) ?>)</span></h2>
        <table class="adm-table">
            <thead><tr><th>Gr.</th><th>Flagge</th><th>Name</th><th>Kürzel</th><th></th></tr></thead>
            <tbody>
            <?php foreach ($teams as $t): ?>
                <tr>
                    <td><?= e((string)$t['group_label']) ?></td><td style="font-size:1.3rem"><?= e((string)$t['flag']) ?></td>
                    <td><strong><?= e($t['name']) ?></strong></td><td class="muted"><?= e((string)$t['short_name']) ?></td>
                    <td><form method="post" onsubmit="return confirm('Team löschen?')"><input type="hidden" name="csrf" value="<?= e($csrf) ?>">
                        <input type="hidden" name="action" value="delete_team"><input type="hidden" name="team_id" value="<?= (int)$t['id'] ?>">
                        <input type="hidden" name="back" value="<?= e($self.'?tab=teams&t='.$curTid) ?>">
                        <button class="btn-red">✕</button></form></td>
                </tr>
            <?php endforeach; ?>
            </tbody>
        </table>
    </div>
    <div class="adm-card">
        <h2>Team hinzufügen</h2>
        <form method="post">
            <input type="hidden" name="csrf" value="<?= e($csrf) ?>"><input type="hidden" name="action" value="add_team">
            <input type="hidden" name="tournament_id" value="<?= $curTid ?>"><input type="hidden" name="back" value="<?= e($self.'?tab=teams&t='.$curTid) ?>">
            <div class="grid">
                <div><label>Name</label><input name="name" required></div>
                <div><label>Kürzel</label><input name="short_name" maxlength="8" style="width:80px"></div>
                <div><label>Flagge (Emoji)</label><input name="flag" style="width:80px"></div>
                <div><label>Gruppe</label><input name="group_label" maxlength="8" style="width:70px"></div>
            </div>
            <div style="margin-top:10px"><button class="btn-gold">Hinzufügen</button></div>
        </form>
    </div>

    <?php elseif ($tab === 'matches' && $cur): ?>
    <!-- ============ SPIELE ============ -->
    <div class="adm-card">
        <h2>Spiele – <?= e($cur['name']) ?></h2>
        <table class="adm-table">
            <thead><tr><th>Anstoß</th><th>Begegnung</th><th>Gr.</th><th>Status</th><th>Ergebnis / Abrechnung</th><th>Märkte</th></tr></thead>
            <tbody>
            <?php foreach ($matches as $m): $hn = $m['home']['name'] ?? '—'; $an = $m['away']['name'] ?? '—'; ?>
                <tr>
                    <td class="muted"><?= e(date('d.m. H:i', strtotime($m['kickoff_at']))) ?></td>
                    <td><strong><?= e(($m['home']['flag']??'').' '.$hn) ?></strong> – <strong><?= e(($m['away']['flag']??'').' '.$an) ?></strong></td>
                    <td><?= e((string)$m['match_group']) ?></td>
                    <td><span class="badge b-<?= $m['status']==='finished'?'settled':($m['status']==='live'?'suspended':'open') ?>"><?= e($m['status']) ?></span></td>
                    <td>
                        <form method="post" class="inline">
                            <input type="hidden" name="csrf" value="<?= e($csrf) ?>"><input type="hidden" name="action" value="set_result">
                            <input type="hidden" name="match_id" value="<?= (int)$m['id'] ?>"><input type="hidden" name="back" value="<?= e($self.'?tab=matches&t='.$curTid) ?>">
                            <input type="number" name="home_score" min="0" max="30" value="<?= $m['home_score']!==null?(int)$m['home_score']:'' ?>" style="width:52px" placeholder="H">
                            <span>:</span>
                            <input type="number" name="away_score" min="0" max="30" value="<?= $m['away_score']!==null?(int)$m['away_score']:'' ?>" style="width:52px" placeholder="A">
                            <label class="inline" style="margin:0"><input type="checkbox" name="auto" value="1" checked style="width:auto"> auto</label>
                            <button class="btn-green">Ergebnis</button>
                        </form>
                    </td>
                    <td><a class="lnk" href="<?= e($self.'?tab=market&t='.$curTid.'&match='.$m['id']) ?>"><?= count($m['markets']) ?> →</a></td>
                </tr>
            <?php endforeach; ?>
            </tbody>
        </table>
    </div>
    <div class="adm-card">
        <h2>Neues Spiel</h2>
        <form method="post">
            <input type="hidden" name="csrf" value="<?= e($csrf) ?>"><input type="hidden" name="action" value="create_match">
            <input type="hidden" name="tournament_id" value="<?= $curTid ?>"><input type="hidden" name="back" value="<?= e($self.'?tab=matches&t='.$curTid) ?>">
            <div class="grid">
                <div><label>Heim</label><select name="home_team_id"><option value="">—</option>
                    <?php foreach ($teams as $t): ?><option value="<?= (int)$t['id'] ?>"><?= e(teamLabel($t)) ?></option><?php endforeach; ?></select></div>
                <div><label>Gast</label><select name="away_team_id"><option value="">—</option>
                    <?php foreach ($teams as $t): ?><option value="<?= (int)$t['id'] ?>"><?= e(teamLabel($t)) ?></option><?php endforeach; ?></select></div>
                <div><label>Phase</label><select name="stage">
                    <?php foreach (['group'=>'Gruppe','round32'=>'Sechzehntel','round16'=>'Achtel','quarter'=>'Viertel','semi'=>'Halbfinale','third'=>'Spiel um Platz 3','final'=>'Finale'] as $k=>$v): ?>
                    <option value="<?= $k ?>"><?= e($v) ?></option><?php endforeach; ?></select></div>
                <div><label>Gruppe</label><input name="match_group" style="width:70px"></div>
                <div><label>Anstoß</label><input type="datetime-local" name="kickoff_at" required></div>
                <div><label>Ort</label><input name="venue"></div>
            </div>
            <div style="margin-top:10px"><button class="btn-gold">Spiel anlegen</button></div>
        </form>
    </div>

    <?php elseif ($tab === 'market' && $cur): ?>
    <!-- ============ MÄRKTE & QUOTEN ============ -->
    <?php
        // Kontext: ein Spiel ODER Spezialwetten
        if ($selMatch) {
            $ctxMatch = $svc->match($selMatch);
            $ctxMarkets = $svc->marketsForMatch($selMatch);
            $ctxTitle = $ctxMatch ? (($svc->teamMap($curTid)[(int)$ctxMatch['home_team_id']]['name'] ?? '—').' – '.($svc->teamMap($curTid)[(int)$ctxMatch['away_team_id']]['name'] ?? '—')) : 'Spiel';
            $backUrl = $self.'?tab=market&t='.$curTid.'&match='.$selMatch;
        } else {
            $ctxMatch = null;
            $ctxMarkets = $svc->specialMarkets($curTid);
            $ctxTitle = 'Spezialwetten';
            $backUrl = $self.'?tab=market&t='.$curTid.'&special=1';
        }
    ?>
    <div class="adm-card">
        <h2>Märkte: <?= e($ctxTitle) ?></h2>
        <div class="inline" style="margin-bottom:12px;flex-wrap:wrap">
            <form method="get" class="inline"><input type="hidden" name="tab" value="market"><input type="hidden" name="t" value="<?= $curTid ?>">
                <label style="margin:0">Spiel:</label>
                <select name="match" onchange="if(this.value==='special'){this.form.match.remove();var i=document.createElement('input');i.type='hidden';i.name='special';i.value='1';this.form.appendChild(i);}this.form.submit()">
                    <option value="special"<?= $showSpecial?' selected':'' ?>>★ Spezialwetten</option>
                    <?php foreach ($matches as $m): ?>
                        <option value="<?= (int)$m['id'] ?>"<?= opt_sel($m['id'],$selMatch) ?>><?= e(date('d.m. H:i',strtotime($m['kickoff_at'])).' · '.($m['home']['name']??'—').' – '.($m['away']['name']??'—')) ?></option>
                    <?php endforeach; ?>
                </select>
            </form>
        </div>

        <?php if (!$ctxMarkets): ?><p class="muted">Keine Märkte. Lege unten einen an.</p><?php endif; ?>

        <?php foreach ($ctxMarkets as $mk): $opts = $svc->options((int)$mk['id']); $locked = in_array($mk['status'],['settled','cancelled'],true); ?>
            <div class="mk">
                <div class="mk-head">
                    <div><strong><?= e($mk['title']) ?></strong> <span class="muted">· <?= e($mk['type']) ?><?= $mk['param']?' ('.e($mk['param']).')':'' ?></span>
                        <span class="badge b-<?= e($mk['status']) ?>"><?= e($mk['status']) ?></span>
                        <?php if ($mk['multi_winner']): ?><span class="muted">Mehrfachgewinn</span><?php endif; ?>
                    </div>
                    <div class="row-actions">
                        <?php if (!$locked): ?>
                            <?php foreach (['open'=>'Öffnen','suspended'=>'Aussetzen','closed'=>'Schließen'] as $s=>$lbl): if ($s!==$mk['status']): ?>
                                <form method="post"><input type="hidden" name="csrf" value="<?= e($csrf) ?>"><input type="hidden" name="action" value="market_status">
                                    <input type="hidden" name="market_id" value="<?= (int)$mk['id'] ?>"><input type="hidden" name="status" value="<?= $s ?>"><input type="hidden" name="back" value="<?= e($backUrl) ?>">
                                    <button><?= $lbl ?></button></form>
                            <?php endif; endforeach; ?>
                            <form method="post" onsubmit="return confirm('Markt stornieren? Alle offenen Einsätze werden erstattet.')"><input type="hidden" name="csrf" value="<?= e($csrf) ?>">
                                <input type="hidden" name="action" value="cancel_market"><input type="hidden" name="market_id" value="<?= (int)$mk['id'] ?>"><input type="hidden" name="back" value="<?= e($backUrl) ?>">
                                <button class="btn-red">Stornieren</button></form>
                        <?php endif; ?>
                        <form method="post" onsubmit="return confirm('Markt komplett löschen?')"><input type="hidden" name="csrf" value="<?= e($csrf) ?>">
                            <input type="hidden" name="action" value="delete_market"><input type="hidden" name="market_id" value="<?= (int)$mk['id'] ?>"><input type="hidden" name="back" value="<?= e($backUrl) ?>">
                            <button class="btn-red">🗑</button></form>
                    </div>
                </div>

                <!-- Quoten bearbeiten -->
                <form method="post">
                    <input type="hidden" name="csrf" value="<?= e($csrf) ?>"><input type="hidden" name="action" value="update_odds">
                    <input type="hidden" name="market_id" value="<?= (int)$mk['id'] ?>"><input type="hidden" name="back" value="<?= e($backUrl) ?>">
                    <div class="mk-opts">
                        <?php foreach ($opts as $o): ?>
                            <div class="mk-opt">
                                <span class="muted" style="width:70px">#<?= (int)$o['id'] ?> <?= e((string)$o['code']) ?></span>
                                <input type="text" name="olabel[<?= (int)$o['id'] ?>]" value="<?= e($o['label']) ?>"<?= $locked?' disabled':'' ?>>
                                <input type="number" step="0.01" min="1" name="odds[<?= (int)$o['id'] ?>]" value="<?= e((string)$o['odds']) ?>"<?= $locked?' disabled':'' ?>>
                                <?php if ((int)$o['is_winner']===1): ?><span class="badge b-settled">Gewinner</span><?php endif; ?>
                                <?php if (!$locked): ?>
                                <form method="post" style="display:inline" onsubmit="return confirm('Option löschen?')"><input type="hidden" name="csrf" value="<?= e($csrf) ?>">
                                    <input type="hidden" name="action" value="delete_option"><input type="hidden" name="option_id" value="<?= (int)$o['id'] ?>"><input type="hidden" name="back" value="<?= e($backUrl) ?>">
                                    <button class="btn-red" formnovalidate>✕</button></form>
                                <?php endif; ?>
                            </div>
                        <?php endforeach; ?>
                    </div>
                    <?php if (!$locked): ?><div style="margin-top:8px"><button class="btn-gold">Quoten speichern</button></div><?php endif; ?>
                </form>

                <?php if (!$locked): ?>
                <!-- Option hinzufügen -->
                <details style="margin-top:8px"><summary class="muted" style="cursor:pointer">+ Option hinzufügen</summary>
                    <form method="post" class="grid" style="margin-top:8px">
                        <input type="hidden" name="csrf" value="<?= e($csrf) ?>"><input type="hidden" name="action" value="add_option">
                        <input type="hidden" name="market_id" value="<?= (int)$mk['id'] ?>"><input type="hidden" name="back" value="<?= e($backUrl) ?>">
                        <div><label>Code</label><input name="code" placeholder="1 / yes / t_GER"></div>
                        <div><label>Label</label><input name="label" required></div>
                        <div><label>Quote</label><input type="number" step="0.01" min="1" name="odds" value="2.00"></div>
                        <div><label>Sort</label><input type="number" name="sort" value="0"></div>
                        <div><button class="btn-gold">+</button></div>
                    </form>
                </details>

                <!-- Abrechnen -->
                <details style="margin-top:8px"><summary class="muted" style="cursor:pointer">⚑ Abrechnen (Gewinner wählen)</summary>
                    <form method="post" onsubmit="return confirm('Markt jetzt abrechnen und Gewinne auszahlen?')" style="margin-top:8px">
                        <input type="hidden" name="csrf" value="<?= e($csrf) ?>"><input type="hidden" name="action" value="settle_market">
                        <input type="hidden" name="market_id" value="<?= (int)$mk['id'] ?>"><input type="hidden" name="back" value="<?= e($backUrl) ?>">
                        <?php foreach ($opts as $o): ?>
                            <label class="inline" style="margin:0 0 5px"><input type="checkbox" name="winners[]" value="<?= (int)$o['id'] ?>" style="width:auto"> <?= e($o['label']) ?> (<?= e((string)$o['odds']) ?>)</label><br>
                        <?php endforeach; ?>
                        <button class="btn-green" style="margin-top:6px">Abrechnen &amp; auszahlen</button>
                        <span class="muted">Ohne Auswahl = alle verlieren.</span>
                    </form>
                </details>
                <?php endif; ?>
            </div>
        <?php endforeach; ?>
    </div>

    <!-- Neuer Markt -->
    <div class="adm-card">
        <h2>Neuer Markt <?= $selMatch ? '(zu diesem Spiel)' : '(Spezialwette)' ?></h2>
        <form method="post">
            <input type="hidden" name="csrf" value="<?= e($csrf) ?>"><input type="hidden" name="action" value="create_market">
            <input type="hidden" name="tournament_id" value="<?= $curTid ?>"><input type="hidden" name="match_id" value="<?= $selMatch ?>"><input type="hidden" name="back" value="<?= e($backUrl) ?>">
            <div class="grid">
                <div><label>Typ</label><select name="type">
                    <?php foreach (['1x2','double_chance','over_under','btts','correct_score','outright','special'] as $ty): ?>
                        <option value="<?= $ty ?>"><?= $ty ?></option><?php endforeach; ?></select></div>
                <div style="grid-column:span 2"><label>Titel</label><input name="title" required style="width:100%"></div>
                <div><label>Param (z. B. 2.5)</label><input name="param" style="width:90px"></div>
                <div><label>Wettschluss</label><input type="datetime-local" name="close_at"></div>
                <div><label>Sort</label><input type="number" name="sort" value="0"></div>
                <div><label class="inline" style="margin:0"><input type="checkbox" name="multi" value="1" style="width:auto"> Mehrfachgewinn</label></div>
            </div>
            <div style="margin-top:10px"><button class="btn-gold">Markt anlegen</button></div>
        </form>
    </div>

    <?php elseif ($tab === 'bets' && $cur): ?>
    <!-- ============ WETTEN ============ -->
    <?php
        $allBets = $pdo->prepare('SELECT b.*, u.username, m.title AS market_title, o.label AS option_label
                                  FROM bet_user_bets b JOIN users u ON u.id=b.user_id
                                  JOIN bet_markets m ON m.id=b.market_id JOIN bet_options o ON o.id=b.option_id
                                  WHERE b.tournament_id=? ORDER BY b.id DESC LIMIT 300');
        $allBets->execute([$curTid]); $allBets = $allBets->fetchAll();
        $sum = $pdo->prepare('SELECT COUNT(*) c, COALESCE(SUM(stake),0) s, COALESCE(SUM(payout),0) p, SUM(status="open") o FROM bet_user_bets WHERE tournament_id=?');
        $sum->execute([$curTid]); $sum = $sum->fetch();
    ?>
    <div class="adm-card">
        <h2>Abgegebene Wetten</h2>
        <p class="muted">Gesamt: <?= (int)$sum['c'] ?> Wetten · offen: <?= (int)$sum['o'] ?> · Einsätze: <?= money_fmt((float)$sum['s']) ?> · ausgezahlt: <?= money_fmt((float)$sum['p']) ?></p>
        <table class="adm-table">
            <thead><tr><th>ID</th><th>Spieler</th><th>Markt / Auswahl</th><th>Einsatz</th><th>Quote</th><th>mögl./Auszahlung</th><th>Status</th><th>Zeit</th><th></th></tr></thead>
            <tbody>
            <?php foreach ($allBets as $b): ?>
                <tr>
                    <td>#<?= (int)$b['id'] ?></td>
                    <td><?= e($b['username']) ?></td>
                    <td><strong><?= e($b['market_title']) ?></strong><br><span class="muted"><?= e($b['option_label']) ?></span></td>
                    <td><?= money_fmt((float)$b['stake']) ?></td>
                    <td><?= number_format((float)$b['odds'],2,',','.') ?></td>
                    <td><?= $b['status']==='won' ? '<span style="color:#4ad991">+'.money_fmt((float)$b['payout']).'</span>' : money_fmt((float)$b['potential_win']) ?></td>
                    <td><span class="badge b-<?= $b['status']==='won'?'settled':($b['status']==='open'?'open':($b['status']==='cancelled'?'cancelled':'closed')) ?>"><?= e($b['status']) ?></span></td>
                    <td class="muted"><?= e(date('d.m. H:i',strtotime($b['placed_at']))) ?></td>
                    <td><?php if ($b['status']==='open'): ?>
                        <form method="post" onsubmit="return confirm('Wette stornieren und Einsatz erstatten?')"><input type="hidden" name="csrf" value="<?= e($csrf) ?>">
                            <input type="hidden" name="action" value="cancel_bet"><input type="hidden" name="bet_id" value="<?= (int)$b['id'] ?>"><input type="hidden" name="back" value="<?= e($self.'?tab=bets&t='.$curTid) ?>">
                            <button class="btn-red">Storno</button></form>
                    <?php endif; ?></td>
                </tr>
            <?php endforeach; ?>
            </tbody>
        </table>
    </div>

    <?php elseif ($tab === 'log'): ?>
    <!-- ============ PROTOKOLL ============ -->
    <div class="adm-card">
        <h2>Admin-Protokoll</h2>
        <table class="adm-table">
            <thead><tr><th>Zeit</th><th>Admin</th><th>Aktion</th><th>Referenz</th><th>Details</th><th>IP</th></tr></thead>
            <tbody>
            <?php foreach ($svc->adminLog(150) as $l): ?>
                <tr>
                    <td class="muted"><?= e(date('d.m. H:i:s',strtotime($l['created_at']))) ?></td>
                    <td><?= e((string)$l['admin_name']) ?></td>
                    <td><span class="badge b-open"><?= e($l['action']) ?></span></td>
                    <td class="muted"><?= e((string)$l['ref_type']) ?> #<?= (int)$l['ref_id'] ?></td>
                    <td class="muted" style="max-width:340px;word-break:break-word"><?= e((string)$l['detail']) ?></td>
                    <td class="muted"><?= e((string)$l['ip']) ?></td>
                </tr>
            <?php endforeach; ?>
            </tbody>
        </table>
    </div>
    <?php endif; ?>

</div>
</body>
</html>

Youez - 2016 - github.com/yon3zu
LinuXploit