466 lines
20 KiB
PHP
466 lines
20 KiB
PHP
<?php
|
|
require_once('include/headscript.php');
|
|
|
|
/**
|
|
* Modulo Eventi - elenco lato insegnante (stile Amelia).
|
|
* Mostra gli eventi raggruppati per data con posti prenotati, stato e azioni:
|
|
* - Partecipanti -> event_participants.php
|
|
* - Modifica -> event_form.php?id=
|
|
* - Annulla -> modale (SweetAlert2) che chiede se inviare la mail di
|
|
* annullamento a tutti i partecipanti, poi event_delete.php
|
|
*/
|
|
$pdo = DBHandlerSelect::getInstance()->getConnection();
|
|
|
|
function e($value): string
|
|
{
|
|
return htmlspecialchars((string) $value, ENT_QUOTES, 'UTF-8');
|
|
}
|
|
|
|
$message = $_GET['message'] ?? '';
|
|
|
|
// Posti prenotati = SOMMA dei posti delle prenotazioni non annullate.
|
|
$sql = "SELECT e.*,
|
|
COALESCE(b.booked, 0) AS booked,
|
|
COALESCE(b.bookings_count, 0) AS bookings_count,
|
|
u.first_name AS creator_first,
|
|
u.last_name AS creator_last
|
|
FROM events e
|
|
LEFT JOIN (
|
|
SELECT event_id,
|
|
SUM(seats) AS booked,
|
|
COUNT(*) AS bookings_count
|
|
FROM event_bookings
|
|
WHERE status IN ('confirmed','pending','offered')
|
|
GROUP BY event_id
|
|
) b ON b.event_id = e.id
|
|
LEFT JOIN auth_users u ON u.id = e.user_id
|
|
ORDER BY e.starts_at ASC";
|
|
$events = $pdo->query($sql)->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
$mesi = [
|
|
1 => 'gennaio',
|
|
2 => 'febbraio',
|
|
3 => 'marzo',
|
|
4 => 'aprile',
|
|
5 => 'maggio',
|
|
6 => 'giugno',
|
|
7 => 'luglio',
|
|
8 => 'agosto',
|
|
9 => 'settembre',
|
|
10 => 'ottobre',
|
|
11 => 'novembre',
|
|
12 => 'dicembre'
|
|
];
|
|
|
|
function dataItaliana(string $dt, array $mesi): string
|
|
{
|
|
$t = strtotime($dt);
|
|
return date('j', $t) . ' ' . $mesi[(int) date('n', $t)] . ' ' . date('Y', $t);
|
|
}
|
|
|
|
/** @return array [label, bgColor, textColor] */
|
|
function statusBadge(string $status): array
|
|
{
|
|
switch ($status) {
|
|
case 'published':
|
|
return ['Aperto', '#e7f7ee', '#1a7f52'];
|
|
case 'cancelled':
|
|
return ['Annullato', '#fdecea', '#c0392b'];
|
|
default:
|
|
return ['Bozza', '#eef0f3', '#6b7280'];
|
|
}
|
|
}
|
|
?>
|
|
<!doctype html>
|
|
<html lang="it">
|
|
|
|
<head>
|
|
<meta charset="utf-8" />
|
|
<title>YogiBook - Eventi</title>
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<meta content="YogiBook - Prenotazione facile YogaSoul" name="description" />
|
|
<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;
|
|
}
|
|
|
|
.events-head {
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
margin-bottom: 4px;
|
|
}
|
|
|
|
.btn-new-event {
|
|
background: #2f7be7;
|
|
border: none;
|
|
color: #fff;
|
|
border-radius: 8px;
|
|
padding: 9px 18px;
|
|
font-weight: 600;
|
|
font-size: 14px;
|
|
white-space: nowrap;
|
|
}
|
|
|
|
.btn-new-event:hover {
|
|
filter: brightness(0.94);
|
|
color: #fff;
|
|
}
|
|
|
|
.events-table thead th {
|
|
font-size: 12px;
|
|
text-transform: uppercase;
|
|
letter-spacing: 0.03em;
|
|
color: #6b7280;
|
|
border-bottom: 2px solid #eef0f3;
|
|
white-space: nowrap;
|
|
}
|
|
|
|
.events-table td {
|
|
vertical-align: middle;
|
|
}
|
|
|
|
.date-group td {
|
|
background: #f7f8fa;
|
|
font-weight: 600;
|
|
color: #4b5563;
|
|
font-size: 13px;
|
|
text-transform: capitalize;
|
|
}
|
|
|
|
.event-name {
|
|
font-weight: 600;
|
|
color: #1f2937;
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 9px;
|
|
}
|
|
|
|
.color-dot {
|
|
display: inline-block;
|
|
width: 12px;
|
|
height: 12px;
|
|
border-radius: 3px;
|
|
flex-shrink: 0;
|
|
}
|
|
|
|
.event-thumb {
|
|
width: 42px;
|
|
height: 42px;
|
|
border-radius: 8px;
|
|
object-fit: cover;
|
|
flex-shrink: 0;
|
|
}
|
|
|
|
.event-thumb.placeholder {
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
font-size: 20px;
|
|
}
|
|
|
|
.event-id {
|
|
color: #9ca3af;
|
|
font-weight: 400;
|
|
font-size: 12px;
|
|
}
|
|
|
|
.seats-pill {
|
|
display: inline-block;
|
|
background: #eef6f1;
|
|
color: #1a7f52;
|
|
font-weight: 700;
|
|
font-size: 13px;
|
|
padding: 2px 10px;
|
|
border-radius: 20px;
|
|
}
|
|
|
|
.seats-pill.full {
|
|
background: #fdecea;
|
|
color: #c0392b;
|
|
}
|
|
|
|
.status-badge {
|
|
display: inline-block;
|
|
font-size: 12px;
|
|
font-weight: 700;
|
|
padding: 3px 10px;
|
|
border-radius: 20px;
|
|
}
|
|
|
|
.btn-act {
|
|
border: 1px solid #e2e4e9;
|
|
background: #fff;
|
|
border-radius: 8px;
|
|
padding: 6px 12px;
|
|
font-size: 13px;
|
|
font-weight: 600;
|
|
color: #374151;
|
|
cursor: pointer;
|
|
transition: background 0.15s, border-color 0.15s;
|
|
white-space: nowrap;
|
|
text-decoration: none;
|
|
}
|
|
|
|
.btn-act:hover {
|
|
background: #f3f4f6;
|
|
color: #111827;
|
|
}
|
|
|
|
.btn-act.danger {
|
|
color: #c0392b;
|
|
border-color: #f2c9c4;
|
|
}
|
|
|
|
.btn-act.danger: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;
|
|
}
|
|
</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">Eventi</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 === 'success') : ?>
|
|
<div class="alert alert-success" role="alert">Evento salvato con successo.</div>
|
|
<?php elseif ($message === 'cancelled') : ?>
|
|
<div class="alert alert-warning" role="alert">Evento annullato.</div>
|
|
<?php elseif ($message === 'error') : ?>
|
|
<div class="alert alert-danger" role="alert">Si è verificato un errore. Controlla i dati e riprova.</div>
|
|
<?php endif; ?>
|
|
|
|
<div class="row">
|
|
<div class="col-12">
|
|
<div class="card admin-card">
|
|
<div class="card-body">
|
|
<div class="events-head">
|
|
<div>
|
|
<div class="section-title">Eventi</div>
|
|
<p class="section-lead mb-0">Ciao <?php echo e($firstname ?? ''); ?>, gestisci qui i tuoi eventi: crea, modifica, vedi i partecipanti o annulla.</p>
|
|
</div>
|
|
<a href="event_form.php" class="btn btn-new-event"><i class="bx bx-plus align-middle"></i> Nuovo evento</a>
|
|
</div>
|
|
|
|
<div class="table-responsive mt-3">
|
|
<table class="table events-table align-middle">
|
|
<thead>
|
|
<tr>
|
|
<th>Orario</th>
|
|
<th>Nome</th>
|
|
<th>Organizzatore</th>
|
|
<th>Prenotato</th>
|
|
<th>Stato</th>
|
|
<th class="text-end">Azioni</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php if (empty($events)) : ?>
|
|
<tr>
|
|
<td colspan="6">
|
|
<div class="empty-state">
|
|
<i class="fas fa-calendar-plus"></i>
|
|
Nessun evento ancora. Crea il primo con "Nuovo evento".
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
<?php else :
|
|
$currentDate = null;
|
|
foreach ($events as $ev) :
|
|
$d = date('Y-m-d', strtotime($ev['starts_at']));
|
|
if ($d !== $currentDate) :
|
|
$currentDate = $d; ?>
|
|
<tr class="date-group">
|
|
<td colspan="6"><?php echo e(dataItaliana($ev['starts_at'], $mesi)); ?></td>
|
|
</tr>
|
|
<?php endif;
|
|
|
|
$organizer = trim((string) $ev['organizer_name']) !== ''
|
|
? $ev['organizer_name']
|
|
: trim(($ev['creator_first'] ?? '') . ' ' . ($ev['creator_last'] ?? ''));
|
|
if ($organizer === '') {
|
|
$organizer = '—';
|
|
}
|
|
|
|
$booked = (int) $ev['booked'];
|
|
$maxSeats = (int) $ev['max_seats'];
|
|
$isFull = $maxSeats > 0 && $booked >= $maxSeats;
|
|
[$stLabel, $stBg, $stColor] = statusBadge($ev['status']);
|
|
|
|
$timeLabel = date('H:i', strtotime($ev['starts_at']));
|
|
if (!empty($ev['ends_at'])) {
|
|
$timeLabel .= ' - ' . date('H:i', strtotime($ev['ends_at']));
|
|
}
|
|
?>
|
|
<tr>
|
|
<td><?php echo e($timeLabel); ?></td>
|
|
<td>
|
|
<div class="event-name">
|
|
<?php if (!empty($ev['cover_image'])) : ?>
|
|
<img class="event-thumb" src="<?php echo e($ev['cover_image']); ?>" alt="">
|
|
<?php else : ?>
|
|
<span class="event-thumb placeholder" style="background: <?php echo e($ev['color']); ?>22;"><i class="bx bx-image" style="color: <?php echo e($ev['color']); ?>;"></i></span>
|
|
<?php endif; ?>
|
|
<span class="color-dot" style="background: <?php echo e($ev['color']); ?>;"></span>
|
|
<span><?php echo e($ev['title']); ?> <span class="event-id">(ID: <?php echo (int) $ev['id']; ?>)</span></span>
|
|
</div>
|
|
</td>
|
|
<td><?php echo e($organizer); ?></td>
|
|
<td>
|
|
<span class="seats-pill <?php echo $isFull ? 'full' : ''; ?>">
|
|
<?php echo $booked; ?> / <?php echo $maxSeats; ?>
|
|
</span>
|
|
</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">
|
|
<a href="event_preview.php?id=<?php echo (int) $ev['id']; ?>" target="_blank" class="btn-act"><i class="bx bx-show"></i> Anteprima</a>
|
|
<a href="event_participants.php?id=<?php echo (int) $ev['id']; ?>" class="btn-act"><i class="bx bx-group"></i> Partecipanti</a>
|
|
<a href="event_form.php?id=<?php echo (int) $ev['id']; ?>" class="btn-act"><i class="bx bx-edit"></i> Modifica</a>
|
|
<?php if ($ev['status'] === 'published' && strtotime($ev['starts_at']) > time()) : ?>
|
|
<a href="event_reminder.php?id=<?php echo (int) $ev['id']; ?>" class="btn-act"><i class="bx bx-bell"></i> Promemoria</a>
|
|
<?php endif; ?>
|
|
<?php if ($ev['status'] !== 'cancelled') : ?>
|
|
<button type="button" class="btn-act danger btn-annulla"
|
|
data-id="<?php echo (int) $ev['id']; ?>"
|
|
data-title="<?php echo e($ev['title']); ?>"
|
|
data-booked="<?php echo $booked; ?>">
|
|
<i class="bx bx-block"></i> Annulla
|
|
</button>
|
|
<?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-annulla').on('click', function() {
|
|
var id = $(this).data('id');
|
|
var title = $(this).data('title');
|
|
var booked = parseInt($(this).data('booked'), 10) || 0;
|
|
|
|
Swal.fire({
|
|
title: "Annullare l'evento?",
|
|
html: '<p style="margin-bottom:12px;">Stai per annullare <strong>' + $('<div>').text(title).html() + '</strong>.</p>' +
|
|
'<div style="text-align:left; background:#f7f8fa; border-radius:8px; padding:12px;">' +
|
|
' <label style="display:flex; align-items:flex-start; gap:8px; cursor:pointer; margin:0;">' +
|
|
' <input type="checkbox" id="notify-check" ' + (booked > 0 ? 'checked' : '') + '>' +
|
|
' <span>Invia email di annullamento ai partecipanti' +
|
|
(booked > 0 ? ' <strong>(' + booked + ' post' + (booked === 1 ? 'o' : 'i') + ' prenotat' + (booked === 1 ? 'o' : 'i') + ')</strong>' : ' <em>(nessun iscritto)</em>') +
|
|
'</span>' +
|
|
' </label>' +
|
|
'</div>',
|
|
icon: 'warning',
|
|
showCancelButton: true,
|
|
confirmButtonText: 'Annulla evento',
|
|
cancelButtonText: 'Chiudi',
|
|
confirmButtonColor: '#e74c3c',
|
|
reverseButtons: true,
|
|
preConfirm: function() {
|
|
return document.getElementById('notify-check').checked ? 1 : 0;
|
|
}
|
|
}).then(function(result) {
|
|
if (result.isConfirmed) {
|
|
window.location.href = 'event_delete.php?id=' + id + '¬ify=' + result.value;
|
|
}
|
|
});
|
|
});
|
|
});
|
|
</script>
|
|
</body>
|
|
|
|
</html>
|