-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdepartments.php
More file actions
488 lines (464 loc) · 17.4 KB
/
Copy pathdepartments.php
File metadata and controls
488 lines (464 loc) · 17.4 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
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
<?php
require_once __DIR__ . '/config.php';
if (!isset($_SESSION['user_id']) || (strcasecmp($_SESSION['role'] ?? '', 'Admin') !== 0)) {
// ================== FUNCTION TO GET FACULTIES ===================
function getFaculties() {
return [
"FACULTY OF AGRICULTURE" => [
"Agricultural Science",
"Agricultural Economics & Extension",
"Animal Science and Fisheries",
"Crop Science and Soil Science"
],
"FACULTY OF VOCATIONAL AND TECHNICAL EDUCATION" => [
"Agricultural Education",
"Technical Education",
"Building Technology",
"Electrical/ Electronics",
"Mechanical Technology",
"Automobile Technology",
"Home Economics, Hospitality & Tourism"
],
"FACULTY OF SOCIAL SCIENCES" => [
"Political Science",
"Economics",
"Sociology",
"Social Works",
"Geography and Environmental Studies",
"Petroleum Economics and Policy Studies",
"Public Administration",
"Library and Information Science"
],
"FACULTY OF EDUCATION" => [
"Educational Management",
"Library and Information Science",
"Primary Education Studies",
"Early Childhood Education",
"Special Education",
"Guidance and Counselling",
"Adult Education and Community Development",
"Educational Technology",
"Education and Political Science",
"Education and Economics",
"Education and Social Studies",
"Education and Geography",
"Education and French",
"Education and Religious Studies",
"Education Fine & Applied Arts",
"Education and History",
"Education and Music",
"Education and English",
"Accounting Education",
"Secretarial Education",
"Marketing Education",
"Management Education",
"Education and Biology",
"Computer Education",
"Education and Mathematics",
"Health and Safety Education",
"Education and Physics",
"Education and Chemistry",
"Education and Integrated Science",
"Human Kinetics and Sports Science"
],
"FACULTY OF HUMANITIES" => [
"French Languages and International and Studies",
"Religious Studies",
"Theatre Arts, Film & Theater Studies",
"Fine & Applied Arts",
"History and Diplomatic Studies",
"Music",
"English and Communication Arts",
"Linguistics",
"Philosophy",
"Mass Communication",
"Peace and Conflict Studies"
],
"FACULTY OF ADMINISTRATION AND MANAGEMENT SCIENCES" => [
"Accounting",
"Office and Information Management",
"Marketing",
"Management",
"Employment & Human Resources Management",
"Entrepreneurship",
"Banking and Finance",
"Hospitality and Tourism Management"
],
"FACULTY OF NATURAL & APPLIED SCIENCES" => [
"Biology",
"Computer Science",
"Mathematics",
"Human Kinetics",
"Physics",
"Chemistry",
"Geophysics",
"Industrial Chemistry",
"Statistics",
"Software Engineering"
]
];
}
header('Location: login.php');
exit;
}
// Handle department addition
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['add_department'])) {
$department_name = $conn->real_escape_string($_POST['department_name']);
$faculty = $conn->real_escape_string($_POST['faculty']);
$sql = "INSERT INTO departments (department_name, faculty_name) VALUES ('$department_name', '$faculty')";
if ($conn->query($sql) === TRUE) {
$success_message = "Department added successfully!";
} else {
$error_message = "Error: " . $conn->error;
// Create departments table if it doesn't exist
if (strpos($conn->error, "doesn't exist") !== false) {
$create_table = "CREATE TABLE departments (
id INT(11) AUTO_INCREMENT PRIMARY KEY,
department_name VARCHAR(255) NOT NULL,
faculty_name VARCHAR(255) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)";
if ($conn->query($create_table) === TRUE) {
// Try inserting again
if ($conn->query($sql) === TRUE) {
$success_message = "Department added successfully!";
}
}
}
}
}
// Create departments table if it doesn't exist
$check_table = $conn->query("SHOW TABLES LIKE 'departments'");
if ($check_table->num_rows == 0) {
$create_table = "CREATE TABLE departments (
id INT(11) AUTO_INCREMENT PRIMARY KEY,
department_name VARCHAR(255) NOT NULL,
faculty VARCHAR(255) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)";
$conn->query($create_table);
}
// Fetch all departments
$departments = [];
$query = "SELECT * FROM departments ORDER BY department_name";
$result = $conn->query($query);
if ($result) {
while ($row = $result->fetch_assoc()) {
$departments[] = $row;
}
}
// Get unique faculties for filter and dropdown
$faculties = [];
// Check if signup.php exists to get faculty list
if (file_exists('signup.php')) {
include_once 'config.php';
// Get faculties from a predefined list or from signup.php
$faculties = ['Science', 'Arts', 'Engineering', 'Business', 'Education', 'Medicine'];
} else {
// Fallback to department names if faculty column doesn't exist
$faculty_query = "SELECT DISTINCT department_name FROM departments ORDER BY department_name";
$faculty_result = $conn->query($faculty_query);
if ($faculty_result) {
while ($row = $faculty_result->fetch_assoc()) {
if (!empty($row['department_name'])) {
$faculties[] = $row['department_name'];
}
}
}
}
// If no faculties exist yet, add some default ones
if (empty($faculties)) {
$faculties = ['Science', 'Arts', 'Engineering', 'Education', 'Business', 'Health Sciences'];
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Manage Departments - Admin Dashboard</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
:root {
--primary: #0b5ed7;
--secondary: #6c757d;
--success: #198754;
--danger: #dc3545;
--warning: #ffc107;
--info: #0dcaf0;
--light: #f8f9fa;
--dark: #212529;
--bg-light: #ffffff;
--text-light: #212529;
--bg-dark: #1e1e2d;
--text-dark: #e4e6ef;
}
[data-theme="dark"] {
--bg-color: var(--bg-dark);
--text-color: var(--text-dark);
--border-color: #2b2b40;
--card-bg: #2b2b40;
}
[data-theme="light"] {
--bg-color: var(--bg-light);
--text-color: var(--text-light);
--border-color: #e4e6ef;
--card-bg: #ffffff;
}
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
margin: 0;
padding: 0;
background-color: var(--bg-color);
color: var(--text-color);
transition: all 0.3s ease;
}
.container {
max-width: 1200px;
margin: 0 auto;
padding: 20px;
}
header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 15px 20px;
background-color: var(--card-bg);
border-bottom: 1px solid var(--border-color);
}
.header-title {
font-size: 1.5rem;
font-weight: 600;
}
.theme-toggle {
background: none;
border: none;
color: var(--text-color);
cursor: pointer;
font-size: 1.2rem;
}
.card {
background-color: var(--card-bg);
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
margin-bottom: 20px;
padding: 20px;
border: 1px solid var(--border-color);
}
.card-title {
font-size: 1.2rem;
font-weight: 600;
margin-bottom: 15px;
padding-bottom: 10px;
border-bottom: 1px solid var(--border-color);
}
.form-group {
margin-bottom: 15px;
}
label {
display: block;
margin-bottom: 5px;
font-weight: 500;
}
input[type="text"], select {
width: 100%;
padding: 8px 12px;
border: 1px solid var(--border-color);
border-radius: 4px;
background-color: var(--bg-color);
color: var(--text-color);
}
.btn {
padding: 8px 16px;
border-radius: 4px;
border: none;
cursor: pointer;
font-weight: 500;
transition: all 0.2s;
}
.btn-primary {
background-color: var(--primary);
color: white;
}
.btn-primary:hover {
background-color: #0a4bb8;
}
.alert {
padding: 10px 15px;
border-radius: 4px;
margin-bottom: 15px;
}
.alert-success {
background-color: #d1e7dd;
color: #0f5132;
border: 1px solid #badbcc;
}
.alert-danger {
background-color: #f8d7da;
color: #842029;
border: 1px solid #f5c2c7;
}
table {
width: 100%;
border-collapse: collapse;
}
th, td {
padding: 12px 15px;
text-align: left;
border-bottom: 1px solid var(--border-color);
}
th {
background-color: var(--card-bg);
font-weight: 600;
}
.filter-section {
display: flex;
gap: 15px;
margin-bottom: 20px;
align-items: center;
}
.filter-section select {
width: auto;
}
.back-link {
display: inline-block;
margin-bottom: 20px;
color: var(--primary);
text-decoration: none;
}
.back-link:hover {
text-decoration: underline;
}
</style>
</head>
<body data-theme="light">
<header>
<div class="header-title">Manage Departments</div>
<button class="theme-toggle" id="themeToggle">
<i class="fas fa-moon"></i>
</button>
</header>
<div class="container">
<a href="admin_dashboard.php" class="back-link"><i class="fas fa-arrow-left"></i> Back to Dashboard</a>
<?php if (isset($success_message)): ?>
<div class="alert alert-success"><?php echo $success_message; ?></div>
<?php endif; ?>
<?php if (isset($error_message)): ?>
<div class="alert alert-danger"><?php echo $error_message; ?></div>
<?php endif; ?>
<div class="card">
<div class="card-title">Add New Department</div>
<form method="POST" action="">
<div class="form-group">
<label for="faculty">Faculty</label>
<select id="faculty" name="faculty" required>
<option value="">Select Faculty</option>
<?php foreach ($faculties as $faculty): ?>
<option value="<?php echo htmlspecialchars($faculty); ?>"><?php echo htmlspecialchars($faculty); ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="form-group">
<label for="department_name">Department Name</label>
<input type="text" id="department_name" name="department_name" required>
</div>
<button type="submit" name="add_department" class="btn btn-primary">Add Department</button>
</form>
</div>
<div class="card">
<div class="card-title">Departments List</div>
<div class="filter-section">
<label for="faculty-filter">Filter by Faculty:</label>
<select id="faculty-filter">
<option value="">All Faculties</option>
<?php foreach ($faculties as $faculty): ?>
<option value="<?php echo htmlspecialchars($faculty); ?>"><?php echo htmlspecialchars($faculty); ?></option>
<?php endforeach; ?>
</select>
</div>
<table id="departments-table">
<thead>
<tr>
<th>ID</th>
<th>Department Name</th>
<th>Faculty</th>
<th>Date Added</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php if (empty($departments)): ?>
<tr>
<td colspan="5" style="text-align: center;">No departments found. Add your first department above.</td>
</tr>
<?php else: ?>
<?php foreach ($departments as $dept): ?>
<tr data-faculty="<?php echo htmlspecialchars($dept['faculty'] ?? ''); ?>">
<td><?php echo htmlspecialchars($dept['id']); ?></td>
<td><?php echo htmlspecialchars($dept['department_name']); ?></td>
<td><?php echo htmlspecialchars($dept['faculty'] ?? 'Not Assigned'); ?></td>
<td><?php echo isset($dept['created_at']) ? date('Y-m-d', strtotime($dept['created_at'])) : date('Y-m-d'); ?></td>
<td>
<a href="?edit=<?php echo $dept['id']; ?>" class="btn btn-sm btn-primary">Edit</a>
<a href="?delete=<?php echo $dept['id']; ?>" class="btn btn-sm btn-danger" onclick="return confirm('Are you sure you want to delete this department?')">Delete</a>
</td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
<script>
// Theme toggle functionality
const themeToggle = document.getElementById('themeToggle');
const body = document.body;
const icon = themeToggle.querySelector('i');
// Check for saved theme preference or use default
const savedTheme = localStorage.getItem('theme') || 'light';
body.setAttribute('data-theme', savedTheme);
updateThemeIcon(savedTheme);
themeToggle.addEventListener('click', () => {
const currentTheme = body.getAttribute('data-theme');
const newTheme = currentTheme === 'light' ? 'dark' : 'light';
body.setAttribute('data-theme', newTheme);
localStorage.setItem('theme', newTheme);
updateThemeIcon(newTheme);
});
function updateThemeIcon(theme) {
if (theme === 'dark') {
icon.classList.remove('fa-moon');
icon.classList.add('fa-sun');
} else {
icon.classList.remove('fa-sun');
icon.classList.add('fa-moon');
}
}
// Faculty filter functionality for table
const facultyFilter = document.getElementById('faculty-filter');
facultyFilter.addEventListener('change', function() {
const selectedFaculty = this.value;
const rows = document.querySelectorAll('#departments-table tbody tr');
rows.forEach(row => {
const rowFaculty = row.getAttribute('data-faculty');
if (!selectedFaculty || rowFaculty === selectedFaculty) {
row.style.display = '';
} else {
row.style.display = 'none';
}
});
});
// Faculty dropdown in form
document.getElementById('faculty').addEventListener('change', function() {
// In a real implementation, this would fetch departments for the selected faculty
// For now, we'll just show a message that the department dropdown would be filtered
const departmentField = document.getElementById('department_name');
if (this.value) {
departmentField.placeholder = `Enter department name for ${this.value} faculty`;
} else {
departmentField.placeholder = '';
}
});
</script>
</body>
</html>