- initial
This commit is contained in:
@@ -0,0 +1,254 @@
|
||||
<?php
|
||||
/**
|
||||
* Dedicated Business Editor — standalone, no dependency on businesses.php
|
||||
* URL: /admin/biz_edit.php?id=N
|
||||
*/
|
||||
$adminTitle = 'Direct Business Editor';
|
||||
include __DIR__.'/admin_header.php';
|
||||
|
||||
$id = iget('id');
|
||||
$msg = '';
|
||||
$err = '';
|
||||
|
||||
// ── Handle save ──────────────────────────────────────────
|
||||
if (isPost() && p('_act') === 'save') {
|
||||
csrfCheck();
|
||||
$id = (int)p('id');
|
||||
|
||||
if (!$id) { $err = 'No business ID provided.'; goto render; }
|
||||
|
||||
$name = ps('name');
|
||||
if (!$name) { $err = 'Business name is required.'; goto render; }
|
||||
|
||||
// Slug: use submitted or regenerate, ensure unique excluding self
|
||||
$baseSlug = ps('slug') ?: makeSlug($name);
|
||||
$slug = $baseSlug;
|
||||
$i = 0;
|
||||
while (true) {
|
||||
$candidate = $baseSlug . ($i ? "-$i" : '');
|
||||
$clash = qval("SELECT id FROM businesses WHERE slug=? AND id!=?", [$candidate, $id]);
|
||||
if (!$clash) { $slug = $candidate; break; }
|
||||
$i++;
|
||||
}
|
||||
|
||||
// Hours
|
||||
$days = ['Mon','Tue','Wed','Thu','Fri','Sat','Sun'];
|
||||
$hrs = [];
|
||||
foreach ($days as $d) {
|
||||
$v = ps("h_$d");
|
||||
if ($v !== '') $hrs[$d] = $v;
|
||||
}
|
||||
|
||||
// Run individual named UPDATEs so a failure on one field is visible
|
||||
$updates = [
|
||||
'name' => ps('name'),
|
||||
'slug' => $slug,
|
||||
'category_id' => (int)p('category_id'),
|
||||
'subcategory' => ps('subcategory'),
|
||||
'description' => ps('description'),
|
||||
'address' => ps('address'),
|
||||
'phone' => ps('phone'),
|
||||
'email' => ps('email'),
|
||||
'website' => ps('website'),
|
||||
'hours' => json_encode($hrs),
|
||||
'lat' => (float)p('lat', 39.4364),
|
||||
'lng' => (float)p('lng', -78.9762),
|
||||
'is_active' => (int)p('is_active', 1),
|
||||
'is_featured' => (int)p('is_featured', 0),
|
||||
];
|
||||
|
||||
try {
|
||||
$setClauses = implode(', ', array_map(fn($k) => "$k=?", array_keys($updates)));
|
||||
$sql = "UPDATE businesses SET $setClauses WHERE id=?";
|
||||
$params = array_merge(array_values($updates), [$id]);
|
||||
$stmt = db()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$affected = $stmt->rowCount();
|
||||
$msg = "Saved successfully ($affected row updated). SQL: $sql";
|
||||
} catch (\Throwable $ex) {
|
||||
$err = 'DB ERROR: '.$ex->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
render:
|
||||
|
||||
// ── Load business ────────────────────────────────────────
|
||||
$biz = $id ? qone("SELECT * FROM businesses WHERE id=?", [$id]) : null;
|
||||
$cats = qall("SELECT * FROM categories ORDER BY sort_order");
|
||||
$days = ['Mon','Tue','Wed','Thu','Fri','Sat','Sun'];
|
||||
$h = $biz ? parseHours($biz['hours']) : [];
|
||||
|
||||
// All businesses for the picker
|
||||
$all = qall("SELECT id, name FROM businesses ORDER BY name");
|
||||
?>
|
||||
|
||||
<?php adminTitle('Direct Business Editor', 'Standalone editor — bypasses the main businesses page entirely.') ?>
|
||||
|
||||
<!-- Business picker -->
|
||||
<div class="ibox" style="margin-bottom:1.5rem;max-width:500px">
|
||||
<div class="ibox-title">SELECT BUSINESS TO EDIT</div>
|
||||
<form method="GET" action="/admin/biz_edit.php" style="display:flex;gap:.6rem">
|
||||
<select name="id" class="fselect" style="flex:1">
|
||||
<option value="">-- choose --</option>
|
||||
<?php foreach ($all as $b): ?>
|
||||
<option value="<?=$b['id']?>"<?= $id === $b['id'] ? ' selected' : '' ?>><?=e($b['name'])?> (ID <?=$b['id']?>)</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
<button type="submit" class="btn btn-primary btn-sm">Load</button>
|
||||
</form>
|
||||
<?php if ($all): ?>
|
||||
<p style="font-size:.78rem;color:var(--text-d);margin-top:.5rem">Or go directly: /admin/biz_edit.php?id=N</p>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<!-- Status messages -->
|
||||
<?php if ($msg): ?>
|
||||
<div style="background:rgba(42,122,71,.25);border:1px solid var(--green-l);color:#86e8a8;padding:.85rem 1.1rem;border-radius:6px;margin-bottom:1rem;font-size:.88rem;font-family:monospace;white-space:pre-wrap;word-break:break-all"><?=e($msg)?></div>
|
||||
<?php endif; ?>
|
||||
<?php if ($err): ?>
|
||||
<div style="background:rgba(143,45,45,.3);border:1px solid var(--red-l);color:#ff9a9a;padding:.85rem 1.1rem;border-radius:6px;margin-bottom:1rem;font-size:.88rem;font-family:monospace;white-space:pre-wrap;word-break:break-all"><?=e($err)?></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($biz): ?>
|
||||
<!-- ── Edit form ─────────────────────────────────────────── -->
|
||||
<div class="ibox" style="border-color:var(--gold-d)">
|
||||
<div class="ibox-title">EDITING: <?=e($biz['name'])?> <span style="font-weight:400;color:var(--text-d)">(ID <?=$biz['id']?>)</span></div>
|
||||
|
||||
<form method="POST" action="/admin/biz_edit.php?id=<?=$biz['id']?>">
|
||||
<?=csrfField()?>
|
||||
<input type="hidden" name="_act" value="save">
|
||||
<input type="hidden" name="id" value="<?=$biz['id']?>">
|
||||
|
||||
<!-- Name & Slug -->
|
||||
<div class="form-row">
|
||||
<div class="fg">
|
||||
<label class="flabel">NAME *</label>
|
||||
<input type="text" name="name" class="finput" value="<?=e($biz['name'])?>" required>
|
||||
</div>
|
||||
<div class="fg">
|
||||
<label class="flabel">SLUG</label>
|
||||
<input type="text" name="slug" class="finput" value="<?=e($biz['slug'])?>">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Category & Subcategory -->
|
||||
<div class="form-row">
|
||||
<div class="fg">
|
||||
<label class="flabel">CATEGORY</label>
|
||||
<select name="category_id" class="fselect">
|
||||
<?php foreach ($cats as $c): ?>
|
||||
<option value="<?=$c['id']?>"<?= (int)$biz['category_id'] === (int)$c['id'] ? ' selected' : '' ?>><?=e($c['icon'].' '.$c['name'])?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="fg">
|
||||
<label class="flabel">SUBCATEGORY</label>
|
||||
<input type="text" name="subcategory" class="finput" value="<?=e($biz['subcategory'])?>">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Description -->
|
||||
<div class="fg">
|
||||
<label class="flabel">DESCRIPTION</label>
|
||||
<textarea name="description" class="ftextarea" style="min-height:100px"><?=e($biz['description'])?></textarea>
|
||||
</div>
|
||||
|
||||
<!-- Address & Phone -->
|
||||
<div class="form-row">
|
||||
<div class="fg">
|
||||
<label class="flabel">ADDRESS</label>
|
||||
<input type="text" name="address" class="finput" value="<?=e($biz['address'])?>">
|
||||
</div>
|
||||
<div class="fg">
|
||||
<label class="flabel">PHONE</label>
|
||||
<input type="text" name="phone" class="finput" value="<?=e($biz['phone'])?>">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Email & Website -->
|
||||
<div class="form-row">
|
||||
<div class="fg">
|
||||
<label class="flabel">EMAIL</label>
|
||||
<input type="email" name="email" class="finput" value="<?=e($biz['email'])?>">
|
||||
</div>
|
||||
<div class="fg">
|
||||
<label class="flabel">WEBSITE (no https://)</label>
|
||||
<input type="text" name="website" class="finput" value="<?=e($biz['website'])?>">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Lat & Lng -->
|
||||
<div class="form-row">
|
||||
<div class="fg">
|
||||
<label class="flabel">LATITUDE</label>
|
||||
<input type="number" name="lat" class="finput" value="<?=e($biz['lat'])?>" step="0.0001">
|
||||
</div>
|
||||
<div class="fg">
|
||||
<label class="flabel">LONGITUDE</label>
|
||||
<input type="number" name="lng" class="finput" value="<?=e($biz['lng'])?>" step="0.0001">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Hours -->
|
||||
<div style="margin-bottom:1rem">
|
||||
<label class="flabel" style="margin-bottom:.6rem">HOURS OF OPERATION</label>
|
||||
<div style="display:grid;grid-template-columns:repeat(auto-fill,minmax(210px,1fr));gap:.45rem">
|
||||
<?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="h_<?=$d?>" class="finput" style="font-size:.8rem;padding:.38rem .6rem"
|
||||
value="<?=e($h[$d] ?? '')?>" placeholder="e.g. 9am-5pm">
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Status & Featured -->
|
||||
<div class="form-row" style="margin-bottom:.85rem">
|
||||
<div class="fg">
|
||||
<label class="flabel">STATUS</label>
|
||||
<select name="is_active" class="fselect">
|
||||
<option value="1"<?= $biz['is_active'] == 1 ? ' selected' : '' ?>>Active (visible)</option>
|
||||
<option value="0"<?= $biz['is_active'] == 0 ? ' selected' : '' ?>>Inactive (hidden)</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="fg">
|
||||
<label class="flabel">FEATURED</label>
|
||||
<select name="is_featured" class="fselect">
|
||||
<option value="0"<?= $biz['is_featured'] == 0 ? ' selected' : '' ?>>Not Featured</option>
|
||||
<option value="1"<?= $biz['is_featured'] == 1 ? ' selected' : '' ?>>Featured</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex-row">
|
||||
<button type="submit" class="btn btn-primary">Save Business</button>
|
||||
<a href="/business.php?slug=<?=e($biz['slug'])?>" target="_blank" class="btn btn-outline btn-sm">View Listing</a>
|
||||
<a href="/admin/biz_edit.php" class="btn btn-secondary btn-sm">Pick Different</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<!-- Raw data panel -->
|
||||
<details style="margin-top:1rem">
|
||||
<summary style="cursor:pointer;font-size:.82rem;color:var(--text-d);font-family:'Oswald',sans-serif;letter-spacing:.08em">🔍 RAW DATABASE VALUES FOR THIS ROW</summary>
|
||||
<div style="background:var(--bg0);border:1px solid var(--bdr);border-radius:6px;padding:1rem;margin-top:.6rem;font-family:monospace;font-size:.78rem;color:var(--text-m)">
|
||||
<?php foreach ($biz as $col => $val): ?>
|
||||
<div style="display:flex;gap:.75rem;padding:.22rem 0;border-bottom:1px solid rgba(255,255,255,.04)">
|
||||
<span style="color:var(--gold);width:120px;flex-shrink:0"><?=e($col)?></span>
|
||||
<span style="word-break:break-all"><?=e(strlen((string)$val) > 200 ? substr($val,0,200).'...' : $val)?></span>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</details>
|
||||
|
||||
<?php elseif ($id): ?>
|
||||
<div class="err-box">No business found with ID <?=(int)$id?>.</div>
|
||||
<?php else: ?>
|
||||
<div class="empty" style="padding:2rem">
|
||||
<div class="empty-ico">🏢</div>
|
||||
<h3>Select a business above to begin editing</h3>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php include __DIR__.'/admin_footer.php'; ?>
|
||||
Reference in New Issue
Block a user