<?php if (!defined('DASHBOARD_ROOT')) { http_response_code(403); exit; } $scheduled = []; try { $scheduled = Database::fetchAll("SELECT id, platform, content, scheduled_at, status_code, created_at FROM social_posts WHERE status_code IN (6001,6004) ORDER BY scheduled_at") ?: []; } catch (\Throwable $e) { } ?> <div id="social-scheduler" class="panel"> <span class="section-label">Social Post Scheduler</span> <div id="social-compose" class="editor-form"> <div class="form-group"><span>Platform</span> <select id="soc-platform" class="form-group input"> <option value="instagram">Instagram</option> <option value="facebook">Facebook</option> <option value="twitter">Twitter/X</option> </select> </div> <div class="form-group"><span>Content</span><input id="soc-content" class="form-group input" type="text" placeholder="Post content..."></div> <div class="form-group"><span>Schedule Date/Time</span><input id="soc-datetime" class="form-group input" type="datetime-local"></div> <div class="form-actions"><a id="soc-schedule" class="btn btn-primary" href="javascript:void(0)"><span>Schedule Post</span></a></div> </div> <div id="social-queue" class="panel"> <span class="section-label">Scheduled Queue (<?= count($scheduled) ?> )</span><?php foreach ($scheduled as $p): ?> <div class="event-row"> <span class="event-action">[<?= UI::e($p['platform']??'') ?> ]<?= UI::e(substr($p['content']??'',0,60)) ?> </span> <span class="event-time"><?= UI::e($p['scheduled_at']??'') ?> </span> <a class="btn btn-danger btn-sm soc-cancel" href="javascript:void(0)" data-id="<?= (int)$p['id'] ?> "><span>Cancel</span></a> </div><?php endforeach; ?> <?php if (empty($scheduled)): ?> <div class="empty-state"><span>No scheduled posts.</span></div><?php endif; ?> </div> </div> <script nonce="<?= $cspNonce ?? '' ?> "> document.getElementById('soc-schedule').addEventListener('click',function(){ window.dashFetch('post',{entity:'social_post','data[platform]':document.getElementById('soc-platform').value,'data[content]':document.getElementById('soc-content').value,'data[scheduled_at]':document.getElementById('soc-datetime').value},function(r){if(r.ok){alert('Scheduled.');location.reload();}else{alert(r.error||'Failed');}}); }); document.querySelectorAll('.soc-cancel').forEach(function(b){b.addEventListener('click',function(){window.dashFetch('modify',{entity:'social_post',id:b.dataset.id,'data[status_code]':'6003'},function(r){if(r.ok)location.reload();});});}); </script>