<?php
require_once __DIR__.'/../includes/functions.php'; $admin=require_admin(); verify_csrf(); mj263_schema(); $adminTitle='Notification Settings';
$keys=['live_notifications_enabled'=>'1','user_live_popup_enabled'=>'1','admin_live_popup_enabled'=>'1','email_queue_enabled'=>'0','listing_email_enabled'=>'1','offer_email_enabled'=>'1','chat_email_enabled'=>'1','marketing_email_enabled'=>'0'];
if($_SERVER['REQUEST_METHOD']==='POST'){ foreach($keys as $k=>$d){ $v=isset($_POST[$k])?'1':'0'; try{ q('INSERT INTO mj_notification_settings(setting_key,setting_value,updated_at) VALUES(?,?,NOW()) ON DUPLICATE KEY UPDATE setting_value=VALUES(setting_value),updated_at=NOW()',[$k,$v]); }catch(Throwable $e){} } flash('success','Notification settings saved.'); redirect('notification-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-bell mr-2"></i>Notification Control</h3></div><form method="post"><?=csrf_input()?><div class="card-body"><?php show_flash(); ?><div class="alert alert-info">Admin can disable live popups and email queue triggers globally. Users can still manage personal preferences unless admin disables globally.</div><?php foreach($keys as $k=>$d): $v=mj263_setting($k,$d); ?><div class="custom-control custom-switch mb-3"><input type="checkbox" class="custom-control-input" id="<?=$k?>" name="<?=$k?>" <?=$v==='1'?'checked':''?>><label class="custom-control-label" for="<?=$k?>"><?=e(ucwords(str_replace('_',' ',$k)))?></label></div><?php endforeach; ?></div><div class="card-footer"><button class="btn btn-primary">Save Settings</button></div></form></div><?php include __DIR__.'/_footer.php'; ?>
