Files
2026-06-19 12:03:13 -04:00

614 lines
26 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
require_once __DIR__.'/includes/boot.php';
$slug = gs('slug');
$b = qone("
SELECT
b.id, b.name, b.slug, b.subcategory, b.description,
b.address, b.phone, b.email, b.website, COALESCE(b.video_url,'') AS video_url,
COALESCE(b.hours,'{}') AS hours,
b.lat, b.lng, b.is_active, b.is_featured, b.created_at,
b.category_id,
COALESCE(c.name,'Uncategorized') AS cat,
COALESCE(c.icon,'🏢') AS cat_icon,
COALESCE(AVG(CASE WHEN r.is_approved=1 THEN r.rating END), 0) AS avg,
COUNT(CASE WHEN r.is_approved=1 THEN r.id END) AS rcnt
FROM businesses b
LEFT JOIN categories c ON c.id = b.category_id
LEFT JOIN reviews r ON r.business_id = b.id
WHERE b.slug = ? AND b.is_active = 1
GROUP BY b.id
", [$slug]);
if (!$b) { flash('Business not found.','error'); go('/directory.php'); }
/* ── POST handlers ─────────────────────────────────────── */
if (isPost()) {
csrfCheck();
$act = p('_act');
// Owner submits edit request
if ($act === 'owner_edit' && owns($b['id']) && !isAdmin()) {
$days = ['Mon','Tue','Wed','Thu','Fri','Sat','Sun'];
$allowedFields = ['description','address','phone','email','website','video_url','is_active'];
$submitted = 0;
// Simple text fields
foreach ($allowedFields as $field) {
$new = ps($field);
$old = (string)($b[$field] ?? '');
// For is_active, p() not ps()
if ($field === 'is_active') {
$new = (string)(int)p('is_active', $b['is_active']);
$old = (string)(int)$b['is_active'];
}
if ($field === 'video_url' && !validBusinessVideoUrl($new)) {
flash('Business videos must be a YouTube or Vimeo URL.', 'error');
go("/business.php?slug=$slug");
}
if ($new !== $old) {
// Remove any existing pending request for this field
qrun("DELETE FROM business_edit_requests WHERE business_id=? AND field=? AND status='pending'",
[$b['id'], $field]);
qrun("INSERT INTO business_edit_requests(business_id,user_id,field,old_value,new_value)VALUES(?,?,?,?,?)",
[$b['id'], uid(), $field, $old, $new]);
$submitted++;
}
}
// Hours field — build JSON from individual day inputs
$hrs = [];
foreach ($days as $d) {
$v = ps("hours_$d");
if ($v !== '') $hrs[$d] = $v;
}
$newHours = json_encode($hrs);
$oldHours = (string)($b['hours'] ?? '{}');
if ($newHours !== $oldHours) {
qrun("DELETE FROM business_edit_requests WHERE business_id=? AND field='hours' AND status='pending'",
[$b['id']]);
qrun("INSERT INTO business_edit_requests(business_id,user_id,field,old_value,new_value)VALUES(?,?,?,?,?)",
[$b['id'], uid(), 'hours', $oldHours, $newHours]);
$submitted++;
}
if ($submitted > 0) {
flash("$submitted change".($submitted>1?'s':'')." submitted for admin review.", 'success');
} else {
flash('No changes detected.', 'info');
}
go("/business.php?slug=$slug");
}
if ($act === 'review' && authed()) {
$rating = max(1, min(5, (int)p('rating', 5)));
$title = ps('rtitle');
$body = ps('rbody');
$ex = qval("SELECT id FROM reviews WHERE business_id=? AND user_id=?", [$b['id'], uid()]);
if ($ex) {
qrun("UPDATE reviews SET rating=?,title=?,body=?,created_at=datetime('now') WHERE id=?",
[$rating, $title, $body, $ex]);
} else {
qrun("INSERT INTO reviews(business_id,user_id,rating,title,body)VALUES(?,?,?,?,?)",
[$b['id'], uid(), $rating, $title, $body]);
}
flash('Review saved!', 'success');
go("/business.php?slug=$slug");
}
if ($act === 'post_alert' && owns($b['id'])) {
$t = ps('atitle');
$body = ps('abody');
$type = p('atype', 'info');
if ($t && $body) {
qrun("INSERT INTO alerts(business_id,type,title,body)VALUES(?,?,?,?)",
[$b['id'], $type, $t, $body]);
flash('Alert posted!', 'success');
}
go("/business.php?slug=$slug");
}
if ($act === 'del_alert' && owns($b['id'])) {
qrun("DELETE FROM alerts WHERE id=? AND business_id=?", [(int)p('aid'), $b['id']]);
go("/business.php?slug=$slug");
}
if ($act === 'del_review' && isAdmin()) {
qrun("DELETE FROM reviews WHERE id=?", [(int)p('rid')]);
flash('Review deleted.', 'success');
go("/business.php?slug=$slug");
}
if ($act === 'report' && authed()) {
$rtype = p('rtype', 'correction');
$rmsg = ps('rmsg');
if ($rmsg) {
qrun("INSERT INTO reports(business_id,user_id,type,message)VALUES(?,?,?,?)",
[$b['id'], uid(), $rtype, $rmsg]);
flash('Report submitted. Thank you!', 'success');
}
go("/business.php?slug=$slug");
}
}
/* ── Page data ─────────────────────────────────────────── */
$pageTitle = e($b['name']).' — Keyser, WV';
$activeNav = 'dir';
$reviews = qall("
SELECT r.*, u.username
FROM reviews r JOIN users u ON u.id = r.user_id
WHERE r.business_id = ? AND r.is_approved = 1
ORDER BY r.created_at DESC
", [$b['id']]);
$sects = qall("SELECT * FROM menu_sections WHERE business_id=? ORDER BY sort_order", [$b['id']]);
$mitems = [];
foreach ($sects as $s) {
$mitems[$s['id']] = qall(
"SELECT * FROM menu_items WHERE section_id=? AND is_available=1 ORDER BY sort_order",
[$s['id']]
);
}
$alerts = qall("SELECT * FROM alerts WHERE business_id=? AND is_active=1 ORDER BY created_at DESC", [$b['id']]);
$myrev = authed() ? qone("SELECT * FROM reviews WHERE business_id=? AND user_id=?", [$b['id'], uid()]) : null;
$hours = parseHours($b['hours']);
$isOwner = owns($b['id']);
$isNonAdminOwner = $isOwner && !isAdmin();
$cat = (string)($b['cat'] ?? 'Uncategorized');
$catIcon = (string)($b['cat_icon'] ?? '🏢');
$days = ['Mon','Tue','Wed','Thu','Fri','Sat','Sun'];
// Pending edit requests for this business (shown to owner)
$pendingEdits = ($isOwner && !isAdmin())
? qall("SELECT * FROM business_edit_requests WHERE business_id=? AND user_id=? AND status='pending' ORDER BY created_at DESC",
[$b['id'], uid()])
: [];
$pendingByField = [];
foreach ($pendingEdits as $pe) $pendingByField[$pe['field']] = $pe;
include __DIR__.'/includes/header.php';
?>
<div class="detail-hdr">
<div class="detail-hdr-inner">
<div class="breadcrumb">
<a href="/index.php">Home</a><span></span>
<a href="/directory.php">Directory</a><span></span>
<a href="/directory.php?cat=<?=urlencode($cat)?>"><?=e($catIcon.' '.$cat)?></a><span></span>
<?=e($b['name'])?>
</div>
<div class="cat-badge"><?=e($catIcon.' '.$cat)?><?= $b['subcategory'] ? ' · '.e($b['subcategory']) : '' ?></div>
<h1 style="font-size:clamp(1.9rem,4vw,2.9rem);margin:.4rem 0"><?=e($b['name'])?></h1>
<div class="flex-row" style="margin-top:.6rem;gap:.9rem">
<?=starDisplay((float)($b['avg'] ?? 0))?>
<span class="rat-score"><?=number_format((float)($b['avg'] ?? 0), 1)?></span>
<span class="rat-cnt">(<?=(int)($b['rcnt'] ?? 0)?> review<?=(int)($b['rcnt'] ?? 0) != 1 ? 's' : ''?>)</span>
<?php if ($b['is_featured']): ?><span class="featured-badge">★ FEATURED</span><?php endif; ?>
</div>
</div>
</div>
<div class="detail-body">
<div><!-- main col -->
<?php if ($alerts): ?>
<div style="margin-bottom:1.75rem">
<div class="eyebrow" style="margin-bottom:.6rem">📢 BUSINESS UPDATES</div>
<?php foreach ($alerts as $a): ?>
<div class="alert-item a-<?=e($a['type'] ?? 'info')?>">
<div class="alert-ico"><?=alertIcon($a['type'] ?? '')?></div>
<div style="flex:1">
<div class="alert-title"><?=e($a['title'] ?? '')?></div>
<div class="alert-body"><?=e($a['body'] ?? '')?></div>
<div class="alert-meta"><?=ago($a['created_at'] ?? '')?></div>
</div>
<?php if ($isOwner): ?>
<form method="POST" style="margin-left:.5rem">
<?=csrfField()?>
<input type="hidden" name="_act" value="del_alert">
<input type="hidden" name="aid" value="<?=(int)$a['id']?>">
<button class="btn btn-xs btn-danger" data-confirm="Delete this alert?">✕</button>
</form>
<?php endif; ?>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
<?php if ($isOwner): ?>
<div class="ibox" style="border-color:var(--gold-d);margin-bottom:1.75rem">
<div class="ibox-title">📢 POST BUSINESS ALERT</div>
<form method="POST">
<?=csrfField()?>
<input type="hidden" name="_act" value="post_alert">
<div class="form-row" style="margin-bottom:.7rem">
<input type="text" name="atitle" class="finput" placeholder="Alert title" required>
<select name="atype" 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>
<textarea name="abody" class="ftextarea" style="min-height:65px" placeholder="Alert details…" required></textarea>
<button type="submit" class="btn btn-primary btn-sm" style="margin-top:.65rem">Post Alert</button>
</form>
</div>
<?php endif; ?>
<!-- ── OWNER EDIT PANEL (non-admin owners only) ───────── -->
<?php if ($isNonAdminOwner): ?>
<div class="ibox" style="border:2px solid var(--navy-m);margin-bottom:1.75rem">
<div class="ibox-title" style="color:var(--text)">
✏️ SUGGEST LISTING CHANGES
<span style="font-family:'Source Sans 3',sans-serif;font-weight:400;font-size:.78rem;color:var(--text-m);letter-spacing:0;margin-left:.5rem">
— Changes require admin approval before going live
</span>
</div>
<?php if ($pendingEdits): ?>
<div style="background:rgba(201,168,76,.08);border:1px solid var(--gold-dim);border-radius:4px;padding:.85rem 1rem;margin-bottom:1.1rem;font-size:.84rem">
<strong style="color:var(--gold)">⏳ Pending review:</strong>
<span style="color:var(--text-m)">
<?= implode(', ', array_map(fn($pe) => '<strong>'.e(ucfirst($pe['field'])).'</strong>', $pendingEdits)) ?>
</span>
— an admin will review these changes shortly.
</div>
<?php endif; ?>
<form method="POST">
<?=csrfField()?>
<input type="hidden" name="_act" value="owner_edit">
<div class="fg">
<label class="flabel">
DESCRIPTION
<?php if (isset($pendingByField['description'])): ?>
<span class="badge badge-gold" style="margin-left:.4rem">PENDING</span>
<?php endif; ?>
</label>
<textarea name="description" class="ftextarea" style="min-height:90px"><?=e(isset($pendingByField['description']) ? $pendingByField['description']['new_value'] : $b['description'])?></textarea>
<?php if (isset($pendingByField['description'])): ?>
<div class="fhint" style="color:var(--amber)">Currently pending: "<?=e(substr($pendingByField['description']['new_value'],0,80))?><?= strlen($pendingByField['description']['new_value'])>80?'…':'' ?>"</div>
<?php endif; ?>
</div>
<div class="form-row">
<div class="fg">
<label class="flabel">
ADDRESS
<?php if (isset($pendingByField['address'])): ?><span class="badge badge-gold" style="margin-left:.4rem">PENDING</span><?php endif; ?>
</label>
<input type="text" name="address" class="finput"
value="<?=e(isset($pendingByField['address']) ? $pendingByField['address']['new_value'] : $b['address'])?>">
</div>
<div class="fg">
<label class="flabel">
PHONE
<?php if (isset($pendingByField['phone'])): ?><span class="badge badge-gold" style="margin-left:.4rem">PENDING</span><?php endif; ?>
</label>
<input type="text" name="phone" class="finput"
value="<?=e(isset($pendingByField['phone']) ? $pendingByField['phone']['new_value'] : $b['phone'])?>">
</div>
</div>
<div class="fg">
<label class="flabel">
EMAIL
<?php if (isset($pendingByField['email'])): ?><span class="badge badge-gold" style="margin-left:.4rem">PENDING</span><?php endif; ?>
</label>
<input type="email" name="email" class="finput"
value="<?=e(isset($pendingByField['email']) ? $pendingByField['email']['new_value'] : $b['email'])?>">
</div>
<div class="form-row">
<div class="fg">
<label class="flabel">
WEBSITE
<?php if (isset($pendingByField['website'])): ?><span class="badge badge-gold" style="margin-left:.4rem">PENDING</span><?php endif; ?>
</label>
<input type="text" name="website" class="finput"
value="<?=e(isset($pendingByField['website']) ? $pendingByField['website']['new_value'] : $b['website'])?>"
placeholder="example.com">
</div>
<div class="fg">
<label class="flabel">
VIDEO URL
<?php if (isset($pendingByField['video_url'])): ?><span class="badge badge-gold" style="margin-left:.4rem">PENDING</span><?php endif; ?>
</label>
<input type="url" name="video_url" class="finput"
value="<?=e(isset($pendingByField['video_url']) ? $pendingByField['video_url']['new_value'] : $b['video_url'])?>"
placeholder="YouTube or Vimeo URL">
<div class="fhint">Optional. Business owners may use YouTube or Vimeo.</div>
</div>
</div>
<div class="fg">
<label class="flabel">
HOURS OF OPERATION
<?php if (isset($pendingByField['hours'])): ?><span class="badge badge-gold" style="margin-left:.4rem">PENDING</span><?php endif; ?>
</label>
<?php
// Show pending hours if exists, else current
$editHours = isset($pendingByField['hours'])
? (parseHours($pendingByField['hours']['new_value']) ?: $hours)
: $hours;
?>
<div style="display:grid;grid-template-columns:repeat(auto-fill,minmax(210px,1fr));gap:.45rem;margin-top:.4rem">
<?php foreach ($days as $d): ?>
<div style="display:flex;gap:.4rem;align-items:center">
<span style="font-family:'Oswald',sans-serif;font-size:.72rem;color:var(--gold);width:30px;flex-shrink:0"><?=$d?></span>
<input type="text" name="hours_<?=$d?>" class="finput" style="font-size:.8rem;padding:.38rem .6rem"
value="<?=e($editHours[$d] ?? '')?>" placeholder="e.g. 9am5pm or Closed">
</div>
<?php endforeach; ?>
</div>
<div class="fhint">Leave blank to omit a day from the hours display.</div>
</div>
<div class="fg">
<label class="flabel">
LISTING STATUS
<?php if (isset($pendingByField['is_active'])): ?><span class="badge badge-gold" style="margin-left:.4rem">PENDING</span><?php endif; ?>
</label>
<?php $currentActive = isset($pendingByField['is_active']) ? (int)$pendingByField['is_active']['new_value'] : (int)$b['is_active']; ?>
<div class="flex-row" style="gap:1.5rem;margin-top:.35rem">
<label style="display:flex;align-items:center;gap:.4rem;cursor:pointer;font-size:.9rem">
<input type="radio" name="is_active" value="1"<?= $currentActive===1?' checked':''?>>
<span style="color:var(--green-l)">✅ Open / Active</span>
</label>
<label style="display:flex;align-items:center;gap:.4rem;cursor:pointer;font-size:.9rem">
<input type="radio" name="is_active" value="0"<?= $currentActive===0?' checked':''?>>
<span style="color:var(--text-d)">🔴 Temporarily Closed / Inactive</span>
</label>
</div>
<div class="fhint">Setting to Inactive will hide this listing from the public directory until an admin approves and it goes live.</div>
</div>
<button type="submit" class="btn btn-navy">Submit Changes for Review</button>
</form>
</div>
<?php endif; ?>
<!-- ── END OWNER EDIT PANEL ──────────────────────────── -->
<div class="ibox" style="margin-bottom:1.75rem">
<div class="ibox-title">ABOUT <?=strtoupper(e($b['name']))?></div>
<p style="color:var(--text-m);line-height:1.85"><?=e($b['description'] ?? '')?></p>
</div>
<?php if (!empty($b['video_url']) && validBusinessVideoUrl($b['video_url'])): ?>
<div class="ibox business-video-box" style="margin-bottom:1.75rem">
<div class="ibox-title">VIDEO FEATURE</div>
<div class="embed-shell">
<iframe
src="/lone-embed.php?video=<?=rawurlencode($b['video_url'])?>&amp;title=<?=rawurlencode($b['name'])?>"
title="<?=e($b['name'])?> video"
loading="lazy"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
allowfullscreen></iframe>
</div>
</div>
<?php endif; ?>
<?php if ($sects): ?>
<div class="ibox" style="margin-bottom:1.75rem">
<div class="ibox-title">🍽️ MENU</div>
<?php foreach ($sects as $s): ?>
<div class="menu-sec">
<div class="menu-sec-name"><?=e($s['name'] ?? '')?></div>
<?php if (!empty($s['description'])): ?>
<div class="menu-sec-desc"><?=e($s['description'])?></div>
<?php endif; ?>
<?php foreach ($mitems[$s['id']] as $mi): ?>
<div class="menu-item">
<?php if (!empty($mi['image_path'])): ?>
<img src="<?=e($mi['image_path'])?>" alt="<?=e($mi['name'] ?? 'Menu item')?>" class="mi-image">
<?php endif; ?>
<div class="mi-info">
<div class="mi-name"><?=e($mi['name'] ?? '')?></div>
<?php if (!empty($mi['description'])): ?>
<div class="mi-desc"><?=e($mi['description'])?></div>
<?php endif; ?>
</div>
<?php if ((float)($mi['price'] ?? 0) > 0): ?>
<div class="mi-price"><?=money((float)$mi['price'])?></div>
<?php endif; ?>
</div>
<?php endforeach; ?>
</div>
<?php endforeach; ?>
<?php if ($isOwner): ?>
<a href="/menu.php?id=<?=(int)$b['id']?>" class="btn btn-outline btn-sm">✏️ Manage Menu</a>
<?php endif; ?>
</div>
<?php elseif ($isOwner): ?>
<div style="margin-bottom:1.75rem">
<a href="/menu.php?id=<?=(int)$b['id']?>" class="btn btn-outline">+ Add Menu</a>
</div>
<?php endif; ?>
<h3 style="font-family:'Oswald',sans-serif;letter-spacing:.1em;font-size:1.05rem;color:var(--text);margin-bottom:1.1rem;padding-bottom:.6rem;border-bottom:1px solid var(--bdr)">
⭐ REVIEWS (<?=(int)($b['rcnt'] ?? 0)?>)
</h3>
<?php if (authed()): ?>
<div class="ibox" style="margin-bottom:1.5rem">
<div class="ibox-title"><?= $myrev ? 'UPDATE YOUR REVIEW' : 'WRITE A REVIEW' ?></div>
<form method="POST">
<?=csrfField()?>
<input type="hidden" name="_act" value="review">
<div class="fg">
<label class="flabel">YOUR RATING</label>
<?=starPicker('rating', (int)($myrev['rating'] ?? 0))?>
</div>
<div class="fg">
<label class="flabel">TITLE (optional)</label>
<input type="text" name="rtitle" class="finput"
value="<?=e($myrev['title'] ?? '')?>" placeholder="One-line summary…">
</div>
<div class="fg">
<label class="flabel">YOUR REVIEW</label>
<textarea name="rbody" class="ftextarea" placeholder="Share your experience…"><?=e($myrev['body'] ?? '')?></textarea>
</div>
<button type="submit" class="btn btn-primary btn-sm">Submit Review</button>
</form>
</div>
<?php else: ?>
<div style="background:var(--bg4);border:1px solid var(--bdr);border-radius:6px;padding:1.1rem;text-align:center;margin-bottom:1.4rem">
<a href="/login.php" class="btn btn-outline btn-sm">Login to Write a Review</a>
</div>
<?php endif; ?>
<?php foreach ($reviews as $r): ?>
<div class="rev-card">
<div class="rev-hdr">
<div class="rev-user">
<div>
<div class="rev-author"><?=e($r['username'] ?? 'Anonymous')?></div>
<?=starDisplay((float)($r['rating'] ?? 0))?>
</div>
</div>
<div class="flex-row" style="gap:.5rem">
<span class="rev-date"><?=ago($r['created_at'] ?? '')?></span>
<?php if (isAdmin()): ?>
<form method="POST">
<?=csrfField()?>
<input type="hidden" name="_act" value="del_review">
<input type="hidden" name="rid" value="<?=(int)$r['id']?>">
<button class="btn btn-xs btn-danger" data-confirm="Delete this review?">Delete</button>
</form>
<?php endif; ?>
</div>
</div>
<?php if (!empty($r['title'])): ?><div class="rev-title"><?=e($r['title'])?></div><?php endif; ?>
<?php if (!empty($r['body'])): ?><div class="rev-body"><?=e($r['body'])?></div><?php endif; ?>
</div>
<?php endforeach; ?>
<?php if (!$reviews): ?>
<p style="color:var(--text-d);font-size:.88rem">No reviews yet — be the first!</p>
<?php endif; ?>
<hr class="divider">
<?php if (authed()): ?>
<details>
<summary style="cursor:pointer;font-size:.82rem;color:var(--text-d);font-family:'Oswald',sans-serif;letter-spacing:.06em">
🚩 REPORT A LISTING ISSUE
</summary>
<div class="ibox" style="margin-top:.75rem">
<form method="POST">
<?=csrfField()?>
<input type="hidden" name="_act" value="report">
<div class="fg">
<label class="flabel">ISSUE TYPE</label>
<select name="rtype" class="fselect">
<option value="correction">Incorrect Information</option>
<option value="closed">Business Closed / Moved</option>
<option value="hours">Wrong Hours</option>
<option value="phone">Wrong Phone Number</option>
<option value="other">Other Issue</option>
</select>
</div>
<div class="fg">
<label class="flabel">DESCRIBE THE ISSUE</label>
<textarea name="rmsg" class="ftextarea" style="min-height:75px" required
placeholder="Please describe what needs correction…"></textarea>
</div>
<button type="submit" class="btn btn-secondary btn-sm">Submit Report</button>
</form>
</div>
</details>
<?php else: ?>
<p style="font-size:.82rem;color:var(--text-d)">
🚩 <a href="/login.php">Log in</a> to report a listing issue.
</p>
<?php endif; ?>
</div><!-- /main col -->
<div><!-- sidebar -->
<div class="ibox">
<div class="ibox-title">BUSINESS INFO</div>
<?php if (!empty($b['address'])): ?>
<div class="irow"><span class="irow-i">📍</span><span class="irow-v"><?=e($b['address'])?></span></div>
<?php endif; ?>
<?php if (!empty($b['phone'])): ?>
<div class="irow"><span class="irow-i">📞</span>
<a href="tel:<?=e($b['phone'])?>" class="irow-v" style="color:var(--gold)"><?=e($b['phone'])?></a>
</div>
<?php endif; ?>
<?php if (!empty($b['email'])): ?>
<div class="irow"><span class="irow-i">✉️</span>
<a href="mailto:<?=e($b['email'])?>" class="irow-v" style="color:var(--gold)"><?=e($b['email'])?></a>
</div>
<?php endif; ?>
<?php if (!empty($b['website'])): ?>
<div class="irow"><span class="irow-i">🌐</span>
<a href="https://<?=e($b['website'])?>" target="_blank" rel="noopener"
class="irow-v" style="color:var(--gold);word-break:break-all"><?=e($b['website'])?> ↗</a>
</div>
<?php endif; ?>
<div class="irow">
<span class="irow-i">🏷️</span>
<span class="irow-v"><?=e($cat)?><?= !empty($b['subcategory']) ? ' · '.e($b['subcategory']) : '' ?></span>
</div>
</div>
<?php if ($hours): ?>
<div class="ibox">
<div class="ibox-title">🕐 HOURS OF OPERATION</div>
<div class="hrs-grid">
<?php foreach ($hours as $day => $time): ?>
<div class="hrs-row">
<span class="hrs-day"><?=strtoupper(substr(e((string)$day), 0, 3))?></span>
<span class="hrs-time"><?=e((string)$time)?></span>
</div>
<?php endforeach; ?>
</div>
</div>
<?php endif; ?>
<?php if (!empty($b['address'])): ?>
<div class="ibox">
<div class="ibox-title">📍 LOCATION</div>
<div style="background:var(--bg4);border:1px dashed var(--bdr);border-radius:4px;padding:1.75rem;text-align:center">
<p style="font-size:.84rem;color:var(--text-m);margin-bottom:.75rem"><?=e($b['address'])?></p>
<a href="https://maps.google.com/?q=<?=urlencode($b['name'].' '.$b['address'])?>"
target="_blank" rel="noopener" class="btn btn-outline btn-sm">Open in Google Maps ↗</a>
</div>
</div>
<?php endif; ?>
<?php if ($isOwner): ?>
<div class="ibox" style="border-color:var(--gold-d)">
<div class="ibox-title">⚙️ OWNER CONTROLS</div>
<a href="/menu.php?id=<?=(int)$b['id']?>" class="btn btn-outline btn-sm btn-block"
style="margin-bottom:.5rem">🍽️ Manage Menu</a>
<?php if (isAdmin()): ?>
<a href="/admin/biz_edit.php?id=<?=(int)$b['id']?>" class="btn btn-secondary btn-sm btn-block"
style="margin-bottom:.5rem">✏️ Edit Listing (Admin)</a>
<a href="/admin/biz_edits.php?biz_id=<?=(int)$b['id']?>" class="btn btn-secondary btn-sm btn-block">
📋 Review Owner Edits
</a>
<?php else: ?>
<?php
$pendingCount = (int)qval(
"SELECT COUNT(*) FROM business_edit_requests WHERE business_id=? AND status='pending'",
[$b['id']]
);
?>
<?php if ($pendingCount): ?>
<div style="text-align:center;font-size:.82rem;color:var(--amber);margin-top:.25rem">
⏳ <?=$pendingCount?> change<?=$pendingCount>1?'s':''?> awaiting admin review
</div>
<?php endif; ?>
<?php endif; ?>
</div>
<?php endif; ?>
</div><!-- /sidebar -->
</div><!-- /detail-body -->
<?php include __DIR__.'/includes/footer.php'; ?>