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; } // POST - Salva impostazioni if ($_SERVER['REQUEST_METHOD'] === 'POST') { try { $show_prices_online = isset($_POST['show_prices_online']) ? 1 : 0; $restrict_start_minutes = trim($_POST['restrict_start_minutes'] ?? '00,30'); $min_booking_notice_hours = (int)($_POST['min_booking_notice_hours'] ?? 2); $max_booking_days_ahead = (int)($_POST['max_booking_days_ahead'] ?? 90); // Validazione restrict_start_minutes $valid_options = ['any', '00', '00,30', '00,15,30,45']; if (!in_array($restrict_start_minutes, $valid_options)) { $restrict_start_minutes = '00,30'; } // Controlla esistenza $stmt = $pdo->prepare("SELECT id FROM shop_settings WHERE shop_id = ?"); $stmt->execute([$shop_id]); $exists = $stmt->fetchColumn() !== false; if ($exists) { $stmt = $pdo->prepare(" UPDATE shop_settings SET show_prices_online = ?, allowed_start_minutes = ?, min_booking_notice_hours = ?, max_booking_days_ahead = ?, updated_at = NOW() WHERE shop_id = ? "); $ok = $stmt->execute([ $show_prices_online, $restrict_start_minutes, $min_booking_notice_hours, $max_booking_days_ahead, $shop_id ]); } else { $stmt = $pdo->prepare(" INSERT INTO shop_settings ( shop_id, show_prices_online, allowed_start_minutes, min_booking_notice_hours, max_booking_days_ahead ) VALUES (?, ?, ?, ?, ?) "); $ok = $stmt->execute([ $shop_id, $show_prices_online, $restrict_start_minutes, $min_booking_notice_hours, $max_booking_days_ahead ]); } setFlash($ok ? 'success' : 'danger', $ok ? "Impostazioni salvate con successo!" : "Errore durante il salvataggio."); header("Location: salon_settings.php"); exit; } catch (Throwable $e) { setFlash('danger', "Errore: " . $e->getMessage()); header("Location: salon_settings.php"); exit; } } // Fetch impostazioni $stmt = $pdo->prepare("SELECT * FROM shop_settings WHERE shop_id = ?"); $stmt->execute([$shop_id]); $settings = $stmt->fetch(PDO::FETCH_ASSOC) ?: [ 'show_prices_online' => 1, 'allowed_start_minutes' => '00,30', 'min_booking_notice_hours' => 2, 'max_booking_days_ahead' => 90 ]; $flash = getFlash(); ?> Impostazioni Salone - <?= htmlspecialchars($shop_name) ?>
Impostazioni Salone
Dashboard
>
I clienti vedranno i prezzi durante la prenotazione online.
Anteprima slot (es. dalle 9:00):
Es: 2 = non prenotabile per oggi se mancano meno di 2 ore.
Es: 90 = massimo 90 giorni da oggi.