1582 lines
88 KiB
PHP
1582 lines
88 KiB
PHP
<?php
|
|
|
|
namespace App\Views;
|
|
|
|
class TeacherPortal
|
|
{
|
|
public static function render(): string
|
|
{
|
|
return <<<'HTML'
|
|
<!DOCTYPE html>
|
|
<html lang="ar" dir="rtl">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>بوابة المعلم — استوديو صَقِل التعليمي</title>
|
|
<link rel="icon" type="image/jpeg" href="/assets/images/saqel_logo.jpg">
|
|
<link rel="apple-touch-icon" href="/assets/images/saqel_logo.jpg">
|
|
<!-- Apple SF Pro & Alexandria Arabic Web Fonts -->
|
|
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
<link href="https://fonts.googleapis.com/css2?family=Alexandria:wght@300;400;500;600;700;800;900&display=swap" rel="stylesheet">
|
|
|
|
<!-- Pure Self-Contained Luxury CSS (Zero External CDN Dependency) -->
|
|
<style>
|
|
:root {
|
|
--bg-dark: #0B132B;
|
|
--bg-card: #16203D;
|
|
--bg-card-hover: #1E2C52;
|
|
--bg-input: #090E20;
|
|
--border: #2A3B66;
|
|
--border-focus: #FFD166;
|
|
--text-primary: #FFFFFF;
|
|
--text-secondary: #CBD5E1;
|
|
--text-muted: #8E9FB8;
|
|
--accent-gold: #FFD166;
|
|
--accent-gold-dark: #F59E0B;
|
|
--accent-cyan: #00F5D4;
|
|
--accent-red: #EF4444;
|
|
--accent-green: #10B981;
|
|
--accent-purple: #A78BFA;
|
|
}
|
|
|
|
* {
|
|
box-sizing: border-box;
|
|
margin: 0;
|
|
padding: 0;
|
|
font-family: -apple-system, BlinkMacSystemFont, "Alexandria", "SF Pro Display", "SF Pro Text", "SF Arabic", "Segoe UI", Roboto, sans-serif;
|
|
-webkit-font-smoothing: antialiased;
|
|
-moz-osx-font-smoothing: grayscale;
|
|
}
|
|
|
|
body {
|
|
background-color: var(--bg-dark);
|
|
color: var(--text-primary);
|
|
min-height: 100vh;
|
|
display: flex;
|
|
flex-direction: column;
|
|
justify-content: space-between;
|
|
background-image:
|
|
radial-gradient(circle at 15% 15%, rgba(255, 209, 102, 0.07) 0%, transparent 40%),
|
|
radial-gradient(circle at 85% 85%, rgba(0, 245, 212, 0.05) 0%, transparent 40%),
|
|
linear-gradient(to right, rgba(255, 255, 255, 0.02) 1px, transparent 1px),
|
|
linear-gradient(to bottom, rgba(255, 255, 255, 0.02) 1px, transparent 1px);
|
|
background-size: 100% 100%, 100% 100%, 32px 32px, 32px 32px;
|
|
}
|
|
|
|
.container { max-width: 1240px; margin: 0 auto; padding: 0 20px; width: 100%; }
|
|
|
|
/* Header */
|
|
header {
|
|
border-bottom: 1px solid var(--border);
|
|
background-color: rgba(11, 19, 43, 0.95);
|
|
backdrop-filter: blur(12px);
|
|
position: sticky;
|
|
top: 0;
|
|
z-index: 50;
|
|
}
|
|
|
|
.header-content { height: 68px; display: flex; align-items: center; justify-content: space-between; }
|
|
|
|
.logo-area { display: flex; align-items: center; gap: 12px; text-decoration: none; }
|
|
.logo-badge {
|
|
width: 42px; height: 42px; border-radius: 12px;
|
|
background: linear-gradient(135deg, var(--accent-gold), var(--accent-gold-dark));
|
|
display: flex; align-items: center; justify-content: center;
|
|
color: #0B132B; font-size: 20px; font-weight: 900;
|
|
box-shadow: 0 0 20px rgba(255, 209, 102, 0.35);
|
|
}
|
|
.brand-title { font-size: 20px; font-weight: 900; color: #FFFFFF; letter-spacing: 0.5px; }
|
|
.portal-pill {
|
|
font-size: 11px; font-weight: 700; padding: 2px 10px; border-radius: 999px;
|
|
background: rgba(255, 209, 102, 0.12); color: var(--accent-gold);
|
|
border: 1px solid rgba(255, 209, 102, 0.35); margin-right: 8px;
|
|
}
|
|
|
|
.nav-link { font-size: 13px; color: var(--text-secondary); text-decoration: none; display: flex; align-items: center; gap: 6px; }
|
|
.nav-link:hover { color: var(--accent-cyan); }
|
|
.nav-link-highlight { color: var(--accent-cyan); font-weight: 800; text-decoration: underline; }
|
|
|
|
/* WS Status Badge */
|
|
.ws-badge {
|
|
display: inline-flex; align-items: center; gap: 6px; font-size: 11px; font-weight: 800;
|
|
padding: 4px 10px; border-radius: 999px;
|
|
}
|
|
.ws-online { background: rgba(16,185,129,0.15); border: 1px solid rgba(16,185,129,0.4); color: #34D399; }
|
|
.ws-offline { background: rgba(239,68,68,0.15); border: 1px solid rgba(239,68,68,0.4); color: #FCA5A5; }
|
|
.ws-dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
|
|
|
|
/* Main Content */
|
|
main { flex: 1; display: flex; align-items: center; justify-content: center; padding: 36px 0; }
|
|
|
|
.auth-card-wrapper { width: 100%; max-width: 500px; margin: 0 auto; }
|
|
.auth-header { text-align: center; margin-bottom: 24px; }
|
|
.icon-box {
|
|
width: 64px; height: 64px; border-radius: 18px;
|
|
background: var(--bg-card); border: 1px solid rgba(255, 209, 102, 0.4);
|
|
display: inline-flex; align-items: center; justify-content: center;
|
|
color: var(--accent-gold); margin-bottom: 16px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
|
|
}
|
|
.auth-title { font-size: 24px; font-weight: 900; color: #FFFFFF; margin-bottom: 6px; }
|
|
.auth-subtitle { font-size: 13px; color: var(--text-muted); line-height: 1.6; }
|
|
.auth-box {
|
|
background: var(--bg-card); border: 1px solid var(--border); border-radius: 20px;
|
|
padding: 32px; box-shadow: 0 16px 40px rgba(0, 0, 0, 0.4); position: relative;
|
|
}
|
|
|
|
/* Forms */
|
|
.form-group { margin-bottom: 20px; }
|
|
.form-label { display: block; font-size: 12px; font-weight: 700; color: var(--text-secondary); margin-bottom: 8px; }
|
|
.input-text {
|
|
width: 100%; background: var(--bg-input); border: 1px solid var(--border);
|
|
border-radius: 12px; padding: 12px 16px; font-size: 14px; color: #FFFFFF; outline: none;
|
|
transition: border-color 0.2s, box-shadow 0.2s;
|
|
}
|
|
.input-text:focus { border-color: var(--accent-gold); box-shadow: 0 0 0 3px rgba(255, 209, 102, 0.2); }
|
|
.phone-input-group { display: flex; align-items: center; direction: ltr; position: relative; }
|
|
.country-badge {
|
|
position: absolute; left: 10px; background: #121A33; border: 1px solid var(--border);
|
|
border-radius: 8px; padding: 6px 10px; font-size: 12px; font-weight: 700; color: var(--accent-gold);
|
|
user-select: none;
|
|
}
|
|
.input-phone { padding-left: 96px !important; font-family: monospace; font-size: 15px; letter-spacing: 1px; }
|
|
.form-hint { font-size: 11px; color: var(--text-muted); margin-top: 6px; display: block; }
|
|
|
|
.btn-primary {
|
|
width: 100%; padding: 14px; background: linear-gradient(135deg, #FFD166 0%, #F59E0B 100%);
|
|
color: #0B132B !important; border: none; border-radius: 12px; font-size: 15px; font-weight: 900 !important;
|
|
cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 8px;
|
|
box-shadow: 0 8px 24px rgba(255, 209, 102, 0.35); transition: transform 0.15s, opacity 0.15s;
|
|
}
|
|
.btn-primary:hover { opacity: 0.95; transform: translateY(-1px); }
|
|
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }
|
|
.btn-secondary { background: none; border: none; color: var(--text-muted); font-size: 12px; cursor: pointer; }
|
|
.btn-link-gold { color: var(--accent-gold); font-weight: 700; text-decoration: underline; }
|
|
.otp-input { text-align: center; font-size: 26px; font-family: monospace; letter-spacing: 10px; font-weight: 900; color: var(--accent-gold); border-color: rgba(255, 209, 102, 0.5); padding: 14px; }
|
|
|
|
/* Alerts */
|
|
.alert { padding: 12px 16px; border-radius: 12px; font-size: 12.5px; margin-bottom: 20px; display: flex; align-items: center; gap: 8px; }
|
|
.alert-error { background: rgba(239, 68, 68, 0.15); border: 1px solid rgba(239, 68, 68, 0.4); color: #FCA5A5; }
|
|
.alert-success { background: rgba(255, 209, 102, 0.15); border: 1px solid rgba(255, 209, 102, 0.4); color: var(--accent-gold); }
|
|
|
|
/* Dashboard View */
|
|
.dashboard-hero {
|
|
background: linear-gradient(135deg, var(--bg-card), var(--bg-card-hover));
|
|
border: 1px solid var(--border); border-radius: 24px; padding: 28px;
|
|
display: flex; align-items: center; justify-content: space-between; gap: 20px; flex-wrap: wrap; margin-bottom: 24px;
|
|
}
|
|
.stats-grid { display: flex; gap: 14px; flex-wrap: wrap; }
|
|
.stat-card {
|
|
background: rgba(11, 19, 43, 0.85); border: 1px solid var(--border);
|
|
border-radius: 16px; padding: 14px 20px; text-align: center; min-width: 130px;
|
|
}
|
|
.stat-card.gold-glow { border-color: rgba(255, 209, 102, 0.5); box-shadow: 0 0 20px rgba(255, 209, 102, 0.15); }
|
|
.stat-label { font-size: 11px; font-weight: 700; color: var(--text-muted); display: block; margin-bottom: 4px; }
|
|
.stat-val { font-size: 22px; font-weight: 900; }
|
|
.val-cyan { color: var(--accent-cyan); }
|
|
.val-purple { color: var(--accent-purple); }
|
|
.val-gold { color: var(--accent-gold); }
|
|
|
|
.tabs-nav { display: flex; gap: 10px; margin-bottom: 20px; border-bottom: 1px solid var(--border); padding-bottom: 12px; }
|
|
.tab-btn {
|
|
background: rgba(22, 32, 61, 0.6); border: 1px solid var(--border);
|
|
color: var(--text-secondary); font-size: 13px; font-weight: 700; padding: 10px 18px;
|
|
border-radius: 12px; cursor: pointer; transition: 0.2s;
|
|
}
|
|
.tab-btn.active {
|
|
background: linear-gradient(135deg, rgba(255,209,102,0.15), rgba(245,158,11,0.15));
|
|
border-color: var(--accent-gold); color: var(--accent-gold); font-weight: 900;
|
|
}
|
|
|
|
.studio-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: 20px; padding: 28px; }
|
|
|
|
/* Full Chat Layout */
|
|
.chat-container {
|
|
display: grid; grid-template-columns: 300px 1fr; gap: 16px;
|
|
height: 520px; background: rgba(11, 19, 43, 0.8); border: 1px solid var(--border); border-radius: 16px; overflow: hidden;
|
|
}
|
|
@media (max-width: 860px) { .chat-container { grid-template-columns: 1fr; height: auto; } }
|
|
|
|
.chat-sidebar { border-left: 1px solid var(--border); background: #0F172E; display: flex; flex-direction: column; }
|
|
.chat-sidebar-header { padding: 14px 16px; border-bottom: 1px solid var(--border); font-size: 13px; font-weight: 800; }
|
|
.conversations-list { overflow-y: auto; flex: 1; }
|
|
.conv-item {
|
|
padding: 12px 16px; border-bottom: 1px solid rgba(255,255,255,0.04); cursor: pointer; transition: 0.2s;
|
|
}
|
|
.conv-item:hover, .conv-item.active { background: rgba(255, 209, 102, 0.08); }
|
|
.conv-name { font-size: 13px; font-weight: 700; color: #FFFFFF; display: flex; justify-content: space-between; }
|
|
.conv-preview { font-size: 11.5px; color: var(--text-muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
|
.unread-badge {
|
|
background: #EF4444; color: #FFF; font-size: 10px; font-weight: 900; border-radius: 999px;
|
|
padding: 1px 6px;
|
|
}
|
|
|
|
.chat-main { display: flex; flex-direction: column; justify-content: space-between; background: var(--bg-card); }
|
|
.chat-main-header {
|
|
padding: 12px 18px; border-bottom: 1px solid var(--border); background: rgba(11, 19, 43, 0.6);
|
|
display: flex; justify-content: space-between; align-items: center;
|
|
}
|
|
.chat-messages { padding: 18px; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 12px; }
|
|
.chat-msg { max-width: 75%; padding: 10px 14px; border-radius: 14px; font-size: 13px; line-height: 1.5; }
|
|
.chat-msg.student { align-self: flex-start; background: #1E2D5A; color: #E2E8F0; border-bottom-right-radius: 2px; }
|
|
.chat-msg.teacher { align-self: flex-end; background: linear-gradient(135deg, #FFD166, #F59E0B); color: #0B132B; font-weight: 700; border-bottom-left-radius: 2px; }
|
|
.chat-time { font-size: 9.5px; opacity: 0.7; margin-top: 4px; display: block; text-align: left; }
|
|
|
|
.chat-input-bar {
|
|
padding: 12px; border-top: 1px solid var(--border); background: #0E152B; display: flex; gap: 8px;
|
|
}
|
|
|
|
.spinner {
|
|
width: 18px; height: 18px; border: 3px solid rgba(11, 19, 43, 0.3);
|
|
border-top-color: #0B132B; border-radius: 50%; animation: spin 0.8s linear infinite;
|
|
}
|
|
@keyframes spin { to { transform: rotate(360deg); } }
|
|
|
|
footer { border-top: 1px solid rgba(255, 255, 255, 0.08); padding: 20px 0; background: var(--bg-dark); color: var(--text-muted); font-size: 12px; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
|
|
<!-- Header -->
|
|
<header>
|
|
<div class="container">
|
|
<div class="header-content">
|
|
<a href="/teacher" class="logo-area">
|
|
<img src="/assets/images/saqel_logo.jpg" alt="صَقِل" style="width: 38px; height: 38px; border-radius: 10px; object-fit: cover; box-shadow: 0 0 16px rgba(255, 209, 102, 0.35); border: 1px solid rgba(255, 255, 255, 0.15);">
|
|
<div>
|
|
<span class="brand-title">صَقِل</span>
|
|
<span class="portal-pill">استوديو المعلمين</span>
|
|
</div>
|
|
</a>
|
|
|
|
<div id="header_user_actions">
|
|
<div id="auth_user_badge" style="display: none; align-items: center; gap: 12px;">
|
|
<span id="ws_status_badge" class="ws-badge ws-offline">
|
|
<span class="ws-dot"></span>
|
|
<span id="ws_status_text">Workerman جاري الاتصال...</span>
|
|
</span>
|
|
<span style="font-size: 13px; color: var(--text-secondary);" id="teacher_display_name"></span>
|
|
<button onclick="handleLogout()" style="background: none; border: 1px solid rgba(239,68,68,0.4); color: #F87171; border-radius: 8px; padding: 6px 12px; font-size: 12px; cursor: pointer;">
|
|
تسجيل الخروج
|
|
</button>
|
|
</div>
|
|
<a href="/student" class="nav-link" id="switch_to_student_link">
|
|
<span>أنت طالب؟</span>
|
|
<span class="nav-link-highlight">بوابة الطلاب ←</span>
|
|
</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</header>
|
|
|
|
<!-- Main Content -->
|
|
<main>
|
|
<div class="container">
|
|
|
|
<!-- ========================================== -->
|
|
<!-- 1. AUTHENTICATION (PHONE & OTP) -->
|
|
<!-- ========================================== -->
|
|
<div id="auth_container" class="auth-card-wrapper">
|
|
<div class="auth-header">
|
|
<div class="icon-box">
|
|
<svg width="28" height="28" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10"></path>
|
|
</svg>
|
|
</div>
|
|
<h1 class="auth-title">استوديو صَقِل للمعلمين</h1>
|
|
<p class="auth-subtitle">حماية محتواك بـ DRM وغرف محادثة تفاعلية مباشرة مع طلابك</p>
|
|
</div>
|
|
|
|
<div class="auth-box">
|
|
<div id="alert_box_error" class="alert alert-error" style="display: none;">
|
|
<span>⚠️</span><span id="alert_error_msg"></span>
|
|
</div>
|
|
<div id="alert_box_success" class="alert alert-success" style="display: none;">
|
|
<span>✓</span><span id="alert_success_msg"></span>
|
|
</div>
|
|
|
|
<!-- Step 1: Phone -->
|
|
<div id="step_phone_container">
|
|
<div class="form-group">
|
|
<label class="form-label">رقم هاتف المعلم (الواتساب) <span style="color: #EF4444;">*</span></label>
|
|
<div class="phone-input-group">
|
|
<div class="country-badge">🇯🇴 +962</div>
|
|
<input type="tel" id="teacher_phone" required placeholder="790000000" class="input-text input-phone">
|
|
</div>
|
|
<span class="form-hint">يصلك رمز التحقق المباشر على الواتساب المعتمد.</span>
|
|
</div>
|
|
<button type="button" id="btn_send_otp" onclick="handleSendOtp(event)" class="btn-primary">
|
|
<span id="btn_send_text">إرسال رمز الدخول (OTP) ←</span>
|
|
<div id="btn_send_spinner" class="spinner" style="display: none;"></div>
|
|
</button>
|
|
</div>
|
|
|
|
<!-- Step 2: OTP Code -->
|
|
<div id="step_otp_container" style="display: none;">
|
|
<div style="text-align: center; margin-bottom: 20px;">
|
|
<span style="font-size: 12px; color: var(--text-muted);">تم إرسال رمز التحقق إلى:</span>
|
|
<div style="font-family: monospace; font-size: 15px; font-weight: 800; color: var(--accent-gold); margin-top: 4px;" id="otp_target_display"></div>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label class="form-label" style="text-align: center;">أدخل رمز التحقق (6 أرقام)</label>
|
|
<input type="text" id="teacher_otp_code" maxlength="6" autofocus placeholder="• • • • • •" class="input-text otp-input">
|
|
</div>
|
|
|
|
<button type="button" id="btn_verify_otp" onclick="handleVerifyOtp(event)" class="btn-primary">
|
|
<span id="btn_verify_text">تأكيد الدخول للاستوديو 🎓</span>
|
|
<div id="btn_verify_spinner" class="spinner" style="display: none;"></div>
|
|
</button>
|
|
|
|
<div style="display: flex; align-items: center; justify-content: space-between; margin-top: 18px;">
|
|
<button type="button" onclick="switchToPhoneStep()" class="btn-secondary">← تعديل الرقم</button>
|
|
<span id="resend_timer_label" style="font-size: 12px; color: var(--text-muted); display: none;"></span>
|
|
<button type="button" id="btn_resend" onclick="handleSendOtp(event)" class="btn-secondary btn-link-gold" style="display: none;">إعادة إرسال الرمز ↺</button>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Step 3: Onboarding Setup (Only for first-time login) -->
|
|
<div id="step_onboarding_container" style="display: none;">
|
|
<div style="background: rgba(255,209,102,0.1); border: 1px solid rgba(255,209,102,0.3); border-radius: 12px; padding: 12px 16px; margin-bottom: 20px;">
|
|
<span style="font-size: 13px; font-weight: 800; color: var(--accent-gold);">👋 مرحباً بك معنا!</span>
|
|
<p style="font-size: 12px; color: var(--text-secondary); margin-top: 2px;">يرجى توثيق لقبك الأكاديمي ومادتك التدريسية.</p>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label class="form-label">الاسم الكامل ولقب التدريس <span style="color: #EF4444;">*</span></label>
|
|
<input type="text" id="onboard_fullname" placeholder="مثال: الأستاذ حمزة الغويري" class="input-text">
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label class="form-label">التخصص والمادة <span style="color: #EF4444;">*</span></label>
|
|
<select id="onboard_specialization" class="input-text">
|
|
<option value="الرياضيات العلمي">رياضيات — الفرع العلمي والمهني</option>
|
|
<option value="الفيزياء">الفيزياء — التوجيهي والأول ثانوي</option>
|
|
<option value="الكيمياء">الكيمياء — توجيهي 2007 و 2008</option>
|
|
<option value="العلوم الحياتية">العلوم الحياتية (أحياء)</option>
|
|
<option value="اللغة العربية">اللغة العربية والتخصص</option>
|
|
<option value="اللغة الإنجليزية">اللغة الإنجليزية</option>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label class="form-label">تعيين كلمة المرور السرية <span style="color: #EF4444;">*</span></label>
|
|
<input type="password" id="onboard_password" placeholder="8 خانات على الأقل" class="input-text">
|
|
</div>
|
|
|
|
<button type="button" id="btn_complete_onboarding" onclick="handleCompleteOnboarding(event)" class="btn-primary">
|
|
<span id="btn_onboard_text">حفظ وتفعيل لوحة التحكم 🚀</span>
|
|
<div id="btn_onboard_spinner" class="spinner" style="display: none;"></div>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- ========================================== -->
|
|
<!-- 2. TEACHER DASHBOARD (AUTHENTICATED) -->
|
|
<!-- ========================================== -->
|
|
<div id="dashboard_container" style="width: 100%; display: none;">
|
|
|
|
<!-- Hero Header -->
|
|
<div class="dashboard-hero">
|
|
<div>
|
|
<span style="display: inline-block; font-size: 11px; font-weight: 800; color: var(--accent-gold); background: rgba(255,209,102,0.12); border: 1px solid rgba(255,209,102,0.3); padding: 4px 12px; border-radius: 999px; margin-bottom: 10px;">استوديو المعلم المعتمد</span>
|
|
<h2 style="font-size: 26px; font-weight: 900; color: #FFFFFF;" id="dashboard_welcome_title">أهلاً بك يا أستاذنا 👨🏫</h2>
|
|
<p style="font-size: 13px; color: var(--text-secondary); margin-top: 4px;" id="dashboard_specialization_badge">مادة الرياضيات — التوجيهي العلمي</p>
|
|
</div>
|
|
|
|
<div class="stats-grid">
|
|
<div class="stat-card">
|
|
<span class="stat-label">الكورسات المنشورة</span>
|
|
<span class="stat-val val-cyan" id="stat_courses_count">3</span>
|
|
</div>
|
|
<div class="stat-card">
|
|
<span class="stat-label">الطلاب المتفاعلون</span>
|
|
<span class="stat-val val-purple" id="stat_students_count">840</span>
|
|
</div>
|
|
<div class="stat-card gold-glow">
|
|
<span class="stat-label">متوسط إتقان الطلاب</span>
|
|
<span class="stat-val val-gold" id="stat_mastery_avg">91.4%</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Tabs -->
|
|
<div class="tabs-nav">
|
|
<button class="tab-btn active" id="tab_btn_chat" onclick="switchDashboardTab('chat')">💬 الشات المباشر مع الطلاب (Workerman)</button>
|
|
<button class="tab-btn" id="tab_btn_courses" onclick="switchDashboardTab('courses')">📚 دوراتي وكويزات الفيديو التفاعلية</button>
|
|
<button class="tab-btn" id="tab_btn_exams" onclick="switchDashboardTab('exams')">📝 بنك الامتحانات وتقارير الذكاء الاصطناعي</button>
|
|
</div>
|
|
|
|
<!-- TAB 1: Real-time Chat -->
|
|
<div id="tab_chat_content" class="studio-card">
|
|
<div class="chat-container">
|
|
<!-- Sidebar: Conversations -->
|
|
<div class="chat-sidebar">
|
|
<div class="chat-sidebar-header">
|
|
<span>قائمة الطلاب (المحادثات النشطة)</span>
|
|
</div>
|
|
<div class="conversations-list" id="conv_list_container">
|
|
<!-- Loaded via API -->
|
|
<div style="padding: 20px; text-align: center; color: var(--text-muted); font-size: 12px;">جارٍ تحميل المحادثات...</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Main Chat Screen -->
|
|
<div class="chat-main">
|
|
<div class="chat-main-header">
|
|
<div>
|
|
<span style="font-size: 14px; font-weight: 800;" id="active_chat_user_name">اختر طالباً لبدء المحادثة</span>
|
|
<span style="font-size: 11px; color: var(--accent-cyan); display: block;" id="active_chat_user_status">متصل عبر Workerman 🟢</span>
|
|
</div>
|
|
<span id="active_chat_typing" style="font-size: 11.5px; color: var(--accent-gold); display: none;">الطالب يكتب الآن...</span>
|
|
</div>
|
|
|
|
<div class="chat-messages" id="chat_messages_area">
|
|
<div style="text-align: center; color: var(--text-muted); font-size: 12px; margin-top: 100px;">
|
|
حدد طالباً من القائمة الجانبية للتواصل المباشر والإجابة عن استفسارات الدروس.
|
|
</div>
|
|
</div>
|
|
|
|
<div class="chat-input-bar">
|
|
<input type="text" id="teacher_chat_input" placeholder="اكتب ردك وتوضيحك للطالب..." class="input-text" style="background: var(--bg-input);" onkeypress="if(event.key==='Enter') sendTeacherMessage()">
|
|
<button type="button" onclick="sendTeacherMessage()" class="btn-primary" style="width: auto; padding: 0 24px; font-size: 13px;">إرسال ↵</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- TAB 2: Courses & Dual Video Upload (API & Bunny Stream) -->
|
|
<div id="tab_courses_content" class="studio-card" style="display: none;">
|
|
<div style="display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; flex-wrap: wrap; gap: 12px;">
|
|
<div>
|
|
<h3 style="font-size: 18px; font-weight: 900;">إدارة الحصص والفيديوهات التعليمية (Direct API & Bunny Stream) 🎬</h3>
|
|
<p style="font-size: 12px; color: var(--text-muted); margin-top: 4px;">رفع وبث الفيديوهات بالطريقتين مع التشفير وتثبيت نقاط الفحص السقراطي داخل الفيديو.</p>
|
|
</div>
|
|
<div style="display: flex; gap: 10px;">
|
|
<button type="button" onclick="switchVideoUploadMode('api')" id="btn_mode_api" class="btn-primary" style="width: auto; padding: 8px 18px; font-size: 12px; background: linear-gradient(135deg, #0284C7, #0369A1);">1. الرفع المباشر عبر السيرفر ⚡</button>
|
|
<button type="button" onclick="switchVideoUploadMode('bunny')" id="btn_mode_bunny" class="btn-primary" style="width: auto; padding: 8px 18px; font-size: 12px; background: rgba(255,255,255,0.06); border: 1px solid var(--border);">2. ربط Bunny Stream CDN 🐰</button>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- UPLOADER BOX 1: Direct API Upload -->
|
|
<div id="uploader_box_api" style="background: rgba(11, 19, 43, 0.85); border: 1px solid rgba(56, 189, 248, 0.3); border-radius: 18px; padding: 24px; margin-bottom: 24px; box-shadow: 0 10px 30px rgba(0,0,0,0.4);">
|
|
<div style="display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px;">
|
|
<h4 style="font-size: 15px; font-weight: 800; color: var(--accent-cyan);">⚡ الرفع المباشر والتلقائي عبر السيرفر (Direct API Stream)</h4>
|
|
<span style="font-size: 11px; background: rgba(56,189,248,0.1); color: var(--accent-cyan); padding: 3px 10px; border-radius: 6px; font-weight: 700;">HTTP 206 Partial Content</span>
|
|
</div>
|
|
|
|
<form id="form_direct_upload" onsubmit="handleDirectVideoUpload(event)">
|
|
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px;">
|
|
<div class="form-group">
|
|
<label class="form-label">الدورة التدريبية</label>
|
|
<select id="direct_upload_course_select" class="input-text" required>
|
|
<option value="1">الرياضيات العلمي — توجيهي 2008 (المستوى الثالث)</option>
|
|
</select>
|
|
</div>
|
|
<div class="form-group">
|
|
<label class="form-label">عنوان الحصة / الدرس</label>
|
|
<input type="text" id="direct_upload_title" placeholder="مثال: الدرس 1 — مفهوم النهايات والاتصال" class="input-text" required>
|
|
</div>
|
|
<div class="form-group">
|
|
<label class="form-label">ترتيب الدرس</label>
|
|
<input type="number" id="direct_upload_seq" value="1" min="1" class="input-text">
|
|
</div>
|
|
</div>
|
|
|
|
<div class="form-group" style="margin-top: 12px;">
|
|
<label class="form-label">ملف الفيديو (MP4, WebM, MOV - حتى 2GB)</label>
|
|
<div style="border: 2px dashed rgba(56, 189, 248, 0.4); border-radius: 14px; padding: 24px; text-align: center; background: rgba(0,0,0,0.2); cursor: pointer;" onclick="document.getElementById('direct_video_file').click()">
|
|
<div style="font-size: 28px; margin-bottom: 8px;">🎬</div>
|
|
<div style="font-size: 13px; font-weight: 700; color: #FFFFFF;" id="file_selected_label">اضغط لاختيار ملف الفيديو أو اسحبه وأفلته هنا</div>
|
|
<div style="font-size: 11px; color: var(--text-muted); margin-top: 4px;">يتم حفظه تلقائياً في مسار السيرفر الآمن وبثه تدفقياً عبر الـ API</div>
|
|
<input type="file" id="direct_video_file" accept="video/mp4,video/webm,video/quicktime,video/x-matroska" style="display: none;" onchange="onVideoFileSelected(this)">
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Progress Bar -->
|
|
<div id="upload_progress_container" style="display: none; margin-top: 16px;">
|
|
<div style="display: flex; justify-content: space-between; font-size: 12px; margin-bottom: 6px;">
|
|
<span id="upload_progress_text" style="color: var(--accent-cyan); font-weight: 700;">جارٍ رفع الفيديو... 0%</span>
|
|
<span id="upload_progress_bytes" style="color: var(--text-muted);"></span>
|
|
</div>
|
|
<div style="height: 8px; background: rgba(255,255,255,0.1); border-radius: 4px; overflow: hidden;">
|
|
<div id="upload_progress_bar" style="width: 0%; height: 100%; background: linear-gradient(90deg, #38BDF8, #00F5D4); transition: width 0.2s ease;"></div>
|
|
</div>
|
|
</div>
|
|
|
|
<button type="submit" id="btn_submit_direct_upload" class="btn-primary" style="margin-top: 18px; width: auto; padding: 12px 32px; font-size: 13px;">بدء رفع وحفظ الفيديو الآن 🚀</button>
|
|
</form>
|
|
</div>
|
|
|
|
<!-- UPLOADER BOX 2: Bunny Stream CDN -->
|
|
<div id="uploader_box_bunny" style="display: none; background: rgba(11, 19, 43, 0.85); border: 1px solid rgba(245, 158, 11, 0.3); border-radius: 18px; padding: 24px; margin-bottom: 24px; box-shadow: 0 10px 30px rgba(0,0,0,0.4);">
|
|
<div style="display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px;">
|
|
<h4 style="font-size: 15px; font-weight: 800; color: var(--accent-gold);">🐰 الربط مع شبكة Bunny.net Stream (Cloud CDN & Token DRM)</h4>
|
|
<span style="font-size: 11px; background: rgba(245,158,11,0.1); color: var(--accent-gold); padding: 3px 10px; border-radius: 6px; font-weight: 700;">HLS + SHA256 DRM</span>
|
|
</div>
|
|
|
|
<form id="form_bunny_link" onsubmit="handleBunnyVideoLink(event)">
|
|
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px;">
|
|
<div class="form-group">
|
|
<label class="form-label">الدورة التدريبية</label>
|
|
<select id="bunny_course_select" class="input-text" required>
|
|
<option value="1">الرياضيات العلمي — توجيهي 2008 (المستوى الثالث)</option>
|
|
</select>
|
|
</div>
|
|
<div class="form-group">
|
|
<label class="form-label">عنوان الحصة / الدرس</label>
|
|
<input type="text" id="bunny_lesson_title" placeholder="مثال: الدرس 2 — مشتقة ضرب اقترانين" class="input-text" required>
|
|
</div>
|
|
<div class="form-group">
|
|
<label class="form-label">معرف فيديو Bunny Stream (Video GUID)</label>
|
|
<div style="display: flex; gap: 8px;">
|
|
<input type="text" id="bunny_video_id_input" placeholder="e.g. 78a9c12b-34ef-..." class="input-text" style="font-family: monospace;" required>
|
|
<button type="button" onclick="handleBunnyCreateVideo()" class="btn-primary" style="width: auto; padding: 0 14px; font-size: 11px; background: #D97706; white-space: nowrap;">+ توليد GUID</button>
|
|
</div>
|
|
</div>
|
|
<div class="form-group">
|
|
<label class="form-label">مدة الفيديو المقدرة (بالثواني)</label>
|
|
<input type="number" id="bunny_duration_input" value="1800" class="input-text">
|
|
</div>
|
|
</div>
|
|
<button type="submit" id="btn_submit_bunny_link" class="btn-primary" style="margin-top: 18px; width: auto; padding: 12px 32px; font-size: 13px; background: linear-gradient(135deg, #F59E0B, #D97706);">حفظ وربط درس Bunny Stream ✓</button>
|
|
</form>
|
|
</div>
|
|
|
|
<!-- IN-VIDEO SOCRATIC CHECKPOINTS -->
|
|
<div style="background: rgba(15, 23, 42, 0.8); border: 1px solid var(--border); border-radius: 18px; padding: 24px;">
|
|
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; flex-wrap: wrap; gap: 8px;">
|
|
<h4 style="font-size: 15px; font-weight: 800; color: var(--accent-cyan);">+ تثبيت نقطة فحص معرفي سقراطي (Socratic Checkpoint) في الفيديو</h4>
|
|
<span style="font-size: 11px; background: rgba(56,189,248,0.1); color: var(--accent-cyan); padding: 3px 10px; border-radius: 6px;">محرك التثبيت الصدمي والعلاجي 🧠</span>
|
|
</div>
|
|
|
|
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px;">
|
|
<div class="form-group">
|
|
<label class="form-label">الدرس المستهدف</label>
|
|
<select id="checkpoint_lesson_select" class="input-text">
|
|
<option value="1">الدرس 1: قواعد الاشتقاق الأساسية</option>
|
|
<option value="2">الدرس 2: مشتقات الاقترانات المثلثية</option>
|
|
</select>
|
|
</div>
|
|
<div class="form-group">
|
|
<label class="form-label">توقيت ظهور السؤال (دقيقة:ثانية)</label>
|
|
<input type="text" id="checkpoint_timestamp" value="00:15" placeholder="00:15" class="input-text" style="color: var(--accent-cyan); font-family: monospace;">
|
|
</div>
|
|
<div class="form-group">
|
|
<label class="form-label">عقوبة الإرجاع عند الخطأ</label>
|
|
<select id="checkpoint_rewind_select" class="input-text">
|
|
<option value="45">إرجاع الطالب 45 ثانية للخلف (موصى به)</option>
|
|
<option value="60">إرجاع الطالب 60 ثانية</option>
|
|
<option value="30">إرجاع الطالب 30 ثانية</option>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="form-group" style="margin-top: 8px;">
|
|
<label class="form-label">نص السؤال السقراطي الفوري</label>
|
|
<input type="text" id="checkpoint_question_input" value="إذا كان f(x) = sin(3x)، فما هي قيمة المشتقة f'(x)؟" placeholder="اكتب نص السؤال لفحص فهم الفكرة..." class="input-text">
|
|
</div>
|
|
|
|
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px;">
|
|
<div class="form-group">
|
|
<label class="form-label">الخيار (أ)</label>
|
|
<input type="text" id="cp_opt_0" value="3 cos(3x)" class="input-text">
|
|
</div>
|
|
<div class="form-group">
|
|
<label class="form-label">الخيار (ب)</label>
|
|
<input type="text" id="cp_opt_1" value="cos(3x)" class="input-text">
|
|
</div>
|
|
<div class="form-group">
|
|
<label class="form-label">الخيار (ج)</label>
|
|
<input type="text" id="cp_opt_2" value="-3 cos(3x)" class="input-text">
|
|
</div>
|
|
<div class="form-group">
|
|
<label class="form-label">الخيار (د)</label>
|
|
<input type="text" id="cp_opt_3" value="3 sin(3x)" class="input-text">
|
|
</div>
|
|
</div>
|
|
|
|
<div style="display: flex; align-items: center; justify-content: space-between; margin-top: 14px; flex-wrap: wrap; gap: 12px;">
|
|
<div class="form-group" style="margin: 0; min-width: 220px;">
|
|
<label class="form-label">الإجابة الصحيحة المعتمدة</label>
|
|
<select id="cp_correct_idx" class="input-text" style="color: var(--accent-gold); font-weight: 700;">
|
|
<option value="0">الخيار (أ) هو الصحيح ✓</option>
|
|
<option value="1">الخيار (ب) هو الصحيح ✓</option>
|
|
<option value="2">الخيار (ج) هو الصحيح ✓</option>
|
|
<option value="3">الخيار (د) هو الصحيح ✓</option>
|
|
</select>
|
|
</div>
|
|
<button type="button" id="btn_save_checkpoint" onclick="handleSaveCheckpoint()" class="btn-primary" style="width: auto; padding: 12px 32px; font-size: 13px;">تثبيت النقطة في محرك التثبيت المعرفي ✓</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- TAB 3: Exams & AI Reports -->
|
|
<div id="tab_exams_content" class="studio-card" style="display: none;">
|
|
<div style="display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px;">
|
|
<div>
|
|
<h3 style="font-size: 18px; font-weight: 900;">بنك الامتحانات والتقييم المعرفي الذكي 📝</h3>
|
|
<p style="font-size: 12px; color: var(--text-muted); margin-top: 4px;">متابعة نتائج امتحانات الدروس، امتحانات الوحدات، والامتحانات النهائية المحاكية للوزاري.</p>
|
|
</div>
|
|
</div>
|
|
|
|
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px;">
|
|
<div style="background: rgba(11,19,43,0.8); border: 1px solid var(--border); border-radius: 16px; padding: 20px;">
|
|
<span style="font-size: 11px; font-weight: 800; color: var(--accent-cyan); background: rgba(0,245,212,0.1); padding: 2px 8px; border-radius: 6px;">امتحان درس</span>
|
|
<h4 style="font-size: 16px; font-weight: 800; margin: 8px 0 4px 0;">امتحان قواعد الاشتقاق</h4>
|
|
<p style="font-size: 12px; color: var(--text-muted);">10 أسئلة • 30 دقيقة • اجتازه 740 طالباً</p>
|
|
</div>
|
|
|
|
<div style="background: rgba(11,19,43,0.8); border: 1px solid var(--border); border-radius: 16px; padding: 20px;">
|
|
<span style="font-size: 11px; font-weight: 800; color: var(--accent-purple); background: rgba(167,139,250,0.1); padding: 2px 8px; border-radius: 6px;">امتحان وحدة</span>
|
|
<h4 style="font-size: 16px; font-weight: 800; margin: 8px 0 4px 0;">امتحان وحدة التفاضل وتطبيقاته</h4>
|
|
<p style="font-size: 12px; color: var(--text-muted);">25 سؤالاً • 60 دقيقة • محاكاة معيارية</p>
|
|
</div>
|
|
|
|
<div style="background: rgba(11,19,43,0.8); border: 1px solid rgba(255,209,102,0.4); border-radius: 16px; padding: 20px;">
|
|
<span style="font-size: 11px; font-weight: 800; color: var(--accent-gold); background: rgba(255,209,102,0.1); padding: 2px 8px; border-radius: 6px;">ذكاء اصطناعي تكيفي</span>
|
|
<h4 style="font-size: 16px; font-weight: 800; margin: 8px 0 4px 0;">امتحان سد الثغرات التلقائي</h4>
|
|
<p style="font-size: 12px; color: var(--text-muted);">توليد فوري لأسئلة مخصصة لكل طالب حسب أخطائه</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
</main>
|
|
|
|
<!-- Footer -->
|
|
<footer>
|
|
<div class="container">
|
|
<div style="display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px;">
|
|
<span>منصة صَقِل التعليمية — نظام استوديو المعلمين المعتمد © 2026</span>
|
|
<span style="color: var(--accent-cyan);">الخادم متصل ومشفر بـ Workerman & WSS 🔒</span>
|
|
</div>
|
|
</div>
|
|
</footer>
|
|
|
|
<!-- Logic Controller with Full Real-time WebSocket Client -->
|
|
<script>
|
|
let wsSocket = null;
|
|
let activeRecipientId = null;
|
|
let countdownTimer = null;
|
|
let timerSeconds = 0;
|
|
|
|
document.addEventListener('DOMContentLoaded', async () => {
|
|
const token = localStorage.getItem('saqel_teacher_jwt');
|
|
const cachedUser = localStorage.getItem('saqel_teacher_user');
|
|
if (token) {
|
|
if (cachedUser) {
|
|
try {
|
|
const u = JSON.parse(cachedUser);
|
|
renderDashboard(u, { specialization: u.specialization || 'المعلم المعتمد' });
|
|
} catch (e) {}
|
|
}
|
|
initWebSocket(token);
|
|
await checkTeacherSession(token);
|
|
}
|
|
});
|
|
|
|
let wsPingInterval = null;
|
|
|
|
function initWebSocket(token) {
|
|
if (!token) return;
|
|
const wsProtocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
|
|
const wsUrl = `${wsProtocol}//${window.location.host}/ws`;
|
|
|
|
if (wsSocket && (wsSocket.readyState === WebSocket.OPEN || wsSocket.readyState === WebSocket.CONNECTING)) {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
wsSocket = new WebSocket(wsUrl);
|
|
|
|
wsSocket.onopen = () => {
|
|
console.log('⚡ Connected to Saqel Workerman Gateway');
|
|
wsSocket.send(JSON.stringify({
|
|
event: 'auth',
|
|
data: { token: token }
|
|
}));
|
|
|
|
// Heartbeat keep-alive every 20s
|
|
clearInterval(wsPingInterval);
|
|
wsPingInterval = setInterval(() => {
|
|
if (wsSocket && wsSocket.readyState === WebSocket.OPEN) {
|
|
wsSocket.send(JSON.stringify({ event: 'ping' }));
|
|
}
|
|
}, 20000);
|
|
};
|
|
|
|
wsSocket.onmessage = (event) => {
|
|
try {
|
|
const msg = JSON.parse(event.data);
|
|
handleIncomingWsEvent(msg);
|
|
} catch (e) {
|
|
console.error('WS Parse error:', e);
|
|
}
|
|
};
|
|
|
|
wsSocket.onclose = () => {
|
|
updateWsStatus(false);
|
|
clearInterval(wsPingInterval);
|
|
setTimeout(() => {
|
|
const currentToken = localStorage.getItem('saqel_teacher_jwt');
|
|
if (currentToken) initWebSocket(currentToken);
|
|
}, 5000);
|
|
};
|
|
|
|
wsSocket.onerror = (err) => {
|
|
updateWsStatus(false);
|
|
};
|
|
} catch (e) {
|
|
console.error('WS Connection failed:', e);
|
|
updateWsStatus(false);
|
|
}
|
|
}
|
|
|
|
function updateWsStatus(isOnline) {
|
|
const badge = document.getElementById('ws_status_badge');
|
|
const text = document.getElementById('ws_status_text');
|
|
if (!badge || !text) return;
|
|
if (isOnline) {
|
|
badge.className = 'ws-badge ws-online';
|
|
text.textContent = 'Workerman متصل 🟢';
|
|
} else {
|
|
badge.className = 'ws-badge ws-offline';
|
|
text.textContent = 'Workerman غير متصل 🔴';
|
|
}
|
|
}
|
|
|
|
// ==========================================
|
|
// Luxury Audio Chime & Real-time Notifications
|
|
// ==========================================
|
|
function playChimeNotification() {
|
|
try {
|
|
const ctx = new (window.AudioContext || window.webkitAudioContext)();
|
|
const now = ctx.currentTime;
|
|
|
|
// Tone 1: High crisp bell (D5)
|
|
const osc1 = ctx.createOscillator();
|
|
const gain1 = ctx.createGain();
|
|
osc1.type = 'sine';
|
|
osc1.frequency.setValueAtTime(587.33, now);
|
|
gain1.gain.setValueAtTime(0.2, now);
|
|
gain1.gain.exponentialRampToValueAtTime(0.001, now + 0.35);
|
|
osc1.connect(gain1);
|
|
gain1.connect(ctx.destination);
|
|
osc1.start(now);
|
|
osc1.stop(now + 0.35);
|
|
|
|
// Tone 2: Harmonic resolution (A5)
|
|
const osc2 = ctx.createOscillator();
|
|
const gain2 = ctx.createGain();
|
|
osc2.type = 'sine';
|
|
osc2.frequency.setValueAtTime(880.00, now + 0.09);
|
|
gain2.gain.setValueAtTime(0.25, now + 0.09);
|
|
gain2.gain.exponentialRampToValueAtTime(0.001, now + 0.55);
|
|
osc2.connect(gain2);
|
|
gain2.connect(ctx.destination);
|
|
osc2.start(now + 0.09);
|
|
osc2.stop(now + 0.55);
|
|
} catch (e) {
|
|
console.warn('Audio Context note:', e);
|
|
}
|
|
}
|
|
|
|
function showLuxuryToast(title, body, icon = '💬') {
|
|
let container = document.getElementById('saqel_toast_stack');
|
|
if (!container) {
|
|
container = document.createElement('div');
|
|
container.id = 'saqel_toast_stack';
|
|
container.style.cssText = 'position: fixed; top: 24px; left: 24px; z-index: 99999; display: flex; flex-direction: column; gap: 10px; pointer-events: none; direction: rtl;';
|
|
document.body.appendChild(container);
|
|
}
|
|
|
|
const toast = document.createElement('div');
|
|
toast.style.cssText = `
|
|
pointer-events: auto;
|
|
min-width: 280px;
|
|
max-width: 380px;
|
|
background: rgba(22, 27, 34, 0.92);
|
|
backdrop-filter: blur(24px);
|
|
-webkit-backdrop-filter: blur(24px);
|
|
border: 1px solid rgba(255, 255, 255, 0.15);
|
|
border-right: 4px solid var(--accent-gold, #F59E0B);
|
|
border-radius: 16px;
|
|
padding: 14px 18px;
|
|
box-shadow: 0 20px 40px rgba(0, 0, 0, 0.6), 0 0 25px rgba(245, 158, 11, 0.2);
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 12px;
|
|
animation: toastSlideIn 0.35s cubic-bezier(0.16, 1, 0.3, 1) forwards;
|
|
cursor: pointer;
|
|
`;
|
|
|
|
toast.innerHTML = `
|
|
<div style="font-size: 24px;">${icon}</div>
|
|
<div style="flex: 1; min-width: 0;">
|
|
<div style="font-size: 13px; font-weight: 700; color: #FFFFFF; margin-bottom: 2px;">${escapeHtml(title)}</div>
|
|
<div style="font-size: 12px; color: var(--text-muted, #94A3B8); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">${escapeHtml(body)}</div>
|
|
</div>
|
|
`;
|
|
|
|
container.appendChild(toast);
|
|
|
|
setTimeout(() => {
|
|
toast.style.opacity = '0';
|
|
toast.style.transform = 'translateX(-30px)';
|
|
toast.style.transition = 'all 0.3s ease';
|
|
setTimeout(() => toast.remove(), 300);
|
|
}, 5000);
|
|
}
|
|
|
|
function triggerDesktopNotification(title, body) {
|
|
if ('Notification' in window && Notification.permission === 'granted') {
|
|
try {
|
|
new Notification(title, {
|
|
body: body,
|
|
icon: '/favicon.ico'
|
|
});
|
|
} catch (e) {}
|
|
}
|
|
}
|
|
|
|
function handleIncomingWsEvent(msg) {
|
|
const event = msg.event;
|
|
const data = msg.data;
|
|
|
|
if (event === 'authenticated') {
|
|
updateWsStatus(true);
|
|
} else if (event === 'chat_message') {
|
|
const senderId = parseInt(data.sender_id);
|
|
if (senderId === activeRecipientId) {
|
|
appendChatMessage({ ...data, is_mine: false });
|
|
}
|
|
|
|
playChimeNotification();
|
|
const senderEl = document.querySelector(`.conv-item[data-user-id="${senderId}"] .conv-name span`);
|
|
const senderName = senderEl ? senderEl.textContent : 'طالب';
|
|
showLuxuryToast(`رسالة جديدة من ${senderName}`, data.message || 'أرسل استفساراً جديداً');
|
|
triggerDesktopNotification(`صَقِل — رسالة من ${senderName}`, data.message || 'استفسار جديد');
|
|
|
|
loadConversations();
|
|
} else if (event === 'chat_sent') {
|
|
loadConversations();
|
|
} else if (event === 'user_typing') {
|
|
const typingSpan = document.getElementById('active_chat_typing');
|
|
if (typingSpan && msg.sender_id === activeRecipientId) {
|
|
typingSpan.style.display = msg.is_typing ? 'inline' : 'none';
|
|
}
|
|
} else if (event === 'drm_session_terminated') {
|
|
alert('⚠️ تم تسجيل الدخول من جهاز آخر. سيتم تسجيل خروجك لحماية حسابك.');
|
|
handleLogout();
|
|
}
|
|
}
|
|
|
|
function switchDashboardTab(tab) {
|
|
document.getElementById('tab_chat_content').style.display = (tab === 'chat') ? 'block' : 'none';
|
|
document.getElementById('tab_courses_content').style.display = (tab === 'courses') ? 'block' : 'none';
|
|
document.getElementById('tab_exams_content').style.display = (tab === 'exams') ? 'block' : 'none';
|
|
|
|
document.getElementById('tab_btn_chat').className = (tab === 'chat') ? 'tab-btn active' : 'tab-btn';
|
|
document.getElementById('tab_btn_courses').className = (tab === 'courses') ? 'tab-btn active' : 'tab-btn';
|
|
document.getElementById('tab_btn_exams').className = (tab === 'exams') ? 'tab-btn active' : 'tab-btn';
|
|
|
|
if (tab === 'chat') {
|
|
loadConversations();
|
|
}
|
|
}
|
|
|
|
function getAuthToken() {
|
|
return localStorage.getItem('saqel_teacher_jwt') || getCookie('saqel_teacher_jwt') || '';
|
|
}
|
|
|
|
function getCookie(name) {
|
|
const v = document.cookie.match('(^|;) ?' + name + '=([^;]*)(;|$)');
|
|
return v ? v[2] : null;
|
|
}
|
|
|
|
// 2. Load Conversations List via REST API
|
|
async function loadConversations() {
|
|
const token = getAuthToken();
|
|
const container = document.getElementById('conv_list_container');
|
|
if (!token) {
|
|
if (container) container.innerHTML = '<div style="padding: 20px; text-align: center; color: var(--text-muted); font-size: 12px;">يرجى تسجيل الدخول أولاً</div>';
|
|
return;
|
|
}
|
|
try {
|
|
const res = await fetch('/api/chat/conversations', {
|
|
headers: { 'Authorization': 'Bearer ' + token }
|
|
});
|
|
const text = await res.text();
|
|
let data;
|
|
try {
|
|
data = JSON.parse(text);
|
|
} catch (jsonErr) {
|
|
console.error('Conversations parse error:', jsonErr, 'Raw:', text);
|
|
if (container) container.innerHTML = '<div style="padding: 20px; text-align: center; color: #F87171; font-size: 12px;">خطأ في معالجة البيانات</div>';
|
|
return;
|
|
}
|
|
|
|
if (res.status === 401 || (data && data.error === 'Unauthorized')) {
|
|
if (container) container.innerHTML = '<div style="padding: 20px; text-align: center; color: #F87171; font-size: 12px;">انتهت الجلسة — يرجى تسجيل الدخول مجدداً</div>';
|
|
return;
|
|
}
|
|
|
|
if (res.ok && data.status === 'success') {
|
|
renderConversations(data.data || []);
|
|
} else {
|
|
console.warn('Load convs returned error payload:', data);
|
|
if (container) {
|
|
container.innerHTML = '<div style="padding: 20px; text-align: center; color: var(--text-muted); font-size: 12px;">' + (data.message || 'لا توجد محادثات نشطة') + '</div>';
|
|
}
|
|
}
|
|
} catch (e) {
|
|
console.error('Load convs network error:', e);
|
|
if (container) {
|
|
container.innerHTML = '<div style="padding: 20px; text-align: center; color: #F87171; font-size: 12px;">تعذر تحميل المحادثات</div>';
|
|
}
|
|
}
|
|
}
|
|
|
|
function escapeHtml(str) {
|
|
if (!str) return '';
|
|
const div = document.createElement('div');
|
|
div.textContent = str;
|
|
return div.innerHTML;
|
|
}
|
|
|
|
function renderConversations(convs) {
|
|
const container = document.getElementById('conv_list_container');
|
|
if (!container) return;
|
|
if (!convs || convs.length === 0) {
|
|
container.innerHTML = '<div style="padding: 20px; text-align: center; color: var(--text-muted); font-size: 12px;">لا يوجد طلاب مسجلون حالياً. سيظهر الطلاب هنا فور تسجيلهم.</div>';
|
|
return;
|
|
}
|
|
|
|
container.innerHTML = '';
|
|
convs.forEach(c => {
|
|
const item = document.createElement('div');
|
|
item.className = 'conv-item' + (c.user_id === activeRecipientId ? ' active' : '');
|
|
item.dataset.userId = c.user_id;
|
|
item.onclick = function() {
|
|
selectConversation(c.user_id, c.full_name);
|
|
};
|
|
item.innerHTML = `
|
|
<div class="conv-name">
|
|
<span>${escapeHtml(c.full_name)}</span>
|
|
${c.unread_count > 0 ? `<span class="unread-badge">${c.unread_count}</span>` : ''}
|
|
</div>
|
|
<div class="conv-preview">${escapeHtml(c.last_message || 'محادثة جديدة')}</div>
|
|
`;
|
|
container.appendChild(item);
|
|
});
|
|
|
|
// Auto-select first conversation if none is selected
|
|
if (!activeRecipientId && convs.length > 0) {
|
|
selectConversation(convs[0].user_id, convs[0].full_name);
|
|
}
|
|
}
|
|
|
|
async function selectConversation(userId, name) {
|
|
activeRecipientId = userId;
|
|
const nameEl = document.getElementById('active_chat_user_name');
|
|
if (nameEl) nameEl.textContent = name;
|
|
|
|
const items = document.querySelectorAll('.conv-item');
|
|
items.forEach(el => {
|
|
if (parseInt(el.dataset.userId) === userId) {
|
|
el.classList.add('active');
|
|
} else {
|
|
el.classList.remove('active');
|
|
}
|
|
});
|
|
|
|
const token = localStorage.getItem('saqel_teacher_jwt');
|
|
if (!token) return;
|
|
try {
|
|
const res = await fetch(`/api/chat/messages?other_user_id=${userId}`, {
|
|
headers: { 'Authorization': 'Bearer ' + token }
|
|
});
|
|
const data = await res.json();
|
|
if (res.ok && data.status === 'success' && data.data) {
|
|
const messagesArea = document.getElementById('chat_messages_area');
|
|
messagesArea.innerHTML = '';
|
|
const msgs = data.data.messages || [];
|
|
if (msgs.length === 0) {
|
|
messagesArea.innerHTML = '<div style="text-align: center; color: var(--text-muted); font-size: 13px; margin-top: 60px;">بدء المحادثة مع الطالب ' + escapeHtml(name) + ' — اكتب ردك بالأسفل.</div>';
|
|
} else {
|
|
msgs.forEach(msg => appendChatMessage(msg));
|
|
}
|
|
}
|
|
} catch (e) {
|
|
console.error('Fetch messages error:', e);
|
|
}
|
|
}
|
|
|
|
function appendChatMessage(msg) {
|
|
const messagesArea = document.getElementById('chat_messages_area');
|
|
const isMine = msg.is_mine || (msg.sender_id !== activeRecipientId);
|
|
const div = document.createElement('div');
|
|
div.className = `chat-msg ${isMine ? 'teacher' : 'student'}`;
|
|
div.innerHTML = `
|
|
<div>${msg.message}</div>
|
|
<span class="chat-time">${msg.created_at || 'الآن'}</span>
|
|
`;
|
|
messagesArea.appendChild(div);
|
|
messagesArea.scrollTop = messagesArea.scrollHeight;
|
|
}
|
|
|
|
async function sendTeacherMessage() {
|
|
const input = document.getElementById('teacher_chat_input');
|
|
const message = input.value.trim();
|
|
if (!message || !activeRecipientId) {
|
|
if (!activeRecipientId) alert('يرجى اختيار طالب من القائمة الجانبية أولاً');
|
|
return;
|
|
}
|
|
|
|
input.value = '';
|
|
const token = localStorage.getItem('saqel_teacher_jwt');
|
|
|
|
// 1. Send via REST API to ensure DB write
|
|
try {
|
|
const res = await fetch('/api/chat/messages', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'Authorization': 'Bearer ' + token
|
|
},
|
|
body: JSON.stringify({
|
|
receiver_id: activeRecipientId,
|
|
message: message,
|
|
message_type: 'text'
|
|
})
|
|
});
|
|
const data = await res.json();
|
|
if (res.ok && data.data) {
|
|
appendChatMessage({ message: message, is_mine: true, created_at: 'الآن' });
|
|
}
|
|
} catch (err) {
|
|
console.error('REST teacher chat notice:', err);
|
|
appendChatMessage({ message: message, is_mine: true, created_at: 'الآن' });
|
|
}
|
|
|
|
// 2. Broadcast via WebSocket
|
|
if (wsSocket && wsSocket.readyState === WebSocket.OPEN) {
|
|
wsSocket.send(JSON.stringify({
|
|
event: 'chat_send',
|
|
data: {
|
|
receiver_id: activeRecipientId,
|
|
message: message,
|
|
message_type: 'text'
|
|
}
|
|
}));
|
|
}
|
|
}
|
|
|
|
// Standard Auth Handlers
|
|
function showError(msg) {
|
|
document.getElementById('alert_box_success').style.display = 'none';
|
|
const errBox = document.getElementById('alert_box_error');
|
|
document.getElementById('alert_error_msg').textContent = msg;
|
|
errBox.style.display = 'flex';
|
|
}
|
|
function showSuccess(msg) {
|
|
document.getElementById('alert_box_error').style.display = 'none';
|
|
const okBox = document.getElementById('alert_box_success');
|
|
document.getElementById('alert_success_msg').textContent = msg;
|
|
okBox.style.display = 'flex';
|
|
}
|
|
function clearAlerts() {
|
|
document.getElementById('alert_box_error').style.display = 'none';
|
|
document.getElementById('alert_box_success').style.display = 'none';
|
|
}
|
|
|
|
function switchToPhoneStep() {
|
|
document.getElementById('step_otp_container').style.display = 'none';
|
|
document.getElementById('step_onboarding_container').style.display = 'none';
|
|
document.getElementById('step_phone_container').style.display = 'block';
|
|
clearAlerts();
|
|
clearInterval(countdownTimer);
|
|
}
|
|
|
|
function switchToOtpStep(maskedPhone) {
|
|
document.getElementById('step_phone_container').style.display = 'none';
|
|
document.getElementById('step_onboarding_container').style.display = 'none';
|
|
document.getElementById('step_otp_container').style.display = 'block';
|
|
document.getElementById('otp_target_display').textContent = maskedPhone;
|
|
const otpInput = document.getElementById('teacher_otp_code');
|
|
otpInput.value = '';
|
|
otpInput.focus();
|
|
startTimer(60);
|
|
}
|
|
|
|
function switchToOnboardingStep() {
|
|
document.getElementById('step_phone_container').style.display = 'none';
|
|
document.getElementById('step_otp_container').style.display = 'none';
|
|
document.getElementById('step_onboarding_container').style.display = 'block';
|
|
}
|
|
|
|
function startTimer(seconds) {
|
|
timerSeconds = seconds;
|
|
clearInterval(countdownTimer);
|
|
const timerLabel = document.getElementById('resend_timer_label');
|
|
const resendBtn = document.getElementById('btn_resend');
|
|
resendBtn.style.display = 'none';
|
|
timerLabel.style.display = 'inline';
|
|
timerLabel.textContent = `إعادة الإرسال بعد (${timerSeconds}ث)`;
|
|
|
|
countdownTimer = setInterval(() => {
|
|
timerSeconds--;
|
|
if (timerSeconds > 0) {
|
|
timerLabel.textContent = `إعادة الإرسال بعد (${timerSeconds}ث)`;
|
|
} else {
|
|
clearInterval(countdownTimer);
|
|
timerLabel.style.display = 'none';
|
|
resendBtn.style.display = 'inline';
|
|
}
|
|
}, 1000);
|
|
}
|
|
|
|
async function handleSendOtp(e) {
|
|
if (e) e.preventDefault();
|
|
clearAlerts();
|
|
|
|
const phoneInput = document.getElementById('teacher_phone');
|
|
const sendBtn = document.getElementById('btn_send_otp');
|
|
const sendText = document.getElementById('btn_send_text');
|
|
const sendSpinner = document.getElementById('btn_send_spinner');
|
|
const phone = phoneInput.value.trim();
|
|
|
|
if (!phone) {
|
|
showError('يرجى إدخال رقم الهاتف');
|
|
phoneInput.focus();
|
|
return;
|
|
}
|
|
|
|
sendBtn.disabled = true;
|
|
sendText.textContent = 'جارٍ إرسال البطاقة عبر الواتساب...';
|
|
sendSpinner.style.display = 'block';
|
|
|
|
try {
|
|
const res = await fetch('/api/auth/otp/request', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ phone_number: phone, role: 'teacher' })
|
|
});
|
|
const data = await res.json();
|
|
if (res.ok && data.status === 'success') {
|
|
showSuccess(data.message || 'تم إرسال بطاقة التحقق عبر الواتساب!');
|
|
switchToOtpStep(data.data?.phone_masked || phone);
|
|
} else {
|
|
showError(data.message || 'فشل إرسال رمز التحقق.');
|
|
}
|
|
} catch (err) {
|
|
showError('حدث خطأ في الاتصال بالخادم.');
|
|
} finally {
|
|
sendBtn.disabled = false;
|
|
sendText.textContent = 'إرسال رمز الدخول (OTP) ←';
|
|
sendSpinner.style.display = 'none';
|
|
}
|
|
}
|
|
|
|
async function handleVerifyOtp(e) {
|
|
if (e) e.preventDefault();
|
|
clearAlerts();
|
|
|
|
const phone = document.getElementById('teacher_phone').value.trim();
|
|
const otpCode = document.getElementById('teacher_otp_code').value.trim();
|
|
const verifyBtn = document.getElementById('btn_verify_otp');
|
|
const verifyText = document.getElementById('btn_verify_text');
|
|
const verifySpinner = document.getElementById('btn_verify_spinner');
|
|
|
|
if (!otpCode || otpCode.length < 6) {
|
|
showError('يرجى إدخال رمز التحقق المكون من 6 أرقام');
|
|
return;
|
|
}
|
|
|
|
verifyBtn.disabled = true;
|
|
verifyText.textContent = 'جارٍ التحقق...';
|
|
verifySpinner.style.display = 'block';
|
|
|
|
try {
|
|
const res = await fetch('/api/auth/otp/verify', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ phone_number: phone, otp: otpCode, role: 'teacher' })
|
|
});
|
|
const data = await res.json();
|
|
if (res.ok && data.status === 'success' && data.data?.token) {
|
|
const token = data.data.token;
|
|
const user = data.data.user;
|
|
const profile = data.data.profile || {};
|
|
localStorage.setItem('saqel_teacher_jwt', token);
|
|
if (user) {
|
|
localStorage.setItem('saqel_teacher_user', JSON.stringify({ ...user, ...profile }));
|
|
}
|
|
document.cookie = "saqel_teacher_jwt=" + token + "; path=/; max-age=2592000; SameSite=Lax";
|
|
initWebSocket(token);
|
|
renderDashboard(user, profile);
|
|
await checkTeacherSession(token);
|
|
} else {
|
|
showError(data.message || 'رمز التحقق غير صحيح');
|
|
}
|
|
} catch (err) {
|
|
showError('حدث خطأ في التحقق من الرمز.');
|
|
} finally {
|
|
verifyBtn.disabled = false;
|
|
verifyText.textContent = 'تأكيد الدخول للاستوديو 🎓';
|
|
verifySpinner.style.display = 'none';
|
|
}
|
|
}
|
|
|
|
async function handleCompleteOnboarding(e) {
|
|
if (e) e.preventDefault();
|
|
const token = localStorage.getItem('saqel_teacher_jwt');
|
|
const fullName = document.getElementById('onboard_fullname').value.trim();
|
|
const spec = document.getElementById('onboard_specialization').value;
|
|
const password = document.getElementById('onboard_password').value.trim();
|
|
|
|
if (!fullName || !password || password.length < 8) {
|
|
showError('يرجى تعبئة كافة الحقول وكلمة مرور 8 خانات على الأقل');
|
|
return;
|
|
}
|
|
|
|
try {
|
|
const res = await fetch('/api/teacher/profile/setup', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'Authorization': 'Bearer ' + token
|
|
},
|
|
body: JSON.stringify({ full_name: fullName, specialization: spec, password: password })
|
|
});
|
|
const data = await res.json();
|
|
if (res.ok && data.status === 'success') {
|
|
const u = { full_name: fullName, specialization: spec };
|
|
localStorage.setItem('saqel_teacher_user', JSON.stringify(u));
|
|
renderDashboard(u, { specialization: spec });
|
|
}
|
|
} catch (e) {
|
|
showError('فشل حفظ الملف.');
|
|
}
|
|
}
|
|
|
|
async function checkTeacherSession(token) {
|
|
try {
|
|
const res = await fetch('/api/teacher/profile/status', {
|
|
headers: { 'Authorization': 'Bearer ' + token }
|
|
});
|
|
if (res.status === 401) {
|
|
handleLogout();
|
|
return;
|
|
}
|
|
const data = await res.json();
|
|
if (res.ok && data.status === 'success') {
|
|
if (data.user) {
|
|
localStorage.setItem('saqel_teacher_user', JSON.stringify({ ...data.user, ...data.profile }));
|
|
}
|
|
renderDashboard(data.user, data.profile);
|
|
}
|
|
} catch (e) {
|
|
console.error('Session check notice:', e);
|
|
}
|
|
}
|
|
|
|
function renderDashboard(user, profile) {
|
|
document.getElementById('auth_container').style.display = 'none';
|
|
document.getElementById('dashboard_container').style.display = 'block';
|
|
document.getElementById('switch_to_student_link').style.display = 'none';
|
|
document.getElementById('auth_user_badge').style.display = 'flex';
|
|
|
|
const name = user?.full_name || 'أستاذنا الفاضل';
|
|
const spec = profile?.specialization || user?.specialization || 'المعلم المعتمد';
|
|
|
|
document.getElementById('teacher_display_name').textContent = `أهلاً، ${name}`;
|
|
document.getElementById('dashboard_welcome_title').textContent = `أهلاً بك، يا ${name} 👨🏫`;
|
|
document.getElementById('dashboard_specialization_badge').textContent = `${spec} — استوديو صَقِل التفاعلي`;
|
|
|
|
loadConversations();
|
|
}
|
|
|
|
// ==========================================
|
|
// Video Storage & Bunny Stream Studio Handlers
|
|
// ==========================================
|
|
function switchVideoUploadMode(mode) {
|
|
const apiBox = document.getElementById('uploader_box_api');
|
|
const bunnyBox = document.getElementById('uploader_box_bunny');
|
|
const btnApi = document.getElementById('btn_mode_api');
|
|
const btnBunny = document.getElementById('btn_mode_bunny');
|
|
|
|
if (mode === 'api') {
|
|
apiBox.style.display = 'block';
|
|
bunnyBox.style.display = 'none';
|
|
btnApi.style.background = 'linear-gradient(135deg, #0284C7, #0369A1)';
|
|
btnApi.style.border = 'none';
|
|
btnBunny.style.background = 'rgba(255,255,255,0.06)';
|
|
btnBunny.style.border = '1px solid var(--border)';
|
|
} else {
|
|
apiBox.style.display = 'none';
|
|
bunnyBox.style.display = 'block';
|
|
btnBunny.style.background = 'linear-gradient(135deg, #F59E0B, #D97706)';
|
|
btnBunny.style.border = 'none';
|
|
btnApi.style.background = 'rgba(255,255,255,0.06)';
|
|
btnApi.style.border = '1px solid var(--border)';
|
|
}
|
|
}
|
|
|
|
function onVideoFileSelected(input) {
|
|
if (input.files && input.files[0]) {
|
|
const f = input.files[0];
|
|
const sizeMb = (f.size / (1024 * 1024)).toFixed(1);
|
|
document.getElementById('file_selected_label').textContent = `✅ تم اختيار: ${f.name} (${sizeMb} MB)`;
|
|
|
|
// Auto-fill title if empty
|
|
const titleInput = document.getElementById('direct_upload_title');
|
|
if (!titleInput.value) {
|
|
titleInput.value = f.name.replace(/\.[^/.]+$/, "");
|
|
}
|
|
}
|
|
}
|
|
|
|
function handleDirectVideoUpload(e) {
|
|
e.preventDefault();
|
|
const token = getAuthToken();
|
|
const fileInput = document.getElementById('direct_video_file');
|
|
const courseSelect = document.getElementById('direct_upload_course_select');
|
|
const titleInput = document.getElementById('direct_upload_title');
|
|
const seqInput = document.getElementById('direct_upload_seq');
|
|
|
|
if (!fileInput.files || !fileInput.files[0]) {
|
|
alert('يرجى اختيار ملف الفيديو أولاً');
|
|
return;
|
|
}
|
|
|
|
const formData = new FormData();
|
|
formData.append('video', fileInput.files[0]);
|
|
formData.append('course_id', courseSelect.value);
|
|
formData.append('title', titleInput.value);
|
|
formData.append('sequence_order', seqInput.value);
|
|
|
|
const progressContainer = document.getElementById('upload_progress_container');
|
|
const progressBar = document.getElementById('upload_progress_bar');
|
|
const progressText = document.getElementById('upload_progress_text');
|
|
const progressBytes = document.getElementById('upload_progress_bytes');
|
|
const submitBtn = document.getElementById('btn_submit_direct_upload');
|
|
|
|
progressContainer.style.display = 'block';
|
|
submitBtn.disabled = true;
|
|
submitBtn.textContent = 'جارٍ رفع الفيديو... ⏳';
|
|
|
|
const xhr = new XMLHttpRequest();
|
|
xhr.open('POST', '/api/teacher/videos/upload-direct', true);
|
|
xhr.setRequestHeader('Authorization', 'Bearer ' + token);
|
|
|
|
xhr.upload.onprogress = function(event) {
|
|
if (event.lengthComputable) {
|
|
const percent = Math.round((event.loaded / event.total) * 100);
|
|
progressBar.style.width = percent + '%';
|
|
progressText.textContent = `جارٍ رفع الفيديو... ${percent}%`;
|
|
const loadedMb = (event.loaded / (1024 * 1024)).toFixed(1);
|
|
const totalMb = (event.total / (1024 * 1024)).toFixed(1);
|
|
progressBytes.textContent = `${loadedMb}MB / ${totalMb}MB`;
|
|
}
|
|
};
|
|
|
|
xhr.onload = function() {
|
|
submitBtn.disabled = false;
|
|
submitBtn.textContent = 'بدء رفع وحفظ الفيديو الآن 🚀';
|
|
try {
|
|
const data = JSON.parse(xhr.responseText);
|
|
if (xhr.status >= 200 && xhr.status < 300 && data.status === 'success') {
|
|
showLuxuryToast('تم حفظ الفيديو بنجاح 🎬', data.message || 'تم إنشاء الدرس وحفظ الفيديو');
|
|
alert('✅ ' + data.message + '\nرابط البث المباشر: ' + data.data.stream_url);
|
|
document.getElementById('form_direct_upload').reset();
|
|
document.getElementById('file_selected_label').textContent = 'اضغط لاختيار ملف الفيديو أو اسحبه وأفلته هنا';
|
|
progressContainer.style.display = 'none';
|
|
loadTeacherCourses();
|
|
} else {
|
|
alert('❌ ' + (data.message || 'فشل رفع الفيديو'));
|
|
}
|
|
} catch (err) {
|
|
alert('❌ خطأ في معالجة استجابة السيرفر');
|
|
}
|
|
};
|
|
|
|
xhr.onerror = function() {
|
|
submitBtn.disabled = false;
|
|
submitBtn.textContent = 'بدء رفع وحفظ الفيديو الآن 🚀';
|
|
alert('❌ حدث خطأ في الاتصال أثناء رفع الفيديو');
|
|
};
|
|
|
|
xhr.send(formData);
|
|
}
|
|
|
|
async function handleBunnyCreateVideo() {
|
|
const token = getAuthToken();
|
|
const title = document.getElementById('bunny_lesson_title').value.trim() || 'درس جديد في الرياضيات';
|
|
const courseId = document.getElementById('bunny_course_select').value;
|
|
|
|
try {
|
|
const res = await fetch('/api/teacher/videos/bunny-create', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'Authorization': 'Bearer ' + token
|
|
},
|
|
body: JSON.stringify({ title: title, course_id: courseId })
|
|
});
|
|
const data = await res.json();
|
|
if (res.ok && data.status === 'success') {
|
|
document.getElementById('bunny_video_id_input').value = data.data.video_id;
|
|
showLuxuryToast('تم توليد المعرف في Bunny Stream 🐰', `GUID: ${data.data.video_id}`);
|
|
} else {
|
|
alert('خطأ: ' + (data.message || 'فشل الاتصال بـ Bunny Stream'));
|
|
}
|
|
} catch (err) {
|
|
console.error(err);
|
|
alert('خطأ في الاتصال بالخادم');
|
|
}
|
|
}
|
|
|
|
async function handleBunnyVideoLink(e) {
|
|
e.preventDefault();
|
|
const token = getAuthToken();
|
|
const courseId = document.getElementById('bunny_course_select').value;
|
|
const title = document.getElementById('bunny_lesson_title').value.trim();
|
|
const bunnyVideoId = document.getElementById('bunny_video_id_input').value.trim();
|
|
const duration = document.getElementById('bunny_duration_input').value;
|
|
|
|
try {
|
|
const res = await fetch('/api/teacher/videos/bunny-link', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'Authorization': 'Bearer ' + token
|
|
},
|
|
body: JSON.stringify({
|
|
course_id: courseId,
|
|
title: title,
|
|
bunny_video_id: bunnyVideoId,
|
|
duration_seconds: duration
|
|
})
|
|
});
|
|
const data = await res.json();
|
|
if (res.ok && data.status === 'success') {
|
|
showLuxuryToast('تم ربط الدرس بنجاح 🐰', data.message);
|
|
alert('✅ تم ربط الحصة بـ Bunny Stream وحمايتها بروابط التشفير الرقمي DRM!');
|
|
document.getElementById('form_bunny_link').reset();
|
|
loadTeacherCourses();
|
|
} else {
|
|
alert('خطأ: ' + (data.message || 'فشل حفظ الدرس'));
|
|
}
|
|
} catch (err) {
|
|
console.error(err);
|
|
alert('خطأ في الاتصال بالخادم');
|
|
}
|
|
}
|
|
|
|
async function loadTeacherCourses() {
|
|
const token = getAuthToken();
|
|
if (!token) return;
|
|
try {
|
|
const res = await fetch('/api/teacher/courses', {
|
|
headers: { 'Authorization': 'Bearer ' + token }
|
|
});
|
|
const data = await res.json();
|
|
if (res.ok && data.data && data.data.length > 0) {
|
|
const selects = [
|
|
document.getElementById('direct_upload_course_select'),
|
|
document.getElementById('bunny_course_select')
|
|
];
|
|
selects.forEach(sel => {
|
|
if (sel) {
|
|
sel.innerHTML = data.data.map(c => `
|
|
<option value="${c.id}">${c.title} (${c.semester || 'فصل أول'})</option>
|
|
`).join('');
|
|
}
|
|
});
|
|
}
|
|
} catch (e) {
|
|
console.error('Load courses note:', e);
|
|
}
|
|
}
|
|
|
|
async function handleSaveCheckpoint() {
|
|
const token = getAuthToken();
|
|
const lessonId = document.getElementById('checkpoint_lesson_select').value;
|
|
const tsStr = document.getElementById('checkpoint_timestamp').value.trim();
|
|
const question = document.getElementById('checkpoint_question_input').value.trim();
|
|
const rewind = parseInt(document.getElementById('checkpoint_rewind_select').value) || 45;
|
|
const correctIdx = parseInt(document.getElementById('cp_correct_idx').value) || 0;
|
|
|
|
// Parse MM:SS to seconds
|
|
let seconds = 15;
|
|
if (tsStr.includes(':')) {
|
|
const parts = tsStr.split(':');
|
|
seconds = (parseInt(parts[0]) || 0) * 60 + (parseInt(parts[1]) || 0);
|
|
} else {
|
|
seconds = parseInt(tsStr) || 15;
|
|
}
|
|
|
|
const options = [
|
|
document.getElementById('cp_opt_0').value.trim() || 'الخيار الأول',
|
|
document.getElementById('cp_opt_1').value.trim() || 'الخيار الثاني',
|
|
document.getElementById('cp_opt_2').value.trim() || 'الخيار الثالث',
|
|
document.getElementById('cp_opt_3').value.trim() || 'الخيار الرابع'
|
|
];
|
|
|
|
const btn = document.getElementById('btn_save_checkpoint');
|
|
btn.disabled = true;
|
|
btn.textContent = 'جارٍ الحفظ والتثبيت... ⏳';
|
|
|
|
try {
|
|
const res = await fetch('/api/teacher/lessons/checkpoints', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'Authorization': 'Bearer ' + token
|
|
},
|
|
body: JSON.stringify({
|
|
lesson_id: lessonId,
|
|
timestamp_seconds: seconds,
|
|
rewind_seconds: rewind,
|
|
question_text: question,
|
|
options: options,
|
|
correct_index: correctIdx
|
|
})
|
|
});
|
|
|
|
const data = await res.json();
|
|
btn.disabled = false;
|
|
btn.textContent = 'تثبيت النقطة في محرك التثبيت المعرفي ✓';
|
|
|
|
if (res.ok && data.status === 'success') {
|
|
showLuxuryToast('تم تثبيت النقطة السقراطية 🧠', `الدرس (${lessonId}) عند التوقيت (${tsStr})`);
|
|
alert('✅ ' + data.message + `\nالتوقيت: ${tsStr} (ثانية: ${seconds})\nعقوبة الإرجاع: ${rewind} ثانية`);
|
|
} else {
|
|
alert('❌ خطأ: ' + (data.message || 'فشل حفظ نقطة الفحص'));
|
|
}
|
|
} catch (err) {
|
|
btn.disabled = false;
|
|
btn.textContent = 'تثبيت النقطة في محرك التثبيت المعرفي ✓';
|
|
alert('❌ حدث خطأ في الاتصال بالخادم');
|
|
}
|
|
}
|
|
|
|
function handleLogout() {
|
|
localStorage.removeItem('saqel_teacher_jwt');
|
|
localStorage.removeItem('saqel_teacher_user');
|
|
document.cookie = "saqel_teacher_jwt=; path=/; max-age=0;";
|
|
if (wsSocket) wsSocket.close();
|
|
location.reload();
|
|
}
|
|
</script>
|
|
</body>
|
|
</html>
|
|
HTML;
|
|
}
|
|
}
|