Korjaa saatavuuskyselyt: näytä kaikkien yritysten kyselyt
Endpoint näytti vain aktiivisen yrityksen kyselyt, mutta kyselyt tallennetaan API-avaimen yrityksen alle. Nyt näytetään kaikkien käyttäjän yritysten kyselyt + yrityssarake taulukkoon. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
18
api.php
18
api.php
@@ -1240,16 +1240,24 @@ switch ($action) {
|
||||
// ---------- 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]);
|
||||
// Näytä kaikkien käyttäjän yritysten kyselyt
|
||||
$userCompanyIds = $_SESSION['companies'] ?? [];
|
||||
if (empty($userCompanyIds)) {
|
||||
echo json_encode(['total' => 0, 'queries' => []]);
|
||||
break;
|
||||
}
|
||||
$placeholders = implode(',', array_fill(0, count($userCompanyIds), '?'));
|
||||
$total = (int)_dbFetchScalar("SELECT COUNT(*) FROM availability_queries WHERE company_id IN ($placeholders)", $userCompanyIds);
|
||||
$params = array_merge($userCompanyIds, [$limit, $offset]);
|
||||
$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]
|
||||
"SELECT aq.id, aq.company_id, c.nimi as company_nimi, aq.osoite, aq.postinumero, aq.kaupunki, aq.saatavilla, aq.ip_address, aq.referer, aq.created_at
|
||||
FROM availability_queries aq LEFT JOIN companies c ON c.id = aq.company_id
|
||||
WHERE aq.company_id IN ($placeholders) ORDER BY aq.created_at DESC LIMIT ? OFFSET ?",
|
||||
$params
|
||||
);
|
||||
echo json_encode(['total' => $total, 'queries' => $rows]);
|
||||
break;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Noxus HUB</title>
|
||||
<link rel="stylesheet" href="style.css?v=20260313j">
|
||||
<link rel="stylesheet" href="style.css?v=20260313k">
|
||||
</head>
|
||||
<body>
|
||||
<!-- Login -->
|
||||
@@ -210,6 +210,7 @@
|
||||
<th>Kaupunki</th>
|
||||
<th>Tulos</th>
|
||||
<th>Lähde</th>
|
||||
<th>Yritys</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody></tbody>
|
||||
@@ -2262,6 +2263,6 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="script.js?v=20260313j"></script>
|
||||
<script src="script.js?v=20260313k"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -3520,7 +3520,7 @@ async function loadAvailabilityQueries(page = 0) {
|
||||
countEl.textContent = `Yhteensä ${data.total} kyselyä`;
|
||||
|
||||
if (data.queries.length === 0) {
|
||||
tbody.innerHTML = '<tr><td colspan="6" style="text-align:center;color:#888;padding:2rem;">Ei vielä kyselyjä</td></tr>';
|
||||
tbody.innerHTML = '<tr><td colspan="7" style="text-align:center;color:#888;padding:2rem;">Ei vielä kyselyjä</td></tr>';
|
||||
} else {
|
||||
tbody.innerHTML = data.queries.map(q => {
|
||||
const date = q.created_at ? q.created_at.replace('T', ' ').substring(0, 16) : '';
|
||||
@@ -3539,6 +3539,7 @@ async function loadAvailabilityQueries(page = 0) {
|
||||
<td>${esc(q.kaupunki)}</td>
|
||||
<td>${badge}</td>
|
||||
<td style="font-size:0.8rem;color:#888;">${esc(source)}</td>
|
||||
<td style="font-size:0.8rem;color:#888;">${esc(q.company_nimi || q.company_id || '')}</td>
|
||||
</tr>`;
|
||||
}).join('');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user