132 lines
3.9 KiB
PHP
132 lines
3.9 KiB
PHP
<?php
|
|
|
|
function error_env($option) {
|
|
global $env;
|
|
|
|
if (empty($env)) {
|
|
$result = "<p class='err_env_result'><span>ERROR:</span> Variable '<u>\$env</u>' is empty!</p>";
|
|
$help = "<p class='err_env_help'>Please insert the correct value in the file 'config/init.php' or leave it to 'generic'</p>";
|
|
} else {
|
|
$result = "<p class='err_env_result'><span>ERROR:</span> The environment '<u>{$env}</u>' does not exist!</p>";
|
|
$help = "<p class='err_env_help'>Please insert the correct value in the file 'config/init.php' or leave it to 'generic'</p>";
|
|
}
|
|
|
|
echo $option === "result" ? $result : $help;
|
|
}
|
|
|
|
|
|
/**
|
|
* Get current page safely.
|
|
*/
|
|
function get_current_page() {
|
|
$page = $_GET["page"] ?? "home";
|
|
|
|
$page = strtolower(trim($page));
|
|
$page = preg_replace("/[^a-z0-9\-]/", "", $page);
|
|
|
|
if ($page === "") {
|
|
$page = "home";
|
|
}
|
|
|
|
return $page;
|
|
}
|
|
|
|
|
|
/**
|
|
* Resolve page file.
|
|
*/
|
|
function resolve_page() {
|
|
$page = get_current_page();
|
|
$file = PAGES_FOLD . $page . ".php";
|
|
|
|
// 👉 rendi disponibile globalmente
|
|
$GLOBALS["current_page"] = $page;
|
|
|
|
if (file_exists($file)) {
|
|
return $file;
|
|
}
|
|
|
|
http_response_code(404);
|
|
$GLOBALS["current_page"] = "404";
|
|
return PAGES_FOLD . "404.php";
|
|
}
|
|
|
|
/**
|
|
* DEBUG FUNCTIONS AND ARRAY
|
|
*/
|
|
|
|
$debug_messages = [
|
|
'High' => [],
|
|
'Medium' => [],
|
|
'Low' => []
|
|
];
|
|
|
|
// FUNCTION TO GET DEBUG STATUS MESSAGES
|
|
function debugStatusMes( string $Message, string $intensity) {
|
|
global $debug, $debug_messages;
|
|
|
|
// Controlla se il debug è attivo
|
|
if ($debug !== "on") {
|
|
return;
|
|
}
|
|
|
|
// Normalizza l'intensità per evitare errori di battitura (es. "high" diventa "High")
|
|
$intensity = ucfirst(strtolower($intensity));
|
|
|
|
// Verifica che l'intensità sia valida prima di inserire il messaggio
|
|
if (array_key_exists($intensity, $debug_messages)) {
|
|
$debug_messages[$intensity][] = $Message;
|
|
} else {
|
|
// Se l'intensità non è corretta, la salva in una categoria generica o Low
|
|
$debug_messages['Low'][] = "[Intensità errata: $intensity] " . $Message;
|
|
}
|
|
}
|
|
|
|
// DISPLAY DEBUG ERROR BAR
|
|
function displayDebug() {
|
|
global $debug, $debug_messages;
|
|
|
|
if ($debug !== "on") {
|
|
return;
|
|
}
|
|
|
|
// Contenitore temporaneo nascosto per non creare sfarfallii nella pagina
|
|
echo '<div id="debug-source-content" style="display: none;">';
|
|
echo '<div style="background: #222; color: #fff; padding: 15px; font-family: monospace; border-bottom: 3px solid #ff4444; border-top: 3px solid #ff4444; margin-bottom: 20px;">';
|
|
echo '<h3 style="margin-bottom:5px;">⚙️ Debug Status Messages</h3>';
|
|
|
|
foreach ($debug_messages as $level => $messages) {
|
|
if (!empty($messages)) {
|
|
$color = '#6cef93';
|
|
if ($level === 'High') $color = '#ff4444';
|
|
if ($level === 'Medium') $color = '#ffbb33';
|
|
|
|
echo "<div style='margin-bottom: 10px;'>";
|
|
echo "<strong style='color: $color;'>[" . $level . "]</strong>";
|
|
echo "<ul style='margin: 5px 0; padding-left: 20px;'>";
|
|
foreach ($messages as $msg) {
|
|
echo "<li>" . htmlspecialchars($msg) . "</li>";
|
|
}
|
|
echo "</ul>";
|
|
echo "</div>";
|
|
}
|
|
}
|
|
echo '</div>';
|
|
echo '</div>';
|
|
|
|
// Questo script JS prende il contenuto appena generato e lo sposta nel segnaposto in cima
|
|
?>
|
|
<script>
|
|
document.addEventListener("DOMContentLoaded", function() {
|
|
const source = document.getElementById('debug-source-content');
|
|
const target = document.getElementById('debug-target-container');
|
|
if (source && target) {
|
|
// Sposta l'HTML dentro il contenitore all'inizio del body
|
|
target.innerHTML = source.innerHTML;
|
|
// Rimuove il vecchio elemento nascosto per pulizia
|
|
source.remove();
|
|
}
|
|
});
|
|
</script>
|
|
<?php
|
|
}
|