<?php
require_once __DIR__.'/../includes/functions.php';
$admin=require_admin(); require_once __DIR__.'/../includes/mj_v3_helpers.php'; mj_v300_ensure_schema(); verify_csrf();
$adminTitle='Deal Upgrade Settings';
if($_SERVER['REQUEST_METHOD']==='POST'){
  try{ $keys=['default_max_deals_per_user','extra_deal_slot_charge_amount','deal_renewal_charge_amount','deal_renewal_default_days','deal_featured_charge_amount','deal_sponsored_charge_amount','deal_homepage_charge_amount','deal_bump_charge_amount','deal_urgent_charge_amount','deal_upgrade_default_days','deal_upgrade_max_days','deal_auto_approve']; foreach($keys as $k){ $v=trim((string)($_POST[$k]??'')); q('INSERT INTO mj_settings(setting_key,setting_value) VALUES(?,?) ON DUPLICATE KEY UPDATE setting_value=VALUES(setting_value), updated_at=NOW()',[$k,$v]); } flash('success','Deal upgrade settings saved.'); redirect('deal-upgrade-settings.php'); }catch(Throwable $e){ flash('error',$e->getMessage()); }
}
include __DIR__.'/_header.php'; $opts=mj_v300_deal_upgrade_options(); ?>
<div class="card card-body border-0 shadow-sm rounded-lg mb-4"><h3 class="h5 font-weight-bold">Deal monetization</h3><p class="text-muted">Users/sellers can pay admin for extra deal slots, renewal, sponsored, featured, homepage, bump and urgent deal labels. Customers still cannot pay sellers through the system.</p><form method="post"><?=csrf_input()?><div class="row"><div class="col-md-4 mb-3"><label>Default max deals per user</label><input class="form-control" type="number" min="0" name="default_max_deals_per_user" value="<?=e(setting('default_max_deals_per_user','3'))?>"></div><div class="col-md-4 mb-3"><label>Default promotion days</label><input class="form-control" type="number" min="1" name="deal_upgrade_default_days" value="<?=e(setting('deal_upgrade_default_days','7'))?>"></div><div class="col-md-4 mb-3"><label>Max promotion days</label><input class="form-control" type="number" min="1" name="deal_upgrade_max_days" value="<?=e(setting('deal_upgrade_max_days','90'))?>"></div><div class="col-md-4 mb-3"><label>Deal auto approve</label><select name="deal_auto_approve" class="form-control"><option value="0" <?=setting('deal_auto_approve','0')==='0'?'selected':''?>>No, admin review required</option><option value="1" <?=setting('deal_auto_approve','0')==='1'?'selected':''?>>Yes, auto approve normal deals</option></select></div><div class="col-md-4 mb-3"><label>Deal renewal default days</label><input class="form-control" type="number" min="1" name="deal_renewal_default_days" value="<?=e(setting('deal_renewal_default_days','30'))?>"></div></div><hr><h4 class="h6 font-weight-bold">Prices charged to user/seller</h4><div class="row"><?php foreach($opts as $key=>$o): ?><div class="col-md-4 mb-3"><label><?=e($o['label'])?></label><input class="form-control" type="number" step="0.01" min="0" name="<?=e($o['setting'])?>" value="<?=e(setting($o['setting'],$o['default']))?>"><small class="text-muted"><?=e($o['desc'])?></small></div><?php endforeach; ?></div><button class="btn btn-primary rounded-pill"><i class="fas fa-save mr-1"></i>Save Settings</button></form></div>
<?php include __DIR__.'/_footer.php'; ?>
