From 9838df1125277fb89641d9c8ef6abd9df53cd04c Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Mon, 6 Apr 2026 13:02:53 +0000 Subject: [PATCH] Autosave: 20260406-130252 --- teacher.php | 386 ++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 348 insertions(+), 38 deletions(-) diff --git a/teacher.php b/teacher.php index f75aa28..58f9253 100644 --- a/teacher.php +++ b/teacher.php @@ -1,51 +1,361 @@ 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 === '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('Preview the teacher-side classroom view with upcoming live rooms and student demand signals.', 'عاين واجهة المعلم مع الغرف المباشرة القادمة ومؤشرات طلب الطلاب.') + t('Manage your courses, students, and activities.', 'إدارة دوراتك وطلابك وأنشطتك.') ); render_nav('teacher.php'); ?>
-
-
- -

-

-
- -
-
-
-
-
4
-
-
- -
-
-
-
-

-

-
- -
-
-
-
-
-
- - -
-
+
+
+ +

- + + +
+ + + 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 && $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); + ?> + +
+
+

-

+

+
+ +
+ +
+
+ + + + +
+ + + + + + + + + + + + + + + + + + + + +
+ + + +
+
+ + +
+ +
+ +
+
+
- + \ No newline at end of file