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";
}
+3
View File
@@ -0,0 +1,3 @@
</main>
</body>
</html>
+15
View File
@@ -0,0 +1,15 @@
<?php
$pageTitle = $pageTitle ?? "Delivery";
$basePath = $basePath ?? "..";
?>
<!DOCTYPE html>
<html lang="it">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?= e($pageTitle) ?> - Delivery</title>
<link rel="stylesheet" href="<?= e($basePath) ?>/css/bootstrap.min.css">
</head>
<body class="bg-light">
<?php require __DIR__ . "/navbar.php"; ?>
<main class="container py-4">
+33
View File
@@ -0,0 +1,33 @@
<?php
$ruolo = $_SESSION["ruolo"] ?? null;
$links = [
"cliente" => [
"Dashboard" => "cliente/dashboard.php", "Menu" => "cliente/menu.php",
"Nuovo ordine" => "cliente/ordine.php", "I miei ordini" => "cliente/miei_ordini.php",
"Preferiti" => "cliente/preferiti.php", "Indirizzi" => "cliente/indirizzi.php",
],
"personale" => [
"Dashboard" => "personale/dashboard.php", "Ordini" => "personale/ordini.php",
],
"proprietario" => [
"Dashboard" => "proprietario/dashboard.php", "Ordini" => "proprietario/ordini.php",
"Prodotti" => "proprietario/prodotti.php", "Caratteristiche" => "proprietario/caratteristiche.php",
"Menu" => "proprietario/menu.php", "Personale" => "proprietario/personale.php",
"Statistiche" => "proprietario/statistiche.php",
],
];
?>
<nav class="navbar navbar-dark bg-dark">
<div class="container d-flex flex-wrap gap-2">
<a class="navbar-brand" href="<?= e($basePath) ?>/dashboard.php">Delivery</a>
<?php if ($ruolo && isset($links[$ruolo])): ?>
<div class="d-flex flex-wrap gap-2 me-auto">
<?php foreach ($links[$ruolo] as $label => $url): ?>
<a class="btn btn-sm btn-outline-light" href="<?= e($basePath . "/" . $url) ?>"><?= e($label) ?></a>
<?php endforeach; ?>
</div>
<span class="navbar-text text-white me-2"><?= e($_SESSION["nome"] ?? "") ?> (<?= e($ruolo) ?>)</span>
<a class="btn btn-sm btn-danger" href="<?= e($basePath) ?>/logout.php">Esci</a>
<?php endif; ?>
</div>
</nav>