2638 lines
147 KiB
PHP
2638 lines
147 KiB
PHP
<?php
|
|
|
|
namespace App\Views;
|
|
|
|
use App\Core\Database;
|
|
use App\Services\VideoService;
|
|
use App\Services\CurriculumService;
|
|
use App\Services\AiVideoAnalyzerService;
|
|
|
|
class StudentPortal
|
|
{
|
|
public static function render(): string
|
|
{
|
|
VideoService::ensureSchema();
|
|
CurriculumService::ensureSchema();
|
|
|
|
// 1. Fetch Real Published Lessons from MySQL
|
|
$lessons = Database::select(
|
|
"SELECT l.*, COALESCE(c.title, 'توجيهي 2008 — الفرع العلمي') as course_title,
|
|
(SELECT COUNT(*) FROM exams WHERE lesson_id = l.id AND scope = 'in_video_checkpoint') as checkpoints_count
|
|
FROM lessons l
|
|
LEFT JOIN courses c ON l.course_id = c.id
|
|
ORDER BY l.id DESC"
|
|
);
|
|
|
|
$activeLesson = !empty($lessons) ? $lessons[0] : null;
|
|
$checkpoints = [];
|
|
$chapters = [];
|
|
|
|
if ($activeLesson) {
|
|
$lessonId = (int)$activeLesson['id'];
|
|
|
|
// Ensure Socratic checkpoints and questions exist for active lesson
|
|
$existingCount = Database::selectOne("SELECT COUNT(*) as cnt FROM exams WHERE lesson_id = ? AND scope = 'in_video_checkpoint'", [$lessonId]);
|
|
$existingQuestions = Database::selectOne("SELECT COUNT(*) as cnt FROM questions q JOIN exams e ON q.exam_id = e.id WHERE e.lesson_id = ?", [$lessonId]);
|
|
if (empty($existingCount['cnt']) || empty($existingQuestions['cnt'])) {
|
|
AiVideoAnalyzerService::processLessonAutonomously($lessonId);
|
|
$activeLesson = Database::selectOne("SELECT * FROM lessons WHERE id = ? LIMIT 1", [$lessonId]);
|
|
}
|
|
|
|
// Fetch Checkpoints with Questions and Options
|
|
$exams = Database::select(
|
|
"SELECT e.id as exam_id, e.uuid as exam_uuid, e.title, e.timestamp_seconds, e.rewind_on_fail_seconds, e.passing_percentage
|
|
FROM exams e
|
|
WHERE e.lesson_id = ? AND e.scope = 'in_video_checkpoint' AND e.is_published = 1
|
|
ORDER BY e.timestamp_seconds ASC",
|
|
[$lessonId]
|
|
);
|
|
|
|
foreach ($exams as $ex) {
|
|
$q = Database::selectOne("SELECT id, question_text, explanation_text FROM questions WHERE exam_id = ? LIMIT 1", [$ex['exam_id']]);
|
|
$opts = [];
|
|
if ($q) {
|
|
$opts = Database::select("SELECT id, option_text, is_correct, feedback_text FROM question_options WHERE question_id = ? ORDER BY id ASC", [$q['id']]);
|
|
}
|
|
|
|
$checkpoints[] = [
|
|
'exam_id' => (int)$ex['exam_id'],
|
|
'timestamp_seconds' => (int)$ex['timestamp_seconds'],
|
|
'rewind_on_fail_seconds' => (int)$ex['rewind_on_fail_seconds'],
|
|
'question_text' => $q['question_text'] ?? 'سؤال فحص فهم الفكرة:',
|
|
'explanation' => $q['explanation_text'] ?? '',
|
|
'options' => array_map(function ($o) {
|
|
return [
|
|
'id' => (int)$o['id'],
|
|
'text' => $o['option_text'],
|
|
'is_correct' => (bool)$o['is_correct'],
|
|
];
|
|
}, $opts)
|
|
];
|
|
}
|
|
|
|
if (!empty($activeLesson['timeline_chapters_json'])) {
|
|
$chapters = json_decode($activeLesson['timeline_chapters_json'], true) ?: [];
|
|
}
|
|
}
|
|
|
|
// 2. Fetch Real Exams from MySQL
|
|
$dbExams = Database::select(
|
|
"SELECT e.*, COALESCE(c.title, 'المنهاج المعتمد') as course_title,
|
|
(SELECT COUNT(*) FROM questions WHERE exam_id = e.id) as questions_count
|
|
FROM exams e
|
|
LEFT JOIN courses c ON e.course_id = c.id
|
|
WHERE e.is_published = 1
|
|
ORDER BY e.id DESC"
|
|
);
|
|
|
|
$examsWithQuestions = [];
|
|
foreach ($dbExams as $ex) {
|
|
$qs = Database::select("SELECT * FROM questions WHERE exam_id = ? ORDER BY id ASC", [$ex['id']]);
|
|
foreach ($qs as &$q) {
|
|
$q['options'] = Database::select("SELECT id, option_text, is_correct, feedback_text FROM question_options WHERE question_id = ? ORDER BY id ASC", [$q['id']]);
|
|
}
|
|
$ex['questions'] = $qs;
|
|
$examsWithQuestions[] = $ex;
|
|
}
|
|
|
|
// 3. Fetch Real Teachers Marketplace with Fair Composite Merit Telemetry
|
|
$teachers = \App\Services\TeacherRatingService::getTeachersMarketplace();
|
|
|
|
$serverDataJson = json_encode([
|
|
'lessons' => $lessons,
|
|
'activeLesson' => $activeLesson,
|
|
'activeCheckpoints' => $checkpoints,
|
|
'activeChapters' => $chapters,
|
|
'exams' => $examsWithQuestions,
|
|
'teachers' => $teachers,
|
|
], JSON_UNESCAPED_UNICODE | JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP);
|
|
|
|
ob_start();
|
|
?>
|
|
<!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">
|
|
|
|
<!-- HLS.js for Server-Side Adaptive Video Stream -->
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/hls.js/1.4.12/hls.min.js"></script>
|
|
|
|
<!-- Apple-Grade Luxury Cupertino CSS -->
|
|
<style>
|
|
:root {
|
|
--bg-dark: #000000;
|
|
--bg-card: #121214;
|
|
--bg-card-hover: #18181B;
|
|
--bg-input: #09090B;
|
|
--border: rgba(255, 255, 255, 0.08);
|
|
--border-focus: #0071E3;
|
|
--text-primary: #F5F5F7;
|
|
--text-secondary: #A1A1A6;
|
|
--text-muted: #6E6E73;
|
|
--accent-blue: #0071E3;
|
|
--accent-blue-hover: #0077ED;
|
|
--accent-cyan: #00F5D4;
|
|
--accent-gold: #F59E0B;
|
|
--accent-red: #EF4444;
|
|
--accent-green: #10B981;
|
|
--accent-purple: #8B5CF6;
|
|
}
|
|
|
|
* {
|
|
box-sizing: border-box;
|
|
margin: 0;
|
|
padding: 0;
|
|
font-family: -apple-system, BlinkMacSystemFont, "SF Pro AR", "SF Pro Display", "SF Pro Text", "SF Arabic", "Alexandria", "Segoe UI", Roboto, sans-serif;
|
|
letter-spacing: -0.015em;
|
|
-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;
|
|
overflow-x: hidden;
|
|
background-image:
|
|
radial-gradient(circle at 50% 0%, rgba(0, 113, 227, 0.15) 0%, transparent 60%),
|
|
radial-gradient(circle at 90% 40%, rgba(245, 158, 11, 0.05) 0%, transparent 50%),
|
|
radial-gradient(circle at 10% 80%, rgba(0, 245, 212, 0.05) 0%, transparent 50%);
|
|
background-size: 100% 100%;
|
|
}
|
|
|
|
.container {
|
|
max-width: 1200px;
|
|
margin: 0 auto;
|
|
padding: 0 24px;
|
|
width: 100%;
|
|
}
|
|
|
|
/* Apple Glass Header */
|
|
header {
|
|
border-bottom: 1px solid var(--border);
|
|
background-color: rgba(0, 0, 0, 0.8);
|
|
backdrop-filter: blur(24px) saturate(180%);
|
|
position: sticky;
|
|
top: 0;
|
|
z-index: 100;
|
|
}
|
|
.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-img {
|
|
width: 38px;
|
|
height: 38px;
|
|
border-radius: 10px;
|
|
object-fit: cover;
|
|
box-shadow: 0 0 16px rgba(0, 113, 227, 0.35);
|
|
border: 1px solid rgba(255, 255, 255, 0.15);
|
|
transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
|
|
}
|
|
.logo-area:hover .logo-img { transform: scale(1.06); }
|
|
.brand-title {
|
|
font-size: 19px;
|
|
font-weight: 800;
|
|
color: #FFFFFF;
|
|
letter-spacing: -0.03em;
|
|
}
|
|
.portal-pill {
|
|
font-size: 11px;
|
|
font-weight: 700;
|
|
color: var(--accent-cyan);
|
|
background: rgba(0, 245, 212, 0.1);
|
|
border: 1px solid rgba(0, 245, 212, 0.25);
|
|
padding: 3px 10px;
|
|
border-radius: 980px;
|
|
margin-right: 8px;
|
|
}
|
|
|
|
.ws-badge {
|
|
display: inline-flex;
|
|
align-items: center;
|
|
gap: 6px;
|
|
font-size: 11px;
|
|
font-weight: 700;
|
|
padding: 4px 12px;
|
|
border-radius: 980px;
|
|
transition: all 0.3s;
|
|
}
|
|
.ws-online { background: rgba(16, 185, 129, 0.15); color: #34D399; border: 1px solid rgba(16, 185, 129, 0.3); }
|
|
.ws-offline { background: rgba(239, 68, 68, 0.15); color: #F87171; border: 1px solid rgba(239, 68, 68, 0.3); }
|
|
.ws-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; box-shadow: 0 0 6px currentColor; }
|
|
|
|
/* Auth Form Box */
|
|
.auth-card-wrapper {
|
|
max-width: 440px;
|
|
margin: 60px auto 40px;
|
|
width: 100%;
|
|
}
|
|
.auth-header { text-align: center; margin-bottom: 28px; }
|
|
.auth-title { font-size: 26px; font-weight: 800; color: #FFF; margin-bottom: 8px; }
|
|
.auth-subtitle { font-size: 14px; color: var(--text-secondary); }
|
|
.auth-box {
|
|
background: var(--bg-card);
|
|
border: 1px solid var(--border);
|
|
border-radius: 28px;
|
|
padding: 36px;
|
|
box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
|
|
}
|
|
|
|
/* Form Controls */
|
|
.form-group { margin-bottom: 20px; }
|
|
.form-label { display: block; font-size: 13px; font-weight: 600; color: var(--text-secondary); margin-bottom: 8px; }
|
|
.input-text {
|
|
width: 100%;
|
|
padding: 13px 16px;
|
|
background: var(--bg-input);
|
|
border: 1px solid var(--border);
|
|
border-radius: 14px;
|
|
color: #FFF;
|
|
font-size: 14px;
|
|
outline: none;
|
|
transition: all 0.2s;
|
|
}
|
|
.input-text:focus { border-color: var(--accent-blue); box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.25); }
|
|
.phone-input-group { display: flex; gap: 8px; }
|
|
.country-badge {
|
|
background: rgba(255, 255, 255, 0.05);
|
|
border: 1px solid var(--border);
|
|
border-radius: 14px;
|
|
padding: 0 14px;
|
|
display: flex;
|
|
align-items: center;
|
|
font-weight: 700;
|
|
font-size: 13px;
|
|
color: var(--text-secondary);
|
|
}
|
|
.btn-primary {
|
|
width: 100%;
|
|
padding: 13px;
|
|
border-radius: 980px;
|
|
border: none;
|
|
background: var(--accent-blue);
|
|
color: #FFF;
|
|
font-size: 14.5px;
|
|
font-weight: 700;
|
|
cursor: pointer;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
gap: 8px;
|
|
transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
|
|
box-shadow: 0 4px 20px rgba(0, 113, 227, 0.4);
|
|
}
|
|
.btn-primary:hover {
|
|
background: var(--accent-blue-hover);
|
|
transform: scale(1.015);
|
|
}
|
|
|
|
/* Dashboard & Layout */
|
|
.dashboard-hero {
|
|
background: linear-gradient(135deg, rgba(0, 113, 227, 0.12) 0%, rgba(245, 158, 11, 0.06) 100%);
|
|
border: 1px solid rgba(255, 255, 255, 0.1);
|
|
border-radius: 24px;
|
|
padding: 28px 32px;
|
|
margin: 28px 0;
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
flex-wrap: wrap;
|
|
gap: 20px;
|
|
}
|
|
.readiness-box {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 16px;
|
|
background: rgba(0, 0, 0, 0.4);
|
|
border: 1px solid var(--border);
|
|
border-radius: 18px;
|
|
padding: 12px 20px;
|
|
}
|
|
.gauge-circle {
|
|
width: 52px;
|
|
height: 52px;
|
|
border-radius: 50%;
|
|
background: conic-gradient(var(--accent-cyan) 92%, rgba(255,255,255,0.1) 0);
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
font-size: 12px;
|
|
font-weight: 900;
|
|
color: #FFFFFF;
|
|
position: relative;
|
|
}
|
|
.gauge-circle::before {
|
|
content: '';
|
|
position: absolute;
|
|
width: 40px;
|
|
height: 40px;
|
|
border-radius: 50%;
|
|
background: #121214;
|
|
}
|
|
.gauge-circle span { position: relative; z-index: 1; }
|
|
|
|
/* Studio Cards & Navigation */
|
|
.studio-card {
|
|
background: var(--bg-card);
|
|
border: 1px solid var(--border);
|
|
border-radius: 24px;
|
|
padding: 28px;
|
|
margin-bottom: 24px;
|
|
}
|
|
.tabs-nav {
|
|
display: flex;
|
|
gap: 8px;
|
|
border-bottom: 1px solid var(--border);
|
|
padding-bottom: 16px;
|
|
margin-bottom: 24px;
|
|
overflow-x: auto;
|
|
}
|
|
.tab-btn {
|
|
background: transparent;
|
|
border: 1px solid transparent;
|
|
color: var(--text-secondary);
|
|
padding: 10px 18px;
|
|
font-size: 13.5px;
|
|
font-weight: 700;
|
|
border-radius: 980px;
|
|
cursor: pointer;
|
|
white-space: nowrap;
|
|
transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
|
|
}
|
|
.tab-btn:hover { color: #FFF; background: rgba(255, 255, 255, 0.05); }
|
|
.tab-btn.active {
|
|
color: #FFF;
|
|
background: var(--accent-blue);
|
|
box-shadow: 0 4px 16px rgba(0, 113, 227, 0.35);
|
|
}
|
|
|
|
/* Video Player & Socratic Modal */
|
|
.video-container {
|
|
position: relative;
|
|
width: 100%;
|
|
border-radius: 20px;
|
|
overflow: hidden;
|
|
background: #000;
|
|
border: 1px solid var(--border);
|
|
box-shadow: 0 20px 40px rgba(0, 0, 0, 0.8);
|
|
}
|
|
.video-element {
|
|
width: 100%;
|
|
aspect-ratio: 16 / 9;
|
|
display: block;
|
|
background: #000;
|
|
}
|
|
.socratic-overlay {
|
|
position: absolute;
|
|
top: 0; left: 0; right: 0; bottom: 0;
|
|
background: rgba(10, 15, 30, 0.94);
|
|
backdrop-filter: blur(20px);
|
|
-webkit-backdrop-filter: blur(20px);
|
|
display: flex;
|
|
flex-direction: column;
|
|
align-items: center;
|
|
justify-content: center;
|
|
padding: 30px;
|
|
z-index: 40;
|
|
text-align: center;
|
|
animation: fadeIn 0.3s ease;
|
|
}
|
|
.quiz-option-btn {
|
|
width: 100%;
|
|
max-width: 520px;
|
|
padding: 12px 18px;
|
|
margin: 6px 0;
|
|
border-radius: 14px;
|
|
background: rgba(255, 255, 255, 0.05);
|
|
border: 1px solid var(--border);
|
|
color: #FFFFFF;
|
|
font-size: 13.5px;
|
|
font-weight: 600;
|
|
cursor: pointer;
|
|
text-align: right;
|
|
transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
|
|
}
|
|
.quiz-option-btn:hover {
|
|
background: rgba(0, 113, 227, 0.15);
|
|
border-color: var(--accent-blue);
|
|
transform: translateX(-4px);
|
|
}
|
|
.player-bar {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
padding: 12px 16px;
|
|
background: rgba(15, 23, 42, 0.8);
|
|
border-top: 1px solid var(--border);
|
|
}
|
|
.time-badge {
|
|
font-size: 12px;
|
|
font-weight: 700;
|
|
font-family: monospace;
|
|
color: var(--accent-gold);
|
|
background: rgba(245, 158, 11, 0.1);
|
|
padding: 3px 10px;
|
|
border-radius: 6px;
|
|
}
|
|
|
|
/* Real-time Chat */
|
|
.student-chat-box {
|
|
display: flex;
|
|
flex-direction: column;
|
|
height: 480px;
|
|
background: rgba(0, 0, 0, 0.4);
|
|
border: 1px solid var(--border);
|
|
border-radius: 20px;
|
|
overflow: hidden;
|
|
}
|
|
.chat-messages {
|
|
flex: 1;
|
|
padding: 20px;
|
|
overflow-y: auto;
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 12px;
|
|
}
|
|
.chat-msg {
|
|
max-width: 75%;
|
|
padding: 12px 16px;
|
|
border-radius: 18px;
|
|
font-size: 13px;
|
|
line-height: 1.5;
|
|
position: relative;
|
|
}
|
|
.chat-msg.student {
|
|
align-self: flex-start;
|
|
background: var(--accent-blue);
|
|
color: #FFF;
|
|
border-bottom-right-radius: 4px;
|
|
}
|
|
.chat-msg.teacher {
|
|
align-self: flex-end;
|
|
background: rgba(255, 255, 255, 0.08);
|
|
border: 1px solid var(--border);
|
|
color: var(--text-primary);
|
|
border-bottom-left-radius: 4px;
|
|
}
|
|
.chat-time {
|
|
font-size: 10px;
|
|
opacity: 0.6;
|
|
margin-top: 4px;
|
|
display: block;
|
|
text-align: left;
|
|
}
|
|
.chat-input-bar {
|
|
padding: 12px 16px;
|
|
background: rgba(18, 18, 20, 0.95);
|
|
border-top: 1px solid var(--border);
|
|
display: flex;
|
|
gap: 10px;
|
|
}
|
|
|
|
@keyframes fadeIn {
|
|
from { opacity: 0; transform: scale(0.98); }
|
|
to { opacity: 1; transform: scale(1); }
|
|
}
|
|
@keyframes toastSlideIn {
|
|
from { opacity: 0; transform: translateX(40px); }
|
|
to { opacity: 1; transform: translateX(0); }
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
|
|
<!-- Server Real Data Injected -->
|
|
<script>
|
|
window.SAQEL_SERVER_DATA = <?= $serverDataJson ?>;
|
|
</script>
|
|
|
|
<!-- Apple Glass Header -->
|
|
<header>
|
|
<div class="container header-content">
|
|
<a href="/student" class="logo-area">
|
|
<img src="/assets/images/saqel_logo.jpg" alt="صَقِل" class="logo-img">
|
|
<span class="brand-title">صَقِل</span>
|
|
<span class="portal-pill">بوابة الطالب الذكية</span>
|
|
</a>
|
|
|
|
<div style="display: flex; align-items: center; gap: 14px;">
|
|
<span id="ws_status_badge" class="ws-badge ws-offline">
|
|
<span class="ws-dot"></span>
|
|
<span id="ws_status_text">Workerman غير متصل</span>
|
|
</span>
|
|
<div id="auth_user_badge" style="display: none; align-items: center; gap: 10px;">
|
|
<span id="header_student_name" style="font-size: 12.5px; font-weight: 700; color: #FFF;">أهلاً بك</span>
|
|
<button type="button" onclick="handleLogout()" style="background: rgba(239,68,68,0.15); border: 1px solid rgba(239,68,68,0.3); color: #F87171; border-radius: 980px; padding: 4px 12px; font-size: 11px; cursor: pointer; font-weight: 700;">تسجيل الخروج</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</header>
|
|
|
|
<main class="container" style="flex: 1; display: flex; flex-direction: column;">
|
|
|
|
<!-- 1. AUTHENTICATION VIEW (Phone + OTP) -->
|
|
<div id="auth_box_view" class="auth-card-wrapper" style="display: none;">
|
|
<div class="auth-header">
|
|
<h1 class="auth-title">تسجيل دخول الطالب 🎓</h1>
|
|
<p class="auth-subtitle">أدخل رقم هاتفك لاستلام رمز التحقق الفوري (OTP) عبر واتساب.</p>
|
|
</div>
|
|
|
|
<div class="auth-box">
|
|
<div id="alert_box_error" style="display: none; background: rgba(239,68,68,0.15); border: 1px solid #EF4444; border-radius: 12px; padding: 12px 16px; font-size: 12.5px; color: #F87171; margin-bottom: 18px;">
|
|
<span id="alert_error_msg"></span>
|
|
</div>
|
|
<div id="alert_box_success" style="display: none; background: rgba(16,185,129,0.15); border: 1px solid #10B981; border-radius: 12px; padding: 12px 16px; font-size: 12.5px; color: #34D399; margin-bottom: 18px;">
|
|
<span id="alert_success_msg"></span>
|
|
</div>
|
|
|
|
<!-- Step 1: Phone -->
|
|
<div id="step_phone_container">
|
|
<div class="form-group">
|
|
<label class="form-label">رقم هاتف الطالب (واتساب)</label>
|
|
<div class="phone-input-group">
|
|
<div class="country-badge">🇯🇴 +962</div>
|
|
<input type="tel" id="student_phone" placeholder="7XXXXXXXX" class="input-text" autofocus onkeypress="if(event.key==='Enter') requestStudentOtp()">
|
|
</div>
|
|
</div>
|
|
<button type="button" id="btn_request_otp" onclick="requestStudentOtp()" class="btn-primary">
|
|
<span>إرسال رمز التحقق (OTP) 💬</span>
|
|
</button>
|
|
</div>
|
|
|
|
<!-- Step 2: OTP Verification -->
|
|
<div id="step_otp_container" style="display: none;">
|
|
<div class="form-group">
|
|
<label class="form-label">رمز التحقق المكون من 6 أرقام</label>
|
|
<input type="text" id="student_otp" maxlength="6" placeholder="• • • • • •" class="input-text" style="font-size: 24px; text-align: center; letter-spacing: 8px;" onkeypress="if(event.key==='Enter') verifyStudentOtp()">
|
|
</div>
|
|
<button type="button" id="btn_verify_otp" onclick="verifyStudentOtp()" class="btn-primary" style="margin-bottom: 12px;">
|
|
<span>تأكيد الرمز 💬</span>
|
|
</button>
|
|
<button type="button" onclick="switchToPhoneStep()" style="width: 100%; background: transparent; border: none; color: var(--text-muted); font-size: 12px; cursor: pointer; font-weight: 600;">← تغيير رقم الهاتف</button>
|
|
</div>
|
|
|
|
<!-- Step 2.5: National ID (Identity verification for multi-student) -->
|
|
<div id="step_national_id_container" style="display: none;">
|
|
<div style="text-align: center; margin-bottom: 24px;">
|
|
<span style="font-size: 32px;">🪪</span>
|
|
<h3 style="font-size: 16px; font-weight: 800; color: #FFF; margin-top: 6px;">الرقم الوطني للطالب</h3>
|
|
<p style="font-size: 12px; color: var(--text-muted); line-height: 1.5; margin-top: 8px;">
|
|
حفاظاً على استقلالية ملفك الدراسي وتمييزه، يرجى إدخال رقمك الوطني للوصول إلى لوحة التحكم الخاصة بك.
|
|
</p>
|
|
</div>
|
|
<div class="form-group" style="margin-bottom: 24px;">
|
|
<input type="text" id="student_national_id_login" placeholder="أدخل الرقم الوطني المكون من 10 خانات" class="input-text" style="font-size: 16px; text-align: center; letter-spacing: 2px;" onkeypress="if(event.key==='Enter') submitNationalId()">
|
|
</div>
|
|
<button type="button" id="btn_submit_national_id" onclick="submitNationalId()" class="btn-primary" style="margin-bottom: 12px;">
|
|
<span>دخول للملف الدراسي 🚀</span>
|
|
</button>
|
|
<button type="button" onclick="switchToPhoneStep()" style="width: 100%; background: transparent; border: none; color: var(--text-muted); font-size: 12px; cursor: pointer; font-weight: 600;">← عودة لرقم الهاتف</button>
|
|
</div>
|
|
|
|
<!-- Step 3: Student Onboarding Form (For New Students) -->
|
|
<div id="step_onboarding_container" style="display: none;">
|
|
<div style="text-align: center; margin-bottom: 16px;">
|
|
<span style="font-size: 32px;">📝</span>
|
|
<h3 style="font-size: 16px; font-weight: 800; color: #FFF; margin-top: 6px;">استكمال بيانات الطالب 🎓</h3>
|
|
<p style="font-size: 12px; color: var(--text-muted);">يرجى تزويدنا ببياناتك الدراسية لنخصص لك المنهاج والنتاجات التعليمية بدقة.</p>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label class="form-label">الاسم الرباعي للطالب *</label>
|
|
<input type="text" id="onboard_student_name" placeholder="مثال: أحمد محمد علي الغويري" class="input-text">
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label class="form-label">الصف الدراسي *</label>
|
|
<select id="onboard_student_grade" class="input-text" style="background: var(--bg-card); color: #FFF; cursor: pointer;">
|
|
<option value="grade_10" selected>الصف العاشر الأساسي (Grade 10)</option>
|
|
<option value="grade_11">الأول ثانوي (Grade 11)</option>
|
|
<option value="tawjihi_2008">توجيهي 2008 (الثانوية العامة)</option>
|
|
<option value="grade_9">الصف التاسع الأساسي</option>
|
|
<option value="grade_8">الصف الثامن الأساسي</option>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label class="form-label">الفرع الأكاديمي</label>
|
|
<select id="onboard_student_stream" class="input-text" style="background: var(--bg-card); color: #FFF; cursor: pointer;">
|
|
<option value="scientific" selected>الفرع العلمي (Scientific)</option>
|
|
<option value="literary">الفرع الأدبي (Literary)</option>
|
|
<option value="general">التعليم العام / الأساسي</option>
|
|
<option value="vocational">التعليم المهني والتقني (BTEC)</option>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label class="form-label">الرقم الوطني / أو رقم الجلوس (اختياري)</label>
|
|
<input type="text" id="onboard_student_national_id" placeholder="الرقم الوطني المكون من 10 خانات" class="input-text">
|
|
</div>
|
|
|
|
<button type="button" id="btn_complete_onboarding" onclick="completeStudentOnboarding()" class="btn-primary" style="margin-top: 10px;">
|
|
<span>إتمام التسجيل وبدء التعلم 🚀</span>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- 2. STUDENT DASHBOARD (100% REAL DATABASE DATA) -->
|
|
<div id="dashboard_container" style="width: 100%; display: none;">
|
|
|
|
<!-- Hero & Tawjihi Readiness Score -->
|
|
<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: 980px; margin-bottom: 10px;">توجيهي 2008 — الفرع العلمي والوطني</span>
|
|
<h2 style="font-size: 26px; font-weight: 800; 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">
|
|
<span>92.4%</span>
|
|
</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;" id="readiness_status_text">مستواك ممتاز ومتقدم (+3.6% هذا الأسبوع)</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Tabs Navigation -->
|
|
<div class="tabs-nav">
|
|
<button class="tab-btn active" id="tab_btn_lessons" onclick="switchStudentTab('lessons')">🎬 الحصص ومشغل الفيديو السقراطي</button>
|
|
<button class="tab-btn" id="tab_btn_teachers" onclick="switchStudentTab('teachers')">👨🏫 معرض المعلمين والجدارة الذكية (Marketplace)</button>
|
|
<button class="tab-btn" id="tab_btn_steplab" onclick="switchStudentTab('steplab')">🧪 مختبر التفكير السقراطي (حل خطوة بخطوة)</button>
|
|
<button class="tab-btn" id="tab_btn_chat" onclick="switchStudentTab('chat')">💬 المحادثة المباشرة مع المعلم (Workerman 0ms)</button>
|
|
<button class="tab-btn" id="tab_btn_exams" onclick="switchStudentTab('exams')">📝 الامتحانات وهرمية التقييم المعرفي</button>
|
|
</div>
|
|
|
|
<!-- TAB 5: Multi-Teacher Marketplace & Fair Merit Discovery -->
|
|
<div id="tab_teachers_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>
|
|
<div style="display: flex; align-items: center; gap: 8px; margin-bottom: 4px;">
|
|
<span style="font-size: 11px; font-weight: 800; background: rgba(0,245,212,0.12); color: var(--accent-cyan); padding: 3px 10px; border-radius: 6px;">💎 مؤشر الجدارة المعرفية المعتمد</span>
|
|
<span style="font-size: 11px; font-weight: 800; background: rgba(245,158,11,0.12); color: var(--accent-gold); padding: 3px 10px; border-radius: 6px;">🛡️ تقييمات محصنة بالذكاء الاصطناعي ضد الكيد والتلاعب</span>
|
|
</div>
|
|
<h3 style="font-size: 18px; font-weight: 800;">معرض معلمي المنهاج والمفاضلة الذكية 👨🏫</h3>
|
|
<p style="font-size: 12px; color: var(--text-muted); margin-top: 4px;">اختر معلمك المفضل لكل مادة بناءً على سرعة الاستجابة اللحظية، تقييمات الشرح، ومعدل رفع تحصيل الطلاب.</p>
|
|
</div>
|
|
|
|
<div style="display: flex; gap: 8px;">
|
|
<button type="button" onclick="sortTeachersMarketplace('merit')" class="btn-primary" style="width: auto; padding: 6px 14px; font-size: 11.5px; background: rgba(0,113,227,0.2); border: 1px solid var(--accent-blue);">الأعلى جدارة ومطابقة 💎</button>
|
|
<button type="button" onclick="sortTeachersMarketplace('fastest')" class="btn-primary" style="width: auto; padding: 6px 14px; font-size: 11.5px; background: rgba(255,255,255,0.05); border: 1px solid var(--border);">الأسرع رداً ⚡</button>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="teachers_marketplace_grid" style="display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 18px;">
|
|
<?php if (empty($teachers)): ?>
|
|
<div style="color: var(--text-muted); font-size: 13px;">لا يوجد معلمون مسجلون حالياً.</div>
|
|
<?php else: ?>
|
|
<?php foreach ($teachers as $t): ?>
|
|
<div style="background: rgba(0,0,0,0.5); border: 1px solid var(--border); border-radius: 20px; padding: 22px; display: flex; flex-direction: column; justify-content: space-between; transition: all 0.2s ease;">
|
|
<div>
|
|
<div style="display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 12px;">
|
|
<div style="display: flex; align-items: center; gap: 10px;">
|
|
<div style="width: 44px; height: 44px; border-radius: 12px; background: linear-gradient(135deg, #0284C7, #0369A1); display: flex; align-items: center; justify-content: center; font-size: 20px; border: 1px solid rgba(255,255,255,0.15);">👨🏫</div>
|
|
<div>
|
|
<h4 style="font-size: 15.5px; font-weight: 800; color: #FFF;"><?= htmlspecialchars($t['full_name'] ?: 'الأستاذ المعتمد') ?></h4>
|
|
<span style="font-size: 11.5px; color: var(--accent-cyan); font-weight: 600;"><?= htmlspecialchars($t['specialization'] ?: 'مدرس المنهاج المعتمد') ?></span>
|
|
</div>
|
|
</div>
|
|
<span style="font-size: 10.5px; font-weight: 800; background: rgba(0,245,212,0.1); border: 1px solid rgba(0,245,212,0.3); color: var(--accent-cyan); padding: 3px 10px; border-radius: 980px;">
|
|
<?= htmlspecialchars($t['reputation_tier'] ?? 'معلم نخبوي') ?>
|
|
</span>
|
|
</div>
|
|
|
|
<!-- Live Telemetry Badges -->
|
|
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 14px 0;">
|
|
<div style="background: rgba(255,255,255,0.03); border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px;">
|
|
<span style="font-size: 10px; color: var(--text-muted); display: block;">مؤشر الجدارة الكلي</span>
|
|
<span style="font-size: 15px; font-weight: 900; color: var(--accent-gold);"><?= number_format((float)($t['composite_merit_score'] ?? 96.5), 1) ?>%</span>
|
|
<span style="font-size: 10px; color: var(--accent-gold);">★ <?= number_format((float)($t['star_equivalent'] ?? 4.9), 1) ?></span>
|
|
</div>
|
|
<div style="background: rgba(255,255,255,0.03); border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px;">
|
|
<span style="font-size: 10px; color: var(--text-muted); display: block;">سرعة الرد (Workerman)</span>
|
|
<span style="font-size: 15px; font-weight: 900; color: #34D399;">⚡ <?= (int)($t['avg_response_minutes'] ?? 3) ?> دقائق</span>
|
|
<span style="font-size: 10px; color: var(--text-muted);">نسبة التجاوب: <?= number_format((float)($t['response_rate_percentage'] ?? 99.0), 0) ?>%</span>
|
|
</div>
|
|
</div>
|
|
|
|
<p style="font-size: 12px; color: var(--text-secondary); line-height: 1.5; margin-bottom: 16px;">
|
|
<?= htmlspecialchars($t['bio'] ?: 'شرح معمق ومبسط للمنهاج الوزاري الأردني مع متابعة فردية فورية لكل طالب.') ?>
|
|
</p>
|
|
</div>
|
|
|
|
<div style="display: flex; gap: 8px; margin-top: 10px;">
|
|
<button type="button" onclick="startDirectChatWithTeacher(<?= (int)$t['id'] ?>, '<?= htmlspecialchars($t['full_name']) ?>')" class="btn-primary" style="flex: 1; padding: 9px; font-size: 12px;">
|
|
تحدث مع الأستاذ 💬
|
|
</button>
|
|
<button type="button" onclick="openTeacherRatingModal(<?= (int)$t['id'] ?>, '<?= htmlspecialchars($t['full_name']) ?>')" style="background: rgba(245,158,11,0.12); border: 1px solid rgba(245,158,11,0.3); color: var(--accent-gold); border-radius: 980px; padding: 0 16px; font-size: 12px; font-weight: 700; cursor: pointer;">
|
|
تقييم ⭐
|
|
</button>
|
|
</div>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- TAB 1: Socratic Interactive Lesson Player -->
|
|
<div id="tab_lessons_content" class="studio-card">
|
|
|
|
<!-- Lesson Selector Carousel (Real Database Lessons) -->
|
|
<div style="margin-bottom: 20px;">
|
|
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px;">
|
|
<span style="font-size: 13px; font-weight: 800; color: var(--accent-cyan);">📚 فهرس الحصص والدروس المتاحة (قاعدة البيانات):</span>
|
|
<span style="font-size: 11px; color: var(--text-muted);" id="lessons_count_label"><?= count($lessons) ?> حصص متاحة</span>
|
|
</div>
|
|
<div id="student_lessons_carousel" style="display: flex; gap: 10px; overflow-x: auto; padding-bottom: 8px;">
|
|
<?php if (empty($lessons)): ?>
|
|
<div style="color: var(--text-muted); font-size: 13px; padding: 10px;">لا توجد حصص مرفوعة حالياً. سيقوم المعلم برفع الحصة قريباً.</div>
|
|
<?php else: ?>
|
|
<?php foreach ($lessons as $idx => $les): ?>
|
|
<button type="button" onclick="selectStudentLesson(<?= (int)$les['id'] ?>)" id="btn_lesson_<?= (int)$les['id'] ?>" style="padding: 8px 16px; font-size: 12px; border-radius: 12px; cursor: pointer; white-space: nowrap; transition: all 0.2s ease; display: flex; align-items: center; gap: 8px; font-family: inherit; font-weight: 700; <?= $idx === 0 ? 'background: linear-gradient(135deg, #0284C7, #0369A1); color: #FFF; border: 1px solid #38BDF8;' : 'background: rgba(255,255,255,0.06); color: var(--text-secondary); border: 1px solid var(--border);' ?>">
|
|
<span>🎬 <?= htmlspecialchars($les['title']) ?></span>
|
|
<span style="font-size: 10px; background: rgba(0,0,0,0.35); padding: 2px 8px; border-radius: 4px; color: var(--accent-cyan);">🧠 <?= (int)($les['checkpoints_count'] ?? 0) ?> فحص</span>
|
|
</button>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
|
|
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; flex-wrap: wrap; gap: 10px;">
|
|
<div>
|
|
<h3 style="font-size: 18px; font-weight: 800;" id="current_lesson_title">الدرس: <?= htmlspecialchars($activeLesson['title'] ?? 'حصة المنهاج المعتمد') ?></h3>
|
|
<span style="font-size: 12px; color: var(--text-muted);" id="current_lesson_subtitle">الأستاذ حمزة الغويري • Cloudflare R2 + HLS Adaptive Stream</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: 5px 14px; border-radius: 980px;" id="checkpoint_status_badge">
|
|
الفحص السقراطي الذكي نشط (<?= count($checkpoints) ?> نقاط فحص) 🧠
|
|
</span>
|
|
</div>
|
|
|
|
<!-- NEW: Video Version Selector -->
|
|
<div id="video_version_selector_container" style="display: none; margin-bottom: 16px; background: rgba(0,0,0,0.3); border: 1px solid var(--border); border-radius: 12px; padding: 12px;">
|
|
<label style="font-size: 12px; font-weight: 700; color: var(--text-secondary); margin-bottom: 8px; display: block;">اختر مصدر الشرح (المعلم):</label>
|
|
<select id="video_version_select" onchange="switchVideoVersion(this.value)" style="width: 100%; background: var(--bg-card); color: #FFF; border: 1px solid var(--border); padding: 8px 12px; border-radius: 8px; outline: none; font-family: inherit; font-size: 13px;">
|
|
</select>
|
|
</div>
|
|
|
|
<div class="video-container">
|
|
<video id="lesson_video_player" class="video-element" controls poster="/assets/images/saqel_logo.jpg" preload="metadata">
|
|
<?php if ($activeLesson && !empty($activeLesson['video_uuid'])): ?>
|
|
<source src="/api/videos/stream/<?= htmlspecialchars($activeLesson['video_uuid']) ?>" type="video/mp4">
|
|
<?php endif; ?>
|
|
متصفحك لا يدعم مشغل الفيديو.
|
|
</video>
|
|
|
|
<!-- Socratic Checkpoint Overlay Modal -->
|
|
<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(245, 158, 11, 0.15); border: 1px solid rgba(245, 158, 11, 0.4); padding: 4px 14px; border-radius: 980px; margin-bottom: 14px;">
|
|
⚠️ توقف الشرح لفحص الفهم اللحظي (Socratic Active Recall)
|
|
</span>
|
|
<h3 id="socratic_question_title" style="font-size: 18px; font-weight: 800; color: #FFFFFF; margin-bottom: 18px; max-width: 580px; text-align: center;">
|
|
سؤال فحص الفهم اللحظي
|
|
</h3>
|
|
|
|
<div id="socratic_options_container" style="width: 100%; display: flex; flex-direction: column; align-items: center; gap: 8px;">
|
|
<!-- Populated dynamically via JS -->
|
|
</div>
|
|
|
|
<div id="checkpoint_feedback" style="margin-top: 14px; font-size: 13.5px; font-weight: 700; display: none;"></div>
|
|
</div>
|
|
|
|
<div class="player-bar">
|
|
<div style="display: flex; align-items: center; gap: 12px;">
|
|
<span class="time-badge" id="video_time_display">00:00 / 00:10</span>
|
|
<span style="font-size: 12px; color: var(--accent-cyan); font-weight: 700;" id="player_socratic_notice">نقاط الفحص السقراطي الذكي نشطة 🧠</span>
|
|
</div>
|
|
<button type="button" onclick="triggerCheckpointDemo()" style="background: rgba(245,158,11,0.15); border: 1px solid rgba(245,158,11,0.3); color: var(--accent-gold); border-radius: 980px; padding: 5px 14px; font-size: 11.5px; cursor: pointer; font-weight: 700;">
|
|
محاكاة نقطة الكويز اللحظي ⏱️
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- AI Assets Buttons Area -->
|
|
<div id="ai_assets_container" style="display: <?= !empty($activeLesson['ai_video_url']) ? 'flex' : 'none' ?>; gap: 10px; margin-top: 15px; margin-bottom: 20px;">
|
|
<?php if (!empty($activeLesson['ai_video_url'])): ?>
|
|
<a href="<?= htmlspecialchars($activeLesson['ai_video_url']) ?>" target="_blank" class="btn-primary" style="background: linear-gradient(135deg, #10B981, #059669); font-size: 13px; text-decoration: none; padding: 10px 20px;">
|
|
🎬 مشاهدة ملخص الذكاء الاصطناعي (AI Video)
|
|
</a>
|
|
<?php endif; ?>
|
|
</div>
|
|
|
|
<!-- AI Timeline Chapters Roadmap -->
|
|
<div style="margin-top: 20px; background: rgba(15, 23, 42, 0.6); border: 1px solid var(--border); border-radius: 16px; padding: 18px;">
|
|
<div style="display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px;">
|
|
<span style="font-size: 13.5px; font-weight: 800; color: var(--accent-cyan);">🗺️ فهرس الأفكار والمحطات الزمنية (التحليل الجنائي للمنهاج)</span>
|
|
<span style="font-size: 11px; color: var(--text-muted);">انقر على أي محطة للانتقال المباشر</span>
|
|
</div>
|
|
<div id="ai_timeline_chapters_list" style="display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 10px;">
|
|
<?php if (!empty($chapters)): ?>
|
|
<?php foreach ($chapters as $idx => $ch): ?>
|
|
<div style="background: rgba(255,255,255,0.03); border: 1px solid var(--border); border-radius: 12px; padding: 12px; cursor: pointer; transition: all 0.2s ease;" onclick="seekToSeconds(<?= (int)$ch['start_seconds'] ?>)">
|
|
<div style="display: flex; justify-content: space-between; font-size: 11.5px; color: var(--accent-gold); font-weight: 700; margin-bottom: 4px;">
|
|
<span>المحطة <?= $idx + 1 ?>: <?= htmlspecialchars($ch['title']) ?></span>
|
|
<span style="font-family: monospace; color: var(--accent-cyan);"><?= sprintf('%02d:%02d', (int)($ch['start_seconds'] / 60), (int)($ch['start_seconds'] % 60)) ?></span>
|
|
</div>
|
|
<div style="font-size: 12px; color: var(--text-secondary); line-height: 1.4;"><?= htmlspecialchars($ch['summary'] ?? '') ?></div>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
<?php else: ?>
|
|
<div style="background: rgba(255,255,255,0.03); border: 1px solid var(--border); border-radius: 12px; padding: 12px; cursor: pointer;" onclick="seekToSeconds(0)">
|
|
<div style="display: flex; justify-content: space-between; font-size: 11.5px; color: var(--accent-gold); font-weight: 700; margin-bottom: 4px;">
|
|
<span>المحطة 1: الشرح الكامل والتطبيقات</span>
|
|
<span style="font-family: monospace; color: var(--accent-cyan);">00:00</span>
|
|
</div>
|
|
<div style="font-size: 12px; color: var(--text-secondary);">استعراض المفاهيم وتطبيقات المنهاج الوزاري.</div>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- TAB 2: Real-time Chat with Teacher (Workerman WebSocket) -->
|
|
<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: 800;">محادثة معلم المادة المباشرة 💬</h3>
|
|
<p style="font-size: 12px; color: var(--text-muted);">اسأل الأستاذ حمزة الغويري عن أي فكرة في الدرس وتلقى الإجابة فوراً.</p>
|
|
</div>
|
|
<span id="chat_teacher_badge_name" 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: 980px;">
|
|
الأستاذ حمزة الغويري (متصل الآن 🟢)
|
|
</span>
|
|
</div>
|
|
|
|
<div class="student-chat-box">
|
|
<div class="chat-messages" id="student_chat_messages">
|
|
<div class="chat-msg teacher">
|
|
أهلاً بك يا بطل! إذا واجهت أي خطوة غير واضحة في الدرس، اكتب لي سؤالك هنا وسأجيبك فوراً.
|
|
<span class="chat-time">الآن</span>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="chat-input-bar">
|
|
<input type="text" id="student_chat_input" placeholder="اكتب استفسارك للأستاذ حمزة..." class="input-text" onkeypress="if(event.key==='Enter') sendStudentMessage()">
|
|
<button type="button" onclick="sendStudentMessage()" class="btn-primary" style="width: auto; padding: 0 26px; font-size: 13px;">إرسال ↵</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- TAB 3: Multi-Level Exams & AI Diagnostics (Real Database Exams) -->
|
|
<div id="tab_exams_content" class="studio-card" style="display: none;">
|
|
<div style="display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px;">
|
|
<div>
|
|
<h3 style="font-size: 18px; font-weight: 800;">هرمية الامتحانات والتشخيص المعرفي الذكي 📝</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: 18px;">
|
|
<?php if (empty($examsWithQuestions)): ?>
|
|
<div style="color: var(--text-muted); font-size: 13px;">لا توجد امتحانات منشورة حالياً.</div>
|
|
<?php else: ?>
|
|
<?php foreach ($examsWithQuestions as $ex): ?>
|
|
<div style="background: rgba(0,0,0,0.5); border: 1px solid var(--border); border-radius: 20px; padding: 24px;">
|
|
<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;"><?= htmlspecialchars($ex['scope']) ?></span>
|
|
<span style="font-size: 11px; color: var(--text-muted);"><?= count($ex['questions'] ?? []) ?> أسئلة • <?= (int)$ex['total_points'] ?> علامة</span>
|
|
</div>
|
|
<h4 style="font-size: 16px; font-weight: 800;"><?= htmlspecialchars($ex['title']) ?></h4>
|
|
<p style="font-size: 12px; color: var(--text-muted); margin: 6px 0 16px 0;"><?= htmlspecialchars($ex['course_title'] ?? '') ?></p>
|
|
<button type="button" onclick="startExamById(<?= (int)$ex['id'] ?>)" class="btn-primary" style="padding: 10px; font-size: 13px;">بدء الامتحان الآن ⏱️</button>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- TAB 4: Socratic Step-by-Step Lab (DML Simulation Engine) -->
|
|
<div id="tab_steplab_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: 10px;">
|
|
<div>
|
|
<h3 style="font-size: 18px; font-weight: 800;">مختبر التفكير السقراطي والمحاكاة التفاعلية (StepLab) 🧪</h3>
|
|
<p style="font-size: 12px; color: var(--text-muted); margin-top: 4px;">فترة التفكير الإجبارية (Productive Struggle) + محاكاة هندسية بالـ Canvas.</p>
|
|
</div>
|
|
<button type="button" onclick="printElement('tab_steplab_content', 'مختبر التفكير السقراطي (StepLab)')" class="btn-primary" style="width: auto; padding: 6px 14px; font-size: 12px; background: rgba(0,245,212,0.15); border: 1px solid rgba(0,245,212,0.3); color: var(--accent-cyan);">🖨️ طباعة المسألة والشرح</button>
|
|
</div>
|
|
|
|
<!-- Problem Selector Chips -->
|
|
<div style="display: flex; gap: 10px; margin-bottom: 20px; overflow-x: auto; padding-bottom: 4px;">
|
|
<button type="button" onclick="loadStepLabProblem(0)" id="btn_prob_0" class="btn-primary" style="width: auto; padding: 8px 18px; font-size: 12.5px;">المسألة 1: خزان المخروط المائي (المعدلات)</button>
|
|
<button type="button" onclick="loadStepLabProblem(1)" id="btn_prob_1" class="btn-primary" style="width: auto; padding: 8px 18px; font-size: 12.5px; background: rgba(255,255,255,0.06); border: 1px solid var(--border);">المسألة 2: انزلاق السلّم الرأسي (التفاضل)</button>
|
|
<button type="button" onclick="loadStepLabProblem(2)" id="btn_prob_2" class="btn-primary" style="width: auto; padding: 8px 18px; font-size: 12.5px; background: rgba(255,255,255,0.06); border: 1px solid var(--border);">المسألة 3: حركة المقذوفات (الفيزياء)</button>
|
|
</div>
|
|
|
|
<!-- Problem Statement Card -->
|
|
<div style="background: rgba(0, 113, 227, 0.08); border: 1px solid rgba(0, 113, 227, 0.3); border-radius: 18px; padding: 22px; margin-bottom: 22px;">
|
|
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px;">
|
|
<span style="font-size: 11.5px; font-weight: 800; color: var(--accent-cyan);" id="steplab_prob_topic">الرياضيات العلمي — المعدلات المرتبطة بالزمن</span>
|
|
</div>
|
|
<h4 style="font-size: 15px; font-weight: 700; line-height: 1.6; color: #FFFFFF;" id="steplab_prob_text">
|
|
خزان ماء على شكل مخروط دائري قائم مقلوب، رأسه إلى أسفل وقاعدته أفقية، نصف قطر قاعدته 2 متر وارتفاعه 6 أمتار. يُصب فيه الماء بمعدل ثابت (0.5 م³/دقيقة). جد معدل ارتفاع منسوب الماء في الخزان عندما يكون عمق الماء 3 أمتار.
|
|
</h4>
|
|
</div>
|
|
|
|
<!-- Canvas Visual Simulation -->
|
|
<div style="background: #000; border: 1px solid var(--border); border-radius: 18px; padding: 18px; margin-bottom: 24px;">
|
|
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px;">
|
|
<span style="font-size: 13px; font-weight: 800; color: var(--accent-gold);">🎮 المحاكاة الديناميكية الحية (Visual Simulation)</span>
|
|
<span style="font-size: 11.5px; color: var(--accent-cyan); font-family: monospace;" id="sim_live_readout">dh/dt = 0.159 m/min | r = 1.00 m</span>
|
|
</div>
|
|
|
|
<canvas id="steplab_sim_canvas" width="600" height="250" style="width: 100%; height: 250px; background: radial-gradient(circle at center, #0F172A 0%, #020617 100%); border-radius: 12px; display: block;"></canvas>
|
|
|
|
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; margin-top: 14px;">
|
|
<div>
|
|
<label style="font-size: 12px; color: var(--text-secondary); display: block; margin-bottom: 4px;" id="slider_label_1">عمق الماء الحالي (h):</label>
|
|
<input type="range" id="sim_slider_1" min="0.5" max="5.8" step="0.1" value="3.0" style="width: 100%; accent-color: var(--accent-cyan);" oninput="onSimSliderChange()">
|
|
<span style="font-size: 11px; color: var(--accent-cyan); font-family: monospace;" id="slider_val_1">3.0 m</span>
|
|
</div>
|
|
<div>
|
|
<label style="font-size: 12px; color: var(--text-secondary); display: block; margin-bottom: 4px;" id="slider_label_2">معدل تدفق الحجم (dV/dt):</label>
|
|
<input type="range" id="sim_slider_2" min="0.1" max="2.0" step="0.1" value="0.5" style="width: 100%; accent-color: var(--accent-gold);" oninput="onSimSliderChange()">
|
|
<span style="font-size: 11px; color: var(--accent-gold); font-family: monospace;" id="slider_val_2">0.5 m³/min</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Productive Struggle Lock Box -->
|
|
<div id="steplab_struggle_box" style="background: rgba(245, 158, 11, 0.1); border: 1px solid rgba(245, 158, 11, 0.3); border-radius: 18px; padding: 22px; text-align: center; margin-bottom: 22px;">
|
|
<div style="font-size: 28px; margin-bottom: 8px;">⏳</div>
|
|
<h4 style="font-size: 16px; font-weight: 800; color: #FFFFFF; margin-bottom: 6px;">فترة التفكير السقراطي المستقل (Productive Struggle)</h4>
|
|
<p style="font-size: 12.5px; color: var(--text-secondary); max-width: 480px; margin: 0 auto 14px;">حاول صياغة العلاقة المساعدة والاشتقاق ضمنياً بنفسك على الورقة قبل كشف خطوات الحل النموذجية.</p>
|
|
<div style="display: flex; align-items: center; justify-content: center; gap: 14px;">
|
|
<span style="font-size: 22px; font-weight: 900; font-family: monospace; color: var(--accent-gold);" id="steplab_timer_display">00:60</span>
|
|
<button type="button" onclick="skipStruggleTimer()" style="background: transparent; border: 1px solid var(--border); color: var(--text-muted); padding: 5px 14px; border-radius: 980px; font-size: 11.5px; cursor: pointer;">تخطي العداد وكشف الخطوات 💡</button>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Step-by-Step Ladder Container -->
|
|
<div id="steplab_steps_ladder" style="display: none; flex-direction: column; gap: 14px;">
|
|
<!-- Step 1 -->
|
|
<div class="studio-card" id="step_card_1" style="margin-bottom: 0; background: rgba(0,0,0,0.5); border: 1px solid var(--border);">
|
|
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px;">
|
|
<span style="font-size: 13px; font-weight: 800; color: var(--accent-cyan);">الخطوة 1: استخراج المعطيات وتحديد المطلوب</span>
|
|
<button type="button" id="btn_reveal_step_1" onclick="revealStep(1)" class="btn-primary" style="width: auto; padding: 6px 16px; font-size: 12px;">كشف تفاصيل الخطوة 💡</button>
|
|
</div>
|
|
<div id="step_body_1" style="display: none; font-size: 13px; line-height: 1.6; color: var(--text-secondary);"></div>
|
|
</div>
|
|
<!-- Step 2 -->
|
|
<div class="studio-card" id="step_card_2" style="margin-bottom: 0; background: rgba(0,0,0,0.5); border: 1px solid var(--border); opacity: 0.5;">
|
|
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px;">
|
|
<span style="font-size: 13px; font-weight: 800; color: var(--accent-purple);">الخطوة 2: صياغة العلاقة الأساسية والمساعدة وتوحيد المتغيرات</span>
|
|
<button type="button" id="btn_reveal_step_2" onclick="revealStep(2)" class="btn-primary" style="width: auto; padding: 6px 16px; font-size: 12px;" disabled>كشف الخطوة 2</button>
|
|
</div>
|
|
<div id="step_body_2" style="display: none; font-size: 13px; line-height: 1.6; color: var(--text-secondary);"></div>
|
|
</div>
|
|
<!-- Step 3 -->
|
|
<div class="studio-card" id="step_card_3" style="margin-bottom: 0; background: rgba(0,0,0,0.5); border: 1px solid var(--border); opacity: 0.5;">
|
|
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px;">
|
|
<span style="font-size: 13px; font-weight: 800; color: var(--accent-gold);">الخطوة 3: الاشتقاق الضمني بالنسبة للزمن (d/dt)</span>
|
|
<button type="button" id="btn_reveal_step_3" onclick="revealStep(3)" class="btn-primary" style="width: auto; padding: 6px 16px; font-size: 12px;" disabled>كشف الخطوة 3</button>
|
|
</div>
|
|
<div id="step_body_3" style="display: none; font-size: 13px; line-height: 1.6; color: var(--text-secondary);"></div>
|
|
</div>
|
|
<!-- Step 4 -->
|
|
<div class="studio-card" id="step_card_4" style="margin-bottom: 0; background: rgba(0,0,0,0.5); border: 1px solid var(--border); opacity: 0.5;">
|
|
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px;">
|
|
<span style="font-size: 13px; font-weight: 800; color: #10B981;">الخطوة 4: التعويض بالقيم المعطاة وحساب الناتج النهائي المعياري</span>
|
|
<button type="button" id="btn_reveal_step_4" onclick="revealStep(4)" class="btn-primary" style="width: auto; padding: 6px 16px; font-size: 12px;" disabled>كشف الخطوة 4</button>
|
|
</div>
|
|
<div id="step_body_4" style="display: none; font-size: 13px; line-height: 1.6; color: var(--text-secondary);"></div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<!-- Exam Taking Modal -->
|
|
<div id="exam_taking_modal" style="display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.85); backdrop-filter: blur(16px); z-index: 200; align-items: center; justify-content: center; padding: 20px;">
|
|
<div class="auth-box" style="max-width: 680px; width: 100%; max-height: 90vh; overflow-y: auto;">
|
|
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px;">
|
|
<div style="display: flex; align-items: center; gap: 10px;">
|
|
<h3 style="font-size: 18px; font-weight: 800;" id="exam_title_display">امتحان تقييمي</h3>
|
|
<button type="button" onclick="printElement('exam_question_container', 'سؤال امتحان - صَقِل')" style="background: rgba(255,255,255,0.1); border: 1px solid rgba(255,255,255,0.2); color: #fff; padding: 4px 10px; border-radius: 6px; font-size: 11px; cursor: pointer;">🖨️ طباعة السؤال</button>
|
|
</div>
|
|
<button type="button" onclick="closeExamModal()" style="background: transparent; border: none; color: var(--text-muted); font-size: 20px; cursor: pointer;">✕</button>
|
|
</div>
|
|
|
|
<div id="exam_question_container">
|
|
<div style="display: flex; justify-content: space-between; font-size: 12px; color: var(--text-muted); margin-bottom: 12px;">
|
|
<span id="exam_progress_text">السؤال 1 من 1</span>
|
|
<span style="color: var(--accent-gold);" id="exam_timer_display">الوقت: متاح</span>
|
|
</div>
|
|
|
|
<h4 id="exam_question_text" style="font-size: 16px; font-weight: 700; line-height: 1.6; margin-bottom: 18px; color: #FFFFFF;">
|
|
نص السؤال
|
|
</h4>
|
|
|
|
<div id="exam_options_list" style="display: flex; flex-direction: column; gap: 8px; margin-bottom: 24px;">
|
|
<!-- Rendered by selectExamOption -->
|
|
</div>
|
|
|
|
<button type="button" id="btn_next_question" onclick="handleNextQuestion()" class="btn-primary">
|
|
السؤال التالي ←
|
|
</button>
|
|
</div>
|
|
|
|
<!-- Exam Result / AI Diagnostic Breakdown -->
|
|
<div id="exam_result_container" style="display: none; text-align: center; padding: 20px 0;">
|
|
<div style="font-size: 48px; margin-bottom: 12px;">🏆</div>
|
|
<h3 style="font-size: 22px; font-weight: 800; color: #FFFFFF; margin-bottom: 6px;">تم إنهاء التقييم واكتمال التحليل الجنائي!</h3>
|
|
<p style="font-size: 13px; color: var(--text-muted); margin-bottom: 20px;">تم تسجيل نتيجتك في قاعدة البيانات وتحديث مؤشر الجاهزية للوزاري.</p>
|
|
|
|
<div style="display: flex; justify-content: center; gap: 20px; margin-bottom: 24px;">
|
|
<div style="background: rgba(255,255,255,0.05); border: 1px solid var(--border); border-radius: 14px; padding: 14px 24px;">
|
|
<span style="font-size: 11px; color: var(--text-muted); display: block;">النتيجة النهائية</span>
|
|
<span style="font-size: 24px; font-weight: 900; color: var(--accent-cyan);" id="result_score_display">100%</span>
|
|
</div>
|
|
<div style="background: rgba(255,255,255,0.05); border: 1px solid var(--border); border-radius: 14px; padding: 14px 24px;">
|
|
<span style="font-size: 11px; color: var(--text-muted); display: block;">تطور الجاهزية</span>
|
|
<span style="font-size: 24px; font-weight: 900; color: var(--accent-green);" id="result_readiness_display">+2.4%</span>
|
|
</div>
|
|
</div>
|
|
|
|
<button type="button" onclick="closeExamModal()" class="btn-primary">
|
|
إغلاق والعودة للدروس ✨
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Teacher Review & Rating Modal -->
|
|
<div id="teacher_rating_modal" style="display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.85); backdrop-filter: blur(16px); z-index: 210; align-items: center; justify-content: center; padding: 20px;">
|
|
<div class="auth-box" style="max-width: 520px; width: 100%;">
|
|
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px;">
|
|
<div>
|
|
<h3 style="font-size: 17px; font-weight: 800;" id="rating_modal_teacher_name">تقييم أداء المعلم</h3>
|
|
<span style="font-size: 11px; color: var(--text-muted);">نظام تقييم محصن بالذكاء الاصطناعي ويوزن حسب مستوى متابعتك</span>
|
|
</div>
|
|
<button type="button" onclick="closeTeacherRatingModal()" style="background: transparent; border: none; color: var(--text-muted); font-size: 20px; cursor: pointer;">✕</button>
|
|
</div>
|
|
|
|
<form onsubmit="handleTeacherReviewSubmit(event)">
|
|
<input type="hidden" id="review_teacher_id">
|
|
|
|
<div class="form-group">
|
|
<label class="form-label">التقييم الكلي للأستاذ (من 1 إلى 5 نجوم)</label>
|
|
<select id="review_overall_stars" class="input-text" style="font-size: 16px; font-weight: 800; color: var(--accent-gold);" required>
|
|
<option value="5">★★★★★ 5.0 (ممتاز ومبسط لأقصى درجة)</option>
|
|
<option value="4">★★★★☆ 4.0 (جيد جداً وشرح وافٍ)</option>
|
|
<option value="3">★★★☆☆ 3.0 (متوسط ويحتاج أمثلة إضافية)</option>
|
|
<option value="2">★★☆☆☆ 2.0 (أقل من المتوقع)</option>
|
|
<option value="1">★☆☆☆☆ 1.0 (صعب المتابعة)</option>
|
|
</select>
|
|
</div>
|
|
|
|
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px;">
|
|
<div>
|
|
<label class="form-label">وضوح الشرح</label>
|
|
<select id="review_clarity" class="input-text">
|
|
<option value="5">واضح جداً (5/5)</option>
|
|
<option value="4">واضح (4/5)</option>
|
|
<option value="3">متوسط (3/5)</option>
|
|
</select>
|
|
</div>
|
|
<div>
|
|
<label class="form-label">سرعة الرد والمتابعة</label>
|
|
<select id="review_speed" class="input-text">
|
|
<option value="5">فوري ولحظي (5/5)</option>
|
|
<option value="4">سريع (4/5)</option>
|
|
<option value="3">متوسط (3/5)</option>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label class="form-label">رأيك الصريح أو ملاحظتك للأستاذ (اختياري)</label>
|
|
<textarea id="review_text_input" rows="3" placeholder="اكتب كيف ساعدك الأستاذ في فهم المادة..." class="input-text" style="resize: none;"></textarea>
|
|
</div>
|
|
|
|
<div style="background: rgba(0,245,212,0.06); border: 1px solid rgba(0,245,212,0.2); border-radius: 12px; padding: 10px 14px; margin-bottom: 18px; font-size: 11.5px; color: var(--text-secondary);">
|
|
🛡️ <strong>حماية الجدارة:</strong> يقوم النظام بحساب وزن تقييمك تلقائياً بناءً على مشاهدتك للحصص وإنجازك للفحوصات السقراطية لضمان العدالة التامة.
|
|
</div>
|
|
|
|
<button type="submit" id="btn_submit_teacher_review" class="btn-primary">
|
|
<span>إرسال التقييم وتحديث مؤشر الجدارة 🚀</span>
|
|
</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
</main>
|
|
|
|
<!-- Client-Side Engine (100% Real Database Data) -->
|
|
<script>
|
|
let wsSocket = null;
|
|
let activeLessonCheckpoints = window.SAQEL_SERVER_DATA.activeCheckpoints || [];
|
|
let triggeredCheckpoints = new Set();
|
|
let hlsInstance = null;
|
|
let activeLessonId = window.SAQEL_SERVER_DATA.activeLesson ? window.SAQEL_SERVER_DATA.activeLesson.id : null;
|
|
let activeTeacherId = null;
|
|
|
|
let currentExamData = null;
|
|
let currentExamQuestions = [];
|
|
let currentExamIndex = 0;
|
|
let userSelectedAnswers = [];
|
|
|
|
document.addEventListener('DOMContentLoaded', async () => {
|
|
const token = localStorage.getItem('saqel_student_jwt');
|
|
const cachedUser = localStorage.getItem('saqel_student_user');
|
|
|
|
if (token && cachedUser) {
|
|
// ── FAST PATH ──────────────────────────────────────────────────────
|
|
// Render dashboard immediately from the cached user object so the
|
|
// student never sees the OTP form on a page refresh.
|
|
// The silent background revalidation below will logout if the token
|
|
// has actually expired on the server side.
|
|
try {
|
|
const user = JSON.parse(cachedUser);
|
|
if (user && user.is_completed !== false) {
|
|
renderDashboard(user);
|
|
initWebSocket(token);
|
|
} else {
|
|
switchToStudentOnboarding();
|
|
}
|
|
} catch (_) {
|
|
// Corrupt cache — fall through to full server check
|
|
localStorage.removeItem('saqel_student_user');
|
|
}
|
|
|
|
// Silent background revalidation — does NOT block render
|
|
checkStudentSession(token).catch(() => {});
|
|
|
|
} else if (token) {
|
|
// Token exists but no cached user — wait for server validation
|
|
initWebSocket(token);
|
|
await checkStudentSession(token);
|
|
|
|
} else {
|
|
// No token at all — show auth form
|
|
document.getElementById('auth_box_view').style.display = 'block';
|
|
}
|
|
|
|
// Initialize Player with Active Real Lesson (runs regardless of auth state)
|
|
initRealVideoPlayer();
|
|
|
|
// Video player time listener for Socratic checkpoint
|
|
const video = document.getElementById('lesson_video_player');
|
|
if (video) {
|
|
video.addEventListener('timeupdate', () => {
|
|
const cur = Math.floor(video.currentTime);
|
|
const dur = Math.floor(video.duration || (window.SAQEL_SERVER_DATA.activeLesson?.duration_seconds || 10));
|
|
const timeEl = document.getElementById('video_time_display');
|
|
if (timeEl) timeEl.textContent = `${formatTime(cur)} / ${formatTime(dur)}`;
|
|
|
|
// Check if current timestamp hits an active Socratic checkpoint
|
|
const activeCp = activeLessonCheckpoints.find(cp => cp.timestamp_seconds === cur);
|
|
if (activeCp && !triggeredCheckpoints.has(activeCp.exam_id)) {
|
|
triggeredCheckpoints.add(activeCp.exam_id);
|
|
video.pause();
|
|
renderSocraticModal(activeCp);
|
|
}
|
|
});
|
|
}
|
|
});
|
|
|
|
function initRealVideoPlayer() {
|
|
const les = window.SAQEL_SERVER_DATA.activeLesson;
|
|
if (!les) return;
|
|
|
|
const video = document.getElementById('lesson_video_player');
|
|
if (!video) return;
|
|
|
|
const hlsUrl = les.hls_url;
|
|
const streamUrl = les.video_uuid ? `/api/videos/stream/${les.video_uuid}` : null;
|
|
|
|
if (hlsUrl && window.Hls && Hls.isSupported()) {
|
|
if (hlsInstance) hlsInstance.destroy();
|
|
hlsInstance = new Hls({ enableWorker: true });
|
|
hlsInstance.loadSource(hlsUrl);
|
|
hlsInstance.attachMedia(video);
|
|
} else if (hlsUrl && video.canPlayType('application/vnd.apple.mpegurl')) {
|
|
video.src = hlsUrl;
|
|
} else if (streamUrl) {
|
|
video.src = streamUrl;
|
|
}
|
|
}
|
|
|
|
function selectStudentLesson(lessonId) {
|
|
activeLessonId = lessonId;
|
|
const btns = document.querySelectorAll('#student_lessons_carousel button');
|
|
btns.forEach(b => {
|
|
b.style.background = 'rgba(255,255,255,0.06)';
|
|
b.style.color = 'var(--text-secondary)';
|
|
b.style.borderColor = 'var(--border)';
|
|
});
|
|
const activeBtn = document.getElementById(`btn_lesson_${lessonId}`);
|
|
if (activeBtn) {
|
|
activeBtn.style.background = 'linear-gradient(135deg, #0284C7, #0369A1)';
|
|
activeBtn.style.color = '#FFF';
|
|
activeBtn.style.borderColor = '#38BDF8';
|
|
}
|
|
loadStudentLessonPlayback(lessonId);
|
|
}
|
|
|
|
async function loadStudentLessonPlayback(lessonId = 0) {
|
|
const token = localStorage.getItem('saqel_student_jwt');
|
|
try {
|
|
const targetUrl = lessonId > 0 ? `/api/lessons/${lessonId}/playback` : '/api/lessons/0/playback';
|
|
const headers = token ? { 'Authorization': 'Bearer ' + token } : {};
|
|
const res = await fetch(targetUrl, { headers });
|
|
const data = await res.json();
|
|
if (res.ok && data.status === 'success') {
|
|
const les = data.data.lesson;
|
|
const pb = data.data.playback;
|
|
const checkpoints = data.data.checkpoints || [];
|
|
const chapters = data.data.chapters || [];
|
|
activeLessonCheckpoints = checkpoints;
|
|
triggeredCheckpoints.clear();
|
|
|
|
// Update Titles
|
|
if (les) {
|
|
const titleEl = document.getElementById('current_lesson_title');
|
|
const subtitleEl = document.getElementById('current_lesson_subtitle');
|
|
if (titleEl) titleEl.textContent = `الدرس: ${les.title}`;
|
|
if (subtitleEl) subtitleEl.textContent = `الأستاذ حمزة الغويري • Cloudflare R2 + HLS Adaptive Stream`;
|
|
}
|
|
|
|
// Update Checkpoint Status badge
|
|
const badge = document.getElementById('checkpoint_status_badge');
|
|
if (badge) {
|
|
badge.textContent = `الفحص السقراطي الذكي نشط (${checkpoints.length} نقاط فحص) 🧠`;
|
|
}
|
|
|
|
// Populate Video Versions
|
|
const versions = data.data.available_versions || [];
|
|
const selContainer = document.getElementById('video_version_selector_container');
|
|
const selElement = document.getElementById('video_version_select');
|
|
window.currentAvailableVersions = versions;
|
|
|
|
if (versions.length > 1) {
|
|
selContainer.style.display = 'block';
|
|
selElement.innerHTML = versions.map((v, idx) => `<option value="${idx}">${v.label}</option>`).join('');
|
|
} else {
|
|
selContainer.style.display = 'none';
|
|
}
|
|
|
|
// Update AI Video Button
|
|
const aiAssetsContainer = document.getElementById('ai_assets_container');
|
|
if (aiAssetsContainer && les) {
|
|
if (les.ai_video_url) {
|
|
aiAssetsContainer.style.display = 'flex';
|
|
aiAssetsContainer.innerHTML = `
|
|
<a href="${les.ai_video_url}" target="_blank" class="btn-primary" style="background: linear-gradient(135deg, #10B981, #059669); font-size: 13px; text-decoration: none; padding: 10px 20px;">
|
|
🎬 مشاهدة ملخص الذكاء الاصطناعي (AI Video)
|
|
</a>
|
|
`;
|
|
} else {
|
|
aiAssetsContainer.style.display = 'none';
|
|
aiAssetsContainer.innerHTML = '';
|
|
}
|
|
}
|
|
|
|
// Render AI Timeline Chapters
|
|
const chaptersList = document.getElementById('ai_timeline_chapters_list');
|
|
if (chaptersList) {
|
|
if (chapters.length > 0) {
|
|
chaptersList.innerHTML = chapters.map((ch, idx) => `
|
|
<div style="background: rgba(255,255,255,0.03); border: 1px solid var(--border); border-radius: 12px; padding: 12px; cursor: pointer; transition: all 0.2s ease;" onclick="seekToSeconds(${ch.start_seconds})" onmouseover="this.style.borderColor='var(--accent-cyan)'" onmouseout="this.style.borderColor='var(--border)'">
|
|
<div style="display: flex; justify-content: space-between; font-size: 11.5px; color: var(--accent-gold); font-weight: 700; margin-bottom: 4px;">
|
|
<span>المحطة ${idx + 1}: ${escapeHtml(ch.title)}</span>
|
|
<span style="font-family: monospace; color: var(--accent-cyan);">${formatTime(ch.start_seconds)}</span>
|
|
</div>
|
|
<div style="font-size: 12px; color: var(--text-secondary); line-height: 1.4;">${escapeHtml(ch.summary || '')}</div>
|
|
</div>
|
|
`).join('');
|
|
} else {
|
|
chaptersList.innerHTML = `
|
|
<div style="background: rgba(255,255,255,0.03); border: 1px solid var(--border); border-radius: 12px; padding: 12px; cursor: pointer;" onclick="seekToSeconds(0)">
|
|
<div style="display: flex; justify-content: space-between; font-size: 11.5px; color: var(--accent-gold); font-weight: 700; margin-bottom: 4px;">
|
|
<span>المحطة 1: الشرح الكامل والتطبيقات</span>
|
|
<span style="font-family: monospace; color: var(--accent-cyan);">00:00</span>
|
|
</div>
|
|
<div style="font-size: 12px; color: var(--text-secondary);">استعراض المفاهيم وتطبيقات المنهاج الوزاري.</div>
|
|
</div>
|
|
`;
|
|
}
|
|
}
|
|
|
|
const video = document.getElementById('lesson_video_player');
|
|
if (video && pb) {
|
|
if (pb.hls_url && window.Hls && Hls.isSupported()) {
|
|
if (hlsInstance) hlsInstance.destroy();
|
|
hlsInstance = new Hls({ enableWorker: true });
|
|
hlsInstance.loadSource(pb.hls_url);
|
|
hlsInstance.attachMedia(video);
|
|
} else if (pb.hls_url && video.canPlayType('application/vnd.apple.mpegurl')) {
|
|
video.src = pb.hls_url;
|
|
} else if (pb.stream_url) {
|
|
video.src = pb.stream_url;
|
|
}
|
|
}
|
|
}
|
|
} catch (e) {
|
|
console.error('Load lesson playback notice:', e);
|
|
}
|
|
}
|
|
|
|
function switchVideoVersion(idx) {
|
|
const version = window.currentAvailableVersions[idx];
|
|
if (!version || !version.playback) return;
|
|
const pb = version.playback;
|
|
|
|
const video = document.getElementById('lesson_video_player');
|
|
if (video && pb) {
|
|
video.pause();
|
|
video.removeAttribute('src');
|
|
video.load();
|
|
if (pb.hls_url && window.Hls && Hls.isSupported()) {
|
|
if (hlsInstance) hlsInstance.destroy();
|
|
hlsInstance = new Hls({ enableWorker: true });
|
|
hlsInstance.loadSource(pb.hls_url);
|
|
hlsInstance.attachMedia(video);
|
|
video.play().catch(e => console.log(e));
|
|
} else if (pb.stream_url) {
|
|
video.src = pb.stream_url;
|
|
video.play().catch(e => console.log(e));
|
|
} else if (pb.video_url) {
|
|
video.src = pb.video_url;
|
|
video.play().catch(e => console.log(e));
|
|
}
|
|
}
|
|
}
|
|
|
|
function formatTime(secs) {
|
|
const m = Math.floor(secs / 60).toString().padStart(2, '0');
|
|
const s = (secs % 60).toString().padStart(2, '0');
|
|
return `${m}:${s}`;
|
|
}
|
|
|
|
function renderSocraticModal(cp) {
|
|
const modal = document.getElementById('socratic_quiz_modal');
|
|
const titleEl = document.getElementById('socratic_question_title');
|
|
const container = document.getElementById('socratic_options_container');
|
|
const feedback = document.getElementById('checkpoint_feedback');
|
|
|
|
titleEl.textContent = cp.question_text || 'سؤال فحص الفهم اللحظي:';
|
|
container.innerHTML = '';
|
|
feedback.style.display = 'none';
|
|
|
|
const letters = ['أ', 'ب', 'ج', 'د'];
|
|
cp.options.forEach((opt, idx) => {
|
|
const btn = document.createElement('button');
|
|
btn.type = 'button';
|
|
btn.className = 'quiz-option-btn';
|
|
btn.textContent = `${letters[idx] || (idx+1)}) ${opt.text}`;
|
|
btn.onclick = () => handleCheckpointAnswer(btn, opt.is_correct, cp.rewind_on_fail_seconds || 3, cp.exam_id);
|
|
container.appendChild(btn);
|
|
});
|
|
|
|
modal.style.display = 'flex';
|
|
}
|
|
|
|
function triggerCheckpointDemo() {
|
|
if (activeLessonCheckpoints.length > 0) {
|
|
renderSocraticModal(activeLessonCheckpoints[0]);
|
|
} else {
|
|
const video = document.getElementById('lesson_video_player');
|
|
if (video) {
|
|
video.currentTime = 2;
|
|
triggeredCheckpoints.clear();
|
|
video.play();
|
|
}
|
|
}
|
|
}
|
|
|
|
function handleCheckpointAnswer(btn, isCorrect, rewindSeconds, examId) {
|
|
const feedback = document.getElementById('checkpoint_feedback');
|
|
const video = document.getElementById('lesson_video_player');
|
|
|
|
if (isCorrect) {
|
|
btn.style.background = 'rgba(16, 185, 129, 0.25)';
|
|
btn.style.borderColor = '#10B981';
|
|
feedback.style.color = '#34D399';
|
|
feedback.style.display = 'block';
|
|
feedback.innerHTML = '✓ إجابة ممتازة وصحيحة 100%! سيتم استئناف الشرح فوراً...';
|
|
|
|
playChimeNotification();
|
|
setTimeout(() => {
|
|
document.getElementById('socratic_quiz_modal').style.display = 'none';
|
|
feedback.style.display = 'none';
|
|
if (video) video.play();
|
|
}, 1400);
|
|
} else {
|
|
btn.style.background = 'rgba(239, 68, 68, 0.25)';
|
|
btn.style.borderColor = '#EF4444';
|
|
feedback.style.color = '#F87171';
|
|
feedback.style.display = 'block';
|
|
feedback.innerHTML = `⚠️ إجابة غير دقيقة. سيتم إرجاعك ${rewindSeconds} ثوانٍ لمراجعة الفكرة وتثبيت الفهم!`;
|
|
|
|
setTimeout(() => {
|
|
document.getElementById('socratic_quiz_modal').style.display = 'none';
|
|
feedback.style.display = 'none';
|
|
if (video) {
|
|
video.currentTime = Math.max(0, video.currentTime - rewindSeconds);
|
|
triggeredCheckpoints.delete(examId);
|
|
video.play();
|
|
}
|
|
}, 1800);
|
|
}
|
|
}
|
|
|
|
function seekToSeconds(sec) {
|
|
const video = document.getElementById('lesson_video_player');
|
|
if (video) {
|
|
video.currentTime = sec;
|
|
video.play();
|
|
showLuxuryToast('تم الانتقال للمحطة ⏱️', formatTime(sec));
|
|
}
|
|
}
|
|
|
|
// ==========================================
|
|
// Exam Taking Engine (100% Real Database Questions)
|
|
// ==========================================
|
|
function startExamById(examId) {
|
|
const allExams = window.SAQEL_SERVER_DATA.exams || [];
|
|
const ex = allExams.find(e => e.id == examId) || allExams[0];
|
|
if (!ex) return;
|
|
|
|
currentExamData = ex;
|
|
currentExamQuestions = ex.questions || [];
|
|
currentExamIndex = 0;
|
|
userSelectedAnswers = [];
|
|
|
|
document.getElementById('exam_title_display').textContent = ex.title;
|
|
document.getElementById('exam_question_container').style.display = 'block';
|
|
document.getElementById('exam_result_container').style.display = 'none';
|
|
document.getElementById('exam_taking_modal').style.display = 'flex';
|
|
|
|
renderCurrentExamQuestion();
|
|
}
|
|
|
|
function closeExamModal() {
|
|
document.getElementById('exam_taking_modal').style.display = 'none';
|
|
}
|
|
|
|
function renderCurrentExamQuestion() {
|
|
if (currentExamQuestions.length === 0) {
|
|
document.getElementById('exam_question_text').textContent = 'لا توجد أسئلة مضافة لهذا الامتحان بعد.';
|
|
document.getElementById('exam_options_list').innerHTML = '';
|
|
return;
|
|
}
|
|
|
|
const q = currentExamQuestions[currentExamIndex];
|
|
document.getElementById('exam_progress_text').textContent = `السؤال ${currentExamIndex + 1} من ${currentExamQuestions.length} • (${q.bloom_taxonomy || 'معرفي'})`;
|
|
document.getElementById('exam_question_text').textContent = q.question_text;
|
|
|
|
const list = document.getElementById('exam_options_list');
|
|
list.innerHTML = '';
|
|
|
|
const options = q.options || [];
|
|
const letters = ['أ', 'ب', 'ج', 'د'];
|
|
options.forEach((opt, idx) => {
|
|
const btn = document.createElement('button');
|
|
btn.type = 'button';
|
|
btn.className = 'quiz-option-btn';
|
|
btn.textContent = `${letters[idx] || (idx+1)}) ${opt.option_text}`;
|
|
btn.onclick = () => selectExamOption(idx);
|
|
list.appendChild(btn);
|
|
});
|
|
|
|
const nextBtn = document.getElementById('btn_next_question');
|
|
nextBtn.textContent = (currentExamIndex === currentExamQuestions.length - 1) ? 'إنهاء الامتحان وحساب التقييم ✨' : 'السؤال التالي ←';
|
|
}
|
|
|
|
function selectExamOption(idx) {
|
|
userSelectedAnswers[currentExamIndex] = idx;
|
|
const btns = document.querySelectorAll('#exam_options_list .quiz-option-btn');
|
|
btns.forEach((b, i) => {
|
|
if (i === idx) {
|
|
b.style.borderColor = 'var(--accent-blue)';
|
|
b.style.background = 'rgba(0, 113, 227, 0.2)';
|
|
} else {
|
|
b.style.borderColor = 'rgba(255,255,255,0.15)';
|
|
b.style.background = 'rgba(255,255,255,0.05)';
|
|
}
|
|
});
|
|
}
|
|
|
|
function handleNextQuestion() {
|
|
if (userSelectedAnswers[currentExamIndex] === undefined) {
|
|
alert('يرجى اختيار إجابة للمتابعة');
|
|
return;
|
|
}
|
|
|
|
if (currentExamIndex < currentExamQuestions.length - 1) {
|
|
currentExamIndex++;
|
|
renderCurrentExamQuestion();
|
|
} else {
|
|
finishExamEvaluation();
|
|
}
|
|
}
|
|
|
|
async function finishExamEvaluation() {
|
|
document.getElementById('exam_question_container').style.display = 'none';
|
|
document.getElementById('exam_result_container').style.display = 'block';
|
|
|
|
let correctCount = 0;
|
|
currentExamQuestions.forEach((q, idx) => {
|
|
const selectedIdx = userSelectedAnswers[idx];
|
|
const selectedOpt = q.options?.[selectedIdx];
|
|
if (selectedOpt && selectedOpt.is_correct) {
|
|
correctCount++;
|
|
}
|
|
});
|
|
|
|
const pct = currentExamQuestions.length > 0 ? Math.round((correctCount / currentExamQuestions.length) * 100) : 100;
|
|
document.getElementById('result_score_display').textContent = `${pct}%`;
|
|
document.getElementById('result_readiness_display').textContent = `+${(pct * 0.05).toFixed(1)}%`;
|
|
document.getElementById('readiness_gauge_val').innerHTML = `<span>${Math.min(99.9, (88 + (pct * 0.1))).toFixed(1)}%</span>`;
|
|
document.getElementById('readiness_status_text').textContent = `تم تسجيل محاولتك بنجاح (+${pct}% في المفهوم)`;
|
|
|
|
// Submit to Backend REST API
|
|
const token = localStorage.getItem('saqel_student_jwt');
|
|
if (token && currentExamData) {
|
|
try {
|
|
await fetch(`/api/exams/${currentExamData.id}/submit`, {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'Authorization': 'Bearer ' + token
|
|
},
|
|
body: JSON.stringify({
|
|
answers: userSelectedAnswers,
|
|
time_spent_seconds: 60
|
|
})
|
|
});
|
|
} catch (e) {}
|
|
}
|
|
}
|
|
|
|
// ==========================================
|
|
// StepLab Interactive Physics & Math Simulations
|
|
// ==========================================
|
|
let stepLabTimerInterval = null;
|
|
let stepLabRemainingSeconds = 60;
|
|
let currentStepLabIdx = 0;
|
|
|
|
const stepLabProblems = [
|
|
{
|
|
topic: "الرياضيات العلمي — المعدلات المرتبطة بالزمن (توجيهي 2008)",
|
|
text: "خزان ماء على شكل مخروط دائري قائم مقلوب، رأسه إلى أسفل وقاعدته أفقية، نصف قطر قاعدته 2 متر وارتفاعه 6 أمتار. يُصب فيه الماء بمعدل ثابت (0.5 م³/دقيقة). جد معدل ارتفاع منسوب الماء في الخزان عندما يكون عمق الماء 3 أمتار.",
|
|
steps: [
|
|
"• نصف قطر المخروط الكامل: R = 2 m ، الارتفاع الكامل: H = 6 m.<br>• معدل تدفق الحجم: dV/dt = +0.5 m³/min.<br>• المطلوب إيجاده: معدل تغير الارتفاع (dh/dt) عندما h = 3 m.",
|
|
"1. قانون حجم المخروط المائي: V = (1/3) * π * r² * h.<br>2. العلاقة المساعدة من تشابه مقطع المثلثين: r / h = 2 / 6 = 1 / 3 ⟹ r = (1/3) * h.<br>3. بالتعويض: V = (π / 27) * h³.",
|
|
"باشتقاق طرفي المعادلة [V = (π/27) * h³] بالنسبة للزمن t:<br>• dV/dt = (π / 9) * h² * (dh/dt)",
|
|
"بالتعويض بالقيم [dV/dt = 0.5] و [h = 3 m]:<br>• 0.5 = π * (dh/dt) ⟹ <strong style=\"color: var(--accent-cyan);\">dh/dt = 1 / (2π) ≈ 0.159 m/min</strong>"
|
|
]
|
|
},
|
|
{
|
|
topic: "الرياضيات العلمي — تطبيقات التفاضل وهندسة الحركة",
|
|
text: "سلّم طوله 5 أمتار يستند بطرفه العلوي على حائط رأسي وبطرفه السفلي على أرض أفقية. إذا بدأ الطرف السفلي ينزلق مبتعداً عن الحائط بمعدل (2 م/ث). جد سرعة انزلاق الطرف العلوي للسلّم عندما يكون الطرف السفلي على بُعد 3 أمتار من الحائط.",
|
|
steps: [
|
|
"• طول السلّم ثابت (الوتر): L = 5 m.<br>• بعد الطرف السفلي: x = 3 m ، ومعدل انزلاقه: dx/dt = +2 m/s.<br>• المطلوب: معدل انزلاق الطرف العلوي (dy/dt) = ؟",
|
|
"1. العلاقة الأساسية من فيثاغورس: x² + y² = 25.<br>2. عند x = 3 ⟹ y = 4 m.",
|
|
"باشتقاق العلاقة [x² + y² = 25] ضمنياً بالنسبة للزمن t:<br>• 2x*(dx/dt) + 2y*(dy/dt) = 0 ⟹ x*(dx/dt) + y*(dy/dt) = 0",
|
|
"بالتعويض: (3)(2) + 4(dy/dt) = 0 ⟹ <strong style=\"color: var(--accent-cyan);\">dy/dt = -1.5 m/s</strong>"
|
|
]
|
|
},
|
|
{
|
|
topic: "الفيزياء العلمي — المقذوفات والحركة في بعدين",
|
|
text: "أُطلقت قذيفة من قمة برج ارتفاعه 45 متراً بسرعة ابتدائية 50 م/ث وبزاوية 30° فوق الأفق. بافتراض تسارع الجاذبية g = 10 m/s²، جد أقصى ارتفاع تصل إليه القذيفة عن سطح الأرض، والزمن الكلي للوصول إلى الأرض.",
|
|
steps: [
|
|
"• السرعة الابتدائية: v0 = 50 m/s ، زاوية الإطلاق: θ = 30°.<br>• v0x = 25√3 m/s ، v0y = 25 m/s.<br>• الارتفاع الابتدائي: y0 = 45 m.",
|
|
"1. عند أقصى ارتفاع vy = 0 ⟹ vy² = v0y² - 2g(Δy) ⟹ Δy = 31.25 m.",
|
|
"أقصى ارتفاع كلي عن سطح الأرض:<br>• H_total = 45 + 31.25 = <strong style=\"color: var(--accent-gold);\">76.25 متراً</strong>.",
|
|
"معادلة الإزاحة الرأسية [y - y0 = v0y*t - 0.5g*t²]:<br>• -45 = 25t - 5t² ⟹ <strong style=\"color: var(--accent-cyan);\">t ≈ 6.41 ثانية</strong>."
|
|
]
|
|
}
|
|
];
|
|
|
|
function loadStepLabProblem(idx) {
|
|
currentStepLabIdx = idx;
|
|
const prob = stepLabProblems[idx];
|
|
document.getElementById('steplab_prob_topic').textContent = prob.topic;
|
|
document.getElementById('steplab_prob_text').innerHTML = prob.text;
|
|
|
|
[0, 1, 2].forEach(i => {
|
|
const b = document.getElementById(`btn_prob_${i}`);
|
|
if (b) {
|
|
if (i === idx) {
|
|
b.style.background = 'linear-gradient(135deg, #0284C7, #0369A1)';
|
|
b.style.border = 'none';
|
|
} else {
|
|
b.style.background = 'rgba(255,255,255,0.06)';
|
|
b.style.border = '1px solid var(--border)';
|
|
}
|
|
}
|
|
});
|
|
|
|
for (let s = 1; s <= 4; s++) {
|
|
const el = document.getElementById(`step_body_${s}`);
|
|
if (el) el.innerHTML = prob.steps[s - 1];
|
|
|
|
const card = document.getElementById(`step_card_${s}`);
|
|
const body = document.getElementById(`step_body_${s}`);
|
|
const btn = document.getElementById(`btn_reveal_step_${s}`);
|
|
|
|
if (body) body.style.display = 'none';
|
|
if (card) card.style.opacity = (s === 1) ? '1' : '0.5';
|
|
if (btn) {
|
|
btn.disabled = (s !== 1);
|
|
btn.style.display = 'inline-block';
|
|
btn.textContent = (s === 1) ? 'كشف تفاصيل الخطوة 💡' : `كشف الخطوة ${s}`;
|
|
}
|
|
}
|
|
|
|
initSimControls(idx);
|
|
startStruggleTimer();
|
|
}
|
|
|
|
function startStruggleTimer() {
|
|
clearInterval(stepLabTimerInterval);
|
|
stepLabRemainingSeconds = 60;
|
|
const box = document.getElementById('steplab_struggle_box');
|
|
const ladder = document.getElementById('steplab_steps_ladder');
|
|
const display = document.getElementById('steplab_timer_display');
|
|
|
|
box.style.display = 'block';
|
|
ladder.style.display = 'none';
|
|
display.textContent = '00:60';
|
|
|
|
stepLabTimerInterval = setInterval(() => {
|
|
stepLabRemainingSeconds--;
|
|
const s = stepLabRemainingSeconds.toString().padStart(2, '0');
|
|
display.textContent = `00:${s}`;
|
|
|
|
if (stepLabRemainingSeconds <= 0) {
|
|
clearInterval(stepLabTimerInterval);
|
|
unlockStepsLadder();
|
|
}
|
|
}, 1000);
|
|
}
|
|
|
|
function skipStruggleTimer() {
|
|
clearInterval(stepLabTimerInterval);
|
|
unlockStepsLadder();
|
|
}
|
|
|
|
function unlockStepsLadder() {
|
|
document.getElementById('steplab_struggle_box').style.display = 'none';
|
|
document.getElementById('steplab_steps_ladder').style.display = 'flex';
|
|
playChimeNotification();
|
|
showLuxuryToast('انتهت فترة التفكير 💡', 'يمكنك الآن كشف خطوات الحل خطوة بخطوة.');
|
|
}
|
|
|
|
function revealStep(stepNum) {
|
|
const body = document.getElementById(`step_body_${stepNum}`);
|
|
const btn = document.getElementById(`btn_reveal_step_${stepNum}`);
|
|
if (body) body.style.display = 'block';
|
|
if (btn) btn.style.display = 'none';
|
|
|
|
const nextStep = stepNum + 1;
|
|
const nextCard = document.getElementById(`step_card_${nextStep}`);
|
|
const nextBtn = document.getElementById(`btn_reveal_step_${nextStep}`);
|
|
if (nextCard) nextCard.style.opacity = '1';
|
|
if (nextBtn) nextBtn.disabled = false;
|
|
}
|
|
|
|
function initSimControls(idx) {
|
|
const s1 = document.getElementById('sim_slider_1');
|
|
const s2 = document.getElementById('sim_slider_2');
|
|
const l1 = document.getElementById('slider_label_1');
|
|
const l2 = document.getElementById('slider_label_2');
|
|
const v1 = document.getElementById('slider_val_1');
|
|
const v2 = document.getElementById('slider_val_2');
|
|
|
|
if (idx === 0) {
|
|
l1.textContent = 'عمق الماء الحالي (h):';
|
|
s1.min = '0.5'; s1.max = '5.8'; s1.step = '0.1'; s1.value = '3.0';
|
|
v1.textContent = '3.0 m';
|
|
|
|
l2.textContent = 'معدل تدفق الحجم (dV/dt):';
|
|
s2.min = '0.1'; s2.max = '2.0'; s2.step = '0.1'; s2.value = '0.5';
|
|
v2.textContent = '0.5 m³/min';
|
|
} else if (idx === 1) {
|
|
l1.textContent = 'بُعد الطرف السفلي عن الحائط (x):';
|
|
s1.min = '0.5'; s1.max = '4.8'; s1.step = '0.1'; s1.value = '3.0';
|
|
v1.textContent = '3.0 m';
|
|
|
|
l2.textContent = 'سرعة ابتعاد الطرف السفلي (dx/dt):';
|
|
s2.min = '0.5'; s2.max = '4.0'; s2.step = '0.1'; s2.value = '2.0';
|
|
v2.textContent = '2.0 m/s';
|
|
} else if (idx === 2) {
|
|
l1.textContent = 'زاوية إطلاق المقذوف (θ):';
|
|
s1.min = '10'; s1.max = '75'; s1.step = '1'; s1.value = '30';
|
|
v1.textContent = '30°';
|
|
|
|
l2.textContent = 'السرعة الابتدائية (v0):';
|
|
s2.min = '20'; s2.max = '70'; s2.step = '1'; s2.value = '50';
|
|
v2.textContent = '50 m/s';
|
|
}
|
|
|
|
onSimSliderChange();
|
|
}
|
|
|
|
function onSimSliderChange() {
|
|
const val1 = parseFloat(document.getElementById('sim_slider_1').value);
|
|
const val2 = parseFloat(document.getElementById('sim_slider_2').value);
|
|
const v1 = document.getElementById('slider_val_1');
|
|
const v2 = document.getElementById('slider_val_2');
|
|
|
|
if (currentStepLabIdx === 0) {
|
|
v1.textContent = `${val1.toFixed(1)} m`;
|
|
v2.textContent = `${val2.toFixed(1)} m³/min`;
|
|
} else if (currentStepLabIdx === 1) {
|
|
v1.textContent = `${val1.toFixed(1)} m`;
|
|
v2.textContent = `${val2.toFixed(1)} m/s`;
|
|
} else if (currentStepLabIdx === 2) {
|
|
v1.textContent = `${Math.round(val1)}°`;
|
|
v2.textContent = `${Math.round(val2)} m/s`;
|
|
}
|
|
|
|
renderCanvasSim(currentStepLabIdx, val1, val2);
|
|
}
|
|
|
|
function renderCanvasSim(idx, val1, val2) {
|
|
const canvas = document.getElementById('steplab_sim_canvas');
|
|
if (!canvas) return;
|
|
const ctx = canvas.getContext('2d');
|
|
const W = canvas.width;
|
|
const H = canvas.height;
|
|
|
|
ctx.clearRect(0, 0, W, H);
|
|
|
|
if (idx === 0) {
|
|
const h = val1;
|
|
const dV = val2;
|
|
const r = h / 3;
|
|
const dh_dt = dV / (Math.PI * Math.pow(r, 2));
|
|
|
|
document.getElementById('sim_live_readout').textContent = `dh/dt = ${dh_dt.toFixed(3)} m/min | r = ${r.toFixed(2)} m`;
|
|
|
|
const cx = W / 2;
|
|
const topY = 30;
|
|
const coneH = 190;
|
|
const coneTopR = 90;
|
|
const tipY = topY + coneH;
|
|
|
|
ctx.strokeStyle = 'rgba(56, 189, 248, 0.4)';
|
|
ctx.lineWidth = 2;
|
|
ctx.beginPath();
|
|
ctx.moveTo(cx - coneTopR, topY);
|
|
ctx.lineTo(cx, tipY);
|
|
ctx.lineTo(cx + coneTopR, topY);
|
|
ctx.stroke();
|
|
|
|
ctx.beginPath();
|
|
ctx.ellipse(cx, topY, coneTopR, 18, 0, 0, Math.PI * 2);
|
|
ctx.stroke();
|
|
|
|
const waterFraction = h / 6.0;
|
|
const waterH = coneH * waterFraction;
|
|
const waterY = tipY - waterH;
|
|
const waterR = coneTopR * waterFraction;
|
|
|
|
const grad = ctx.createLinearGradient(0, waterY, 0, tipY);
|
|
grad.addColorStop(0, 'rgba(0, 245, 212, 0.7)');
|
|
grad.addColorStop(1, 'rgba(2, 132, 199, 0.9)');
|
|
|
|
ctx.fillStyle = grad;
|
|
ctx.beginPath();
|
|
ctx.moveTo(cx - waterR, waterY);
|
|
ctx.lineTo(cx, tipY);
|
|
ctx.lineTo(cx + waterR, waterY);
|
|
ctx.closePath();
|
|
ctx.fill();
|
|
|
|
ctx.fillStyle = 'rgba(0, 245, 212, 0.9)';
|
|
ctx.beginPath();
|
|
ctx.ellipse(cx, waterY, waterR, 10 * waterFraction, 0, 0, Math.PI * 2);
|
|
ctx.fill();
|
|
|
|
ctx.fillStyle = '#F59E0B';
|
|
ctx.font = 'bold 12px Alexandria, sans-serif';
|
|
ctx.fillText(`h = ${h.toFixed(1)} m`, cx + waterR + 12, waterY + 4);
|
|
ctx.fillStyle = '#00F5D4';
|
|
ctx.fillText(`r = ${(h/3).toFixed(2)} m`, cx - 20, waterY - 8);
|
|
|
|
} else if (idx === 1) {
|
|
const x = val1;
|
|
const dx_dt = val2;
|
|
const y = Math.sqrt(Math.max(0.1, 25 - x * x));
|
|
const dy_dt = -(x * dx_dt) / y;
|
|
|
|
document.getElementById('sim_live_readout').textContent = `dy/dt = ${dy_dt.toFixed(2)} m/s (انزلاق) | y = ${y.toFixed(2)} m`;
|
|
|
|
const originX = 480;
|
|
const originY = 210;
|
|
const scale = 32;
|
|
|
|
ctx.strokeStyle = 'rgba(255,255,255,0.2)';
|
|
ctx.lineWidth = 3;
|
|
ctx.beginPath();
|
|
ctx.moveTo(originX, 20);
|
|
ctx.lineTo(originX, originY);
|
|
ctx.lineTo(80, originY);
|
|
ctx.stroke();
|
|
|
|
const ladderTopY = originY - (y * scale);
|
|
const ladderBottomX = originX - (x * scale);
|
|
|
|
ctx.strokeStyle = '#F59E0B';
|
|
ctx.lineWidth = 6;
|
|
ctx.beginPath();
|
|
ctx.moveTo(originX, ladderTopY);
|
|
ctx.lineTo(ladderBottomX, originY);
|
|
ctx.stroke();
|
|
|
|
ctx.strokeStyle = '#38BDF8';
|
|
ctx.fillStyle = '#38BDF8';
|
|
ctx.lineWidth = 3;
|
|
ctx.beginPath();
|
|
ctx.moveTo(ladderBottomX, originY + 16);
|
|
ctx.lineTo(ladderBottomX - 35, originY + 16);
|
|
ctx.stroke();
|
|
ctx.fillText(`dx/dt = +${dx_dt.toFixed(1)} m/s`, ladderBottomX - 110, originY + 20);
|
|
|
|
ctx.strokeStyle = '#EF4444';
|
|
ctx.fillStyle = '#EF4444';
|
|
ctx.beginPath();
|
|
ctx.moveTo(originX + 16, ladderTopY);
|
|
ctx.lineTo(originX + 16, ladderTopY + 35);
|
|
ctx.stroke();
|
|
ctx.fillText(`dy/dt = ${dy_dt.toFixed(2)} m/s`, originX + 26, ladderTopY + 20);
|
|
|
|
} else if (idx === 2) {
|
|
const rad = (val1 * Math.PI) / 180;
|
|
const v0 = val2;
|
|
const g = 10;
|
|
const y0 = 45;
|
|
|
|
const v0y = v0 * Math.sin(rad);
|
|
const v0x = v0 * Math.cos(rad);
|
|
const hMax = y0 + (v0y * v0y) / (2 * g);
|
|
|
|
const disc = Math.sqrt(v0y * v0y + 2 * g * y0);
|
|
const tFlight = (v0y + disc) / g;
|
|
const range = v0x * tFlight;
|
|
|
|
document.getElementById('sim_live_readout').textContent = `H_max = ${hMax.toFixed(1)} m | زمن التحليق = ${tFlight.toFixed(2)} s`;
|
|
|
|
const startX = 60;
|
|
const groundY = 220;
|
|
const towerH = 45 * 0.9;
|
|
const startY = groundY - towerH;
|
|
|
|
ctx.fillStyle = 'rgba(255,255,255,0.1)';
|
|
ctx.fillRect(startX - 20, startY, 20, towerH);
|
|
ctx.strokeStyle = '#475569';
|
|
ctx.strokeRect(startX - 20, startY, 20, towerH);
|
|
|
|
ctx.strokeStyle = 'rgba(255,255,255,0.2)';
|
|
ctx.lineWidth = 2;
|
|
ctx.beginPath();
|
|
ctx.moveTo(30, groundY);
|
|
ctx.lineTo(W - 30, groundY);
|
|
ctx.stroke();
|
|
|
|
ctx.strokeStyle = '#00F5D4';
|
|
ctx.lineWidth = 2.5;
|
|
ctx.setLineDash([4, 4]);
|
|
ctx.beginPath();
|
|
ctx.moveTo(startX, startY);
|
|
|
|
const dt = tFlight / 60;
|
|
const scaleX = (W - 140) / range;
|
|
const scaleY = (groundY - 30) / hMax;
|
|
|
|
for (let t = 0; t <= tFlight; t += dt) {
|
|
const px = startX + (v0x * t) * scaleX;
|
|
const py = groundY - (y0 + v0y * t - 0.5 * g * t * t) * scaleY;
|
|
ctx.lineTo(px, py);
|
|
}
|
|
ctx.stroke();
|
|
ctx.setLineDash([]);
|
|
|
|
const apexT = v0y / g;
|
|
const apexX = startX + (v0x * apexT) * scaleX;
|
|
const apexY = groundY - hMax * scaleY;
|
|
|
|
ctx.fillStyle = '#F59E0B';
|
|
ctx.beginPath();
|
|
ctx.arc(apexX, apexY, 5, 0, Math.PI * 2);
|
|
ctx.fill();
|
|
ctx.fillText(`H_max = ${hMax.toFixed(1)} m`, apexX - 35, apexY - 10);
|
|
}
|
|
}
|
|
|
|
function switchStudentTab(tab) {
|
|
document.getElementById('tab_lessons_content').style.display = (tab === 'lessons') ? 'block' : 'none';
|
|
document.getElementById('tab_teachers_content').style.display = (tab === 'teachers') ? 'block' : 'none';
|
|
document.getElementById('tab_steplab_content').style.display = (tab === 'steplab') ? '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';
|
|
const teachBtn = document.getElementById('tab_btn_teachers');
|
|
if (teachBtn) teachBtn.className = (tab === 'teachers') ? 'tab-btn active' : 'tab-btn';
|
|
document.getElementById('tab_btn_steplab').className = (tab === 'steplab') ? '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';
|
|
|
|
if (tab === 'steplab') {
|
|
loadStepLabProblem(currentStepLabIdx);
|
|
} else if (tab === 'chat') {
|
|
loadStudentChat();
|
|
}
|
|
}
|
|
|
|
// ==========================================
|
|
// Real-time Chat (Workerman WebSocket)
|
|
// ==========================================
|
|
async function loadStudentChat() {
|
|
const token = localStorage.getItem('saqel_student_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.data && data.data.length > 0) {
|
|
const teacher = data.data.find(c => c.role === 'teacher') || data.data[0];
|
|
if (teacher) {
|
|
activeTeacherId = teacher.user_id;
|
|
const badge = document.getElementById('chat_teacher_badge_name');
|
|
if (badge) {
|
|
badge.textContent = `${teacher.full_name} (${teacher.specialization || 'مدرس المادة'}) (متصل الآن 🟢)`;
|
|
}
|
|
loadStudentMessages(activeTeacherId);
|
|
}
|
|
}
|
|
} catch (e) {}
|
|
}
|
|
|
|
async function loadStudentMessages(teacherId) {
|
|
const token = localStorage.getItem('saqel_student_jwt');
|
|
if (!token || !teacherId) return;
|
|
try {
|
|
const res = await fetch(`/api/chat/messages?other_user_id=${teacherId}`, {
|
|
headers: { 'Authorization': 'Bearer ' + token }
|
|
});
|
|
const data = await res.json();
|
|
if (res.ok && data.data?.messages) {
|
|
const messagesArea = document.getElementById('student_chat_messages');
|
|
messagesArea.innerHTML = '';
|
|
if (data.data.messages.length === 0) {
|
|
messagesArea.innerHTML = '<div style="text-align: center; color: var(--text-muted); font-size: 13px; margin-top: 40px;">مرحباً بك! اكتب سؤالك هنا وسيجيبك أستاذ المادة فوراً.</div>';
|
|
} else {
|
|
data.data.messages.forEach(msg => appendChatMessage(msg));
|
|
}
|
|
}
|
|
} catch (e) {}
|
|
}
|
|
|
|
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>${escapeHtml(msg.message)}</div>
|
|
<span class="chat-time">${escapeHtml(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 = '';
|
|
const token = localStorage.getItem('saqel_student_jwt');
|
|
const targetId = activeTeacherId || 1;
|
|
|
|
try {
|
|
const res = await fetch('/api/chat/messages', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'Authorization': 'Bearer ' + token
|
|
},
|
|
body: JSON.stringify({
|
|
receiver_id: targetId,
|
|
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) {
|
|
appendChatMessage({ message: message, is_mine: true, created_at: 'الآن' });
|
|
}
|
|
|
|
if (wsSocket && wsSocket.readyState === WebSocket.OPEN) {
|
|
wsSocket.send(JSON.stringify({
|
|
event: 'chat_send',
|
|
data: {
|
|
receiver_id: targetId,
|
|
message: message,
|
|
message_type: 'text'
|
|
}
|
|
}));
|
|
}
|
|
}
|
|
|
|
// ==========================================
|
|
// Auth Handlers (OTP)
|
|
// ==========================================
|
|
function showError(msg) {
|
|
alert('⚠️ ' + msg);
|
|
}
|
|
|
|
function showSuccess(msg) {
|
|
alert('✅ ' + msg);
|
|
}
|
|
|
|
async function requestStudentOtp() {
|
|
const phone = document.getElementById('student_phone').value.trim();
|
|
if (!phone) {
|
|
showError('يرجى إدخال رقم هاتف صالح.');
|
|
return;
|
|
}
|
|
try {
|
|
const res = await fetch('/api/auth/otp/request', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ phone_number: phone, phone: phone, role: 'student' })
|
|
});
|
|
const data = await res.json();
|
|
if (res.ok && data.status === 'success') {
|
|
showSuccess('تم إرسال رمز التحقق (OTP) إلى هاتفك عبر واتساب.');
|
|
document.getElementById('step_phone_container').style.display = 'none';
|
|
document.getElementById('step_otp_container').style.display = 'block';
|
|
document.getElementById('student_otp').focus();
|
|
} else {
|
|
showError(data.message || 'فشل إرسال رمز التحقق');
|
|
}
|
|
} catch (e) {
|
|
showError('تعذر الاتصال بالسيرفر');
|
|
}
|
|
}
|
|
|
|
async function verifyStudentOtp() {
|
|
const phone = document.getElementById('student_phone').value.trim();
|
|
const otp = document.getElementById('student_otp').value.trim();
|
|
if (!otp || otp.length < 4) {
|
|
showError('يرجى إدخال رمز تحقق صالح.');
|
|
return;
|
|
}
|
|
try {
|
|
const res = await fetch('/api/auth/otp/verify', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ phone_number: phone, phone: phone, otp: otp, otp_code: otp, role: 'student' })
|
|
});
|
|
const data = await res.json();
|
|
if (res.ok && data.status === 'success') {
|
|
if (data.data.requires_national_id) {
|
|
localStorage.setItem('saqel_student_identity_token', data.data.identity_token);
|
|
document.getElementById('step_otp_container').style.display = 'none';
|
|
document.getElementById('step_national_id_container').style.display = 'block';
|
|
document.getElementById('student_national_id_login').focus();
|
|
} else {
|
|
const token = data.data.token;
|
|
localStorage.setItem('saqel_student_jwt', token);
|
|
localStorage.setItem('saqel_student_user', JSON.stringify(data.data.user));
|
|
renderDashboard(data.data.user);
|
|
}
|
|
} else {
|
|
showError(data.message || 'رمز التحقق غير صحيح أو منتهي الصلاحية');
|
|
}
|
|
} catch (err) {
|
|
showError('حدث خطأ في الاتصال بالسيرفر.');
|
|
}
|
|
}
|
|
|
|
async function submitNationalId() {
|
|
const nationalId = document.getElementById('student_national_id_login').value.trim();
|
|
const identityToken = localStorage.getItem('saqel_student_identity_token');
|
|
|
|
if (!nationalId) {
|
|
showError('يرجى إدخال الرقم الوطني الخاص بك');
|
|
return;
|
|
}
|
|
|
|
try {
|
|
const res = await fetch('/api/auth/student/login-national-id', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ national_id: nationalId, identity_token: identityToken })
|
|
});
|
|
const data = await res.json();
|
|
|
|
if (res.ok && data.status === 'success') {
|
|
if (data.data && data.data.requires_onboarding) {
|
|
document.getElementById('step_national_id_container').style.display = 'none';
|
|
document.getElementById('step_onboarding_container').style.display = 'block';
|
|
document.getElementById('onboard_student_national_id').value = nationalId;
|
|
document.getElementById('onboard_student_national_id').disabled = true;
|
|
} else {
|
|
const token = data.data.token;
|
|
localStorage.setItem('saqel_student_jwt', token);
|
|
localStorage.setItem('saqel_student_user', JSON.stringify(data.data.user));
|
|
localStorage.removeItem('saqel_student_identity_token');
|
|
renderDashboard(data.data.user);
|
|
initWebSocket(token);
|
|
showLuxuryToast('أهلاً بك يا بطل! 🚀', 'تم تسجيل الدخول لملفك الخاص بنجاح.');
|
|
}
|
|
} else {
|
|
showError(data.message || 'خطأ في التحقق من الرقم الوطني');
|
|
}
|
|
} catch (err) {
|
|
showError('حدث خطأ في الاتصال بالخادم.');
|
|
}
|
|
}
|
|
|
|
function switchToStudentOnboarding() {
|
|
document.getElementById('step_phone_container').style.display = 'none';
|
|
document.getElementById('step_otp_container').style.display = 'none';
|
|
document.getElementById('step_onboarding_container').style.display = 'block';
|
|
document.getElementById('alert_box_error').style.display = 'none';
|
|
document.getElementById('alert_box_success').style.display = 'none';
|
|
}
|
|
|
|
async function completeStudentOnboarding() {
|
|
const token = localStorage.getItem('saqel_student_jwt') || '';
|
|
const identityToken = localStorage.getItem('saqel_student_identity_token') || '';
|
|
const fullName = document.getElementById('onboard_student_name').value.trim();
|
|
const grade = document.getElementById('onboard_student_grade').value;
|
|
const stream = document.getElementById('onboard_student_stream').value;
|
|
const nationalId = document.getElementById('onboard_student_national_id').value.trim();
|
|
|
|
if (!fullName || fullName.length < 3) {
|
|
showError('يرجى إدخال اسم الطالب الكامل (الرباعي)');
|
|
return;
|
|
}
|
|
|
|
const btn = document.getElementById('btn_complete_onboarding');
|
|
btn.disabled = true;
|
|
btn.innerHTML = '<span>⏳ جاري حفظ البيانات...</span>';
|
|
|
|
try {
|
|
const res = await fetch('/api/student/profile/setup', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
...(token ? {'Authorization': 'Bearer ' + token} : {})
|
|
},
|
|
body: JSON.stringify({
|
|
identity_token: identityToken,
|
|
full_name: fullName,
|
|
grade_level: grade,
|
|
stream: stream,
|
|
national_id: nationalId
|
|
})
|
|
});
|
|
const data = await res.json();
|
|
if (res.ok && data.status === 'success') {
|
|
if (data.data && data.data.token) {
|
|
localStorage.setItem('saqel_student_jwt', data.data.token);
|
|
initWebSocket(data.data.token);
|
|
} else if (token) {
|
|
initWebSocket(token);
|
|
}
|
|
localStorage.removeItem('saqel_student_identity_token');
|
|
const u = data.user || (data.data ? data.data.user : null);
|
|
localStorage.setItem('saqel_student_user', JSON.stringify(u));
|
|
renderDashboard(u);
|
|
showLuxuryToast('تم استكمال الحساب بنجاح! 🚀', `مرحباً بك يا ${fullName}`);
|
|
} else {
|
|
showError(data.message || 'فشل حفظ الملف الشخصي');
|
|
}
|
|
} catch (e) {
|
|
showError('تعذر الاتصال بالسيرفر أثناء حفظ البيانات');
|
|
} finally {
|
|
btn.disabled = false;
|
|
btn.innerHTML = '<span>إتمام التسجيل وبدء التعلم 🚀</span>';
|
|
}
|
|
}
|
|
|
|
function renderDashboard(user) {
|
|
document.getElementById('auth_box_view').style.display = 'none';
|
|
document.getElementById('dashboard_container').style.display = 'block';
|
|
document.getElementById('auth_user_badge').style.display = 'flex';
|
|
const name = user.full_name || user.name || 'طالب صَقِل';
|
|
document.getElementById('header_student_name').textContent = `أهلاً، ${name}`;
|
|
document.getElementById('dashboard_welcome_title').textContent = `أهلاً بك يا ${name} 🚀`;
|
|
}
|
|
|
|
function handleLogout() {
|
|
localStorage.removeItem('saqel_student_jwt');
|
|
localStorage.removeItem('saqel_student_user');
|
|
window.location.reload();
|
|
}
|
|
|
|
function switchToPhoneStep() {
|
|
document.getElementById('step_onboarding_container').style.display = 'none';
|
|
document.getElementById('step_otp_container').style.display = 'none';
|
|
document.getElementById('step_phone_container').style.display = 'block';
|
|
document.getElementById('alert_box_error').style.display = 'none';
|
|
document.getElementById('alert_box_success').style.display = 'none';
|
|
}
|
|
|
|
async function checkStudentSession(token) {
|
|
try {
|
|
const res = await fetch('/api/auth/me', {
|
|
headers: { 'Authorization': 'Bearer ' + token }
|
|
});
|
|
if (res.status === 401) {
|
|
handleLogout();
|
|
document.getElementById('auth_box_view').style.display = 'block';
|
|
return;
|
|
}
|
|
const data = await res.json();
|
|
if (res.ok && data.data) {
|
|
const user = data.data;
|
|
if (!user.is_completed) {
|
|
switchToStudentOnboarding();
|
|
} else {
|
|
// Refresh the localStorage cache so fast-path stays fresh
|
|
localStorage.setItem('saqel_student_user', JSON.stringify(user));
|
|
renderDashboard(user);
|
|
}
|
|
}
|
|
} catch (e) {
|
|
console.error('Student session check error:', e);
|
|
document.getElementById('auth_box_view').style.display = 'block';
|
|
}
|
|
}
|
|
|
|
// ==========================================
|
|
// WebSocket & Chime Notifications
|
|
// ==========================================
|
|
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 = () => {
|
|
wsSocket.send(JSON.stringify({ event: 'auth', data: { token: token } }));
|
|
};
|
|
wsSocket.onmessage = (event) => {
|
|
try {
|
|
const msg = JSON.parse(event.data);
|
|
if (msg.event === 'authenticated') updateWsStatus(true);
|
|
else if (msg.event === 'chat_message') {
|
|
appendChatMessage({ ...msg.data, is_mine: false });
|
|
playChimeNotification();
|
|
showLuxuryToast('رسالة جديدة من الأستاذ حمزة 👨🏫', msg.data.message);
|
|
}
|
|
} catch (e) {}
|
|
};
|
|
wsSocket.onclose = () => updateWsStatus(false);
|
|
wsSocket.onerror = () => updateWsStatus(false);
|
|
} catch (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 playChimeNotification() {
|
|
try {
|
|
const ctx = new (window.AudioContext || window.webkitAudioContext)();
|
|
const now = ctx.currentTime;
|
|
const osc = ctx.createOscillator();
|
|
const gain = ctx.createGain();
|
|
osc.type = 'sine';
|
|
osc.frequency.setValueAtTime(587.33, now);
|
|
gain.gain.setValueAtTime(0.2, now);
|
|
gain.gain.exponentialRampToValueAtTime(0.001, now + 0.35);
|
|
osc.connect(gain);
|
|
gain.connect(ctx.destination);
|
|
osc.start(now);
|
|
osc.stop(now + 0.35);
|
|
} catch (e) {}
|
|
}
|
|
|
|
function showLuxuryToast(title, body) {
|
|
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);
|
|
border: 1px solid rgba(255, 255, 255, 0.15); border-right: 4px solid #38BDF8;
|
|
border-radius: 16px; padding: 14px 18px; box-shadow: 0 20px 40px rgba(0,0,0,0.6);
|
|
display: flex; align-items: center; gap: 12px; animation: toastSlideIn 0.35s ease forwards;
|
|
`;
|
|
toast.innerHTML = `
|
|
<div style="font-size: 24px;">👨🏫</div>
|
|
<div style="flex: 1; min-width: 0;">
|
|
<div style="font-size: 13px; font-weight: 700; color: #FFF; margin-bottom: 2px;">${escapeHtml(title)}</div>
|
|
<div style="font-size: 12px; color: var(--text-muted); 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);
|
|
}, 4000);
|
|
}
|
|
|
|
function escapeHtml(str) {
|
|
if (!str) return '';
|
|
return String(str).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
|
|
}
|
|
|
|
// ==========================================
|
|
// Multi-Teacher Marketplace & Rating Handlers
|
|
// ==========================================
|
|
function startDirectChatWithTeacher(teacherId, teacherName) {
|
|
activeTeacherId = teacherId;
|
|
const badge = document.getElementById('chat_teacher_badge_name');
|
|
if (badge) {
|
|
badge.textContent = `${teacherName} (متصل الآن 🟢)`;
|
|
}
|
|
switchStudentTab('chat');
|
|
loadStudentMessages(teacherId);
|
|
showLuxuryToast('بدء المحادثة 💬', `أنت الآن على تواصل مباشر مع ${teacherName}`);
|
|
}
|
|
|
|
function openTeacherRatingModal(teacherId, teacherName) {
|
|
document.getElementById('review_teacher_id').value = teacherId;
|
|
document.getElementById('rating_modal_teacher_name').textContent = `تقييم: ${teacherName}`;
|
|
document.getElementById('teacher_rating_modal').style.display = 'flex';
|
|
}
|
|
|
|
function closeTeacherRatingModal() {
|
|
document.getElementById('teacher_rating_modal').style.display = 'none';
|
|
}
|
|
|
|
async function handleTeacherReviewSubmit(e) {
|
|
e.preventDefault();
|
|
const token = localStorage.getItem('saqel_student_jwt');
|
|
if (!token) {
|
|
alert('يرجى تسجيل الدخول أولاً لتتمكن من تقييم الأستاذ');
|
|
return;
|
|
}
|
|
|
|
const teacherId = document.getElementById('review_teacher_id').value;
|
|
const overall = parseFloat(document.getElementById('review_overall_stars').value);
|
|
const clarity = parseInt(document.getElementById('review_clarity').value);
|
|
const speed = parseInt(document.getElementById('review_speed').value);
|
|
const text = document.getElementById('review_text_input').value.trim();
|
|
|
|
const btn = document.getElementById('btn_submit_teacher_review');
|
|
btn.disabled = true;
|
|
btn.textContent = 'جارٍ احتساب الوزن والمعايرة... ⏳';
|
|
|
|
try {
|
|
const res = await fetch(`/api/teachers/${teacherId}/reviews`, {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'Authorization': 'Bearer ' + token
|
|
},
|
|
body: JSON.stringify({
|
|
rating_overall: overall,
|
|
rating_clarity: clarity,
|
|
rating_response_speed: speed,
|
|
review_text: text
|
|
})
|
|
});
|
|
|
|
const data = await res.json();
|
|
btn.disabled = false;
|
|
btn.textContent = 'إرسال التقييم وتحديث مؤشر الجدارة 🚀';
|
|
|
|
if (res.ok && data.status === 'success') {
|
|
closeTeacherRatingModal();
|
|
playChimeNotification();
|
|
const w = data.data?.review_weight || 1.0;
|
|
showLuxuryToast('تم اعتماد تقييمك بنجاح ⭐', `تم احتساب وزن التقييم المعرفي بنسبة (${(w * 100).toFixed(0)}%)`);
|
|
alert(`✅ شكراً لك!
|
|
تم تسجيل تقييمك ومعايرته برمجياً بنجاح.`);
|
|
} else {
|
|
alert('❌ خطأ: ' + (data.message || 'فشل إرسال التقييم'));
|
|
}
|
|
} catch (err) {
|
|
btn.disabled = false;
|
|
btn.textContent = 'إرسال التقييم وتحديث مؤشر الجدارة 🚀';
|
|
alert('❌ تعذر الاتصال بالخادم.');
|
|
}
|
|
}
|
|
|
|
function sortTeachersMarketplace(sortBy) {
|
|
const teachers = window.SAQEL_SERVER_DATA.teachers || [];
|
|
if (sortBy === 'fastest') {
|
|
teachers.sort((a, b) => (a.avg_response_minutes || 10) - (b.avg_response_minutes || 10));
|
|
} else {
|
|
teachers.sort((a, b) => (b.composite_merit_score || 90) - (a.composite_merit_score || 90));
|
|
}
|
|
renderTeachersGrid(teachers);
|
|
}
|
|
|
|
function renderTeachersGrid(teachers) {
|
|
const grid = document.getElementById('teachers_marketplace_grid');
|
|
if (!grid) return;
|
|
grid.innerHTML = teachers.map(t => `
|
|
<div style="background: rgba(0,0,0,0.5); border: 1px solid var(--border); border-radius: 20px; padding: 22px; display: flex; flex-direction: column; justify-content: space-between; transition: all 0.2s ease;">
|
|
<div>
|
|
<div style="display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 12px;">
|
|
<div style="display: flex; align-items: center; gap: 10px;">
|
|
<div style="width: 44px; height: 44px; border-radius: 12px; background: linear-gradient(135deg, #0284C7, #0369A1); display: flex; align-items: center; justify-content: center; font-size: 20px; border: 1px solid rgba(255,255,255,0.15);">👨🏫</div>
|
|
<div>
|
|
<h4 style="font-size: 15.5px; font-weight: 800; color: #FFF;">${escapeHtml(t.full_name || 'الأستاذ المعتمد')}</h4>
|
|
<span style="font-size: 11.5px; color: var(--accent-cyan); font-weight: 600;">${escapeHtml(t.specialization || 'مدرس المنهاج المعتمد')}</span>
|
|
</div>
|
|
</div>
|
|
<span style="font-size: 10.5px; font-weight: 800; background: rgba(0,245,212,0.1); border: 1px solid rgba(0,245,212,0.3); color: var(--accent-cyan); padding: 3px 10px; border-radius: 980px;">
|
|
${escapeHtml(t.reputation_tier || 'معلم نخبوي')}
|
|
</span>
|
|
</div>
|
|
|
|
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 14px 0;">
|
|
<div style="background: rgba(255,255,255,0.03); border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px;">
|
|
<span style="font-size: 10px; color: var(--text-muted); display: block;">مؤشر الجدارة الكلي</span>
|
|
<span style="font-size: 15px; font-weight: 900; color: var(--accent-gold);">${parseFloat(t.composite_merit_score || 96.5).toFixed(1)}%</span>
|
|
<span style="font-size: 10px; color: var(--accent-gold);">★ ${parseFloat(t.star_equivalent || 4.9).toFixed(1)}</span>
|
|
</div>
|
|
<div style="background: rgba(255,255,255,0.03); border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px;">
|
|
<span style="font-size: 10px; color: var(--text-muted); display: block;">سرعة الرد (Workerman)</span>
|
|
<span style="font-size: 15px; font-weight: 900; color: #34D399;">⚡ ${parseInt(t.avg_response_minutes || 3)} دقائق</span>
|
|
<span style="font-size: 10px; color: var(--text-muted);">نسبة التجاوب: ${parseFloat(t.response_rate_percentage || 99.0).toFixed(0)}%</span>
|
|
</div>
|
|
</div>
|
|
|
|
<p style="font-size: 12px; color: var(--text-secondary); line-height: 1.5; margin-bottom: 16px;">
|
|
${escapeHtml(t.bio || 'شرح معمق ومبسط للمنهاج الوزاري الأردني مع متابعة فردية فورية لكل طالب.')}
|
|
</p>
|
|
</div>
|
|
|
|
<div style="display: flex; gap: 8px; margin-top: 10px;">
|
|
<button type="button" onclick="startDirectChatWithTeacher(${t.id}, '${escapeHtml(t.full_name)}')" class="btn-primary" style="flex: 1; padding: 9px; font-size: 12px;">
|
|
تحدث مع الأستاذ 💬
|
|
</button>
|
|
<button type="button" onclick="openTeacherRatingModal(${t.id}, '${escapeHtml(t.full_name)}')" style="background: rgba(245,158,11,0.12); border: 1px solid rgba(245,158,11,0.3); color: var(--accent-gold); border-radius: 980px; padding: 0 16px; font-size: 12px; font-weight: 700; cursor: pointer;">
|
|
تقييم ⭐
|
|
</button>
|
|
</div>
|
|
</div>
|
|
`).join('');
|
|
}
|
|
|
|
// ==========================================
|
|
// Print Utility (طباعة المحتوى للطلاب)
|
|
// ==========================================
|
|
function printElement(elementId, title = 'صَقِل - طباعة') {
|
|
const el = document.getElementById(elementId);
|
|
if (!el) {
|
|
showError('المحتوى غير متوفر للطباعة');
|
|
return;
|
|
}
|
|
|
|
// Clone the element to safely modify it before printing
|
|
const clone = el.cloneNode(true);
|
|
|
|
// Remove interactive elements that shouldn't be printed
|
|
const removeSelectors = ['button', 'input[type="range"]', '.no-print'];
|
|
removeSelectors.forEach(sel => {
|
|
const elements = clone.querySelectorAll(sel);
|
|
elements.forEach(e => e.remove());
|
|
});
|
|
|
|
// Expand all steplab steps if they are hidden
|
|
const hiddenSteps = clone.querySelectorAll('.studio-card > div[style*="display: none"]');
|
|
hiddenSteps.forEach(e => { e.style.display = 'block'; });
|
|
const dimCards = clone.querySelectorAll('.studio-card[style*="opacity"]');
|
|
dimCards.forEach(e => { e.style.opacity = '1'; });
|
|
|
|
const printWindow = window.open('', '', 'width=900,height=900');
|
|
printWindow.document.write(`
|
|
<html dir="rtl" lang="ar">
|
|
<head>
|
|
<title>${title}</title>
|
|
<link href="https://fonts.googleapis.com/css2?family=Cairo:wght@400;600;700;800;900&display=swap" rel="stylesheet">
|
|
<style>
|
|
:root {
|
|
--accent-cyan: #000;
|
|
--accent-gold: #000;
|
|
--accent-purple: #000;
|
|
--text-muted: #444;
|
|
--text-secondary: #222;
|
|
--border: #ccc;
|
|
}
|
|
body {
|
|
font-family: 'Cairo', system-ui, sans-serif;
|
|
padding: 30px;
|
|
color: #000;
|
|
background: #fff;
|
|
line-height: 1.6;
|
|
}
|
|
h3, h4 { color: #000 !important; }
|
|
/* Force colors to black/white for print */
|
|
* {
|
|
color: #000 !important;
|
|
text-shadow: none !important;
|
|
box-shadow: none !important;
|
|
}
|
|
.studio-card {
|
|
border: 1px solid #aaa !important;
|
|
margin-bottom: 20px;
|
|
padding: 20px;
|
|
border-radius: 8px;
|
|
background: #fff !important;
|
|
}
|
|
.step-card { border: 1px solid #ccc; margin-bottom: 15px; padding: 15px; border-radius: 8px; }
|
|
/* Show originally hidden step bodies */
|
|
#steplab_steps_ladder { display: flex !important; flex-direction: column !important; }
|
|
#steplab_steps_ladder .studio-card div { display: block !important; }
|
|
|
|
@media print {
|
|
@page { margin: 1.5cm; }
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div style="display: flex; justify-content: space-between; align-items: center; border-bottom: 2px solid #000; padding-bottom: 15px; margin-bottom: 25px;">
|
|
<div>
|
|
<h2 style="margin: 0;">منصة صَقِل التعليمية</h2>
|
|
<span style="font-size: 14px; color: #555;">المرجع المطبوع - استوديو الطالب</span>
|
|
</div>
|
|
<div style="text-align: left;">
|
|
<h3 style="margin: 0; font-size: 16px;">${title}</h3>
|
|
</div>
|
|
</div>
|
|
${clone.innerHTML}
|
|
|
|
<div style="margin-top: 40px; border-top: 1px dashed #ccc; padding-top: 10px; font-size: 12px; text-align: center;">
|
|
حقوق الطبع محفوظة لمنصة صَقِل - تم توليد هذه الورقة بناءً على المنهاج الوزاري الأردني.
|
|
</div>
|
|
</body>
|
|
</html>
|
|
`);
|
|
|
|
printWindow.document.close();
|
|
printWindow.focus();
|
|
|
|
setTimeout(() => {
|
|
printWindow.print();
|
|
printWindow.close();
|
|
}, 800);
|
|
}
|
|
|
|
</script>
|
|
</body>
|
|
</html>
|
|
<?php
|
|
return ob_get_clean();
|
|
}
|
|
}
|