Compare commits

...

12 Commits

15 changed files with 789 additions and 46 deletions

View File

@ -13,6 +13,8 @@ All notable changes to this project will be documented in this file.
- gitlab: https://gitlab.com/lindeas/jilo-web/-/compare/v0.4...HEAD
### Added
- Added CSS and JS to the default theme
- Added change theme menu entry
### Changed

View File

@ -6,6 +6,15 @@
* Core session management functionality for the application
*/
class Session {
private static $initialized = false;
private static $sessionName = ''; // Will be set from config, if not we'll have a random session name
/**
* Generate a random session name
*/
private static function generateRandomSessionName(): string {
return 'sess_' . bin2hex(random_bytes(8)); // 16-character random string
}
private static $sessionOptions = [
'cookie_httponly' => 1,
'cookie_secure' => 1,
@ -13,12 +22,45 @@ class Session {
'gc_maxlifetime' => 7200 // 2 hours
];
/**
* Initialize session configuration
*/
private static function initialize() {
if (self::$initialized) {
return;
}
global $config;
// Load session settings from config if available
self::$sessionName = self::generateRandomSessionName();
if (isset($config['session']) && is_array($config['session'])) {
if (!empty($config['session']['name'])) {
self::$sessionName = $config['session']['name'];
}
if (isset($config['session']['lifetime'])) {
self::$sessionOptions['gc_maxlifetime'] = (int)$config['session']['lifetime'];
}
}
self::$initialized = true;
}
/**
* Start or resume a session with secure options
*/
public static function startSession() {
session_name('jilo');
if (session_status() !== PHP_SESSION_ACTIVE && !headers_sent()) {
self::initialize();
if (session_status() === PHP_SESSION_NONE) {
session_name(self::$sessionName);
session_start(self::$sessionOptions);
} elseif (session_status() === PHP_SESSION_ACTIVE && session_name() !== self::$sessionName) {
// If session is active but with wrong name, destroy and restart it
session_destroy();
session_name(self::$sessionName);
session_start(self::$sessionOptions);
}
}

View File

@ -10,8 +10,17 @@ return [
'domain' => 'localhost',
// subfolder for the web app, if any
'folder' => '/jilo-web/',
// site name used in emails and in the inteerface
// site name used in emails and in the interface
'site_name' => 'Jilo Web',
// session configuration
'session' => [
// session name, if empty a random one will be generated
'name' => 'jilo',
// 2 hours (7200) default, when "remember me" is not checked
'lifetime' => 7200,
// 30 days (2592000) default, when "remember me" is checked
'remember_me_lifetime' => 2592000,
],
// set to false to disable new registrations
'registration_enabled' => true,
// will be displayed on login screen

View File

@ -7,7 +7,8 @@ return [
// Available themes with their display names
'available_themes' => [
'default' => 'Default built-in theme',
'modern' => 'Modern Theme'
'modern' => 'Modern theme',
'retro' => 'Alternative retro theme'
],
// Path configurations

View File

@ -12,6 +12,10 @@ namespace App\Helpers;
use Exception;
// Include Session class
require_once __DIR__ . '/../classes/session.php';
use Session;
class Theme
{
/**
@ -19,6 +23,18 @@ class Theme
*/
private static $config;
/**
* Get the theme configuration
*
* @return array
*/
public static function getConfig()
{
// Always reload the config to get the latest changes
self::$config = require __DIR__ . '/../config/theme.php';
return self::$config;
}
/**
* @var string Current theme name
*/
@ -29,7 +45,10 @@ class Theme
*/
public static function init()
{
self::$config = require __DIR__ . '/../config/theme.php';
// Only load config if not already loaded
if (self::$config === null) {
self::$config = require __DIR__ . '/../config/theme.php';
}
self::$currentTheme = self::getCurrentThemeName();
}
@ -40,13 +59,19 @@ class Theme
*/
public static function getCurrentThemeName()
{
// Ensure session is started
if (session_status() === PHP_SESSION_NONE) {
Session::startSession();
}
// Check if already determined
if (self::$currentTheme !== null) {
return self::$currentTheme;
}
// Get from session if available
if (Session::isValidSession() && ($theme = Session::get('user_theme'))) {
if (Session::isValidSession() && isset($_SESSION['user_theme'])) {
$theme = $_SESSION['user_theme'];
if (self::themeExists($theme)) {
self::$currentTheme = $theme;
return $theme;
@ -70,11 +95,33 @@ class Theme
return false;
}
// Update session
if (Session::isValidSession()) {
Session::set('user_theme', $themeName);
$_SESSION['user_theme'] = $themeName;
} else {
return false;
}
self::$currentTheme = $themeName;
// Update config file
$configFile = __DIR__ . '/../config/theme.php';
if (file_exists($configFile) && is_writable($configFile)) {
$config = file_get_contents($configFile);
// Update the active_theme in the config
$newConfig = preg_replace(
"/'active_theme'\s*=>\s*'[^']*'/",
"'active_theme' => '" . addslashes($themeName) . "'",
$config
);
if ($newConfig !== $config) {
if (file_put_contents($configFile, $newConfig) === false) {
return false;
}
}
self::$currentTheme = $themeName;
return true;
}
return false;
return true;
}
@ -86,6 +133,11 @@ class Theme
*/
public static function themeExists(string $themeName): bool
{
// Default theme always exists as it uses core templates
if ($themeName === 'default') {
return true;
}
$themePath = self::getThemePath($themeName);
return is_dir($themePath) && file_exists("$themePath/config.php");
}
@ -134,41 +186,35 @@ class Theme
}
/**
* Include a theme template
* Include a theme template file
*
* @param string $template
* @param array $data
* @param string $template Template name without .php extension
* @return void
*/
public static function include($template, $data = [])
public static function include($template)
{
$themeName = self::getCurrentThemeName();
$config = self::getConfig();
// For non-default themes, look in the theme directory
// Import all global variables into local scope
// We need this here, otherwise because this helper
// between index and the views breaks the session vars
extract($GLOBALS, EXTR_SKIP | EXTR_REFS);
// For non-default themes, look in the theme directory first
if ($themeName !== 'default') {
$themePath = $config['paths']['themes'] . '/' . $themeName . '/views/' . $template . '.php';
if (file_exists($themePath)) {
extract($data);
include $themePath;
return;
}
}
// Fallback to default theme if template not found in custom theme
$legacyPath = $config['paths']['templates'] . '/' . $template . '.php';
if (file_exists($legacyPath)) {
extract($data);
include $legacyPath;
return;
}
} else {
// Default theme uses app/templates
$legacyPath = $config['paths']['templates'] . '/' . $template . '.php';
if (file_exists($legacyPath)) {
extract($data);
include $legacyPath;
return;
}
// Fallback to default template location
$defaultPath = $config['paths']['templates'] . '/' . $template . '.php';
if (file_exists($defaultPath)) {
include $defaultPath;
return;
}
// Log error if template not found
@ -182,22 +228,20 @@ class Theme
*/
public static function getAvailableThemes(): array
{
$config = self::getConfig();
$availableThemes = $config['available_themes'] ?? [];
$themes = [];
$themesDir = self::$config['path'] ?? (__DIR__ . '/../../themes');
if (!is_dir($themesDir)) {
return [];
// Add default theme if not already present
if (!isset($availableThemes['default'])) {
$availableThemes['default'] = 'Default built-in theme';
}
foreach (scandir($themesDir) as $item) {
if ($item === '.' || $item === '..' || !is_dir("$themesDir/$item")) {
continue;
}
$configFile = "$themesDir/$item/config.php";
if (file_exists($configFile)) {
$config = include $configFile;
$themes[$item] = $config['name'] ?? ucfirst($item);
// Verify each theme exists and has a config file
$themesDir = $config['paths']['themes'] ?? (__DIR__ . '/../../themes');
foreach ($availableThemes as $id => $name) {
if ($id === 'default' || (is_dir("$themesDir/$id") && file_exists("$themesDir/$id/config.php"))) {
$themes[$id] = $name;
}
}

View File

@ -9,6 +9,10 @@
* - switch_to: Changes the active theme for the current user
*/
// Initialize security
require_once '../app/helpers/security.php';
$security = SecurityHelper::getInstance();
// Only allow access to logged-in users
if (!Session::isValidSession()) {
header('Location: ' . $app_root . '?page=login');
@ -20,9 +24,6 @@ if (isset($_GET['switch_to'])) {
$themeName = $_GET['switch_to'];
// Validate CSRF token for state-changing operations
require_once '../app/helpers/security.php';
$security = SecurityHelper::getInstance();
if (!$security->verifyCsrfToken($_GET['csrf_token'] ?? '')) {
Feedback::flash('SECURITY', 'CSRF_INVALID');
header("Location: $app_root?page=theme");

View File

@ -15,7 +15,7 @@
</div>
<li class="font-weight-light text-uppercase" style="font-size: 0.5em; color: whitesmoke; margin-right: 70px; align-content: center;">
version&nbsp;<?= htmlspecialchars($config['version']) ?>
version&nbsp;<?= htmlspecialchars($config['version'] ?? '1.0.0') ?>
</li>
<?php if (Session::isValidSession()) { ?>
@ -47,6 +47,10 @@
</a>
<div class="dropdown-menu dropdown-menu-right">
<h6 class="dropdown-header"><?= htmlspecialchars($currentUser) ?></h6>
<a class="dropdown-item" href="<?= htmlspecialchars($app_root) ?>?page=theme">
<i class="fas fa-paint-brush"></i>Change theme
</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="<?= htmlspecialchars($app_root) ?>?page=profile">
<i class="fas fa-id-card"></i>Profile details
</a>

View File

@ -24,7 +24,7 @@
<p class="card-text text-muted">Theme ID: <code><?= htmlspecialchars($themeId) ?></code></p>
<div class="mt-auto">
<?php if (!$isActive) { ?>
<a href="?page=theme&switch_to=<?= urlencode($themeId) ?>" class="btn btn-primary">Switch to this theme</a>
<a href="?page=theme&switch_to=<?= urlencode($themeId) ?>&csrf_token=<?= $csrf_token ?>" class="btn btn-primary">Switch to this theme</a>
<?php } else { ?>
<button class="btn btn-outline-secondary" disabled>Currently active</button>
<?php } ?>

View File

@ -0,0 +1,180 @@
/* Modern Theme Styles */
:root {
--primary-color: #4361ee;
--secondary-color: #3f37c9;
--accent-color: #4895ef;
--light-color: #f8f9fa;
--dark-color: #212529;
--success-color: #4bb543;
--warning-color: #f9c74f;
--danger-color: #ef476f;
--border-radius: 0.5rem;
}
/* General Styles */
body.modern-theme {
background-color: #f5f7fa;
color: #333;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
/* Navigation */
.menu-container {
background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
padding: 0.5rem 1rem;
}
.menu-left {
display: flex;
align-items: center;
}
.menu-right {
display: flex;
align-items: center;
justify-content: flex-end;
}
/* Cards */
.card {
border: none;
border-radius: var(--border-radius);
box-shadow: 0 2px 15px rgba(0, 0, 0, 0.05);
transition: transform 0.2s, box-shadow 0.2s;
margin-bottom: 1.5rem;
}
.card:hover {
transform: translateY(-2px);
box-shadow: 0 5px 20px rgba(0, 0, 0, 0.1);
}
.card-header {
background-color: white;
border-bottom: 1px solid rgba(0, 0, 0, 0.05);
font-weight: 600;
}
/* Buttons */
.btn-primary {
background-color: var(--primary-color);
border-color: var(--primary-color);
border-radius: var(--border-radius);
padding: 0.375rem 1rem;
font-weight: 500;
transition: all 0.2s;
}
.btn-primary:hover {
background-color: var(--secondary-color);
border-color: var(--secondary-color);
transform: translateY(-1px);
}
/* Forms */
.form-control {
border-radius: var(--border-radius);
border: 1px solid #e1e5eb;
padding: 0.5rem 0.75rem;
}
.form-control:focus {
border-color: var(--accent-color);
box-shadow: 0 0 0 0.2rem rgba(67, 97, 238, 0.25);
}
/* Tables */
.table {
background-color: white;
border-radius: var(--border-radius);
overflow: hidden;
}
.table thead th {
background-color: #f8f9fa;
border-bottom: 2px solid #e9ecef;
font-weight: 600;
text-transform: uppercase;
font-size: 0.75rem;
letter-spacing: 0.5px;
}
/* Alerts */
.alert {
border-radius: var(--border-radius);
border: none;
padding: 1rem 1.25rem;
}
.alert-success {
background-color: rgba(75, 181, 67, 0.1);
color: var(--success-color);
}
.alert-warning {
background-color: rgba(249, 199, 79, 0.1);
color: #c9a227;
}
.alert-danger {
background-color: rgba(239, 71, 111, 0.1);
color: var(--danger-color);
}
/* Theme Switcher */
.theme-switcher {
margin-left: 1rem;
}
.theme-switcher .dropdown-toggle {
background: rgba(255, 255, 255, 0.1);
border: none;
border-radius: 50%;
width: 36px;
height: 36px;
display: flex;
align-items: center;
justify-content: center;
color: white;
transition: all 0.2s;
}
.theme-switcher .dropdown-toggle:hover {
background: rgba(255, 255, 255, 0.2);
}
.theme-option {
display: flex;
align-items: center;
padding: 0.5rem 1rem;
cursor: pointer;
transition: background-color 0.2s;
}
.theme-option:hover {
background-color: rgba(0, 0, 0, 0.05);
}
.theme-preview {
width: 20px;
height: 20px;
border-radius: 4px;
margin-right: 10px;
border: 1px solid rgba(0, 0, 0, 0.1);
}
/* Responsive adjustments */
@media (max-width: 768px) {
.menu-container {
flex-direction: column;
padding: 0.5rem;
}
.menu-left, .menu-right {
width: 100%;
justify-content: space-between;
padding: 0.25rem 0;
}
}

View File

@ -0,0 +1,81 @@
/**
* Modern Theme JavaScript
*
* This file contains theme-specific JavaScript functionality.
*/
document.addEventListener('DOMContentLoaded', function() {
// Initialize tooltips
$('[data-toggle="tooltip"]').tooltip();
// Initialize popovers
$('[data-toggle="popover"]').popover();
// Add smooth scrolling to anchor links
$('a[href^="#"]').on('click', function(e) {
if (this.hash !== '') {
e.preventDefault();
const hash = this.hash;
$('html, body').animate(
{ scrollTop: $(hash).offset().top - 20 },
800
);
}
});
// Handle form validation feedback
$('form.needs-validation').on('submit', function(event) {
if (this.checkValidity() === false) {
event.preventDefault();
event.stopPropagation();
}
$(this).addClass('was-validated');
});
// Add active class to current nav item
const currentPage = window.location.pathname.split('/').pop() || 'index.php';
$('.nav-link').each(function() {
if ($(this).attr('href') === currentPage) {
$(this).addClass('active');
$(this).closest('.nav-item').addClass('active');
}
});
// Handle sidebar toggle
const sidebarToggle = document.querySelector('.sidebar-toggle');
if (sidebarToggle) {
sidebarToggle.addEventListener('click', function() {
document.documentElement.classList.toggle('sidebar-collapsed');
localStorage.setItem('sidebarState',
document.documentElement.classList.contains('sidebar-collapsed') ? 'collapsed' : 'expanded');
});
}
// Handle dropdown menus
$('.dropdown-menu a.dropdown-toggle').on('click', function(e) {
if (!$(this).next().hasClass('show')) {
$(this).parents('.dropdown-menu').first().find('.show').removeClass('show');
}
const $subMenu = $(this).next('.dropdown-menu');
$subMenu.toggleClass('show');
$(this).parents('li.nav-item.dropdown.show').on('hidden.bs.dropdown', function() {
$('.dropdown-submenu .show').removeClass('show');
});
return false;
});
});
// Theme switcher functionality
function setTheme(themeName) {
localStorage.setItem('theme', themeName);
document.documentElement.className = themeName;
}
// Immediately-invoked function to set the theme on initial load
(function () {
const savedTheme = localStorage.getItem('theme') || 'light-theme';
setTheme(savedTheme);
})();

View File

@ -0,0 +1,180 @@
/* Retro Theme Styles */
:root {
--primary-color: #4361ee;
--secondary-color: #3f37c9;
--accent-color: #4895ef;
--light-color: #f8f9fa;
--dark-color: #212529;
--success-color: #4bb543;
--warning-color: #f9c74f;
--danger-color: #ef476f;
--border-radius: 0.5rem;
}
/* General Styles */
body.modern-theme {
background-color: #f5f7fa;
color: #333;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
/* Navigation */
.menu-container {
background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
padding: 0.5rem 1rem;
}
.menu-left {
display: flex;
align-items: center;
}
.menu-right {
display: flex;
align-items: center;
justify-content: flex-end;
}
/* Cards */
.card {
border: none;
border-radius: var(--border-radius);
box-shadow: 0 2px 15px rgba(0, 0, 0, 0.05);
transition: transform 0.2s, box-shadow 0.2s;
margin-bottom: 1.5rem;
}
.card:hover {
transform: translateY(-2px);
box-shadow: 0 5px 20px rgba(0, 0, 0, 0.1);
}
.card-header {
background-color: white;
border-bottom: 1px solid rgba(0, 0, 0, 0.05);
font-weight: 600;
}
/* Buttons */
.btn-primary {
background-color: var(--primary-color);
border-color: var(--primary-color);
border-radius: var(--border-radius);
padding: 0.375rem 1rem;
font-weight: 500;
transition: all 0.2s;
}
.btn-primary:hover {
background-color: var(--secondary-color);
border-color: var(--secondary-color);
transform: translateY(-1px);
}
/* Forms */
.form-control {
border-radius: var(--border-radius);
border: 1px solid #e1e5eb;
padding: 0.5rem 0.75rem;
}
.form-control:focus {
border-color: var(--accent-color);
box-shadow: 0 0 0 0.2rem rgba(67, 97, 238, 0.25);
}
/* Tables */
.table {
background-color: white;
border-radius: var(--border-radius);
overflow: hidden;
}
.table thead th {
background-color: #f8f9fa;
border-bottom: 2px solid #e9ecef;
font-weight: 600;
text-transform: uppercase;
font-size: 0.75rem;
letter-spacing: 0.5px;
}
/* Alerts */
.alert {
border-radius: var(--border-radius);
border: none;
padding: 1rem 1.25rem;
}
.alert-success {
background-color: rgba(75, 181, 67, 0.1);
color: var(--success-color);
}
.alert-warning {
background-color: rgba(249, 199, 79, 0.1);
color: #c9a227;
}
.alert-danger {
background-color: rgba(239, 71, 111, 0.1);
color: var(--danger-color);
}
/* Theme Switcher */
.theme-switcher {
margin-left: 1rem;
}
.theme-switcher .dropdown-toggle {
background: rgba(255, 255, 255, 0.1);
border: none;
border-radius: 50%;
width: 36px;
height: 36px;
display: flex;
align-items: center;
justify-content: center;
color: white;
transition: all 0.2s;
}
.theme-switcher .dropdown-toggle:hover {
background: rgba(255, 255, 255, 0.2);
}
.theme-option {
display: flex;
align-items: center;
padding: 0.5rem 1rem;
cursor: pointer;
transition: background-color 0.2s;
}
.theme-option:hover {
background-color: rgba(0, 0, 0, 0.05);
}
.theme-preview {
width: 20px;
height: 20px;
border-radius: 4px;
margin-right: 10px;
border: 1px solid rgba(0, 0, 0, 0.1);
}
/* Responsive adjustments */
@media (max-width: 768px) {
.menu-container {
flex-direction: column;
padding: 0.5rem;
}
.menu-left, .menu-right {
width: 100%;
justify-content: space-between;
padding: 0.25rem 0;
}
}

View File

@ -0,0 +1,81 @@
/**
* Retro Theme JavaScript
*
* This file contains theme-specific JavaScript functionality.
*/
document.addEventListener('DOMContentLoaded', function() {
// Initialize tooltips
$('[data-toggle="tooltip"]').tooltip();
// Initialize popovers
$('[data-toggle="popover"]').popover();
// Add smooth scrolling to anchor links
$('a[href^="#"]').on('click', function(e) {
if (this.hash !== '') {
e.preventDefault();
const hash = this.hash;
$('html, body').animate(
{ scrollTop: $(hash).offset().top - 20 },
800
);
}
});
// Handle form validation feedback
$('form.needs-validation').on('submit', function(event) {
if (this.checkValidity() === false) {
event.preventDefault();
event.stopPropagation();
}
$(this).addClass('was-validated');
});
// Add active class to current nav item
const currentPage = window.location.pathname.split('/').pop() || 'index.php';
$('.nav-link').each(function() {
if ($(this).attr('href') === currentPage) {
$(this).addClass('active');
$(this).closest('.nav-item').addClass('active');
}
});
// Handle sidebar toggle
const sidebarToggle = document.querySelector('.sidebar-toggle');
if (sidebarToggle) {
sidebarToggle.addEventListener('click', function() {
document.documentElement.classList.toggle('sidebar-collapsed');
localStorage.setItem('sidebarState',
document.documentElement.classList.contains('sidebar-collapsed') ? 'collapsed' : 'expanded');
});
}
// Handle dropdown menus
$('.dropdown-menu a.dropdown-toggle').on('click', function(e) {
if (!$(this).next().hasClass('show')) {
$(this).parents('.dropdown-menu').first().find('.show').removeClass('show');
}
const $subMenu = $(this).next('.dropdown-menu');
$subMenu.toggleClass('show');
$(this).parents('li.nav-item.dropdown.show').on('hidden.bs.dropdown', function() {
$('.dropdown-submenu .show').removeClass('show');
});
return false;
});
});
// Theme switcher functionality
function setTheme(themeName) {
localStorage.setItem('theme', themeName);
document.documentElement.className = themeName;
}
// Immediately-invoked function to set the theme on initial load
(function () {
const savedTheme = localStorage.getItem('theme') || 'light-theme';
setTheme(savedTheme);
})();

View File

@ -0,0 +1,12 @@
<?php
return [
'name' => 'Retro theme',
'description' => 'Example theme. An alternative to the default theme for Jilo Web.',
'version' => '1.0.0',
'author' => 'Lindeas Inc.',
'screenshot' => 'screenshot.png',
'options' => [
// Theme-specific options can be defined here
]
];

View File

@ -0,0 +1,31 @@
<!-- Retro Theme Footer -->
<footer class="footer mt-5 py-3 bg-light">
<div class="container">
<div class="row">
<div class="col-md-6">
<span class="text-muted">
&copy; <?= date('Y') ?> <?= htmlspecialchars($config['site_name'] ?? '') ?> v<?= htmlspecialchars($config['version'] ?? '') ?>
</span>
</div>
<div class="col-md-6 text-md-end">
<span class="text-muted">
<?= htmlspecialchars($themeName ?? 'Modern Theme') ?>
</span>
</div>
</div>
</div>
</footer>
<!-- Theme-specific JavaScript -->
<script src="<?= \App\Helpers\Theme::asset('js/theme.js') ?>"></script>
<!-- Global site scripts -->
<script src="<?= htmlspecialchars($app_root) ?>static/js/messages.js"></script>
<?php if ($page === 'graphs'): ?>
<script src="<?= htmlspecialchars($app_root) ?>static/js/graphs.js"></script>
<?php endif; ?>
<?php do_hook('footer_scripts'); ?>
</body>
</html>

View File

@ -0,0 +1,75 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?= htmlspecialchars($config['site_name'] ?? '') ?> - <?= htmlspecialchars($pageTitle ?? 'Dashboard') ?></title>
<!-- Bootstrap 5.3.3 CSS -->
<link rel="stylesheet" type="text/css" href="<?= htmlspecialchars($app_root) ?>static/libs/bootstrap/bootstrap-5.3.3.min.css">
<!-- Font Awesome -->
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.0/css/all.css">
<!-- Custom CSS -->
<link rel="stylesheet" type="text/css" href="<?= htmlspecialchars($app_root) ?>static/css/main.css">
<!-- Theme-specific CSS -->
<link rel="stylesheet" type="text/css" href="<?= \App\Helpers\Theme::asset('css/theme.css') ?>">
<!-- jQuery -->
<script src="<?= htmlspecialchars($app_root) ?>static/libs/jquery/jquery.min.js"></script>
<!-- Bootstrap JS -->
<script src="<?= htmlspecialchars($app_root) ?>static/libs/bootstrap/popper.min.js"></script>
<script src="<?= htmlspecialchars($app_root) ?>static/libs/bootstrap/bootstrap-4.0.0.min.js"></script>
<?php if (Session::getUsername()): ?>
<script>
// Restore sidebar state before the page is rendered
(function() {
var savedState = localStorage.getItem('sidebarState');
if (savedState === 'collapsed') {
document.documentElement.classList.add('sidebar-collapsed');
}
})();
</script>
<?php endif; ?>
<!-- Page-specific CSS -->
<?php if ($page === 'logs'): ?>
<link rel="stylesheet" type="text/css" href="<?= htmlspecialchars($app_root) ?>static/css/logs.css">
<?php endif; ?>
<?php if ($page === 'profile'): ?>
<link rel="stylesheet" type="text/css" href="<?= htmlspecialchars($app_root) ?>static/css/profile.css">
<?php endif; ?>
<?php if ($page === 'agents'): ?>
<script src="<?= htmlspecialchars($app_root) ?>static/js/agents.js"></script>
<?php endif; ?>
<?php if ($page === 'graphs'): ?>
<script src="<?= htmlspecialchars($app_root) ?>static/libs/chartjs/chart.umd.min.js"></script>
<script src="<?= htmlspecialchars($app_root) ?>static/libs/chartjs/moment.min.js"></script>
<script src="<?= htmlspecialchars($app_root) ?>static/libs/chartjs/chartjs-adapter-moment.min.js"></script>
<script src="<?= htmlspecialchars($app_root) ?>static/libs/chartjs/chartjs-plugin-zoom.min.js"></script>
<?php endif; ?>
<link rel="icon" type="image/x-icon" href="<?= htmlspecialchars($app_root) ?>static/favicon.ico">
</head>
<body class="modern-theme">
<div id="messages-container" class="container-fluid mt-2"></div>
<?php if (isset($system_messages) && is_array($system_messages)): ?>
<div class="container-fluid">
<div class="row">
<div class="col">
<?php foreach ($system_messages as $msg): ?>
<?= Feedback::render($msg['category'], $msg['key'], $msg['custom_message'] ?? null) ?>
<?php endforeach; ?>
</div>
</div>
</div>
<?php endif; ?>