From 64dc02f4322fef19368f3f49ee088060906c7fb4 Mon Sep 17 00:00:00 2001 From: Jukka Lampikoski Date: Fri, 13 Mar 2026 02:23:40 +0200 Subject: [PATCH] =?UTF-8?q?Korjaa=20saatavuuskyselyt:=20n=C3=A4yt=C3=A4=20?= =?UTF-8?q?kaikkien=20yritysten=20kyselyt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- api.php | 18 +++++++++++++----- index.html | 5 +++-- script.js | 3 ++- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/api.php b/api.php index 6c40b6b..0a07f68 100644 --- a/api.php +++ b/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; diff --git a/index.html b/index.html index d2621f1..8da7295 100644 --- a/index.html +++ b/index.html @@ -4,7 +4,7 @@ Noxus HUB - + @@ -210,6 +210,7 @@ Kaupunki Tulos Lähde + Yritys @@ -2262,6 +2263,6 @@ - + diff --git a/script.js b/script.js index 554f68e..a60f8f4 100644 --- a/script.js +++ b/script.js @@ -3520,7 +3520,7 @@ async function loadAvailabilityQueries(page = 0) { countEl.textContent = `Yhteensä ${data.total} kyselyä`; if (data.queries.length === 0) { - tbody.innerHTML = 'Ei vielä kyselyjä'; + tbody.innerHTML = 'Ei vielä kyselyjä'; } 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) { ${esc(q.kaupunki)} ${badge} ${esc(source)} + ${esc(q.company_nimi || q.company_id || '')} `; }).join(''); }