Site Builder
Editing:
index2.php
writable 0666
<?php // --------- 1. Get numbers from query, path, or cookie ---------- $biznums = []; // 1. Try query string: /compare-business/?ph=727610188-7272599113 if (isset($_GET['ph'])) { $biznums = explode('-', preg_replace('/[^\d\-]/', '', $_GET['ph'])); } // 2. Try path: /compare-business/727610188-7272599113 elseif (preg_match('~^/compare-business/([\d\-]+)~', $_SERVER['REQUEST_URI'], $m)) { $biznums = explode('-', $m[1]); } // 3. Fallback: cookie elseif (isset($_COOKIE['mybizlist'])) { $biznums = explode('-', $_COOKIE['mybizlist']); } $biznums = array_filter($biznums, function($n){ return preg_match('/^\d{10}$/', $n); }); $biznums = array_unique($biznums); // --------- 2. Load business data ---------- $businesses = []; foreach ($biznums as $ph) { $bizfile = __DIR__ . "/../ph/$ph/business.json"; if (is_readable($bizfile)) { $businesses[$ph] = json_decode(file_get_contents($bizfile), true); $businesses[$ph]['ph'] = $ph; // for JS reference } } // --------- 3. Collect all tags ---------- $all_tags = []; foreach ($businesses as $b) { if (!empty($b['tags']) && is_array($b['tags'])) $all_tags = array_merge($all_tags, $b['tags']); } $all_tags = array_unique($all_tags); sort($all_tags); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Compare Businesses | BestDealOn</title> <meta name="viewport" content="width=device-width,initial-scale=1"> <style> body {font-family:system-ui,Arial,sans-serif; margin:0; background:#f6fafd; color:#193050;} h1{margin:1em 0 .4em .3em;font-size:1.37em;} .compare-row { display:flex; flex-wrap:wrap; justify-content:center; margin-bottom:1.4em; gap:2em;} .compare-card { background:#fff; border-radius:18px; box-shadow:0 2px 16px #dde3fa26; padding:1.4em 1.2em; min-width:320px; max-width:390px; flex:1 1 340px; position:relative; } .compare-card .remove-x { position:absolute; top:9px; right:14px; color:#e8513f; font-size:1.3em; font-weight:bold; cursor:pointer; background:rgba(245,245,245,.7); border-radius:99px; padding:.13em .47em .09em .47em; border:1.2px solid #f1dad6; transition:.15s; } .compare-card .remove-x:hover { background:#ffeaeb; } .tags {margin:.6em 0 0 0;} .tag {display:inline-block; background:#e5f0fd; color:#0d3e7e; border-radius:15px; padding:.13em .75em; margin:0 .10em .14em 0; font-size:.95em;} .list-row {margin:0 auto 2em auto; max-width:700px;} .sortbar {margin:.7em 0 1em .5em;} .sortbar label{font-weight:500;} @media (max-width:900px) { .compare-row{flex-direction:column;align-items:center;} .compare-card{min-width:96vw;max-width:99vw;} } </style> </head> <body> <h1>Compare Your Saved Businesses</h1> <div class="sortbar"> <label>Filter by Tag:</label> <select id="tagFilter"> <option value="">All</option> <?php foreach($all_tags as $t): ?> <option value="<?= htmlspecialchars($t) ?>"><?= htmlspecialchars($t) ?></option> <?php endforeach; ?> </select> </div> <?php // Debug/info if (empty($biznums)) { echo "<p style='color:red;font-size:1.15em;'>No businesses selected. Use the 'Compare' feature from a business profile to add.</p>"; } elseif (empty($businesses)) { echo "<p style='color:red;font-size:1.15em;'>No business data found for: ".implode(', ', $biznums)."<br>Check your URL or if the business exists.</p>"; } ?> <div class="compare-row" id="compareRow"> <?php // Show the first two businesses side-by-side for comparison $compare = array_slice($businesses, 0, 2); foreach ($compare as $b): ?> <div class="compare-card" data-ph="<?= htmlspecialchars($b['ph']) ?>"> <span class="remove-x" title="Remove from list" onclick="removeBiz('<?= htmlspecialchars($b['ph']) ?>')">×</span> <div style="font-size:1.2em;font-weight:700;margin-bottom:.2em;"><?= htmlspecialchars($b['name'] ?? 'Business') ?></div> <div style="font-style:italic;color:#3c62b8;margin-bottom:.37em;"><?= htmlspecialchars($b['slogan'] ?? '') ?></div> <div><b>Phone:</b> <?= htmlspecialchars($b['phone'] ?? '') ?></div> <div><b>Address:</b> <?= htmlspecialchars($b['address'] ?? '') ?></div> <div><b>City/State:</b> <?= htmlspecialchars($b['city'] ?? '') ?><?= $b['state'] ? ', ' . htmlspecialchars($b['state']) : '' ?></div> <div><b>Website:</b> <?php if(!empty($b['website'])):?><a href="<?= htmlspecialchars($b['website']) ?>" target="_blank"><?= htmlspecialchars($b['website']) ?></a><?php endif;?></div> <div class="tags"> <?php if(!empty($b['tags'])) foreach($b['tags'] as $tag): ?> <span class="tag"><?= htmlspecialchars($tag) ?></span> <?php endforeach; ?> </div> </div> <?php endforeach; ?> </div> <?php // Show additional businesses below in a list $others = array_slice($businesses, 2); if ($others): ?> <div class="list-row" id="listRow"> <?php foreach($others as $b): ?> <div class="compare-card" data-ph="<?= htmlspecialchars($b['ph']) ?>" style="max-width:99vw;"> <span class="remove-x" title="Remove from list" onclick="removeBiz('<?= htmlspecialchars($b['ph']) ?>')">×</span> <div style="font-size:1.15em;font-weight:600;margin-bottom:.22em;"><?= htmlspecialchars($b['name'] ?? 'Business') ?></div> <div style="font-style:italic;color:#3c62b8;margin-bottom:.37em;"><?= htmlspecialchars($b['slogan'] ?? '') ?></div> <div><b>Phone:</b> <?= htmlspecialchars($b['phone'] ?? '') ?></div> <div><b>Address:</b> <?= htmlspecialchars($b['address'] ?? '') ?></div> <div><b>City/State:</b> <?= htmlspecialchars($b['city'] ?? '') ?><?= $b['state'] ? ', ' . htmlspecialchars($b['state']) : '' ?></div> <div><b>Website:</b> <?php if(!empty($b['website'])):?><a href="<?= htmlspecialchars($b['website']) ?>" target="_blank"><?= htmlspecialchars($b['website']) ?></a><?php endif;?></div> <div class="tags"> <?php if(!empty($b['tags'])) foreach($b['tags'] as $tag): ?> <span class="tag"><?= htmlspecialchars($tag) ?></span> <?php endforeach; ?> </div> </div> <?php endforeach; ?> </div> <?php endif; ?> <script> // Remove business (updates cookie & reloads page without the number) function removeBiz(ph) { var cookie = document.cookie.match(/mybizlist=([^;]+)/); if (cookie) { var list = cookie[1].split('-'); list = list.filter(function(item){return item !== ph;}); document.cookie = "mybizlist=" + list.join('-') + ";path=/;max-age=" + (60*60*24*30); // Remove from URL too var url = window.location.pathname; // Remove ph from URL or from query string var re = new RegExp("([-/]?)" + ph); url = url.replace(re, ''); if (url.match(/\/compare-business\/?$/)) url += '?'; // go back to empty compare page window.location.href = url; } } // Tag filter: shows only cards with selected tag document.getElementById('tagFilter').addEventListener('change', function(){ var val = this.value; document.querySelectorAll('.compare-card').forEach(function(card){ if(!val || Array.from(card.querySelectorAll('.tag')).some(t => t.textContent === val)) { card.style.display = ''; } else { card.style.display = 'none'; } }); }); </script> </body> </html>
Save changes
Create folder
writable 0777
Create
Cancel