Files
saqel/backend/app/Views/TeacherPortal.php
T

973 lines
53 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);">
<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 & In-Video Checkpoint Quizzes -->
<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;">
<div>
<h3 style="font-size: 18px; font-weight: 900;">إدارة الكورسات والحصص المربوطة بـ Bunny Stream 🎬</h3>
<p style="font-size: 12px; color: var(--text-muted); margin-top: 4px;">تحديد نقاط الكويز الصدمي داخل الفيديو بالدقيقة والثانية مع الإرجاع العلاجي.</p>
</div>
</div>
<div style="background: rgba(11, 19, 43, 0.8); border: 1px solid var(--border); border-radius: 16px; padding: 24px;">
<h4 style="font-size: 15px; font-weight: 800; color: var(--accent-gold); margin-bottom: 12px;">+ إضافة نقطة فحص فهم (Socratic Checkpoint) داخل الحصة</h4>
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 16px;">
<div>
<div class="form-group">
<label class="form-label">الدرس المستهدف</label>
<select class="input-text">
<option>الرياضيات العلمي — الدرس 4: قواعد الاشتقاق الأساسية</option>
<option>الرياضيات العلمي — الدرس 5: مشتقات الاقترانات المثلثية</option>
</select>
</div>
<div class="form-group">
<label class="form-label">توقيت ظهور السؤال داخل الفيديو (دقيقة:ثانية)</label>
<input type="text" value="08:30" class="input-text" style="color: var(--accent-cyan); font-family: monospace;">
</div>
</div>
<div>
<div class="form-group">
<label class="form-label">نص السؤال السقراطي</label>
<input type="text" placeholder="ما هي نتيجة اشتقاق المقدار المعروض؟" class="input-text">
</div>
<div class="form-group">
<label class="form-label">عقوبة الإرجاع عند الخطأ</label>
<select class="input-text">
<option>إرجاع الطالب 45 ثانية للخلف (موصى به)</option>
<option>إرجاع الطالب 60 ثانية</option>
</select>
</div>
</div>
</div>
<button type="button" onclick="alert('تم حفظ وتثبيت الكويز داخل مشغل الفيديو!')" class="btn-primary" style="width: auto; padding: 10px 24px; font-size: 13px;">حفظ النقطة التفاعلية ✓</button>
</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');
if (token) {
await checkTeacherSession(token);
initWebSocket(token);
}
});
// 1. Initialize Real-time WebSocket (Workerman)
function initWebSocket(token) {
if (!token) return;
const wsProtocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
const wsUrl = `${wsProtocol}//${window.location.host}/ws`;
try {
wsSocket = new WebSocket(wsUrl);
wsSocket.onopen = () => {
console.log('⚡ Connected to Saqel Workerman Gateway');
updateWsStatus(true);
wsSocket.send(JSON.stringify({
event: 'auth',
data: { token: token }
}));
};
wsSocket.onmessage = (event) => {
try {
const msg = JSON.parse(event.data);
handleIncomingWsEvent(msg);
} catch (e) {
console.error('WS Parse error:', e);
}
};
wsSocket.onclose = () => {
updateWsStatus(false);
// Reconnect after 3s
setTimeout(() => initWebSocket(token), 3000);
};
wsSocket.onerror = (err) => {
console.warn('WS Error:', 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 غير متصل 🔴';
}
}
function handleIncomingWsEvent(msg) {
const event = msg.event;
const data = msg.data;
if (event === 'chat_message' || event === 'chat_sent') {
appendChatMessage(data);
loadConversations(); // refresh sidebar
} 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();
}
}
// 2. Load Conversations List via REST API
async function loadConversations() {
const token = localStorage.getItem('saqel_teacher_jwt');
if (!token) return;
try {
const res = await fetch('/api/chat/conversations', {
headers: { 'Authorization': 'Bearer ' + token }
});
const data = await res.json();
if (res.ok && data.status === 'success') {
renderConversations(data.data);
}
} catch (e) {
console.error('Load convs error:', e);
}
}
function renderConversations(convs) {
const container = document.getElementById('conv_list_container');
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.map(c => `
<div class="conv-item ${c.user_id === activeRecipientId ? 'active' : ''}" onclick="selectConversation(${c.user_id}, '${c.full_name}')">
<div class="conv-name">
<span>${c.full_name}</span>
${c.unread_count > 0 ? `<span class="unread-badge">${c.unread_count}</span>` : ''}
</div>
<div class="conv-preview">${c.last_message || 'محادثة جديدة'}</div>
</div>
`).join('');
}
async function selectConversation(userId, name) {
activeRecipientId = userId;
document.getElementById('active_chat_user_name').textContent = name;
loadConversations();
const token = localStorage.getItem('saqel_teacher_jwt');
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') {
const messagesArea = document.getElementById('chat_messages_area');
messagesArea.innerHTML = '';
data.data.messages.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 = '';
// Try sending via Workerman WebSocket first
if (wsSocket && wsSocket.readyState === WebSocket.OPEN) {
wsSocket.send(JSON.stringify({
event: 'chat_send',
data: {
receiver_id: activeRecipientId,
message: message,
message_type: 'text'
}
}));
} else {
// Fallback to REST API
const token = localStorage.getItem('saqel_teacher_jwt');
await fetch('/api/chat/messages', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + token
},
body: JSON.stringify({
receiver_id: activeRecipientId,
message: message
})
});
appendChatMessage({ message: message, is_mine: true });
}
}
// 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;
localStorage.setItem('saqel_teacher_jwt', token);
initWebSocket(token);
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') {
renderDashboard({ full_name: fullName }, { specialization: spec });
}
} catch (e) {
showError('فشل حفظ الملف.');
}
}
async function checkTeacherSession(token) {
try {
const res = await fetch('/api/teacher/profile/status', {
headers: { 'Authorization': 'Bearer ' + token }
});
const data = await res.json();
if (res.ok && data.status === 'success') {
if (data.is_completed) {
renderDashboard(data.user, data.profile);
} else {
switchToOnboardingStep();
}
} else {
localStorage.removeItem('saqel_teacher_jwt');
}
} catch (e) {
console.error(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 || 'المعلم المعتمد';
document.getElementById('teacher_display_name').textContent = `أهلاً، ${name}`;
document.getElementById('dashboard_welcome_title').textContent = `أهلاً بك، يا ${name} 👨‍🏫`;
document.getElementById('dashboard_specialization_badge').textContent = `${spec} — استوديو صَقِل التفاعلي`;
loadConversations();
}
function handleLogout() {
localStorage.removeItem('saqel_teacher_jwt');
if (wsSocket) wsSocket.close();
location.reload();
}
</script>
</body>
</html>
HTML;
}
}