dashboard

This commit is contained in:
2026-01-25 21:22:35 +01:00
parent 8d8e213f1c
commit bd9d3811f6
6 changed files with 2814 additions and 348 deletions
+200
View File
@@ -0,0 +1,200 @@
<?php
include('include/headscript.php');
$dbHandler = DBHandlerSelect::getInstance();
$pdo = $dbHandler->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.";
}
}
}
?>
<!doctype html>
<html lang="it">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<?php include('cssinclude.php'); ?>
<title>Benvenuto - Crea il tuo Salone</title>
</head>
<body class="bg-light d-flex align-items-center min-vh-100">
<div class="container">
<div class="row justify-content-center">
<div class="col-lg-6 col-xl-5">
<div class="card shadow border-0">
<div class="card-header bg-primary text-white text-center py-4">
<h3 class="mb-1">Benvenuto nel tuo gestionale!</h3>
<p class="mb-0">Crea il tuo salone per iniziare</p>
</div>
<div class="card-body p-4 p-md-5">
<?php if ($success): ?>
<div class="alert alert-success text-center py-4">
<i class="bx bx-check-circle bx-lg mb-3 d-block"></i>
<h4>Salone creato con successo!</h4>
<p>Stai per essere reindirizzato alla dashboard...</p>
<div class="spinner-border text-primary mt-3" role="status"></div>
</div>
<?php else: ?>
<?php if ($errors): ?>
<div class="alert alert-danger">
<?php foreach ($errors as $err): ?>
<div>× <?= htmlspecialchars($err) ?></div>
<?php endforeach; ?>
</div>
<?php endif; ?>
<form method="POST" class="needs-validation" novalidate>
<div class="mb-4">
<label class="form-label fw-bold">Nome salone <span class="text-danger">*</span></label>
<input type="text" name="name" class="form-control form-control-lg" required
value="<?= htmlspecialchars($_POST['name'] ?? '') ?>">
</div>
<div class="mb-4">
<label class="form-label fw-bold">Città <span class="text-danger">*</span></label>
<input type="text" name="city" class="form-control form-control-lg" required
value="<?= htmlspecialchars($_POST['city'] ?? '') ?>">
</div>
<div class="row g-3">
<div class="col-md-6">
<label class="form-label">Indirizzo</label>
<input type="text" name="address" class="form-control"
value="<?= htmlspecialchars($_POST['address'] ?? '') ?>">
</div>
<div class="col-md-6">
<label class="form-label">CAP</label>
<input type="text" name="zip_code" class="form-control"
value="<?= htmlspecialchars($_POST['zip_code'] ?? '') ?>">
</div>
</div>
<div class="row g-3 mt-3">
<div class="col-md-4">
<label class="form-label">Provincia</label>
<input type="text" name="province" class="form-control text-uppercase" maxlength="2"
placeholder="MI" value="<?= htmlspecialchars($_POST['province'] ?? '') ?>">
</div>
<div class="col-md-8">
<label class="form-label">Telefono o Email <span class="text-danger">*</span></label>
<div class="input-group">
<input type="tel" name="phone" class="form-control" placeholder="Telefono"
value="<?= htmlspecialchars($_POST['phone'] ?? '') ?>">
<input type="email" name="email" class="form-control" placeholder="Email"
value="<?= htmlspecialchars($_POST['email'] ?? '') ?>">
</div>
</div>
</div>
<div class="d-grid mt-5">
<button type="submit" class="btn btn-primary btn-lg">
Crea il mio salone
</button>
</div>
</form>
<?php endif; ?>
</div>
</div>
</div>
</div>
</div>
<?php include('jsinclude.php'); ?>
</body>
</html>