false, 'error' => 'Authentication required']); exit; } $usr_id = $_SESSION['user_id']; $notifications = new VNotifications(); $method = $_SERVER['REQUEST_METHOD']; if ($method === 'GET') { // Get preferences $prefs = $notifications->getPreferences($usr_id); echo json_encode([ 'success' => true, 'data' => $prefs ]); } elseif ($method === 'POST') { // Update preferences $input = json_decode(file_get_contents('php://input'), true); if (!$input) { // Try form data $input = $_POST; } $result = $notifications->updatePreferences($usr_id, $input); if ($result) { echo json_encode([ 'success' => true, 'data' => $notifications->getPreferences($usr_id) ]); } else { http_response_code(400); echo json_encode(['success' => false, 'error' => 'Failed to update preferences']); } } else { http_response_code(405); echo json_encode(['success' => false, 'error' => 'Method not allowed']); }