Game Management: soft-delete, slug reuse, new game form fix, master-admin gating

- DB: added is_deleted, deleted_at columns to platforms table
- Soft delete: archive button moves games to archived section instead of hard delete
- Archived section: master admin can restore (reactivates) or permanently delete
- Slug reuse: creating a game with an archived slug reactivates the old record
- New game form: master admin always sees add form + agent info; other admins hidden
- Edit: non-master admins have form card revealed on edit
- Delete/Add buttons: only visible to master admin
- api/platforms.php: public and admin_list queries exclude archived games
- api/admin.php: platforms_archived, platforms_restore, platforms_purge actions added

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-04 18:45:31 +00:00
parent 185c27f6b4
commit 0c96b0ad7c
3 changed files with 122 additions and 21 deletions
+72 -9
View File
@@ -774,8 +774,8 @@ tr:hover td{background:rgba(255,255,255,.015)}
<div class="section" id="section-games">
<div class="page-title">🕹️ Game Management</div>
<!-- Add / Edit form -->
<div class="card" id="game-form-card" style="margin-bottom:16px">
<!-- Add / Edit form — master admin always sees this; others see it only when editing -->
<div class="card" id="game-form-card" style="margin-bottom:16px;<?= (int)$_SESSION['user_id'] !== MASTER_ADMIN_ID ? 'display:none' : '' ?>">
<div class="card-title" id="game-form-title"> Add New Game</div>
<div id="game-form-alert" class="alert" style="margin-bottom:10px"></div>
<input type="hidden" id="gf-id" value="">
@@ -910,6 +910,17 @@ tr:hover td{background:rgba(255,255,255,.015)}
</div>
<div id="games-list"></div>
</div>
<?php if ((int)$_SESSION['user_id'] === MASTER_ADMIN_ID): ?>
<!-- Archived Games — master admin only -->
<div class="card" style="padding:0;overflow:hidden;margin-top:16px">
<div style="padding:14px 18px;border-bottom:1px solid var(--border);display:flex;justify-content:space-between;align-items:center">
<div style="font-family:'Exo 2',sans-serif;font-weight:700;font-size:14px;color:var(--text2)">🗄️ Archived Games</div>
<button onclick="loadArchivedGames()" style="background:none;border:none;color:var(--cyan);font-size:13px;font-weight:700;cursor:pointer">↻ Refresh</button>
</div>
<div id="archived-games-list"><div style="padding:16px 18px;color:var(--text2);font-size:14px">Loading...</div></div>
</div>
<?php endif; ?>
</div>
<!-- ── HISTORY ─────────────────────────────────── -->
@@ -1161,6 +1172,8 @@ loadStats();
loadPurchases('pending');
loadCashouts('pending');
loadUsers();
// Initialize game form state on page load
if (typeof resetGameForm === 'function') resetGameForm();
async function loadStats() {
const d = await apiFetch('stats');
@@ -2897,7 +2910,7 @@ async function loadGames() {
<div id="credit-total-${g.id}" style="font-family:'Exo 2',sans-serif;font-weight:700;font-size:13px;color:var(--cyan);margin-bottom:6px">💳 —</div>
<div class="game-actions">
<button class="game-edit-btn" style="background:rgba(0,229,255,.1);color:var(--cyan);border:1px solid rgba(0,229,255,.2)" onclick="editGame(${g.id})">✏️ Edit</button>
<button class="game-edit-btn" style="background:rgba(255,68,68,.1);color:var(--red);border:1px solid rgba(255,68,68,.2)" onclick="deleteGame(${g.id},'${escAttr(g.name)}')">🗑</button>
${IS_MASTER_ADMIN ? `<button class="game-edit-btn" style="background:rgba(255,68,68,.1);color:var(--red);border:1px solid rgba(255,68,68,.2)" onclick="deleteGame(${g.id},'${escAttr(g.name)}')">🗑 Archive</button>` : ''}
</div>
</div>
</div>`).join('');
@@ -2990,6 +3003,8 @@ function editGame(id) {
document.getElementById('gf-credit-total').textContent = t%1===0 ? t.toLocaleString() : parseFloat(t).toLocaleString(undefined,{minimumFractionDigits:2,maximumFractionDigits:2});
}
});
// Non-master admins need the form card revealed when editing
document.getElementById('game-form-card').style.display = 'block';
document.getElementById('game-form-card').scrollIntoView({behavior:'smooth'});
}
@@ -3005,10 +3020,10 @@ function resetGameForm() {
document.getElementById('gf-active').value = '1';
document.getElementById('gf-credit-total').textContent = '—';
document.getElementById('gf-credit-btn').disabled = true;
// Always hide both agent panels when clearing
document.getElementById('gf-agent-edit').style.display = 'none';
document.getElementById('gf-agent-view').style.display = 'none';
if (IS_MASTER_ADMIN) {
// Master admin: show edit panel (visible for new games too), clear all fields
document.getElementById('gf-agent-edit').style.display = 'block';
document.getElementById('gf-agent-view').style.display = 'none';
document.getElementById('gf-agent-link').value = '';
document.getElementById('gf-agent-login').value = '';
document.getElementById('gf-agent-password').value = '';
@@ -3018,6 +3033,10 @@ function resetGameForm() {
document.getElementById('gf-sub-agent-password').value = '';
document.getElementById('gf-cashier-login').value = '';
document.getElementById('gf-cashier-password').value = '';
} else {
// Non-master: hide both panels; they only appear when editing
document.getElementById('gf-agent-edit').style.display = 'none';
document.getElementById('gf-agent-view').style.display = 'none';
}
document.getElementById('game-form-title').textContent = ' Add New Game';
document.getElementById('game-form-alert').className = 'alert';
@@ -3063,9 +3082,53 @@ async function saveGame() {
}
async function deleteGame(id, name) {
if (!confirm('Delete game "' + name + '"? This cannot be undone.\n\nNote: existing purchase records referencing this game will still show the old platform ID.')) return;
if (!confirm('Archive "' + name + '"?\n\nThis hides it from active games but does NOT permanently delete it. You can restore it from the Archived Games section below.')) return;
const d = await apiFetch('platforms_delete','POST',{id});
if (d.success) { toast('Game deleted','ok'); loadGames(); }
if (d.success) { toast('Game archived','ok'); loadGames(); loadArchivedGames(); }
else toast(d.error||'Error','err');
}
async function loadArchivedGames() {
const list = document.getElementById('archived-games-list');
if (!list) return;
const d = await apiFetch('platforms_archived');
if (!d.success) { list.innerHTML='<div style="padding:16px 18px;color:var(--red)">Failed to load.</div>'; return; }
if (!d.platforms.length) {
list.innerHTML='<div style="padding:16px 18px;color:var(--text2);font-size:14px">No archived games.</div>';
return;
}
list.innerHTML = d.platforms.map(g=>`
<div style="display:flex;align-items:center;justify-content:space-between;padding:12px 18px;border-bottom:1px solid var(--border);gap:10px">
<div style="flex:1;min-width:0">
<div style="font-family:'Exo 2',sans-serif;font-weight:700;font-size:15px;color:var(--text)">${escHtmlA(g.name)}</div>
<div style="font-size:12px;font-family:monospace;color:var(--text2);margin-top:2px">${escHtmlA(g.slug)}</div>
<div style="font-size:11px;color:var(--text2);margin-top:2px">Archived: ${g.deleted_at ? new Date(g.deleted_at).toLocaleDateString('en-US',{month:'short',day:'numeric',year:'numeric'}) : '—'}</div>
</div>
<div style="display:flex;gap:6px;flex-shrink:0">
<button onclick="restoreGame(${g.id},'${escAttr(g.name)}')"
style="background:rgba(0,230,118,.1);border:1px solid rgba(0,230,118,.25);color:var(--green);border-radius:6px;padding:6px 12px;font-size:13px;font-weight:700;cursor:pointer">
↩ Restore
</button>
<button onclick="purgeGame(${g.id},'${escAttr(g.name)}')"
style="background:rgba(255,68,68,.08);border:1px solid rgba(255,68,68,.2);color:var(--red);border-radius:6px;padding:6px 12px;font-size:13px;font-weight:700;cursor:pointer">
🗑 Delete Permanently
</button>
</div>
</div>`).join('');
}
async function restoreGame(id, name) {
if (!confirm('Restore "' + name + '" back to active games?')) return;
const d = await apiFetch('platforms_restore','POST',{id});
if (d.success) { toast('Game restored','ok'); loadGames(); loadArchivedGames(); }
else toast(d.error||'Error','err');
}
async function purgeGame(id, name) {
if (!confirm('PERMANENTLY delete "' + name + '"?\n\nThis cannot be undone. Historical purchase records will still reference the slug.')) return;
if (!confirm('Are you absolutely sure? This is irreversible.')) return;
const d = await apiFetch('platforms_purge','POST',{id});
if (d.success) { toast('Game permanently deleted','ok'); loadArchivedGames(); }
else toast(d.error||'Error','err');
}
@@ -3365,7 +3428,7 @@ function showSec(name) {
if (name === 'referrals') { loadAdminReferrals('pending', document.querySelector('#section-referrals .ftab')); }
if (name === 'platform-accounts') loadPlatformAccountRequests('pending', document.querySelector('#section-platform-accounts .ftab'));
if (name === 'broadcasts') loadBroadcasts();
if (name === 'games') loadGames();
if (name === 'games') { loadGames(); loadArchivedGames(); }
if (name === 'payments') loadPaymentSettings();
if (name === 'payout-settings') loadPayoutSettings();
if (name === 'cashout-methods') loadCashoutMethods();