data/ directory is not writable. Please run: chmod 750 data/';
}
if (!is_writable(UPLOADS_PATH)) {
$errors[] = 'The uploads/ directory is not writable. Please run: chmod 755 uploads/';
}
$step = (int)($_GET['step'] ?? 1);
$done = false;
if ($_SERVER['REQUEST_METHOD'] === 'POST' && empty($errors)) {
$step = (int)($_POST['step'] ?? 1);
if ($step === 1) {
// Save basic settings
$siteTitle = trim($_POST['site_title'] ?? 'IndexGram');
$siteDesc = trim($_POST['site_description'] ?? '');
$baseUrl = rtrim(trim($_POST['base_url'] ?? AUTO_BASE_URL), '/');
set_setting('site_title', $siteTitle ?: 'IndexGram');
set_setting('og_title', $siteTitle ?: 'IndexGram');
set_setting('site_description', $siteDesc);
set_setting('og_description', $siteDesc);
set_setting('base_url', $baseUrl);
set_setting('footer_text', trim($_POST['footer_text'] ?? 'IndexGram by Amfile.org of Page Telegram Volunteer Services v1.00 2026'));
header('Location: setup.php?step=2'); exit;
} elseif ($step === 2) {
// Create admin user
$username = trim($_POST['username'] ?? '');
$email = trim($_POST['email'] ?? '');
$password = $_POST['password'] ?? '';
$confirm = $_POST['confirm'] ?? '';
if (strlen($username) < 3) $errors[] = 'Username must be at least 3 characters.';
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) $errors[] = 'Invalid email address.';
if (strlen($password) < 8) $errors[] = 'Password must be at least 8 characters.';
if ($password !== $confirm) $errors[] = 'Passwords do not match.';
if (empty($errors)) {
$hash = password_hash($password, PASSWORD_DEFAULT);
db()->prepare(
"INSERT INTO users (username, email, password_hash, role) VALUES (?,?,?,'admin')"
)->execute([$username, $email, $hash]);
// Seed default OS/2 theme into DB now that CSS file may exist
$themeCount = db()->query("SELECT COUNT(*) FROM themes")->fetchColumn();
if ($themeCount == 0) {
$cssPath = ROOT_PATH . '/assets/css/os2.css';
$css = file_exists($cssPath) ? file_get_contents($cssPath) : '/* OS/2 theme */';
db()->prepare("INSERT INTO themes (name, css_content, is_active) VALUES (?, ?, 1)")
->execute(['OS/2 Warp 3.0 (Default)', $css]);
}
// Mark installed
file_put_contents(DATA_PATH . '/installed', date('Y-m-d H:i:s'));
header('Location: admin/'); exit;
}
}
}
?>