119 lines
5.3 KiB
PHP
119 lines
5.3 KiB
PHP
<?php include 'header.php'; ?>
|
|
|
|
<div class="container-fluid">
|
|
<?php if (isset($_SESSION['user_id'])): ?>
|
|
<div class="d-flex justify-content-between align-items-center">
|
|
<h1 class="h2">Dashboard</h1>
|
|
<div>
|
|
<span class="me-3">Welcome, <?php echo htmlspecialchars($_SESSION['role']); ?>!</span>
|
|
</div>
|
|
</div>
|
|
|
|
<?php
|
|
if (isset($_SESSION['role']) && $_SESSION['role'] == 'teacher') {
|
|
// Function to get teacher's courses
|
|
function getTeacherCourses($teacher_id) {
|
|
$pdo = db();
|
|
$stmt = $pdo->prepare("SELECT id, name FROM courses WHERE teacher_id = ?");
|
|
$stmt->execute([$teacher_id]);
|
|
return $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
}
|
|
|
|
// Function to get student activities for a course
|
|
function getStudentActivities($course_id) {
|
|
$pdo = db();
|
|
$stmt = $pdo->prepare("
|
|
SELECT u.email, a.activity_name, a.grade, a.activity_date
|
|
FROM activities a
|
|
JOIN enrollments e ON a.enrollment_id = e.id
|
|
JOIN users u ON e.student_id = u.id
|
|
WHERE e.course_id = ?
|
|
ORDER BY a.activity_date DESC
|
|
");
|
|
$stmt->execute([$course_id]);
|
|
return $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
}
|
|
|
|
$courses = getTeacherCourses($_SESSION['user_id']);
|
|
$activities = [];
|
|
foreach ($courses as $course) {
|
|
$activities[$course['name']] = getStudentActivities($course['id']);
|
|
}
|
|
}
|
|
?>
|
|
|
|
<div class="row mt-4">
|
|
<div class="col-md-8">
|
|
<div class="card">
|
|
<div class="card-body">
|
|
<h5 class="card-title">My Classes</h5>
|
|
<ul class="list-group list-group-flush">
|
|
<?php if (!empty($courses)): ?>
|
|
<?php foreach ($courses as $course):
|
|
echo "<li class=\"list-group-item\">" . htmlspecialchars($course['name']) . "</li>";
|
|
endforeach; ?>
|
|
<?php else: ?>
|
|
<li class="list-group-item">No classes found.</li>
|
|
<?php endif; ?>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-4">
|
|
<div class="card">
|
|
<div class="card-body">
|
|
<h5 class="card-title">Upcoming Assignments</h5>
|
|
<p class="card-text">No upcoming assignments.</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="row mt-4">
|
|
<div class="col-md-12">
|
|
<div class="card">
|
|
<div class="card-body">
|
|
<h5 class="card-title">Assignment Submissions</h5>
|
|
<?php if (!empty($activities)): ?>
|
|
<?php foreach ($activities as $courseName => $studentActivities): ?>
|
|
<h6 class="mt-3"><?php echo htmlspecialchars($courseName); ?></h6>
|
|
<?php if (!empty($studentActivities)): ?>
|
|
<table class="table table-striped">
|
|
<thead>
|
|
<tr>
|
|
<th>Student</th>
|
|
<th>Assignment</th>
|
|
<th>Grade</th>
|
|
<th>Date</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($studentActivities as $activity): ?>
|
|
<tr>
|
|
<td><?php echo htmlspecialchars($activity['email']); ?></td>
|
|
<td><?php echo htmlspecialchars($activity['activity_name']); ?></td>
|
|
<td><?php echo $activity['grade']; ?></td>
|
|
<td><?php echo date('M d, Y', strtotime($activity['activity_date'])); ?></td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
<?php else: ?>
|
|
<p>No assignment submissions for this course.</p>
|
|
<?php endif; ?>
|
|
<?php endforeach; ?>
|
|
<?php else: ?>
|
|
<p class="card-text">No assignment submissions.</p>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?php else:
|
|
header('Location: login.php');
|
|
exit;
|
|
?>
|
|
<?php endif; ?>
|
|
</div>
|
|
|
|
<?php include 'footer.php'; ?>
|