Migrate Dark/light mode to a user settings instead of global setting, created new include called router.php to dynamically prepend ../../ to asset pathes based off currect directory depth
This commit is contained in:
@@ -3821,6 +3821,13 @@ if (LATEST_DATABASE_VERSION > CURRENT_DATABASE_VERSION) {
|
|||||||
mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '2.2.7'");
|
mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '2.2.7'");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (CURRENT_DATABASE_VERSION == '2.2.7') {
|
||||||
|
mysqli_query($mysqli, "ALTER TABLE `user_settings` ADD `user_config_theme_dark` TINYINT(1) NOT NULL DEFAULT 0 AFTER `user_config_signature`");
|
||||||
|
mysqli_query($mysqli, "ALTER TABLE `settings` DROP `config_theme_dark`");
|
||||||
|
|
||||||
|
mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '2.2.8'");
|
||||||
|
}
|
||||||
|
|
||||||
/* 2025-07-21 - JQ For next release Pauyment Provider Switch Over
|
/* 2025-07-21 - JQ For next release Pauyment Provider Switch Over
|
||||||
if (CURRENT_DATABASE_VERSION == '2.2.4') {
|
if (CURRENT_DATABASE_VERSION == '2.2.4') {
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
require_once "../config.php";
|
require_once "../config.php";
|
||||||
require_once "../functions.php";
|
require_once "../functions.php";
|
||||||
|
require_once "../includes/router.php";
|
||||||
require_once "../includes/check_login.php";
|
require_once "../includes/check_login.php";
|
||||||
require_once "../includes/page_title.php";
|
require_once "../includes/page_title.php";
|
||||||
if (!isset($session_is_admin) || !$session_is_admin) {
|
if (!isset($session_is_admin) || !$session_is_admin) {
|
||||||
|
|||||||
@@ -6,11 +6,9 @@ if (isset($_POST['edit_theme_settings'])) {
|
|||||||
|
|
||||||
validateCSRFToken($_POST['csrf_token']);
|
validateCSRFToken($_POST['csrf_token']);
|
||||||
|
|
||||||
$dark_mode = intval($_POST['dark_mode'] ?? 0);
|
|
||||||
|
|
||||||
$theme = preg_replace("/[^0-9a-zA-Z-]/", "", sanitizeInput($_POST['edit_theme_settings']));
|
$theme = preg_replace("/[^0-9a-zA-Z-]/", "", sanitizeInput($_POST['edit_theme_settings']));
|
||||||
|
|
||||||
mysqli_query($mysqli,"UPDATE settings SET config_theme = '$theme', config_theme_dark = $dark_mode WHERE company_id = 1");
|
mysqli_query($mysqli,"UPDATE settings SET config_theme = '$theme' WHERE company_id = 1");
|
||||||
|
|
||||||
logAction("Settings", "Edit", "$session_name edited theme settings $dark_mode");
|
logAction("Settings", "Edit", "$session_name edited theme settings $dark_mode");
|
||||||
|
|
||||||
|
|||||||
@@ -10,15 +10,6 @@ require_once "includes/inc_all_admin.php";
|
|||||||
<form action="post.php" method="post" autocomplete="off">
|
<form action="post.php" method="post" autocomplete="off">
|
||||||
<input type="hidden" name="csrf_token" value="<?php echo $_SESSION['csrf_token'] ?>">
|
<input type="hidden" name="csrf_token" value="<?php echo $_SESSION['csrf_token'] ?>">
|
||||||
|
|
||||||
<h5>Dark Mode</h5>
|
|
||||||
|
|
||||||
<div class="form-group">
|
|
||||||
<div class="custom-control custom-switch">
|
|
||||||
<input type="checkbox" class="custom-control-input" name="dark_mode" <?php if ($config_theme_dark == 1) { echo "checked"; } ?> value="1" onchange="this.form.submit()" id="darkModeSwitch">
|
|
||||||
<label class="custom-control-label" for="darkModeSwitch">Enable Dark Mode</label>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<label>Select a Theme</label>
|
<label>Select a Theme</label>
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
|
|
||||||
|
|||||||
4
db.sql
4
db.sql
@@ -2057,7 +2057,6 @@ CREATE TABLE `settings` (
|
|||||||
`config_log_retention` int(11) NOT NULL DEFAULT 90,
|
`config_log_retention` int(11) NOT NULL DEFAULT 90,
|
||||||
`config_module_enable_ticketing` tinyint(1) NOT NULL DEFAULT 1,
|
`config_module_enable_ticketing` tinyint(1) NOT NULL DEFAULT 1,
|
||||||
`config_theme` varchar(200) DEFAULT 'blue',
|
`config_theme` varchar(200) DEFAULT 'blue',
|
||||||
`config_theme_dark` tinyint(1) NOT NULL DEFAULT 0,
|
|
||||||
`config_telemetry` tinyint(1) DEFAULT 0,
|
`config_telemetry` tinyint(1) DEFAULT 0,
|
||||||
`config_timezone` varchar(200) NOT NULL DEFAULT 'America/New_York',
|
`config_timezone` varchar(200) NOT NULL DEFAULT 'America/New_York',
|
||||||
`config_destructive_deletes_enable` tinyint(1) NOT NULL DEFAULT 0,
|
`config_destructive_deletes_enable` tinyint(1) NOT NULL DEFAULT 0,
|
||||||
@@ -2611,6 +2610,7 @@ CREATE TABLE `user_settings` (
|
|||||||
`user_config_dashboard_technical_enable` tinyint(1) NOT NULL DEFAULT 0,
|
`user_config_dashboard_technical_enable` tinyint(1) NOT NULL DEFAULT 0,
|
||||||
`user_config_calendar_first_day` tinyint(1) NOT NULL DEFAULT 0,
|
`user_config_calendar_first_day` tinyint(1) NOT NULL DEFAULT 0,
|
||||||
`user_config_signature` text DEFAULT NULL,
|
`user_config_signature` text DEFAULT NULL,
|
||||||
|
`user_config_theme_dark` tinyint(1) NOT NULL DEFAULT 0,
|
||||||
PRIMARY KEY (`user_id`)
|
PRIMARY KEY (`user_id`)
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
||||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||||
@@ -2766,4 +2766,4 @@ CREATE TABLE `vendors` (
|
|||||||
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
|
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
|
||||||
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
|
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
|
||||||
|
|
||||||
-- Dump completed on 2025-08-01 13:36:16
|
-- Dump completed on 2025-08-05 13:30:24
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ if (isset($row['role_is_admin']) && $row['role_is_admin'] == 1) {
|
|||||||
}
|
}
|
||||||
$session_user_config_force_mfa = intval($row['user_config_force_mfa']);
|
$session_user_config_force_mfa = intval($row['user_config_force_mfa']);
|
||||||
$user_config_records_per_page = intval($row['user_config_records_per_page']);
|
$user_config_records_per_page = intval($row['user_config_records_per_page']);
|
||||||
|
$user_config_theme_dark = intval($row['user_config_theme_dark']);
|
||||||
|
|
||||||
// Check user type
|
// Check user type
|
||||||
if ($session_user_type !== 1) {
|
if ($session_user_type !== 1) {
|
||||||
|
|||||||
@@ -5,4 +5,4 @@
|
|||||||
* It is used in conjunction with database_updates.php
|
* It is used in conjunction with database_updates.php
|
||||||
*/
|
*/
|
||||||
|
|
||||||
DEFINE("LATEST_DATABASE_VERSION", "2.2.7");
|
DEFINE("LATEST_DATABASE_VERSION", "2.2.8");
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ $config_smtp_username = $row['config_smtp_username'];
|
|||||||
$config_smtp_password = $row['config_smtp_password'];
|
$config_smtp_password = $row['config_smtp_password'];
|
||||||
$config_mail_from_email = $row['config_mail_from_email'];
|
$config_mail_from_email = $row['config_mail_from_email'];
|
||||||
$config_mail_from_name = $row['config_mail_from_name'];
|
$config_mail_from_name = $row['config_mail_from_name'];
|
||||||
|
|
||||||
// Mail - IMAP
|
// Mail - IMAP
|
||||||
$config_imap_host = $row['config_imap_host'];
|
$config_imap_host = $row['config_imap_host'];
|
||||||
$config_imap_port = intval($row['config_imap_port']);
|
$config_imap_port = intval($row['config_imap_port']);
|
||||||
@@ -128,7 +129,6 @@ $config_time_format = "H:i";
|
|||||||
|
|
||||||
// Theme
|
// Theme
|
||||||
$config_theme = $row['config_theme'];
|
$config_theme = $row['config_theme'];
|
||||||
$config_theme_dark = intval($row['config_theme_dark']);
|
|
||||||
|
|
||||||
// Telemetry
|
// Telemetry
|
||||||
$config_telemetry = intval($row['config_telemetry']);
|
$config_telemetry = intval($row['config_telemetry']);
|
||||||
|
|||||||
@@ -6,13 +6,6 @@
|
|||||||
|
|
||||||
header("X-Frame-Options: DENY");
|
header("X-Frame-Options: DENY");
|
||||||
|
|
||||||
// Determine URI prepending logic (URI Routing maybe move to /includes/router.php)
|
|
||||||
if ($_SERVER['REQUEST_URI'] === '/user/reports') {
|
|
||||||
$prepend_uri = "../";
|
|
||||||
} else {
|
|
||||||
$prepend_uri = '';
|
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
@@ -23,7 +16,7 @@ if ($_SERVER['REQUEST_URI'] === '/user/reports') {
|
|||||||
<meta http-equiv="x-ua-compatible" content="ie=edge">
|
<meta http-equiv="x-ua-compatible" content="ie=edge">
|
||||||
<meta name="robots" content="noindex">
|
<meta name="robots" content="noindex">
|
||||||
|
|
||||||
<title><?php echo $session_company_name; ?></title>
|
<title><?= $session_company_name; ?></title>
|
||||||
|
|
||||||
<!-- Favicon -->
|
<!-- Favicon -->
|
||||||
<?php if(file_exists($prepend_uri . '../uploads/favicon.ico')): ?>
|
<?php if(file_exists($prepend_uri . '../uploads/favicon.ico')): ?>
|
||||||
@@ -51,7 +44,7 @@ if ($_SERVER['REQUEST_URI'] === '/user/reports') {
|
|||||||
<body class="
|
<body class="
|
||||||
hold-transition sidebar-mini layout-fixed layout-navbar-fixed
|
hold-transition sidebar-mini layout-fixed layout-navbar-fixed
|
||||||
accent-<?php echo isset($_GET['client_id']) ? 'blue' : nullable_htmlentities($config_theme); ?>
|
accent-<?php echo isset($_GET['client_id']) ? 'blue' : nullable_htmlentities($config_theme); ?>
|
||||||
<?php if ($config_theme_dark) echo 'dark-mode'; ?>
|
<?php if ($user_config_theme_dark) echo 'dark-mode'; ?>
|
||||||
">
|
">
|
||||||
<div class="wrapper text-sm">
|
<div class="wrapper text-sm">
|
||||||
|
|
||||||
|
|||||||
11
includes/router.php
Normal file
11
includes/router.php
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
// URI Router
|
||||||
|
// Currently unused, but the idea is to dynamically prepend ../../ to asset paths (like includes, libraries, etc.)
|
||||||
|
// based on the current directory depth. This allows us to support deeply nested folder structures.
|
||||||
|
|
||||||
|
if ($_SERVER['REQUEST_URI'] === '/user/reports') {
|
||||||
|
$prepend_uri = "../";
|
||||||
|
} else {
|
||||||
|
$prepend_uri = '';
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
require_once "../config.php";
|
require_once "../config.php";
|
||||||
require_once "../functions.php";
|
require_once "../functions.php";
|
||||||
|
require_once "../includes/router.php";
|
||||||
require_once "../includes/check_login.php";
|
require_once "../includes/check_login.php";
|
||||||
require_once "../includes/page_title.php";
|
require_once "../includes/page_title.php";
|
||||||
require_once "../includes/header.php";
|
require_once "../includes/header.php";
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
require_once "../config.php";
|
require_once "../config.php";
|
||||||
require_once "../functions.php";
|
require_once "../functions.php";
|
||||||
|
require_once "../includes/router.php";
|
||||||
require_once "../includes/check_login.php";
|
require_once "../includes/check_login.php";
|
||||||
require_once "../includes/page_title.php";
|
require_once "../includes/page_title.php";
|
||||||
// Reporting Perms
|
// Reporting Perms
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
require_once "../config.php";
|
require_once "../config.php";
|
||||||
require_once "../functions.php";
|
require_once "../functions.php";
|
||||||
|
require_once "../includes/router.php";
|
||||||
require_once "../includes/check_login.php";
|
require_once "../includes/check_login.php";
|
||||||
require_once "../includes/page_title.php";
|
require_once "../includes/page_title.php";
|
||||||
require_once "../includes/header.php";
|
require_once "../includes/header.php";
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
require_once "../config.php";
|
require_once "../config.php";
|
||||||
require_once "../functions.php";
|
require_once "../functions.php";
|
||||||
|
require_once "../includes/router.php";
|
||||||
require_once "../includes/check_login.php";
|
require_once "../includes/check_login.php";
|
||||||
require_once "../includes/page_title.php";
|
require_once "../includes/page_title.php";
|
||||||
require_once "../includes/header.php";
|
require_once "../includes/header.php";
|
||||||
|
|||||||
@@ -157,10 +157,11 @@ if (isset($_POST['edit_your_user_preferences'])) {
|
|||||||
validateCSRFToken($_POST['csrf_token']);
|
validateCSRFToken($_POST['csrf_token']);
|
||||||
|
|
||||||
$calendar_first_day = intval($_POST['calendar_first_day']);
|
$calendar_first_day = intval($_POST['calendar_first_day']);
|
||||||
|
$dark_mode = intval($_POST['dark_mode'] ?? 0);
|
||||||
|
|
||||||
// Calendar
|
// Calendar
|
||||||
if (isset($calendar_first_day)) {
|
if (isset($calendar_first_day)) {
|
||||||
mysqli_query($mysqli, "UPDATE user_settings SET user_config_calendar_first_day = $calendar_first_day WHERE user_id = $session_user_id");
|
mysqli_query($mysqli, "UPDATE user_settings SET user_config_calendar_first_day = $calendar_first_day, user_config_theme_dark = $dark_mode WHERE user_id = $session_user_id");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enable extension access, only if it isn't already setup (user doesn't have cookie)
|
// Enable extension access, only if it isn't already setup (user doesn't have cookie)
|
||||||
|
|||||||
@@ -15,6 +15,21 @@ $user_config_calendar_first_day = intval($row['user_config_calendar_first_day'])
|
|||||||
<form action="post.php" method="post" enctype="multipart/form-data" autocomplete="off">
|
<form action="post.php" method="post" enctype="multipart/form-data" autocomplete="off">
|
||||||
<input type="hidden" name="csrf_token" value="<?php echo $_SESSION['csrf_token'] ?>">
|
<input type="hidden" name="csrf_token" value="<?php echo $_SESSION['csrf_token'] ?>">
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<h5>Dark Mode</h5>
|
||||||
|
|
||||||
|
<div class="btn-group btn-group-toggle" data-toggle="buttons">
|
||||||
|
<label class="btn btn-outline-primary <?php if ($user_config_theme_dark === 0) { echo "active"; } ?>">
|
||||||
|
<input type="radio" name="dark_mode" id="light-mode" autocomplete="off" <?php if ($user_config_theme_dark === 0) { echo "checked"; } ?>>
|
||||||
|
<i class="fas fa-sun mr-2"></i>Light
|
||||||
|
</label>
|
||||||
|
<label class="btn btn-outline-dark <?php if ($user_config_theme_dark === 1) { echo "active"; } ?>">
|
||||||
|
<input type="radio" name="dark_mode" id="dark-mode" autocomplete="off" value="1" <?php if ($user_config_theme_dark === 1) { echo "checked"; } ?>>
|
||||||
|
<i class="fas fa-moon mr-2"></i>Dark
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label>Calendar starts on<strong class="text-danger">*</strong></label>
|
<label>Calendar starts on<strong class="text-danger">*</strong></label>
|
||||||
<div class="input-group">
|
<div class="input-group">
|
||||||
|
|||||||
Reference in New Issue
Block a user