getConnection(); if (!isset($iduserlogin)) { header("Location: login.php"); // o la tua pagina di login exit; } // Se ha già un salone → torna alla dashboard $stmt = $pdo->prepare("SELECT id FROM shops WHERE owner_id = ? LIMIT 1"); $stmt->execute([$iduserlogin]); if ($stmt->fetch()) { header("Location: salon_dashboard.php"); exit; } $errors = []; $success = false; if ($_SERVER['REQUEST_METHOD'] === 'POST') { $name = trim($_POST['name'] ?? ''); $address = trim($_POST['address'] ?? ''); $city = trim($_POST['city'] ?? ''); $province = strtoupper(trim($_POST['province'] ?? '')); $zip_code = trim($_POST['zip_code'] ?? ''); $phone = trim($_POST['phone'] ?? ''); $email = trim($_POST['email'] ?? ''); // Validazioni minime if (empty($name)) $errors[] = "Il nome del salone è obbligatorio"; if (empty($city)) $errors[] = "La città è obbligatoria"; if (empty($phone) && empty($email)) { $errors[] = "Inserisci almeno telefono oppure email"; } if (empty($errors)) { // Slug generico ma unico abbastanza $slug_base = strtolower(preg_replace('/[^a-z0-9]+/', '-', $name)); $slug = $slug_base . '-' . substr(md5(time()), 0, 6); $stmt = $pdo->prepare(" INSERT INTO shops ( owner_id, name, slug, address, city, province, zip_code, phone, email, active, created_at, updated_at ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, 1, NOW(), NOW() ) "); $ok = $stmt->execute([ $iduserlogin, $name, $slug, $address, $city, $province, $zip_code, $phone, $email ]); if ($ok) { $success = true; // Opzionale: crea orari di default $new_shop_id = $pdo->lastInsertId(); // Esempio orari base (lun-ven 9-19, sab 9-13, dom chiuso) $default_hours = [ ['day_of_week' => 1, 'is_open' => 1, 'open_time' => '09:00:00', 'close_time' => '19:00:00'], ['day_of_week' => 2, 'is_open' => 1, 'open_time' => '09:00:00', 'close_time' => '19:00:00'], ['day_of_week' => 3, 'is_open' => 1, 'open_time' => '09:00:00', 'close_time' => '19:00:00'], ['day_of_week' => 4, 'is_open' => 1, 'open_time' => '09:00:00', 'close_time' => '19:00:00'], ['day_of_week' => 5, 'is_open' => 1, 'open_time' => '09:00:00', 'close_time' => '19:00:00'], ['day_of_week' => 6, 'is_open' => 1, 'open_time' => '09:00:00', 'close_time' => '13:00:00'], ['day_of_week' => 0, 'is_open' => 0], ]; $stmt_hour = $pdo->prepare(" INSERT INTO shop_hours (shop_id, day_of_week, is_open, open_time, close_time) VALUES (?, ?, ?, ?, ?) "); foreach ($default_hours as $h) { $stmt_hour->execute([ $new_shop_id, $h['day_of_week'], $h['is_open'], $h['open_time'] ?? null, $h['close_time'] ?? null ]); } // Reindirizza dopo 2 secondi header("Refresh: 2; url=salon_dashboard.php"); } else { $errors[] = "Errore durante la creazione del salone. Riprova."; } } } ?> Benvenuto - Crea il tuo Salone

Benvenuto nel tuo gestionale!

Crea il tuo salone per iniziare

Salone creato con successo!

Stai per essere reindirizzato alla dashboard...

×