password_hash($adminPass, PASSWORD_DEFAULT), 'installed_at' => date('c'), 'cron_secret' => bin2hex(random_bytes(32)), 'ui_locale' => current_locale(), ]); $docTypeIds = []; foreach ($standardTemplates as $slugKey => $tpl) { $isRequired = in_array($slugKey, ['impressum', 'privacy']) ? 1 : (isset($selectedPages[$slugKey]) ? 0 : 0); $stmt = $pdo->prepare("INSERT INTO doc_types (slug, title, is_required) VALUES (?, ?, ?)"); $stmt->execute([$tpl['slug'], $tpl['title'], $isRequired]); $docTypeIds[$slugKey] = (int)$pdo->lastInsertId(); } $customCreatedIds = []; if (!empty($customTitles) && is_array($customTitles)) { foreach ($customTitles as $idx => $cTitle) { $cTitle = trim((string)$cTitle); if ($cTitle === '') continue; $cSlug = trim((string)($customSlugs[$idx] ?? '')); if ($cSlug === '') { $cSlug = strtolower(preg_replace('/[^a-zA-Z0-9]+/', '-', $cTitle)); } $cIsReq = !empty($customRequired[$idx]) ? 1 : 0; $stmt = $pdo->prepare("INSERT INTO doc_types (slug, title, is_required) VALUES (?, ?, ?)"); $stmt->execute([$cSlug, $cTitle, $cIsReq]); $customCreatedIds[] = [ 'id' => (int)$pdo->lastInsertId(), 'title' => $cTitle, 'slug' => $cSlug, 'is_required' => $cIsReq ]; } } $activeLanguagesStr = implode(',', array_unique(array_merge([$primaryLang], $selectedLangs))); $stmt = $pdo->prepare(" INSERT INTO projects (domain, name, primary_lang, active_languages, brand_color, deepl_api_key, company_name, address, email, phone, representative, register_info) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) "); $stmt->execute([ $projectDomain, $projectName, $primaryLang, $activeLanguagesStr, $brandColor, $deeplApiKey, $companyName, $address, $email, $phone, $representative, $registerInfo ]); $projectId = (int)$pdo->lastInsertId(); foreach ($selectedPages as $pageKey) { if (isset($standardTemplates[$pageKey]) && isset($docTypeIds[$pageKey])) { $docTypeId = $docTypeIds[$pageKey]; $tpl = $standardTemplates[$pageKey]; $docStmt = $pdo->prepare("INSERT INTO documents (project_id, doc_type_id) VALUES (?, ?)"); $docStmt->execute([$projectId, $docTypeId]); $documentId = (int)$pdo->lastInsertId(); $transStmt = $pdo->prepare(" INSERT INTO translations (document_id, lang, title, slug, content, previous_content, status, source_hash) VALUES (?, ?, ?, ?, ?, ?, 'draft', ?) "); $transStmt->execute([ $documentId, $primaryLang, $tpl['title'], $tpl['slug'], $tpl['content'], $tpl['content'], md5($tpl['content']) ]); } } foreach ($customCreatedIds as $cDoc) { $docStmt = $pdo->prepare("INSERT INTO documents (project_id, doc_type_id) VALUES (?, ?)"); $docStmt->execute([$projectId, $cDoc['id']]); $documentId = (int)$pdo->lastInsertId(); $defaultContent = "
Hier den Inhalt für {{company_name}} einfügen.
"; $transStmt = $pdo->prepare(" INSERT INTO translations (document_id, lang, title, slug, content, previous_content, status, source_hash) VALUES (?, ?, ?, ?, ?, ?, 'draft', ?) "); $transStmt->execute([ $documentId, $primaryLang, $cDoc['title'], $cDoc['slug'], $defaultContent, $defaultContent, md5($defaultContent) ]); } if (session_status() === PHP_SESSION_NONE) { $isHttps = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') || (($_SERVER['HTTP_X_FORWARDED_PROTO'] ?? '') === 'https'); session_set_cookie_params(['lifetime' => 0, 'path' => '/', 'secure' => $isHttps, 'httponly' => true, 'samesite' => 'Lax']); session_start(); } session_regenerate_id(true); $_SESSION['paragrafy_admin'] = true; flock($lockHandle, LOCK_UN); header('Location: /admin'); exit; } catch (Throwable $e) { error_log('Paragrafy install failed: ' . $e->getMessage()); $error = t('install.error.install_failed', ['message' => t('install.error.generic_detail')]); } flock($lockHandle, LOCK_UN); } } } ?>