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>
This commit is contained in:
andreandClaude Opus 5.5 committed 2026-09-24 14:58:57 +01:00
1 parent 8a494d59a5
commit f95c9ebc52
27 files changed
+2063 -16

No files matched your search

+28
View File
@@ -7,6 +7,7 @@ $user = require_admin();
$counts = [
'clientes' => (int) $pdo->query("SELECT COUNT(*) FROM users WHERE role = 'client'")->fetchColumn(),
'equipa' => (int) $pdo->query("SELECT COUNT(*) FROM users WHERE role IN ('admin','staff')")->fetchColumn(),
'leads_novos' => db_membership_leads_count_new($pdo),
];
$page_title = 'Painel';
@@ -81,6 +82,33 @@ include __DIR__ . '/../../includes/header.php';
</div>
</a>
</div>
<div class="col-sm-6 col-lg-4">
<a class="card text-decoration-none border-primary shadow-sm h-100" href="<?= base_url('views/admin/memberships/index.php') ?>">
<div class="card-body">
<i class="bi bi-credit-card-2-front-fill fs-3 text-primary mb-2 d-block"></i>
<strong>Mensalidades</strong><?php if ($counts['leads_novos']): ?> <span class="badge bg-danger"><?= $counts['leads_novos'] ?> novo<?= $counts['leads_novos'] > 1 ? 's' : '' ?></span><?php endif; ?>
<p class="text-muted small mb-0">Cartões de preço e pedidos de inscrição</p>
</div>
</a>
</div>
<div class="col-sm-6 col-lg-4">
<a class="card text-decoration-none border-primary shadow-sm h-100" href="<?= base_url('views/admin/reviews/index.php') ?>">
<div class="card-body">
<i class="bi bi-star-fill fs-3 text-primary mb-2 d-block"></i>
<strong>Reviews Google</strong>
<p class="text-muted small mb-0">Reviews do Google na página inicial</p>
</div>
</a>
</div>
<div class="col-sm-6 col-lg-4">
<a class="card text-decoration-none border-primary shadow-sm h-100" href="<?= base_url('views/admin/info/edit.php') ?>">
<div class="card-body">
<i class="bi bi-telephone-fill fs-3 text-primary mb-2 d-block"></i>
<strong>Contactos</strong>
<p class="text-muted small mb-0">Telefone, e-mail, morada e redes sociais</p>
</div>
</a>
</div>
</div>
</div></div>
+52
View File
@@ -0,0 +1,52 @@
<?php
require __DIR__ . '/../../../config/db.php';
require __DIR__ . '/../../../config/functions.php';
$user = require_admin();
$errors = [];
$data = site_info($pdo);
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
csrf_check();
$data = info_from_post($_POST, $errors);
if (!$errors) {
$changed = db_info_save($pdo, $data);
session()->setFlashdata($changed ? 'success' : 'warning', $changed ? 'Contactos atualizados.' : 'Nenhuma alteração.');
header('Location: ' . base_url('views/admin/info/edit.php'));
exit;
}
}
$page_title = 'Contactos';
include __DIR__ . '/../../../includes/header.php';
?>
<div class="container" style="max-width:800px;">
<div class="d-flex justify-content-between align-items-center mb-4">
<h1 class="h3 mb-0">Contactos</h1>
<a class="btn btn-outline-secondary btn-sm" href="<?= base_url('home#contactos') ?>" target="_blank" rel="noopener"><i class="bi bi-box-arrow-up-right me-1"></i>Ver no site</a>
</div>
<p class="text-muted small">Estes dados alimentam a secção de contactos, o rodapé, o botão «Ligar» no telemóvel, o botão de WhatsApp e os dados para o Google (SEO). Campos vazios não aparecem no site.</p>
<?php foreach ($errors as $e): ?><div class="alert alert-danger"><?= htmlspecialchars($e) ?></div><?php endforeach; ?>
<form method="POST" class="card shadow-sm"><div class="card-body">
<?= csrf_field() ?>
<div class="row g-3">
<?php foreach (info_fields() as $key => [$label, $max, $type]): $req = in_array($key, ['name', 'phone'], true); ?>
<?php if ($type === 'textarea'): ?>
<div class="col-12"><label class="form-label" for="f_<?= $key ?>"><?= htmlspecialchars($label) ?></label>
<textarea class="form-control font-monospace small" id="f_<?= $key ?>" name="<?= $key ?>" rows="4"><?= htmlspecialchars((string) ($data[$key] ?? '')) ?></textarea>
<div class="form-text">No Google Maps: Partilhar → Incorporar um mapa → Copiar HTML. Só é aceite um iframe do Google Maps.</div></div>
<?php else: ?>
<div class="col-md-6"><label class="form-label" for="f_<?= $key ?>"><?= htmlspecialchars($label) ?><?= $req ? ' <span class="text-danger">*</span>' : '' ?></label>
<input class="form-control" id="f_<?= $key ?>" type="<?= $type ?>" name="<?= $key ?>"<?= $max ? ' maxlength="' . $max . '"' : '' ?><?= $req ? ' required' : '' ?>
value="<?= htmlspecialchars((string) ($data[$key] ?? '')) ?>"></div>
<?php endif; ?>
<?php endforeach; ?>
</div>
<div class="mt-4 d-flex gap-2">
<button type="submit" class="btn btn-primary">Guardar</button>
<a class="btn btn-outline-secondary" href="<?= base_url('views/admin/dashboard.php') ?>">Cancelar</a>
</div>
</div></form>
</div>
<?php include __DIR__ . '/../../../includes/footer.php'; ?>
+63
View File
@@ -0,0 +1,63 @@
<?php
// Shared membership form fields, rendered inside the <form> of create.php and
// edit.php. Expects $data (see memberships_defaults()).
$price_val = ($data['price'] ?? '') === null ? '' : (string) ($data['price'] ?? '');
if ($price_val !== '' && is_numeric($price_val)) {
$p = (float) $price_val;
$price_val = number_format($p, floor($p) == $p ? 0 : 2, ',', '');
}
?>
<div class="row g-3">
<div class="col-md-8">
<label class="form-label">Nome <span class="text-danger">*</span></label>
<input class="form-control" name="name" required maxlength="100" placeholder="ex.: Off-hours" value="<?= htmlspecialchars($data['name'] ?? '') ?>">
</div>
<div class="col-md-4">
<label class="form-label">Ordem</label>
<input type="number" class="form-control" name="item_order" value="<?= (int) ($data['item_order'] ?? 0) ?>">
<div class="form-text">Menor aparece primeiro.</div>
</div>
<div class="col-12">
<label class="form-label">Descrição curta</label>
<input class="form-control" name="subtitle" maxlength="255" placeholder="ex.: Mensalidade para as horas baixas do ginásio." value="<?= htmlspecialchars($data['subtitle'] ?? '') ?>">
</div>
<div class="col-md-4">
<label class="form-label">Preço (€)</label>
<input class="form-control" name="price" inputmode="decimal" placeholder="ex.: 34,90" value="<?= htmlspecialchars($price_val) ?>">
<div class="form-text">Vazio = «Sob consulta».</div>
</div>
<div class="col-md-5">
<label class="form-label">Texto do preço</label>
<input class="form-control" name="price_suffix" maxlength="60" placeholder="/mês" value="<?= htmlspecialchars($data['price_suffix'] ?? '') ?>">
<div class="form-text">ex.: «/mês» ou «acresce à mensalidade».</div>
</div>
<div class="col-md-3 d-flex align-items-center">
<div class="form-check mt-3">
<input class="form-check-input" type="checkbox" name="is_addon" id="is_addon" value="1" <?= !empty($data['is_addon']) ? 'checked' : '' ?>>
<label class="form-check-label" for="is_addon">Acresce à mensalidade <span class="text-muted small">(mostra «+»)</span></label>
</div>
</div>
<div class="col-12">
<label class="form-label">Incluído</label>
<textarea class="form-control" name="features" rows="5" placeholder="Um ponto por linha"><?= htmlspecialchars($data['features'] ?? '') ?></textarea>
</div>
<div class="col-md-4">
<label class="form-label">Texto do botão</label>
<input class="form-control" name="cta_label" maxlength="40" value="<?= htmlspecialchars($data['cta_label'] ?? 'Inscrever') ?>">
</div>
<div class="col-md-4">
<label class="form-label">Selo do destaque</label>
<input class="form-control" name="featured_label" maxlength="40" value="<?= htmlspecialchars($data['featured_label'] ?? 'Mais popular') ?>">
</div>
<div class="col-md-4 d-flex flex-column justify-content-end gap-1">
<div class="form-check">
<input class="form-check-input" type="checkbox" name="is_featured" id="is_featured" value="1" <?= !empty($data['is_featured']) ? 'checked' : '' ?>>
<label class="form-check-label" for="is_featured">Em destaque</label>
</div>
<div class="form-check">
<input class="form-check-input" type="checkbox" name="is_active" id="is_active" value="1" <?= !empty($data['is_active']) ? 'checked' : '' ?>>
<label class="form-check-label" for="is_active">Visível no site</label>
</div>
</div>
<div class="col-12"><div class="form-text mt-0">Só um cartão pode estar em destaque — ao marcar este, o anterior deixa de estar.</div></div>
</div>
+38
View File
@@ -0,0 +1,38 @@
<?php
require __DIR__ . '/../../../config/db.php';
require __DIR__ . '/../../../config/functions.php';
$user = require_admin();
$errors = [];
$data = memberships_defaults();
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
csrf_check();
$data = memberships_from_post($_POST, $errors);
if (!$errors) {
db_memberships_create($pdo, $data);
session()->setFlashdata('success', 'Mensalidade criada.');
header('Location: ' . base_url('views/admin/memberships/index.php'));
exit;
}
}
$page_title = 'Nova Mensalidade';
include __DIR__ . '/../../../includes/header.php';
?>
<div class="container" style="max-width:800px;">
<div class="d-flex justify-content-between align-items-center mb-4">
<h1 class="h3 mb-0">Nova Mensalidade</h1>
<a class="btn btn-outline-secondary btn-sm" href="index.php"><i class="bi bi-arrow-left me-1"></i>Voltar</a>
</div>
<?php foreach ($errors as $e): ?><div class="alert alert-danger"><?= htmlspecialchars($e) ?></div><?php endforeach; ?>
<form method="POST" class="card shadow-sm"><div class="card-body">
<?= csrf_field() ?>
<?php include __DIR__ . '/_form.php'; ?>
<div class="mt-4 d-flex gap-2">
<button type="submit" class="btn btn-primary">Criar</button>
<a class="btn btn-outline-secondary" href="index.php">Cancelar</a>
</div>
</div></form>
</div>
<?php include __DIR__ . '/../../../includes/footer.php'; ?>
+42
View File
@@ -0,0 +1,42 @@
<?php
require __DIR__ . '/../../../config/db.php';
require __DIR__ . '/../../../config/functions.php';
$user = require_admin();
$id = (int) ($_GET['id'] ?? 0);
$item = $id ? db_memberships_get($pdo, $id) : null;
if (!$item) { header('Location: index.php'); exit; }
$errors = [];
$data = $item;
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
csrf_check();
$data = memberships_from_post($_POST, $errors);
if (!$errors) {
$changed = db_memberships_update($pdo, $id, $data);
session()->setFlashdata($changed ? 'success' : 'warning', $changed ? 'Mensalidade atualizada.' : 'Nenhuma alteração.');
header('Location: ' . base_url('views/admin/memberships/edit.php?id=' . $id));
exit;
}
}
$page_title = 'Editar Mensalidade';
include __DIR__ . '/../../../includes/header.php';
?>
<div class="container" style="max-width:800px;">
<div class="d-flex justify-content-between align-items-center mb-4">
<h1 class="h3 mb-0">Editar Mensalidade</h1>
<a class="btn btn-outline-secondary btn-sm" href="index.php"><i class="bi bi-arrow-left me-1"></i>Voltar</a>
</div>
<?php foreach ($errors as $e): ?><div class="alert alert-danger"><?= htmlspecialchars($e) ?></div><?php endforeach; ?>
<form method="POST" class="card shadow-sm"><div class="card-body">
<?= csrf_field() ?>
<?php include __DIR__ . '/_form.php'; ?>
<div class="mt-4 d-flex gap-2">
<button type="submit" class="btn btn-primary">Atualizar</button>
<a class="btn btn-outline-secondary" href="index.php">Cancelar</a>
</div>
</div></form>
</div>
<?php include __DIR__ . '/../../../includes/footer.php'; ?>
+70
View File
@@ -0,0 +1,70 @@
<?php
require __DIR__ . '/../../../config/db.php';
require __DIR__ . '/../../../config/functions.php';
$user = require_admin();
// Delete / restore are POST + CSRF (csrf_check() only guards POST).
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
csrf_check();
if (isset($_POST['delete'])) {
db_memberships_delete($pdo, (int) $_POST['delete']);
session()->setFlashdata('success', 'Mensalidade apagada.');
} elseif (isset($_POST['restore'])) {
db_memberships_restore($pdo, (int) $_POST['restore']);
session()->setFlashdata('success', 'Mensalidade restaurada.');
}
header('Location: ' . base_url('views/admin/memberships/index.php'));
exit;
}
$items = db_memberships_list($pdo, true);
$new_leads = db_membership_leads_count_new($pdo);
$page_title = 'Mensalidades';
include __DIR__ . '/../../../includes/header.php';
?>
<div class="container">
<div class="d-flex justify-content-between align-items-center flex-wrap gap-2 mb-4">
<h1 class="h3 mb-0">Mensalidades</h1>
<div class="d-flex gap-2">
<a class="btn btn-outline-primary" href="<?= base_url('views/admin/memberships/leads.php') ?>">
<i class="bi bi-inbox me-1"></i>Pedidos de inscrição<?php if ($new_leads): ?> <span class="badge bg-danger"><?= $new_leads ?></span><?php endif; ?>
</a>
<a class="btn btn-primary" href="<?= base_url('views/admin/memberships/create.php') ?>"><i class="bi bi-plus-lg me-1"></i>Adicionar</a>
</div>
</div>
<div class="card shadow-sm"><div class="card-body p-0">
<form method="POST" class="mb-0"><?= csrf_field() ?>
<table class="table table-hover align-middle mb-0">
<thead class="table-light"><tr>
<th>Nome</th><th>Preço</th><th>Estado</th><th>Ordem</th><th style="width:120px">Ações</th>
</tr></thead>
<tbody>
<?php if (!$items): ?>
<tr><td colspan="5" class="text-center text-muted py-4">Nenhuma mensalidade.</td></tr>
<?php else: foreach ($items as $m): $deleted = $m['deleted_at'] !== null; ?>
<tr class="<?= $deleted ? 'text-muted' : '' ?>">
<td><strong><?= htmlspecialchars($m['name']) ?></strong>
<?php if ($m['is_featured']): ?><span class="badge bg-warning text-dark ms-1"><i class="bi bi-star-fill"></i> Destaque</span><?php endif; ?>
<?php if ($m['subtitle'] !== ''): ?><div class="small text-muted"><?= htmlspecialchars($m['subtitle']) ?></div><?php endif; ?></td>
<td class="text-nowrap"><?= htmlspecialchars(membership_price_label($m)) ?> <span class="small text-muted"><?= htmlspecialchars($m['price_suffix']) ?></span></td>
<td><?php if ($deleted): ?><span class="badge bg-secondary">Apagada</span>
<?php elseif ($m['is_active']): ?><span class="badge bg-success">Visível</span>
<?php else: ?><span class="badge bg-light text-dark border">Oculta</span><?php endif; ?></td>
<td><?= (int) $m['item_order'] ?></td>
<td class="text-nowrap">
<?php if ($deleted): ?>
<button class="btn btn-sm btn-outline-info" name="restore" value="<?= (int) $m['id'] ?>">Restaurar</button>
<?php else: ?>
<a class="btn btn-sm btn-outline-primary" href="edit.php?id=<?= (int) $m['id'] ?>"><i class="bi bi-pencil"></i></a>
<button class="btn btn-sm btn-outline-danger" name="delete" value="<?= (int) $m['id'] ?>" onclick="return confirm('Apagar esta mensalidade?')"><i class="bi bi-trash"></i></button>
<?php endif; ?>
</td>
</tr>
<?php endforeach; endif; ?>
</tbody>
</table>
</form>
</div></div>
</div>
<?php include __DIR__ . '/../../../includes/footer.php';
+105
View File
@@ -0,0 +1,105 @@
<?php
require __DIR__ . '/../../../config/db.php';
require __DIR__ . '/../../../config/functions.php';
$user = require_admin();
$statuses = membership_lead_statuses();
$filter = (string) ($_GET['status'] ?? '');
if (!isset($statuses[$filter])) $filter = '';
$self = base_url('views/admin/memberships/leads.php' . ($filter !== '' ? '?status=' . $filter : ''));
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
csrf_check();
if (isset($_POST['delete'])) {
db_membership_lead_delete($pdo, (int) $_POST['delete']);
session()->setFlashdata('success', 'Pedido apagado.');
} elseif (isset($_POST['save'])) {
$id = (int) $_POST['save'];
db_membership_lead_update($pdo, $id, (string) ($_POST['status'][$id] ?? ''), trim((string) ($_POST['notes'][$id] ?? '')));
session()->setFlashdata('success', 'Pedido atualizado.');
}
header('Location: ' . $self);
exit;
}
$leads = db_membership_leads_list($pdo, $filter);
// CSV export of the current filter (Excel-friendly: UTF-8 BOM + ';').
if (isset($_GET['csv'])) {
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename="pedidos-inscricao-' . date('Y-m-d') . '.csv"');
$out = fopen('php://output', 'w');
fwrite($out, "\xEF\xBB\xBF");
fputcsv($out, ['Data', 'Mensalidade', 'Nome', 'Telemóvel', 'E-mail', 'Mensagem', 'Estado', 'Notas', 'Consentimento'], ';', '"', '');
foreach ($leads as $l) {
fputcsv($out, [$l['created_at'], $l['membership_name'], $l['name'], $l['phone'], $l['email'], $l['message'],
$statuses[$l['status']] ?? $l['status'], (string) $l['admin_notes'], $l['consent'] ? 'sim' : 'não'], ';', '"', '');
}
exit;
}
$badge = ['novo' => 'bg-danger', 'contactado' => 'bg-info text-dark', 'inscrito' => 'bg-success', 'descartado' => 'bg-secondary'];
$page_title = 'Pedidos de inscrição';
include __DIR__ . '/../../../includes/header.php';
?>
<div class="container">
<div class="d-flex justify-content-between align-items-center flex-wrap gap-2 mb-3">
<h1 class="h3 mb-0">Pedidos de inscrição</h1>
<div class="d-flex gap-2">
<a class="btn btn-outline-secondary" href="<?= $self . ($filter !== '' ? '&' : '?') ?>csv=1"><i class="bi bi-filetype-csv me-1"></i>Exportar CSV</a>
<a class="btn btn-outline-secondary" href="<?= base_url('views/admin/memberships/index.php') ?>"><i class="bi bi-arrow-left me-1"></i>Mensalidades</a>
</div>
</div>
<p class="text-muted small">Pedidos enviados pelo botão de inscrição dos cartões de mensalidade. Cada pedido também é enviado por e-mail para o endereço dos Contactos.</p>
<ul class="nav nav-pills mb-3">
<li class="nav-item"><a class="nav-link<?= $filter === '' ? ' active' : '' ?>" href="?">Todos</a></li>
<?php foreach ($statuses as $k => $label): ?>
<li class="nav-item"><a class="nav-link<?= $filter === $k ? ' active' : '' ?>" href="?status=<?= $k ?>"><?= $label ?></a></li>
<?php endforeach; ?>
</ul>
<form method="POST" class="card shadow-sm"><div class="card-body p-0">
<?= csrf_field() ?>
<div class="table-responsive">
<table class="table align-middle mb-0">
<thead class="table-light"><tr>
<th>Data</th><th>Mensalidade</th><th>Contacto</th><th>Mensagem</th><th style="min-width:220px">Estado / notas</th><th></th>
</tr></thead>
<tbody>
<?php if (!$leads): ?>
<tr><td colspan="6" class="text-center text-muted py-4">Sem pedidos.</td></tr>
<?php else: foreach ($leads as $l): $id = (int) $l['id']; ?>
<tr>
<td class="small text-nowrap"><?= htmlspecialchars(date('d/m/Y H:i', strtotime($l['created_at']))) ?></td>
<td><?= htmlspecialchars($l['membership_name'] !== '' ? $l['membership_name'] : '—') ?></td>
<td class="small">
<strong><?= htmlspecialchars($l['name']) ?></strong>
<?php if ($l['phone'] !== ''): ?><div><a href="tel:<?= htmlspecialchars(preg_replace('/\s+/', '', $l['phone'])) ?>"><?= htmlspecialchars($l['phone']) ?></a></div><?php endif; ?>
<?php if ($l['email'] !== ''): ?><div><a href="mailto:<?= htmlspecialchars($l['email']) ?>"><?= htmlspecialchars($l['email']) ?></a></div><?php endif; ?>
<?php if ($l['consent']): ?><span class="badge bg-success mt-1" title="<?= htmlspecialchars($l['consent_text'] . ' · IP ' . $l['ip']) ?>">RGPD <i class="bi bi-check-lg"></i></span><?php endif; ?>
</td>
<td class="small" style="max-width:260px;"><?= $l['message'] !== '' ? nl2br(htmlspecialchars($l['message'])) : '<span class="text-muted">—</span>' ?></td>
<td>
<div class="d-flex gap-1 mb-1">
<select class="form-select form-select-sm" name="status[<?= $id ?>]">
<?php foreach ($statuses as $k => $label): ?>
<option value="<?= $k ?>" <?= $l['status'] === $k ? 'selected' : '' ?>><?= $label ?></option>
<?php endforeach; ?>
</select>
<span class="badge <?= $badge[$l['status']] ?? 'bg-secondary' ?> align-self-center"><?= htmlspecialchars($statuses[$l['status']] ?? $l['status']) ?></span>
</div>
<textarea class="form-control form-control-sm" name="notes[<?= $id ?>]" rows="2" placeholder="Notas internas"><?= htmlspecialchars((string) $l['admin_notes']) ?></textarea>
</td>
<td class="text-nowrap">
<button class="btn btn-sm btn-outline-primary" name="save" value="<?= $id ?>" title="Guardar"><i class="bi bi-check-lg"></i></button>
<button class="btn btn-sm btn-outline-danger" name="delete" value="<?= $id ?>" title="Apagar" onclick="return confirm('Apagar este pedido?')"><i class="bi bi-trash"></i></button>
</td>
</tr>
<?php endforeach; endif; ?>
</tbody>
</table>
</div>
</div></form>
</div>
<?php include __DIR__ . '/../../../includes/footer.php';
+161
View File
@@ -0,0 +1,161 @@
<?php
require __DIR__ . '/../../../config/db.php';
require __DIR__ . '/../../../config/functions.php';
$user = require_admin();
$search = null;
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
csrf_check();
$uid = (int) ($user['id'] ?? 0) ?: null;
$action = (string) ($_POST['action'] ?? '');
if ($action === 'save') {
// Key: blank keeps the stored one; the "remover" box clears it.
$key = trim((string) ($_POST['google_places_api_key'] ?? ''));
if (!empty($_POST['clear_key'])) {
db_update_setting($pdo, 'google_places_api_key', '', $uid);
} elseif ($key !== '') {
db_update_setting($pdo, 'google_places_api_key', secret_encrypt($key), $uid);
}
db_update_setting($pdo, 'google_place_id', trim((string) ($_POST['google_place_id'] ?? '')), $uid);
db_update_setting($pdo, 'google_reviews_min_rating', (string) max(1, min(5, (int) ($_POST['min_rating'] ?? 4))), $uid);
db_update_setting($pdo, 'google_reviews_max', (string) max(1, min(5, (int) ($_POST['max'] ?? 3))), $uid);
db_update_setting($pdo, 'google_reviews_cache_hours', (string) max(1, (int) ($_POST['cache_hours'] ?? 24)), $uid);
reviews_cache_clear(); // new settings → next view fetches fresh
session()->setFlashdata('success', 'Definições guardadas.');
header('Location: ' . base_url('views/admin/reviews/index.php'));
exit;
}
if ($action === 'refresh') {
$r = reviews_refresh();
session()->setFlashdata(!empty($r['error']) ? 'error' : 'success',
!empty($r['error']) ? 'Falhou: ' . $r['error'] : 'Reviews atualizadas (' . count($r['reviews'] ?? []) . ' recebidas da Google).');
header('Location: ' . base_url('views/admin/reviews/index.php'));
exit;
}
if ($action === 'search') {
$apiKey = reviews_config()['api_key'];
$q = trim((string) ($_POST['query'] ?? ''));
$search = ($apiKey === '') ? ['error' => 'Guarda primeiro a chave da API.', 'places' => []]
: ($q === '' ? ['error' => 'Escreve o nome do ginásio.', 'places' => []] : reviews_find_place($q, $apiKey));
}
}
$cfg = reviews_config();
$env_key = (string) env('GOOGLE_PLACES_API_KEY', '') !== '';
$cache = reviews_cache_read();
$preview = site_reviews();
$info = site_info($pdo);
$page_title = 'Reviews Google';
include __DIR__ . '/../../../includes/header.php';
?>
<div class="container" style="max-width:900px;">
<div class="d-flex justify-content-between align-items-center mb-3">
<h1 class="h3 mb-0">Reviews Google</h1>
<a class="btn btn-outline-secondary btn-sm" href="<?= base_url('home#reviews') ?>" target="_blank" rel="noopener"><i class="bi bi-box-arrow-up-right me-1"></i>Ver no site</a>
</div>
<p class="text-muted small">A secção mostra as melhores reviews do ginásio no Google, obtidas pela Places API. A Google devolve no máximo 5 reviews (escolhidas por relevância); o site mostra as que têm a classificação mínima definida. Se nenhuma se qualificar, a secção fica escondida.</p>
<div class="card shadow-sm mb-4"><div class="card-body">
<h2 class="h5 mb-3">Configuração</h2>
<form method="POST">
<?= csrf_field() ?>
<input type="hidden" name="action" value="save">
<div class="row g-3">
<div class="col-md-7">
<label class="form-label">Chave da API (Places API — New)</label>
<?php if ($env_key): ?>
<input class="form-control" disabled value="Definida no .env (GOOGLE_PLACES_API_KEY)">
<?php else: ?>
<input class="form-control font-monospace" type="password" name="google_places_api_key" autocomplete="off"
placeholder="<?= $cfg['api_key'] !== '' ? 'Guardada — deixa vazio para manter' : 'AIza…' ?>">
<?php if ($cfg['api_key'] !== ''): ?>
<div class="form-check mt-1"><input class="form-check-input" type="checkbox" name="clear_key" id="clear_key" value="1">
<label class="form-check-label small" for="clear_key">Remover chave guardada</label></div>
<?php endif; ?>
<?php if (!secrets_available()): ?><div class="form-text text-warning">Sem chave de encriptação no .env — a chave fica guardada sem encriptação.</div><?php endif; ?>
<?php endif; ?>
<div class="form-text">Google Cloud Console → ativar «Places API (New)» → Credenciais. Restringe a chave a essa API.</div>
</div>
<div class="col-md-5">
<label class="form-label">Place ID</label>
<input class="form-control font-monospace" name="google_place_id" value="<?= htmlspecialchars($cfg['place_id']) ?>" placeholder="ChIJ…">
<div class="form-text">Não sabes? Usa a pesquisa abaixo.</div>
</div>
<div class="col-md-4">
<label class="form-label">Classificação mínima</label>
<select class="form-select" name="min_rating">
<?php for ($i = 5; $i >= 1; $i--): ?><option value="<?= $i ?>" <?= $cfg['min_rating'] === $i ? 'selected' : '' ?>><?= $i ?> ★<?= $i < 5 ? ' ou mais' : '' ?></option><?php endfor; ?>
</select>
</div>
<div class="col-md-4">
<label class="form-label">Número de reviews</label>
<input type="number" class="form-control" name="max" min="1" max="5" value="<?= $cfg['max'] ?>">
</div>
<div class="col-md-4">
<label class="form-label">Atualizar a cada (horas)</label>
<input type="number" class="form-control" name="cache_hours" min="1" value="<?= $cfg['cache_hours'] ?>">
<div class="form-text">Cada atualização é um pedido pago à Google.</div>
</div>
</div>
<button class="btn btn-primary mt-3">Guardar</button>
</form>
</div></div>
<div class="card shadow-sm mb-4"><div class="card-body">
<h2 class="h5 mb-3">Encontrar o Place ID</h2>
<form method="POST" class="d-flex gap-2">
<?= csrf_field() ?>
<input type="hidden" name="action" value="search">
<input class="form-control" name="query" value="<?= htmlspecialchars((string) ($_POST['query'] ?? trim($info['name'] . ' ' . $info['adress']))) ?>">
<button class="btn btn-outline-primary text-nowrap"><i class="bi bi-search me-1"></i>Procurar</button>
</form>
<?php if ($search !== null): ?>
<?php if ($search['error'] !== ''): ?><div class="alert alert-danger mt-3 mb-0"><?= htmlspecialchars($search['error']) ?></div>
<?php elseif (!$search['places']): ?><div class="alert alert-warning mt-3 mb-0">Sem resultados.</div>
<?php else: ?>
<ul class="list-group mt-3">
<?php foreach ($search['places'] as $p): ?>
<li class="list-group-item d-flex justify-content-between align-items-center gap-2">
<div><strong><?= htmlspecialchars($p['name']) ?></strong>
<?php if ($p['rating'] !== null): ?><span class="small text-muted"> · <?= htmlspecialchars((string) $p['rating']) ?> ★ (<?= (int) $p['total'] ?>)</span><?php endif; ?>
<div class="small text-muted"><?= htmlspecialchars($p['address']) ?></div>
<code class="small"><?= htmlspecialchars($p['id']) ?></code></div>
<button type="button" class="btn btn-sm btn-outline-success text-nowrap" onclick="document.querySelector('[name=google_place_id]').value='<?= htmlspecialchars($p['id'], ENT_QUOTES) ?>';window.scrollTo(0,0);">Usar</button>
</li>
<?php endforeach; ?>
</ul>
<div class="form-text">Depois de «Usar», carrega em Guardar.</div>
<?php endif; ?>
<?php endif; ?>
</div></div>
<div class="card shadow-sm"><div class="card-body">
<div class="d-flex justify-content-between align-items-center mb-3">
<h2 class="h5 mb-0">Estado</h2>
<form method="POST" class="mb-0"><?= csrf_field() ?><input type="hidden" name="action" value="refresh">
<button class="btn btn-sm btn-outline-primary" <?= reviews_configured() ? '' : 'disabled' ?>><i class="bi bi-arrow-clockwise me-1"></i>Atualizar agora</button></form>
</div>
<?php if (!reviews_configured()): ?>
<p class="text-muted mb-0">Por configurar — a secção não aparece no site.</p>
<?php else: ?>
<p class="small mb-2">
Última atualização: <?= !empty($cache['fetched_at']) ? date('d/m/Y H:i', (int) $cache['fetched_at']) : '—' ?>
<?php if (isset($cache['rating'])): ?> · <?= htmlspecialchars(number_format((float) $cache['rating'], 1, ',', '')) ?> ★ em <?= (int) ($cache['total'] ?? 0) ?> avaliações<?php endif; ?>
</p>
<?php if (!empty($cache['error'])): ?><div class="alert alert-danger small">Último erro: <?= htmlspecialchars($cache['error']) ?></div><?php endif; ?>
<?php if ($preview): ?>
<p class="small text-muted mb-2">No site aparecem <?= count($preview['reviews']) ?>:</p>
<?php foreach ($preview['reviews'] as $r): ?>
<div class="border rounded p-2 mb-2 small">
<strong><?= htmlspecialchars($r['author']) ?></strong> · <?= str_repeat('★', $r['rating']) ?> · <span class="text-muted"><?= htmlspecialchars($r['relative']) ?></span>
<div><?= nl2br(htmlspecialchars(mb_strimwidth($r['text'], 0, 240, '…'))) ?></div>
</div>
<?php endforeach; ?>
<?php else: ?>
<p class="text-muted small mb-0">Nenhuma review qualifica neste momento — a secção está escondida.</p>
<?php endif; ?>
<?php endif; ?>
</div></div>
</div>
<?php include __DIR__ . '/../../../includes/footer.php';
+14 -2
View File
@@ -4,7 +4,8 @@ require __DIR__ . '/../../../config/functions.php';
$user = require_admin();
$errors = [];
$data = ['name' => '', 'birthday' => '', 'at' => '', 'status' => 'ativo', 'description' => ''];
$data = ['name' => '', 'title' => '', 'birthday' => '', 'at' => '', 'status' => 'ativo', 'description' => '',
'skills' => '', 'certifications' => ''];
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
csrf_check();
@@ -14,6 +15,9 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
'at' => trim($_POST['at'] ?? ''),
'status' => $_POST['status'] ?? 'ativo',
'description' => trim($_POST['description'] ?? ''),
'title' => mb_substr(trim($_POST['title'] ?? ''), 0, 100),
'skills' => trim($_POST['skills'] ?? ''),
'certifications' => trim($_POST['certifications'] ?? ''),
];
if ($data['name'] === '') $errors[] = 'O nome é obrigatório.';
@@ -70,7 +74,15 @@ include __DIR__ . '/../../../includes/header.php';
</select></div>
<div class="col-md-4"><label class="form-label">Foto</label>
<input type="file" class="form-control" name="photo" accept=".jpg,.jpeg,.png,.gif,.webp"></div>
<div class="col-12"><label class="form-label">Descrição</label>
<div class="col-12"><label class="form-label">Título</label>
<input class="form-control" name="title" maxlength="100" placeholder="ex.: Personal Trainer · Coach CrossFit" value="<?= htmlspecialchars($data['title'] ?? '') ?>">
<div class="form-text">Aparece no site por baixo do nome.</div></div>
<div class="col-md-6"><label class="form-label">Aptidões / Funções</label>
<textarea class="form-control" name="skills" rows="5" placeholder="Uma por linha"><?= htmlspecialchars($data['skills'] ?? '') ?></textarea></div>
<div class="col-md-6"><label class="form-label">Formações</label>
<textarea class="form-control" name="certifications" rows="5" placeholder="Uma por linha"><?= htmlspecialchars($data['certifications'] ?? '') ?></textarea></div>
<div class="col-12"><div class="form-text mt-0">Aptidões e formações aparecem no cartão de detalhe do site (hover no computador, toque no telemóvel).</div></div>
<div class="col-12"><label class="form-label">Descrição <span class="text-muted small">(opcional — aparece no cartão de detalhe)</span></label>
<textarea class="form-control js-wysiwyg" data-wysiwyg-height="200" name="description" rows="3"><?= htmlspecialchars($data['description']) ?></textarea></div>
</div>
<div class="mt-4 d-flex gap-2">
+12 -1
View File
@@ -29,6 +29,9 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
'at' => trim($_POST['at'] ?? ''),
'status' => $_POST['status'] ?? 'ativo',
'description' => trim($_POST['description'] ?? ''),
'title' => mb_substr(trim($_POST['title'] ?? ''), 0, 100),
'skills' => trim($_POST['skills'] ?? ''),
'certifications' => trim($_POST['certifications'] ?? ''),
];
if ($data['name'] === '') $errors[] = 'O nome é obrigatório.';
@@ -92,7 +95,15 @@ include __DIR__ . '/../../../includes/header.php';
<?php endif; ?>
<input type="file" class="form-control" name="photo" accept=".jpg,.jpeg,.png,.gif,.webp">
</div>
<div class="col-12"><label class="form-label">Descrição</label>
<div class="col-12"><label class="form-label">Título</label>
<input class="form-control" name="title" maxlength="100" placeholder="ex.: Personal Trainer · Coach CrossFit" value="<?= htmlspecialchars($data['title'] ?? '') ?>">
<div class="form-text">Aparece no site por baixo do nome.</div></div>
<div class="col-md-6"><label class="form-label">Aptidões / Funções</label>
<textarea class="form-control" name="skills" rows="5" placeholder="Uma por linha"><?= htmlspecialchars($data['skills'] ?? '') ?></textarea></div>
<div class="col-md-6"><label class="form-label">Formações</label>
<textarea class="form-control" name="certifications" rows="5" placeholder="Uma por linha"><?= htmlspecialchars($data['certifications'] ?? '') ?></textarea></div>
<div class="col-12"><div class="form-text mt-0">Aptidões e formações aparecem no cartão de detalhe do site (hover no computador, toque no telemóvel).</div></div>
<div class="col-12"><label class="form-label">Descrição <span class="text-muted small">(opcional — aparece no cartão de detalhe)</span></label>
<textarea class="form-control js-wysiwyg" data-wysiwyg-height="200" name="description" rows="3"><?= htmlspecialchars($data['description'] ?? '') ?></textarea></div>
</div>
<div class="mt-4 d-flex gap-2">
+1 -1
View File
@@ -53,7 +53,7 @@ include __DIR__ . '/../../../includes/header.php';
<?php foreach ($items as $item): ?>
<tr>
<td><?php if ($item['photo']): ?><img src="<?= base_url('uploads/team/foto/' . $item['photo']) ?>" alt="" style="width:40px;height:40px;object-fit:cover;border-radius:50%"><?php else: ?><span style="width:40px;height:40px;border-radius:50%;background:#dee2e6;display:inline-flex;align-items:center;justify-content:center"><i class="bi bi-person text-muted"></i></span><?php endif; ?></td>
<td><strong><?= htmlspecialchars($item['name']) ?></strong></td>
<td><strong><?= htmlspecialchars($item['name']) ?></strong><?php if (!empty($item['title'])): ?><div class="small text-muted"><?= htmlspecialchars($item['title']) ?></div><?php endif; ?></td>
<td><?= htmlspecialchars($item['at'] ?? '—') ?></td>
<td><span class="badge <?= $item['status'] === 'ativo' ? 'bg-success' : 'bg-secondary' ?>"><?= htmlspecialchars($item['status']) ?></span>
<?php if ($item['deleted_at']): ?><span class="badge bg-danger ms-1">apagado</span><?php endif; ?></td>