<?php
require_once __DIR__.'/../includes/functions.php';
require_once __DIR__.'/../includes/v292_admin_portal_helpers.php';
$admin=require_admin(); mj292_ensure_schema();
$adminTitle='Sponsored / Featured Performance'; $adminSubtitle='Track paid visibility value: views, lead events, expiry and renewal opportunity.';
$rows=[];
try { if(table_exists('mj_listings')) { $rows=all_rows("SELECT l.*, u.name user_name, u.email user_email,
  (SELECT COUNT(*) FROM mj_lead_events le WHERE le.listing_id=l.id) lead_events
  FROM mj_listings l LEFT JOIN mj_users u ON u.id=l.user_id
  WHERE COALESCE(l.is_sponsored,0)=1 OR COALESCE(l.is_featured,0)=1 ORDER BY l.id DESC LIMIT 100"); } } catch(Throwable $e) { $rows=[]; }
include __DIR__.'/_header.php';
?>
<div class="card mj-v292-card"><div class="card-header"><h3 class="card-title">Paid Visibility Listings</h3></div><div class="table-responsive"><table class="table table-hover mb-0"><thead><tr><th>Listing</th><th>User</th><th class="text-right">Views</th><th class="text-right">Leads</th><th>Sponsored</th><th>Featured</th><th>Expiry</th><th>Action</th></tr></thead><tbody><?php foreach($rows as $r): ?><tr><td><b><?=e($r['title']??('Listing #'.$r['id']))?></b></td><td><?=e($r['user_name']??'')?><br><small><?=e($r['user_email']??'')?></small></td><td class="text-right"><?=e((int)($r['views']??0))?></td><td class="text-right"><?=e((int)($r['lead_events']??0))?></td><td><?=((int)($r['is_sponsored']??0)?'<span class="badge badge-warning">Yes</span>':'<span class="badge badge-secondary">No</span>')?></td><td><?=((int)($r['is_featured']??0)?'<span class="badge badge-success">Yes</span>':'<span class="badge badge-secondary">No</span>')?></td><td><small><?=e($r['sponsored_until']??$r['featured_until']??'')?></small></td><td><a class="btn btn-xs btn-outline-primary" href="listing-view.php?id=<?=e($r['id'])?>">View</a></td></tr><?php endforeach; if(!$rows): ?><tr><td colspan="8" class="text-center text-muted p-4">No sponsored or featured listing.</td></tr><?php endif; ?></tbody></table></div></div>
<?php include __DIR__.'/_footer.php'; ?>
