ver. 0.314: fix wyszukiwarki admin + title zamówienia

- Fix: globalna wyszukiwarka - Content-Type, Cache-Control, POST,
  FETCH_ASSOC, try/catch wrapper
- New: document.title w szczegółach zamówienia = numer zamówienia

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-23 12:32:54 +01:00
parent 8f43f5ab4d
commit 09d266204e
6 changed files with 59 additions and 19 deletions

View File

@@ -73,26 +73,45 @@ class SettingsController
*/
public function globalSearchAjax(): void
{
global $mdb;
header('Content-Type: application/json; charset=utf-8');
header('Cache-Control: no-store');
$phrase = trim((string)\Shared\Helpers\Helpers::get('q'));
if ($phrase === '' || mb_strlen($phrase) < 2) {
try {
$this->executeGlobalSearch();
} catch (\Throwable $e) {
echo json_encode([
'status' => 'ok',
'status' => 'error',
'items' => [],
]);
exit;
}
exit;
}
private function executeGlobalSearch(): void
{
global $mdb;
$phrase = isset($_REQUEST['q']) ? trim((string)$_REQUEST['q']) : '';
if ($phrase === '' || mb_strlen($phrase) < 2) {
echo json_encode(['status' => 'ok', 'items' => []]);
return;
}
$phrase = mb_substr($phrase, 0, 120);
$phraseNormalized = preg_replace('/\s+/', ' ', $phrase);
$phraseNormalized = trim((string)$phraseNormalized);
$phraseNormalized = trim((string)preg_replace('/\s+/', ' ', $phrase));
$like = '%' . $phrase . '%';
$likeNormalized = '%' . $phraseNormalized . '%';
$items = [];
$defaultLang = (string)$this->languagesRepository->defaultLanguage();
$defaultLang = '1';
try {
$defaultLang = (string)$this->languagesRepository->defaultLanguage();
} catch (\Throwable $e) {
// fallback to '1'
}
// --- Produkty ---
try {
$productStmt = $mdb->query(
'SELECT '
@@ -115,7 +134,10 @@ class SettingsController
$productStmt = false;
}
$productRows = $productStmt ? $productStmt->fetchAll() : [];
$productRows = ($productStmt && method_exists($productStmt, 'fetchAll'))
? $productStmt->fetchAll(\PDO::FETCH_ASSOC)
: [];
if (is_array($productRows)) {
foreach ($productRows as $row) {
$productId = (int)($row['id'] ?? 0);
@@ -147,6 +169,7 @@ class SettingsController
}
}
// --- Zamowienia ---
try {
$orderStmt = $mdb->query(
'SELECT '
@@ -178,7 +201,10 @@ class SettingsController
$orderStmt = false;
}
$orderRows = $orderStmt ? $orderStmt->fetchAll() : [];
$orderRows = ($orderStmt && method_exists($orderStmt, 'fetchAll'))
? $orderStmt->fetchAll(\PDO::FETCH_ASSOC)
: [];
if (is_array($orderRows)) {
foreach ($orderRows as $row) {
$orderId = (int)($row['id'] ?? 0);
@@ -214,11 +240,12 @@ class SettingsController
}
}
echo json_encode([
'status' => 'ok',
'items' => array_slice($items, 0, 20),
]);
exit;
$json = json_encode(['status' => 'ok', 'items' => array_slice($items, 0, 20)]);
if ($json === false) {
echo json_encode(['status' => 'ok', 'items' => []], JSON_UNESCAPED_UNICODE);
return;
}
echo $json;
}
/**