Siteβ―Builder
Editing:
indexoknewest.php
writable 0666
<?php function h($s){ return htmlspecialchars($s ?? '', ENT_QUOTES, 'UTF-8'); } $ph = preg_replace('/\D/', '', $_GET['ph'] ?? ''); $root = dirname(__DIR__, 1); // Adjust if needed for your structure $bizdir = $root . '/ph/' . $ph; $bizjson = "$bizdir/business.json"; $isPaid = is_readable($bizjson); ?><script src="/ai-business-research/admin-protect.js"></script> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Coupon Creator for <?= h($ph) ?> | BestDealOn</title> <meta name="viewport" content="width=device-width,initial-scale=1"> <style> body {background:#f5f8fb;font-family:system-ui,Arial,sans-serif;margin:0;color:#263238;} .top-bar{background:#eee;padding:.8em 1.2em;font-weight:900;} .page-wrap{max-width:760px;margin:2.7em auto 0 auto;} h1{color:#2a3ca5;margin-bottom:.18em;} .coupon-form{background:#fffbe6;border:2.5px solid #ffd973;padding:2.4em 2em 2em 2em;border-radius:18px;box-shadow:0 4px 30px #f5db9c3c;} .coupon-form label{font-weight:600;color:#704000;} .coupon-form input,.coupon-form textarea{font-size:1.1em;width:100%;padding:.4em;border-radius:7px;border:1.1px solid #ead27b;margin:.25em 0 1.05em 0;} .coupon-form input[type=date]{padding:.33em;} .coupon-form .small{font-size:.97em;color:#986;} .coupon-preview-wrap{margin-top:2.5em;} .coupon-preview-title{font-size:1.18em;font-weight:700;color:#b23c00;margin-bottom:.75em;} .coupon-toolbar{display:flex;justify-content:flex-end;gap:1.1em;margin-bottom:.6em;} .coupon-btn { padding: .5em 1.15em; border-radius: 8px; font-size: 1.07em; font-weight: 700; border: none; cursor: pointer; box-shadow: 0 1px 5px #ffeebb50; background:#ffeebb; transition: background .17s, color .17s; } .coupon-btn:hover { background: #ffd670; color: #fff; } .coupon-preview { background: #fff; border:3.5px solid #ffb63b; border-radius:27px; max-width:500px; margin:auto; padding:2.2em 2em 1.5em 2em; box-shadow:0 10px 38px #c59e6933, 0 2.5px 17px #fae1a1; position:relative; overflow:hidden; transition: max-width .25s; } .coupon-preview h2 {margin:0 0 .46em 0;color:#df6200;font-size:1.49em;} .coupon-preview .desc {font-size:1.15em;color:#56411e;margin-bottom:1.31em;line-height:1.5;} .coupon-preview .desc.collapsed {max-height:4.6em;overflow:hidden;position:relative;} .coupon-preview .read-more {color:#b0640d;font-weight:600;text-decoration:underline;cursor:pointer;margin-left:.36em;font-size:1.07em;} .coupon-preview .row {display:flex;justify-content:space-between;align-items:center;margin-bottom:.3em;} .coupon-preview .label {font-weight:700;color:#ab2d00;font-size:1.05em;} .coupon-preview .code { background:#ffefc1;border-radius:9px;display:inline-block;padding:.37em 2.1em;font-size:1.22em;color:#a95600;font-family:monospace;font-weight:700; letter-spacing:.08em;box-shadow:0 1px 8px #ffbe4e42; } .coupon-preview .expiry {font-size:1.09em;color:#a75608;font-weight:600;} @media(max-width:600px){ .page-wrap,.coupon-preview{padding:.7em .14em;} .coupon-preview{max-width:98vw;} } .upgrade-block{margin-top:2.9em;text-align:center;background:#f7e6e6;padding:2.1em 1.3em;border-radius:13px;border:2px solid #f2cccc;box-shadow:0 1.5px 9px #f5bebe30;} .upgrade-block h2{color:#c00;} .upgrade-block a{display:inline-block;margin-top:1.1em;background:#ef8f13;color:#fff;padding:.65em 2.3em;border-radius:9px;font-weight:700;text-decoration:none;} .coupon-preview .desc.collapsed:after { content: ""; display: block; position: absolute; right: 0; bottom: 0; width: 90%; height: 1.9em; background: linear-gradient(to top,#fff,0%,rgba(255,255,255,0) 100%); } </style> </head> <body> <div class="top-bar"><a href="/" style="text-decoration:none;color:#2a3ca5">BestDealOn</a> » Coupon Builder</div> <div class="page-wrap"> <?php if (!$ph || !is_dir($bizdir)): ?> <div class="upgrade-block"> <h2>Business Not Found</h2> Please use a valid business phone number.<br> <span style="font-size:1em;color:#b22222"> Folder tried: <b><?= h($bizdir) ?></b> </span> </div> <?php elseif (!$isPaid): ?> <div class="upgrade-block"> <h2>Coupons are a Premium Feature</h2> <div>Upgrade to a Premium Membership to create a business coupon and unlock AI marketing tools!</div> <a href="/advertise.php?geo=<?= h($ph) ?>">Become a Member</a> </div> <?php else: ?> <h1>Coupon Creator for <?= h($ph) ?></h1> <form class="coupon-form" id="couponForm" autocomplete="off" onsubmit="return false;"> <input type="hidden" name="ph" value="<?= h($ph) ?>"> <label>Coupon Headline/Title<br> <input name="title" maxlength="100" required> </label> <label>Details/Description<br> <textarea name="desc" rows="4" required></textarea> </label> <label>Coupon Code<br> <input name="code" maxlength="40" required> </label> <label>Expires (date)<br> <input name="expiry" type="date" id="expiryField"> <span class="small">(Leave blank for 'No Expiry')</span> </label> <button type="submit" style="background:#ef8f13;color:#fff;padding:.55em 2.1em;border-radius:8px;font-weight:700;letter-spacing:.05em; font-size:1.13em; border:none;cursor:pointer;">Save Coupon</button> <div id="saveMsg" style="margin-top:1em;font-size:1.06em;"></div> </form> <div class="coupon-preview-wrap"> <div class="coupon-preview-title">Live Coupon Preview</div> <div class="coupon-toolbar"> <button class="coupon-btn" id="printCouponBtn" title="Print only the coupon" style="background:#ffeebb;color:#b25a00;"> π¨οΈ Print Coupon </button> <button class="coupon-btn" id="shareCouponBtn" title="Share this coupon" style="background:#ffeebb;color:#12754e;"> π€ Share Coupon </button> </div> <div class="coupon-preview" id="couponPreview" itemscope itemtype="https://schema.org/Offer"> <h2 id="pvTitle" itemprop="name">Your Coupon Headline Here</h2> <div class="desc collapsed" id="pvDesc" itemprop="description"></div> <span id="readMoreLink" class="read-more" style="display:none;">Read more</span> <div class="row"> <span class="label">Coupon Code:</span> <span class="code" id="pvCode" itemprop="identifier">BESTDEAL</span> </div> <div class="row"> <span class="label">Expires:</span> <span class="expiry" id="pvExpiry" itemprop="validThrough"></span> </div> </div> </div> <script> const ph = <?= json_encode($ph) ?>; // --- Fetch coupon data on load --- window.addEventListener('DOMContentLoaded', async function() { try { let r = await fetch('api.php?ph=' + encodeURIComponent(ph)); // <-- API endpoint is api.php let json = await r.json(); if (json.success && json.coupon) { document.querySelector('[name=title]').value = json.coupon.title || ''; document.querySelector('[name=desc]').value = json.coupon.desc || ''; document.querySelector('[name=code]').value = json.coupon.code || ''; document.querySelector('[name=expiry]').value = json.coupon.expiry || ''; } } catch (e) { /* ignore if no coupon yet */ } updatePreview(); // Set default expiry if empty let expiryInput = document.getElementById('expiryField'); if (expiryInput && !expiryInput.value) { let dt = new Date(); dt.setFullYear(dt.getFullYear() + 1); let m = String(dt.getMonth() + 1).padStart(2, '0'); let d = String(dt.getDate()).padStart(2, '0'); expiryInput.value = dt.getFullYear() + '-' + m + '-' + d; } updatePreview(); }); function updatePreview() { var title = document.querySelector('[name=title]').value || 'Your Coupon Headline Here'; var desc = document.querySelector('[name=desc]').value || 'Your best deal description will appear here.'; var code = document.querySelector('[name=code]').value || 'BESTDEAL'; var exp = document.querySelector('[name=expiry]').value; document.getElementById('pvTitle').innerText = title; document.getElementById('pvCode').innerText = code; document.getElementById('pvExpiry').innerText = exp ? exp : 'No Expiry'; // Description - Read more logic var pvDesc = document.getElementById('pvDesc'); var readMoreLink = document.getElementById('readMoreLink'); const descLimit = 170; if (desc.length > descLimit) { pvDesc.textContent = desc.substring(0, descLimit) + '...'; pvDesc.classList.add('collapsed'); readMoreLink.style.display = ''; readMoreLink.onclick = function() { pvDesc.textContent = desc; pvDesc.classList.remove('collapsed'); readMoreLink.style.display = 'none'; }; } else { pvDesc.textContent = desc; pvDesc.classList.remove('collapsed'); readMoreLink.style.display = 'none'; } } document.querySelector('[name=desc]').removeAttribute('maxlength'); Array.from(document.querySelectorAll('.coupon-form input,.coupon-form textarea')).forEach(el=>{ el.addEventListener('input', updatePreview); }); document.getElementById('printCouponBtn').onclick = function() { var couponHtml = document.getElementById('couponPreview').outerHTML; var printWindow = window.open('', '', 'width=600,height=800'); printWindow.document.write(` <html> <head> <title>Print Coupon</title> <style> body { background: #f5f8fb; font-family: system-ui, Arial, sans-serif; margin:0; } .coupon-preview { max-width: 500px; margin:2em auto; padding:2em; border:3.5px solid #ffb63b; border-radius:27px; background:#fff; box-shadow:0 10px 38px #c59e6933, 0 2.5px 17px #fae1a1; } .coupon-preview h2 {margin:0 0 .46em 0;color:#df6200;font-size:1.49em;} .coupon-preview .desc {font-size:1.15em;color:#56411e;margin-bottom:1.31em;line-height:1.5;} .coupon-preview .row {display:flex;justify-content:space-between;align-items:center;margin-bottom:.3em;} .coupon-preview .label {font-weight:700;color:#ab2d00;font-size:1.05em;} .coupon-preview .code { background:#ffefc1;border-radius:9px;display:inline-block;padding:.37em 2.1em;font-size:1.22em;color:#a95600;font-family:monospace;font-weight:700; letter-spacing:.08em;box-shadow:0 1px 8px #ffbe4e42; } .coupon-preview .expiry {font-size:1.09em;color:#a75608;font-weight:600;} </style> </head> <body>${couponHtml}</body> </html> `); printWindow.document.close(); setTimeout(() => { printWindow.print(); printWindow.close(); }, 200); }; document.getElementById('shareCouponBtn').onclick = function() { const url = window.location.href; const title = document.querySelector('[name=title]').value || 'Your Coupon Headline Here'; const desc = document.querySelector('[name=desc]').value || ''; if (navigator.share) { navigator.share({ title: title, text: desc, url: url }); } else { navigator.clipboard.writeText(url); this.textContent = "β Link Copied!"; setTimeout(()=>{ this.textContent = "π€ Share Coupon"; }, 1700); } }; document.getElementById('couponForm').onsubmit = async function(event) { event.preventDefault(); // Prevent default submit! const fd = new FormData(this); let payload = {}; fd.forEach((v,k)=>payload[k]=v); let r = await fetch('api.php?ph=' + encodeURIComponent(ph), { method:'POST', headers: {'Content-Type':'application/json'}, body: JSON.stringify(payload) }); let json = await r.json(); document.getElementById('saveMsg').innerText = json.success ? 'Coupon saved!' : 'Error saving coupon.'; }; updatePreview(); </script> <?php endif; ?> </div> </body> </html>
Save changes
Create folder
writable 0777
Create
Cancel