BX
BRANDEX
AI MARKETING PLATFORM BY IMAGYNEX
تسجيل الدخول
حساب جديد
Powered by IMAGYNEX
BX
BRANDEX
لوحة التحكم
نظرة عامة على أداء منشوراتك
القائمة
الرئيسية
لوحة التحكم
النشر
إنشاء بـ AI ذكي
الجدولة
منشوراتي
التحليل
التحليلات
الهاشتاقات AI
المنصات
🔒
انتهى اشتراكك
للمواصلة، فعّل كود اشتراك جديد
imagynex.com
async function saveSchedule(status) { try { const title = (document.getElementById('schedTitle')?.value || '').trim(); const postContent = (document.getElementById('schedContent')?.value || '').trim(); const schedTime = document.getElementById('schedTime')?.value || ''; const platform = document.getElementById('schedPlat')?.value || 'Instagram'; if(!title) { toast(lang==='en'?'⚠️ Enter post title first':'⚠️ أدخل عنوان المنشور أولاً','error'); document.getElementById('schedTitle')?.focus(); return; } if(status==='scheduled' && !schedTime) { toast(lang==='en'?'⚠️ Choose date and time':'⚠️ اختر تاريخاً ووقتاً','error'); document.getElementById('schedTime')?.focus(); return; } const r = await fetch('schedule.php', { method:'POST', headers:{'Content-Type':'application/json'}, body:JSON.stringify({ action:'create', title, content: postContent, platform, scheduled_at: schedTime || null, status, hashtags: lastGen.hashtags || '' }) }); const d = await r.json(); if(d.success) { toast(status==='scheduled' ? (lang==='en'?'Post scheduled ✓':'تم الجدولة ✓') : (lang==='en'?'Draft saved ✓':'تم حفظ المسودة ✓') ); if(document.getElementById('schedTitle')) document.getElementById('schedTitle').value=''; if(document.getElementById('schedContent')) document.getElementById('schedContent').value=''; if(document.getElementById('schedTime')) document.getElementById('schedTime').value=''; loadScheduled(); } else { toast(d.message || (lang==='en'?'Error saving':'خطأ في الحفظ'),'error'); } } catch(err) { toast('Error: '+err.message,'error'); console.error(err); } } async function loadAnalytics() { try { const r = await fetch('schedule.php',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({action:'get_analytics'})}); const d = await r.json(); if(d.success) { const a = d.analytics; const el = id => document.getElementById(id); if(el('anTotal')) el('anTotal').textContent = a.total_posts; if(el('anPub')) el('anPub').textContent = a.published; if(el('anSched')) el('anSched').textContent = a.scheduled; if(el('anCost')) el('anCost').textContent = '$'+a.total_cost; if(el('anCalls')) el('anCalls').textContent = a.api_calls; if(el('anTotalCost')) el('anTotalCost').textContent = '$'+a.total_cost; if(el('anTokens')) el('anTokens').textContent = Number(a.total_tokens).toLocaleString(); const ra = el('recentActivity'); if(ra) { if(a.recent_posts && a.recent_posts.length > 0) { ra.innerHTML = a.recent_posts.map(p=>`
${p.title||p.content?.substring(0,40)||'-'} ${p.platform||''} ${p.status==='published'?t('published'):p.status==='scheduled'?t('scheduled'):t('draft')} ${new Date(p.created_at).toLocaleDateString(lang==='en'?'en':'ar')}
`).join(''); } else { ra.innerHTML = `
${t('noPosts')}
`; } } } } catch(e) { console.error('Analytics error:',e); } } async function deletePost(id) { const r = await fetch('schedule.php',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({action:'delete',post_id:id})}); const d = await r.json(); if(d.success) { toast(lang==='en'?'Deleted ✓':'تم الحذف ✓'); loadScheduled(); loadPosts(); } } async function loadScheduled() { const el = document.getElementById('schedList'); if(!el) return; try { const r = await fetch('schedule.php',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({action:'get_scheduled'})}); const d = await r.json(); if(d.success && d.posts.length > 0) { el.innerHTML = d.posts.map(p => { const dt = p.scheduled_at ? new Date(p.scheduled_at).toLocaleString(lang==='en'?'en':'ar') : (lang==='en'?'Draft':'مسودة'); return `
${dt} ${p.title||p.content?.substring(0,40)||'-'} ${p.platform||''} ${p.status==='scheduled'?t('scheduled'):t('draft')}
`; }).join(''); } else { el.innerHTML = `
${lang==='en'?'No scheduled posts yet':'لا توجد منشورات مجدولة بعد'}
`; } } catch(e) { el.innerHTML='
Error loading
'; } }