435 lines
18 KiB
PHP
435 lines
18 KiB
PHP
<?php
|
|
require_once('include/headscript.php');
|
|
|
|
/**
|
|
* Modulo Eventi - elenco partecipanti di un evento.
|
|
* Mostra riepilogo (posti, iscrizioni, incasso) e la tabella delle prenotazioni.
|
|
* Gestisce anche l'annullamento della singola iscrizione via ?cancel_booking=ID.
|
|
*/
|
|
$pdo = DBHandlerSelect::getInstance()->getConnection();
|
|
|
|
function e($value): string
|
|
{
|
|
return htmlspecialchars((string) $value, ENT_QUOTES, 'UTF-8');
|
|
}
|
|
|
|
function initials(string $first, string $last): string
|
|
{
|
|
$ini = strtoupper(mb_substr(trim($first), 0, 1) . mb_substr(trim($last), 0, 1));
|
|
return $ini !== '' ? $ini : '?';
|
|
}
|
|
|
|
function avatarColor(string $seed): string
|
|
{
|
|
$palette = ['#1ebf73', '#2980b9', '#8e44ad', '#e67e22', '#16a085', '#c0392b', '#2c3e50', '#d35400'];
|
|
return $palette[abs(crc32($seed)) % count($palette)];
|
|
}
|
|
|
|
$eventId = isset($_GET['id']) ? (int) $_GET['id'] : 0;
|
|
if ($eventId <= 0) {
|
|
header('Location: events.php');
|
|
exit();
|
|
}
|
|
|
|
// Annullamento singola iscrizione (deve avvenire prima di ogni output)
|
|
if (isset($_GET['cancel_booking'])) {
|
|
$bookingId = (int) $_GET['cancel_booking'];
|
|
$upd = $pdo->prepare("UPDATE event_bookings SET status = 'cancelled', updated_at = NOW() WHERE id = ? AND event_id = ?");
|
|
$upd->execute([$bookingId, $eventId]);
|
|
header('Location: event_participants.php?id=' . $eventId . '&message=booking_cancelled');
|
|
exit();
|
|
}
|
|
|
|
$stmt = $pdo->prepare("SELECT * FROM events WHERE id = ?");
|
|
$stmt->execute([$eventId]);
|
|
$event = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
if (!$event) {
|
|
header('Location: events.php?message=error');
|
|
exit();
|
|
}
|
|
|
|
$bStmt = $pdo->prepare("SELECT * FROM event_bookings WHERE event_id = ? ORDER BY created_at DESC, id DESC");
|
|
$bStmt->execute([$eventId]);
|
|
$bookings = $bStmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
// Riepilogo (solo prenotazioni non annullate)
|
|
$bookedSeats = 0;
|
|
$activeCount = 0;
|
|
$revenue = 0.0;
|
|
foreach ($bookings as $b) {
|
|
if ($b['status'] !== 'cancelled') {
|
|
$bookedSeats += (int) $b['seats'];
|
|
$activeCount++;
|
|
$revenue += (float) $b['amount'];
|
|
}
|
|
}
|
|
$maxSeats = (int) $event['max_seats'];
|
|
$message = $_GET['message'] ?? '';
|
|
|
|
function bookingBadge(string $status): array
|
|
{
|
|
switch ($status) {
|
|
case 'confirmed':
|
|
return ['Confermata', '#e7f7ee', '#1a7f52'];
|
|
case 'cancelled':
|
|
return ['Annullata', '#fdecea', '#c0392b'];
|
|
default:
|
|
return ['In attesa', '#fff4e5', '#b26a00'];
|
|
}
|
|
}
|
|
?>
|
|
<!doctype html>
|
|
<html lang="it">
|
|
|
|
<head>
|
|
<meta charset="utf-8" />
|
|
<title>YogiBook - Partecipanti</title>
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<link rel="shortcut icon" href="assets/images/favicon.ico">
|
|
<link href="assets/css/bootstrap.min.css" id="bootstrap-style" rel="stylesheet" type="text/css" />
|
|
<link href="assets/css/icons.min.css" rel="stylesheet" type="text/css" />
|
|
<link href="assets/css/app.min.css" id="app-style" rel="stylesheet" type="text/css" />
|
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
|
|
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
|
|
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
|
|
|
<style>
|
|
.admin-card {
|
|
border: none;
|
|
border-radius: 14px;
|
|
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.06);
|
|
}
|
|
|
|
.admin-card .card-body {
|
|
padding: 26px 30px;
|
|
}
|
|
|
|
.section-title {
|
|
font-size: 15px;
|
|
font-weight: 700;
|
|
letter-spacing: 0.04em;
|
|
text-transform: uppercase;
|
|
color: #6b7280;
|
|
margin-bottom: 4px;
|
|
}
|
|
|
|
.section-lead {
|
|
color: #9ca3af;
|
|
font-size: 14px;
|
|
margin-bottom: 22px;
|
|
}
|
|
|
|
.stat-box {
|
|
background: #f7f8fa;
|
|
border-radius: 12px;
|
|
padding: 18px 20px;
|
|
}
|
|
|
|
.stat-value {
|
|
font-size: 26px;
|
|
font-weight: 700;
|
|
color: #1f2937;
|
|
}
|
|
|
|
.stat-label {
|
|
color: #6b7280;
|
|
font-size: 13px;
|
|
font-weight: 600;
|
|
text-transform: uppercase;
|
|
letter-spacing: 0.03em;
|
|
}
|
|
|
|
.part-table thead th {
|
|
font-size: 12px;
|
|
text-transform: uppercase;
|
|
letter-spacing: 0.03em;
|
|
color: #6b7280;
|
|
border-bottom: 2px solid #eef0f3;
|
|
white-space: nowrap;
|
|
}
|
|
|
|
.part-table td {
|
|
vertical-align: middle;
|
|
}
|
|
|
|
.user-cell {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 10px;
|
|
}
|
|
|
|
.avatar {
|
|
width: 36px;
|
|
height: 36px;
|
|
border-radius: 50%;
|
|
color: #fff;
|
|
font-weight: 700;
|
|
font-size: 13px;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
flex-shrink: 0;
|
|
}
|
|
|
|
.user-name {
|
|
font-weight: 600;
|
|
color: #1f2937;
|
|
}
|
|
|
|
.guest-tag {
|
|
font-size: 11px;
|
|
font-weight: 600;
|
|
color: #6b7280;
|
|
background: #eef0f3;
|
|
border-radius: 10px;
|
|
padding: 1px 7px;
|
|
margin-left: 6px;
|
|
}
|
|
|
|
.status-badge {
|
|
display: inline-block;
|
|
font-size: 12px;
|
|
font-weight: 700;
|
|
padding: 3px 10px;
|
|
border-radius: 20px;
|
|
}
|
|
|
|
.btn-cancel-b {
|
|
border: 1px solid #f2c9c4;
|
|
background: #fff;
|
|
color: #c0392b;
|
|
border-radius: 8px;
|
|
padding: 5px 11px;
|
|
font-size: 13px;
|
|
font-weight: 600;
|
|
cursor: pointer;
|
|
white-space: nowrap;
|
|
}
|
|
|
|
.btn-cancel-b:hover {
|
|
background: #fdecea;
|
|
}
|
|
|
|
.empty-state {
|
|
text-align: center;
|
|
padding: 44px 10px;
|
|
color: #9ca3af;
|
|
}
|
|
|
|
.empty-state i {
|
|
font-size: 34px;
|
|
margin-bottom: 10px;
|
|
display: block;
|
|
color: #d5d9e0;
|
|
}
|
|
|
|
.yes-mark {
|
|
color: #1a7f52;
|
|
font-weight: 700;
|
|
}
|
|
|
|
.no-mark {
|
|
color: #c0392b;
|
|
font-weight: 700;
|
|
}
|
|
</style>
|
|
</head>
|
|
|
|
<body>
|
|
<div id="layout-wrapper">
|
|
<header id="page-topbar" class="isvertical-topbar">
|
|
<div class="navbar-header">
|
|
<div class="d-flex">
|
|
<?php include('include/logoarea.php'); ?>
|
|
<button type="button" class="btn btn-sm px-3 font-size-24 header-item waves-effect vertical-menu-btn">
|
|
<i class="bx bx-menu align-middle"></i>
|
|
</button>
|
|
<div class="page-title-box align-self-center d-none d-md-block">
|
|
<h4 class="page-title mb-0">Partecipanti</h4>
|
|
</div>
|
|
</div>
|
|
<div class="d-flex">
|
|
<?php include('include/languageselection.php'); ?>
|
|
<?php include('include/profiletopbar.php'); ?>
|
|
</div>
|
|
</div>
|
|
</header>
|
|
<?php include('include/sidebar.php'); ?>
|
|
<header class="ishorizontal-topbar">
|
|
<div class="navbar-header">
|
|
<div class="d-flex"></div>
|
|
</div>
|
|
<div class="topnav">
|
|
<div class="container-fluid">
|
|
<nav class="navbar navbar-light navbar-expand-lg topnav-menu"></nav>
|
|
</div>
|
|
</div>
|
|
</header>
|
|
|
|
<div class="main-content">
|
|
<div class="page-content">
|
|
<div class="container-fluid">
|
|
|
|
<?php if ($message === 'booking_cancelled') : ?>
|
|
<div class="alert alert-warning" role="alert">Iscrizione annullata.</div>
|
|
<?php endif; ?>
|
|
|
|
<div class="row">
|
|
<div class="col-12">
|
|
<div class="card admin-card mb-4">
|
|
<div class="card-body">
|
|
<div class="d-flex justify-content-between align-items-start">
|
|
<div>
|
|
<div class="section-title">Partecipanti</div>
|
|
<p class="section-lead mb-0">
|
|
<strong style="color:#1f2937;"><?php echo e($event['title']); ?></strong>
|
|
· <?php echo e(date('d-m-Y H:i', strtotime($event['starts_at']))); ?>
|
|
</p>
|
|
</div>
|
|
<a href="events.php" class="btn btn-light" style="border-radius:8px;font-weight:600;"><i class="bx bx-arrow-back"></i> Tutti gli eventi</a>
|
|
</div>
|
|
|
|
<div class="row mt-4">
|
|
<div class="col-md-4 mb-3">
|
|
<div class="stat-box">
|
|
<div class="stat-value"><?php echo $bookedSeats; ?> / <?php echo $maxSeats; ?></div>
|
|
<div class="stat-label">Posti prenotati</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-4 mb-3">
|
|
<div class="stat-box">
|
|
<div class="stat-value"><?php echo $activeCount; ?></div>
|
|
<div class="stat-label">Iscrizioni attive</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-4 mb-3">
|
|
<div class="stat-box">
|
|
<div class="stat-value"><?php echo e(number_format($revenue, 2, ',', '.')); ?> <?php echo e($event['currency']); ?></div>
|
|
<div class="stat-label">Incasso stimato</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="row">
|
|
<div class="col-12">
|
|
<div class="card admin-card">
|
|
<div class="card-body">
|
|
<div class="table-responsive">
|
|
<table class="table part-table align-middle">
|
|
<thead>
|
|
<tr>
|
|
<th>Partecipante</th>
|
|
<th>Email</th>
|
|
<th>Telefono</th>
|
|
<th>Posti</th>
|
|
<th>Marketing</th>
|
|
<th>Iscritto il</th>
|
|
<th>Stato</th>
|
|
<th class="text-end">Azioni</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php if (empty($bookings)) : ?>
|
|
<tr>
|
|
<td colspan="8">
|
|
<div class="empty-state">
|
|
<i class="fas fa-users"></i>
|
|
Ancora nessun iscritto a questo evento.
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
<?php else :
|
|
foreach ($bookings as $b) :
|
|
// Il nome può essere un unico campo: proviamo a spezzarlo per le iniziali
|
|
$nameParts = preg_split('/\s+/', trim($b['name']), 2);
|
|
$first = $nameParts[0] ?? '';
|
|
$last = $nameParts[1] ?? '';
|
|
$isGuest = empty($b['user_id']);
|
|
[$stLabel, $stBg, $stColor] = bookingBadge($b['status']);
|
|
?>
|
|
<tr>
|
|
<td>
|
|
<div class="user-cell">
|
|
<div class="avatar" style="background: <?php echo avatarColor($b['name']); ?>;">
|
|
<?php echo e(initials($first, $last)); ?>
|
|
</div>
|
|
<span class="user-name"><?php echo e($b['name']); ?>
|
|
<?php if ($isGuest) : ?><span class="guest-tag">ospite</span><?php endif; ?>
|
|
</span>
|
|
</div>
|
|
</td>
|
|
<td><?php echo e($b['email']); ?></td>
|
|
<td><?php echo e($b['phone'] ?: '—'); ?></td>
|
|
<td><?php echo (int) $b['seats']; ?></td>
|
|
<td>
|
|
<?php if (($b['marketing_opt_in'] ?? 'N') === 'Y') : ?>
|
|
<span class="yes-mark">Sì</span>
|
|
<?php else : ?>
|
|
<span class="no-mark">No</span>
|
|
<?php endif; ?>
|
|
</td>
|
|
<td><?php echo e($b['created_at'] ? date('d-m-Y', strtotime($b['created_at'])) : '—'); ?></td>
|
|
<td><span class="status-badge" style="background: <?php echo $stBg; ?>; color: <?php echo $stColor; ?>;"><?php echo e($stLabel); ?></span></td>
|
|
<td class="text-end">
|
|
<?php if ($b['status'] !== 'cancelled') : ?>
|
|
<button type="button" class="btn-cancel-b btn-cancel-booking"
|
|
data-id="<?php echo (int) $b['id']; ?>"
|
|
data-name="<?php echo e($b['name']); ?>">
|
|
<i class="bx bx-block"></i> Annulla
|
|
</button>
|
|
<?php else : ?>
|
|
<span style="color:#9ca3af;font-size:13px;">—</span>
|
|
<?php endif; ?>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
<?php include('include/footer.php'); ?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script src="assets/libs/bootstrap/js/bootstrap.bundle.min.js"></script>
|
|
<script src="assets/libs/metismenujs/metismenujs.min.js"></script>
|
|
<script src="assets/libs/simplebar/simplebar.min.js"></script>
|
|
<script src="assets/libs/eva-icons/eva.min.js"></script>
|
|
<script src="assets/js/app.js"></script>
|
|
|
|
<script>
|
|
$(document).ready(function() {
|
|
$('.btn-cancel-booking').on('click', function() {
|
|
var id = $(this).data('id');
|
|
var name = $(this).data('name');
|
|
Swal.fire({
|
|
title: 'Annullare iscrizione?',
|
|
html: 'Stai per annullare l\'iscrizione di <strong>' + $('<div>').text(name).html() + '</strong>.',
|
|
icon: 'warning',
|
|
showCancelButton: true,
|
|
confirmButtonText: 'Annulla iscrizione',
|
|
cancelButtonText: 'Chiudi',
|
|
confirmButtonColor: '#e74c3c',
|
|
reverseButtons: true
|
|
}).then(function(result) {
|
|
if (result.isConfirmed) {
|
|
window.location.href = 'event_participants.php?id=<?php echo $eventId; ?>&cancel_booking=' + id;
|
|
}
|
|
});
|
|
});
|
|
});
|
|
</script>
|
|
</body>
|
|
|
|
</html>
|