<?php require_once __DIR__.'/../includes/functions.php'; $admin=require_admin(); verify_csrf(); mj_ensure_listing_module_schema(true); $adminTitle='Expired / Expiring Listings'; if(isset($_POST['id'],$_POST['action'])){ $id=(int)$_POST['id']; if($_POST['action']==='renew30'){ q('UPDATE mj_listings SET status="active", expires_at=?, expired_at=NULL WHERE id=?',[date('Y-m-d H:i:s',strtotime('+30 days')),$id]); mj_listing_log($id,'admin_renew_from_expired',[],[]); flash('success','Listing renewed 30 days.'); } elseif($_POST['action']==='expire'){ q('UPDATE mj_listings SET status="expired", expired_at=NOW() WHERE id=?',[$id]); mj_listing_log($id,'admin_expire_now',[],[]); flash('success','Listing expired.'); } redirect('expired-listings.php'); } $rows=all_rows("SELECT * FROM mj_listings WHERE (expires_at IS NOT NULL AND expires_at<=DATE_ADD(NOW(), INTERVAL 7 DAY)) OR status='expired' ORDER BY expires_at ASC,id DESC LIMIT 500"); include __DIR__.'/_header.php'; ?>
<div class="card card-danger card-outline"><div class="card-header"><h3 class="card-title"><i class="fas fa-hourglass-end mr-2"></i>Expired / Expiring Listings</h3></div><div class="card-body table-responsive"><table class="table table-striped mj-data-table"><thead><tr><th>ID</th><th>Title</th><th>Status</th><th>Expires</th><th>Boost</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['id'])?>"><?=e($r['title'])?></a></td><td><span class="badge badge-<?=mj_listing_status_badge($r['status']??'')?>"><?=e($r['status'])?></span></td><td class="<?=!empty($r['expires_at'])&&strtotime($r['expires_at'])<time()?'text-danger':'text-warning'?>"><?=e($r['expires_at'])?></td><td><?php if(mj_listing_active_sponsored($r)): ?><span class="badge badge-danger">Sponsored</span><?php endif; ?> <?php if(mj_listing_active_featured($r)): ?><span class="badge badge-warning">Featured</span><?php endif; ?></td><td><form method="post" class="btn-group btn-group-sm"><?=csrf_input()?><input type="hidden" name="id" value="<?=e($r['id'])?>"><button class="btn btn-success" name="action" value="renew30">Renew 30 Days</button><button class="btn btn-danger" name="action" value="expire">Expire Now</button></form></td></tr><?php endforeach; ?></tbody></table></div></div><?php include __DIR__.'/_footer.php'; ?>
