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 ((int)$stmt->fetchColumn() === 0) { header("Location: onboarding_salon.php"); exit; } // Prendi il primo salone $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 = (int)$shop['id']; $shop_name = $shop['name']; // Helpers flash function setFlash(string $type, string $text): void { $_SESSION['flash'] = ['type' => $type, 'text' => $text]; } function getFlash(): ?array { if (!isset($_SESSION['flash'])) return null; $f = $_SESSION['flash']; unset($_SESSION['flash']); return $f; } // Fetch orari esistenti $stmt = $pdo->prepare("SELECT * FROM shop_hours WHERE shop_id = ? ORDER BY day_of_week"); $stmt->execute([$shop_id]); $hours_raw = $stmt->fetchAll(PDO::FETCH_ASSOC); // Organizza per giorno $hours = []; for ($d = 0; $d <= 6; $d++) { $hours[$d] = [ 'is_open' => 0, 'open_time' => '09:00', 'close_time' => '19:00', 'open_time_2' => null, 'close_time_2' => null, 'notes' => '' ]; } foreach ($hours_raw as $h) { $d = (int)$h['day_of_week']; $hours[$d] = $h; } $flash = getFlash(); ?>