Files
fitme3070.pt/config/functions_info.php
T
andreandClaude Opus 5.5 f95c9ebc52 feat: contactos editáveis, equipa com título/aptidões, mensalidades e reviews Google
- Contactos: nova página no backoffice (fitme3070_info) e 964 201 137 como
  telefone principal; o telefone secundário só aparece quando existe.
- Equipa: título, aptidões/funções e formações; o cartão mostra foto, nome e
  título e abre um cartão horizontal de detalhe (hover no desktop, toque no
  telemóvel) sem mexer na grelha.
- Mensalidades: cartões editáveis com um destaque, modal de inscrição que
  guarda o pedido (RGPD + estado + campos reservados para o CRM) e avisa o
  ginásio por e-mail; lista de pedidos com estados, notas e CSV.
- Reviews Google via Places API (New), filtradas por classificação mínima e
  em cache configurável; página de configuração com pesquisa do Place ID.
- Assets com ?v=<mtime>: site/assets é servido com cache imutável de 1 ano.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-24 14:58:57 +01:00

59 lines
3.2 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());
$exists = (bool) $pdo->query("SELECT COUNT(*) FROM fitme3070_info WHERE id = 1")->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 = 1");
} 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 (1, $marks, NOW())");
}
$stmt->execute($vals);
return $stmt->rowCount() > 0;
}