getConnection();
// Helper flash
if (!function_exists('getFlash')) {
function getFlash()
{
if (!empty($_SESSION['flash'])) {
$f = $_SESSION['flash'];
unset($_SESSION['flash']);
return $f;
}
return null;
}
}
// --- Parametri ---
$shop_id = (int)($_GET['shop'] ?? 0);
$service_id = (int)($_GET['service'] ?? 0);
// Preselezioni (es. ritorno dal login o da uno slot già scelto)
$pre_staff = (int)($_GET['staff'] ?? 0);
$pre_date = trim($_GET['date'] ?? '');
$pre_time = trim($_GET['time'] ?? '');
$need_login = !empty($_GET['need_login']);
if ($shop_id <= 0 || $service_id <= 0) {
header('Location: search.php');
exit;
}
// --- Salone ---
$s = $pdo->prepare("SELECT id, name, slug, address, city, province, cover_image FROM shops WHERE id = ? AND active = 1");
$s->execute([$shop_id]);
$shop = $s->fetch(PDO::FETCH_ASSOC);
if (!$shop) {
header('Location: search.php');
exit;
}
// --- Servizio ---
$sv = $pdo->prepare("SELECT id, name, description, duration_minutes, price FROM services WHERE id = ? AND shop_id = ? AND is_active = 1");
$sv->execute([$service_id, $shop_id]);
$service = $sv->fetch(PDO::FETCH_ASSOC);
if (!$service) {
header('Location: salon.php?slug=' . urlencode($shop['slug']));
exit;
}
// --- Staff prenotabili online ---
$stf = $pdo->prepare("SELECT id, first_name, last_name, nickname, role, avatar, color_hex
FROM staff
WHERE shop_id = ? AND is_active = 1 AND can_book_online = 1
ORDER BY first_name ASC");
$stf->execute([$shop_id]);
$staffList = $stf->fetchAll(PDO::FETCH_ASSOC);
// --- Limiti calendario ---
$setStmt = $pdo->prepare("SELECT min_booking_notice_hours, max_booking_days_ahead FROM shop_settings WHERE shop_id = ?");
$setStmt->execute([$shop_id]);
$setRow = $setStmt->fetch(PDO::FETCH_ASSOC) ?: [];
$maxDaysAhead = (int)($setRow['max_booking_days_ahead'] ?? 90);
$minDate = (new DateTime('today'))->format('Y-m-d');
$maxDate = (new DateTime('today'))->modify("+{$maxDaysAhead} days")->format('Y-m-d');
$isLogged = !empty($_SESSION['iduserlogin']);
$flash = getFlash();
// Durata leggibile
$dur = (int)$service['duration_minutes'];
$durLabel = $dur >= 60 ? floor($dur / 60) . 'h' . ($dur % 60 ? ' ' . ($dur % 60) . 'min' : '') : $dur . ' min';
?>
Prenota da = htmlspecialchars($shop['name']) ?>
= htmlspecialchars($service['name']) ?> · = $durLabel ?>
· = number_format((float)$service['price'], 2, ',', '.') ?> €
= htmlspecialchars($flash['text']) ?>
1 Scegli l'operatore
Nessun operatore disponibile per la prenotazione online. Contatta direttamente il salone.
 ?>)
= $initial ?>
= $stNick ?>
= htmlspecialchars($st['role']) ?>
2 Scegli il giorno
3 Scegli l'orario
Seleziona prima operatore e giorno.
Riepilogo
Salone= htmlspecialchars($shop['name']) ?>
Servizio= htmlspecialchars($service['name']) ?>
Durata= $durLabel ?>
Operatore—
Giorno—
Orario—
La prenotazione sarà confermata dal salone.