prepare("SELECT id, name_en, name_ar FROM courses WHERE id = ? AND teacher_id = ?"); $stmt->execute([$course_id, $teacher_id]); return $stmt->fetch(PDO::FETCH_ASSOC); } // Handle POST actions for activities and assessments if ($_SERVER['REQUEST_METHOD'] === 'POST') { $post_action = $_POST['action'] ?? ''; if ($post_action === 'add_activity' || $post_action === 'edit_activity') { $c_id = (int)$_POST['course_id']; $course = owns_course($db, $c_id, $teacher_id); if ($course) { $act_id = (int)($_POST['activity_id'] ?? 0); $title_en = $_POST['title_en'] ?? ''; $title_ar = $_POST['title_ar'] ?? ''; $desc_en = $_POST['description_en'] ?? ''; $desc_ar = $_POST['description_ar'] ?? ''; if ($post_action === 'add_activity') { $stmt = $db->prepare("INSERT INTO course_activities (course_id, title_en, title_ar, description_en, description_ar) VALUES (?, ?, ?, ?, ?)"); $stmt->execute([$c_id, $title_en, $title_ar, $desc_en, $desc_ar]); } else if ($post_action === 'edit_activity' && $act_id > 0) { $stmt = $db->prepare("UPDATE course_activities SET title_en = ?, title_ar = ?, description_en = ?, description_ar = ? WHERE id = ? AND course_id = ?"); $stmt->execute([$title_en, $title_ar, $desc_en, $desc_ar, $act_id, $c_id]); } } header("Location: " . app_url('teacher.php', ['action' => 'activities', 'course_id' => $c_id])); 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'] ?? ''; $meet_url = trim($_POST['meet_url'] ?? ''); 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, meet_url) VALUES (?, ?, ?, ?, ?)"); $stmt->execute([$c_id, $title, $scheduled_at, $room_name, $meet_url]); } else if ($post_action === 'edit_live' && $live_id > 0) { $stmt = $db->prepare("UPDATE course_live_lessons SET title = ?, scheduled_at = ?, meet_url = ? WHERE id = ? AND course_id = ?"); $stmt->execute([$title, $scheduled_at, $meet_url, $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') { $c_id = (int)$_POST['course_id']; $act_id = (int)$_POST['activity_id']; if (owns_course($db, $c_id, $teacher_id)) { $stmt = $db->prepare("DELETE FROM course_activities WHERE id = ? AND course_id = ?"); $stmt->execute([$act_id, $c_id]); } header("Location: " . app_url('teacher.php', ['action' => 'activities', 'course_id' => $c_id])); exit; } if ($post_action === 'save_assessments') { $c_id = (int)$_POST['course_id']; $act_id = (int)$_POST['activity_id']; if (owns_course($db, $c_id, $teacher_id)) { $scores = $_POST['scores'] ?? []; $feedbacks = $_POST['feedbacks'] ?? []; $stmt = $db->prepare("INSERT INTO student_assessments (activity_id, student_id, score, feedback) VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE score = VALUES(score), feedback = VALUES(feedback)"); foreach ($scores as $s_id => $score) { $s_id = (int)$s_id; $score_val = ($score !== '') ? (float)$score : null; $fb = $feedbacks[$s_id] ?? ''; $stmt->execute([$act_id, $s_id, $score_val, $fb]); } } header("Location: " . app_url('teacher.php', ['action' => 'assessments', 'course_id' => $c_id, 'activity_id' => $act_id])); exit; } } render_head( t('Teacher workspace', 'مساحة المعلم'), t('Manage your courses, students, and activities.', 'إدارة دوراتك وطلابك وأنشطتك.') ); render_nav('teacher.php'); ?>

prepare("SELECT c.*, (SELECT COUNT(*) FROM course_students cs WHERE cs.course_id = c.id) as students_count FROM courses c WHERE c.teacher_id = ? AND c.status = 'active'"); $stmt->execute([$teacher_id]); $courses = $stmt->fetchAll(PDO::FETCH_ASSOC); ?>
No Image

0): ?> prepare(" SELECT s.id, s.full_name, s.email, s.whatsapp, cs.assigned_at FROM course_students cs JOIN student_subscriptions s ON cs.student_id = s.id WHERE cs.course_id = ? ORDER BY cs.assigned_at DESC "); $stmt->execute([$course_id]); $students = $stmt->fetchAll(PDO::FETCH_ASSOC); ?>

-

0): ?> prepare("SELECT * FROM course_activities WHERE course_id = ? ORDER BY created_at DESC"); $stmt->execute([$course_id]); $activities = $stmt->fetchAll(PDO::FETCH_ASSOC); ?>

-

0): ?> prepare("SELECT * FROM course_live_lessons WHERE course_id = ? ORDER BY scheduled_at ASC"); $stmt->execute([$course_id]); $lessons = $stmt->fetchAll(PDO::FETCH_ASSOC); ?>

-

0 && $activity_id > 0): ?> prepare("SELECT title_en, title_ar FROM course_activities WHERE id = ? AND course_id = ?"); $stmt->execute([$activity_id, $course_id]); $activity = $stmt->fetch(PDO::FETCH_ASSOC); if (!$activity) die('Activity not found'); $stmt = $db->prepare(" SELECT s.id as student_id, s.full_name, sa.score, sa.feedback FROM course_students cs JOIN student_subscriptions s ON cs.student_id = s.id LEFT JOIN student_assessments sa ON sa.student_id = s.id AND sa.activity_id = ? WHERE cs.course_id = ? ORDER BY s.full_name ASC "); $stmt->execute([$activity_id, $course_id]); $students = $stmt->fetchAll(PDO::FETCH_ASSOC); ?>

-