Messages system troubleshoot
parent
708a50bcf8
commit
a8bf994ae5
|
@ -124,12 +124,13 @@ class Messages {
|
||||||
/**
|
/**
|
||||||
* Render message HTML
|
* Render message HTML
|
||||||
*/
|
*/
|
||||||
public static function render($category, $key, $customMessage = null, $dismissible = false, $small = false) {
|
// Usage: echo Messages::render('LOGIN', 'LOGIN_SUCCESS', 'custom message [or null]', true [for dismissible; or null], true [for small; or omit]);
|
||||||
|
public static function render($category, $key, $customMessage = null, $dismissible = null, $small = false) {
|
||||||
$config = self::get($category, $key);
|
$config = self::get($category, $key);
|
||||||
if (!$config) return '';
|
if (!$config) return '';
|
||||||
|
|
||||||
$message = $customMessage ?? $config['message'];
|
$message = $customMessage ?? $config['message'];
|
||||||
$isDismissible = $dismissible ?? $config['dismissible'];
|
$isDismissible = $dismissible ?? $config['dismissible'] ?? false;
|
||||||
$dismissClass = $isDismissible ? ' alert-dismissible fade show' : '';
|
$dismissClass = $isDismissible ? ' alert-dismissible fade show' : '';
|
||||||
$dismissButton = $isDismissible ? '<button type="button" class="btn-close' . ($small ? ' btn-close-sm' : '') . '" data-bs-dismiss="alert" aria-label="Close"></button>' : '';
|
$dismissButton = $isDismissible ? '<button type="button" class="btn-close' . ($small ? ' btn-close-sm' : '') . '" data-bs-dismiss="alert" aria-label="Close"></button>' : '';
|
||||||
$smallClass = $small ? ' alert-sm' : '';
|
$smallClass = $small ? ' alert-sm' : '';
|
||||||
|
@ -147,15 +148,21 @@ class Messages {
|
||||||
/**
|
/**
|
||||||
* Store message in session for display after redirect
|
* Store message in session for display after redirect
|
||||||
*/
|
*/
|
||||||
public static function flash($category, $key, $customMessage = null, $dismissible = false, $small = false) {
|
// Usage: Messages::flash('LOGIN', 'LOGIN_SUCCESS', 'custom message [or null]', true [for dismissible; or null], true [for small; or omit]);
|
||||||
|
public static function flash($category, $key, $customMessage = null, $dismissible = null, $small = false) {
|
||||||
if (!isset($_SESSION['flash_messages'])) {
|
if (!isset($_SESSION['flash_messages'])) {
|
||||||
$_SESSION['flash_messages'] = [];
|
$_SESSION['flash_messages'] = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get the message configuration
|
||||||
|
$config = self::get($category, $key);
|
||||||
|
$isDismissible = $dismissible ?? $config['dismissible'] ?? false;
|
||||||
|
|
||||||
$_SESSION['flash_messages'][] = [
|
$_SESSION['flash_messages'][] = [
|
||||||
'category' => $category,
|
'category' => $category,
|
||||||
'key' => $key,
|
'key' => $key,
|
||||||
'custom_message' => $customMessage,
|
'custom_message' => $customMessage,
|
||||||
'dismissible' => $dismissible,
|
'dismissible' => $isDismissible,
|
||||||
'small' => $small
|
'small' => $small
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
if (isset($messages) && is_array($messages)) {
|
if (isset($messages) && is_array($messages)) {
|
||||||
foreach ($messages as $msg) {
|
foreach ($messages as $msg) {
|
||||||
echo Messages::render($msg['category'], $msg['key'], $msg['custom_message'] ?? null);
|
echo Messages::render($msg['category'], $msg['key'], $msg['custom_message'] ?? null, $msg['dismissible'] ?? false, $msg['small'] ?? false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,9 @@ if (!empty($flash_messages)) {
|
||||||
return [
|
return [
|
||||||
'category' => $flash['category'],
|
'category' => $flash['category'],
|
||||||
'key' => $flash['key'],
|
'key' => $flash['key'],
|
||||||
'custom_message' => $flash['custom_message']
|
'custom_message' => $flash['custom_message'] ?? null,
|
||||||
|
'dismissible' => $flash['dismissible'] ?? false,
|
||||||
|
'small' => $flash['small'] ?? false
|
||||||
];
|
];
|
||||||
}, $flash_messages));
|
}, $flash_messages));
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,7 +74,7 @@ try {
|
||||||
$logObject->insertLog($user_id, "Login: User \"$username\" logged in. IP: $user_IP", 'user');
|
$logObject->insertLog($user_id, "Login: User \"$username\" logged in. IP: $user_IP", 'user');
|
||||||
|
|
||||||
// Set success message and redirect
|
// Set success message and redirect
|
||||||
Messages::flash('LOGIN', 'LOGIN_SUCCESS');
|
Messages::flash('LOGIN', 'LOGIN_SUCCESS', null, true);
|
||||||
header('Location: ' . htmlspecialchars($app_root));
|
header('Location: ' . htmlspecialchars($app_root));
|
||||||
exit();
|
exit();
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -22,7 +22,7 @@ require '../app/includes/sanitize.php';
|
||||||
require_once '../app/classes/messages.php';
|
require_once '../app/classes/messages.php';
|
||||||
$messages = [];
|
$messages = [];
|
||||||
|
|
||||||
include '../app/includes/messages.php';
|
//include '../app/includes/messages.php';
|
||||||
|
|
||||||
require '../app/includes/errors.php';
|
require '../app/includes/errors.php';
|
||||||
|
|
||||||
|
@ -189,7 +189,7 @@ if ($page == 'logout') {
|
||||||
$server_endpoint = '/health';
|
$server_endpoint = '/health';
|
||||||
$server_status = $serverObject->getServerStatus($server_host, $server_port, $server_endpoint);
|
$server_status = $serverObject->getServerStatus($server_host, $server_port, $server_endpoint);
|
||||||
if (!$server_status) {
|
if (!$server_status) {
|
||||||
echo Messages::render('ERROR', 'DEFAULT', 'The Jilo Server is not running. Some data may be old and incorrect.', false, true);
|
Messages::flash('ERROR', 'DEFAULT', 'The Jilo Server is not running. Some data may be old and incorrect.', false, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue