feat: aulas experimentais guardadas, anti-spam partilhado nos formulários, audit das escritas
- Pedido de aula experimental passa a ficar em trial_leads (por ginásio) ANTES do email: sem SMTP o visitante já não vê «erro» e o pedido não se perde. Gestão → Aulas experimentais: estados, notas, CSV (auditado), apagar para a lixeira; aviso «sem email» quando o aviso não saiu. - Aula experimental, inscrição e eventos usam o anti-spam do platform-tools (honeypot, carimbo assinado com tempo mínimo, prova de JS, limite por IP, pontuação de conteúdo) e o bloqueio de IP, em vez de honeypots locais. Recusas ficam em blocked_submissions; resposta igual à de sucesso. Falha aberto se o módulo rebentar. - Checkbox de consentimento da aula experimental passa a ser guardada. - Audit das escritas de conteúdo: criar/editar equipa, modalidades, eventos, mensalidades, pedidos de inscrição, galerias, horário (incl. arrastar no calendário), horas, contactos e ginásios, com antes/depois campo a campo (audit_row/audit_change). Exportação CSV de inscrições auditada. - .table-responsive em todas as tabelas do backoffice. - Migração: database/migration_20260926_trial_leads.sql (só cria tabelas). Testado numa cópia da BD de produção: 63/63 verificações HTTP. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
0e8b53f620
commit
04c8c83e66
29 files changed
+480
-29
No files matched your search
+36
-1
@@ -37,6 +37,12 @@ if ($nome === '' || $telefone === '' || !filter_var($email, FILTER_VALIDATE_EMAI
|
||||
agendar_redirect('erro');
|
||||
}
|
||||
|
||||
// Anti-spam partilhado (config/functions_forms.php). Recusado = mesma resposta
|
||||
// de sucesso; fica em blocked_submissions.
|
||||
if (public_form_screen($pdo, 'trial', 'trial_leads', $nome, $mensagem) !== null) {
|
||||
agendar_redirect('ok');
|
||||
}
|
||||
|
||||
// Pretty-print the preferred date if it parses; otherwise leave it blank.
|
||||
$data_fmt = '';
|
||||
if ($data !== '') {
|
||||
@@ -44,6 +50,29 @@ if ($data !== '') {
|
||||
$data_fmt = ($d && $d->format('Y-m-d') === $data) ? $d->format('d/m/Y') : '';
|
||||
}
|
||||
|
||||
// O pedido fica guardado ANTES do email: sem SMTP (ou com ele em baixo) o
|
||||
// pedido já não se perde — aparece em Gestão → Aulas experimentais.
|
||||
$consent_text = 'Li e aceito a Política de Privacidade.';
|
||||
$leadId = 0;
|
||||
try {
|
||||
$leadId = db_trial_lead_create($pdo, [
|
||||
'gym_id' => (int) $gym['id'],
|
||||
'name' => $nome,
|
||||
'email' => $email,
|
||||
'phone' => $telefone,
|
||||
'preferred_date' => $data_fmt !== '' ? $data : '',
|
||||
'period' => $periodo,
|
||||
'message' => $mensagem,
|
||||
'consent' => !empty($_POST['consent']),
|
||||
'consent_text' => !empty($_POST['consent']) ? $consent_text : '',
|
||||
'ip' => client_ip(),
|
||||
'user_agent' => (string) ($_SERVER['HTTP_USER_AGENT'] ?? ''),
|
||||
]);
|
||||
} catch (Throwable $e) {
|
||||
// Tabela por migrar: segue só por email, como antes.
|
||||
error_log('[agendar] ' . $e->getMessage());
|
||||
}
|
||||
|
||||
$info = site_info($pdo, (int) $gym['id']);
|
||||
$to = $info['email'] !== '' ? $info['email'] : EMAIL_FROM;
|
||||
|
||||
@@ -81,4 +110,10 @@ $id = enqueue_email([
|
||||
'context_type' => 'fitme_trial',
|
||||
]);
|
||||
|
||||
agendar_redirect(flush_message($id) ? 'ok' : 'erro');
|
||||
$sent = false;
|
||||
try { $sent = flush_message($id); } catch (Throwable $e) { error_log('[agendar] email: ' . $e->getMessage()); }
|
||||
if ($sent && $leadId) db_trial_lead_mark_emailed($pdo, $leadId);
|
||||
|
||||
// Guardado = sucesso para o visitante, mesmo que o email falhe (fica na fila e
|
||||
// o pedido está no backoffice). Só é erro se não ficou em lado nenhum.
|
||||
agendar_redirect(($leadId || $sent) ? 'ok' : 'erro');
|
||||
+5
-4
@@ -21,8 +21,10 @@ if ($can_view && $_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
csrf_check();
|
||||
$back = base_url('evento/' . rawurlencode($event['slug']));
|
||||
|
||||
// Honeypot: a filled "website" field means a bot — silently accept & drop.
|
||||
if (trim((string) ($_POST['website'] ?? '')) !== '') {
|
||||
// Anti-spam partilhado (config/functions_forms.php). Recusado = mesma
|
||||
// resposta de sucesso; fica em blocked_submissions.
|
||||
if (public_form_screen($pdo, 'evento', 'event_leads',
|
||||
(string) ($_POST['lead_name'] ?? ''), (string) ($_POST['lead_message'] ?? '')) !== null) {
|
||||
header('Location: ' . $back . '?ok=1#inscricao');
|
||||
exit;
|
||||
}
|
||||
@@ -197,8 +199,7 @@ require __DIR__ . '/_open.php';
|
||||
|
||||
<form method="POST" action="<?= base_url('evento/' . rawurlencode($event['slug'])) ?>#inscricao" class="event-form">
|
||||
<?= csrf_field() ?>
|
||||
<!-- honeypot: must stay empty -->
|
||||
<input type="text" name="website" tabindex="-1" autocomplete="off" class="event-hp" aria-hidden="true">
|
||||
<?= public_form_trap('evento') /* honeypot + carimbo + prova de JS */ ?>
|
||||
<div class="event-form-grid">
|
||||
<div class="event-field">
|
||||
<label>Nome *</label>
|
||||
|
||||
+3
-2
@@ -754,6 +754,7 @@ if ($on('personal_trainer')):
|
||||
</div>
|
||||
<form class="trial-form" method="post" action="<?= htmlspecialchars(gym_url($gym, 'agendar')) ?>">
|
||||
<?= csrf_field() ?>
|
||||
<?= public_form_trap('trial') /* honeypot + carimbo + prova de JS */ ?>
|
||||
<div class="form-row">
|
||||
<div class="col-12 col-md-6 mb-3">
|
||||
<input type="text" name="nome" required placeholder="Nome *" aria-label="Nome">
|
||||
@@ -780,7 +781,7 @@ if ($on('personal_trainer')):
|
||||
</div>
|
||||
<div class="col-12">
|
||||
<label class="consent-check">
|
||||
<input type="checkbox" required>
|
||||
<input type="checkbox" name="consent" value="1" required>
|
||||
<span>Li e aceito a <a href="<?= base_url('home/privacidade') ?>" target="_blank" rel="noopener">Política de Privacidade</a>.</span>
|
||||
</label>
|
||||
</div>
|
||||
@@ -813,7 +814,7 @@ if ($memberships):
|
||||
</div>
|
||||
<form class="trial-form" method="post" action="<?= htmlspecialchars(gym_url($gym, 'inscricao')) ?>">
|
||||
<?= csrf_field() ?>
|
||||
<input type="text" name="website" class="event-hp" tabindex="-1" autocomplete="off" aria-hidden="true">
|
||||
<?= public_form_trap('inscricao') /* honeypot + carimbo + prova de JS */ ?>
|
||||
<div class="form-row">
|
||||
<div class="col-12 mb-3">
|
||||
<select name="membership_id" aria-label="Mensalidade" required>
|
||||
|
||||
+7
-2
@@ -27,8 +27,13 @@ function inscricao_redirect(string $status): void {
|
||||
exit;
|
||||
}
|
||||
|
||||
// Honeypot: a filled "website" field means a bot — pretend success, store nothing.
|
||||
if (trim((string) ($_POST['website'] ?? '')) !== '') inscricao_redirect('ok');
|
||||
// Anti-spam partilhado (config/functions_forms.php): honeypot, carimbo com
|
||||
// tempo mínimo, prova de JS, limite por IP e conteúdo. Recusado = mesma
|
||||
// resposta de sucesso; fica em blocked_submissions.
|
||||
if (public_form_screen($pdo, 'inscricao', 'membership_leads',
|
||||
(string) ($_POST['nome'] ?? ''), (string) ($_POST['mensagem'] ?? '')) !== null) {
|
||||
inscricao_redirect('ok');
|
||||
}
|
||||
|
||||
$consent_text = 'Autorizo o contacto e o tratamento dos meus dados para efeitos desta inscrição, nos termos da Política de Privacidade.';
|
||||
$membership = db_memberships_get($pdo, (int) ($_POST['membership_id'] ?? 0));
|
||||
|
||||
Reference in new issue
Block a user