live lessons

This commit is contained in:
Flatlogic Bot 2026-04-06 13:49:07 +00:00
parent 9838df1125
commit c40ef2f754
3 changed files with 383 additions and 57 deletions

View File

@ -2,9 +2,24 @@
require_once __DIR__ . '/includes/app.php'; require_once __DIR__ . '/includes/app.php';
$subscription = current_subscription(); $subscription = current_subscription();
$history = []; $history = [];
$enrolled_courses = [];
$db = db();
if ($subscription) { if ($subscription) {
$history = fetch_subscriptions_by_email((string) $subscription['email']); $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( render_head(
t('Student dashboard', 'لوحة الطالب'), t('Student dashboard', 'لوحة الطالب'),
t('Review the active subscription, upcoming live classes, and access to subject detail pages.', 'راجع الاشتراك النشط والفصول المباشرة القادمة والوصول إلى صفحات تفاصيل المواد.') t('Review the active subscription, upcoming live classes, and access to subject detail pages.', 'راجع الاشتراك النشط والفصول المباشرة القادمة والوصول إلى صفحات تفاصيل المواد.')
@ -20,7 +35,7 @@ render_nav('dashboard.php');
<p class="text-secondary mb-4"><?= h(t('Start with pricing, complete the checkout form, and your personalized classroom dashboard will appear here.', 'ابدأ بالتسعير وأكمل نموذج الدفع وستظهر هنا لوحة الفصول الشخصية الخاصة بك.')) ?></p> <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"> <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-dark" href="<?= h(app_url('pricing.php')) ?>"><?= h(t('Choose a plan', 'اختر خطة')) ?></a>
<a class="btn btn-outline-dark" href="<?= h(app_url('catalog.php')) ?>"><?= h(t('Browse catalog', 'تصفح الكتالوج')) ?></a> <a class="btn btn-outline-dark" href="<?= h(app_url('index.php')) ?>"><?= h(t('Browse courses', 'تصفح الدورات')) ?></a>
</div> </div>
</div> </div>
<?php else: ?> <?php else: ?>
@ -30,86 +45,80 @@ render_nav('dashboard.php');
<div class="panel-card mb-4"> <div class="panel-card mb-4">
<div class="d-flex flex-wrap justify-content-between gap-3 align-items-start"> <div class="d-flex flex-wrap justify-content-between gap-3 align-items-start">
<div> <div>
<span class="eyebrow"><?= h(t('Active subscription', 'الاشتراك النشط')) ?></span> <span class="eyebrow"><?= h(t('Active Profile', 'الملف النشط')) ?></span>
<h1 class="section-title mb-2"><?= h(t('Welcome back, ', 'مرحباً بعودتك، ') . $subscription['full_name']) ?></h1> <h1 class="section-title mb-2"><?= h(t('Welcome back, ', 'مرحباً بعودتك، ') . $subscription['full_name']) ?></h1>
<p class="text-secondary mb-0"><?= h(t('Your plan is active and your next live classrooms are listed below.', 'خطتك نشطة وتم إدراج الفصول المباشرة القادمة أدناه.')) ?></p> <p class="text-secondary mb-0"><?= h(t('Here are your enrolled courses and upcoming live lessons.', 'إليك دوراتك المسجلة والدروس المباشرة القادمة.')) ?></p>
</div> </div>
<span class="badge bg-success-subtle text-success-emphasis border border-success-subtle px-3 py-2"><?= h(plan_name($plan)) ?></span>
</div> </div>
</div> </div>
<h2 class="h5 mb-3"><?= h(t('My Enrolled Courses', 'دوراتي المسجلة')) ?></h2>
<div class="row g-3 mb-4"> <div class="row g-3 mb-4">
<?php $unlocked = array_slice(subjects_catalog(), 0, $plan['subjects_limit'] >= 999 ? 4 : $plan['subjects_limit']); ?> <?php foreach ($enrolled_courses as $course): ?>
<?php foreach ($unlocked as $subject): ?>
<?php <?php
$modules = subject_modules($subject); // Fetch next or current live lesson
$totalModules = count($modules); $live_stmt = $db->prepare("
$completed = count(get_completed_modules((int) $subscription['id'], $subject['slug'])); SELECT *
$progress = $totalModules > 0 ? round(($completed / $totalModules) * 100) : 0; 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"> <div class="col-md-6">
<article class="subject-card h-100 d-flex flex-column"> <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 class="d-flex justify-content-between align-items-start gap-3 mb-2">
<div> <div>
<h2 class="h6 mb-1"><?= h(subject_title($subject)) ?></h2> <h2 class="h6 mb-1"><?= h(t($course['name_en'], $course['name_ar'])) ?></h2>
<p class="small text-secondary mb-0"><?= h(subject_teacher($subject)) ?></p>
</div>
<span class="mini-tag"><?= h(t('Unlocked', 'مفتوحة')) ?></span>
</div>
<div class="mb-3">
<p class="text-secondary small mb-1"><?= h(t('Progress:', 'التقدم:')) ?> <?= h((string) $progress) ?>%</p>
<div class="progress" style="height: 6px;">
<div class="progress-bar bg-dark" role="progressbar" style="width: <?= h((string) $progress) ?>%;" aria-valuenow="<?= h((string) $progress) ?>" aria-valuemin="0" aria-valuemax="100"></div>
</div> </div>
</div> </div>
<p class="text-secondary small mb-3 flex-grow-1"><?= h(t('Next live:', 'الجلسة المباشرة القادمة:')) ?> <?= h(subject_next_live($subject)) ?></p>
<div class="d-flex gap-2"> <?php if ($next_lesson): ?>
<a class="btn btn-sm btn-dark" href="<?= h($subject['meet_url']) ?>" target="_blank" rel="noreferrer"><?= h(t('Meet', 'ميت')) ?></a> <div class="mt-2 p-2 bg-light rounded border border-light-subtle">
<a class="btn btn-sm btn-outline-dark" href="<?= h(app_url('subject.php', ['slug' => $subject['slug']])) ?>"><?= h(t('Details', 'التفاصيل')) ?></a> <p class="small fw-bold mb-1">
</div> <?php if ($next_lesson['status'] === 'live'): ?>
<span class="badge bg-danger animate-pulse me-1">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> </article>
</div> </div>
<?php endforeach; ?> <?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="panel-card">
<div class="d-flex justify-content-between align-items-center mb-3">
<h2 class="h5 mb-0"><?= h(t('Subscription history', 'سجل الاشتراكات')) ?></h2>
<a class="link-dark text-decoration-none fw-semibold" href="<?= h(app_url('subscription.php', ['id' => (int) $subscription['id']])) ?>"><?= h(t('Open current detail', 'افتح التفاصيل الحالية')) ?></a>
</div>
<div class="table-responsive">
<table class="table align-middle dashboard-table mb-0">
<thead>
<tr>
<th><?= h(t('Reference', 'المرجع')) ?></th>
<th><?= h(t('Plan', 'الخطة')) ?></th>
<th><?= h(t('Created', 'تاريخ الإنشاء')) ?></th>
<th><?= h(t('Action', 'الإجراء')) ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($history as $item): ?>
<?php $historyPlan = get_plan($item['plan_key']) ?? get_plan('plus'); ?>
<tr>
<td><?= h($item['thawani_reference']) ?></td>
<td><?= h(plan_name($historyPlan)) ?></td>
<td><?= h((string) $item['created_at']) ?></td>
<td><a class="btn btn-sm btn-outline-dark" href="<?= h(app_url('subscription.php', ['id' => (int) $item['id']])) ?>"><?= h(t('View', 'عرض')) ?></a></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
</div> </div>
<div class="col-lg-4"> <div class="col-lg-4">
<aside class="panel-card sticky-card"> <aside class="panel-card sticky-card">
<h2 class="h5 mb-3"><?= h(t('Student profile', 'ملف الطالب')) ?></h2> <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('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> <div class="summary-row"><span><?= h(t('WhatsApp reminders', 'تذكيرات واتساب')) ?></span><strong><?= h((int) $subscription['wablas_opt_in'] === 1 ? t('Enabled', 'مفعلة') : t('Off', 'متوقفة')) ?></strong></div>
<div class="summary-row"><span><?= h(t('Payment gateway', 'بوابة الدفع')) ?></span><strong><?= h($subscription['payment_gateway']) ?></strong></div>
<div class="summary-row"><span><?= h(t('Live classroom', 'الفصل المباشر')) ?></span><strong>Google Meet</strong></div>
<hr> <hr>
<div class="d-grid gap-2"> <div class="d-grid gap-2">
<a class="btn btn-dark" href="<?= h(app_url('catalog.php')) ?>"><?= h(t('Explore more subjects', 'استكشف المزيد من المواد')) ?></a> <a class="btn btn-dark" href="<?= h(app_url('index.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> <a class="btn btn-outline-dark" href="<?= h(app_url('teacher.php')) ?>"><?= h(t('Open teacher view', 'افتح عرض المعلم')) ?></a>
</div> </div>
</aside> </aside>

172
live_lesson.php Normal file
View File

@ -0,0 +1,172 @@
<?php
require_once __DIR__ . '/includes/app.php';
$lesson_id = (int)($_GET['id'] ?? 0);
$db = db();
$stmt = $db->prepare("
SELECT l.*, c.name_en, c.name_ar, c.teacher_id
FROM course_live_lessons l
JOIN courses c ON l.course_id = c.id
WHERE l.id = ?
");
$stmt->execute([$lesson_id]);
$lesson = $stmt->fetch(PDO::FETCH_ASSOC);
if (!$lesson) {
die("Lesson not found.");
}
// Check role
$is_teacher = false;
$is_student = false;
// Mock student and teacher IDs for the prototype based on current session
// In reality, this would be based on logged-in user session
$current_teacher_id = 1; // Used in teacher.php
$current_student_id = 1; // Assuming we use 1 for student preview too
if (isset($_GET['as']) && $_GET['as'] === 'teacher') {
if ($lesson['teacher_id'] == $current_teacher_id) {
$is_teacher = true;
}
} else {
// Basic check if student is in course
$is_student = true;
}
if (!$is_teacher && !$is_student) {
die("Unauthorized access.");
}
// Ensure lesson status logic
if ($is_teacher && isset($_GET['start'])) {
if ($lesson['status'] === 'scheduled') {
$db->prepare("UPDATE course_live_lessons SET status = 'live' WHERE id = ?")->execute([$lesson_id]);
$lesson['status'] = 'live';
}
}
if ($is_teacher && isset($_GET['end'])) {
if ($lesson['status'] === 'live') {
$db->prepare("UPDATE course_live_lessons SET status = 'ended' WHERE id = ?")->execute([$lesson_id]);
$lesson['status'] = 'ended';
}
}
$room_name = $lesson['room_name'];
$user_display_name = $is_teacher ? 'Teacher' : 'Student';
render_head(
t('Live Lesson: ', 'درس مباشر: ') . t($lesson['title'], $lesson['title']),
t('Join the live streaming lesson.', 'انضم إلى بث الدرس المباشر.')
);
// We won't render normal nav here to maximize screen space for the lesson, or we render a simplified one
?>
<style>
body, html { margin: 0; padding: 0; height: 100%; overflow: hidden; background: #000; }
.lesson-header {
background: #111;
color: #fff;
padding: 10px 20px;
display: flex;
justify-content: space-between;
align-items: center;
z-index: 10;
position: relative;
}
.lesson-title { margin: 0; font-size: 1.2rem; font-weight: 500; }
#jitsi-container {
width: 100%;
height: calc(100vh - 56px); /* 56px is header height */
}
.btn-end { background: #dc3545; color: white; border: none; padding: 5px 15px; border-radius: 4px; text-decoration: none; font-size: 0.9rem; }
.btn-end:hover { background: #c82333; color: white; }
.btn-leave { background: #6c757d; color: white; border: none; padding: 5px 15px; border-radius: 4px; text-decoration: none; font-size: 0.9rem; }
</style>
<div class="lesson-header">
<div class="d-flex align-items-center gap-3">
<h1 class="lesson-title">
<span class="badge bg-danger animate-pulse me-2">LIVE</span>
<?= h(t($lesson['name_en'], $lesson['name_ar'])) ?> - <?= h($lesson['title']) ?>
</h1>
</div>
<div>
<?php if ($is_teacher): ?>
<?php if ($lesson['status'] !== 'ended'): ?>
<a href="?id=<?= $lesson_id ?>&as=teacher&end=1" class="btn-end" onclick="return confirm('End the live lesson for everyone?');"><?= t('End Lesson', 'إنهاء الدرس') ?></a>
<?php else: ?>
<span class="badge bg-secondary">Ended</span>
<?php endif; ?>
<a href="teacher.php?action=live&course_id=<?= $lesson['course_id'] ?>" class="btn-leave ms-2"><?= t('Back to Dashboard', 'العودة للوحة') ?></a>
<?php else: ?>
<a href="dashboard.php" class="btn-leave"><?= t('Leave', 'مغادرة') ?></a>
<?php endif; ?>
</div>
</div>
<?php if ($lesson['status'] === 'scheduled'): ?>
<div class="d-flex align-items-center justify-content-center text-white" style="height: calc(100vh - 56px);">
<div class="text-center">
<h2 class="mb-3"><?= t('Lesson hasn\'t started yet.', 'لم يبدأ الدرس بعد.') ?></h2>
<p class="text-secondary"><?= t('Scheduled for: ', 'مجدول في: ') ?> <?= date('Y-m-d H:i', strtotime($lesson['scheduled_at'])) ?></p>
<?php if ($is_teacher): ?>
<a href="?id=<?= $lesson_id ?>&as=teacher&start=1" class="btn btn-primary btn-lg mt-3"><?= t('Start Live Streaming Now', 'ابدأ البث المباشر الآن') ?></a>
<?php else: ?>
<button class="btn btn-outline-light mt-3" onclick="location.reload()"><?= t('Refresh', 'تحديث') ?></button>
<?php endif; ?>
</div>
</div>
<?php elseif ($lesson['status'] === 'ended'): ?>
<div class="d-flex align-items-center justify-content-center text-white" style="height: calc(100vh - 56px);">
<div class="text-center">
<h2 class="mb-3"><?= t('This live lesson has ended.', 'انتهى هذا الدرس المباشر.') ?></h2>
<p class="text-secondary"><?= t('Thank you for participating.', 'شكراً لمشاركتك.') ?></p>
</div>
</div>
<?php else: ?>
<!-- Jitsi Meet iframe container -->
<div id="jitsi-container"></div>
<script src="https://meet.jit.si/external_api.js"></script>
<script>
window.onload = () => {
const domain = 'meet.jit.si';
const options = {
roomName: '<?= htmlspecialchars(rawurlencode($room_name)) ?>',
width: '100%',
height: '100%',
parentNode: document.querySelector('#jitsi-container'),
userInfo: {
displayName: '<?= htmlspecialchars($user_display_name) ?>'
},
configOverwrite: {
prejoinPageEnabled: false,
startWithAudioMuted: <?= $is_teacher ? 'false' : 'true' ?>,
startWithVideoMuted: <?= $is_teacher ? 'false' : 'true' ?>,
disableDeepLinking: true
},
interfaceConfigOverwrite: {
SHOW_JITSI_WATERMARK: false,
SHOW_WATERMARK_FOR_GUESTS: false,
TOOLBAR_BUTTONS: [
'microphone', 'camera', 'closedcaptions', 'desktop', 'fullscreen',
'fodeviceselection', 'hangup', 'profile', 'chat', 'recording',
'livestreaming', 'etherpad', 'sharedvideo', 'settings', 'raisehand',
'videoquality', 'filmstrip', 'invite', 'feedback', 'stats', 'shortcuts',
'tileview', 'videobackgroundblur', 'download', 'help', 'mute-everyone',
'security'
]
}
};
const api = new JitsiMeetExternalAPI(domain, options);
<?php if ($is_teacher): ?>
// Any specific teacher controls
api.executeCommand('subject', '<?= h(t($lesson['name_en'], $lesson['name_ar'])) ?> - <?= h($lesson['title']) ?>');
<?php endif; ?>
};
</script>
<?php endif; ?>
</body>
</html>

View File

@ -41,6 +41,37 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
exit; exit;
} }
if ($post_action === 'add_live' || $post_action === 'edit_live') {
$c_id = (int)$_POST['course_id'];
$live_id = (int)($_POST['live_id'] ?? 0);
$title = $_POST['title'] ?? '';
$scheduled_at = $_POST['scheduled_at'] ?? '';
if (owns_course($db, $c_id, $teacher_id)) {
if ($post_action === 'add_live') {
$room_name = 'room_' . substr(md5(uniqid()), 0, 10);
$stmt = $db->prepare("INSERT INTO course_live_lessons (course_id, title, scheduled_at, room_name) VALUES (?, ?, ?, ?)");
$stmt->execute([$c_id, $title, $scheduled_at, $room_name]);
} else if ($post_action === 'edit_live' && $live_id > 0) {
$stmt = $db->prepare("UPDATE course_live_lessons SET title = ?, scheduled_at = ? WHERE id = ? AND course_id = ?");
$stmt->execute([$title, $scheduled_at, $live_id, $c_id]);
}
}
header("Location: " . app_url('teacher.php', ['action' => 'live', 'course_id' => $c_id]));
exit;
}
if ($post_action === 'delete_live') {
$c_id = (int)$_POST['course_id'];
$live_id = (int)$_POST['live_id'];
if (owns_course($db, $c_id, $teacher_id)) {
$stmt = $db->prepare("DELETE FROM course_live_lessons WHERE id = ? AND course_id = ?");
$stmt->execute([$live_id, $c_id]);
}
header("Location: " . app_url('teacher.php', ['action' => 'live', 'course_id' => $c_id]));
exit;
}
if ($post_action === 'delete_activity') { if ($post_action === 'delete_activity') {
$c_id = (int)$_POST['course_id']; $c_id = (int)$_POST['course_id'];
$act_id = (int)$_POST['activity_id']; $act_id = (int)$_POST['activity_id'];
@ -284,6 +315,120 @@ render_nav('teacher.php');
} }
</script> </script>
<?php elseif ($action === 'live' && $course_id > 0): ?>
<?php
$course = owns_course($db, $course_id, $teacher_id);
if (!$course) die('Unauthorized');
$stmt = $db->prepare("SELECT * FROM course_live_lessons WHERE course_id = ? ORDER BY scheduled_at ASC");
$stmt->execute([$course_id]);
$lessons = $stmt->fetchAll(PDO::FETCH_ASSOC);
?>
<div class="d-flex justify-content-between align-items-center mb-4">
<h2 class="h4 mb-0"><?= h(t($course['name_en'], $course['name_ar'])) ?> - <?= h(t('Live Lessons', 'دروس البث المباشر')) ?></h2>
<button class="btn btn-danger text-white" data-bs-toggle="modal" data-bs-target="#liveModal" onclick="resetLiveForm()">
<?= h(t('+ Schedule Lesson', '+ جدولة درس')) ?>
</button>
</div>
<div class="panel-card">
<div class="table-responsive">
<table class="table table-hover align-middle mb-0">
<thead>
<tr>
<th><?= h(t('Title', 'العنوان')) ?></th>
<th><?= h(t('Scheduled At', 'موعد الدرس')) ?></th>
<th><?= h(t('Status', 'الحالة')) ?></th>
<th><?= h(t('Actions', 'الإجراءات')) ?></th>
</tr>
</thead>
<tbody>
<?php foreach($lessons as $les): ?>
<tr>
<td><?= h($les['title']) ?></td>
<td><?= h(date('Y-m-d H:i', strtotime($les['scheduled_at']))) ?></td>
<td>
<?php if($les['status'] === 'scheduled'): ?>
<span class="badge bg-warning text-dark"><?= h(t('Scheduled', 'مجدول')) ?></span>
<?php elseif($les['status'] === 'live'): ?>
<span class="badge bg-danger animate-pulse"><?= h(t('LIVE', 'مباشر')) ?></span>
<?php else: ?>
<span class="badge bg-secondary"><?= h(t('Ended', 'منتهي')) ?></span>
<?php endif; ?>
</td>
<td>
<div class="d-flex gap-2">
<?php if($les['status'] !== 'ended'): ?>
<a href="live_lesson.php?id=<?= $les['id'] ?>&as=teacher" class="btn btn-sm btn-success text-white">
<?= h(t('Enter Studio', 'دخول الاستوديو')) ?>
</a>
<?php endif; ?>
<button class="btn btn-sm btn-outline-secondary" onclick="editLive(<?= htmlspecialchars(json_encode($les)) ?>)"><?= h(t('Edit', 'تعديل')) ?></button>
<form method="post" class="d-inline" onsubmit="return confirm('<?= h(t('Are you sure?', 'هل أنت متأكد؟')) ?>')">
<input type="hidden" name="action" value="delete_live">
<input type="hidden" name="course_id" value="<?= $course_id ?>">
<input type="hidden" name="live_id" value="<?= $les['id'] ?>">
<button type="submit" class="btn btn-sm btn-outline-danger"><?= h(t('Del', 'حذف')) ?></button>
</form>
</div>
</td>
</tr>
<?php endforeach; ?>
<?php if(empty($lessons)): ?>
<tr><td colspan="4" class="text-center text-muted"><?= h(t('No live lessons scheduled.', 'لا يوجد دروس مجدولة.')) ?></td></tr>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
<!-- Live Modal -->
<div class="modal fade" id="liveModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<form method="post">
<div class="modal-header">
<h5 class="modal-title"><?= h(t('Live Lesson', 'الدرس المباشر')) ?></h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<input type="hidden" name="action" id="modal_live_action" value="add_live">
<input type="hidden" name="course_id" value="<?= $course_id ?>">
<input type="hidden" name="live_id" id="modal_live_id" value="">
<div class="mb-3">
<label class="form-label"><?= h(t('Lesson Title', 'عنوان الدرس')) ?></label>
<input type="text" name="title" id="modal_live_title" class="form-control" required>
</div>
<div class="mb-3">
<label class="form-label"><?= h(t('Scheduled Time', 'وقت الدرس')) ?></label>
<input type="datetime-local" name="scheduled_at" id="modal_live_time" class="form-control" required>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal"><?= h(t('Cancel', 'إلغاء')) ?></button>
<button type="submit" class="btn btn-danger"><?= h(t('Save', 'حفظ')) ?></button>
</div>
</form>
</div>
</div>
</div>
<script>
function resetLiveForm() {
document.getElementById('modal_live_action').value = 'add_live';
document.getElementById('modal_live_id').value = '';
document.getElementById('modal_live_title').value = '';
document.getElementById('modal_live_time').value = '';
}
function editLive(les) {
document.getElementById('modal_live_action').value = 'edit_live';
document.getElementById('modal_live_id').value = les.id;
document.getElementById('modal_live_time').value = les.scheduled_at.replace(' ', 'T').substring(0, 16);
var modal = new bootstrap.Modal(document.getElementById('liveModal'));
modal.show();
}
</script>
<?php elseif ($action === 'assessments' && $course_id > 0 && $activity_id > 0): ?> <?php elseif ($action === 'assessments' && $course_id > 0 && $activity_id > 0): ?>
<?php <?php
$course = owns_course($db, $course_id, $teacher_id); $course = owns_course($db, $course_id, $teacher_id);