Lisää saatavuuskyselyjen keräys ja listausnäkymä
Jokainen nettisivujen kautta tehty saatavuustarkistus tallennetaan tietokantaan (osoite, postinumero, kaupunki, tulos, IP, referer). Kyselyt näkyvät Asiakkaat > Saatavuuskyselyt -välilehdellä sivutettuna taulukkona. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
38
api.php
38
api.php
@@ -1215,12 +1215,48 @@ switch ($action) {
|
||||
}
|
||||
}
|
||||
|
||||
// Tallenna kysely tietokantaan
|
||||
try {
|
||||
_dbExecute(
|
||||
"INSERT INTO availability_queries (company_id, osoite, postinumero, kaupunki, saatavilla, ip_address, user_agent, referer, created_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
[
|
||||
$matchedCompany['id'],
|
||||
$_GET['osoite'] ?? '',
|
||||
$_GET['postinumero'] ?? '',
|
||||
$_GET['kaupunki'] ?? '',
|
||||
$found ? 1 : 0,
|
||||
getClientIp(),
|
||||
substr($_SERVER['HTTP_USER_AGENT'] ?? '', 0, 500),
|
||||
substr($_SERVER['HTTP_REFERER'] ?? '', 0, 500),
|
||||
date('Y-m-d H:i:s'),
|
||||
]
|
||||
);
|
||||
} catch (\Throwable $e) { /* logitus ei saa kaataa API-vastausta */ }
|
||||
|
||||
echo json_encode(['saatavilla' => $found]);
|
||||
break;
|
||||
|
||||
// ---------- SAATAVUUSKYSELYT ----------
|
||||
case 'availability_queries':
|
||||
requireAuth();
|
||||
$companyId = requireCompanyOrParam();
|
||||
$limit = (int)($_GET['limit'] ?? 100);
|
||||
$offset = (int)($_GET['offset'] ?? 0);
|
||||
if ($limit > 500) $limit = 500;
|
||||
|
||||
$total = (int)_dbFetchScalar("SELECT COUNT(*) FROM availability_queries WHERE company_id = ?", [$companyId]);
|
||||
$rows = _dbFetchAll(
|
||||
"SELECT id, osoite, postinumero, kaupunki, saatavilla, ip_address, referer, created_at
|
||||
FROM availability_queries WHERE company_id = ? ORDER BY created_at DESC LIMIT ? OFFSET ?",
|
||||
[$companyId, $limit, $offset]
|
||||
);
|
||||
echo json_encode(['total' => $total, 'queries' => $rows]);
|
||||
break;
|
||||
|
||||
// ---------- CONFIG (admin, yrityskohtainen) ----------
|
||||
case 'config':
|
||||
requireAdmin();
|
||||
requireAuth();
|
||||
$companyId = requireCompany();
|
||||
$globalConf = dbLoadConfig();
|
||||
echo json_encode([
|
||||
|
||||
Reference in New Issue
Block a user