60 lines
3.5 KiB
PHP
60 lines
3.5 KiB
PHP
<?php
|
||
$adminTitle = 'Business Alerts';
|
||
include __DIR__.'/admin_header.php';
|
||
|
||
if (isPost()) {
|
||
csrfCheck();
|
||
$act = p('_act');
|
||
if ($act === 'add') {
|
||
$bid=(int)p('business_id');$title=ps('title');$body=ps('body');$type=p('type','info');
|
||
if($bid&&$title) qrun("INSERT INTO alerts(business_id,type,title,body)VALUES(?,?,?,?)",[$bid,$type,$title,$body]);
|
||
flash('Alert posted!','success');
|
||
}
|
||
if ($act === 'toggle') { qrun("UPDATE alerts SET is_active=1-is_active WHERE id=?",[(int)p('id')]); }
|
||
if ($act === 'delete') { qrun("DELETE FROM alerts WHERE id=?",[(int)p('id')]); flash('Alert deleted.','success'); }
|
||
go('/admin/alerts.php');
|
||
}
|
||
|
||
$bizs = qall("SELECT id,name FROM businesses WHERE is_active=1 ORDER BY name");
|
||
$alerts = qall("SELECT a.*,b.name biz FROM alerts a JOIN businesses b ON b.id=a.business_id ORDER BY a.created_at DESC");
|
||
?>
|
||
<?php adminTitle('Business Alerts & Announcements') ?>
|
||
|
||
<div class="ibox" style="border-color:var(--gold-d);margin-bottom:2rem">
|
||
<div class="ibox-title">➕ POST NEW ALERT</div>
|
||
<form method="POST"><?=csrfField()?><input type="hidden" name="_act" value="add">
|
||
<div class="form-row">
|
||
<div class="fg"><label class="flabel">BUSINESS</label><select name="business_id" class="fselect" required><option value="">— Select —</option><?php foreach($bizs as $b): ?><option value="<?=$b['id']?>"><?=e($b['name'])?></option><?php endforeach; ?></select></div>
|
||
<div class="fg"><label class="flabel">TYPE</label><select name="type" class="fselect"><option value="info">ℹ️ Info</option><option value="news">📰 News</option><option value="event">🎉 Event</option><option value="warning">⚠️ Warning</option><option value="sale">🏷️ Sale/Promo</option></select></div>
|
||
</div>
|
||
<div class="fg"><label class="flabel">TITLE *</label><input type="text" name="title" class="finput" required></div>
|
||
<div class="fg"><label class="flabel">BODY</label><textarea name="body" class="ftextarea" style="min-height:65px"></textarea></div>
|
||
<button type="submit" class="btn btn-primary btn-sm">Post Alert</button>
|
||
</form>
|
||
</div>
|
||
|
||
<div class="admin-sec-title">ALL ALERTS (<?=count($alerts)?>)</div>
|
||
<div class="tbl-wrap">
|
||
<table class="dtbl">
|
||
<thead><tr><th>BUSINESS</th><th>TYPE</th><th>TITLE</th><th>STATUS</th><th>POSTED</th><th>ACTIONS</th></tr></thead>
|
||
<tbody>
|
||
<?php foreach($alerts as $a): ?>
|
||
<tr>
|
||
<td class="td-name"><?=e($a['biz'])?></td>
|
||
<td><span style="font-size:1rem"><?=alertIcon($a['type'])?></span> <?=e($a['type'])?></td>
|
||
<td style="font-size:.85rem;max-width:220px"><?=e($a['title'])?></td>
|
||
<td><?=$a['is_active']?'<span class="badge badge-green">Active</span>':'<span class="badge badge-gray">Inactive</span>'?></td>
|
||
<td style="font-size:.8rem"><?=ago($a['created_at'])?></td>
|
||
<td>
|
||
<div class="flex-row" style="gap:.3rem">
|
||
<form method="POST" style="display:inline"><?=csrfField()?><input type="hidden" name="_act" value="toggle"><input type="hidden" name="id" value="<?=$a['id']?>"><button class="btn btn-xs btn-secondary"><?=$a['is_active']?'Disable':'Enable'?></button></form>
|
||
<form method="POST" style="display:inline"><?=csrfField()?><input type="hidden" name="_act" value="delete"><input type="hidden" name="id" value="<?=$a['id']?>"><button class="btn btn-xs btn-danger" data-confirm="Delete alert?">🗑️</button></form>
|
||
</div>
|
||
</td>
|
||
</tr>
|
||
<?php endforeach; ?>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
<?php include __DIR__.'/admin_footer.php'; ?>
|