<?php if (!defined('DASHBOARD_ROOT')) { http_response_code(403); exit; } if ($_SERVER['REQUEST_METHOD'] === 'POST' && ($_POST['_mkt_ad_studio'] ?? '') !== '') { while (ob_get_level()) { ob_end_clean(); } header('Content-Type: application/json'); CSRF::enforce(); $act = $_POST['_mkt_ad_studio']; if ($act === 'load_assets') { try { $assets = Database::fetchAll("SELECT id, title AS filename, asset_type, status, created_at FROM mkt_social_assets ORDER BY created_at DESC LIMIT 30"); } catch (\Throwable $e) { $assets = []; } exit(json_encode(['ok' => true, 'assets' => $assets])); } exit(json_encode(['ok' => false, 'error' => 'Unknown action'])); } ?> <script nonce="<?= $cspNonce ?> "> (function(){ var panel = document.getElementById('panel-ad_studio'); if (!panel) return; function load(){ var fd = new FormData(); fd.append('_mkt_ad_studio','load_assets'); fd.append('_csrf', getCSRF()); fetch('', {method:'POST',body:fd,credentials:'same-origin'}) .then(function(r){return r.json()}) .then(function(d){ render(d.assets || []); }) .catch(function(){ render([]); }); } function render(assets){ var h = '<div class="mkt-section"><div class="mkt-section-hdr"><span class="mkt-icon" style="color:var(--accent-light)">●</span><span class="mkt-title">AD STUDIO</span><span class="mkt-badge" style="color:var(--text-dim)">CREATIVE PIPELINE</span></div>'; if(!assets.length){ h += '<div style="text-align:center;padding:40px;color:var(--text-dim);font-size:12px">No creative assets generated yet. Connect AI generation pipeline in Settings.</div>'; } else { h += '<div style="display:grid;grid-template-columns:repeat(auto-fill,minmax(180px,1fr));gap:12px">'; assets.forEach(function(a){ h += '<div style="background:var(--bg-card);border:1px solid var(--border);border-radius:var(--radius-md);padding:14px;text-align:center">'; h += '<div style="font-size:11px;font-weight:700;color:var(--text-bright);margin-bottom:6px">'+a.filename+'</div>'; h += '<div style="font-size:9px;color:var(--text-dim);text-transform:uppercase;letter-spacing:1px">'+a.asset_type+'</div>'; h += '</div>'; }); h += '</div>'; } h += '</div>'; panel.innerHTML = h; } load(); })(); </script>