diff --git a/app/pages/config.php b/app/pages/config.php index 50403a5..7b83583 100644 --- a/app/pages/config.php +++ b/app/pages/config.php @@ -18,6 +18,13 @@ $configObject = new Config(); $isAjax = !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'; +// Check if file is writable +$isWritable = is_writable($config_file); +$configMessage = ''; +if (!$isWritable) { + $configMessage = Messages::render('ERROR', 'DEFAULT', 'Config file is not writable', false); +} + if ($_SERVER['REQUEST_METHOD'] === 'POST') { // Ensure no output before this point ob_clean(); @@ -39,16 +46,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { exit; } - // Check if file is writable - if (!is_writable($config_file)) { - Messages::flash('ERROR', 'DEFAULT', 'Config file is not writable', true); - echo json_encode([ - 'success' => false, - 'message' => 'Config file is not writable' - ]); - exit; - } - // Try to update config file $result = $configObject->editConfigFile($postData, $config_file); if ($result === true) { @@ -70,15 +67,11 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { } // Handle non-AJAX POST - if (!is_writable($config_file)) { - Messages::flash('ERROR', 'DEFAULT', 'Config file is not writable', true); + $result = $configObject->editConfigFile($_POST, $config_file); + if ($result === true) { + Messages::flash('NOTICE', 'DEFAULT', 'Config file updated successfully', true); } else { - $result = $configObject->editConfigFile($_POST, $config_file); - if ($result === true) { - Messages::flash('NOTICE', 'DEFAULT', 'Config file updated successfully', true); - } else { - Messages::flash('ERROR', 'DEFAULT', "Error updating config file: $result", true); - } + Messages::flash('ERROR', 'DEFAULT', "Error updating config file: $result", true); } header('Location: ' . htmlspecialchars($app_root) . '?page=config'); diff --git a/app/templates/config.php b/app/templates/config.php index d6bf531..6e773a2 100644 --- a/app/templates/config.php +++ b/app/templates/config.php @@ -5,6 +5,9 @@