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

431 lines
14 KiB
PHP

<?php
require_once($_SERVER['DOCUMENT_ROOT'] . "/session.php");
if(!isset($_SESSION["level"]) || $_SESSION["level"]>5) {
sleep(1);
header("Location:" . $WebSite . "login/login_form.php");
exit;
}
include $_SERVER['DOCUMENT_ROOT'] . '/load_header.php';
// 첫 화면 표시 문구
$title_message = '품질관리서 그룹';
?>
<title> <?=$title_message?> </title>
</head>
<body>
<?php
$option = isset($_REQUEST['option']) ? $_REQUEST['option'] : '';
// 담당자 추가하면 option=add
$search = isset($_REQUEST['search']) ? $_REQUEST['search'] : '';
$mode = isset($_REQUEST['mode']) ? $_REQUEST['mode'] : '';
$header = isset($_REQUEST['header']) ? $_REQUEST['header'] : '';
$tablename = 'acigroup';
require_once($_SERVER['DOCUMENT_ROOT'] . "/lib/mydb.php");
$pdo = db_connect();
$num = isset($_REQUEST["num"]) ? $_REQUEST["num"] : 0;
// 수정일 경우
if($num>0)
{
try{
$sql = "select * from ". $DB . "." . $tablename . " where num=?";
$stmh = $pdo->prepare($sql);
$stmh->bindValue(1, $num, PDO::PARAM_STR);
$stmh->execute();
$row = $stmh->fetch(PDO::FETCH_ASSOC);
include '_row.php';
}catch (PDOException $Exception) {
print "오류: ".$Exception->getMessage();
}
$mode = 'update';
}
else
{
include '_request.php';
$mode = 'insert';
}
?>
<form id="board_form" name="board_form" method="post" enctype="multipart/form-data">
<input type="hidden" id="mode" name="mode" value="<?=$mode?>">
<input type="hidden" id="num" name="num" value=<?=$num?> >
<input type="hidden" id="tablename" name="tablename" value=<?=$tablename?> >
<input type="hidden" id="update_log" name="update_log" value=<?=$update_log?> >
<input type="hidden" id="header" name="header" value="<?=$header?>">
<div class="container" >
<div class="d-flex align-items-center justify-content-center" >
<div class="card justify-content-center" >
<div class="card-header text-center">
<span class="text-center fs-5" > <?=$title_message?> </span>
</div>
<div class="card-body">
<div class="row justify-content-center text-center">
<div class="d-flex align-items-center justify-content-center m-2">
<table class="table table-bordered" >
<tbody>
<tr>
<td colspan="1" class="text-center fw-bold w150px"> 등록일자 </td>
<td class="text-center" >
<input type="text" class="form-control w100px" id="registdate" name="registdate" value="<?=$registdate?>">
</td>
</tr>
<tr>
<td colspan="1" class="text-center fw-bold"> 품질관리서 번호 </td>
<td class="text-center" >
<input type="text" class="form-control w100px" id="groupCode" name="groupCode" value="<?=$groupCode?>" autocomplete="off" >
</td>
</tr>
<tr>
<td colspan="1" class="text-center fw-bold"> 품질관리서 현장명</td>
<td class="text-center w400px" >
<input type="text" class="form-control text-start" id="groupName" name="groupName" value="<?=$groupName?>" autocomplete="off" >
</td>
</tr>
<tr>
<td colspan="1" class="text-center fw-bold"> 연결된 수주Num 리스트 </td>
<td class="text-center w400px" >
<input type="text" class="form-control text-start" id="connectedNum" name="connectedNum" value="<?=$connectedNum?>" autocomplete="off" >
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="d-flex justify-content-center">
<button type="button" id="saveBtn" class="btn btn-dark btn-sm me-3">
<i class="bi bi-floppy-fill"></i> 저장
</button>
<button type="button" id="closeBtn" class="btn btn-outline-dark btn-sm me-2">
&times; 닫기
</button>
</div>
</div>
</div>
</div>
</div>
<div class="container-fluid">
<?php
$tablenameOutput = 'output';
require_once($_SERVER['DOCUMENT_ROOT'] . "/lib/mydb.php");
$pdo = db_connect();
// 검색 조건 설정
$search = isset($_REQUEST['search']) ? $_REQUEST['search'] : '';
$fromdate = isset($_REQUEST['fromdate']) ? $_REQUEST['fromdate'] : '';
$todate = isset($_REQUEST['todate']) ? $_REQUEST['todate'] : '';
$mode = isset($_REQUEST['mode']) ? $_REQUEST['mode'] : '';
$SettingDate = isset($_REQUEST['SettingDate']) ? $_REQUEST['SettingDate'] : " regist_day ";
if(isset($_REQUEST["separate_date"]))
$separate_date=$_REQUEST["separate_date"];
else
$separate_date="";
if($separate_date=="") $separate_date="1";
if(isset($_REQUEST["status_option"]))
$existing_status=$_REQUEST["status_option"];
else
$existing_status='전체';
// 현재 날짜
$currentDate = date("Y-m-d");
// fromdate 또는 todate가 빈 문자열이거나 null인 경우
if ($fromdate === "" || $fromdate === null || $todate === "" || $todate === null) {
$fromdate = date("Y-m-d", strtotime("-10000 weeks", strtotime($currentDate))); // 1개월 이전 날짜 1주전 날짜
$todate = date("Y-m-d", strtotime("+3 months", strtotime($currentDate))); // 3개월 이전 날짜
$Transtodate = $todate;
} else {
// fromdate와 todate가 모두 설정된 경우 (기존 로직 유지)
$Transtodate = $todate;
}
if($separate_date == "1")
$SettingDate = "outdate";
else
$SettingDate = "indate";
// 진행상태에 대한 검색
$orderby = " order by " . $SettingDate . " desc, num desc limit 200"; // 200개까지만 보여주기
if ($existing_status == '전체') {
$where = " where " . $SettingDate . " between date('$fromdate') and date('$Transtodate') and is_deleted = '0' " . $orderby;
$searchwhere = " where is_deleted = '0' and searchtag like '%$search%'" . $orderby;
} else {
$where = " where " . $SettingDate . " between date('$fromdate') and date('$Transtodate') and is_deleted = '0' and regist_state = '$existing_status'" . $orderby;
$searchwhere = " where is_deleted = '0' and regist_state = '$existing_status' and searchtag like '%$search%'" . $orderby;
}
// 수정된 쿼리: outputnum이 존재하는 자료만 선택
if ($search == "") {
$sql = "select * from $DB.$tablenameOutput " . $where;
} else {
$sql = "select * from $DB.$tablenameOutput " . $searchwhere;
}
$today=date("Y-m-d"); // 현재일자 변수지정
// print $sql;
try {
$stmh = $pdo->query($sql); // 검색조건에 맞는글 stmh
$total_row = $stmh->rowCount();
?>
<div class="container-fluid">
<div class="card mb-2 mt-2">
<div class="card-body">
<div class="d-flex justify-content-center">
<div class="inputWrap">
<input type="text" id="search" name="search" value="<?=$search?>" onkeydown="JavaScript:SearchEnter();" autocomplete="off" class="form-control w150px mx-1" >
<button class="btnClear"></button>
</div>
<button id="searchBtn" type="button" class="btn btn-dark btn-sm" > <i class="bi bi-search"></i> 검색 </button> &nbsp;&nbsp;&nbsp;
</div>
</div> <!--card-body-->
</div> <!--card -->
</div> <!--container-fluid -->
<div class="container-fluid">
<div class="d-flex justify-content-center align-items-center">
<table class="table table-hover" id="myTable">
<thead class="table-primary">
<tr>
<!-- 전체 선택 체크박스 -->
<th class="text-center" style="width:30px;">
<input type="checkbox" id="select_all">
</th>
<th class="text-center" >수주Num</th>
<th class="text-center" >출고일</th>
<th class="text-center" >진행</th>
<th class="text-center" >발주처</th>
<th class="text-center" >현장명</th>
<th class="text-center" >품질괸리서번호</th>
<th class="text-center" >관리서명 </th>
<th class="text-center" >수신자</th>
<th class="text-center" >인정</th>
</tr>
</thead>
<tbody>
<?php
$start_num = $total_row;
while($row = $stmh->fetch(PDO::FETCH_ASSOC)) {
include $_SERVER['DOCUMENT_ROOT'] . '/output/_row.php';
// 예시로 수주Num은 $num 변수에 들어있다고 가정합니다.
?>
<tr>
<!-- 각 행마다 체크박스 추가 (data-ordernum 속성에 수주Num 값을 저장) -->
<td class="text-center">
<input type="checkbox" class="row_checkbox" data-ordernum="<?= $num ?>">
</td>
<td class="text-center"><?= $num ?></td>
<td class="text-center"><?= $outdate ?></td>
<td class="text-center">
<?php
switch ($regist_state) {
case "등록":
echo '<span class="badge bg-danger">등록</span>';
break;
case "수정":
echo '<span class="badge bg-warning blink">수정</span>';
break;
case "접수":
echo '<span class="badge bg-success">접수</span>';
break;
case "완료":
echo '<span class="badge bg-dark">완료</span>';
break;
}
?>
</td>
<td class="text-start"><?= $secondord ?></td>
<td class="text-start"><?= $outworkplace ?></td>
<td class="text-start"><?= $ACIgroupCode ?></td>
<td class="text-start"><?= $ACIgroupName ?></td>
<td class="text-start"><?= $receiver ?></td>
<td class="text-center"><?= $warranty ?></td>
</tr>
<?php
$start_num--;
}
} catch (PDOException $Exception) {
print "오류: ".$Exception->getMessage();
}
?>
</tbody>
</table>
</div>
</div> <!--container-->
</form>
<!-- 페이지로딩 -->
<script>
// 페이지 로딩
$(document).ready(function(){
var loader = document.getElementById('loadingOverlay');
if(loader)
loader.style.display = 'none';
});
ajaxRequest_write = null;
/* ESC 키 누를시 팝업 닫기 */
// $(document).keydown(function(e){
// //keyCode 구 브라우저, which 현재 브라우저
// var code = e.keyCode || e.which;
// if (code == 27) { // 27은 ESC 키번호
// self.close();
// }
// });
$(document).ready(function(){
// 창닫기 버튼
$("#closeBtn").on("click", function() {
self.close();
});
$("#saveBtn").on("click", function() {
Swal.fire({
title: '저장 확인',
text: '각 수주리스트에 품질관리서 번호와 그룹코드를 저장하시겠습니까?',
icon: 'question',
showCancelButton: true,
confirmButtonText: '저장',
cancelButtonText: '취소'
}).then((result) => {
if(result.isConfirmed) {
// 폼 내 입력값 읽어오기
var groupCode = $("#groupCode").val();
var groupName = $("#groupName").val();
// 연결된 수주Num 리스트 인풋의 값 읽기
var connectedList = $("#connectedNum").val();
// 값이 비어있다면 오류 메시지 출력
if(connectedList.trim() === "") {
Swal.fire('오류', '수주리스트를 선택해주세요.', 'error');
return;
}
// 콤마(,)로 구분된 문자열을 배열로 변환 (각 항목의 양쪽 공백 제거)
var selectedOrders = connectedList.split(",").map(function(item) {
return item.trim();
});
// ajax로 save_groupcode.php에 데이터 전송
$.ajax({
url: 'save_groupcode.php',
type: 'POST',
data: {
groupCode: groupCode,
groupName: groupName,
orders: selectedOrders
},
dataType: 'json',
success: function(response) {
},
error: function(xhr, status, error) {
Swal.fire('오류', '저장에 실패했습니다.', 'error');
}
});
}
// 서버에 데이터 저장
saveData();
setTimeout(function() {
$(opener.location).attr("href", "javascript:reloadlist();");
self.close();
}, 3000);
});
});
function saveData() {
var header = $("#header").val();
let msg = '저장완료';
if (ajaxRequest_write !== null) {
ajaxRequest_write.abort();
}
ajaxRequest_write = $.ajax({
url: "process.php",
type: "post",
data: $("#board_form").serialize(),
success : function( data ){
// console.log(data);
Swal.fire('성공', '저장되었습니다.', 'success').then(function(){
// 필요 시 목록 재로딩 또는 창 닫기 처리
// 예: opener.location.reload();
});
},
error : function( jqxhr , status , error ){
console.log( jqxhr , status , error );
}
});
}
}); // end of ready
$(document).ready(function(){
// 전체 선택 체크박스 이벤트
$('#select_all').on('change', function(){
$('.row_checkbox').prop('checked', $(this).prop('checked'));
updateConnectedNum();
});
// 개별 체크박스 변경 시 이벤트
$('.row_checkbox').on('change', function(){
// 전체 선택 체크박스의 상태도 업데이트 (모두 선택되면 체크, 아니면 해제)
if ($('.row_checkbox:checked').length === $('.row_checkbox').length) {
$('#select_all').prop('checked', true);
} else {
$('#select_all').prop('checked', false);
}
updateConnectedNum();
});
// 테이블의 각 행(tr)을 클릭하면 해당 행의 체크박스를 토글하도록 이벤트 등록
$("#myTable tbody tr").on("click", function(e){
// 만약 클릭한 대상이 이미 체크박스라면 토글하지 않음
if($(e.target).is("input[type=checkbox]")) return;
// 해당 행의 체크박스 찾기 및 토글
var $checkbox = $(this).find(".row_checkbox");
// 체크박스의 상태를 토글하고 change 이벤트도 강제로 발생시킴
$checkbox.prop("checked", !$checkbox.prop("checked")).trigger('change');
});
// 선택된 체크박스의 data-ordernum 값을 콤마(,)로 구분하여 #connectedNum 인풋에 업데이트하는 함수
function updateConnectedNum(){
let selectedNums = [];
$('.row_checkbox:checked').each(function(){
selectedNums.push($(this).data('ordernum'));
});
$('#connectedNum').val(selectedNums.join(','));
}
});
</script>
</body>
</html>