added mail to events
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
require_once('include/headscript.php');
|
||||
require_once('include/event_waitlist.php');
|
||||
require_once('include/event_mailer.php');
|
||||
|
||||
/**
|
||||
* Modulo Eventi - elenco partecipanti di un evento.
|
||||
@@ -35,6 +36,7 @@ if ($eventId <= 0) {
|
||||
// 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]);
|
||||
@@ -44,15 +46,31 @@ if (isset($_GET['cancel_booking'])) {
|
||||
$bStatus = $bl->fetchColumn();
|
||||
|
||||
if ($bStatus !== false && $bStatus !== 'cancelled') {
|
||||
$wasOccupying = in_array($bStatus, ['confirmed', 'pending'], true);
|
||||
$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 -> promuove la prima in lista d'attesa
|
||||
promoteFromWaitlist($pdo, $eventId);
|
||||
// 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();
|
||||
@@ -75,13 +93,13 @@ $bStmt = $pdo->prepare("SELECT * FROM event_bookings WHERE event_id = ? ORDER BY
|
||||
$bStmt->execute([$eventId]);
|
||||
$bookings = $bStmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
// Riepilogo: i posti occupati sono solo confermate/pending; la lista d'attesa a parte
|
||||
// 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'], true)) {
|
||||
if (in_array($b['status'], ['confirmed', 'pending', 'offered'], true)) {
|
||||
$bookedSeats += (int) $b['seats'];
|
||||
$activeCount++;
|
||||
$revenue += (float) $b['amount'];
|
||||
@@ -96,13 +114,15 @@ function bookingBadge(string $status): array
|
||||
{
|
||||
switch ($status) {
|
||||
case 'confirmed':
|
||||
return ['Confermata', '#e7f7ee', '#1a7f52'];
|
||||
return ['Confermata', '#e7f7ee', '#1a7f52'];
|
||||
case 'cancelled':
|
||||
return ['Annullata', '#fdecea', '#c0392b'];
|
||||
return ['Annullata', '#fdecea', '#c0392b'];
|
||||
case 'waiting':
|
||||
return ["Lista d'attesa", '#eef2fb', '#3a5bb8'];
|
||||
return ["Lista d'attesa", '#eef2fb', '#3a5bb8'];
|
||||
case 'offered':
|
||||
return ['Da riconfermare', '#fff4e5', '#b26a00'];
|
||||
default:
|
||||
return ['In attesa', '#fff4e5', '#b26a00'];
|
||||
return ['In attesa', '#fff4e5', '#b26a00'];
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user