39496-vm/subject.php
2026-04-06 04:21:26 +00:00

93 lines
5.2 KiB
PHP

<?php
require_once __DIR__ . '/includes/app.php';
$slug = (string) ($_GET['slug'] ?? '');
$subject = get_subject($slug);
$subscription = current_subscription();
$hasAccess = $subscription !== null;
if (!$subject) {
header('Location: ' . app_url('catalog.php'));
exit;
}
if ($_SERVER['REQUEST_METHOD'] === 'POST' && $hasAccess && isset($_POST['action']) && $_POST['action'] === 'toggle_module') {
$moduleIndex = (int) $_POST['module_index'];
$completed = (int) ($_POST['completed'] ?? 0) === 1;
toggle_module_progress((int) $subscription['id'], $slug, $moduleIndex, $completed);
header('Location: ' . app_url('subject.php', ['slug' => $slug]));
exit;
}
$completedModules = $hasAccess ? get_completed_modules((int) $subscription['id'], $slug) : [];
render_head(subject_title($subject), subject_summary($subject));
render_nav('catalog.php');
?>
<main class="py-5">
<div class="container">
<div class="row g-4">
<div class="col-lg-8">
<div class="panel-card">
<div class="mb-4">
<a class="text-secondary text-decoration-none small d-inline-flex align-items-center mb-3" href="<?= h(app_url('catalog.php')) ?>">&larr; <?= h(t('Back to catalog', 'العودة للكتالوج')) ?></a>
<div class="d-flex justify-content-between align-items-start mb-3">
<div>
<h1 class="section-title mb-2"><?= h(subject_title($subject)) ?></h1>
<p class="text-secondary mb-0"><?= h(subject_summary($subject)) ?></p>
</div>
</div>
<span class="mini-tag"><?= h(subject_level($subject)) ?></span>
</div>
<div class="detail-meta-grid mb-5">
<div><strong><?= h(t('Teacher', 'المعلم')) ?></strong><span><?= h(subject_teacher($subject)) ?></span></div>
<div><strong><?= h(t('Duration', 'المدة')) ?></strong><span><?= h(subject_duration($subject)) ?></span></div>
<?php if ($hasAccess): ?>
<div><strong><?= h(t('Live classroom', 'الفصل المباشر')) ?></strong><span><?= h(subject_next_live($subject)) ?></span></div>
<?php endif; ?>
</div>
<h2 class="h5 mb-3"><?= h(t('Modules & Curriculum', 'الوحدات والمنهج')) ?></h2>
<ul class="list-unstyled compact-list mb-0">
<?php foreach (subject_modules($subject) as $index => $module): ?>
<li class="d-flex align-items-center justify-content-between">
<span><?= h($module) ?></span>
<?php if ($hasAccess): ?>
<?php $isCompleted = in_array($index, $completedModules, false); ?>
<form method="post" class="m-0 p-0">
<input type="hidden" name="action" value="toggle_module">
<input type="hidden" name="module_index" value="<?= h((string) $index) ?>">
<input type="hidden" name="completed" value="<?= $isCompleted ? '0' : '1' ?>">
<button type="submit" class="btn btn-sm <?= $isCompleted ? 'btn-success' : 'btn-outline-secondary' ?>">
<?= $isCompleted ? h(t('Completed', 'مكتمل')) : h(t('Mark complete', 'تحديد كمكتمل')) ?>
</button>
</form>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
</div>
</div>
<div class="col-lg-4">
<aside class="panel-card sticky-card text-center">
<?php if ($hasAccess): ?>
<div class="mb-3">
<span class="badge bg-success-subtle text-success-emphasis border border-success-subtle px-3 py-2"><?= h(t('Access granted', 'صلاحية الدخول ممنوحة')) ?></span>
</div>
<p class="text-secondary small mb-4"><?= h(t('You can enter the live classroom when the session begins.', 'يمكنك دخول الفصل المباشر عند بدء الجلسة.')) ?></p>
<div class="d-grid gap-2">
<a class="btn btn-dark" href="<?= h($subject['meet_url']) ?>" target="_blank" rel="noreferrer"><?= h(t('Open Google Meet lobby', 'افتح صالة Google Meet')) ?></a>
<a class="btn btn-outline-dark" href="<?= h(app_url('dashboard.php', ['subscription_id' => (int) $subscription['id']])) ?>"><?= h(t('Go to dashboard', 'اذهب إلى لوحة التحكم')) ?></a>
</div>
<?php else: ?>
<div class="mb-3">
<span class="badge bg-secondary-subtle text-secondary-emphasis border border-secondary-subtle px-3 py-2"><?= h(t('Subscription required', 'يلزم الاشتراك')) ?></span>
</div>
<p class="text-secondary small mb-4"><?= h(t('Subscribe to a plan to unlock live classrooms, module materials, and teacher office hours.', 'اشترك في خطة لفتح الفصول المباشرة ومواد الوحدات والساعات المكتبية للمعلم.')) ?></p>
<a class="btn btn-dark w-100" href="<?= h(app_url('pricing.php')) ?>"><?= h(t('Choose a plan', 'اختر خطة')) ?></a>
<?php endif; ?>
</aside>
</div>
</div>
</div>
</main>
<?php render_footer(); ?>