Site Builder
Editing:
tools-writing-cs-omni11.php
writable 0666
<?php /***************************************************************** * Promptinator — Omni‑Issue CS Reply Studio v1.0 (Aug‑2025) *****************************************************************/ declare(strict_types=1); /* ---------- 0. shared cookie helpers ------------------------ */ define('COOKIE', 'openai_key'); define('TTL', 30*24*3600); define('SECRET', 'openai-shared-v1'); // same in every tool $host = $_SERVER['HTTP_HOST'] ?? ''; $root = (!filter_var($host, FILTER_VALIDATE_IP) && preg_match('/([a-z0-9-]+\.[a-z]{2,})$/i', $host,$m)) ? '.'.$m[1] : ''; function enc(string $v):string{ $m='aes-128-ctr'; $k=substr(hash('sha256',SECRET,true),0,16); $iv=random_bytes(openssl_cipher_iv_length($m)); return base64_encode(openssl_encrypt($v,$m,$k,0,$iv)."::{$iv}"); } function dec(string $c):string{ [$ct,$iv]=explode('::',base64_decode($c),2)+['','']; $m='aes-128-ctr'; $k=substr(hash('sha256',SECRET,true),0,16); return openssl_decrypt($ct,$m,$k,0,$iv)?:''; } /* ---------- 1. save / delete key --------------------------- */ if($_SERVER['REQUEST_METHOD']==='POST' && isset($_POST['save_key'])){ $raw=trim($_POST['api_key']??''); $ctx=stream_context_create(['http'=>['method'=>'GET','header'=>"Authorization: Bearer $raw\r\n",'timeout'=>6]]); if(@file_get_contents('https://api.openai.com/v1/models',false,$ctx)){ setcookie(COOKIE,enc($raw),time()+TTL,'/',$root,isset($_SERVER['HTTPS']),true); header('Location: '.$_SERVER['REQUEST_URI']);exit; } http_response_code(400);echo'Bad key';exit; } if(isset($_GET['logout'])){ setcookie(COOKIE,'',time()-3600,'/',$root,isset($_SERVER['HTTPS']),true); header('Location: '.$_SERVER['PHP_SELF']);exit; } /* ---------- 2. AJAX --------------------------------------- */ if($_SERVER['REQUEST_METHOD']==='POST' && ($_GET['ajax']??'')==='1'){ header('Content-Type: application/json;charset=utf-8'); $msg = trim($_POST['cust']??''); $issue = $_POST['issue'] ?? ''; $prod = trim($_POST['prod']??''); $order = trim($_POST['order']??''); $tone = $_POST['tone'] ?? 'Professional'; $extra1= trim($_POST['extra1']??''); // ETA, warranty status, etc. $policy= trim($_POST['policy']??''); $model = $_POST['model'] ?? 'gpt-3.5-turbo'; $key = isset($_COOKIE[COOKIE]) ? dec($_COOKIE[COOKIE]) : ''; if(!$key){echo json_encode(['error'=>'No API key']);exit;} if(!$msg){echo json_encode(['error'=>'Customer message required']);exit;} $prompt="You are an e‑commerce customer‑service agent.\n" ."ISSUE TYPE: {$issue}\nTONE: {$tone}\n" .($prod ?"PRODUCT: {$prod}\n":'') .($order?"ORDER #: {$order}\n":'') .($extra1?"ADDITIONAL CONTEXT: {$extra1}\n":'') .($policy?"COMPANY POLICY: {$policy}\n":'') ."TASKS:\n• Draft a helpful reply e‑mail solving the issue.\n" ."• Offer clear next steps.\n• Use brand‑appropriate empathy.\n" ."• After the e‑mail add <h3>Internal Note</h3> summarising action in ≤40 words.\n\n" ."CUSTOMER MESSAGE:\n{$msg}"; $payload=['model'=>$model,'messages'=>[['role'=>'user','content'=>$prompt]], 'max_tokens'=>800,'temperature'=>0.6]; $ch=curl_init('https://api.openai.com/v1/chat/completions'); curl_setopt_array($ch,[CURLOPT_RETURNTRANSFER=>1,CURLOPT_POST=>1, CURLOPT_HTTPHEADER=>['Authorization: Bearer '.$key,'Content-Type: application/json'], CURLOPT_POSTFIELDS=>json_encode($payload),CURLOPT_TIMEOUT=>60]); $raw=curl_exec($ch);curl_close($ch); $out=$raw?json_decode($raw,true)['choices'][0]['message']['content']:''; echo $out?json_encode(['html'=>$out]):json_encode(['error'=>'Empty response']);exit; } /* ---------- 3. page --------------------------------------- */ $logged = isset($_COOKIE[COOKIE]) && dec($_COOKIE[COOKIE]); $models = ['gpt-3.5-turbo','gpt-4o-mini','gpt-4']; ?> <!doctype html><html lang="en"><head> <meta charset="utf-8"><meta name=viewport content="width=device-width,initial-scale=1"> <title>Omni‑Issue CS Reply • Promptinator</title> <style> :root{--bg:#f1f4fb;--card:#fff;--dark:#121720;--brand:#004cff;--brand-d:#0841c4; --green:#5af287;--red:#e24d4b;--radius:26px;--shadow:0 6px 30px rgba(0,0,0,.08); font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,sans-serif;font-size:16px} body{margin:0;min-height:100vh;background:var(--bg);display:flex;flex-direction:column;color:#111} .breadcrumb{background:#ececec;font-weight:600;padding:.7rem 1.2rem}.breadcrumb a{color:var(--brand);text-decoration:none} main{width:100%;max-width:960px;margin:2.4rem auto;padding:0 1.2rem;flex:1} .tool-card{background:var(--card);border-radius:var(--radius);box-shadow:var(--shadow);padding:2rem} #bar{background:var(--dark);color:#fff;padding:.9rem 1.2rem;border-radius:var(--radius);display:flex;flex-wrap:wrap;align-items:center;gap:1rem} #bar select,#bar input{border:none;border-radius:8px;padding:.55rem .85rem;font-size:1rem}#bar select{background:#1e2535;color:#fff} .badge{display:flex;align-items:center;gap:.4ch;font-weight:600;font-size:.95rem}.badge i{width:.55rem;height:.55rem;border-radius:50%;background:var(--green)} .badge button{background:none;border:none;color:var(--red);font-size:1.1rem;cursor:pointer} label{font-weight:600;font-size:.95rem;display:flex;flex-direction:column;gap:.4rem} input,select,textarea{width:100%;padding:.7rem 1rem;border:1px solid #ccd4e8;border-radius:10px;font-size:1rem;background:#fff;box-sizing:border-box} input:focus,select:focus,textarea:focus{outline:2px solid var(--brand)} textarea{resize:vertical;min-height:120px;font-family:ui-monospace,monospace} .form-grid{display:grid;gap:1.4rem;margin-top:1.8rem} @media(min-width:700px){.form-grid{grid-template-columns:repeat(auto-fit,minmax(260px,1fr))}} .btn{background:var(--brand);color:#fff;border:none;border-radius:10px;padding:.75rem 1.55rem;font-size:1rem;font-weight:600;cursor:pointer} .btn:hover{background:var(--brand-d)}.copyBtn{margin-top:.7rem} #spin{display:none;gap:.6ch;align-items:center;margin-top:.8rem}#spin.show{display:flex}@keyframes rot{to{transform:rotate(360deg)}} #spin svg{width:20px;height:20px;animation:rot 1s linear infinite} .preview{background:#fff;border:1px solid #dfe3ef;border-radius:12px;padding:1.2rem;max-height:65vh;overflow:auto} </style> </head><body> <nav class="breadcrumb"> <a href="/members/dashboard.php">Dashboard</a> » <a href="/ai-tools/tools.php">AI Toolbox</a> » Omni‑Issue CS Reply <a href="/<?= $_SESSION['slug']??''?>/" style="float:right">View Site</a> </nav> <main> <!-- API key bar --> <div id="bar"> <?php if(!$logged): ?> <form method="post" style="display:flex;flex-wrap:wrap;gap:.7rem" autocomplete="off"> <input type="password" name="api_key" placeholder="sk-…" required> <button class="btn" name="save_key">Save Key</button> </form> <?php else: ?> <span class="badge"><i></i> API key saved <button onclick="location='?logout=1'">×</button></span> <select id="modelSel"><?php foreach($models as $m):?><option><?=$m?></option><?php endforeach;?></select> <?php endif;?> </div> <?php if(!$logged): ?> <div class="tool-card" style="text-align:center;margin-top:2rem"><h2>Get started</h2><p>Save your API key above.</p></div> <?php else: ?> <div class="tool-card"> <h2 style="margin-top:0">Generate a customer‑service reply</h2> <form id="gen" class="form-grid"> <input type="hidden" name="model" id="modelHidden" value="gpt-3.5-turbo"> <label class="full" style="grid-column:1/-1">Customer message <small>(omit personal data)</small> <textarea id="cust" name="cust"></textarea> </label> <label>Issue type <select id="issue" name="issue"> <option>Order status update</option> <option>Shipping delay apology</option> <option>Out‑of‑stock / substitution</option> <option>Warranty / return request</option> <option>Received wrong item</option> <option>Price‑match / discount request</option> </select> </label> <label>Product<input id="prod" name="prod" placeholder="e.g. XL Red Hoodie"></label> <label>Order #<input id="order" name="order"></label> <label>Extra context <input id="extra1" name="extra1" placeholder="ETA date, warranty state, etc."> </label> <label>Tone <select id="tone" name="tone"><?php foreach(['Professional','Friendly','Apologetic','Cheerful','Concise'] as $t):?><option><?=$t?></option><?php endforeach;?></select> </label> <label class="full" style="grid-column:1/-1">Policy snippet (optional) <textarea id="policy" name="policy" placeholder="e.g. 30‑day return policy, free replacement if damaged…"></textarea> </label> <button class="btn" id="go" style="grid-column:1/-1">Generate reply</button> <div id="spin"><svg viewBox="0 0 24 24"><circle cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4" fill="none"/></svg><span id="s">0</span> s</div> </form> <section id="out" style="display:none;margin-top:2.2rem"> <h3>HTML source</h3><textarea id="raw" readonly style="min-height:180px"></textarea> <button class="btn copyBtn" id="copyRaw">Copy HTML</button> <h3 style="margin-top:2rem">Rendered preview</h3> <div id="rend" class="preview"></div> <button class="btn copyBtn" id="copyR">Copy Rendered HTML</button> </section> </div> <?php endif;?> </main> <script> (()=>{ const $=id=>document.getElementById(id); /* ---------- AJAX ------------------------------------------- */ if($('gen')){ $('gen').onsubmit=e=>{ e.preventDefault(); if(!$('cust').value.trim()){alert('Paste the customer message first');return;} $('go').disabled=true;let sec=0;$('s').textContent=0;$('spin').classList.add('show'); const tick=setInterval(()=>$('s').textContent=++sec,1000); fetch('?ajax=1',{method:'POST',body:new FormData($('gen'))}) .then(r=>r.json()).then(j=>{ clearInterval(tick);$('spin').classList.remove('show');$('go').disabled=false; if(j.error){alert(j.error);return;} $('raw').value=j.html;$('rend').innerHTML=j.html;$('out').style.display=''; $('copyRaw').onclick=()=>navigator.clipboard.writeText($('raw').value).then(()=>flash($('copyRaw'))); $('copyR').onclick =()=>navigator.clipboard.writeText($('rend').innerHTML).then(()=>flash($('copyR'))); $('rend').scrollIntoView({behavior:'smooth'}); }).catch(err=>{clearInterval(tick);$('spin').classList.remove('show');$('go').disabled=false;alert(err);}); }; } /* ---------- model selector sync ---------------------------- */ if($('modelSel')) $('modelSel').onchange=e=>$('modelHidden').value=e.target.value; /* ---------- helper ----------------------------------------- */ function flash(btn){const t=btn.textContent;btn.textContent='✔ Copied';setTimeout(()=>btn.textContent=t,1200);} })(); </script> </body></html>
Save changes
Create folder
writable 0777
Create
Cancel