From 752f519cccf5dd18095a7c625c7b6bb3f922b166 Mon Sep 17 00:00:00 2001 From: Yasen Pramatarov Date: Thu, 23 Jan 2025 14:06:36 +0200 Subject: [PATCH] Enhances messages system with JS-based messages --- app/pages/config.php | 29 ++++++++----------- app/templates/config.php | 34 ++++++++++++++++------- app/templates/page-header.php | 1 + public_html/static/css/messages.css | 43 +++++++++++++++++++++++++++++ 4 files changed, 79 insertions(+), 28 deletions(-) create mode 100644 public_html/static/css/messages.css 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 @@

Configuration

+ + +
@@ -16,7 +19,7 @@ hasRight($user_id, 'edit config file')): ?>
-
@@ -109,7 +112,7 @@