false, 'error' => 'Method not allowed']); return; } if (session_status() !== PHP_SESSION_ACTIVE) { session_start(); } AdminController::requireAuth(); AdminController::requireAdmin(); AdminController::requireCsrf(); $raw = file_get_contents('php://input'); $body = json_decode($raw, true); if (!is_array($body)) { http_response_code(400); echo json_encode(['success' => false, 'error' => 'Invalid JSON payload.']); return; } $groups = $body['groups'] ?? null; if (!is_array($groups)) { http_response_code(400); echo json_encode(['success' => false, 'error' => 'Invalid groups format.']); return; } $ctrl = new AdminController(); $ctrl->saveProGroups($groups); echo json_encode(['success' => true], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); } catch (Throwable $e) { $code = $e instanceof InvalidArgumentException ? 400 : 500; http_response_code($code); echo json_encode([ 'success' => false, 'error' => 'Error saving groups: ' . $e->getMessage(), ]); }