- URL 하드코딩 → .env APP_URL 기반 동적 URL로 변경 - DB 연결 하드코딩 → .env 기반으로 변경 - MySQL strict mode DATE 오류 수정
61 lines
1.6 KiB
PHP
61 lines
1.6 KiB
PHP
<?php
|
|
require_once($_SERVER['DOCUMENT_ROOT'] . "/session.php");
|
|
|
|
// 검색 조건 받기
|
|
$exit_direction = $_GET['exit_direction'] ?? '';
|
|
$searchKeyword = $_GET['searchKeyword'] ?? '';
|
|
|
|
// shutterbox.json 파일 읽기
|
|
$jsonFile = $_SERVER['DOCUMENT_ROOT'].'/shutterbox/shutterbox.json';
|
|
$shutterboxData = [];
|
|
|
|
if (file_exists($jsonFile)) {
|
|
$jsonContent = file_get_contents($jsonFile);
|
|
$shutterboxData = json_decode($jsonContent, true);
|
|
if (!is_array($shutterboxData)) {
|
|
$shutterboxData = [];
|
|
}
|
|
}
|
|
|
|
// 검색 조건에 따라 필터링
|
|
$filteredData = [];
|
|
|
|
foreach ($shutterboxData as $item) {
|
|
// 점검구 형태 필터
|
|
if (!empty($exit_direction) && $item['exit_direction'] !== $exit_direction) {
|
|
continue;
|
|
}
|
|
|
|
// 검색어 필터
|
|
if (!empty($searchKeyword)) {
|
|
$searchTrimmed = str_replace(' ', '', $searchKeyword);
|
|
$searchFields = [
|
|
$item['search_keyword'] ?? '',
|
|
$item['exit_direction'] ?? '',
|
|
$item['front_bottom_width'] ?? '',
|
|
$item['rail_width'] ?? '',
|
|
$item['box_width'] ?? '',
|
|
$item['box_height'] ?? ''
|
|
];
|
|
|
|
$found = false;
|
|
foreach ($searchFields as $field) {
|
|
if (stripos($field, $searchTrimmed) !== false) {
|
|
$found = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (!$found) {
|
|
continue;
|
|
}
|
|
}
|
|
|
|
// 필터링을 통과한 항목 저장
|
|
$filteredData[] = $item;
|
|
}
|
|
|
|
// JSON 형태로 결과 출력
|
|
header('Content-Type: application/json');
|
|
echo json_encode($filteredData);
|
|
?>
|