Files
fitme3070.pt/site/agendar.php
T
andreandClaude Opus 5.5 5e300fc341 feat: vários ginásios (/3070/ e /<código postal>/), CRUD de ginásios, modalidades após a galeria
Estrutura multi-ginásio: as mesmas secções do site, conteúdo próprio por
ginásio, e cada um numa pasta da URL com o código postal da zona.

- migration_20260926_gyms: tabela gyms (pasta, nome, localidade, publicado,
  principal, secções visíveis, título/imagem do header, SEO, galeria, Place ID,
  página CrossFit) com o FitMe 3070 como ginásio 1 em /3070/; gym_id em team,
  modalidades (o horário segue a modalidade), work_hours, memberships,
  membership_leads e website_offer (tudo o existente → ginásio 1); events com
  gym_id NULL = todos; fitme3070_info passa a uma linha por ginásio (id = gym).
- Site: /<pasta>/, /<pasta>/crossfit, /<pasta>/agendar|inscricao. Ginásio por
  publicar → 404 para o público, pré-visualização (com faixa) para a equipa.
  / e /home → 301 para o ginásio principal (a manter a query); com mais de um
  ginásio publicado, a raiz passa a uma página para escolher. Secções
  desligadas não aparecem nem no menu; menu, canonical, JSON-LD, sitemap,
  formulários, e-mails e reviews (Place ID e cache) são do ginásio.
- Backoffice: Gestão → Ginásios (criar/editar/apagar, secções, e «começar
  com o conteúdo de» outro ginásio — cópias independentes) e o seletor
  «A editar» no topo; equipa, modalidades, horários, horário de
  funcionamento, mensalidades, pedidos, contactos e reviews trabalham sobre o
  ginásio escolhido, e um registo de outro ginásio não abre.
- Modalidades passam para logo a seguir à galeria das instalações.
- Galeria sem cantos arredondados (raio da marca).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-25 07:26:40 +01:00

85 lines
3.3 KiB
PHP

<?php
// POST handler for the "aula experimental" (trial class) modal on the homepage.
// Builds a booking-request email and relays it to id.andmore.pt's centralized
// mail service via the enqueue_email()/flush_message() façade, then redirects
// back to #contactos with an ?agendar=ok|erro flag the homepage renders.
//
// Reached via .htaccess: ^home/agendar/?$ → site/agendar.php
require_once __DIR__ . '/../config/db.php';
require_once __DIR__ . '/../config/functions.php';
// The gym comes from the URL folder (/<slug>/agendar); the old /home/agendar
// route has no ?gym and falls back to the default gym.
$gym = site_gym($pdo) ?? db_gyms_default($pdo) ?? gym_fallback();
$GLOBALS['_gym'] = $gym;
// Only POST is meaningful here; anything else just goes to the gym's page.
if (($_SERVER['REQUEST_METHOD'] ?? 'GET') !== 'POST') {
header('Location: ' . gym_url($gym));
exit;
}
csrf_check(); // 403s and exits on a bad/missing token
function agendar_redirect(string $status): void {
header('Location: ' . gym_url(current_gym(), '?agendar=' . $status . '#contactos'));
exit;
}
$nome = trim((string) ($_POST['nome'] ?? ''));
$email = trim((string) ($_POST['email'] ?? ''));
$telefone = trim((string) ($_POST['telefone'] ?? ''));
$data = trim((string) ($_POST['data'] ?? ''));
$periodo = trim((string) ($_POST['periodo'] ?? ''));
$mensagem = trim((string) ($_POST['mensagem'] ?? ''));
if ($nome === '' || $telefone === '' || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
agendar_redirect('erro');
}
// Pretty-print the preferred date if it parses; otherwise leave it blank.
$data_fmt = '';
if ($data !== '') {
$d = DateTime::createFromFormat('Y-m-d', $data);
$data_fmt = ($d && $d->format('Y-m-d') === $data) ? $d->format('d/m/Y') : '';
}
$info = site_info($pdo, (int) $gym['id']);
$to = $info['email'] !== '' ? $info['email'] : EMAIL_FROM;
$e = static fn($v) => htmlspecialchars((string) $v, ENT_QUOTES, 'UTF-8');
$rows = [
'Nome' => $nome,
'Telemóvel' => $telefone,
'E-mail' => $email,
'Dia preferido' => $data_fmt,
'Período preferido'=> $periodo,
'Mensagem' => $mensagem,
];
$body = '<h2 style="margin:0 0 16px;">Novo pedido de aula experimental</h2><table cellpadding="6" style="border-collapse:collapse;font-family:Arial,sans-serif;font-size:14px;">';
foreach ($rows as $label => $value) {
if (trim((string) $value) === '') continue;
$body .= '<tr><td style="font-weight:bold;vertical-align:top;">' . $e($label)
. ':</td><td>' . nl2br($e($value)) . '</td></tr>';
}
$body .= '</table><p style="font-family:Arial,sans-serif;font-size:13px;color:#666;margin-top:18px;">'
. 'Pedido enviado através do formulário do site ' . $e($gym['name']) . '. Responde diretamente a '
. $e($email) . ' ou liga para ' . $e($telefone) . '.</p>';
$alt = "Novo pedido de aula experimental\n\n";
foreach ($rows as $label => $value) {
if (trim((string) $value) === '') continue;
$alt .= "$label: $value\n";
}
$id = enqueue_email([
'to_address' => $to,
'to_name' => $info['name'] !== '' ? $info['name'] : $gym['name'],
'subject' => 'Pedido de aula experimental — ' . $nome,
'body' => $body,
'alt_body' => $alt,
'context_type' => 'fitme_trial',
]);
agendar_redirect(flush_message($id) ? 'ok' : 'erro');