- 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>
64 lines
3.5 KiB
PHP
64 lines
3.5 KiB
PHP
<?php
|
|
// ─── Contactos (fitme3070_info, linha id=1) ───────────────────────────────────
|
|
// Single-row table read by site_info() (functions_site.php) — contact section,
|
|
// footer, mobile "Ligar" bar, WhatsApp button and the SEO JSON-LD all take their
|
|
// values from here, so one save updates every place.
|
|
// Used by views/admin/info/edit.php.
|
|
|
|
// field => [label, max length, input type]. Order is the form order.
|
|
function info_fields(): array {
|
|
return [
|
|
'name' => ['Nome do ginásio', 200, 'text'],
|
|
'adress' => ['Morada', 200, 'text'],
|
|
'phone' => ['Telefone principal', 25, 'tel'],
|
|
'telephone' => ['Telefone secundário', 25, 'tel'],
|
|
'whatsapp' => ['WhatsApp (só dígitos, ex.: 351964201137)', 13, 'text'],
|
|
'email' => ['E-mail', 100, 'email'],
|
|
'website' => ['Website', 100, 'text'],
|
|
'instagram' => ['Instagram (URL)', 200, 'url'],
|
|
'facebook' => ['Facebook (URL)', 200, 'url'],
|
|
'messenger' => ['Messenger (URL)', 200, 'url'],
|
|
'google_maps_link' => ['Google Maps — link', 255, 'url'],
|
|
'google_maps' => ['Google Maps — código embed (iframe)', 0, 'textarea'],
|
|
];
|
|
}
|
|
|
|
function info_from_post(array $post, array &$errors): array {
|
|
$data = [];
|
|
foreach (info_fields() as $key => [$label, $max, $type]) {
|
|
$v = trim((string) ($post[$key] ?? ''));
|
|
if ($key === 'whatsapp') $v = preg_replace('/\D+/', '', $v);
|
|
if ($max > 0 && mb_strlen($v) > $max) $errors[] = "«{$label}» tem mais de {$max} caracteres.";
|
|
if ($v !== '' && $type === 'email' && !filter_var($v, FILTER_VALIDATE_EMAIL)) $errors[] = 'O e-mail não é válido.';
|
|
if ($v !== '' && $type === 'url' && !preg_match('~^https?://~i', $v)) $errors[] = "«{$label}» tem de começar por https://";
|
|
$data[$key] = $v;
|
|
}
|
|
// Only a Google Maps iframe survives; anything else is dropped here rather
|
|
// than stored and filtered on every page view.
|
|
$data['google_maps'] = clean_map_embed($data['google_maps']);
|
|
if ($data['name'] === '') $errors[] = 'O nome é obrigatório.';
|
|
if ($data['phone'] === '') $errors[] = 'O telefone principal é obrigatório.';
|
|
return $data;
|
|
}
|
|
|
|
function db_info_save(PDO $pdo, array $data): bool {
|
|
$cols = array_keys(info_fields());
|
|
// One row per gym (id = gyms.id): the gym being edited in the backoffice.
|
|
$gid = admin_gym_id();
|
|
$__before = audit_row($pdo, 'fitme3070_info', 'id', (int) $gid);
|
|
$exists = (bool) $pdo->query("SELECT COUNT(*) FROM fitme3070_info WHERE id = " . $gid)->fetchColumn();
|
|
$vals = array_map(fn($c) => $data[$c] ?? '', $cols);
|
|
if ($exists) {
|
|
$sets = implode(', ', array_map(fn($c) => "`$c` = ?", $cols));
|
|
$stmt = $pdo->prepare("UPDATE fitme3070_info SET $sets, updated_at = NOW() WHERE id = " . $gid);
|
|
} else {
|
|
$names = implode(', ', array_map(fn($c) => "`$c`", $cols));
|
|
$marks = implode(', ', array_fill(0, count($cols), '?'));
|
|
$stmt = $pdo->prepare("INSERT INTO fitme3070_info (id, $names, updated_at) VALUES (" . $gid . ", $marks, NOW())");
|
|
}
|
|
$stmt->execute($vals);
|
|
$__r = $stmt->rowCount() > 0;
|
|
audit_change($pdo, 'info', 'fitme3070_info', 'id', (int) $gid, $__before ? 'update' : 'create', $__before, 'name');
|
|
return $__r;
|
|
}
|