Add agent fields to game management

- DB: renamed console_url to agent_link, added agent_login, agent_password, games_link, agent_guide to platforms table
- api/platforms.php: create/update now handles all 5 agent fields (admin-only)
- admin/index.php: game form has new Agent Info section (purple, admin-only styling); game list cards show all agent fields inline; JS saveGame/editGame/resetGameForm updated

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-04 17:39:48 +00:00
parent 497071e1b7
commit 0aec13daf4
2 changed files with 93 additions and 37 deletions
+66 -18
View File
@@ -793,9 +793,31 @@ tr:hover td{background:rgba(255,255,255,.015)}
<label class="gm-edit-label">Player URL * <span style="font-weight:400;color:var(--text2)">shown to players — opens the game</span></label>
<input class="fi-sm" id="gf-player-url" type="url" placeholder="https://game.example.com/play" style="width:100%;padding:10px 12px">
</div>
<div style="margin-bottom:10px">
<label class="gm-edit-label">Console / Admin URL <span style="font-weight:400;color:var(--text2)">only visible to admins</span></label>
<input class="fi-sm" id="gf-console-url" type="url" placeholder="https://admin.game.example.com" style="width:100%;padding:10px 12px">
<!-- Agent Fields — admin only -->
<div style="background:rgba(155,93,229,0.06);border:1px solid rgba(155,93,229,0.2);border-radius:8px;padding:12px 14px;margin-bottom:10px">
<div style="font-size:12px;font-weight:700;color:var(--purple);letter-spacing:1px;text-transform:uppercase;margin-bottom:10px">🔐 Agent Info — Admin Only</div>
<div style="display:grid;grid-template-columns:1fr 1fr;gap:10px;margin-bottom:10px">
<div>
<label class="gm-edit-label">Agent Login</label>
<input class="fi-sm" id="gf-agent-login" type="text" placeholder="Username or email" style="width:100%;padding:10px 12px">
</div>
<div>
<label class="gm-edit-label">Agent Password</label>
<input class="fi-sm" id="gf-agent-password" type="text" placeholder="Password" style="width:100%;padding:10px 12px">
</div>
</div>
<div style="margin-bottom:10px">
<label class="gm-edit-label">Agent Link <span style="font-weight:400;color:var(--text2)">admin/console URL</span></label>
<input class="fi-sm" id="gf-agent-link" type="url" placeholder="https://admin.game.example.com" style="width:100%;padding:10px 12px">
</div>
<div style="margin-bottom:10px">
<label class="gm-edit-label">Games Link <span style="font-weight:400;color:var(--text2)">game listing or lobby URL</span></label>
<input class="fi-sm" id="gf-games-link" type="url" placeholder="https://game.example.com/lobby" style="width:100%;padding:10px 12px">
</div>
<div>
<label class="gm-edit-label">Agent Guide <span style="font-weight:400;color:var(--text2)">notes, instructions, tips</span></label>
<textarea class="fi-sm" id="gf-agent-guide" rows="3" placeholder="Step-by-step agent instructions, notes, or tips..." style="width:100%;padding:10px 12px;resize:vertical;font-family:inherit;font-size:14px"></textarea>
</div>
</div>
<div style="display:grid;grid-template-columns:1fr 1fr 1fr;gap:10px;margin-bottom:14px">
<div>
@@ -2701,11 +2723,25 @@ async function loadGames() {
<span class="game-url-val">${escHtmlA(g.player_url)}</span>
<a href="${escHtmlA(g.player_url)}" target="_blank" class="game-url-link">↗</a>
</div>
${g.console_url ? `<div class="game-url-row">
<span class="game-url-label" style="color:var(--gold)">CONSOLE</span>
<span class="game-url-val">${escHtmlA(g.console_url)}</span>
<a href="${escHtmlA(g.console_url)}" target="_blank" class="game-url-link" style="color:var(--gold)">↗</a>
${g.agent_link ? `<div class="game-url-row">
<span class="game-url-label" style="color:var(--gold)">AGENT LINK</span>
<span class="game-url-val">${escHtmlA(g.agent_link)}</span>
<a href="${escHtmlA(g.agent_link)}" target="_blank" class="game-url-link" style="color:var(--gold)">↗</a>
</div>` : ''}
${g.games_link ? `<div class="game-url-row">
<span class="game-url-label" style="color:var(--cyan)">GAMES LINK</span>
<span class="game-url-val">${escHtmlA(g.games_link)}</span>
<a href="${escHtmlA(g.games_link)}" target="_blank" class="game-url-link" style="color:var(--cyan)">↗</a>
</div>` : ''}
${g.agent_login ? `<div class="game-url-row">
<span class="game-url-label" style="color:var(--purple)">LOGIN</span>
<span class="game-url-val">${escHtmlA(g.agent_login)}</span>
</div>` : ''}
${g.agent_password ? `<div class="game-url-row">
<span class="game-url-label" style="color:var(--purple)">PASSWORD</span>
<span class="game-url-val">${escHtmlA(g.agent_password)}</span>
</div>` : ''}
${g.agent_guide ? `<div style="margin-top:6px;padding:8px 10px;background:rgba(155,93,229,0.07);border-radius:6px;font-size:12px;color:var(--text2);white-space:pre-wrap;max-height:80px;overflow:auto"><span style="color:var(--purple);font-weight:700;font-size:11px;letter-spacing:1px">AGENT GUIDE </span>${escHtmlA(g.agent_guide)}</div>` : ''}
</div>
</div>
<div style="text-align:right;flex-shrink:0">
@@ -2727,9 +2763,13 @@ function editGame(id) {
document.getElementById('gf-name').value = g.name;
document.getElementById('gf-slug').value = g.slug;
document.getElementById('gf-slug').disabled = true; // slug can't change (used as FK in purchases)
document.getElementById('gf-player-url').value = g.player_url;
document.getElementById('gf-console-url').value= g.console_url || '';
document.getElementById('gf-color').value = g.color || '#f0c040';
document.getElementById('gf-player-url').value = g.player_url;
document.getElementById('gf-agent-link').value = g.agent_link || '';
document.getElementById('gf-agent-login').value = g.agent_login || '';
document.getElementById('gf-agent-password').value= g.agent_password || '';
document.getElementById('gf-games-link').value = g.games_link || '';
document.getElementById('gf-agent-guide').value = g.agent_guide || '';
document.getElementById('gf-color').value = g.color || '#f0c040';
document.getElementById('gf-color-hex').value = g.color || '#f0c040';
document.getElementById('gf-sort').value = g.sort_order;
document.getElementById('gf-active').value = g.is_active;
@@ -2742,9 +2782,13 @@ function resetGameForm() {
document.getElementById('gf-name').value = '';
document.getElementById('gf-slug').value = '';
document.getElementById('gf-slug').disabled = false;
document.getElementById('gf-player-url').value = '';
document.getElementById('gf-console-url').value = '';
document.getElementById('gf-color').value = '#f0c040';
document.getElementById('gf-player-url').value = '';
document.getElementById('gf-agent-link').value = '';
document.getElementById('gf-agent-login').value = '';
document.getElementById('gf-agent-password').value= '';
document.getElementById('gf-games-link').value = '';
document.getElementById('gf-agent-guide').value = '';
document.getElementById('gf-color').value = '#f0c040';
document.getElementById('gf-color-hex').value = '#f0c040';
document.getElementById('gf-sort').value = '99';
document.getElementById('gf-active').value = '1';
@@ -2761,11 +2805,15 @@ async function saveGame() {
const id = document.getElementById('gf-id').value;
const data = {
id: id ? parseInt(id) : undefined,
name: document.getElementById('gf-name').value.trim(),
slug: document.getElementById('gf-slug').value.trim(),
player_url: document.getElementById('gf-player-url').value.trim(),
console_url: document.getElementById('gf-console-url').value.trim(),
color: document.getElementById('gf-color-hex').value.trim() || document.getElementById('gf-color').value,
name: document.getElementById('gf-name').value.trim(),
slug: document.getElementById('gf-slug').value.trim(),
player_url: document.getElementById('gf-player-url').value.trim(),
agent_link: document.getElementById('gf-agent-link').value.trim(),
agent_login: document.getElementById('gf-agent-login').value.trim(),
agent_password: document.getElementById('gf-agent-password').value.trim(),
games_link: document.getElementById('gf-games-link').value.trim(),
agent_guide: document.getElementById('gf-agent-guide').value.trim(),
color: document.getElementById('gf-color-hex').value.trim() || document.getElementById('gf-color').value,
sort_order: parseInt(document.getElementById('gf-sort').value) || 99,
is_active: parseInt(document.getElementById('gf-active').value),
};
+27 -19
View File
@@ -23,7 +23,7 @@ switch ($action) {
echo json_encode(['success'=>true, 'platforms'=>$out]);
break;
// ── Admin: full list including console_url and inactive ─
// ── Admin: full list including agent fields and inactive ─
case 'admin_list':
if (!$isAdmin) { echo json_encode(['success'=>false,'error'=>'Forbidden']); exit; }
$rows = db()->query("SELECT * FROM platforms ORDER BY sort_order ASC, id ASC")->fetchAll();
@@ -34,17 +34,21 @@ switch ($action) {
case 'create':
if (!$isAdmin || $_SERVER['REQUEST_METHOD'] !== 'POST') { echo json_encode(['success'=>false,'error'=>'Forbidden']); exit; }
$d = json_decode(file_get_contents('php://input'), true);
$slug = preg_replace('/[^a-z0-9_]/', '', strtolower(trim($d['slug'] ?? '')));
$name = substr(trim($d['name'] ?? ''), 0, 100);
$player_url = substr(trim($d['player_url'] ?? ''), 0, 500);
$console_url = substr(trim($d['console_url'] ?? ''), 0, 500);
$color = preg_match('/^#[0-9a-fA-F]{3,8}$/', $d['color'] ?? '') ? $d['color'] : '#f0c040';
$sort_order = (int)($d['sort_order'] ?? 99);
$is_active = isset($d['is_active']) ? (int)(bool)$d['is_active'] : 1;
$slug = preg_replace('/[^a-z0-9_]/', '', strtolower(trim($d['slug'] ?? '')));
$name = substr(trim($d['name'] ?? ''), 0, 100);
$player_url = substr(trim($d['player_url'] ?? ''), 0, 500);
$agent_link = substr(trim($d['agent_link'] ?? ''), 0, 500);
$agent_login = substr(trim($d['agent_login'] ?? ''), 0, 200);
$agent_password = substr(trim($d['agent_password'] ?? ''), 0, 200);
$games_link = substr(trim($d['games_link'] ?? ''), 0, 500);
$agent_guide = trim($d['agent_guide'] ?? '');
$color = preg_match('/^#[0-9a-fA-F]{3,8}$/', $d['color'] ?? '') ? $d['color'] : '#f0c040';
$sort_order = (int)($d['sort_order'] ?? 99);
$is_active = isset($d['is_active']) ? (int)(bool)$d['is_active'] : 1;
if (!$slug || !$name || !$player_url) { echo json_encode(['success'=>false,'error'=>'Slug, name, and player URL are required']); exit; }
try {
$stmt = db()->prepare("INSERT INTO platforms (slug,name,player_url,console_url,color,sort_order,is_active) VALUES (?,?,?,?,?,?,?)");
$stmt->execute([$slug,$name,$player_url,$console_url,$color,$sort_order,$is_active]);
$stmt = db()->prepare("INSERT INTO platforms (slug,name,player_url,agent_link,agent_login,agent_password,games_link,agent_guide,color,sort_order,is_active) VALUES (?,?,?,?,?,?,?,?,?,?,?)");
$stmt->execute([$slug,$name,$player_url,$agent_link,$agent_login,$agent_password,$games_link,$agent_guide,$color,$sort_order,$is_active]);
echo json_encode(['success'=>true,'id'=>db()->lastInsertId()]);
} catch (Exception $e) {
echo json_encode(['success'=>false,'error'=>'Slug already exists or DB error']);
@@ -55,16 +59,20 @@ switch ($action) {
case 'update':
if (!$isAdmin || $_SERVER['REQUEST_METHOD'] !== 'POST') { echo json_encode(['success'=>false,'error'=>'Forbidden']); exit; }
$d = json_decode(file_get_contents('php://input'), true);
$id = (int)($d['id'] ?? 0);
$name = substr(trim($d['name'] ?? ''), 0, 100);
$player_url = substr(trim($d['player_url'] ?? ''), 0, 500);
$console_url = substr(trim($d['console_url'] ?? ''), 0, 500);
$color = preg_match('/^#[0-9a-fA-F]{3,8}$/', $d['color'] ?? '') ? $d['color'] : '#f0c040';
$sort_order = (int)($d['sort_order'] ?? 99);
$is_active = (int)(bool)($d['is_active'] ?? 1);
$id = (int)($d['id'] ?? 0);
$name = substr(trim($d['name'] ?? ''), 0, 100);
$player_url = substr(trim($d['player_url'] ?? ''), 0, 500);
$agent_link = substr(trim($d['agent_link'] ?? ''), 0, 500);
$agent_login = substr(trim($d['agent_login'] ?? ''), 0, 200);
$agent_password = substr(trim($d['agent_password'] ?? ''), 0, 200);
$games_link = substr(trim($d['games_link'] ?? ''), 0, 500);
$agent_guide = trim($d['agent_guide'] ?? '');
$color = preg_match('/^#[0-9a-fA-F]{3,8}$/', $d['color'] ?? '') ? $d['color'] : '#f0c040';
$sort_order = (int)($d['sort_order'] ?? 99);
$is_active = (int)(bool)($d['is_active'] ?? 1);
if (!$id || !$name || !$player_url) { echo json_encode(['success'=>false,'error'=>'ID, name, and player URL required']); exit; }
db()->prepare("UPDATE platforms SET name=?,player_url=?,console_url=?,color=?,sort_order=?,is_active=? WHERE id=?")
->execute([$name,$player_url,$console_url,$color,$sort_order,$is_active,$id]);
db()->prepare("UPDATE platforms SET name=?,player_url=?,agent_link=?,agent_login=?,agent_password=?,games_link=?,agent_guide=?,color=?,sort_order=?,is_active=? WHERE id=?")
->execute([$name,$player_url,$agent_link,$agent_login,$agent_password,$games_link,$agent_guide,$color,$sort_order,$is_active,$id]);
echo json_encode(['success'=>true]);
break;