75 lines
4.0 KiB
PHP
75 lines
4.0 KiB
PHP
<?php
|
|
require __DIR__ . '/../../../config/db.php';
|
|
require __DIR__ . '/../../../config/functions.php';
|
|
$user = require_admin();
|
|
|
|
// Handle delete BEFORE any output
|
|
if (isset($_GET['delete']) && is_numeric($_GET['delete'])) {
|
|
csrf_check();
|
|
db_team_delete($pdo, (int) $_GET['delete']);
|
|
session()->setFlashdata('success', 'Membro apagado.');
|
|
header('Location: ' . base_url('views/admin/team/index.php'));
|
|
exit;
|
|
}
|
|
|
|
// Optimize existing photos (resize/compress to the team cap)
|
|
if (isset($_POST['optimize'])) {
|
|
csrf_check();
|
|
$stats = img_optimize_dir(__DIR__ . '/../../../uploads/team/foto/', IMG_MAX_TEAM);
|
|
session()->setFlashdata($stats['failed'] ? 'warning' : 'success', img_stats_message($stats));
|
|
header('Location: ' . base_url('views/admin/team/index.php'));
|
|
exit;
|
|
}
|
|
|
|
$items = db_team_list($pdo);
|
|
$page_title = 'Equipa';
|
|
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">Equipa</h1>
|
|
<div class="d-flex gap-2">
|
|
<form method="POST" class="mb-0">
|
|
<?= csrf_field() ?>
|
|
<button type="submit" name="optimize" value="1" class="btn btn-outline-success"
|
|
title="Redimensiona e comprime as fotos da equipa para o máximo de <?= IMG_MAX_TEAM ?>px"
|
|
onclick="return confirm('Otimizar todas as fotos da equipa (máx. <?= IMG_MAX_TEAM ?>px)? Os ficheiros originais serão substituídos.')">
|
|
<i class="bi bi-arrows-angle-contract me-1"></i>Otimizar fotos
|
|
</button>
|
|
</form>
|
|
<a class="btn btn-primary" href="<?= base_url('views/admin/team/create.php') ?>"><i class="bi bi-plus-lg me-1"></i>Adicionar Membro</a>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card shadow-sm"><div class="card-body p-0">
|
|
<table class="table table-hover align-middle mb-0">
|
|
<thead class="table-light"><tr>
|
|
<th style="width:60px">Foto</th><th>Nome</th><th>Área</th><th>Estado</th><th style="width:120px">Ações</th>
|
|
</tr></thead>
|
|
<tbody>
|
|
<?php if (!$items): ?>
|
|
<tr><td colspan="5" class="text-center text-muted py-4">Nenhum membro. Clique "Adicionar Membro" para começar.</td></tr>
|
|
<?php else: ?>
|
|
<?php foreach ($items as $item): ?>
|
|
<tr>
|
|
<td><?php if ($item['photo']): ?><img src="<?= base_url('uploads/team/foto/' . $item['photo']) ?>" alt="" style="width:40px;height:40px;object-fit:cover;border-radius:50%"><?php else: ?><span style="width:40px;height:40px;border-radius:50%;background:#dee2e6;display:inline-flex;align-items:center;justify-content:center"><i class="bi bi-person text-muted"></i></span><?php endif; ?></td>
|
|
<td><strong><?= htmlspecialchars($item['name']) ?></strong></td>
|
|
<td><?= htmlspecialchars($item['at'] ?? '—') ?></td>
|
|
<td><span class="badge <?= $item['status'] === 'ativo' ? 'bg-success' : 'bg-secondary' ?>"><?= htmlspecialchars($item['status']) ?></span>
|
|
<?php if ($item['deleted_at']): ?><span class="badge bg-danger ms-1">apagado</span><?php endif; ?></td>
|
|
<td>
|
|
<?php if ($item['deleted_at']): ?>
|
|
<a class="btn btn-sm btn-outline-info" href="edit.php?id=<?= $item['id'] ?>&restore=1">Restaurar</a>
|
|
<?php else: ?>
|
|
<a class="btn btn-sm btn-outline-primary" href="edit.php?id=<?= $item['id'] ?>"><i class="bi bi-pencil"></i></a>
|
|
<a class="btn btn-sm btn-outline-danger" href="?delete=<?= $item['id'] ?>" onclick="return confirm('Apagar este membro?')"><i class="bi bi-trash"></i></a>
|
|
<?php endif; ?>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; endif; ?>
|
|
</tbody>
|
|
</table>
|
|
</div></div>
|
|
</div>
|
|
<?php include __DIR__ . '/../../../includes/footer.php';
|