Auditoria 6.3 apontava dashboard.php (2×), user/index.php e
user/profile.php como as únicas vistas com SQL direto, quebrando a
convenção da frota (config/functions_*.php como camada de models). As
quatro passam a chamar db_users_count_clients(), db_users_count_team(),
db_users_list() e db_user_update_profile() — mesmo SQL, mesmos
parâmetros, só movido para onde o resto do código já vai buscar dados.
Nota: views/admin/gyms/{create,edit}.php e views/admin/reviews/index.php
também têm SQL direto, mas não estavam no âmbito dos "3 vistas" da
auditoria (entraram depois, no trabalho de multi-ginásio) — por tratar
numa próxima passagem.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
52 lines
2.4 KiB
PHP
52 lines
2.4 KiB
PHP
<?php
|
|
require __DIR__ . '/../../config/db.php';
|
|
require __DIR__ . '/../../config/functions.php';
|
|
$user = require_admin();
|
|
|
|
$users = db_users_list($pdo);
|
|
|
|
include __DIR__ . '/../../includes/header.php';
|
|
?>
|
|
<div class="container">
|
|
<h1 class="h3 mb-4">Utilizadores</h1>
|
|
<div class="card shadow-sm"><div class="card-body">
|
|
<div class="table-responsive">
|
|
<table class="am-datatable table table-hover align-middle">
|
|
<thead><tr>
|
|
<th>Nome</th><th>Email</th><th>Perfil</th><th>Ativo</th>
|
|
<th>Palavra-passe</th><th>Último acesso</th><th></th>
|
|
</tr></thead>
|
|
<tbody>
|
|
<?php foreach ($users as $u): ?>
|
|
<tr>
|
|
<td><?= htmlspecialchars($u['name']) ?></td>
|
|
<td><?= htmlspecialchars($u['email']) ?></td>
|
|
<td><span class="badge text-bg-secondary"><?= htmlspecialchars(role_label($u['role'])) ?></span></td>
|
|
<td><?= $u['is_active'] ? '<i class="bi bi-check-circle text-success"></i>' : '<i class="bi bi-x-circle text-muted"></i>' ?></td>
|
|
<td>
|
|
<?php if (!empty($u['password_hash'])): ?>
|
|
<i class="bi bi-key-fill text-success" title="Definida"></i>
|
|
<?php else: ?>
|
|
<span class="badge text-bg-warning-subtle text-warning-emphasis">Por definir</span>
|
|
<?php endif; ?>
|
|
</td>
|
|
<td class="small text-muted">
|
|
<?php if ($u['last_login_at']): ?>
|
|
<?= htmlspecialchars(format_date_pt($u['last_login_at'])) ?>
|
|
· <?= htmlspecialchars(parse_user_agent((string) $u['last_login_ua'])) ?>
|
|
<?php else: ?>—<?php endif; ?>
|
|
</td>
|
|
<td class="text-end">
|
|
<a class="btn btn-sm btn-outline-secondary"
|
|
href="<?= base_url('views/user/set_password.php?id=' . (int) $u['id']) ?>"
|
|
title="Gerir palavra-passe"><i class="bi bi-key"></i></a>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div></div>
|
|
</div>
|
|
<?php include __DIR__ . '/../../includes/footer.php'; ?>
|