Files
MyKeyser/dashboard.php
T
2026-06-18 12:50:44 -04:00

105 lines
5.3 KiB
PHP

<?php
require_once __DIR__.'/includes/boot.php';
requireLogin();
$pageTitle = 'My Dashboard — Keyser WV';
$bizIds = isAdmin()
? array_column(qall("SELECT id FROM businesses"),'id')
: array_column(qall("SELECT business_id FROM business_owners WHERE user_id=?",[uid()]),'business_id');
$myBiz = $bizIds
? qall("SELECT b.*,c.name cat,COALESCE(AVG(r.rating),0) avg,COUNT(r.id) rcnt FROM businesses b JOIN categories c ON c.id=b.category_id LEFT JOIN reviews r ON r.business_id=b.id WHERE b.id IN(".implode(',',array_fill(0,count($bizIds),'?')).") GROUP BY b.id ORDER BY b.name",$bizIds)
: [];
$myEvents = authed() ? qall("SELECT * FROM events WHERE submitted_by=? ORDER BY created_at DESC LIMIT 10",[uid()]) : [];
$myClaims = authed() ? qall("
SELECT bcr.*, b.name biz_name, b.slug biz_slug
FROM business_claim_requests bcr
JOIN businesses b ON b.id=bcr.business_id
WHERE bcr.user_id=?
ORDER BY bcr.created_at DESC
LIMIT 5
", [uid()]) : [];
include __DIR__.'/includes/header.php';
?>
<div class="page-hdr">
<div class="page-hdr-inner">
<div class="eyebrow">MY ACCOUNT</div>
<h1 style="font-size:2rem;margin-bottom:.3rem">Dashboard — <?=e(uname())?></h1>
<p style="color:var(--text-m)">Manage your listings, menus, alerts, and submitted events.</p>
</div>
</div>
<div class="section">
<?php if($myClaims): ?>
<div class="eyebrow" style="margin-bottom:1rem">BUSINESS CLAIMS</div>
<div class="tbl-wrap" style="margin-bottom:2.5rem">
<table class="dtbl">
<thead><tr><th>BUSINESS</th><th>CONTACT PHONE</th><th>STATUS</th><th>SUBMITTED</th><th></th></tr></thead>
<tbody>
<?php foreach($myClaims as $claim): ?>
<tr>
<td class="td-name"><?=e($claim['biz_name'])?></td>
<td><?=e($claim['contact_phone'])?></td>
<td>
<?php $cc=['approved'=>'badge-green','pending'=>'badge-gold','rejected'=>'badge-red']; ?>
<span class="badge <?=$cc[$claim['status']]??'badge-gray'?>"><?=strtoupper($claim['status'])?></span>
<?php if($claim['status']==='pending'): ?>
<div style="font-size:.76rem;color:var(--text-d);margin-top:.2rem">We will contact you within a few business days for verification.</div>
<?php endif; ?>
</td>
<td><?=ago($claim['created_at'] ?? '')?></td>
<td><a href="/business.php?slug=<?=e($claim['biz_slug'])?>" class="btn btn-xs btn-outline">View Page</a></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php endif; ?>
<?php if($myBiz): ?>
<div class="eyebrow" style="margin-bottom:1rem">MY BUSINESS LISTINGS</div>
<div style="display:grid;grid-template-columns:repeat(auto-fill,minmax(340px,1fr));gap:1.4rem;margin-bottom:2.5rem">
<?php foreach($myBiz as $b): ?>
<div class="ibox">
<div class="ibox-title"><?=e($b['name'])?></div>
<div style="font-size:.82rem;color:var(--text-m);margin-bottom:.75rem"><?=e($b['cat'])?><?=$b['subcategory']?' · '.e($b['subcategory']):''?></div>
<div class="flex-row" style="gap:.4rem;margin-bottom:.85rem"><?=starDisplay((float)$b['avg'])?><span class="rat-score"><?=number_format((float)$b['avg'],1)?></span><span class="rat-cnt">(<?=$b['rcnt']?> reviews)</span></div>
<?php if($b['address']): ?><div style="font-size:.8rem;color:var(--text-d);margin-bottom:.75rem">📍 <?=e($b['address'])?></div><?php endif; ?>
<div class="flex-row" style="gap:.5rem;flex-wrap:wrap">
<a href="/business.php?slug=<?=e($b['slug'])?>" class="btn btn-outline btn-xs">View Listing</a>
<a href="/menu.php?id=<?=$b['id']?>" class="btn btn-secondary btn-xs">🍽️ Menu</a>
<?php if(isAdmin()): ?><a href="/admin/businesses.php?edit=<?=$b['id']?>" class="btn btn-secondary btn-xs">✏️ Edit</a><?php endif; ?>
</div>
</div>
<?php endforeach; ?>
</div>
<?php else: ?>
<div class="empty" style="padding:2rem"><div class="empty-ico">🏢</div><h3>No businesses assigned yet</h3><p style="margin-top:.5rem">Contact an administrator to link your business listing.</p></div>
<?php endif; ?>
<?php if($myEvents): ?>
<div class="eyebrow" style="margin-bottom:.8rem">MY SUBMITTED EVENTS</div>
<div class="tbl-wrap" style="margin-bottom:2.5rem">
<table class="dtbl">
<thead><tr><th>EVENT</th><th>DATE</th><th>STATUS</th><th></th></tr></thead>
<tbody>
<?php foreach($myEvents as $ev): ?>
<tr>
<td class="td-name"><?=e($ev['title'])?></td>
<td><?=fdate($ev['event_date'])?></td>
<td><?php $sc=['approved'=>'badge-green','pending'=>'badge-gold','rejected'=>'badge-red']; ?>
<span class="badge <?=$sc[$ev['status']]??'badge-gray'?>"><?=strtoupper($ev['status'])?></span></td>
<td><?php if($ev['status']==='approved'): ?><a href="/events.php" class="btn btn-xs btn-outline">View</a><?php endif; ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php endif; ?>
<div class="eyebrow" style="margin-bottom:1rem">QUICK ACTIONS</div>
<div class="flex-row">
<a href="/events.php?submit=1" class="btn btn-outline">📅 Submit Event</a>
<a href="/account.php" class="btn btn-secondary">⚙️ Account Settings</a>
<?php if(isAdmin()): ?><a href="/admin/" class="btn btn-navy">⚙ Admin Panel</a><?php endif; ?>
</div>
</div>
<?php include __DIR__.'/includes/footer.php'; ?>