Novo helper csv_export() (config/functions.php): CSV Excel-friendly (BOM UTF-8 + ';') e cada exportação fica no audit_log (RGPD: exportar dados pessoais tem de ser rastreável). Botão "Exportar CSV" em todas as listagens do backoffice: equipa, eventos, galerias, ginásios, horário, mensalidades, modalidades, horário de funcionamento e lixeira (pedidos de inscrição e aulas experimentais já tinham). Fecha a metade "exportação com permissões e audit" do item 6.9 (a única parte que o relatório considera ganho real à escala atual). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
97 lines
5.2 KiB
PHP
97 lines
5.2 KiB
PHP
<?php
|
|
require __DIR__ . '/../../../config/db.php';
|
|
require __DIR__ . '/../../../config/functions.php';
|
|
$user = require_admin();
|
|
|
|
// Handle delete BEFORE any output
|
|
// POST + CSRF: um link GET podia ser disparado a partir de outro site.
|
|
if (isset($_POST['delete']) && is_numeric($_POST['delete'])) {
|
|
csrf_check();
|
|
db_events_delete($pdo, (int) $_POST['delete']);
|
|
session()->setFlashdata('success', 'Evento apagado — fica na lixeira 30 dias.');
|
|
header('Location: ' . base_url('views/admin/events/index.php'));
|
|
exit;
|
|
}
|
|
|
|
$items = db_events_list($pdo, true); // include soft-deleted so they can be restored
|
|
|
|
if (isset($_GET['csv'])) {
|
|
$rows = [];
|
|
foreach ($items as $item) {
|
|
$rows[] = [$item['title'], $item['summary'] ?? '', format_date_pt((string) $item['publish_from']), format_date_pt((string) $item['publish_until']), events_status($item), db_event_leads_count($pdo, (int) $item['e_id'])];
|
|
}
|
|
csv_export('event', 'eventos', 'Exportação CSV de eventos', ['Evento', 'Resumo', 'Início', 'Fim', 'Estado', 'Leads'], $rows);
|
|
}
|
|
|
|
// Status badge styling + label (PT).
|
|
$badge = [
|
|
'active' => ['bg-success', 'Ativo'],
|
|
'scheduled' => ['bg-info text-dark', 'Agendado'],
|
|
'expired' => ['bg-secondary', 'Expirado'],
|
|
'inactive' => ['bg-warning text-dark', 'Inativo'],
|
|
'deleted' => ['bg-dark', 'Apagado'],
|
|
];
|
|
|
|
$page_title = 'Eventos';
|
|
include __DIR__ . '/../../../includes/header.php';
|
|
?>
|
|
<div class="container">
|
|
<div class="d-flex justify-content-between align-items-center mb-4">
|
|
<h1 class="h3 mb-0">Eventos</h1>
|
|
<div class="d-flex gap-2">
|
|
<a class="btn btn-outline-secondary" href="?csv=1"><i class="bi bi-filetype-csv me-1"></i>Exportar CSV</a>
|
|
<a class="btn btn-primary" href="<?= base_url('views/admin/events/create.php') ?>"><i class="bi bi-plus-lg me-1"></i>Adicionar Evento</a>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card shadow-sm"><div class="card-body p-0">
|
|
<div class="table-responsive">
|
|
<table class="table table-hover align-middle mb-0">
|
|
<thead class="table-light"><tr>
|
|
<th>Evento</th><th>Estado</th><th>Janela de publicação</th><th class="text-center">Leads</th><th style="width:160px">Ações</th>
|
|
</tr></thead>
|
|
<tbody>
|
|
<?php if (!$items): ?>
|
|
<tr><td colspan="5" class="text-center text-muted py-4">Nenhum evento. <a href="<?= base_url('views/admin/events/create.php') ?>">Criar o primeiro</a>.</td></tr>
|
|
<?php else: ?>
|
|
<?php foreach ($items as $item):
|
|
$status = events_status($item);
|
|
[$cls, $lbl] = $badge[$status] ?? ['bg-light text-dark', $status];
|
|
$leads = db_event_leads_count($pdo, (int) $item['e_id']);
|
|
?>
|
|
<tr<?= $item['deleted_at'] ? ' class="opacity-50"' : '' ?>>
|
|
<td>
|
|
<strong><?= htmlspecialchars($item['title']) ?></strong>
|
|
<?php if ($item['summary']): ?><div class="small text-muted text-truncate" style="max-width:340px;"><?= htmlspecialchars($item['summary']) ?></div><?php endif; ?>
|
|
<div class="small text-muted">/evento/<?= htmlspecialchars($item['slug']) ?></div>
|
|
</td>
|
|
<td><span class="badge <?= $cls ?>"><?= $lbl ?></span></td>
|
|
<td class="small">
|
|
<?= htmlspecialchars(format_date_pt((string) $item['publish_from'])) ?>
|
|
→
|
|
<?= htmlspecialchars(format_date_pt((string) $item['publish_until'])) ?>
|
|
</td>
|
|
<td class="text-center"><?= $leads > 0 ? '<span class="badge bg-primary">' . $leads . '</span>' : '<span class="text-muted">0</span>' ?></td>
|
|
<td>
|
|
<?php if ($item['deleted_at']): ?>
|
|
<form method="POST" action="<?= base_url('views/admin/events/edit.php?id=' . $item['e_id'] . '&restore=1') ?>" class="d-inline">
|
|
<?= csrf_field() ?>
|
|
<button class="btn btn-sm btn-outline-info">Restaurar</button>
|
|
</form>
|
|
<?php else: ?>
|
|
<?php if (events_is_live($item)): ?>
|
|
<a class="btn btn-sm btn-outline-secondary" href="<?= base_url('evento/' . rawurlencode($item['slug'])) ?>" target="_blank" rel="noopener" title="Ver página"><i class="bi bi-box-arrow-up-right"></i></a>
|
|
<?php endif; ?>
|
|
<a class="btn btn-sm btn-outline-primary" href="edit.php?id=<?= $item['e_id'] ?>"><i class="bi bi-pencil"></i></a>
|
|
<form method="POST" class="d-inline" onsubmit="return confirm('Apagar este evento?')"><?= csrf_field() ?><button class="btn btn-sm btn-outline-danger" name="delete" value="<?= (int) $item['e_id'] ?>" aria-label="Apagar"><i class="bi bi-trash"></i></button></form>
|
|
<?php endif; ?>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; endif; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div></div>
|
|
</div>
|
|
<?php include __DIR__ . '/../../../includes/footer.php';
|