Files
MyKeyser/admin/reports.php
T
Ty Clifford b57091e4ad - initial
2026-04-24 08:41:52 -04:00

61 lines
3.4 KiB
PHP

<?php
$adminTitle = 'Listing Reports';
include __DIR__.'/admin_header.php';
if (isPost()) {
csrfCheck();
$act = p('_act');
if ($act === 'close') { qrun("UPDATE reports SET status='closed',admin_notes=? WHERE id=?",[ps('notes'),(int)p('id')]); flash('Report closed.','success'); }
if ($act === 'delete') { qrun("DELETE FROM reports WHERE id=?",[(int)p('id')]); flash('Report deleted.','success'); }
go('/admin/reports.php');
}
$filter = gs('filter') ?: 'open';
$where = $filter === 'all' ? "" : "WHERE r.status='open'";
$reports = qall("SELECT r.*,b.name biz,b.slug biz_slug,u.username reporter FROM reports r JOIN businesses b ON b.id=r.business_id JOIN users u ON u.id=r.user_id $where ORDER BY r.created_at DESC");
?>
<?php adminTitle('Listing Correction Reports','User-submitted corrections and issues for business listings.') ?>
<div style="display:flex;gap:.4rem;margin-bottom:1rem">
<a href="/admin/reports.php?filter=open" class="btn btn-xs<?=$filter==='open'?' btn-primary':' btn-outline'?>">Open</a>
<a href="/admin/reports.php?filter=all" class="btn btn-xs<?=$filter==='all'?' btn-primary':' btn-outline'?>">All</a>
</div>
<?php if($reports): ?>
<div class="tbl-wrap">
<table class="dtbl">
<thead><tr><th>BUSINESS</th><th>REPORTER</th><th>TYPE</th><th>MESSAGE</th><th>STATUS</th><th>DATE</th><th>ACTIONS</th></tr></thead>
<tbody>
<?php foreach($reports as $r): ?>
<tr>
<td><a href="/business.php?slug=<?=e($r['biz_slug'])?>" target="_blank" class="td-name"><?=e($r['biz'])?></a></td>
<td><?=e($r['reporter'])?></td>
<td><span class="badge badge-gold"><?=e($r['type'])?></span></td>
<td style="font-size:.82rem;max-width:250px"><?=e(substr($r['message'],0,100)).(strlen($r['message'])>100?'…':'')?></td>
<td><?=$r['status']==='open'?'<span class="badge badge-red">Open</span>':'<span class="badge badge-green">Closed</span>'?></td>
<td style="font-size:.8rem"><?=ago($r['created_at'])?></td>
<td>
<?php if($r['status']==='open'): ?>
<details><summary class="btn btn-xs btn-outline" style="list-style:none;cursor:pointer">Close</summary>
<div style="background:var(--bg4);border:1px solid var(--bdr);border-radius:4px;padding:.75rem;margin-top:.4rem;min-width:220px">
<div style="font-size:.78rem;color:var(--text-m);margin-bottom:.5rem"><?=e($r['message'])?></div>
<form method="POST"><?=csrfField()?><input type="hidden" name="_act" value="close"><input type="hidden" name="id" value="<?=$r['id']?>">
<textarea name="notes" class="ftextarea" style="min-height:55px;font-size:.8rem" placeholder="Admin notes (optional)…"></textarea>
<button type="submit" class="btn btn-xs btn-success" style="margin-top:.4rem">Mark Closed</button>
</form>
</div>
</details>
<?php else: ?>
<form method="POST" style="display:inline"><?=csrfField()?><input type="hidden" name="_act" value="delete"><input type="hidden" name="id" value="<?=$r['id']?>"><button class="btn btn-xs btn-danger" data-confirm="Delete report?">🗑️</button></form>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php else: ?>
<div class="empty" style="padding:2rem"><div class="empty-ico">✅</div><h3>No <?=$filter==='open'?'open':''?> reports</h3></div>
<?php endif; ?>
<?php include __DIR__.'/admin_footer.php'; ?>