comelifacciamo/public/userarea/user_dashboard.php
2026-02-01 20:37:49 +01:00

262 lines
12 KiB
PHP

<?php
// Forza la visualizzazione degli errori (solo dev)
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
if (session_status() === PHP_SESSION_NONE) {
session_start();
}
include('include/headscript.php');
// Connessione DB
$dbHandler = DBHandlerSelect::getInstance();
$pdo = $dbHandler->getConnection();
// Verifica utente loggato
if (!isset($iduserlogin)) {
header("Location: login.php");
exit;
}
// Dati utente
$stmt = $pdo->prepare("
SELECT first_name, last_name, phone, email, avatar
FROM auth_users
WHERE id = ?
");
$stmt->execute([$iduserlogin]);
$user = $stmt->fetch(PDO::FETCH_ASSOC);
if (!$user) {
die("Errore: utente non trovato.");
}
$user_name = htmlspecialchars(trim($user['first_name'] . ' ' . $user['last_name']) ?: 'Cliente');
// Prossimi appuntamenti (da oggi in poi, max 5)
$today = date('Y-m-d');
$stmt = $pdo->prepare("
SELECT a.id, a.start_at, a.end_at, a.status,
s.name AS service_name, s.color_hex AS service_color,
st.first_name AS staff_first, st.last_name AS staff_last, st.color_hex AS staff_color,
sh.name AS shop_name
FROM appointments a
LEFT JOIN services s ON a.service_id = s.id
LEFT JOIN staff st ON a.staff_id = st.id
LEFT JOIN shops sh ON a.shop_id = sh.id
WHERE a.customer_id = (SELECT id FROM customers WHERE user_id = ? LIMIT 1)
AND DATE(a.start_at) >= ?
ORDER BY a.start_at ASC
LIMIT 5
");
$stmt->execute([$iduserlogin, $today]);
$future_appts = $stmt->fetchAll(PDO::FETCH_ASSOC);
// Ultimi appuntamenti passati (max 5)
$stmt = $pdo->prepare("
SELECT a.id, a.start_at, a.end_at, a.status,
s.name AS service_name, s.color_hex AS service_color,
st.first_name AS staff_first, st.last_name AS staff_last, st.color_hex AS staff_color,
sh.name AS shop_name
FROM appointments a
LEFT JOIN services s ON a.service_id = s.id
LEFT JOIN staff st ON a.staff_id = st.id
LEFT JOIN shops sh ON a.shop_id = sh.id
WHERE a.customer_id = (SELECT id FROM customers WHERE user_id = ? LIMIT 1)
AND DATE(a.start_at) < ?
ORDER BY a.start_at DESC
LIMIT 5
");
$stmt->execute([$iduserlogin, $today]);
$past_appts = $stmt->fetchAll(PDO::FETCH_ASSOC);
// Helpers flash (copia-incolla esattamente qui)
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;
}
// Flash
$flash = getFlash();
?>
<!doctype html>
<html lang="it">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" href="assets/images/favicon-32x32.png" type="image/png" />
<?php include('cssinclude.php'); ?>
<?php include('siteinfo.php'); ?>
<title>La Mia Dashboard</title>
</head>
<body>
<div class="wrapper">
<?php include('include/navbar.php'); ?>
<?php include('include/topbar.php'); ?>
<div class="page-wrapper">
<div class="page-content">
<!-- Benvenuto utente -->
<div class="card radius-10 mb-4">
<div class="card-body">
<div class="d-flex align-items-center flex-wrap gap-4">
<div>
<img src="../upload/users/<?= htmlspecialchars($user['avatar'] ?: 'assets/images/default-user.png') ?>"
alt="Avatar" class="rounded-circle" style="width:90px;height:90px;object-fit:cover;border:3px solid #e5e7eb;">
</div>
<div class="flex-grow-1">
<h4 class="mb-1">Ciao, <?= $user_name ?>!</h4>
<p class="mb-1 text-muted">
<i class="bx bx-phone me-1"></i> <?= htmlspecialchars($user['phone'] ?: '—') ?><br>
<i class="bx bx-envelope me-1"></i> <?= htmlspecialchars($user['email']) ?>
</p>
</div>
<div class="d-flex gap-2 flex-wrap">
<a href="profile.php" class="btn btn-warning">
<i class="bx bx-edit me-1"></i> Modifica Profilo
</a>
<a href="user_settings.php" class="btn btn-info">
<i class="bx bx-bell me-1"></i> Notifiche
</a>
</div>
</div>
</div>
</div>
<!-- Pulsanti rapidi -->
<div class="row mb-4">
<div class="col-12">
<div class="d-flex flex-wrap justify-content-center gap-3">
<a href="book_appointment.php" class="btn btn-success px-5 py-3 shadow-sm">
<i class="bx bx-calendar-plus bx-lg me-2"></i> Prenota Appuntamento
</a>
<a href="my_appointments.php" class="btn btn-primary px-5 py-3 shadow-sm">
<i class="bx bx-calendar-check bx-lg me-2"></i> I Miei Appuntamenti
</a>
</div>
</div>
</div>
<!-- Prossimi appuntamenti -->
<div class="card radius-10 mb-4">
<div class="card-header bg-light d-flex justify-content-between align-items-center">
<h6 class="mb-0">Prossimi Appuntamenti</h6>
<a href="my_appointments.php?filter=future" class="btn btn-outline-primary btn-sm">
Vedi tutti <i class="bx bx-right-arrow-alt ms-1"></i>
</a>
</div>
<div class="card-body">
<?php if (empty($future_appts)): ?>
<div class="alert alert-info text-center py-4 mb-0">
<i class="bx bx-calendar-x bx-lg mb-3 d-block"></i>
Non hai appuntamenti futuri.<br>
<a href="book_appointment.php" class="alert-link">Prenota il tuo prossimo taglio!</a>
</div>
<?php else: ?>
<div class="row g-3">
<?php foreach ($future_appts as $a):
$status_class = match ($a['status']) {
'confirmed' => 'bg-success',
'pending' => 'bg-warning',
'cancelled' => 'bg-danger',
'no_show' => 'bg-secondary',
default => 'bg-info'
};
?>
<div class="col-md-6 col-lg-4">
<div class="card border-0 shadow-sm h-100">
<div class="card-body">
<div class="d-flex justify-content-between align-items-start mb-2">
<h6 class="card-title mb-0 fw-bold">
<?= htmlspecialchars($a['service_name']) ?>
</h6>
<span class="badge <?= $status_class ?>">
<?= ucfirst($a['status']) ?>
</span>
</div>
<div class="small text-muted mb-2">
<?= date('d/m/Y H:i', strtotime($a['start_at'])) ?> - <?= date('H:i', strtotime($a['end_at'])) ?>
</div>
<div class="d-flex align-items-center gap-2 mb-2">
<span class="badge rounded-pill" style="background: <?= htmlspecialchars($a['staff_color'] ?? '#6c757d') ?>">
<?= htmlspecialchars($a['staff_first'] . ' ' . substr($a['staff_last'], 0, 1) . '.') ?>
</span>
<small class="text-muted">presso <?= htmlspecialchars($a['shop_name']) ?></small>
</div>
<small class="text-muted">
<i class="bx bx-phone me-1"></i> <?= htmlspecialchars($a['customer_phone'] ?? '—') ?>
</small>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
</div>
<!-- Ultimi appuntamenti passati -->
<div class="card radius-10">
<div class="card-header bg-light d-flex justify-content-between align-items-center">
<h6 class="mb-0">Ultimi Appuntamenti</h6>
<a href="my_appointments.php?filter=past" class="btn btn-outline-secondary btn-sm">
Vedi tutti <i class="bx bx-right-arrow-alt ms-1"></i>
</a>
</div>
<div class="card-body">
<?php if (empty($past_appts)): ?>
<div class="text-center text-muted py-4">
Non hai ancora appuntamenti passati.
</div>
<?php else: ?>
<div class="list-group list-group-flush">
<?php foreach ($past_appts as $a):
$status_class = match ($a['status']) {
'completed' => 'bg-success',
'cancelled' => 'bg-danger',
'no_show' => 'bg-secondary',
default => 'bg-info'
};
?>
<a href="appointment_detail.php?id=<?= $a['id'] ?>" class="list-group-item list-group-item-action">
<div class="d-flex w-100 justify-content-between align-items-center">
<div>
<h6 class="mb-1 fw-bold"><?= htmlspecialchars($a['service_name']) ?></h6>
<small class="text-muted">
<?= htmlspecialchars($a['staff_first'] . ' ' . $a['staff_last']) ?> • <?= date('d/m/Y', strtotime($a['start_at'])) ?>
</small>
</div>
<span class="badge <?= $status_class ?>">
<?= ucfirst($a['status']) ?>
</span>
</div>
</a>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
</div>
</div>
</div>
<?php include('include/footer.php'); ?>
</div>
<?php include('jsinclude.php'); ?>
</body>
</html>