- URL 하드코딩 → .env APP_URL 기반 동적 URL로 변경 - DB 연결 하드코딩 → .env 기반으로 변경 - MySQL strict mode DATE 오류 수정
128 lines
4.9 KiB
PHP
128 lines
4.9 KiB
PHP
<?php
|
|
// 기초절곡정보 검색
|
|
require_once($_SERVER['DOCUMENT_ROOT'] . "/session.php");
|
|
require_once($_SERVER['DOCUMENT_ROOT'] . "/lib/mydb.php");
|
|
|
|
// POST 데이터 받기
|
|
$search_keyword = isset($_POST['search_keyword']) ? trim($_POST['search_keyword']) : '';
|
|
$itemName = isset($_POST['itemName']) ? trim($_POST['itemName']) : '';
|
|
$material = isset($_POST['material']) ? trim($_POST['material']) : '';
|
|
$item_bending = isset($_POST['item_bending']) ? trim($_POST['item_bending']) : '';
|
|
$exit_direction = isset($_POST['exit_direction']) ? trim($_POST['exit_direction']) : '';
|
|
$front_bottom_width = isset($_POST['front_bottom_width']) ? trim($_POST['front_bottom_width']) : '';
|
|
$rail_width = isset($_POST['rail_width']) ? trim($_POST['rail_width']) : '';
|
|
$box_width = isset($_POST['box_width']) ? trim($_POST['box_width']) : '';
|
|
$box_height = isset($_POST['box_height']) ? trim($_POST['box_height']) : '';
|
|
|
|
$response = array('success' => false, 'data' => null, 'message' => '');
|
|
|
|
try {
|
|
$pdo = db_connect();
|
|
|
|
// 품목 검색어가 있는 경우
|
|
if (!empty($search_keyword)) {
|
|
$sql = "SELECT num, itemName, item_spec, material, search_keyword, item_bending, exit_direction, front_bottom_width, rail_width, box_width, box_height FROM {$DB}.bending
|
|
WHERE search_keyword LIKE :search_keyword
|
|
ORDER BY num DESC
|
|
LIMIT 1";
|
|
|
|
$stmh = $pdo->prepare($sql);
|
|
$stmh->bindValue(':search_keyword', '%' . $search_keyword . '%');
|
|
$stmh->execute();
|
|
|
|
$row = $stmh->fetch(PDO::FETCH_ASSOC);
|
|
|
|
if ($row) {
|
|
$response['success'] = true;
|
|
$response['data'] = $row;
|
|
$response['message'] = '품목검색어로 검색된 결과입니다.';
|
|
} else {
|
|
$response['message'] = '품목검색어로 검색된 결과가 없습니다.';
|
|
}
|
|
}
|
|
// 품목 검색어가 없는 경우 - 조건별 검색 (품목명은 '셔터박스'로 고정)
|
|
else {
|
|
// 규격을 120*70 형태로 변환
|
|
$formatted_spec = '';
|
|
if (!empty($item_spec)) {
|
|
// 기존 규격에서 가로*세로 형태로 변환
|
|
// 예: 120*70 형태로 변환
|
|
$formatted_spec = $item_spec;
|
|
}
|
|
|
|
// 조건별 검색 쿼리 구성 (절곡그룹은 찾기)
|
|
$where_conditions = array("item_bending = :item_bending");
|
|
$params = array(':item_bending' => $item_bending);
|
|
|
|
if (!empty($exit_direction)) {
|
|
$where_conditions[] = "exit_direction = :exit_direction";
|
|
$params[':exit_direction'] = $exit_direction;
|
|
}
|
|
|
|
if (!empty($front_bottom_width)) {
|
|
$where_conditions[] = "front_bottom_width = :front_bottom_width";
|
|
$params[':front_bottom_width'] = $front_bottom_width;
|
|
}
|
|
|
|
if (!empty($rail_width)) {
|
|
$where_conditions[] = "rail_width = :rail_width";
|
|
$params[':rail_width'] = $rail_width;
|
|
}
|
|
|
|
if (!empty($box_width)) {
|
|
$where_conditions[] = "box_width = :box_width";
|
|
$params[':box_width'] = $box_width;
|
|
}
|
|
|
|
if (!empty($box_height)) {
|
|
$where_conditions[] = "box_height = :box_height";
|
|
$params[':box_height'] = $box_height;
|
|
}
|
|
|
|
// 추가 검색 조건들
|
|
if (!empty($material)) {
|
|
$where_conditions[] = "material = :material";
|
|
$params[':material'] = $material;
|
|
}
|
|
|
|
if (!empty($itemName)) {
|
|
$where_conditions[] = "itemName = :itemName";
|
|
$params[':itemName'] = $itemName;
|
|
}
|
|
|
|
|
|
$sql = "SELECT num, itemName, material, search_keyword, item_bending, exit_direction, front_bottom_width, rail_width, box_width, box_height FROM {$DB}.bending
|
|
WHERE " . implode(' AND ', $where_conditions) . "
|
|
ORDER BY num DESC
|
|
LIMIT 1";
|
|
|
|
$stmh = $pdo->prepare($sql);
|
|
|
|
// 파라미터 바인딩
|
|
foreach ($params as $key => $value) {
|
|
$stmh->bindValue($key, $value);
|
|
}
|
|
|
|
$stmh->execute();
|
|
$row = $stmh->fetch(PDO::FETCH_ASSOC);
|
|
|
|
if ($row) {
|
|
$response['success'] = true;
|
|
$response['data'] = $row;
|
|
$response['message'] = '조건별 검색으로 찾은 결과입니다.';
|
|
} else {
|
|
$row['num'] = '';
|
|
$response['data'] = $row;
|
|
$response['success'] = false;
|
|
$response['message'] = '조건에 맞는 결과가 없습니다.';
|
|
}
|
|
}
|
|
|
|
} catch (PDOException $e) {
|
|
$response['message'] = '검색 중 오류가 발생했습니다: ' . $e->getMessage();
|
|
}
|
|
|
|
// JSON 응답
|
|
header('Content-Type: application/json; charset=utf-8');
|
|
echo json_encode($response, JSON_UNESCAPED_UNICODE);
|
|
?>
|