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'];
$promoted = [];
try {
$pdo->beginTransaction();
$pdo->prepare("SELECT id FROM events WHERE id = ? FOR UPDATE")->execute([$eventId]);
$bl = $pdo->prepare("SELECT status FROM event_bookings WHERE id = ? AND event_id = ?");
$bl->execute([$bookingId, $eventId]);
$bStatus = $bl->fetchColumn();
if ($bStatus !== false && $bStatus !== 'cancelled') {
$wasOccupying = in_array($bStatus, ['confirmed', 'pending', 'offered'], true);
$pdo->prepare("UPDATE event_bookings SET status = 'cancelled', updated_at = NOW() WHERE id = ? AND event_id = ?")
->execute([$bookingId, $eventId]);
if ($wasOccupying) {
// libera posti -> offre alla prima in lista d'attesa
$promoted = promoteFromWaitlist($pdo, $eventId);
}
}
$pdo->commit();
// Email di promozione (E, con riconferma) ai nuovi "offered"
if (!empty($promoted)) {
$ev = $pdo->prepare("SELECT * FROM events WHERE id = ?");
$ev->execute([$eventId]);
$evRow = $ev->fetch(PDO::FETCH_ASSOC);
if ($evRow) {
foreach ($promoted as $pr) {
try {
yse_mail_promotion($pr, $evRow);
} catch (Throwable $me) {
error_log('[promo mail] ' . $me->getMessage());
}
}
}
}
} catch (Throwable $ex) {
if ($pdo->inTransaction()) {
$pdo->rollBack();
}
error_log('[participants cancel] ' . $ex->getMessage());
}
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: posti occupati = confermate/pending/offerte (in riconferma); lista d'attesa a parte
$bookedSeats = 0;
$waitingSeats = 0;
$activeCount = 0;
$revenue = 0.0;
foreach ($bookings as $b) {
if (in_array($b['status'], ['confirmed', 'pending', 'offered'], true)) {
$bookedSeats += (int) $b['seats'];
$activeCount++;
$revenue += (float) $b['amount'];
} elseif ($b['status'] === 'waiting') {
$waitingSeats += (int) $b['seats'];
}
}
$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'];
case 'waiting':
return ["Lista d'attesa", '#eef2fb', '#3a5bb8'];
case 'offered':
return ['Da riconfermare', '#fff4e5', '#b26a00'];
default:
return ['In attesa', '#fff4e5', '#b26a00'];
}
}
?>
YogiBook - Partecipanti
Iscrizione annullata.
| Partecipante |
Email |
Telefono |
Posti |
Marketing |
Iscritto il |
Stato |
Azioni |
|
Ancora nessun iscritto a questo evento.
|
|
|
|
|
|
Sì
No
|
|
|
—
|