0 && in_array($tenantId, $allowedTenantIds, true); })); } elseif (TenantScopeService::isStrict()) { $tenants = []; } $roles = RoleService::list(); $departments = $allowedTenantIds ? DepartmentService::listByTenantIds($allowedTenantIds) : []; if (!$allowedTenantIds && !TenantScopeService::isStrict()) { $departments = DepartmentService::list(); } $errors = []; $form = [ 'first_name' => '', 'last_name' => '', 'email' => '', 'profile_description' => '', 'job_title' => '', 'phone' => '', 'mobile' => '', 'short_dial' => '', 'address' => '', 'postal_code' => '', 'city' => '', 'country' => '', 'region' => '', 'hire_date' => '', 'totp_secret' => '', 'locale' => I18n::$locale ?? I18n::$defaultLocale, 'active' => 1, ]; if (isset($_POST['email'])) { $input = $_POST; $tenantIds = UserService::normalizeIdInput($input['tenant_ids'] ?? []); if ($allowedTenantIds) { $tenantIds = array_values(array_intersect($tenantIds, $allowedTenantIds)); } elseif (TenantScopeService::isStrict()) { $tenantIds = []; } $defaultTenantId = SettingService::getDefaultTenantId(); if (TenantScopeService::isStrict() && !$tenantIds && !$defaultTenantId) { $errors[] = t('Please select at least one tenant'); } $input['tenant_ids'] = $tenantIds; $result = UserService::createFromAdmin($input, $currentUserId); $form = $result['form'] ?? $form; $errors = array_merge($errors, $result['errors'] ?? []); if (($result['ok'] ?? false) && !$errors) { $action = (string) ($_POST['action'] ?? 'create'); if ($action === 'create_close') { Flash::success('User created', 'admin/users', 'user_created'); Router::redirect('admin/users'); } else { $uuid = (string) ($result['uuid'] ?? ''); if ($uuid !== '') { $target = "admin/users/edit/{$uuid}"; Flash::success('User created', $target, 'user_created'); Router::redirect($target); } else { Flash::success('User created', 'admin/users', 'user_created'); Router::redirect('admin/users'); } } } } Buffer::set('title', t('Create user'));