- initial

This commit is contained in:
Ty Clifford
2026-04-24 08:41:52 -04:00
commit b57091e4ad
49 changed files with 7371 additions and 0 deletions
+148
View File
@@ -0,0 +1,148 @@
<?php
require_once __DIR__.'/includes/boot.php';
$activeNav='dir';
$q = gs('q');
$cat = gs('cat');
$page = max(1, iget('page'));
$perPage = 18;
$where = "WHERE b.is_active=1";
$params = [];
if ($q) {
$where .= " AND (b.name LIKE ? OR b.description LIKE ? OR b.subcategory LIKE ? OR b.address LIKE ?)";
$lk = "%$q%";
$params = [$lk, $lk, $lk, $lk];
}
if ($cat) {
$where .= " AND c.name=?";
$params[] = $cat;
}
$total = (int)qval("SELECT COUNT(*) FROM businesses b LEFT JOIN categories c ON c.id=b.category_id $where", $params);
$pages = max(1, (int)ceil($total / $perPage));
$page = min($page, $pages);
$offset = ($page - 1) * $perPage;
$bizs = qall("
SELECT b.*,
COALESCE(c.name,'Uncategorized') AS cat,
COALESCE(c.icon,'🏢') AS cat_icon,
COALESCE(AVG(r.rating),0) AS avg,
COUNT(r.id) 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 AND r.is_approved = 1
$where
GROUP BY b.id
ORDER BY b.is_featured DESC, b.name ASC
LIMIT $perPage OFFSET $offset
", $params);
$cats = qall("SELECT DISTINCT c.name, c.icon FROM categories c
JOIN businesses b ON b.category_id = c.id
WHERE b.is_active = 1
ORDER BY c.sort_order");
$pageTitle = 'Business Directory — Keyser, WV';
include __DIR__.'/includes/header.php';
?>
<div class="page-hdr">
<div class="page-hdr-inner">
<div class="eyebrow">EXPLORE KEYSER</div>
<h1 style="font-size:clamp(2rem,4vw,2.9rem);margin-bottom:.4rem">Business Directory</h1>
<p style="color:var(--text-m)">Discover <?=$total?> local businesses, restaurants, services, and more in Keyser, West Virginia.</p>
</div>
</div>
<div class="search-bar">
<div class="search-bar-inner">
<form method="GET" class="search-form">
<div class="search-wrap">
<span class="s-icon">🔍</span>
<input class="search-input" type="text" name="q" value="<?=e($q)?>" placeholder="Search businesses…">
</div>
<select name="cat" class="finput" style="flex:0 0 auto;width:auto;padding:.72rem 1rem">
<option value="">All Categories</option>
<?php foreach ($cats as $c): ?>
<option value="<?=e($c['name'])?>"<?= $c['name']===$cat ? ' selected' : '' ?>><?=e($c['icon'].' '.$c['name'])?></option>
<?php endforeach; ?>
</select>
<button type="submit" class="btn btn-primary">Search</button>
<?php if ($q || $cat): ?><a href="/directory.php" class="btn btn-secondary">Clear</a><?php endif; ?>
</form>
<?php if ($q || $cat): ?>
<p style="margin-top:.65rem;font-size:.84rem;color:var(--text-m)">
Found <strong style="color:var(--gold)"><?=$total?></strong> result<?=$total!==1?'s':''?>
<?php if ($q): ?> for "<em><?=e($q)?></em>"<?php endif; ?>
<?php if ($cat): ?> in <em><?=e($cat)?></em><?php endif; ?>
</p>
<?php endif; ?>
</div>
</div>
<div class="filter-bar">
<div class="filter-bar-inner">
<a href="/directory.php<?= $q ? '?q='.urlencode($q) : '' ?>" class="btn btn-xs<?= !$cat ? ' btn-primary' : ' btn-outline' ?>">All</a>
<?php foreach ($cats as $c): ?>
<a href="/directory.php?cat=<?=urlencode($c['name'])?><?= $q ? '&q='.urlencode($q) : '' ?>"
class="btn btn-xs<?= $c['name']===$cat ? ' btn-primary' : ' btn-outline' ?>"><?=e($c['icon'].' '.$c['name'])?></a>
<?php endforeach; ?>
</div>
</div>
<div class="section">
<?php if ($bizs): ?>
<div class="g3">
<?php foreach ($bizs as $b): ?>
<a href="/business.php?slug=<?=e($b['slug'])?>" style="text-decoration:none">
<div class="biz-card">
<div class="biz-card-top">
<div class="cat-badge"><?=e($b['cat_icon'].' '.$b['cat'])?></div>
<?php if ($b['is_featured']): ?><span class="featured-badge" style="float:right">★</span><?php endif; ?>
<div class="biz-name"><?=e($b['name'])?></div>
<?php if ($b['subcategory']): ?><div class="biz-sub"><?=e($b['subcategory'])?></div><?php endif; ?>
</div>
<div class="biz-card-body">
<div class="biz-desc"><?=e($b['description'])?></div>
<div class="biz-meta">
<?php if ($b['address']): ?>
<div class="biz-meta-row"><span class="biz-meta-icon">📍</span><?=e($b['address'])?></div>
<?php endif; ?>
<?php if ($b['phone']): ?>
<div class="biz-meta-row"><span class="biz-meta-icon">📞</span><?=e($b['phone'])?></div>
<?php endif; ?>
</div>
</div>
<div class="biz-card-foot">
<div class="flex-row" style="gap:.4rem">
<?=starDisplay((float)$b['avg'])?>
<span class="rat-score"><?=number_format((float)$b['avg'],1)?></span>
<span class="rat-cnt">(<?=$b['rcnt']?> review<?=$b['rcnt']!=1?'s':''?>)</span>
</div>
<span style="color:var(--gold);font-size:.76rem;font-family:'Oswald',sans-serif">VIEW →</span>
</div>
</div>
</a>
<?php endforeach; ?>
</div>
<?php if ($pages > 1): ?>
<div style="display:flex;justify-content:center;gap:.5rem;margin-top:2.5rem;flex-wrap:wrap">
<?php for ($i = 1; $i <= $pages; $i++): ?>
<a href="?<?=http_build_query(array_filter(['q'=>$q,'cat'=>$cat,'page'=>$i]))?>"
class="btn btn-sm<?= $i===$page ? ' btn-primary' : ' btn-outline' ?>"><?=$i?></a>
<?php endfor; ?>
</div>
<?php endif; ?>
<?php else: ?>
<div class="empty">
<div class="empty-ico">🔍</div>
<h3>No results found</h3>
<p style="margin-top:.5rem">Try different search terms or browse all categories.</p>
<a href="/directory.php" class="btn btn-outline" style="margin-top:1.5rem">Browse All</a>
</div>
<?php endif; ?>
</div>
<?php include __DIR__.'/includes/footer.php'; ?>