/inscricao); the old /home/inscricao // route has no ?gym and falls back to the default gym. $gym = site_gym($pdo) ?? db_gyms_default($pdo) ?? gym_fallback(); $GLOBALS['_gym'] = $gym; if (($_SERVER['REQUEST_METHOD'] ?? 'GET') !== 'POST') { header('Location: ' . gym_url($gym, '#mensalidades')); exit; } csrf_check(); // 403s and exits on a bad/missing token function inscricao_redirect(string $status): void { header('Location: ' . gym_url(current_gym(), '?inscricao=' . $status . '#mensalidades')); exit; } // 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)); if ($membership && ($membership['deleted_at'] !== null || !$membership['is_active'] || (int) $membership['gym_id'] !== (int) $gym['id'])) $membership = null; $lead = [ 'gym_id' => (int) $gym['id'], 'membership_id' => $membership ? (int) $membership['id'] : null, 'membership_name' => $membership ? $membership['name'] : '', 'name' => trim((string) ($_POST['nome'] ?? '')), 'phone' => trim((string) ($_POST['telefone'] ?? '')), 'email' => trim((string) ($_POST['email'] ?? '')), 'message' => trim((string) ($_POST['mensagem'] ?? '')), 'consent' => !empty($_POST['consent']) ? 1 : 0, 'consent_text' => $consent_text, // IP real atrás do proxy (config/env.php) — o primeiro valor do // X-Forwarded-For é escrito pelo cliente. 'ip' => client_ip(), 'user_agent' => (string) ($_SERVER['HTTP_USER_AGENT'] ?? ''), ]; if ($lead['name'] === '' || $lead['phone'] === '' || !$lead['consent'] || ($lead['email'] !== '' && !filter_var($lead['email'], FILTER_VALIDATE_EMAIL))) { inscricao_redirect('erro'); } try { db_membership_lead_create($pdo, $lead); } catch (Throwable $e) { error_log('[inscricao] ' . $e->getMessage()); inscricao_redirect('erro'); } // Notify the gym. Best effort: the request is already stored. try { $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 = [ 'Mensalidade' => $lead['membership_name'], 'Nome' => $lead['name'], 'Telemóvel' => $lead['phone'], 'E-mail' => $lead['email'], 'Mensagem' => $lead['message'], ]; $body = '
| ' . $e($label) . ': | ' . nl2br($e($value)) . ' |
' . 'Pedido guardado no backoffice (Mensalidades → Pedidos de inscrição).
'; $id = enqueue_email([ 'to_address' => $to, 'to_name' => $info['name'] !== '' ? $info['name'] : APP_NAME, 'subject' => 'Pedido de inscrição' . ($lead['membership_name'] !== '' ? ' (' . $lead['membership_name'] . ')' : '') . ' — ' . $lead['name'], 'body' => $body, 'alt_body' => $alt, 'context_type' => 'fitme_inscricao', ]); flush_message($id); } catch (Throwable $e) { error_log('[inscricao] email: ' . $e->getMessage()); } inscricao_redirect('ok');