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

121 lines
4.4 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']) : '';
$item_sep = isset($_POST['item_sep']) ? trim($_POST['item_sep']) : '';
$model_UA = isset($_POST['model_UA']) ? trim($_POST['model_UA']) : '';
$item_spec = isset($_POST['item_spec']) ? trim($_POST['item_spec']) : '';
$itemName = isset($_POST['itemName']) ? trim($_POST['itemName']) : '';
$material = isset($_POST['material']) ? trim($_POST['material']) : '';
$firstitem = isset($_POST['firstitem']) ? trim($_POST['firstitem']) : '';
$item_bending = isset($_POST['item_bending']) ? trim($_POST['item_bending']) : '';
$response = array('success' => false, 'data' => null, 'message' => '');
try {
$pdo = db_connect();
// 품목 검색어가 있는 경우
if (!empty($search_keyword)) {
$sql = "SELECT num, itemName, item_sep, model_UA, item_spec, material, search_keyword, item_bending 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($item_sep)) {
$where_conditions[] = "item_sep = :item_sep";
$params[':item_sep'] = $item_sep;
}
if (!empty($model_UA)) {
$where_conditions[] = "model_UA = :model_UA";
$params[':model_UA'] = $model_UA;
}
if (!empty($formatted_spec)) {
$where_conditions[] = "item_spec = :item_spec";
$params[':item_spec'] = $formatted_spec;
}
// 추가 검색 조건들
if (!empty($material)) {
$where_conditions[] = "material = :material";
$params[':material'] = $material;
}
if (!empty($firstitem)) {
$where_conditions[] = "firstitem = :firstitem";
$params[':firstitem'] = $firstitem;
}
if (!empty($itemName)) {
$where_conditions[] = "itemName = :itemName";
$params[':itemName'] = $itemName;
}
$sql = "SELECT num, itemName, item_sep, model_UA, item_spec, material, search_keyword, item_bending 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);
?>