-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdashboard_admin.php
More file actions
140 lines (130 loc) · 4.55 KB
/
dashboard_admin.php
File metadata and controls
140 lines (130 loc) · 4.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<?php
session_start();
// Check if user is logged in
if (!isset($_SESSION['user_id']) || $_SESSION['role_id'] != 1) { // Role ID 1 = Admin
header("Location: login.php");
exit();
}
// Include the database connection
include 'connecting.php';
// Replace with dynamic department ID based on Admin login
$department_id = 1; // Example department ID, replace it dynamically as needed
// Total Students
$students_query = "SELECT COUNT(*) AS total_students FROM students WHERE department_id = ?";
$stmt = $conn->prepare($students_query);
$stmt->bind_param("i", $department_id);
$stmt->execute();
$students_result = $stmt->get_result();
$students = $students_result->fetch_assoc()['total_students'];
// Total Professors
$professors_query = "SELECT COUNT(*) AS total_professors FROM professors WHERE department_id = ?";
$stmt = $conn->prepare($professors_query);
$stmt->bind_param("i", $department_id);
$stmt->execute();
$professors_result = $stmt->get_result();
$professors = $professors_result->fetch_assoc()['total_professors'];
// List of Courses
$courses_query = "SELECT course_name, course_code, credit_hours FROM courses WHERE department_id = ?";
$stmt = $conn->prepare($courses_query);
$stmt->bind_param("i", $department_id);
$stmt->execute();
$courses_result = $stmt->get_result();
// Attendance
$attendance_query = "SELECT s.first_name, s.last_name, a.status, a.attendance_date
FROM attendance a
JOIN students s ON a.student_id = s.student_id
WHERE s.department_id = ?";
$stmt = $conn->prepare($attendance_query);
$stmt->bind_param("i", $department_id);
$stmt->execute();
$attendance_result = $stmt->get_result();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Admin Dashboard</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/css/bootstrap.min.css" rel="stylesheet">
<style>
body {
background-color: #f7f7f7;
}
.container {
margin-top: 30px;
}
.card {
border-radius: 8px;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
}
</style>
</head>
<body>
<div class="container">
<h1 class="text-center mb-4">Admin Dashboard</h1>
<div class="row">
<!-- Total Students -->
<div class="col-md-6">
<div class="card bg-info text-white text-center">
<div class="card-body">
<h4>Total Students</h4>
<h2><?= $students ?></h2>
</div>
</div>
</div>
<!-- Total Professors -->
<div class="col-md-6">
<div class="card bg-success text-white text-center">
<div class="card-body">
<h4>Total Professors</h4>
<h2><?= $professors ?></h2>
</div>
</div>
</div>
</div>
<!-- Courses Section -->
<h2 class="mt-5">Courses</h2>
<table class="table table-striped">
<thead>
<tr>
<th>Course Name</th>
<th>Course Code</th>
<th>Credit Hours</th>
</tr>
</thead>
<tbody>
<?php while ($course = $courses_result->fetch_assoc()): ?>
<tr>
<td><?= $course['course_name'] ?></td>
<td><?= $course['course_code'] ?></td>
<td><?= $course['credit_hours'] ?></td>
</tr>
<?php endwhile; ?>
</tbody>
</table>
<!-- Attendance Section -->
<h2 class="mt-5">Attendance</h2>
<table class="table table-striped">
<thead>
<tr>
<th>Student Name</th>
<th>Status</th>
<th>Date</th>
</tr>
</thead>
<tbody>
<?php while ($attendance = $attendance_result->fetch_assoc()): ?>
<tr>
<td><?= $attendance['first_name'] . ' ' . $attendance['last_name'] ?></td>
<td><?= $attendance['status'] ?></td>
<td><?= $attendance['attendance_date'] ?></td>
</tr>
<?php endwhile; ?>
</tbody>
</table>
</div>
</body>
</html>
<?php
$conn->close();
?>