-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpdashboard.php
More file actions
337 lines (309 loc) · 14.5 KB
/
Copy pathpdashboard.php
File metadata and controls
337 lines (309 loc) · 14.5 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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
<?php
session_start();
require_once 'db_connect.php';
// Check if user is logged in as principal
if (!isset($_SESSION['user_id']) || $_SESSION['role'] !== 'principal') {
header("Location: login.php");
exit();
}
$school_id = $_SESSION['school_id'];
// Get teacher count
$teacherQuery = "SELECT COUNT(*) as teacher_count FROM teacher WHERE school_id = ?";
$stmt = $conn->prepare($teacherQuery);
$stmt->bind_param("i", $school_id);
$stmt->execute();
$teacherResult = $stmt->get_result();
$teacherCount = $teacherResult->fetch_assoc()['teacher_count'];
// Get student count
$studentQuery = "SELECT COUNT(*) as student_count FROM student WHERE school_id = ?";
$stmt = $conn->prepare($studentQuery);
$stmt->bind_param("i", $school_id);
$stmt->execute();
$studentResult = $stmt->get_result();
$studentCount = $studentResult->fetch_assoc()['student_count'];
// Get class count
$classQuery = "SELECT COUNT(*) as class_count FROM class WHERE school_id = ?";
$stmt = $conn->prepare($classQuery);
$stmt->bind_param("i", $school_id);
$stmt->execute();
$classResult = $stmt->get_result();
$classCount = $classResult->fetch_assoc()['class_count'];
// Get subject count
$subjectQuery = "SELECT COUNT(*) as subject_count FROM subject WHERE school_id = ?";
$stmt = $conn->prepare($subjectQuery);
$stmt->bind_param("i", $school_id);
$stmt->execute();
$subjectResult = $stmt->get_result();
$subjectCount = $subjectResult->fetch_assoc()['subject_count'];
$username = $_SESSION['fullname'];
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Principal Dashboard - SRMS</title> <link rel="stylesheet" href="assets/css/iris-design-system.css">
</head>
<body>
<nav class="navbar">
<div class="logo">🎓 SRMS</div>
<ul class="nav-links">
<li><a href="pdashboard.php">Dashboard</a></li>
<li><a href="manage_teacher.php">Teachers</a></li>
<li><a href="manage_students.php">Students</a></li>
<li><a href="manage_classes.php">Classes</a></li>
<li><a href="manage_subjects.php">Subjects</a></li>
<li><a href="manage_exams.php">Exams</a></li>
<li><a href="logout.php">Logout</a></li>
</ul>
</nav>
<div class="container">
<div class="welcome-banner">
<h1>Welcome, <?php echo htmlspecialchars($username); ?>!</h1>
<p>Manage your school in the Student Result Management System.</p>
</div>
<div class="stats-container">
<div class="stat-card">
<div class="stat-value"><?php echo $teacherCount; ?></div>
<div class="stat-label">Teachers</div>
</div>
<div class="stat-card">
<div class="stat-value"><?php echo $studentCount; ?></div>
<div class="stat-label">Students</div>
</div>
<div class="stat-card">
<div class="stat-value"><?php echo $classCount; ?></div>
<div class="stat-label">Classes</div>
</div>
<div class="stat-card">
<div class="stat-value"><?php echo $subjectCount; ?></div>
<div class="stat-label">Subjects</div>
</div>
</div>
<div class="action-buttons">
<button onclick="showAssignmentModal()" class="btn">Assign Teacher to Class & Subject</button>
<button onclick="exportResults('csv')" class="btn btn-secondary">Export Results (CSV)</button>
<button onclick="exportStudents('csv')" class="btn btn-secondary">Export Students (CSV)</button>
<button onclick="window.location.href='student_pass_fail_report.php'" class="btn">Pass/Fail Report</button>
<button onclick="window.location.href='manage_passwords.php'" class="btn">🔐 Manage Passwords</button>
<button onclick="window.location.href='bulk_operations.php'" class="btn">📋 Bulk Operations</button>
<button onclick="window.location.href='change_password.php'" class="btn btn-secondary">🔑 Change Password</button>
</div>
<div class="card">
<h2>Student Performance Overview</h2>
<div class="form-group" style="margin-bottom: 20px;">
<label for="classFilter">Filter by Class:</label>
<select id="classFilter" class="form-control" style="width: 200px; display: inline-block;" onchange="updatePerformanceChart()">
<option value="">All Classes</option>
<?php
$classQuery = "SELECT class_id, class_name, division FROM class WHERE school_id = ? ORDER BY class_name, division";
$stmt = $conn->prepare($classQuery);
$stmt->bind_param("i", $school_id);
$stmt->execute();
$classResult = $stmt->get_result();
while ($class = $classResult->fetch_assoc()) {
echo "<option value='{$class['class_id']}'>{$class['class_name']} {$class['division']}</option>";
}
?>
</select>
</div>
<canvas id="performanceChart" width="400" height="200"></canvas>
</div>
<div class="card">
<h2>Teacher Assignments</h2>
<table class="table">
<thead>
<tr>
<th>Teacher</th>
<th>Class</th>
<th>Subject</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php
$assignmentsQuery = "SELECT tcs.teacher_class_subject_id, u.fullname, c.class_name, c.division, s.subject_name
FROM teacher_class_subject tcs
JOIN teacher t ON tcs.teacher_id = t.teacher_id
JOIN user u ON t.user_id = u.user_id
JOIN class c ON tcs.class_id = c.class_id
JOIN subject s ON tcs.subject_id = s.subject_id
WHERE t.school_id = ?
ORDER BY u.fullname";
$stmt = $conn->prepare($assignmentsQuery);
$stmt->bind_param("i", $school_id);
$stmt->execute();
$assignmentsResult = $stmt->get_result();
while ($assignment = $assignmentsResult->fetch_assoc()):
?>
<tr>
<td><?php echo htmlspecialchars($assignment['fullname']); ?></td>
<td><?php echo htmlspecialchars($assignment['class_name'] . ' ' . $assignment['division']); ?></td>
<td><?php echo htmlspecialchars($assignment['subject_name']); ?></td>
<td>
<button class="btn btn-danger" onclick="deleteAssignment(<?php echo $assignment['teacher_class_subject_id']; ?>)">Remove</button>
</td>
</tr>
<?php endwhile; ?>
</tbody>
</table>
</div>
</div>
<!-- Assignment Modal -->
<div id="assignmentModal" class="modal">
<div class="modal-content">
<span class="close" onclick="closeAssignmentModal()">×</span>
<h2>Assign Teacher to Class & Subject</h2>
<form id="assignmentForm">
<div class="form-group">
<label>Teacher</label>
<select name="teacher_id" class="form-control" required>
<option value="">Select Teacher</option>
<?php
$teacherQuery = "SELECT t.teacher_id, u.fullname FROM teacher t JOIN user u ON t.user_id = u.user_id WHERE t.school_id = ?";
$stmt = $conn->prepare($teacherQuery);
$stmt->bind_param("i", $school_id);
$stmt->execute();
$teacherResult = $stmt->get_result();
while ($teacher = $teacherResult->fetch_assoc()) {
echo "<option value='{$teacher['teacher_id']}'>{$teacher['fullname']}</option>";
}
?>
</select>
</div>
<div class="form-group">
<label>Class</label>
<select name="class_id" class="form-control" required>
<option value="">Select Class</option>
<?php
$classQuery = "SELECT class_id, class_name, division FROM class WHERE school_id = ?";
$stmt = $conn->prepare($classQuery);
$stmt->bind_param("i", $school_id);
$stmt->execute();
$classResult = $stmt->get_result();
while ($class = $classResult->fetch_assoc()) {
echo "<option value='{$class['class_id']}'>{$class['class_name']} {$class['division']}</option>";
}
?>
</select>
</div>
<div class="form-group">
<label>Subject</label>
<select name="subject_id" class="form-control" required>
<option value="">Select Subject</option>
<?php
$subjectQuery = "SELECT subject_id, subject_name FROM subject WHERE school_id = ?";
$stmt = $conn->prepare($subjectQuery);
$stmt->bind_param("i", $school_id);
$stmt->execute();
$subjectResult = $stmt->get_result();
while ($subject = $subjectResult->fetch_assoc()) {
echo "<option value='{$subject['subject_id']}'>{$subject['subject_name']}</option>";
}
?>
</select>
</div>
<button type="submit" class="btn">Create Assignment</button>
</form>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script src="js/app.js"></script>
<script>
let performanceChart;
function updatePerformanceChart() {
const classId = document.getElementById('classFilter').value;
const url = classId ?
`get_performance_data.php?type=subjects&school_id=<?php echo $school_id; ?>&class_id=${classId}` :
`get_performance_data.php?type=subjects&school_id=<?php echo $school_id; ?>`;
fetch(url)
.then(response => response.json())
.then(data => {
if (performanceChart) {
performanceChart.destroy();
}
const ctx = document.getElementById('performanceChart').getContext('2d');
performanceChart = new Chart(ctx, {
type: 'bar',
data: {
labels: data.labels,
datasets: [{
label: 'Average Percentage',
data: data.values,
backgroundColor: ['#2563eb', '#10b981', '#f59e0b', '#ef4444'],
borderWidth: 1
}]
},
options: {
responsive: true,
scales: {
y: {
beginAtZero: true,
max: 100
}
}
}
});
})
.catch(error => console.error('Error loading chart data:', error));
}
// Load initial chart
updatePerformanceChart();
function showAssignmentModal() {
document.getElementById('assignmentModal').style.display = 'block';
}
function closeAssignmentModal() {
document.getElementById('assignmentModal').style.display = 'none';
}
document.getElementById('assignmentForm').addEventListener('submit', function(e) {
e.preventDefault();
const formData = new FormData(this);
formData.append('action', 'create');
fetch('assignment_actions.php', {
method: 'POST',
body: formData
})
.then(response => response.json())
.then(data => {
if (data.success) {
showNotification(data.success, 'success');
closeAssignmentModal();
setTimeout(() => location.reload(), 1500);
} else {
showNotification(data.error, 'error');
}
});
});
function deleteAssignment(id) {
if (confirm('Are you sure you want to remove this assignment? This action cannot be undone.')) {
const formData = new FormData();
formData.append('action', 'delete');
formData.append('assignment_id', id);
fetch('assignment_actions.php', {
method: 'POST',
body: formData
})
.then(response => response.json())
.then(data => {
if (data.success) {
showNotification(data.success, 'success');
setTimeout(() => location.reload(), 1500);
} else {
showNotification(data.error, 'error');
// If error mentions results exist, show additional info
if (data.error.includes('result records exist')) {
showNotification('Tip: You can view and manage results from the Results section', 'info');
}
}
});
}
}
window.onclick = function(event) {
if (event.target.classList.contains('modal')) {
closeAssignmentModal();
}
}
</script>
</div>
</body>
</html>