Files
sam-kd/shutterbox/search_shutterbox_json.php
hskwon aca1767eb9 초기 커밋: 5130 레거시 시스템
- URL 하드코딩 → .env APP_URL 기반 동적 URL로 변경
- DB 연결 하드코딩 → .env 기반으로 변경
- MySQL strict mode DATE 오류 수정
2025-12-10 20:14:31 +09:00

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);
?>