body { background-color: #2b2a3d; color: #d7e6e1; font-family: monospace, monospace; padding: 50px; font-size: 13px; } input[type="text"],input[type="email"]{ width: 550px; background-color: #151220; color: #d7e6e1; font-size: 100%; } label { text-align: right; display: block; } a { color: #6e9fff; } '); $installerHead = '
' . $logo;
}
function resultHtmlEnd() {
    return '';
}
function formHtml() {
    global $installerHead, $formBody;
    return $installerHead . $formBody . '';
}
function finishOk() {
    $out = "\n\n======================== Setup completed! ========================";
    $out .= "\n* Please delete the ./install directory and all its included files.";
    $out .= "\n* Visit /signup to create your account.";
    return $out;
}
function finishError() {
    global $backButton;
    $out = "\n====================== Something went wrong ======================";
    $out .= "\n$backButton";
    return $out;
}
$steps = [
    [
        'description' => 'Compatibility checks',
        'tasks' => [
            ['description' => 'PHP version', 'status' => null],
            ['description' => 'PDO PostgreSQL driver', 'status' => null],
            ['description' => 'Configuration folder (/config) read/write permission', 'status' => null],
            ['description' => '.htaccess available', 'status' => null],
            ['description' => 'cURL', 'status' => null],
            ['description' => 'Memory limit (Min. 128MB)', 'status' => null],
        ],
    ],
    [
        'description' => 'Database params',
        'tasks' => [
            ['description' => 'Schema accessible', 'status' => null],
            ['description' => 'Database name', 'status' => null],
            ['description' => 'Database user', 'status' => null],
            ['description' => 'Database password', 'status' => null],
            ['description' => 'Database host', 'status' => null],
            ['description' => 'Database port', 'status' => null],
        ],
    ],
    [
        'description' => 'Database setup',
        'tasks' => [
            ['description' => 'Database connection', 'status' => null],
            /*['description' => 'Database version', 'status' => null],*/
            ['description' => 'Apply database schema', 'status' => null],
        ],
    ],
    [
        'description' => 'Config build',
        'tasks' => [
            ['description' => 'Write config file', 'status' => null],
        ],
    ],
];
function proceed() {
    $out = '';
    if (configAlreadyExists()) {
        $out .= resultHtmlStart();
        $out .= "\nThe app is already configured.";
        $out .= resultHtmlEnd();
        echo $out;
        return;
    }
    if ($_SERVER['REQUEST_METHOD'] === 'POST') {
        $out .= resultHtmlStart();
        [$status, $result, $config] = execute($_POST);
        $out .= $result;
        $out .= $status ? finishOk() : finishError();
        $out .= resultHtmlEnd();
    } else {
        substituteFormWithEnv();
        $out .= formHtml();
    }
    echo $out;
}
function execute(array $values) {
    global $steps;
    $out = '';
    compatibilityCheck(0, $steps);
    $out .= printTasks($steps[0]);
    if (!tasksCompleted($steps[0])) {
        return [false, $out, null];
    }
    dbConfig(1, $values, $steps);
    $out .= printTasks($steps[1]);
    if (!tasksCompleted($steps[1])) {
        return [false, $out, null];
    }
    dbSaveConfig(2, $values, $steps);
    $out .= printTasks($steps[2]);
    if (!tasksCompleted($steps[2])) {
        return [false, $out, null];
    }
    if (strval($values['mode'] ?? '') !== 'schema') {
        $config = saveConfig(3, $values, $steps);
        $out .= printTasks($steps[3]);
        if (!tasksCompleted($steps[3])) {
            return [false, $out, null];
        }
    }
    return [true, $out, $config];
}
function configAlreadyExists(): bool {
    return (getenv('SITE') && getenv('DATABASE_URL')) || file_exists('../config/local/config.local.ini');
}
function substituteFormWithEnv(): void {
    global $formBody;
    if (strval($_GET['mode'] ?? '') === 'schema') {
        $formBody = preg_replace(
            '/(