events yogibook
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
require_once('include/headscript.php');
|
||||
require_once('include/event_mailer.php'); // stub mailer (template vero: step successivo)
|
||||
|
||||
/**
|
||||
* Annullamento evento.
|
||||
* Sceglierne uno soft (consigliato): imposta status='cancelled' e mantiene le
|
||||
* prenotazioni/contatti raccolti. Se notify=1 invia la mail di annullamento a
|
||||
* tutti i partecipanti attivi (recuperati PRIMA di annullare).
|
||||
*
|
||||
* Chiamato da events.php: event_delete.php?id=123¬ify=1|0
|
||||
*/
|
||||
$pdo = DBHandlerSelect::getInstance()->getConnection();
|
||||
|
||||
$id = isset($_GET['id']) ? (int) $_GET['id'] : 0;
|
||||
$notify = (int) ($_GET['notify'] ?? 0) === 1;
|
||||
|
||||
if ($id <= 0) {
|
||||
header('Location: events.php');
|
||||
exit();
|
||||
}
|
||||
|
||||
$stmt = $pdo->prepare("SELECT * FROM events WHERE id = ?");
|
||||
$stmt->execute([$id]);
|
||||
$event = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
if (!$event) {
|
||||
header('Location: events.php?message=error');
|
||||
exit();
|
||||
}
|
||||
|
||||
// 1) Recupera i partecipanti attivi PRIMA di annullare (servono per la mail)
|
||||
$pStmt = $pdo->prepare("SELECT * FROM event_bookings WHERE event_id = ? AND status <> 'cancelled'");
|
||||
$pStmt->execute([$id]);
|
||||
$participants = $pStmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
try {
|
||||
// 2) Annulla l'evento (soft) e le relative prenotazioni
|
||||
$pdo->prepare("UPDATE events SET status = 'cancelled', updated_at = NOW() WHERE id = ?")->execute([$id]);
|
||||
$pdo->prepare("UPDATE event_bookings SET status = 'cancelled', updated_at = NOW() WHERE event_id = ? AND status <> 'cancelled'")->execute([$id]);
|
||||
|
||||
// 3) Notifica (opzionale). Il template vero arriva nello step successivo.
|
||||
if ($notify && !empty($participants)) {
|
||||
foreach ($participants as $p) {
|
||||
sendEventCancellationMail($p['email'], $p['name'], $event);
|
||||
}
|
||||
}
|
||||
|
||||
header('Location: events.php?message=cancelled');
|
||||
exit();
|
||||
} catch (Throwable $ex) {
|
||||
error_log('[event_delete] ' . $ex->getMessage());
|
||||
header('Location: events.php?message=error');
|
||||
exit();
|
||||
}
|
||||
Reference in New Issue
Block a user