From e93f08d5e048ba4c6102dd6da9ec36cee3896b8f Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Sat, 28 Feb 2026 07:24:57 +0000 Subject: [PATCH] update installation --- install.php | 43 ++++++++++++++++++++----------------------- mail/install.php | 24 +++++++++++------------- 2 files changed, 31 insertions(+), 36 deletions(-) diff --git a/install.php b/install.php index 45b21d3..e5edfef 100644 --- a/install.php +++ b/install.php @@ -31,11 +31,11 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $host = $_POST['db_host'] ?? '127.0.0.1'; $name = $_POST['db_name'] ?? 'app_database'; $user = $_POST['db_user'] ?? 'root'; - $pass = $_POST['db_pass'] ?? ''; + $password = $_POST['db_pass'] ?? ''; // Test connection try { - $test_pdo = new PDO("mysql:host=$host;dbname=$name;charset=utf8mb4", $user, $pass); + $test_pdo = new PDO("mysql:host=$host;dbname=$name;charset=utf8mb4", $user, $password); $test_pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // Generate config file content @@ -44,16 +44,19 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $content .= "define('DB_HOST', " . var_export($host, true) . ");\n"; $content .= "define('DB_NAME', " . var_export($name, true) . ");\n"; $content .= "define('DB_USER', " . var_export($user, true) . ");\n"; - $content .= "define('DB_PASS', " . var_export($pass, true) . ");\n"; + $content .= "define('DB_PASS', " . var_export($password, true) . ");\n"; $content .= "\n"; $content .= "if (!function_exists('db')) {\n"; $content .= " function db() {\n"; $content .= " static \$pdo;\n"; $content .= " if (!\$pdo) {\n"; $content .= " try {\n"; - $content .= " \$pdo = new PDO('mysql:host=' . DB_HOST . ';dbname=' . DB_NAME . ';charset=utf8mb4', DB_USER, DB_PASS);\n"; - $content .= " \$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);\n"; - $content .= " \$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);\n"; + $content .= " \$pdo = new PDO('mysql:host=' . DB_HOST . ';dbname=' . DB_NAME . ';charset=utf8mb4', DB_USER, DB_PASS); +"; + $content .= " \$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); +"; + $content .= " \$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); +"; $content .= " } catch (PDOException \$e) {\n"; $content .= " die('Connection failed: ' . \$e->getMessage());\n"; $content .= " }\n"; @@ -63,7 +66,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $content .= "}\n"; if (file_put_contents($config_file, $content)) { - header('Location: install.php?step=3'); + header('Location: ' . $_SERVER['PHP_SELF'] . '?step=3'); exit; } else { $error = "Failed to write configuration file to $config_file. Please check permissions."; @@ -95,9 +98,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { if (empty($sql)) continue; try { - // Split SQL into multiple statements if necessary - // Simple split by semicolon. This might fail on some complex SQL, - // but usually works for basic migrations. $statements = array_filter(array_map('trim', explode(';', $sql))); foreach ($statements as $stmt_sql) { if (empty($stmt_sql)) continue; @@ -105,11 +105,10 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $pdo->exec($stmt_sql); } catch (Throwable $e) { $msg = $e->getMessage(); - // Check if it's a common "already exists" error which we can safely ignore if (strpos($msg, 'Duplicate column name') !== false || strpos($msg, 'Duplicate key name') !== false || strpos($msg, 'Duplicate table') !== false || - strpos($msg, 'already exists') !== false) { + strpos($msg, 'already exists') !== false || strpos($msg, 'Duplicate key on write or update') !== false || strpos($msg, 'errno: 121') !== false) { continue; } else { throw $e; @@ -124,7 +123,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { if (empty($errors)) { $success = "Successfully applied $applied migrations."; - header('Location: install.php?step=4'); + header('Location: ' . $_SERVER['PHP_SELF'] . '?step=4'); exit; } else { $error = "Applied migrations, but some errors occurred:
"; @@ -155,7 +154,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $pdo->exec("INSERT IGNORE INTO charity_settings (id, charity_name) VALUES (1, 'Admin Panel')"); $pdo->exec("INSERT IGNORE INTO smtp_settings (id, is_enabled) VALUES (1, 0)"); - header('Location: install.php?step=5'); + header('Location: ' . $_SERVER['PHP_SELF'] . '?step=5'); exit; } catch (Throwable $e) { $error = "Failed to create admin account: " . $e->getMessage(); @@ -190,10 +189,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$i\n"; + $class = ($i == $step) ? 'active' : (($i < $step) ? 'completed' : ''); + echo "$i\n"; endfor; ?>
@@ -221,7 +218,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
- Next: Database Config + Next: Database Config Fix requirements to continue"; endif; ?> @@ -229,7 +226,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {

Step 2: Database Connection

-
+
@@ -254,7 +251,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {

Step 3: Database Migrations

We will now run the SQL scripts to set up your database tables.

- +
@@ -262,7 +259,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {

Step 4: Admin Account

- +
@@ -293,4 +290,4 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
- \ No newline at end of file + diff --git a/mail/install.php b/mail/install.php index 97d2120..5e759b3 100644 --- a/mail/install.php +++ b/mail/install.php @@ -66,7 +66,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $content .= "}\n"; if (file_put_contents($config_file, $content)) { - header('Location: install.php?step=3'); + header('Location: ' . $_SERVER['PHP_SELF'] . '?step=3'); exit; } else { $error = "Failed to write configuration file to $config_file. Please check permissions."; @@ -109,7 +109,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { if (strpos($msg, 'Duplicate column name') !== false || strpos($msg, 'Duplicate key name') !== false || strpos($msg, 'Duplicate table') !== false || - strpos($msg, 'already exists') !== false) { + strpos($msg, 'already exists') !== false || strpos($msg, 'Duplicate key on write or update') !== false || strpos($msg, 'errno: 121') !== false) { continue; } else { throw $e; @@ -124,7 +124,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { if (empty($errors)) { $success = "Successfully applied $applied migrations."; - header('Location: install.php?step=4'); + header('Location: ' . $_SERVER['PHP_SELF'] . '?step=4'); exit; } else { $error = "Applied migrations, but some errors occurred:
  • " . implode('
  • ', $errors) . "
"; @@ -155,7 +155,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $pdo->exec("INSERT IGNORE INTO charity_settings (id, charity_name) VALUES (1, 'Admin Panel')"); $pdo->exec("INSERT IGNORE INTO smtp_settings (id, is_enabled) VALUES (1, 0)"); - header('Location: install.php?step=5'); + header('Location: ' . $_SERVER['PHP_SELF'] . '?step=5'); exit; } catch (Throwable $e) { $error = "Failed to create admin account: " . $e->getMessage(); @@ -190,10 +190,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$i\n"; + $class = ($i == $step) ? 'active' : (($i < $step) ? 'completed' : ''); + echo "$i\n"; endfor; ?>
@@ -221,7 +219,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
- Next: Database Config + Next: Database Config Fix requirements to continue"; endif; ?> @@ -229,7 +227,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {

Step 2: Database Connection

- +
@@ -254,7 +252,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {

Step 3: Database Migrations

We will now run the SQL scripts to set up your database tables.

- +
@@ -262,7 +260,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {

Step 4: Admin Account

- +
@@ -293,4 +291,4 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
- + \ No newline at end of file