/home/techb158/workloadmatch.com/api
Edit: /home/techb158/workloadmatch.com/api/change_status.php (1332B)
false, 'error' => 'Not logged in']);
exit();
}
$status = $_POST['status'] ?? '';
$user_type = $_POST['user_type'] ?? '';
$validStatuses = ['Online', 'Busy', 'Unavailable', 'Offline'];
if (!in_array($status, $validStatuses)) {
echo json_encode(['success' => false, 'error' => 'Invalid status']);
exit();
}
$tableMap = [
'manager' => ['manager_profile', 'Manager_ID'],
'master' => ['master_profile', 'Master_ID'],
'teacher' => ['teacher_profile', 'Teacher_ID'],
'admin' => ['admin_profile', 'Admin_ID'],
];
if (!isset($tableMap[$user_type])) {
echo json_encode(['success' => false, 'error' => 'Invalid user type']);
exit();
}
[$table, $idCol] = $tableMap[$user_type];
$stmt = $mysqli->prepare("UPDATE $table SET Profile_Status = ? WHERE $idCol = ?");
if ($stmt) {
$stmt->bind_param('ss', $status, $_SESSION['user_id']);
$success = $stmt->execute();
$stmt->close();
echo json_encode(['success' => $success]);
} else {
echo json_encode(['success' => false, 'error' => 'Database error']);
}