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

868 lines
47 KiB
PHP

<?php
namespace App\Views;
class StudentPortal
{
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: #00F5D4;
--text-primary: #FFFFFF;
--text-secondary: #CBD5E1;
--text-muted: #8E9FB8;
--accent-cyan: #00F5D4;
--accent-cyan-dark: #00BAA1;
--accent-gold: #FFD166;
--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(0, 245, 212, 0.06) 0%, transparent 40%),
radial-gradient(circle at 85% 85%, rgba(255, 209, 102, 0.04) 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-cyan), var(--accent-cyan-dark));
display: flex; align-items: center; justify-content: center;
color: #0B132B; font-size: 20px; font-weight: 900;
box-shadow: 0 0 20px rgba(0, 245, 212, 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(0, 245, 212, 0.12); color: var(--accent-cyan);
border: 1px solid rgba(0, 245, 212, 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-gold); }
.nav-link-highlight { color: var(--accent-gold); 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: 480px; 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(0, 245, 212, 0.4);
display: inline-flex; align-items: center; justify-content: center;
color: var(--accent-cyan); 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-cyan); box-shadow: 0 0 0 3px rgba(0, 245, 212, 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-cyan);
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, #00F5D4 0%, #00BAA1 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(0, 245, 212, 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-cyan { color: var(--accent-cyan); 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-cyan); border-color: rgba(0, 245, 212, 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(0, 245, 212, 0.15); border: 1px solid rgba(0, 245, 212, 0.4); color: var(--accent-cyan); }
/* Dashboard & Learning Center */
.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;
}
.readiness-box {
background: rgba(11, 19, 43, 0.85); border: 1px solid var(--border);
border-radius: 16px; padding: 14px 20px; display: flex; align-items: center; gap: 14px; min-width: 230px;
}
.gauge-circle {
width: 54px; height: 54px; border-radius: 50%; border: 4px solid var(--accent-cyan);
display: flex; align-items: center; justify-content: center; font-size: 17px; font-weight: 900;
color: var(--accent-cyan); box-shadow: 0 0 16px rgba(0, 245, 212, 0.3);
}
.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(0,245,212,0.15), rgba(0,186,161,0.15));
border-color: var(--accent-cyan); color: var(--accent-cyan); font-weight: 900;
}
.studio-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: 20px; padding: 28px; }
/* Video Interactive Experience */
.video-player-frame {
position: relative; width: 100%; aspect-ratio: 16/9; background: #000;
border-radius: 16px; overflow: hidden; border: 1px solid var(--border);
display: flex; align-items: center; justify-content: center;
}
.socratic-overlay {
position: absolute; inset: 0; background: rgba(11, 19, 43, 0.95); backdrop-filter: blur(8px);
display: flex; flex-direction: column; justify-content: center; align-items: center; padding: 30px;
z-index: 40; text-align: center;
}
.quiz-option-btn {
width: 100%; max-width: 500px; text-align: right; padding: 12px 18px; margin-bottom: 10px;
background: #16203D; border: 1px solid var(--border); border-radius: 12px; color: #FFFFFF;
font-size: 14px; font-weight: 700; cursor: pointer; transition: 0.2s;
}
.quiz-option-btn:hover { border-color: var(--accent-cyan); }
.quiz-option-btn.correct { background: rgba(16,185,129,0.2); border-color: #10B981; color: #6EE7B7; }
.quiz-option-btn.wrong { background: rgba(239,68,68,0.2); border-color: #EF4444; color: #FCA5A5; }
/* Student Live Chat with Teacher */
.student-chat-box {
height: 460px; background: rgba(11, 19, 43, 0.85); border: 1px solid var(--border);
border-radius: 16px; display: flex; flex-direction: column; justify-content: space-between; overflow: hidden;
}
.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-end; background: linear-gradient(135deg, #00F5D4, #00BAA1); color: #0B132B; font-weight: 700; border-bottom-left-radius: 2px; }
.chat-msg.teacher { align-self: flex-start; background: #1E2D5A; color: #E2E8F0; border-bottom-right-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; }
/* Watermark */
@keyframes bounce-watermark {
0%, 100% { transform: translate(10px, 10px); }
50% { transform: translate(140px, 80px); }
}
.watermark-anim {
position: fixed; bottom: 20px; left: 20px; z-index: 99; pointer-events: none; opacity: 0.35;
animation: bounce-watermark 12s infinite ease-in-out; background: rgba(0, 0, 0, 0.75);
border: 1px solid rgba(255, 255, 255, 0.2); padding: 4px 10px; border-radius: 6px;
font-family: monospace; font-size: 11px; color: var(--accent-cyan);
}
.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="/student" 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(0, 245, 212, 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="student_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="/teacher" class="nav-link" id="switch_to_teacher_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="M12 6.253v13m0-13C10.832 5.477 9.246 5 7.5 5S4.168 5.477 3 6.253v13C4.168 18.477 5.754 18 7.5 18s3.332.477 4.5 1.253m0-13C13.168 5.477 14.754 5 16.5 5c1.747 0 3.332.477 4.5 1.253v13C19.832 18.477 18.247 18 16.5 18c-1.746 0-3.332.477-4.5 1.253"></path>
</svg>
</div>
<h1 class="auth-title">ادخل لعالم التمكين والفهم</h1>
<p class="auth-subtitle">تسجيل دخول آمن وسريع عبر رمز الواتساب المعتمد</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">الاسم الكامل للطالب</label>
<input type="text" id="student_fullname" placeholder="مثال: أحمد محمد خالد" class="input-text">
</div>
<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="student_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-cyan); 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="student_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-cyan" style="display: none;">إعادة إرسال الرمز ↺</button>
</div>
</div>
</div>
</div>
<!-- ========================================== -->
<!-- 2. STUDENT DASHBOARD (AUTHENTICATED) -->
<!-- ========================================== -->
<div id="dashboard_container" style="width: 100%; display: none;">
<!-- Hero & Readiness Gauge -->
<div class="dashboard-hero">
<div>
<span style="display: inline-block; font-size: 11px; font-weight: 800; color: var(--accent-cyan); background: rgba(0,245,212,0.12); border: 1px solid rgba(0,245,212,0.3); padding: 4px 12px; border-radius: 999px; margin-bottom: 10px;">توجيهي 2008 — الفرع العلمي</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;">صقل الفهم، حل الأسئلة الوزارية، والتواصل الحي مع معلمك.</p>
</div>
<div class="readiness-box">
<div class="gauge-circle" id="readiness_gauge_val">87%</div>
<div>
<span style="font-size: 11px; font-weight: 700; color: var(--text-muted); display: block;">مؤشر الجاهزية للوزاري</span>
<span style="font-size: 12px; font-weight: 800; color: #34D399;">مستواك ممتاز ومستقر</span>
</div>
</div>
</div>
<!-- Tabs -->
<div class="tabs-nav">
<button class="tab-btn active" id="tab_btn_lessons" onclick="switchStudentTab('lessons')">🎬 الحصص ومشغل الفيديو السقراطي</button>
<button class="tab-btn" id="tab_btn_chat" onclick="switchStudentTab('chat')">💬 اسأل معلم المادة مباشرة (Workerman)</button>
<button class="tab-btn" id="tab_btn_exams" onclick="switchStudentTab('exams')">📝 الامتحانات ومؤشر التشخيص الذكي</button>
</div>
<!-- TAB 1: Socratic Interactive Lesson Player -->
<div id="tab_lessons_content" class="studio-card">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px;">
<div>
<h3 style="font-size: 18px; font-weight: 900;">الدرس 4: قواعد الاشتقاق الأساسية — رياضيات علمي</h3>
<span style="font-size: 12px; color: var(--text-muted);">الأستاذ حمزة الغويري • Bunny Stream DRM Protected</span>
</div>
<span style="font-size: 11px; font-weight: 800; color: var(--accent-cyan); background: rgba(0,245,212,0.1); border: 1px solid rgba(0,245,212,0.3); padding: 4px 12px; border-radius: 8px;">
Checkpoint Active (08:30)
</span>
</div>
<div class="video-player-frame">
<div style="text-align: center; color: var(--text-muted);">
<div style="font-size: 40px; margin-bottom: 10px;">▶</div>
<div style="font-size: 15px; font-weight: 800; color: #FFF;">مشغل الفيديو التفاعلي — Bunny Stream</div>
<span style="font-size: 12px;">المقطع سيصل لنقطة فحص الفهم عند الدقيقة 08:30</span>
<div style="margin-top: 14px;">
<button type="button" onclick="triggerCheckpointDemo()" class="btn-primary" style="width: auto; padding: 8px 18px; font-size: 12px;">محاكاة الوصول لنقطة الكويز (08:30) ⏱️</button>
</div>
</div>
<!-- Socratic Checkpoint Overlay (Hidden until triggered) -->
<div id="socratic_quiz_modal" class="socratic-overlay" style="display: none;">
<span style="font-size: 11px; font-weight: 800; color: var(--accent-gold); background: rgba(255,209,102,0.15); border: 1px solid rgba(255,209,102,0.4); padding: 4px 12px; border-radius: 999px; margin-bottom: 12px;">
⚠️ توقف الشرح لفحص الفهم اللحظي (Checkpoint)
</span>
<h3 style="font-size: 17px; font-weight: 900; color: #FFFFFF; margin-bottom: 16px;">
إذا كان f(x) = sin(3x)، فما هي قيمة المشتقة f'(x)؟
</h3>
<div style="width: 100%; display: flex; flex-direction: column; align-items: center;">
<button type="button" class="quiz-option-btn" onclick="handleCheckpointAnswer(this, true)">
أ) 3 cos(3x) (مشتقة الزاوية ضرب مشتقة الاقتران)
</button>
<button type="button" class="quiz-option-btn" onclick="handleCheckpointAnswer(this, false)">
ب) cos(3x)
</button>
<button type="button" class="quiz-option-btn" onclick="handleCheckpointAnswer(this, false)">
ج) -3 cos(3x)
</button>
</div>
<div id="checkpoint_feedback" style="margin-top: 12px; font-size: 13px; font-weight: 800; display: none;"></div>
</div>
</div>
</div>
<!-- TAB 2: Real-time Chat with Teacher -->
<div id="tab_chat_content" class="studio-card" style="display: none;">
<div style="display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px;">
<div>
<h3 style="font-size: 18px; font-weight: 900;">محادثة معلم المادة المباشرة 💬</h3>
<p style="font-size: 12px; color: var(--text-muted);">اسأل أستاذك عن أي سؤال أو خطوة في الدرس وتلقى الإجابة فوراً.</p>
</div>
<span style="font-size: 11px; font-weight: 800; background: rgba(16,185,129,0.15); border: 1px solid rgba(16,185,129,0.4); color: #34D399; padding: 4px 12px; border-radius: 999px;">
الأستاذ حمزة الغويري (متصل الآن 🟢)
</span>
</div>
<div class="student-chat-box">
<div class="chat-messages" id="student_chat_messages">
<div class="chat-msg teacher">
أهلاً بك يا بطل! إذا واجهت أي نقطة غير واضحة في درس قواعد الاشتقاق، اكتب لي سؤالك هنا وسأجيبك فوراً.
<span class="chat-time">قبل 5 دقائق</span>
</div>
</div>
<div class="chat-input-bar">
<input type="text" id="student_chat_input" placeholder="اكتب استفسارك لمعلم المادة..." class="input-text" style="background: var(--bg-input);">
<button type="button" onclick="sendStudentMessage()" class="btn-primary" style="width: auto; padding: 0 24px; font-size: 13px;">إرسال ↵</button>
</div>
</div>
</div>
<!-- TAB 3: Multi-Level Exams & AI Diagnostics -->
<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(300px, 1fr)); gap: 16px;">
<div style="background: rgba(11,19,43,0.8); border: 1px solid var(--border); border-radius: 16px; padding: 22px;">
<div style="display: flex; justify-content: space-between; margin-bottom: 8px;">
<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>
<span style="font-size: 11px; color: var(--text-muted);">10 أسئلة • 20 دقيقة</span>
</div>
<h4 style="font-size: 16px; font-weight: 800;">امتحان قواعد الاشتقاق وتطبيقاتها</h4>
<p style="font-size: 12px; color: var(--text-muted); margin: 6px 0 16px 0;">قياس الفهم الرياضي المباشر بعد انتهاء الدرس.</p>
<button type="button" onclick="alert('جاري تجهيز بيئة الامتحان...') " class="btn-primary" style="padding: 10px; font-size: 13px;">بدء الامتحان الآن ⏱️</button>
</div>
<div style="background: rgba(11,19,43,0.8); border: 1px solid var(--border); border-radius: 16px; padding: 22px;">
<div style="display: flex; justify-content: space-between; margin-bottom: 8px;">
<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>
<span style="font-size: 11px; color: var(--text-muted);">25 سؤالاً • 60 دقيقة</span>
</div>
<h4 style="font-size: 16px; font-weight: 800;">امتحان وحدة التفاضل الشامل</h4>
<p style="font-size: 12px; color: var(--text-muted); margin: 6px 0 16px 0;">محاكاة معيارية لكافة أنماط الأسئلة الوزارية.</p>
<button type="button" onclick="alert('امتحان الوحدة متاح بعد إكمال 80% من الدروس')" class="btn-secondary" style="padding: 10px; font-size: 13px; border: 1px solid var(--border); width: 100%; border-radius: 12px;">مغلق حتى إكمال الدروس 🔒</button>
</div>
</div>
</div>
<!-- Dynamic DRM Watermark -->
<div class="watermark-anim">
<span id="drm_watermark_text">SAQEL-DRM • 079XXXXXXX</span>
</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 countdownTimer = null;
let timerSeconds = 0;
let studentData = null;
document.addEventListener('DOMContentLoaded', async () => {
const token = localStorage.getItem('saqel_student_jwt');
if (token) {
await checkStudentSession(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('⚡ Student 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);
setTimeout(() => initWebSocket(token), 3000);
};
wsSocket.onerror = (err) => {
console.warn('WS Error:', err);
updateWsStatus(false);
};
} catch (e) {
console.error('WS Connect error:', 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);
} else if (event === 'drm_session_terminated') {
alert('⚠️ تم فتح هذا الحساب من جهاز آخر. تم إنهاء الجلسة.');
handleLogout();
}
}
function switchStudentTab(tab) {
document.getElementById('tab_lessons_content').style.display = (tab === 'lessons') ? 'block' : 'none';
document.getElementById('tab_chat_content').style.display = (tab === 'chat') ? 'block' : 'none';
document.getElementById('tab_exams_content').style.display = (tab === 'exams') ? 'block' : 'none';
document.getElementById('tab_btn_lessons').className = (tab === 'lessons') ? 'tab-btn active' : 'tab-btn';
document.getElementById('tab_btn_chat').className = (tab === 'chat') ? 'tab-btn active' : 'tab-btn';
document.getElementById('tab_btn_exams').className = (tab === 'exams') ? 'tab-btn active' : 'tab-btn';
}
// Socratic In-Video Checkpoint Demo
function triggerCheckpointDemo() {
document.getElementById('socratic_quiz_modal').style.display = 'flex';
}
function handleCheckpointAnswer(btn, isCorrect) {
const feedback = document.getElementById('checkpoint_feedback');
const btns = document.querySelectorAll('.quiz-option-btn');
btns.forEach(b => b.disabled = true);
if (isCorrect) {
btn.className = 'quiz-option-btn correct';
feedback.style.color = '#34D399';
feedback.textContent = '✓ إجابة ممتازة وصحيحة! يتم الآن استئناف شرح الحصة...';
feedback.style.display = 'block';
setTimeout(() => {
document.getElementById('socratic_quiz_modal').style.display = 'none';
btns.forEach(b => { b.disabled = false; b.className = 'quiz-option-btn'; });
feedback.style.display = 'none';
}, 2000);
} else {
btn.className = 'quiz-option-btn wrong';
feedback.style.color = '#F87171';
feedback.textContent = '✗ إجابة غير دقيقة — يتم إرجاعك 45 ثانية لمشاهدة شرح المفهوم مجدداً.';
feedback.style.display = 'block';
setTimeout(() => {
document.getElementById('socratic_quiz_modal').style.display = 'none';
btns.forEach(b => { b.disabled = false; b.className = 'quiz-option-btn'; });
feedback.style.display = 'none';
}, 2500);
}
}
function appendChatMessage(msg) {
const messagesArea = document.getElementById('student_chat_messages');
const isMine = msg.is_mine || false;
const div = document.createElement('div');
div.className = `chat-msg ${isMine ? 'student' : 'teacher'}`;
div.innerHTML = `
<div>${msg.message}</div>
<span class="chat-time">${msg.created_at || 'الآن'}</span>
`;
messagesArea.appendChild(div);
messagesArea.scrollTop = messagesArea.scrollHeight;
}
async function sendStudentMessage() {
const input = document.getElementById('student_chat_input');
const message = input.value.trim();
if (!message) return;
input.value = '';
// Default teacher recipient (Teacher ID 1 or course teacher)
const teacherId = 1;
if (wsSocket && wsSocket.readyState === WebSocket.OPEN) {
wsSocket.send(JSON.stringify({
event: 'chat_send',
data: {
receiver_id: teacherId,
message: message,
message_type: 'text'
}
}));
} else {
const token = localStorage.getItem('saqel_student_jwt');
await fetch('/api/chat/messages', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + token
},
body: JSON.stringify({
receiver_id: teacherId,
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_phone_container').style.display = 'block';
clearAlerts();
clearInterval(countdownTimer);
}
function switchToOtpStep(maskedPhone) {
document.getElementById('step_phone_container').style.display = 'none';
document.getElementById('step_otp_container').style.display = 'block';
document.getElementById('otp_target_display').textContent = maskedPhone;
const otpInput = document.getElementById('student_otp_code');
otpInput.value = '';
otpInput.focus();
startTimer(60);
}
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('student_phone');
const nameInput = document.getElementById('student_fullname');
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();
const fullName = nameInput.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: 'student', full_name: fullName })
});
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('student_phone').value.trim();
const fullName = document.getElementById('student_fullname').value.trim();
const otpCode = document.getElementById('student_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: 'student', full_name: fullName })
});
const data = await res.json();
if (res.ok && data.status === 'success' && data.data?.token) {
const token = data.data.token;
localStorage.setItem('saqel_student_jwt', token);
initWebSocket(token);
await checkStudentSession(token);
} else {
showError(data.message || 'رمز التحقق غير صحيح');
}
} catch (err) {
showError('حدث خطأ في التحقق من الرمز.');
} finally {
verifyBtn.disabled = false;
verifyText.textContent = 'تأكيد الدخول للمنصة ✨';
verifySpinner.style.display = 'none';
}
}
async function checkStudentSession(token) {
try {
const res = await fetch('/api/auth/me', {
headers: { 'Authorization': 'Bearer ' + token }
});
const data = await res.json();
if (res.ok && data.data) {
studentData = data.data;
renderDashboard(data.data);
} else {
localStorage.removeItem('saqel_student_jwt');
}
} catch (e) {
console.error(e);
}
}
function renderDashboard(user) {
document.getElementById('auth_container').style.display = 'none';
document.getElementById('dashboard_container').style.display = 'block';
document.getElementById('switch_to_teacher_link').style.display = 'none';
document.getElementById('auth_user_badge').style.display = 'flex';
const displayName = user?.full_name || 'طالبنا المتميز';
document.getElementById('student_display_name').textContent = `أهلاً، ${displayName}`;
document.getElementById('dashboard_welcome_title').textContent = `أهلاً بك يا ${displayName} 🚀`;
document.getElementById('drm_watermark_text').textContent = `SAQEL-DRM • ${user?.phone_number || '079XXXXXXX'}`;
}
function handleLogout() {
localStorage.removeItem('saqel_student_jwt');
if (wsSocket) wsSocket.close();
location.reload();
}
</script>
</body>
</html>
HTML;
}
}