-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmanage_staff.php
More file actions
1188 lines (1094 loc) · 57.9 KB
/
Copy pathmanage_staff.php
File metadata and controls
1188 lines (1094 loc) · 57.9 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
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
require_once __DIR__ . '/config.php';
// ================== FUNCTION TO SEND USER CREDENTIALS ===================
function sendStaffCredentials($email, $fullname, $staff_id, $password, $phone = '') {
// Email notification
$subject = "Welcome to IAUE Complaints System - Your Staff Account Credentials";
$message = "
<html>
<head>
<title>Staff Account Credentials</title>
</head>
<body>
<h2>Welcome to Ignatius Ajuru University Complaints and Response System Staff Portal!</h2>
<p>Dear " . htmlspecialchars($fullname) . ",</p>
<p>Your staff account has been successfully created. Below are your login credentials:</p>
<div style='background-color: #f8f9fa; padding: 15px; border-radius: 5px; margin: 15px 0;'>
<h3>Login Credentials:</h3>
<p><strong>Staff ID:</strong> " . htmlspecialchars($staff_id) . "</p>
<p><strong>Password:</strong> " . htmlspecialchars($password) . "</p>
</div>
<p><strong>Login URL:</strong> <a href='http://localhost/complaint-system/user_staff.php'>http://localhost/complaint-system/user_staff.php</a></p>
<p><strong>Important Security Notes:</strong></p>
<ul>
<li>Please change your password after your first login</li>
<li>Keep your credentials secure and do not share them</li>
<li>Contact the admin if you have any issues accessing your account</li>
</ul>
<p>Best regards,<br>IAUE Complaints System Administration</p>
</body>
</html>
";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= "From: noreply@iauecomplaints.com" . "\r\n";
// Send email (with error suppression to avoid warnings)
$mail_sent = @mail($email, $subject, $message, $headers);
if ($mail_sent) {
error_log("Staff credentials email sent successfully to: " . $email);
} else {
error_log("Failed to send staff credentials email to: " . $email . " - Mail server not configured");
// For development, we'll just log the credentials instead
error_log("STAFF CREDENTIALS FOR " . $fullname . " - Staff ID: " . $staff_id . ", Password: " . $password);
}
}
// SMS notification (if phone number provided)
if (!empty($phone)) {
$sms_message = "Welcome to Ignatius Ajuru University Complaints and Response System! Your staff account is ready. Staff ID: " . $staff_id . ". Login at: http://localhost/complaint-system/user_staff.php";
// Note: For actual SMS sending, you would integrate with an SMS service like Twilio, Nexmo, etc.
// For now, we'll just log it
error_log("SMS notification for staff: " . $phone . " - " . $sms_message);
// Uncomment and configure when you have an SMS service:
// sendSmsNotification($phone, $sms_message);
}
// ================== 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"
]
];
}
if (!isset($_SESSION['user_id']) || ($_SESSION['role'] ?? '') !== 'Admin') {
header('Location: login.php');
exit;
}
// Ensure staff_id column exists with proper error handling
try {
if (!$conn->query("SHOW COLUMNS FROM users LIKE 'staff_id'")->num_rows) {
$alterQuery = "ALTER TABLE users ADD COLUMN staff_id VARCHAR(50) NULL UNIQUE";
if (!$conn->query($alterQuery)) {
throw new Exception("Failed to create staff_id column: " . $conn->error);
}
}
} catch (Exception $e) {
die("Database Error: " . $e->getMessage());
}
// Handle form submissions
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$action = $_POST['action'] ?? '';
if ($action === 'create_admin') {
$fullname = trim($_POST['fullname'] ?? '');
$email = trim($_POST['email'] ?? '');
$faculty = trim($_POST['faculty'] ?? '');
$department = trim($_POST['department'] ?? '');
$phone = trim($_POST['phone'] ?? '');
if (empty($fullname) || empty($email) || empty($faculty) || empty($department)) {
$error = 'All fields are required to create an admin account.';
} else {
// auto-generate office_id and password
$office_id = 'ADM' . strtoupper(substr(md5(uniqid((string)mt_rand(), true)), 0, 6));
$password_plain = bin2hex(random_bytes(5)); // 10 hex chars
$hashedPassword = password_hash($password_plain, PASSWORD_DEFAULT);
// Ensure office_id unique
$checkStmt = $conn->prepare("SELECT id FROM users WHERE email = ? OR office_id = ? LIMIT 1");
if ($checkStmt) {
$checkStmt->bind_param('ss', $email, $office_id);
$checkStmt->execute();
$checkStmt->store_result();
if ($checkStmt->num_rows > 0) {
$error = "An account with this email or office ID already exists.";
$checkStmt->close();
} else {
$checkStmt->close();
$stmtA = $conn->prepare("INSERT INTO users (fullname, email, office_id, password, role, faculty, department, phone) VALUES (?, ?, ?, ?, 'Admin', ?, ?, ?)");
if ($stmtA) {
$stmtA->bind_param('sssssss', $fullname, $email, $office_id, $hashedPassword, $faculty, $department, $phone);
if ($stmtA->execute()) {
$success = "Admin account created successfully. Office ID and password have been sent to the user.";
// Send credentials via notifyUser (email + SMS)
require_once __DIR__ . '/notify.php';
$newAdminId = $stmtA->insert_id;
$subject = 'Admin Account Created - IAUE Complaint System';
$message = "Dear {$fullname},\n\nAn admin account has been created for you.\n\nOffice ID: {$office_id}\nPassword: {$password_plain}\n\nPlease log in at: http://{$_SERVER['HTTP_HOST']}/complaint-system/user_admin.php and change your password immediately.";
notifyUser((int)$newAdminId, $subject, $message, ['in_app' => true, 'email' => true, 'sms' => true]);
} else {
$error = "Error creating admin account: " . $stmtA->error;
}
$stmtA->close();
} else {
$error = "Database error preparing admin insert: " . $conn->error;
}
}
} else {
$error = "Database error while checking admin uniqueness: " . $conn->error;
}
}
} else if ($action === 'create_staff') {
$fullname = trim($_POST['fullname'] ?? '');
$email = trim($_POST['email'] ?? '');
$staff_id = trim($_POST['staff_id'] ?? '');
$password = $_POST['password'] ?? '';
$faculty = trim($_POST['faculty'] ?? '');
$department = trim($_POST['department'] ?? '');
$phone = trim($_POST['phone'] ?? '');
if ($fullname && $email && $staff_id && $password && $faculty && $department) {
// Check if email already exists
$checkStmt = $conn->prepare("SELECT id FROM users WHERE email = ? OR staff_id = ? LIMIT 1");
if (!$checkStmt) {
error_log("Error preparing check statement: " . $conn->error);
$error = "Database error occurred while checking for existing staff.";
} else {
$checkStmt->bind_param('ss', $email, $staff_id);
if (!$checkStmt->execute()) {
error_log("Error executing check statement: " . $checkStmt->error);
$error = "Database error occurred while checking for existing staff.";
} else {
$checkStmt->store_result();
if ($checkStmt->num_rows > 0) {
$error = "A staff member with this email or staff ID already exists.";
$checkStmt->close();
} else {
$checkStmt->close();
$hashedPassword = password_hash($password, PASSWORD_DEFAULT);
$role = trim($_POST['role'] ?? 'Staff');
// Ensure role is valid
if (!in_array($role, ['Staff', 'Department Head', 'Faculty Head'])) {
$role = 'Staff';
}
$stmt = $conn->prepare("INSERT INTO users (fullname, email, staff_id, password, role, faculty, department, phone) VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
if (!$stmt) {
error_log("Error preparing insert statement: " . $conn->error);
$error = "Database error occurred while creating staff member.";
} else {
$stmt->bind_param('ssssssss', $fullname, $email, $staff_id, $hashedPassword, $role, $faculty, $department, $phone);
if (!$stmt->execute()) {
error_log("Error executing insert statement: " . $stmt->error);
$error = "Error creating staff member: " . $stmt->error;
} else {
error_log("Successfully created staff member with ID: " . $conn->insert_id);
$success = "Staff member created successfully!<br><strong>Login Credentials:</strong><br>Staff ID: " . htmlspecialchars($staff_id) . "<br>Password: " . htmlspecialchars($password);
// Send login credentials via email and SMS
sendStaffCredentials($email, $fullname, $staff_id, $password, $phone ?? '');
// Immediately refresh the staff list after successful creation
$refresh_query = "SELECT id, fullname, email, staff_id, role, faculty, department, phone, created_at
FROM users
WHERE (role = 'Staff' OR role = 'Department Head' OR role = 'Faculty Head' OR staff_id IS NOT NULL)
ORDER BY fullname";
$refresh_result = $conn->query($refresh_query);
if ($refresh_result) {
$staff_members = $refresh_result->fetch_all(MYSQLI_ASSOC);
error_log("Refreshed staff list, found " . count($staff_members) . " members");
}
}
$stmt->close();
}
}
}
}
} else {
$error = "All fields are required.";
}
}
if ($action === 'update_staff') {
$id = (int)($_POST['id'] ?? 0);
$fullname = trim($_POST['fullname'] ?? '');
$email = trim($_POST['email'] ?? '');
$faculty = trim($_POST['faculty'] ?? '');
$department = trim($_POST['department'] ?? '');
if ($id && $fullname && $email && $faculty && $department) {
$stmt = $conn->prepare("UPDATE users SET fullname = ?, email = ?, faculty = ?, department = ? WHERE id = ? AND role = 'Staff'");
$stmt->bind_param('ssssi', $fullname, $email, $faculty, $department, $id);
if ($stmt->execute()) {
$success = "Staff member updated successfully!";
} else {
$error = "Error updating staff member: " . $conn->error;
}
$stmt->close();
}
}
if ($action === 'delete_staff') {
$id = (int)($_POST['id'] ?? 0);
if ($id) {
$stmt = $conn->prepare("DELETE FROM users WHERE id = ? AND role = 'Staff'");
$stmt->bind_param('i', $id);
if ($stmt->execute()) {
$success = "Staff member deleted successfully!";
} else {
$error = "Error deleting staff member: " . $conn->error;
}
$stmt->close();
}
}
if ($action === 'update_admin') {
$id = (int)($_POST['id'] ?? 0);
$fullname = trim($_POST['fullname'] ?? '');
$email = trim($_POST['email'] ?? '');
$faculty = trim($_POST['faculty'] ?? '');
$department = trim($_POST['department'] ?? '');
if ($id && $fullname && $email && $faculty && $department) {
// Check if the email is unique (except for the current admin)
$check_stmt = $conn->prepare("SELECT id FROM users WHERE email = ? AND id != ? LIMIT 1");
$check_stmt->bind_param('si', $email, $id);
$check_stmt->execute();
$check_stmt->store_result();
if ($check_stmt->num_rows > 0) {
$error = "An account with this email already exists.";
} else {
$stmt = $conn->prepare("UPDATE users SET fullname = ?, email = ?, faculty = ?, department = ? WHERE id = ? AND role = 'Admin'");
$stmt->bind_param('ssssi', $fullname, $email, $faculty, $department, $id);
if ($stmt->execute()) {
$success = "Administrator updated successfully!";
} else {
$error = "Error updating administrator: " . $conn->error;
}
$stmt->close();
}
$check_stmt->close();
} else {
$error = "All fields are required to update the administrator.";
}
}
if ($action === 'delete_admin') {
$id = (int)($_POST['id'] ?? 0);
if ($id) {
// Check if this is not the last admin
$check_stmt = $conn->prepare("SELECT COUNT(*) as admin_count FROM users WHERE role = 'Admin'");
$check_stmt->execute();
$result = $check_stmt->get_result();
$admin_count = $result->fetch_assoc()['admin_count'];
if ($admin_count <= 1) {
$error = "Cannot delete the last administrator account. System requires at least one admin.";
} else {
$stmt = $conn->prepare("DELETE FROM users WHERE id = ? AND role = 'Admin'");
$stmt->bind_param('i', $id);
if ($stmt->execute()) {
$success = "Administrator deleted successfully!";
} else {
$error = "Error deleting administrator: " . $conn->error;
}
$stmt->close();
}
$check_stmt->close();
}
}
}
// Initialize arrays for both staff and admin members
$staff_members = [];
$admin_members = [];
$error_occurred = false;
try {
// First, verify the database connection
if (!$conn || $conn->connect_error) {
throw new Exception("Database connection error: " . ($conn ? $conn->connect_error : "No connection"));
}
// Prepare the statement - use more flexible role matching
$query = "SELECT id, fullname, email, staff_id, role, faculty, department, phone, created_at
FROM users
WHERE (role = 'Staff' OR role = 'Department Head' OR role = 'Faculty Head' OR staff_id IS NOT NULL)
ORDER BY fullname";
$stmt = $conn->prepare($query);
if (!$stmt) {
throw new Exception("Failed to prepare statement: " . $conn->error);
}
// Execute the query
if (!$stmt->execute()) {
throw new Exception("Failed to execute query: " . $stmt->error);
}
// Get the result
$result = $stmt->get_result();
if (!$result) {
throw new Exception("Failed to get result set: " . $stmt->error);
}
// Fetch all staff members
$staff_members = $result->fetch_all(MYSQLI_ASSOC);
// Log the number of staff members found
error_log("Retrieved " . count($staff_members) . " staff members from database");
// Close the staff statement
$stmt->close();
// Now get all admin users
$admin_query = "SELECT id, fullname, email, office_id, role, faculty, department, phone, created_at
FROM users
WHERE role = 'Admin'
ORDER BY fullname";
$admin_stmt = $conn->prepare($admin_query);
if (!$admin_stmt) {
throw new Exception("Failed to prepare admin statement: " . $conn->error);
}
// Execute the admin query
if (!$admin_stmt->execute()) {
throw new Exception("Failed to execute admin query: " . $admin_stmt->error);
}
// Get the admin results
$admin_result = $admin_stmt->get_result();
if (!$admin_result) {
throw new Exception("Failed to get admin result set: " . $admin_stmt->error);
}
// Fetch all admin members
$admin_members = $admin_result->fetch_all(MYSQLI_ASSOC);
// Log the number of admin users found
error_log("Retrieved " . count($admin_members) . " admin users from database");
// Close the admin statement
$admin_stmt->close();
// Debug: Display all users to check role values
$debug_query = "SELECT id, fullname, email, staff_id, role FROM users";
$debug_result = $conn->query($debug_query);
if ($debug_result) {
$all_users = $debug_result->fetch_all(MYSQLI_ASSOC);
error_log("All users in database: " . print_r($all_users, true));
}
// Additional debug: Check if any users have staff_id but wrong role
$debug_staff_query = "SELECT id, fullname, email, staff_id, role FROM users WHERE staff_id IS NOT NULL";
$debug_staff_result = $conn->query($debug_staff_query);
if ($debug_staff_result) {
$staff_users = $debug_staff_result->fetch_all(MYSQLI_ASSOC);
error_log("Users with staff_id: " . print_r($staff_users, true));
}
} catch (Exception $e) {
error_log("Error retrieving staff members: " . $e->getMessage());
$error = "Failed to retrieve staff members. Please check the error log for details.";
$error_occurred = true;
}
// If no error occurred but we still have no staff members, log this information
if (!$error_occurred && empty($staff_members)) {
error_log("No staff members found in the database");
}
// Get departments for dropdown
$dept_query = $conn->query("SELECT DISTINCT department_name FROM departments ORDER BY department_name");
if (!$dept_query) {
error_log("Error retrieving departments: " . $conn->error);
$departments = [];
} else {
$departments = $dept_query->fetch_all(MYSQLI_ASSOC);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Manage Staff - Admin Dashboard</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.0/css/all.min.css">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<style>
body {
background: #f8f9fa;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
.navbar {
background: #0f2647 !important;
}
.navbar-brand {
color: #eaf2ff !important;
font-weight: 600;
}
.navbar-nav .nav-link {
color: #cde1ff !important;
}
.navbar-nav .nav-link:hover {
color: #fff !important;
}
.card {
border: none;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
border-radius: 12px;
}
.card-header {
background: #0b5ed7;
color: white;
border-radius: 12px 12px 0 0 !important;
font-weight: 600;
}
.btn-primary {
background: #0b5ed7;
border-color: #0b5ed7;
}
.btn-primary:hover {
background: #0a58ca;
border-color: #0a58ca;
}
.table th {
font-weight: 600;
color: #495057;
}
.table-primary {
background-color: #0b5ed7 !important;
color: white;
}
.table-primary th {
color: white;
border-color: #0a58ca;
}
.table-striped > tbody > tr:nth-of-type(odd) > * {
background-color: rgba(11, 94, 215, 0.05);
}
.badge-department {
background-color: #e9ecef;
color: #495057;
font-weight: 500;
padding: 5px 10px;
border-radius: 30px;
}
.staff-actions .btn {
padding: 0.25rem 0.5rem;
font-size: 0.875rem;
}
.alert {
border-radius: 10px;
}
.form-control, .form-select {
border-radius: 8px;
}
.modal-header {
background: #0b5ed7;
color: white;
}
.modal-title {
font-weight: 600;
}
.btn-close {
filter: invert(1);
}
/* Pointer cursor styles */
button, .btn, select, .form-select, .form-control, a, .nav-link, .navbar-brand {
cursor: pointer;
}
</style>
</head>
<body>
<!-- Navigation -->
<nav class="navbar navbar-expand-lg navbar-dark">
<div class="container-fluid">
<a class="navbar-brand" href="admin_dashboard.php">
<i class="fas fa-shield-alt me-2"></i>Admin Dashboard
</a>
<div class="navbar-nav ms-auto">
<a class="nav-link" href="admin_dashboard.php">
<i class="fas fa-arrow-left me-1"></i>Back to Dashboard
</a>
<a class="nav-link" href="logout.php">
<i class="fas fa-sign-out-alt me-1"></i>Logout
</a>
</div>
</div>
</nav>
<div class="container-fluid mt-4">
<?php if (isset($success)): ?>
<div class="alert alert-success alert-dismissible fade show" role="alert">
<i class="fas fa-check-circle me-2"></i><?php echo htmlspecialchars($success); ?>
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
</div>
<?php endif; ?>
<?php if (isset($error)): ?>
<div class="alert alert-danger alert-dismissible fade show" role="alert">
<i class="fas fa-exclamation-circle me-2"></i><?php echo htmlspecialchars($error); ?>
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
</div>
<?php endif; ?>
<div class="row">
<div class="col-12">
<!-- Admin Users Card -->
<div class="card mb-4">
<div class="card-header d-flex justify-content-between align-items-center bg-primary text-white">
<h5 class="mb-0"><i class="fas fa-user-shield me-2"></i>System Administrators</h5>
<div class="d-flex align-items-center">
<button class="btn btn-light" data-bs-toggle="modal" data-bs-target="#createAdminModal">
<i class="fas fa-plus me-2"></i>Create Admin
</button>
</div>
</div>
<div class="card-body">
<div class="table-responsive">
<table class="table table-hover">
<thead class="table-light">
<tr>
<th>Admin ID</th>
<th>Full Name</th>
<th>Email</th>
<th>Phone</th>
<th>Faculty</th>
<th>Department</th>
<th>Created</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php if (empty($admin_members)): ?>
<tr>
<td colspan="8" class="text-center text-muted py-4">
<i class="fas fa-user-shield fa-2x mb-2"></i><br>
No administrators found. Create your first admin account.
</td>
</tr>
<?php else: ?>
<?php foreach ($admin_members as $admin): ?>
<tr>
<td><strong><?php echo htmlspecialchars($admin['office_id']); ?></strong></td>
<td><?php echo htmlspecialchars($admin['fullname']); ?></td>
<td><?php echo htmlspecialchars($admin['email']); ?></td>
<td><?php echo htmlspecialchars($admin['phone'] ?? 'N/A'); ?></td>
<td><?php echo htmlspecialchars($admin['faculty']); ?></td>
<td><?php echo htmlspecialchars($admin['department']); ?></td>
<td><?php echo date('M j, Y', strtotime($admin['created_at'])); ?></td>
<td>
<button class="btn btn-sm btn-outline-primary me-1"
onclick="editAdmin(<?php echo htmlspecialchars(json_encode($admin)); ?>)">
<i class="fas fa-edit"></i>
</button>
<button class="btn btn-sm btn-outline-danger"
onclick="deleteAdmin(<?php echo $admin['id']; ?>, '<?php echo htmlspecialchars($admin['fullname']); ?>')">
<i class="fas fa-trash"></i>
</button>
</td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
</div>
<!-- Department Staff Card -->
<div class="card">
<div class="card-header d-flex justify-content-between align-items-center">
<h5 class="mb-0"><i class="fas fa-users-cog me-2"></i>Department Staff</h5>
<div class="d-flex align-items-center">
<button class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#createStaffModal">
<i class="fas fa-plus me-2"></i>Add New Staff
</button>
</div>
</div>
<div class="card-body">
<div class="table-responsive">
<table class="table table-hover">
<thead>
<tr>
<th>Staff ID</th>
<th>Full Name</th>
<th>Email</th>
<th>Phone</th>
<th>Role</th>
<th>Faculty</th>
<th>Department</th>
<th>Created</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php if (empty($staff_members)): ?>
<tr>
<td colspan="7" class="text-center text-muted py-4">
<i class="fas fa-users fa-2x mb-2"></i><br>
No staff members found. Create your first staff account.
</td>
</tr>
<?php else: ?>
<?php foreach ($staff_members as $staff): ?>
<tr>
<td><strong><?php echo htmlspecialchars($staff['staff_id']); ?></strong></td>
<td><?php echo htmlspecialchars($staff['fullname']); ?></td>
<td><?php echo htmlspecialchars($staff['email']); ?></td>
<td><?php echo htmlspecialchars($staff['phone'] ?? 'N/A'); ?></td>
<td><?php echo htmlspecialchars($staff['role']); ?></td>
<td><?php echo htmlspecialchars($staff['faculty']); ?></td>
<td><?php echo htmlspecialchars($staff['department']); ?></td>
<td><?php echo date('M j, Y', strtotime($staff['created_at'])); ?></td>
<td>
<button class="btn btn-sm btn-outline-primary me-1"
onclick="editStaff(<?php echo htmlspecialchars(json_encode($staff)); ?>)">
<i class="fas fa-edit"></i>
</button>
<button class="btn btn-sm btn-outline-danger"
onclick="deleteStaff(<?php echo $staff['id']; ?>, '<?php echo htmlspecialchars($staff['fullname']); ?>')">
<i class="fas fa-trash"></i>
</button>
</td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Create Admin Modal (backend-only admin creation) -->
<div class="modal fade" id="createAdminModal" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title"><i class="fas fa-user-shield me-2"></i>Create New Admin Account</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<form method="POST">
<div class="modal-body">
<input type="hidden" name="action" value="create_admin">
<div class="row">
<div class="col-md-6 mb-3">
<label class="form-label">Full Name</label>
<input type="text" class="form-control" name="fullname" required>
</div>
<div class="col-md-6 mb-3">
<label class="form-label">Email</label>
<input type="email" class="form-control" name="email" required>
</div>
</div>
<div class="row">
<div class="col-md-6 mb-3">
<label class="form-label">Faculty</label>
<select class="form-select" name="faculty" id="adminFaculty" onchange="updateAdminDepartments()" required>
<option value="">Select Faculty</option>
<?php foreach(array_keys(getFaculties()) as $faculty): ?>
<option value="<?php echo htmlspecialchars($faculty); ?>"><?php echo htmlspecialchars($faculty); ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="col-md-6 mb-3">
<label class="form-label">Department</label>
<select class="form-select" name="department" id="adminDepartment" required>
<option value="">Select Department</option>
</select>
<div class="form-text">Select a faculty first to see available departments</div>
</div>
</div>
<div class="row">
<div class="col-md-12 mb-3">
<label class="form-label">Phone Number</label>
<input type="tel" class="form-control" name="phone" placeholder="e.g., +2348012345678">
<small class="text-muted">Optional - credentials will be sent via email and SMS if provided</small>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
<button type="submit" class="btn btn-primary">Create Admin Account</button>
</div>
</form>
</div>
</div>
</div>
<!-- Create Staff Modal -->
<div class="modal fade" id="createStaffModal" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title"><i class="fas fa-user-plus me-2"></i>Create New Staff Account</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<form method="POST">
<div class="modal-body">
<input type="hidden" name="action" value="create_staff">
<div class="row">
<div class="col-md-6 mb-3">
<label class="form-label">Full Name</label>
<input type="text" class="form-control" name="fullname" required>
</div>
<div class="col-md-6 mb-3">
<label class="form-label">Email</label>
<input type="email" class="form-control" name="email" required>
</div>
</div>
<div class="row">
<div class="col-md-6 mb-3">
<label class="form-label">Password</label>
<div class="input-group">
<input type="text" class="form-control" name="password" required>
<button class="btn btn-outline-secondary" type="button" onclick="generatePassword()">Generate</button>
</div>
</div>
<div class="col-md-6 mb-3">
<label class="form-label">Role</label>
<select class="form-select" name="role" required>
<option value="Staff">Staff</option>
<option value="Department Head">Department Head</option>
<option value="Faculty Head">Faculty Head</option>
</select>
</div>
</div>
<div class="row">
<div class="col-md-6 mb-3">
<label class="form-label">Faculty</label>
<select class="form-select" name="faculty" id="faculty" required onchange="updateDepartments()">
<option value="">Select Faculty</option>
<?php foreach(array_keys(getFaculties()) as $faculty): ?>
<option value="<?php echo htmlspecialchars($faculty); ?>"><?php echo htmlspecialchars($faculty); ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="col-md-6 mb-3">
<label class="form-label">Department</label>
<select class="form-select" name="department" id="department" required onchange="generateStaffId()">
<option value="">Select Department</option>
</select>
</div>
</div>
<div class="row">
<div class="col-md-6 mb-3">
<label class="form-label">Phone Number</label>
<input type="tel" class="form-control" name="phone" placeholder="e.g., 08012345678">
<small class="text-muted">Optional - for SMS notifications</small>
</div>
<div class="col-md-6 mb-3">
<label class="form-label">Staff ID</label>
<input type="text" class="form-control" name="staff_id" id="staff_id" readonly>
<small class="text-muted">Auto-generated based on department</small>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
<button type="submit" class="btn btn-primary">Create Staff Account</button>
</div>
</form>
</div>
</div>
</div>
<!-- Edit Staff Modal -->
<div class="modal fade" id="editStaffModal" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title"><i class="fas fa-user-edit me-2"></i>Edit Staff Account</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<form method="POST" id="editStaffForm">
<div class="modal-body">
<input type="hidden" name="action" value="update_staff">
<input type="hidden" name="id" id="editStaffId">
<div class="row">
<div class="col-md-6 mb-3">
<label class="form-label">Full Name</label>
<input type="text" class="form-control" name="fullname" id="editFullname" required>
</div>
<div class="col-md-6 mb-3">
<label class="form-label">Email</label>
<input type="email" class="form-control" name="email" id="editEmail" required>
</div>
</div>
<div class="row">
<div class="col-md-6 mb-3">
<label class="form-label">Faculty</label>
<input type="text" class="form-control" name="faculty" id="editFaculty" required>
</div>
<div class="col-md-6 mb-3">
<label class="form-label">Department</label>
<input type="text" class="form-control" name="department" id="editDepartment" required>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
<button type="submit" class="btn btn-primary">Update Staff Account</button>
</div>
</form>
</div>
</div>
</div>
<!-- Delete Confirmation Modal -->
<div class="modal fade" id="deleteStaffModal" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header bg-danger text-white">
<h5 class="modal-title"><i class="fas fa-exclamation-triangle me-2"></i>Confirm Deletion</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<form method="POST" id="deleteStaffForm">
<div class="modal-body">
<input type="hidden" name="action" value="delete_staff">
<input type="hidden" name="id" id="deleteStaffId">
<p>Are you sure you want to delete the staff account for <strong id="deleteStaffName"></strong>?</p>
<p class="text-danger"><i class="fas fa-warning me-1"></i>This action cannot be undone.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
<button type="submit" class="btn btn-danger">Delete Staff Account</button>
</div>
</form>
</div>
</div>
</div>
<!-- Edit Admin Modal -->
<div class="modal fade" id="editAdminModal" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title"><i class="fas fa-user-shield me-2"></i>Edit Admin Account</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<form method="POST" id="editAdminForm">
<div class="modal-body">
<input type="hidden" name="action" value="update_admin">
<input type="hidden" name="id" id="editAdminId">
<div class="row">
<div class="col-md-6 mb-3">
<label class="form-label">Full Name</label>
<input type="text" class="form-control" name="fullname" id="editAdminFullname" required>
</div>
<div class="col-md-6 mb-3">
<label class="form-label">Email</label>
<input type="email" class="form-control" name="email" id="editAdminEmail" required>
</div>
</div>
<div class="row">
<div class="col-md-6 mb-3">
<label class="form-label">Faculty</label>
<select class="form-select" name="faculty" id="editAdminFaculty" onchange="updateAdminDepartments()" required>
<option value="">Select Faculty</option>
<?php foreach(array_keys(getFaculties()) as $faculty): ?>
<option value="<?php echo htmlspecialchars($faculty); ?>"><?php echo htmlspecialchars($faculty); ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="col-md-6 mb-3">
<label class="form-label">Department</label>
<select class="form-select" name="department" id="editAdminDepartment" required>