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

262 lines
10 KiB
PHP

<?php
// 셔터박스 데이터 초기화
$box_data = [];
// echo $WebSite;
// $eList를 순회하며 데이터 생성
foreach ($eList as $item) {
$boxSize = trim($item['col37']); // 셔터박스 크기
if ($boxSize == 'custom') {
$boxSize = trim($item['col37_custom']);
}
$boxdirection = $item['col37_boxdirection'];
$boxfrontbottom = $item['col37_frontbottom'];
$boxrailwidth = $item['col37_railwidth'];
$cover = intval($item['col45']); // 상부덮개 수량
$fincover = intval($item['col47']); // 측면부(마구리) 수량
$boxLengths = [
['length' => '1219', 'quantity' => intval($item['col39'])],
['length' => '2438', 'quantity' => intval($item['col40'])],
['length' => '3000', 'quantity' => intval($item['col41'])],
['length' => '3500', 'quantity' => intval($item['col42'])],
['length' => '4000', 'quantity' => intval($item['col43'])],
['length' => '4150', 'quantity' => intval($item['col44'])]
];
// 동일한 `size` 값이 이미 존재하는지 확인
$existingKey = array_search($boxSize, array_column($box_data, 'size'));
if ($existingKey === false) {
// 새로운 사이즈 추가
$box_data[] = [
'size' => $boxSize,
'sum' => 1,
'cover' => $cover,
'fincover' => $fincover,
'boxdirection' => $boxdirection,
'boxfrontbottom' => $boxfrontbottom,
'boxrailwidth' => $boxrailwidth,
'length_data' => array_map(function ($length) {
return ['length' => $length['length'], 'sum' => $length['quantity']];
}, $boxLengths)
];
} else {
// 기존 데이터에 값 누적
$box_data[$existingKey]['sum'] += 1;
$box_data[$existingKey]['cover'] += $cover;
$box_data[$existingKey]['fincover'] += $fincover;
// 길이 데이터 누적
foreach ($boxLengths as $index => $length) {
$box_data[$existingKey]['length_data'][$index]['sum'] += $length['quantity'];
}
}
}
function fetchImageData($url) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // HTTPS 인증 무시
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); // 연결 시간 초과 설정
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // 리다이렉트 따라가기
$imageData = curl_exec($ch);
// if (curl_errno($ch)) {
// echo "DEBUG: cURL 오류 -> " . curl_error($ch) . "<br>";
// }
curl_close($ch);
return $imageData;
}
function drawImage($sourcePath, $savePath, $textData, $fontSize = 3) {
// URL을 로컬 경로로 변환
$documentRoot = $_SERVER['DOCUMENT_ROOT'];
global $root_dir;
$relativePath = str_replace($root_dir, '', $savePath);
$localSavePath = $documentRoot . $relativePath;
// echo "DEBUG: 변환된 로컬 저장 경로 -> {$localSavePath}<br>";
// 폴더 생성
$saveDir = dirname($localSavePath);
if (!is_dir($saveDir)) {
if (!mkdir($saveDir, 0777, true)) {
echo "DEBUG: 폴더 생성 실패 -> {$saveDir}<br>";
return false;
}
} else {
chmod($saveDir, 0777);
// echo "DEBUG: 폴더 권한 설정 -> {$saveDir}<br>";
}
// 원본 이미지 데이터 가져오기 (cURL 사용)
// echo "DEBUG: 원본 이미지 경로 -> {$sourcePath}<br>";
$imageData = fetchImageData($sourcePath);
if (!$imageData) {
// echo "DEBUG: 원본 이미지 데이터를 가져올 수 없습니다.<br>";
return false;
}
// echo "DEBUG: 원본 이미지 데이터 로드 성공<br>";
// 이미지 로드 및 작업
$tempImage = tempnam(sys_get_temp_dir(), 'image');
file_put_contents($tempImage, $imageData);
$image = @imagecreatefromjpeg($tempImage);
unlink($tempImage);
if (!$image) {
echo "DEBUG: JPEG 이미지를 로드할 수 없습니다.<br>";
return false;
}
// echo "DEBUG: 이미지 리소스 생성 성공<br>";
// 텍스트 추가
$textColor = imagecolorallocate($image, 255, 0, 0); // 빨간색
foreach ($textData as $textItem) {
if (isset($textItem['text'], $textItem['x'], $textItem['y'])) {
imagestring(
$image,
$fontSize,
intval($textItem['x']),
intval($textItem['y']),
$textItem['text'],
$textColor
);
// echo "DEBUG: 텍스트 추가 -> '{$textItem['text']}' @ ({$textItem['x']}, {$textItem['y']})<br>";
}
}
// 이미지 저장
$result = @imagejpeg($image, $localSavePath);
// if ($result) {
// echo "DEBUG: 이미지 저장 성공 -> {$localSavePath}<br>";
// } else {
// echo "DEBUG: 이미지 저장 실패 -> {$localSavePath}<br>";
// }
imagedestroy($image);
return $result ? $localSavePath : false;
}
?>
<?php foreach ($box_data as $box): ?>
<?PHP
// echo '<pre>';
// print_r($box);
// echo '</pre>';
?>
<div class="row">
<div class="col-sm-12">
<div class="d-flex align-items-center justify-content-start">
<table class="table" style="border-collapse: collapse;">
<thead class="table-secondary">
<tr>
<th class="text-center"><?php echo $box['size']; ?> 셔터박스 (점검구:<?=$box['boxdirection']?>) </th>
</tr>
</thead>
<tbody>
<?php
if($box['boxdirection'] == '밑면')
{
// 점검구 양면 이미지 생성
$sourcePath = $WebSite . 'img/box/source/box_bottom.jpg';
$saveName = 'box_' . str_replace('*', 'x', $box['size']) . '_bottom.jpg';
$savePath = $WebSite . 'img/box/' . $saveName;
list($boxwidth, $boxheight) = explode('*', $box['size']);
$TopcoverSize = $boxwidth - 111; // 텍스트로 추가할 값
// 여러 텍스트 데이터
$textData = [
['text' => $boxheight , 'x' => 15, 'y' => 85],
['text' => $TopcoverSize, 'x' => 100, 'y' => 2],
['text' => $box['boxfrontbottom'] , 'x' => 25, 'y' => 170],
['text' => $box['boxrailwidth'] , 'x' => 55, 'y' => 210],
['text' => ($boxwidth-$box['boxfrontbottom']-$box['boxrailwidth']-140) , 'x' => 120, 'y' => 175],
['text' => ($boxheight) , 'x' => 176, 'y' => 90],
['text' => ($boxwidth+5) , 'x' => 100, 'y' => 225],
['text' => ($boxheight+5) , 'x' => 135, 'y' => 250],
];
}
else if($box['boxdirection'] == '후면')
{
// 점검구 후면 이미지 생성
$sourcePath = $WebSite . 'img/box/source/box_rear.jpg';
$saveName = 'box_' . str_replace('*', 'x', $box['size']) . '_rear.jpg';
$savePath = $WebSite . 'img/box/' . $saveName;
list($boxwidth, $boxheight) = explode('*', $box['size']);
$TopcoverSize = $boxwidth - 111; // 텍스트로 추가할 값
$textData = [
['text' => $boxheight , 'x' => 15, 'y' => 85],
['text' => $TopcoverSize, 'x' => 100, 'y' => 2],
['text' => $box['boxfrontbottom'] , 'x' => 25, 'y' => 170],
['text' => $box['boxrailwidth'] , 'x' => 55, 'y' => 210],
['text' => ($boxwidth-$box['boxfrontbottom']-$box['boxrailwidth']) , 'x' => 120, 'y' => 165],
['text' => ($boxheight-140) , 'x' => 192, 'y' => 90],
['text' => ($boxwidth+5) , 'x' => 100, 'y' => 225],
['text' => ($boxheight+5) , 'x' => 135, 'y' => 250],
];
}
else // 없으면 양면으로 추정함 ($box['boxdirection'] == '양면')
{
// 점검구 양면 이미지 생성
$sourcePath = $WebSite . 'img/box/source/box_both.jpg';
$saveName = 'box_' . str_replace('*', 'x', $box['size']) . '_both.jpg';
$savePath = $WebSite . 'img/box/' . $saveName;
list($boxwidth, $boxheight) = explode('*', $box['size']);
$TopcoverSize = $boxwidth - 111; // 텍스트로 추가할 값
// 여러 텍스트 데이터
$textData = [
['text' => $boxheight , 'x' => 15, 'y' => 85],
['text' => $TopcoverSize, 'x' => 100, 'y' => 2],
['text' => $box['boxfrontbottom'] , 'x' => 25, 'y' => 170],
['text' => $box['boxrailwidth'] , 'x' => 55, 'y' => 210],
['text' => ($boxwidth-$box['boxfrontbottom']-$box['boxrailwidth']-140) , 'x' => 120, 'y' => 175],
['text' => ($boxheight-140) , 'x' => 192, 'y' => 90],
['text' => ($boxwidth+5) , 'x' => 100, 'y' => 225],
['text' => ($boxheight+5) , 'x' => 135, 'y' => 250],
];
}
drawImage($sourcePath, $savePath, $textData, 4);
// 길이 데이터 필터링
$filteredLengths = array_filter($box['length_data'], function ($length) {
return $length['sum'] > 0;
});
// echo '<pre>';
// print_r($filteredLengths);
// echo '</pre>';
$rowspan = count($filteredLengths); // 유효 길이의 개수만큼 rowspan 계산
$innerCount = 0;
?>
<?php foreach ($filteredLengths as $index => $length):
$innerCount ++ ;
?>
<tr>
<?php if ($innerCount === 1): ?>
<!-- 첫 번째 행에만 이미지를 출력 -->
<td class="text-center" rowspan="<?php echo $rowspan; ?>">
<img src="../img/box/<?php echo $saveName; ?>" alt="셔터박스" width="220">
<br>
①전면부 ②린텔부 ③하부점검구 ④후면코너부 ⑤후면점검구 ⑥상부덮개 ⑦측면부(마구리)
</td>
<?php endif; ?>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
</div>
<?php endforeach; ?>