Siteβ―Builder
Editing:
indexokkk.php
writable 0666
<?php // Config $root = dirname(__DIR__); // must resolve to the folder containing /ph/ $ph = preg_replace('/\D/', '', $_GET['ph'] ?? ''); $bizdir = $root . '/ph/' . $ph; $bizjson = "$bizdir/business.json"; $couponjson = "$bizdir/coupon.json"; $isPaid = is_readable($bizjson); $coupon = []; if ($isPaid && is_readable($couponjson)) { $coupon = json_decode(file_get_contents($couponjson), true) ?: []; } function h($s){ return htmlspecialchars($s ?? '', ENT_QUOTES, 'UTF-8'); } // --- Handle AJAX save --- if ($_SERVER['REQUEST_METHOD']==='POST' && $isPaid) { $data = json_decode(file_get_contents("php://input"), true); $coupon = [ 'title' => trim($data['title'] ?? ''), 'desc' => trim($data['desc'] ?? ''), 'code' => trim($data['code'] ?? ''), 'expiry' => trim($data['expiry'] ?? ''), ]; file_put_contents($couponjson, json_encode($coupon, JSON_PRETTY_PRINT)); header('Content-Type: application/json'); echo json_encode(['success'=>true,'coupon'=>$coupon]); exit; } ?> <!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"> <meta property="og:title" content="<?= h($coupon['title'] ?? 'Coupon') ?>"> <meta property="og:description" content="<?= h($coupon['desc'] ?? '') ?>"> <meta property="og:type" content="website"> <meta property="og:url" content="<?= h('https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']) ?>"> <meta name="description" content="<?= h($coupon['desc'] ?? '') ?>"> <meta name="keywords" content="<?= h($coupon['code'] ?? '') ?>,coupon,deal,discount,<?= h($coupon['title'] ?? '') ?>"> <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" value="<?= h($coupon['title'] ?? '') ?>" required> </label> <label>Details/Description<br> <textarea name="desc" rows="4" required><?= h($coupon['desc'] ?? '') ?></textarea> </label> <label>Coupon Code<br> <input name="code" maxlength="40" value="<?= h($coupon['code'] ?? '') ?>" required> </label> <label>Expires (date)<br> <input name="expiry" type="date" value="<?= h($coupon['expiry'] ?? '') ?>" id="expiryField"> <span class="small">(Leave blank for 'No Expiry')</span> </label> <button 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"><?= h($coupon['title'] ?? '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"><?= h($coupon['code'] ?? 'BESTDEAL') ?></span> </div> <div class="row"> <span class="label">Expires:</span> <span class="expiry" id="pvExpiry" itemprop="validThrough"><?= h($coupon['expiry'] ?? '') ?></span> </div> </div> </div> <script> // --- Default Expiry: 1 year from now if blank --- window.addEventListener('DOMContentLoaded', function() { var expiryInput = document.getElementById('expiryField'); if (expiryInput && !expiryInput.value) { var dt = new Date(); dt.setFullYear(dt.getFullYear() + 1); var m = String(dt.getMonth() + 1).padStart(2, '0'); var 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'; } } // Remove maxlength from textarea for unlimited desc document.querySelector('[name=desc]').removeAttribute('maxlength'); Array.from(document.querySelectorAll('.coupon-form input,.coupon-form textarea')).forEach(el=>{ el.addEventListener('input', updatePreview); }); updatePreview(); // --- Print coupon card only --- 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); }; // --- Share coupon (native share or copy link) --- 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() { const fd = new FormData(this); let payload = {}; fd.forEach((v,k)=>payload[k]=v); let r = await fetch(location.pathname+location.search, { 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.'; }; </script> <?php endif; ?> </div> </body> </html>
Save changes
Create folder
writable 0777
Create
Cancel