-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathteacher.php
More file actions
236 lines (200 loc) · 5.58 KB
/
Copy pathteacher.php
File metadata and controls
236 lines (200 loc) · 5.58 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
<?php
require_once "admin_middleware.php";
require_once "config.php";
/* -------------------------------------------
FETCH ALL TEACHERS + RELATED DATA
-------------------------------------------- */
$stmt = $pdo->query("
SELECT
t.*,
u.full_name,
u.email AS user_email,
u.reg_number,
d.name AS department_name
FROM teachers t
LEFT JOIN users u ON t.user_id = u.id
LEFT JOIN departments d ON t.department_id = d.id
ORDER BY u.full_name ASC
");
$teachers = $stmt->fetchAll(PDO::FETCH_ASSOC);
/* -------------------------------------------
FETCH COURSES & LEVELS PER TEACHER
-------------------------------------------- */
$courseStmt = $pdo->prepare("
SELECT
tc.teacher_id,
l.level_name,
c.title AS course_title
FROM teacher_courses tc
JOIN levels l ON tc.level_id = l.id
JOIN courses c ON tc.course_id = c.id
");
$courseStmt->execute();
$courseRows = $courseStmt->fetchAll(PDO::FETCH_ASSOC);
$teacherMap = [];
foreach ($courseRows as $row) {
$teacherMap[$row['teacher_id']][] =
$row['level_name'] . ' — ' . $row['course_title'];
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Admin • Teachers</title>
<style>
body {
font-family: "Segoe UI", Tahoma, Arial, sans-serif;
background: #f4f6f9;
padding: 30px;
}
/* Card */
.card {
background: #fff;
border-radius: 12px;
padding: 24px;
box-shadow: 0 10px 25px rgba(0,0,0,.08);
max-width: 1700px;
margin: auto;
}
/* Header */
.header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 20px;
}
.header h2 {
margin: 0;
color: #1f2937;
}
/* Search */
.search {
padding: 10px 14px;
border-radius: 8px;
border: 1px solid #d1d5db;
width: 260px;
}
/* Table */
table {
width: 100%;
border-collapse: collapse;
}
thead {
background: #f1f5f9;
}
th {
padding: 12px;
font-size: 0.75rem;
text-transform: uppercase;
text-align: left;
color: #475569;
border-bottom: 1px solid #e5e7eb;
}
td {
padding: 12px;
font-size: 0.85rem;
border-bottom: 1px solid #e5e7eb;
color: #111827;
vertical-align: top;
}
tbody tr:hover {
background: #f9fafb;
}
/* Avatar */
.avatar {
width: 40px;
height: 40px;
border-radius: 50%;
object-fit: cover;
border: 1px solid #e5e7eb;
}
/* Badge */
.badge {
display: inline-block;
padding: 4px 8px;
background: #e0e7ff;
color: #1e40af;
border-radius: 6px;
font-size: 0.75rem;
margin: 2px 0;
}
.close-btn {
background: #2563eb;
color: #fff;
padding: 10px 14px;
border-radius: 6px;
text-decoration: none;
font-weight: 600;
cursor: pointer;
}
</style>
</head>
<body>
<div class="card">
<div class="header">
<span class="close-btn" title="Close" onclick="window.location='student_dashboard.php'">×</span>
<h2>👩🏫 Teachers Management</h2>
<input type="text" id="searchInput" class="search" placeholder="Search teachers...">
</div>
<table id="teacherTable">
<thead>
<tr>
<th>Photo</th>
<th>Full Name</th>
<th>Department</th>
<th>Email</th>
<th>Phone</th>
<th>Date of Birth</th>
<th>Address</th>
<th>Courses & Levels</th>
</tr>
</thead>
<tbody>
<?php if (empty($teachers)): ?>
<tr>
<td colspan="8" style="text-align:center;">No teachers found</td>
</tr>
<?php else: ?>
<?php foreach ($teachers as $t): ?>
<tr>
<td>
<img
src="uploads/profile_pic/<?= htmlspecialchars($t['profile_pic'] ?? 'default.png') ?>"
class="avatar"
>
</td>
<td><?= htmlspecialchars($t['full_name'] ?? '') ?></td>
<td><?= htmlspecialchars($t['department_name'] ?? 'Not Assigned') ?></td>
<td><?= htmlspecialchars($t['user_email'] ?? $t['email'] ?? '') ?></td>
<td><?= htmlspecialchars($t['phone'] ?? '') ?></td>
<td>
<?= $t['dob'] ? date('M d, Y', strtotime($t['dob'])) : 'N/A' ?>
</td>
<td><?= htmlspecialchars($t['address'] ?? '') ?></td>
<td>
<?php if (!empty($teacherMap[$t['user_id']])): ?>
<?php foreach ($teacherMap[$t['user_id']] as $cl): ?>
<div class="badge"><?= htmlspecialchars($cl) ?></div>
<?php endforeach; ?>
<?php else: ?>
<span style="color:#9ca3af;">Not Assigned</span>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
</div>
<script>
/* 🔍 Client-side Search */
document.getElementById('searchInput').addEventListener('keyup', function () {
let value = this.value.toLowerCase();
document.querySelectorAll('#teacherTable tbody tr').forEach(row => {
row.style.display = row.innerText.toLowerCase().includes(value) ? '' : 'none';
});
});
</script>
</body>
</html>