130 lines
7.4 KiB
PHP
130 lines
7.4 KiB
PHP
<?php
|
|
require_once __DIR__ . '/includes/app.php';
|
|
$subscription = current_subscription();
|
|
$history = [];
|
|
$enrolled_courses = [];
|
|
$db = db();
|
|
|
|
if ($subscription) {
|
|
$history = fetch_subscriptions_by_email((string) $subscription['email']);
|
|
|
|
// Fetch enrolled courses for this student
|
|
$student_id = (int) $subscription['id'];
|
|
$stmt = $db->prepare("
|
|
SELECT c.*
|
|
FROM courses c
|
|
JOIN course_students cs ON c.id = cs.course_id
|
|
WHERE cs.student_id = ? AND c.status = 'active'
|
|
");
|
|
$stmt->execute([$student_id]);
|
|
$enrolled_courses = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
}
|
|
|
|
render_head(
|
|
t('Student dashboard', 'لوحة الطالب'),
|
|
t('Review the active subscription, upcoming live classes, and access to subject detail pages.', 'راجع الاشتراك النشط والفصول المباشرة القادمة والوصول إلى صفحات تفاصيل المواد.')
|
|
);
|
|
render_nav('dashboard.php');
|
|
?>
|
|
<main class="py-5">
|
|
<div class="container">
|
|
<?php if (!$subscription): ?>
|
|
<div class="panel-card text-center">
|
|
<span class="eyebrow"><?= h(t('Student dashboard', 'لوحة الطالب')) ?></span>
|
|
<h1 class="section-title mb-2"><?= h(t('No active subscription yet', 'لا يوجد اشتراك نشط بعد')) ?></h1>
|
|
<p class="text-secondary mb-4"><?= h(t('Start with pricing, complete the checkout form, and your personalized classroom dashboard will appear here.', 'ابدأ بالتسعير وأكمل نموذج الدفع وستظهر هنا لوحة الفصول الشخصية الخاصة بك.')) ?></p>
|
|
<div class="d-flex justify-content-center flex-wrap gap-2">
|
|
<a class="btn btn-dark" href="<?= h(app_url('pricing.php')) ?>"><?= h(t('Choose a plan', 'اختر خطة')) ?></a>
|
|
<a class="btn btn-outline-dark" href="<?= h(app_url('courses.php')) ?>"><?= h(t('Browse courses', 'تصفح الدورات')) ?></a>
|
|
</div>
|
|
</div>
|
|
<?php else: ?>
|
|
<?php $plan = get_plan($subscription['plan_key']) ?? get_plan('plus'); ?>
|
|
<div class="row g-4">
|
|
<div class="col-lg-8">
|
|
<div class="panel-card mb-4">
|
|
<div class="d-flex flex-wrap justify-content-between gap-3 align-items-start">
|
|
<div>
|
|
<span class="eyebrow"><?= h(t('Active Profile', 'الملف النشط')) ?></span>
|
|
<h1 class="section-title mb-2"><?= h(t('Welcome back, ', 'مرحباً بعودتك، ') . $subscription['full_name']) ?></h1>
|
|
<p class="text-secondary mb-0"><?= h(t('Here are your enrolled courses and upcoming live lessons.', 'إليك دوراتك المسجلة والدروس المباشرة القادمة.')) ?></p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<h2 class="h5 mb-3"><?= h(t('My Enrolled Courses', 'دوراتي المسجلة')) ?></h2>
|
|
<div class="row g-3 mb-4">
|
|
<?php foreach ($enrolled_courses as $course): ?>
|
|
<?php
|
|
// Fetch next or current live lesson
|
|
$live_stmt = $db->prepare("
|
|
SELECT *
|
|
FROM course_live_lessons
|
|
WHERE course_id = ? AND status != 'ended'
|
|
ORDER BY scheduled_at ASC
|
|
LIMIT 1
|
|
");
|
|
$live_stmt->execute([$course['id']]);
|
|
$next_lesson = $live_stmt->fetch(PDO::FETCH_ASSOC);
|
|
?>
|
|
<div class="col-md-6">
|
|
<article class="panel-card h-100 d-flex flex-column" style="padding: 1.25rem;">
|
|
<?php if ($course['picture']): ?>
|
|
<img src="<?= h($course['picture']) ?>" class="img-fluid rounded mb-3" style="object-fit:cover; height:120px; width:100%;" alt="">
|
|
<?php endif; ?>
|
|
<div class="d-flex justify-content-between align-items-start gap-3 mb-2">
|
|
<div>
|
|
<h2 class="h6 mb-1"><?= h(t($course['name_en'], $course['name_ar'])) ?></h2>
|
|
</div>
|
|
</div>
|
|
|
|
<?php if ($next_lesson): ?>
|
|
<div class="mt-2 p-2 bg-light rounded border border-light-subtle">
|
|
<p class="small fw-bold mb-1">
|
|
<?php if ($next_lesson['status'] === 'live'): ?>
|
|
<span class="badge bg-danger animate-pulse me-1"><?= h(t('LIVE', 'مباشر')) ?></span>
|
|
<?php else: ?>
|
|
<span class="badge bg-warning text-dark me-1"><?= h(t('Upcoming', 'قادم')) ?></span>
|
|
<?php endif; ?>
|
|
<?= h($next_lesson['title']) ?>
|
|
</p>
|
|
<p class="text-secondary small mb-2"><?= h(date('Y-m-d H:i', strtotime($next_lesson['scheduled_at']))) ?></p>
|
|
|
|
<?php if ($next_lesson['status'] === 'live'): ?>
|
|
<a class="btn btn-sm btn-danger text-white w-100" href="<?= h(app_url('live_lesson.php', ['id' => $next_lesson['id']])) ?>"><?= h(t('Join Lesson Now', 'انضم للدرس الآن')) ?></a>
|
|
<?php else: ?>
|
|
<button class="btn btn-sm btn-outline-secondary w-100" disabled><?= h(t('Waiting for teacher...', 'في انتظار المعلم...')) ?></button>
|
|
<?php endif; ?>
|
|
</div>
|
|
<?php else: ?>
|
|
<p class="text-secondary small mt-2 mb-3 flex-grow-1"><?= h(t('No upcoming live lessons.', 'لا توجد دروس مباشرة قادمة.')) ?></p>
|
|
<?php endif; ?>
|
|
</article>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
|
|
<?php if (empty($enrolled_courses)): ?>
|
|
<div class="col-12">
|
|
<div class="alert alert-info"><?= h(t('You are not enrolled in any courses yet. Browse the homepage to find courses.', 'أنت غير مسجل في أي دورات بعد. تصفح الصفحة الرئيسية للبحث عن دورات.')) ?></div>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
|
|
</div>
|
|
<div class="col-lg-4">
|
|
<aside class="panel-card sticky-card">
|
|
<h2 class="h5 mb-3"><?= h(t('Student profile', 'ملف الطالب')) ?></h2>
|
|
<div class="summary-row"><span><?= h(t('Preferred language', 'اللغة المفضلة')) ?></span><strong><?= h($subscription['preferred_language'] === 'ar' ? 'العربية' : 'English') ?></strong></div>
|
|
<div class="summary-row"><span><?= h(t('WhatsApp reminders', 'تذكيرات واتساب')) ?></span><strong><?= h((int) $subscription['wablas_opt_in'] === 1 ? t('Enabled', 'مفعلة') : t('Off', 'متوقفة')) ?></strong></div>
|
|
<hr>
|
|
<div class="d-grid gap-2">
|
|
<a class="btn btn-dark" href="<?= h(app_url('courses.php')) ?>"><?= h(t('Explore more courses', 'استكشف المزيد من الدورات')) ?></a>
|
|
<a class="btn btn-outline-dark" href="<?= h(app_url('teacher.php')) ?>"><?= h(t('Open teacher view', 'افتح عرض المعلم')) ?></a>
|
|
</div>
|
|
</aside>
|
|
</div>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
</main>
|
|
<?php render_footer(); ?>
|