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>
104 lines
5.3 KiB
PHP
104 lines
5.3 KiB
PHP
<?php
|
|
require __DIR__ . '/../../../config/db.php';
|
|
require __DIR__ . '/../../../config/functions.php';
|
|
$user = require_admin();
|
|
|
|
// Lixeira: tudo o que foi apagado no backoffice. Restaurar é sempre possível;
|
|
// eliminar de vez só depois de TRASH_RETENTION_DAYS dias — trash_purge() volta
|
|
// a verificar a data no próprio DELETE, por isso um POST forjado antes do prazo
|
|
// não apaga nada.
|
|
$types = trash_types();
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
csrf_check();
|
|
$type = (string) ($_POST['type'] ?? '');
|
|
$id = (int) ($_POST['id'] ?? 0);
|
|
if (!isset($types[$type]) || $id < 1) {
|
|
session()->setFlashdata('error', 'Pedido inválido.');
|
|
} elseif (isset($_POST['restore'])) {
|
|
trash_restore($pdo, $type, $id)
|
|
? session()->setFlashdata('success', $types[$type]['label'] . ' restaurado(a).')
|
|
: session()->setFlashdata('error', 'Não foi possível restaurar (já não está na lixeira?).');
|
|
} elseif (isset($_POST['purge'])) {
|
|
trash_purge($pdo, $type, $id)
|
|
? session()->setFlashdata('success', $types[$type]['label'] . ' eliminado(a) definitivamente.')
|
|
: session()->setFlashdata('error', 'Só é possível eliminar de vez ao fim de ' . TRASH_RETENTION_DAYS . ' dias na lixeira.');
|
|
}
|
|
header('Location: ' . base_url('views/admin/trash/index.php'));
|
|
exit;
|
|
}
|
|
|
|
$items = trash_list($pdo);
|
|
|
|
if (isset($_GET['csv'])) {
|
|
$rows = [];
|
|
foreach ($items as $it) {
|
|
$rows[] = [$it['label'], $it['title'], $it['deleted_at'], $it['deleted_by_name'] ?? ''];
|
|
}
|
|
csv_export('trash', 'lixeira', 'Exportação CSV da lixeira', ['Tipo', 'Registo', 'Apagado em', 'Por'], $rows);
|
|
}
|
|
|
|
$page_title = 'Lixeira';
|
|
include __DIR__ . '/../../../includes/header.php';
|
|
?>
|
|
<div class="container">
|
|
<div class="d-flex justify-content-between align-items-center mb-2">
|
|
<h1 class="h3 mb-0">Lixeira</h1>
|
|
<div class="d-flex align-items-center gap-2">
|
|
<span class="badge bg-secondary"><?= count($items) ?></span>
|
|
<a class="btn btn-outline-secondary btn-sm" href="?csv=1"><i class="bi bi-filetype-csv me-1"></i>Exportar CSV</a>
|
|
</div>
|
|
</div>
|
|
<p class="text-muted small mb-4">
|
|
O que se apaga no backoffice fica aqui. Pode ser restaurado a qualquer momento;
|
|
só pode ser eliminado de vez depois de <?= (int) TRASH_RETENTION_DAYS ?> dias na lixeira.
|
|
</p>
|
|
|
|
<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>Tipo</th><th>Registo</th><th>Apagado em</th><th>Por</th><th class="text-end">Ações</th>
|
|
</tr></thead>
|
|
<tbody>
|
|
<?php if (!$items): ?>
|
|
<tr><td colspan="5" class="text-center text-muted py-4">A lixeira está vazia.</td></tr>
|
|
<?php else: foreach ($items as $it): ?>
|
|
<tr>
|
|
<td class="small text-nowrap">
|
|
<?= htmlspecialchars($it['label']) ?>
|
|
<?php if ($it['personal']): ?><span class="badge bg-warning text-dark ms-1" title="Contém dados pessoais">RGPD</span><?php endif; ?>
|
|
</td>
|
|
<td><?= htmlspecialchars((string) $it['title']) ?></td>
|
|
<td class="small text-nowrap"><?= htmlspecialchars(date('d/m/Y H:i', strtotime((string) $it['deleted_at']))) ?></td>
|
|
<td class="small"><?= htmlspecialchars((string) ($it['deleted_by_name'] ?? '—')) ?></td>
|
|
<td class="text-end text-nowrap">
|
|
<form method="POST" class="d-inline">
|
|
<?= csrf_field() ?>
|
|
<input type="hidden" name="type" value="<?= htmlspecialchars($it['type']) ?>">
|
|
<input type="hidden" name="id" value="<?= (int) $it['id'] ?>">
|
|
<button class="btn btn-sm btn-outline-info" name="restore" value="1"><i class="bi bi-arrow-counterclockwise me-1"></i>Restaurar</button>
|
|
</form>
|
|
<?php if ($it['can_purge']): ?>
|
|
<form method="POST" class="d-inline" onsubmit="return confirm('Eliminar de vez? Esta ação não pode ser desfeita.')">
|
|
<?= csrf_field() ?>
|
|
<input type="hidden" name="type" value="<?= htmlspecialchars($it['type']) ?>">
|
|
<input type="hidden" name="id" value="<?= (int) $it['id'] ?>">
|
|
<button class="btn btn-sm btn-outline-danger" name="purge" value="1"><i class="bi bi-x-octagon me-1"></i>Eliminar de vez</button>
|
|
</form>
|
|
<?php else: ?>
|
|
<button class="btn btn-sm btn-outline-secondary" disabled
|
|
title="Pode ser eliminado de vez daqui a <?= (int) $it['days_left'] ?> dia(s)">
|
|
<i class="bi bi-hourglass-split me-1"></i><?= (int) $it['days_left'] ?> dia(s)
|
|
</button>
|
|
<?php endif; ?>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; endif; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div></div>
|
|
</div>
|
|
<?php include __DIR__ . '/../../../includes/footer.php';
|