<?php
require_once __DIR__.'/../includes/functions.php'; $admin=require_admin(); verify_csrf(); mj_ensure_listing_module_schema(true); $adminTitle='Listing Settings';
if($_SERVER['REQUEST_METHOD']==='POST'){
  $settings=['listing_default_expiry_days','listing_approval_required','show_sold_listings','user_renew_requires_approval','listing_allow_user_delete','listing_allow_user_inactive'];
  foreach($settings as $k){ $v=trim((string)($_POST[$k]??'')); try{ q('INSERT INTO mj_settings(setting_key,setting_value) VALUES(?,?) ON DUPLICATE KEY UPDATE setting_value=VALUES(setting_value)',[$k,$v]); }catch(Throwable $e){} }
  flash('success','Listing settings saved.'); redirect('listing-settings.php');
}
include __DIR__.'/_header.php'; ?>
<div class="card card-primary card-outline"><div class="card-header"><h3 class="card-title"><i class="fas fa-cogs mr-2"></i>Listing Settings</h3></div><form method="post"><?=csrf_input()?><div class="card-body"><?php show_flash(); ?><div class="row"><div class="col-md-4"><label>Default expiry days</label><input class="form-control" type="number" min="1" name="listing_default_expiry_days" value="<?=e(setting('listing_default_expiry_days','30'))?>"></div><div class="col-md-4"><label>Approval required</label><select class="form-control" name="listing_approval_required"><option value="1" <?=setting('listing_approval_required','1')==='1'?'selected':''?>>Yes</option><option value="0" <?=setting('listing_approval_required','1')==='0'?'selected':''?>>No</option></select></div><div class="col-md-4"><label>Show sold listings public</label><select class="form-control" name="show_sold_listings"><option value="1" <?=setting('show_sold_listings','1')==='1'?'selected':''?>>Yes, with SOLD badge</option><option value="0" <?=setting('show_sold_listings','1')==='0'?'selected':''?>>No</option></select></div></div><div class="row mt-3"><div class="col-md-4"><label>User renew requires approval</label><select class="form-control" name="user_renew_requires_approval"><option value="1" <?=setting('user_renew_requires_approval','1')==='1'?'selected':''?>>Yes</option><option value="0" <?=setting('user_renew_requires_approval','1')==='0'?'selected':''?>>No</option></select></div><div class="col-md-4"><label>Allow user delete own listing</label><select class="form-control" name="listing_allow_user_delete"><option value="1" <?=setting('listing_allow_user_delete','1')==='1'?'selected':''?>>Yes</option><option value="0" <?=setting('listing_allow_user_delete','1')==='0'?'selected':''?>>No</option></select></div><div class="col-md-4"><label>Allow user inactive/reactivate</label><select class="form-control" name="listing_allow_user_inactive"><option value="1" <?=setting('listing_allow_user_inactive','1')==='1'?'selected':''?>>Yes</option><option value="0" <?=setting('listing_allow_user_inactive','1')==='0'?'selected':''?>>No</option></select></div></div></div><div class="card-footer"><button class="btn btn-primary">Save Settings</button></div></form></div><?php include __DIR__.'/_footer.php'; ?>
