first commit
This commit is contained in:
Executable
+46
@@ -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";
|
||||
}
|
||||
Executable
+3
@@ -0,0 +1,3 @@
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
Executable
+15
@@ -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">
|
||||
Executable
+33
@@ -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>
|
||||
Reference in New Issue
Block a user