first commit

This commit is contained in:
Emanuele Slusarz
2026-08-22 11:15:29 +02:00
commit ec30fb40b9
38 changed files with 3723 additions and 0 deletions
+46
View File
@@ -0,0 +1,46 @@
<?php
if (session_status() !== PHP_SESSION_ACTIVE) {
session_start();
}
function requireLogin(): void
{
if (empty($_SESSION["idUtente"])) {
$cartellaScript = basename(dirname($_SERVER["SCRIPT_NAME"] ?? ""));
$login = $cartellaScript === "PHP" ? "index.php" : "../index.php";
header("Location: " . $login . "?errore=accesso");
exit;
}
}
function requireRole(string $ruolo): void
{
requireLogin();
if (($_SESSION["ruolo"] ?? null) !== $ruolo) {
header("Location: ../dashboard.php?errore=autorizzazione");
exit;
}
}
function dashboardForRole(?string $ruolo): string
{
$destinazioni = [
"cliente" => "cliente/dashboard.php",
"personale" => "personale/dashboard.php",
"proprietario" => "proprietario/dashboard.php",
];
return $destinazioni[$ruolo] ?? "index.php";
}
function e(mixed $valore): string
{
return htmlspecialchars((string) $valore, ENT_QUOTES, "UTF-8");
}
function postMethod(): bool
{
return ($_SERVER["REQUEST_METHOD"] ?? "GET") === "POST";
}