/home/techb158/workloadmatch.com/Admin
NameSizeModeActions
dashboard.php105150644editdlrm
logs.php100170644editdlrm
main-header-inc.php11950644editdlrm
main-header.php75270644editdlrm
managers.php215240644editdlrm
masters.php217050644editdlrm
pages.php158220644editdlrm
pages_ajax.php6300644editdlrm
reports.php91930644editdlrm
roles.php158330644editdlrm
roles_ajax.php10070644editdlrm
settings.php45750644editdlrm
teachers.php278500644editdlrm
teacher_absence.php3050644editdlrm
Edit: /home/techb158/workloadmatch.com/Admin/teachers.php (27850B)
verifyRequest(); if (isset($_POST['action'])) { $action = $_POST['action']; if ($action === 'add_teacher') { $firstName = trim($_POST['first_name']); $lastName = trim($_POST['last_name']); $email = trim($_POST['email']); $phone = trim($_POST['phone']); $password = trim($_POST['password']); $managerId = $_POST['manager_id']; $teacherId = uniqid('TCH-'); $salt = bin2hex(openssl_random_pseudo_bytes(32)); $hashedPassword = hash('sha512', $password . $salt); $adminId = $_SESSION['user_id']; // Get Master_ID from the selected manager $stmt = $mysqli->prepare("SELECT Master_ID, Admin_ID FROM manager_profile WHERE Manager_ID = ?"); $masterId = ''; $mgrAdminId = ''; if ($stmt) { $stmt->bind_param('s', $managerId); $stmt->execute(); $stmt->bind_result($masterId, $mgrAdminId); $stmt->fetch(); $stmt->close(); } $insertStmt = $mysqli->prepare("INSERT INTO teacher_profile (Teacher_ID, Admin_ID, Master_ID, Manager_ID, First_Name, Last_Name, Email, Phone, Password, salt, User_Access, Reg_Date) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 1, NOW())"); if ($insertStmt) { $insertStmt->bind_param('ssssssssss', $teacherId, $adminId, $masterId, $managerId, $firstName, $lastName, $email, $phone, $hashedPassword, $salt); if ($insertStmt->execute()) { set_flash_msg('Teacher added successfully.', 'success'); log_activity($mysqli, 'Created Teacher', 'Teacher', $teacherId, $firstName . ' ' . $lastName); } else { set_flash_msg('Failed to add teacher: ' . $insertStmt->error, 'error'); } $insertStmt->close(); } else { set_flash_msg('Database error.', 'error'); } header('Location: ' . $_SERVER['PHP_SELF']); exit; } if ($action === 'edit_teacher') { $teacherId = $_POST['teacher_id']; $firstName = trim($_POST['first_name']); $lastName = trim($_POST['last_name']); $email = trim($_POST['email']); $phone = trim($_POST['phone']); $managerId = $_POST['manager_id']; $stmt = $mysqli->prepare("SELECT Master_ID FROM manager_profile WHERE Manager_ID = ?"); $masterId = ''; if ($stmt) { $stmt->bind_param('s', $managerId); $stmt->execute(); $stmt->bind_result($masterId); $stmt->fetch(); $stmt->close(); } $updateStmt = $mysqli->prepare("UPDATE teacher_profile SET First_Name = ?, Last_Name = ?, Email = ?, Phone = ?, Manager_ID = ?, Master_ID = ? WHERE Teacher_ID = ?"); if ($updateStmt) { $updateStmt->bind_param('sssssss', $firstName, $lastName, $email, $phone, $managerId, $masterId, $teacherId); if ($updateStmt->execute()) { set_flash_msg('Teacher updated successfully.', 'success'); log_activity($mysqli, 'Updated Teacher', 'Teacher', $teacherId, $firstName . ' ' . $lastName); } else { set_flash_msg('Failed to update teacher.', 'error'); } $updateStmt->close(); } header('Location: ' . $_SERVER['PHP_SELF']); exit; } if ($action === 'transfer_teacher') { $teacherId = $_POST['teacher_id']; $newManagerId = $_POST['new_manager_id']; $stmt = $mysqli->prepare("SELECT Master_ID FROM manager_profile WHERE Manager_ID = ?"); $masterId = ''; if ($stmt) { $stmt->bind_param('s', $newManagerId); $stmt->execute(); $stmt->bind_result($masterId); $stmt->fetch(); $stmt->close(); } $updateStmt = $mysqli->prepare("UPDATE teacher_profile SET Manager_ID = ?, Master_ID = ? WHERE Teacher_ID = ?"); if ($updateStmt) { $updateStmt->bind_param('sss', $newManagerId, $masterId, $teacherId); if ($updateStmt->execute()) { set_flash_msg('Teacher transferred successfully.', 'success'); log_activity($mysqli, 'Transferred Teacher', 'Teacher', $teacherId, 'Transferred to Manager: ' . $newManagerId); } else { set_flash_msg('Failed to transfer teacher.', 'error'); } $updateStmt->close(); } header('Location: ' . $_SERVER['PHP_SELF']); exit; } if ($action === 'toggle_teacher') { $teacherId = $_POST['teacher_id']; $newStatus = intval($_POST['status']); $stmt = $mysqli->prepare("SELECT First_Name, Last_Name FROM teacher_profile WHERE Teacher_ID = ?"); $name = ''; if ($stmt) { $stmt->bind_param('s', $teacherId); $stmt->execute(); $stmt->bind_result($fn, $ln); $stmt->fetch(); $name = $fn . ' ' . $ln; $stmt->close(); } if (toggle_user_status($mysqli, 'teacher_profile', 'Teacher_ID', $teacherId, $newStatus)) { set_flash_msg('Teacher status updated.', 'success'); log_activity($mysqli, $newStatus ? 'Enabled Teacher' : 'Disabled Teacher', 'Teacher', $teacherId, $name); } else { set_flash_msg('Failed to update status.', 'error'); } header('Location: ' . $_SERVER['PHP_SELF']); exit; } if ($action === 'delete_teacher') { $teacherId = $_POST['teacher_id']; $stmt = $mysqli->prepare("SELECT First_Name, Last_Name FROM teacher_profile WHERE Teacher_ID = ?"); $name = ''; if ($stmt) { $stmt->bind_param('s', $teacherId); $stmt->execute(); $stmt->bind_result($fn, $ln); $stmt->fetch(); $name = $fn . ' ' . $ln; $stmt->close(); } $stmt = $mysqli->prepare("UPDATE teacher_profile SET is_archived = 1 WHERE Teacher_ID = ?"); if ($stmt) { $stmt->bind_param('s', $teacherId); if ($stmt->execute()) { set_flash_msg('Teacher archived successfully.', 'success'); log_activity($mysqli, 'Archived Teacher', 'Teacher', $teacherId, $name); } else { set_flash_msg('Failed to archive teacher.', 'error'); } $stmt->close(); } header('Location: ' . $_SERVER['PHP_SELF']); exit; } } } // Fetch counts $totalStmt = $mysqli->query("SELECT COUNT(*) AS cnt FROM teacher_profile WHERE is_archived IS NULL OR is_archived = 0"); $totalTeachers = $totalStmt ? $totalStmt->fetch_assoc()['cnt'] : 0; $activeStmt = $mysqli->query("SELECT COUNT(*) AS cnt FROM teacher_profile WHERE User_Access = 1 AND (is_archived IS NULL OR is_archived = 0)"); $activeTeachers = $activeStmt ? $activeStmt->fetch_assoc()['cnt'] : 0; $disabledStmt = $mysqli->query("SELECT COUNT(*) AS cnt FROM teacher_profile WHERE User_Access = 0 AND (is_archived IS NULL OR is_archived = 0)"); $disabledTeachers = $disabledStmt ? $disabledStmt->fetch_assoc()['cnt'] : 0; // Fetch all managers for dropdowns (with Master info) $managers = []; $mgrResult = $mysqli->query("SELECT mg.Manager_ID, mg.First_Name, mg.Last_Name, mp.First_Name AS Master_First, mp.Last_Name AS Master_Last FROM manager_profile mg LEFT JOIN master_profile mp ON mg.Master_ID = mp.Master_ID ORDER BY mp.First_Name, mg.First_Name"); if ($mgrResult) { while ($r = $mgrResult->fetch_assoc()) { $managers[] = $r; } } // Fetch all masters for filter $masters = []; $mstResult = $mysqli->query("SELECT Master_ID, First_Name, Last_Name FROM master_profile WHERE User_Access = 1 AND (is_archived IS NULL OR is_archived = 0) ORDER BY First_Name"); if ($mstResult) { while ($r = $mstResult->fetch_assoc()) { $masters[] = $r; } } ?> Course Management System | Teachers

Teachers Manage all Teacher accounts

Total Teachers

Active Teachers

Disabled Teachers

Teacher List

query($query); while ($row = $result->fetch_assoc()): $statusLabel = $row['User_Access'] == 1 ? 'Active' : 'Disabled'; $fullName = htmlspecialchars($row['First_Name'] . ' ' . $row['Last_Name']); $mgrName = ($row['Mgr_First'] ? htmlspecialchars($row['Mgr_First'] . ' ' . $row['Mgr_Last']) : 'None'); $mstName = ($row['Mst_First'] ? htmlspecialchars($row['Mst_First'] . ' ' . $row['Mst_Last']) : 'None'); ?>
Teacher ID Name Email Phone Manager Master Status Actions