<?php if (!defined('DASHBOARD_ROOT')) { http_response_code(403); exit; } $accounts = Database::fetchAll("SELECT id, meta_account_id, account_name, status FROM meta_ad_accounts ORDER BY account_name"); $appId = defined('META_APP_ID') && META_APP_ID ? 'Configured' : 'Not Set'; $appSecret = defined('META_APP_SECRET') && META_APP_SECRET ? 'Configured' : 'Not Set'; ?> <div id="meta-oauth" class="editor-form"> <span class="section-label">Meta API Setup</span> <div class="detail-grid"> <div><span class="kpi-label">App ID</span><span><?= UI::badge($appId, $appId==='Configured'?'success':'warning') ?> </span></div> <div><span class="kpi-label">App Secret</span><span><?= UI::badge($appSecret, $appSecret==='Configured'?'success':'warning') ?> </span></div> </div> <div class="panel"> <span class="section-label">Connect Ad Account</span> <div class="form-group"><span>Access Token</span><input id="meta-token" class="form-group input" type="text" placeholder="Paste long-lived access token"></div> <div class="form-group"><span>Account ID</span><input id="meta-acctid" class="form-group input" type="text" placeholder="act_XXXXXXXXX"></div> <div class="form-group"><span>Account Name</span><input id="meta-name" class="form-group input" type="text" placeholder="My Ad Account"></div> <div class="form-actions"><a id="meta-connect" class="btn btn-primary" href="javascript:void(0)"><span>Connect Account</span></a></div> </div><?php if (!empty($accounts)): ?> <div class="panel"> <span class="section-label">Connected Accounts</span><?php foreach ($accounts as $a): ?> <div class="account-card"> <span><?= UI::e($a['account_name']) ?> </span> <span><?= UI::e($a['meta_account_id']) ?> </span><?= UI::badge(UI::e($a['status']), $a['status'] === 'active' ? 'success' : 'default') ?> </div><?php endforeach; ?> </div><?php endif; ?> </div> <script nonce="<?= $cspNonce ?? '' ?> "> document.getElementById('meta-connect').addEventListener('click',function(){ window.dashFetch('post',{entity:'meta_account','data[access_token]':document.getElementById('meta-token').value,'data[meta_account_id]':document.getElementById('meta-acctid').value,'data[account_name]':document.getElementById('meta-name').value},function(r){if(r.ok){alert('Connected.');location.reload();}else{alert(r.error||'Failed');};}); }); </script>