From bd9d3811f6481fdb237f261ff15cba0829250d0b Mon Sep 17 00:00:00 2001 From: solocla Date: Sun, 25 Jan 2026 21:22:35 +0100 Subject: [PATCH] dashboard --- public/userarea/day_off.php | 385 +++-- public/userarea/include/headscript.php | 4 +- public/userarea/include/navbar.php | 255 ++- public/userarea/onboarding_salon.php | 200 +++ public/userarea/salon_dashboard.php | 336 ++++ public/userarea/school_dashboard.php | 1982 ++++++++++++++++++++++++ 6 files changed, 2814 insertions(+), 348 deletions(-) create mode 100644 public/userarea/onboarding_salon.php create mode 100644 public/userarea/salon_dashboard.php create mode 100644 public/userarea/school_dashboard.php diff --git a/public/userarea/day_off.php b/public/userarea/day_off.php index 648d2c2..8f05b9d 100644 --- a/public/userarea/day_off.php +++ b/public/userarea/day_off.php @@ -1,258 +1,247 @@ getConnection(); -// Verifica che iduserlogin sia definito +// Verifica utente loggato if (!isset($iduserlogin)) { - die("Errore: ID utente non definito."); + header("Location: login.php"); + exit; } -// Recupera i dati della scuola in base all'utente loggato -$stmt = $pdo->prepare("SELECT id, name FROM schools WHERE owner_id = ?"); +// Controlla se esiste almeno un salone +$stmt = $pdo->prepare("SELECT COUNT(*) FROM shops WHERE owner_id = ?"); $stmt->execute([$iduserlogin]); -$school = $stmt->fetch(); -if (!$school) { - die("Errore: Nessuna scuola trovata per l'utente loggato."); +if ($stmt->fetchColumn() === 0) { + header("Location: onboarding_salon.php"); + exit; } -$school_id = $school['id']; -$school_name = $school['name']; -// Gestione delle azioni (aggiunta, modifica, cancellazione) -if ($_SERVER['REQUEST_METHOD'] === 'POST') { - if (isset($_POST['action'])) { - $action = $_POST['action']; +// Prendi il primo salone (o quello attivo – puoi aggiungere switcher dopo) +$stmt = $pdo->prepare(" + SELECT id, name + FROM shops + WHERE owner_id = ? + ORDER BY created_at ASC + LIMIT 1 +"); +$stmt->execute([$iduserlogin]); +$shop = $stmt->fetch(PDO::FETCH_ASSOC); - // Aggiunta di un giorno di chiusura - if ($action === 'add') { - $start_date = $_POST['start_date'] ?? ''; - $end_date = $_POST['end_date'] ?? ''; - $description = $_POST['description'] ?? null; +if (!$shop) { + die("Errore: salone non trovato."); +} - // Validazione: assicurarsi che end_date >= start_date - if (empty($start_date) || empty($end_date)) { - $error = "Le date di inizio e fine sono obbligatorie."; - } elseif (strtotime($end_date) < strtotime($start_date)) { - $error = "La data di fine non può essere precedente alla data di inizio."; - } else { +$shop_id = $shop['id']; +$shop_name = $shop['name']; + +// ========================================================================= +// Gestione POST (add / edit / delete) +// ========================================================================= +$success_message = ''; +$error_message = ''; + +if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) { + $action = $_POST['action']; + + if ($action === 'add' || $action === 'edit') { + $start_date = trim($_POST['start_date'] ?? ''); + $end_date = trim($_POST['end_date'] ?? ''); + $description = trim($_POST['description'] ?? ''); + $id = ($action === 'edit') ? (int)($_POST['id'] ?? 0) : 0; + + // Validazioni + if (empty($start_date) || empty($end_date)) { + $error_message = "Le date di inizio e fine sono obbligatorie."; + } elseif (strtotime($end_date) < strtotime($start_date)) { + $error_message = "La data di fine non può essere precedente alla data di inizio."; + } else { + if ($action === 'add') { $stmt = $pdo->prepare(" - INSERT INTO day_off (school_id, start_date, end_date, description) - VALUES (?, ?, ?, ?) + INSERT INTO shop_day_off (shop_id, date, title, description, is_recurring, created_at) + VALUES (?, ?, ?, ?, 0, NOW()) "); - $success = $stmt->execute([ - $school_id, - $start_date, - $end_date, - $description - ]); - - if ($success) { - $success_message = "Giorno di chiusura aggiunto con successo!"; - } else { - $error = "Errore durante l'aggiunta del giorno di chiusura."; - } - } - } - - // Modifica di un giorno di chiusura - if ($action === 'edit') { - $id = $_POST['id'] ?? 0; - $start_date = $_POST['start_date'] ?? ''; - $end_date = $_POST['end_date'] ?? ''; - $description = $_POST['description'] ?? null; - - // Validazione: assicurarsi che end_date >= start_date - if (empty($start_date) || empty($end_date)) { - $error = "Le date di inizio e fine sono obbligatorie."; - } elseif (strtotime($end_date) < strtotime($start_date)) { - $error = "La data di fine non può essere precedente alla data di inizio."; - } else { + $ok = $stmt->execute([$shop_id, $start_date, $description ?: 'Chiusura', $description]); + $success_message = $ok ? "Giorno di chiusura aggiunto!" : "Errore durante l'aggiunta."; + } else { // edit $stmt = $pdo->prepare(" - UPDATE day_off - SET start_date = ?, end_date = ?, description = ? - WHERE id = ? AND school_id = ? + UPDATE shop_day_off + SET date = ?, title = ?, description = ?, updated_at = NOW() + WHERE id = ? AND shop_id = ? "); - $success = $stmt->execute([ - $start_date, - $end_date, - $description, - $id, - $school_id - ]); - - if ($success) { - $success_message = "Giorno di chiusura aggiornato con successo!"; - } else { - $error = "Errore durante l'aggiornamento del giorno di chiusura."; - } + $ok = $stmt->execute([$start_date, $description ?: 'Chiusura', $description, $id, $shop_id]); + $success_message = $ok ? "Giorno di chiusura aggiornato!" : "Errore durante l'aggiornamento."; } } + } - // Cancellazione di un giorno di chiusura - if ($action === 'delete') { - $id = $_POST['id'] ?? 0; - $stmt = $pdo->prepare("DELETE FROM day_off WHERE id = ? AND school_id = ?"); - $success = $stmt->execute([$id, $school_id]); - - if ($success) { - $success_message = "Giorno di chiusura eliminato con successo!"; - } else { - $error = "Errore durante l'eliminazione del giorno di chiusura."; - } + if ($action === 'delete') { + $id = (int)($_POST['id'] ?? 0); + if ($id > 0) { + $stmt = $pdo->prepare("DELETE FROM shop_day_off WHERE id = ? AND shop_id = ?"); + $ok = $stmt->execute([$id, $shop_id]); + $success_message = $ok ? "Giorno di chiusura eliminato!" : "Errore durante l'eliminazione."; } + } - // Reindirizza per evitare il doppio invio del form - header("Location: day_off.php"); + // Evita doppio submit + if ($success_message || $error_message) { + header("Location: day_off.php" . ($success_message ? "?msg=success" : "?msg=error")); exit; } } -// Recupera tutti i giorni di chiusura della scuola +// Recupera tutti i giorni di chiusura $stmt = $pdo->prepare(" - SELECT * - FROM day_off - WHERE school_id = ? - ORDER BY start_date + SELECT id, date, title, description, is_recurring + FROM shop_day_off + WHERE shop_id = ? + ORDER BY date ASC "); -$stmt->execute([$school_id]); +$stmt->execute([$shop_id]); $days_off = $stmt->fetchAll(); ?> - + - - + Giorni di Chiusura - <?= htmlspecialchars($shop_name) ?> -
- - - - - +
-
-
-
-
Giorni di Chiusura -
-
-
- - Torna alla Dashboard -
+
+
Giorni di Chiusura -
+
+ + + Dashboard +
+
- - + + + + + + - - +
- - -
- - - - +
- - -