getConnection(); // Verifica utente loggato if (!isset($iduserlogin)) { header("Location: login.php"); exit; } // Controlla se esiste almeno un salone $stmt = $pdo->prepare("SELECT COUNT(*) FROM shops WHERE owner_id = ?"); $stmt->execute([$iduserlogin]); if ($stmt->fetchColumn() === 0) { header("Location: onboarding_salon.php"); exit; } // 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); if (!$shop) { die("Errore: salone non trovato."); } $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 shop_day_off (shop_id, date, title, description, is_recurring, created_at) VALUES (?, ?, ?, ?, 0, NOW()) "); $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 shop_day_off SET date = ?, title = ?, description = ?, updated_at = NOW() WHERE id = ? AND shop_id = ? "); $ok = $stmt->execute([$start_date, $description ?: 'Chiusura', $description, $id, $shop_id]); $success_message = $ok ? "Giorno di chiusura aggiornato!" : "Errore durante l'aggiornamento."; } } } 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."; } } // 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 $stmt = $pdo->prepare(" SELECT id, date, title, description, is_recurring FROM shop_day_off WHERE shop_id = ? ORDER BY date ASC "); $stmt->execute([$shop_id]); $days_off = $stmt->fetchAll(); ?> Giorni di Chiusura - <?= htmlspecialchars($shop_name) ?>
Giorni di Chiusura -
Dashboard
Non hai ancora impostato giorni di chiusura.
Aggiungine uno per bloccare le prenotazioni in quei giorni.
Data Titolo / Descrizione Ricorrente Azioni
Sì (ogni anno) No