|]+/u', '-', $name) ?? $name; $name = preg_replace('/\\s+/u', ' ', $name) ?? $name; $name = trim($name, " .-\t"); return $name !== '' ? $name : 'Stolik'; } function buildUniqueQrFileNames(array $tables): array { $used = []; foreach ($tables as &$table) { $base = sanitizeZipFileName(formatQrDisplayName((string) ($table['nazwa'] ?? ''))); $candidate = $base; $index = 2; while (isset($used[$candidate])) { $candidate = $base . ' (' . $index . ')'; $index++; } $used[$candidate] = true; $table['fileName'] = $candidate . '.png'; } unset($table); return $tables; } function buildGuestAppBaseUrl(): array { $host = $_SERVER['HTTP_HOST'] ?? 'localhost'; $scheme = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http'; $scriptDir = str_replace('\\', '/', dirname($_SERVER['SCRIPT_NAME'] ?? '/public/staff')); $publicDir = str_replace('\\', '/', dirname($scriptDir)); $basePath = rtrim($publicDir, '/') . '/app.html?h='; $baseUrl = "{$scheme}://{$host}{$basePath}"; return [$baseUrl, $basePath]; } function appendPreviewParam(string $link, string $previewQuery): string { return str_contains($link, '?') ? $link . '&' . $previewQuery : $link . '?' . $previewQuery; }