<?php
require_once __DIR__.'/../includes/functions.php'; $admin=require_admin(); verify_csrf(); mj263_schema(); $adminTitle='Reported Listings';
if(isset($_POST['status'],$_POST['report_id'])){ q('UPDATE mj_listing_reports SET status=?,admin_id=?,admin_note=?,reviewed_at=NOW() WHERE id=?',[$_POST['status'],$admin['id'],$_POST['admin_note']??'',(int)$_POST['report_id']]); flash('success','Report updated.'); redirect('reported-listings.php'); }
$rows=table_exists('mj_listing_reports')?all_rows('SELECT r.*,l.title,u.name user_name FROM mj_listing_reports r LEFT JOIN mj_listings l ON l.id=r.listing_id LEFT JOIN mj_users u ON u.id=r.user_id ORDER BY r.id DESC LIMIT 300'):[]; include __DIR__.'/_header.php'; ?>
<div class="card card-danger card-outline"><div class="card-header"><h3 class="card-title"><i class="fas fa-flag mr-2"></i>Reported Listings</h3></div><div class="card-body"><?php show_flash(); ?><table class="table table-hover"><thead><tr><th>ID</th><th>Listing</th><th>User</th><th>Reason</th><th>Message</th><th>Status</th><th>Action</th></tr></thead><tbody><?php foreach($rows as $r): ?><tr><td><?=e($r['id'])?></td><td><a href="listing-edit.php?id=<?=e($r['listing_id'])?>">#<?=e($r['listing_id'])?> <?=e($r['title'])?></a></td><td><?=e($r['user_name']??'Guest')?></td><td><?=e($r['reason'])?></td><td><?=e($r['message'])?></td><td><?=e($r['status'])?></td><td><form method="post" class="d-flex gap-1"><?=csrf_input()?><input type="hidden" name="report_id" value="<?=e($r['id'])?>"><select class="form-control form-control-sm" name="status"><option>new</option><option>reviewing</option><option>resolved</option><option>ignored</option></select><input class="form-control form-control-sm" name="admin_note" placeholder="note"><button class="btn btn-sm btn-primary">Save</button></form></td></tr><?php endforeach; ?></tbody></table></div></div><?php include __DIR__.'/_footer.php'; ?>
