Dashboard'; // Role-based logic if ($role === 'teacher') { $page_title = 'Manage Exams'; // Handle form submissions for creating/editing exams if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['exam_name'])) { $exam_name = trim($_POST['exam_name']); if (!empty($exam_name)) { if (isset($_POST['exam_id']) && !empty($_POST['exam_id'])) { $stmt = $pdo->prepare('UPDATE exams SET name = ? WHERE id = ? AND created_by = ?'); $stmt->execute([$exam_name, $_POST['exam_id'], $user_id]); } else { $stmt = $pdo->prepare('INSERT INTO exams (name, created_by) VALUES (?, ?)'); $stmt->execute([$exam_name, $user_id]); } } header('Location: exams.php'); exit(); } // Handle exam deletion if (isset($_GET['delete_exam'])) { $stmt = $pdo->prepare('DELETE FROM exams WHERE id = ? AND created_by = ?'); $stmt->execute([$_GET['delete_exam'], $user_id]); header('Location: exams.php'); exit(); } // Fetch exams for the teacher view $stmt = $pdo->prepare('SELECT * FROM exams WHERE created_by = ? ORDER BY created_at DESC'); $stmt->execute([$user_id]); $exams = $stmt->fetchAll(); // Check if we are editing an exam $edit_exam = null; if (isset($_GET['edit_exam'])) { $stmt = $pdo->prepare('SELECT * FROM exams WHERE id = ? AND created_by = ?'); $stmt->execute([$_GET['edit_exam'], $user_id]); $edit_exam = $stmt->fetch(); } } elseif ($role === 'student') { $page_title = 'Your Exams'; // Fetch assigned exams for the student view $stmt = $pdo->prepare(' SELECT e.name, se.status, se.score, se.id as student_exam_id FROM student_exams se JOIN exams e ON se.exam_id = e.id WHERE se.student_id = ? ORDER BY e.created_at DESC '); $stmt->execute([$user_id]); $assigned_exams = $stmt->fetchAll(); } else { // Redirect other roles to their dashboard header('Location: ' . $role . '_dashboard.php'); exit(); } ?> <?php echo $page_title; ?>

Exam

Cancel Edit

Your Exams

Exam Name Actions
View Submissions | Edit | Manage Questions | Delete
You have not created any exams yet.

Assigned Exams

Exam Name Status Score Action
Take Exam View Results
You have no assigned exams.