Siteβ―Builder
Editing:
editbu.php
writable 0666
<script src="/ai-business-research/admin-protect.js"></script> <?php // ---- ADMIN PROTECTION (add your one-liner here) ---- // include $_SERVER['DOCUMENT_ROOT'] . '/admin-protect.php'; // example // ----------------------- MAIN LOGIC ----------------------- $ph = preg_replace('/[^\d]/','',$_GET['ph'] ?? ''); $phDir = $_SERVER['DOCUMENT_ROOT'] . '/ph/' . $ph; $newfile = $phDir . '/new-business.json'; $bizfile = $phDir . '/business.json'; $msg = ''; $fields = [ 'name' => '', 'slogan' => '', 'description' => '', 'address' => '', 'city' => '', 'state' => '', 'zip' => '', 'phone' => $ph, 'website' => '', 'tags' => [], 'location_tags' => [], 'lat'=>'', 'lon'=>'' ]; // Detect which file is in use for editing $curFile = ''; if (is_readable($bizfile)) { $curFile = $bizfile; $fileType = 'business.json'; } elseif (is_readable($newfile)) { $curFile = $newfile; $fileType = 'new-business.json'; } else { $fileType = ''; } if ($curFile) { $data = json_decode(file_get_contents($curFile), true); if (is_array($data)) { foreach ($fields as $k => $v) $fields[$k] = $data[$k] ?? $v; } } // ----- Handle POST (Save changes) if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['edit_save'])) { foreach ($fields as $k => $v) { if ($k === 'tags' || $k === 'location_tags') { $fields[$k] = array_filter(array_map('trim', explode(',', $_POST[$k] ?? ''))); } else { $fields[$k] = trim($_POST[$k] ?? ''); } } $saveFile = $_POST['activefile'] === 'business.json' ? $bizfile : $newfile; file_put_contents($saveFile, json_encode($fields, JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE)); $msg = "β Changes saved to <b>{$_POST['activefile']}</b>!"; $curFile = $saveFile; // reload this file $fileType = $_POST['activefile']; } // ----- Handle COPY (new-business.json β business.json) if (isset($_POST['make_paid'])) { if (is_readable($newfile)) { copy($newfile, $bizfile); $msg = "β Copied new-business.json to business.json (upgraded to paid)"; $fileType = 'business.json'; $curFile = $bizfile; } else { $msg = "β Cannot copy: new-business.json does not exist"; } } // ----- Handle Delete (delete file) if (isset($_POST['deletefile']) && in_array($_POST['deletefile'], ['new-business.json','business.json'])) { $f = $_POST['deletefile'] === 'business.json' ? $bizfile : $newfile; if (is_file($f)) { unlink($f); $msg = "β Deleted <b>{$_POST['deletefile']}</b>"; if ($_POST['deletefile'] === $fileType) { $fileType = ''; $curFile = ''; } } // reload default fields if all deleted if (!is_readable($bizfile) && !is_readable($newfile)) { foreach ($fields as $k => $v) $fields[$k] = ''; $fields['phone'] = $ph; } } // Get current JSON for textarea $curJson = $curFile && is_readable($curFile) ? file_get_contents($curFile) : ''; function h($s) { return htmlspecialchars($s, ENT_QUOTES, 'UTF-8'); } function tags_csv($a) { return is_array($a) ? implode(', ', $a) : $a; } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Edit Business: <?= h($ph) ?> | BestDealOn Admin</title> <meta name="viewport" content="width=device-width,initial-scale=1"> <style> body {background:#f6f8fb;font-family:system-ui,Arial,sans-serif;margin:0;color:#234;} .wrap {max-width:650px;margin:2.5em auto 2em;background:#fff;padding:2em 2em 2em 2em;border-radius:17px;box-shadow:0 2px 18px #dde3fa33;} h1 {text-align:center;font-size:1.42em;margin-bottom:.55em;} fieldset {margin:1.6em 0 1.2em 0;padding:1.2em 1em 1em 1em;border-radius:12px;border:1.5px solid #c9d8ec;background:#f7faff;} legend {font-size:1.14em;font-weight:700;color:#306fd4;} label {font-weight:600;display:block;margin-top:.7em;} input[type=text],input[type=tel],textarea {width:100%;padding:.7em;border-radius:7px;border:1.4px solid #b7c2df;margin-bottom:.15em;font-size:1.08em;} input[readonly], textarea[readonly] {background:#e6eaf2;} input[type=submit],button {padding:.64em 1.4em;font-size:1.08em;font-weight:700;background:#2357d7;color:#fff;border:none;border-radius:8px;cursor:pointer;transition:background .16s;} input[type=submit]:hover:enabled, button:hover:enabled {background:#0a3798;} input[type=submit]:disabled, button:disabled { background: #8ba0c5 !important; color: #dbe7fa !important; cursor: not-allowed !important; opacity: .72; } .flex {display:flex;gap:1.2em;} .flex > div {flex:1;} .inlinebtns {display:flex;gap:.9em;margin-top:1em;} .msg {text-align:center;margin-bottom:1.3em;font-size:1.06em;} .tiny {font-size:.99em;color:#557;} hr {margin:2.1em 0 1.5em 0;} @media (max-width:700px){.wrap{padding:1em .2em 1em .2em;max-width:98vw;}} </style> </head> <body> <div class="wrap"> <h1>Edit Business: <?= h($fields['name'] ?: $ph) ?> (<?= h($ph) ?>)</h1> <?php if($msg): ?><div class="msg" style="color:<?=strpos($msg,'β ')!==false?'green':'red'?>"><?= $msg ?></div><?php endif; ?> <?php if ($curFile): ?> <form method="post"> <fieldset> <legend>Edit Fields (<?= h($fileType) ?>)</legend> <input type="hidden" name="activefile" value="<?= h($fileType) ?>"> <label>Business Name</label> <input type="text" name="name" maxlength="80" value="<?= h($fields['name']) ?>" required> <label>Slogan</label> <input type="text" name="slogan" maxlength="120" value="<?= h($fields['slogan']) ?>"> <label>Description</label> <textarea name="description" maxlength="500" required><?= h($fields['description']) ?></textarea> <label>Address</label> <input type="text" name="address" maxlength="120" value="<?= h($fields['address']) ?>" required> <div class="flex"> <div> <label>City</label> <input type="text" name="city" maxlength="40" value="<?= h($fields['city']) ?>" required> </div> <div> <label>State</label> <input type="text" name="state" maxlength="2" value="<?= h($fields['state']) ?>" required> </div> <div> <label>ZIP</label> <input type="text" name="zip" maxlength="12" value="<?= h($fields['zip']) ?>" required> </div> </div> <div class="flex"> <div> <label>Phone</label> <input type="tel" name="phone" maxlength="14" value="<?= h($fields['phone']) ?>" required readonly> </div> <div> <label>Website</label> <input type="text" name="website" maxlength="120" value="<?= h($fields['website']) ?>"> </div> </div> <label>Tags (comma separated)</label> <input type="text" name="tags" value="<?= h(tags_csv($fields['tags'])) ?>" maxlength="200" placeholder="e.g. Pizza, Delivery, Family"> <label>Location Tags (comma separated)</label> <input type="text" name="location_tags" value="<?= h(tags_csv($fields['location_tags'])) ?>" maxlength="200"> <div class="flex"> <div> <label>Latitude</label> <input type="text" name="lat" maxlength="24" value="<?= h($fields['lat']) ?>"> </div> <div> <label>Longitude</label> <input type="text" name="lon" maxlength="24" value="<?= h($fields['lon']) ?>"> </div> </div> <div class="inlinebtns"> <input type="submit" name="edit_save" value="Save Changes"> <?php if ($fileType === 'new-business.json' && is_file($newfile)): ?> <button type="submit" name="make_paid" value="1" title="Copy new-business.json to business.json">Upgrade to Paid</button> <?php endif; ?> <button type="submit" name="deletefile" value="<?= h($fileType) ?>" onclick="return confirm('Delete <?= h($fileType) ?>? This cannot be undone.');" style="background:#c41c1c;color:#fff;">Delete <?= h($fileType) ?></button> </div> <div class="tiny"> <b>Status:</b> <?= is_file($bizfile) ? "business.json <span style='color:green;'>(PAID)</span>" : "<span style='color:#b49d3c;'>Not Paid</span>" ?> <?php if (is_file($newfile) && $fileType!=='new-business.json'): ?> | <button type="submit" name="deletefile" value="new-business.json" onclick="return confirm('Delete new-business.json?');" style="background:#d89a13;color:#fff;font-size:.97em;padding:.4em 1em;">Delete new-business.json</button> <?php endif; ?> </div> </fieldset> </form> <hr> <fieldset> <legend>Raw <?= h($fileType) ?> JSON</legend> <textarea readonly style="width:100%;min-height:120px;font-family:monospace;font-size:.98em;background:#f6fafd;border-radius:8px;padding:.7em 1em;"><?= h($curJson) ?></textarea> </fieldset> <?php else: ?> <div class="msg" style="color:#d7262d;">No business found for phone <?= h($ph) ?>.</div> <?php endif; ?> </div> </body> </html>
Save changes
Create folder
writable 0777
Create
Cancel