Site Builder
Editing:
update.php
writable 0666
<?php require_once rtrim($_SERVER['DOCUMENT_ROOT'], '/') . '/members/lib/auth.php'; require_login(); if (current_user()['role'] !== 'admin') forbidden_page(); // UI and admin script for copying geo templates (simplified progress) // Adjust $root to the path where your geo folders start: $root = dirname(__DIR__) . '/USA'; // e.g., "/home/onlinemortgage/public_html/geo/USA" // Enable error reporting for debugging ini_set('display_errors', 1); error_reporting(E_ALL); // Templates source: $pages = __DIR__; $cityIndexSrc = "$pages/city-index.php"; $stateIndexSrc = "$pages/state-index.php"; $bizSrc = "$pages/business.php"; $jsonTemplate = "$pages/city-name-biz-list.json"; // Gather all tasks for progress calculation $states = glob("$root/*", GLOB_ONLYDIR) ?: []; $totalTasks = count($states); foreach ($states as $stateFolder) { $cities = glob("$stateFolder/*", GLOB_ONLYDIR) ?: []; $totalTasks += count($cities) * 3; } if (isset($_GET['action']) && $_GET['action'] === 'run') { header('Content-Type: text/event-stream'); header('Cache-Control: no-cache'); @ini_set('output_buffering', 'off'); @ini_set('zlib.output_compression', 0); echo "\n\n"; flush(); $taskCount = 0; foreach ($states as $stateFolder) { // state index if (file_exists($stateIndexSrc)) { copy($stateIndexSrc, "$stateFolder/index.php"); $taskCount++; echo "data: $taskCount\n\n"; flush(); } // city-level files $cities = glob("$stateFolder/*", GLOB_ONLYDIR) ?: []; foreach ($cities as $cityFolder) { // city index copy($cityIndexSrc, "$cityFolder/index.php"); $taskCount++; echo "data: $taskCount\n\n"; flush(); // business.php copy($bizSrc, "$cityFolder/business.php"); $taskCount++; echo "data: $taskCount\n\n"; flush(); // JSON file $dest = "$cityFolder/" . basename($cityFolder) . "-biz-list.json"; if (file_exists($jsonTemplate)) { copy($jsonTemplate, $dest); $taskCount++; echo "data: $taskCount\n\n"; flush(); } else { foreach (glob("$pages/*-biz-list.json") ?: [] as $cand) { if (basename($cand, '-biz-list.json') === basename($cityFolder)) { copy($cand, $dest); $taskCount++; echo "data: $taskCount\n\n"; flush(); break; } } } } } echo "event: done\ndata: Completed $taskCount of $totalTasks tasks.\n\n"; flush(); exit; } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>BestDeal1 Geo Admin</title> <style> body { font-family: Arial, sans-serif; margin: 0; background: #f9f9f9; } header { display: flex; align-items: center; justify-content: space-between; background: #fff; padding: 0.5rem 1rem; border-bottom: 1px solid #ddd; } header img { height: 40px; } nav a { margin-left: 1rem; text-decoration: none; color: #333; font-weight: bold; } main { padding: 1rem; max-width: 500px; margin: 0 auto; text-align: center; } .button { padding: 0.75rem 1.5rem; font-size: 1rem; cursor: pointer; background: #007bff; color: #fff; border: none; border-radius: 4px; } .button:disabled { background: #aaa; cursor: not-allowed; } .progress { width: 100%; background: #e9ecef; border-radius: 4px; overflow: hidden; margin: 1rem 0; height: 1.5rem; } .progress-bar { width: 0%; height: 100%; background: #28a745; transition: width 0.2s; } #status { font-size: 1rem; color: #333; } </style> </head> <body> <header> <div> <a href="/members/dashboard.php">Dashboard</a></div> <nav> <a href="/geo/statesadmin.php">Create States</a><a href="/geo/pages/update.php">Create City Pages</a> </nav> </header> <main> <h1>Geo Template Generator</h1> <p>Click the button to generate templates for all states + cities in <code>USA</code>.</p> <button id="runBtn" class="button">Run Generation</button> <div class="progress"><div id="bar" class="progress-bar"></div></div> <div id="status"></div> </main> <script> (function() { const btn = document.getElementById('runBtn'); const bar = document.getElementById('bar'); const status = document.getElementById('status'); const total = <?php echo $totalTasks; ?>; btn.addEventListener('click', () => { btn.disabled = true; status.textContent = 'Processing...'; bar.style.width = '0%'; const es = new EventSource('?action=run'); es.onmessage = e => { const count = parseInt(e.data, 10); bar.style.width = ((count / total) * 100) + '%'; }; es.addEventListener('done', e => { bar.style.width = '100%'; status.textContent = e.data; btn.disabled = false; es.close(); }); es.onerror = () => { status.textContent = 'Error during generation.'; btn.disabled = false; es.close(); }; }); })(); </script> </body> </html>
Save changes
Create folder
writable 0777
Create
Cancel