<?php
require_once $_SERVER['DOCUMENT_ROOT'] . '/load_GoogleDrive.php'; // 세션 등 여러가지 포함됨 파일 포함

if(!isset($_SESSION["level"]) || $_SESSION["level"]>5) {
	 sleep(1);
		  header("Location:" . $WebSite . "login/login_form.php");  
	 exit;
}

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

include $_SERVER['DOCUMENT_ROOT'] . '/load_header.php';

$mode = 'view';
$num = isset($_REQUEST["num"]) ? $_REQUEST["num"] : "";
$tablename = isset($_REQUEST["tablename"]) ? $_REQUEST["tablename"] : "output";

require_once $_SERVER['DOCUMENT_ROOT'] . '/load_GoogleDriveSecond.php'; // attached, image에 대한 정보 불러오기  

$title_message = "인정제품 심사자료 " ;

$authorities = ["개발자","이경호","이세희","함신옥"];

// 서버에서 날짜 값을 받아온다고 가정
$receivedCode = ""; // 예시값, 실제로는 서버에서 받아오는 값으로 대체

$version = 1;
?>  
<title> <?=$title_message?> </title>
<link rel="stylesheet" href="css/style.css">
<style>
textarea {
overflow: hidden;
resize: none; /* 사용자 크기 조절을 방지 */
}  
/* 기본 스타일 설정 */
input[type="checkbox"],
input[type="radio"] {
	transform: scale(1.5); /* 크기 확대 */
	margin: 3px; /* 여백 추가 */
}

/* "readonly" 상태일 때 스타일 설정 */
.readonly-checkbox,
.readonly-radio {
	pointer-events: none; /* 사용자 상호작용 비활성화 */
	opacity: 1; /* 불투명도 설정 */
	color: red;
}

/* 레이블 텍스트 크게 설정 */
label {
	font-size: 1.5em; /* 글꼴 크기 확대 */
	display: inline-block;
	margin: 3px 0;
}
.w-40{
	 width: 40%!important;
}
.w-50{
	 width: 50%!important;
}
.w-60{
	 width: 60%!important;
}

.w-85{
	 width: 85%!important;
}

.viewNoBtn {
	cursor : pointer;
}
</style>

</head>
<?   
include $_SERVER['DOCUMENT_ROOT'] . '/mymodal.php';
  
// 첨부 이미지에 대한 부분
require_once($_SERVER['DOCUMENT_ROOT'] . "/lib/mydb.php");
$pdo = db_connect();	
 
$today = date("Y-m-d"); // 현재일자 변수지정

    try{
      $sql = "select * from $DB.$tablename where num = ? ";
      $stmh = $pdo->prepare($sql); 

      $stmh->bindValue(1,$num,PDO::PARAM_STR); 
      $stmh->execute();
      $count = $stmh->rowCount();            
	  $row = $stmh->fetch(PDO::FETCH_ASSOC);  // $row 배열로 DB 정보를 불러온다.
    if($count<1){  
      print "검색결과가 없습니다.<br>";
     }else{

       include '_row.php';
	  
	 if($indate!="0000-00-00") $indate = date("Y-m-d", strtotime( $indate) );
			else $indate="";	 
	 if($outdate!="0000-00-00") $outdate = date("Y-m-d", strtotime( $outdate) );
			else $outdate="";	 

	 // output_extra 테이블에서 데이터 불러오기
	 require_once $_SERVER['DOCUMENT_ROOT'] . '/output/load_output_extraTable.php';	
			  
      }
     }catch (PDOException $Exception) {
       print "오류: ".$Exception->getMessage();
     }

// JSON 문자열을 PHP 배열로 디코딩합니다.

if(!empty($eList_slat)  and $eList_slat !=='[]')
	$eList = json_decode($eList_slat, true);
if(!empty($eList_screen) and $eList_screen !=='[]')
	$eList = json_decode($eList_screen, true);

// 행의 수는 배열의 크기와 동일하므로, count() 함수를 사용하여 구합니다.
$surang = count($eList);

$prodname = '';
$FinishMat = '';

// 디코딩된 데이터가 배열인지 확인합니다.
if (!is_array($eList)) {
    echo "데이터가 정상적이지 않습니다. 확인바랍니다.";
    exit;
}
else {
	foreach ($eList as $item) {
		$prodcode = $item['col4'];
		$GuiderailType = $item['col6'];
		$FinishMat = $item['col7'];
		$prodname = '';
	}
}

// echo '<pre>';
// print_r($row);
// echo '</pre>';
// echo '<pre>';
// print_r($eList);
// echo '</pre>';

$indateStr = date("m/d", strtotime($indate));
$todayStr = date("m/d");  

$suffix ='';
if($ACIcheck == '1')
	 $suffix ='(제외)';
 
?>
  
<form id="board_form"  name="board_form" method="post" enctype="multipart/form-data"  >
<input type="hidden" id="timekey" name="timekey" value="<?= isset($timekey) ? $timekey : '' ?>"> <!-- 신규데이터 작성시 parentid key값으로 사용 -->				
<input type="hidden" id="mode" name="mode" value="<?= isset($mode) ? $mode : '' ?>">
<input type="hidden" id="num" name="num" value="<?= isset($num) ? $num : '' ?>">
<input type="hidden" id="level" name="level" value="<?= isset($level) ? $level : '' ?>">
<input type="hidden" id="user_name" name="user_name" value="<?= isset($user_name) ? $user_name : '' ?>">
<input type="hidden" id="tablename" name="tablename" value="<?= isset($tablename) ? $tablename : '' ?>">
<input type="hidden" id="is_deleted" name="is_deleted" value="<?= isset($is_deleted) ? $is_deleted : '0' ?>">
<input type="hidden" id="motor_state" name="motor_state" value="<?= isset($motor_state) ? $motor_state : '등록' ?>">
<input type="hidden" id="bend_state" name="bend_state" value="<?= isset($bend_state) ? $bend_state : '등록' ?>">
<input type="hidden" id="screen_state" name="screen_state" value="<?= isset($screen_state) ? $screen_state : '등록' ?>">
<input type="hidden" id="slat_state" name="slat_state" value="<?= isset($slat_state) ? $slat_state : '등록' ?>">
<input type="hidden" id="screenlist" name="screenlist" >
<input type="hidden" id="screen_su" name="screen_su" value="<?= isset($screen_su) ? $screen_su : '' ?>">
<input type="hidden" id="screen_m2" name="screen_m2" value="<?= isset($screen_m2) ? $screen_m2 : '' ?>">
<input type="hidden" id="screen" name="screen" value="<?= isset($screen) ? $screen : '' ?>">
<input type="hidden" id="slatlist" name="slatlist" >
<input type="hidden" id="slat_su" name="slat_su" value="<?= isset($slat_su) ? $slat_su : '' ?>">
<input type="hidden" id="slat_m2" name="slat_m2" value="<?= isset($slat_m2) ? $slat_m2 : '' ?>">
<input type="hidden" id="slat" name="slat" value="<?= isset($slat) ? $slat : '' ?>">
<input type="hidden" id="prodCode" name="prodCode" value="<?= isset($prodCode) ? $prodCode : '' ?>">

<input type="hidden" id="eList_screen" name="eList_screen" >
<input type="hidden" id="eList_slat" name="eList_slat" >
<input type="hidden" id="etcList" name="etcList" >

<div class="container"> 
<div class="row justify-content-center align-items-center ">	        
		<div class="card align-middle " style="width:50rem; padding:0;">	
		<div class="card-body text-center"  style="padding:4;" >							
			<div class="row d-flex justify-content-center align-items-center mt-3 mb-3" >					
				<div class="col-sm-3" >			
					<div class="d-flex p-1 mb-1  justify-content-start align-items-center ">				
					  								
				   </div>
				</div>			
				<div class="col-sm-6" >					
					<div class="d-flex p-1 mb-1  justify-content-center align-items-center ">	
					  <h3>	<?=$title_message?>   <?= $suffix ?>  <h3>					
					</div>
				</div>			
				<div class="col-sm-3" >	
					<button class="btn btn-dark btn-sm me-2 ms-1 saveData" > <i class="bi bi-floppy2-fill"></i> 저장 </button>				
					<button type="button" class="btn btn-outline-dark  btn-sm " onclick="self.close();" > <i class="bi bi-x-lg"></i> 창닫기 </button>	&nbsp; 				
				</div>	
			   </div>	
			</div>
		</div>		
	</div>		

<div class="row m-1">   
<div class="d-flex align-items-center justify-content-center">
<table class="table table-bordered w-50" style="border-collapse: collapse;">
	<thead>
		<tr>
			<th colspan="2" class="text-center align-middle lightgray" style="width:33%;">신  청  업  체</th>
			<th colspan="6" class="text-center align-middle lightgray" style="width:33%;">신  청  내  용</th>
		</tr>        
		<tr>
			<th class="text-center align-middle lightgray">발주일</th>
			<th class="text-center"><?=specialDate($orderdate)?></th>
			<th class="text-center align-middle lightgray">현  장  명</th>
			<th  colspan="4" class="text-center text-primary fw-bold"><?=$outworkplace?> </th>	
		</tr>
		<tr>
			<th class="text-center align-middle lightgray">업체명</th>
			<th class="text-center"><?=$secondord?></th>
			<th class="text-center align-middle lightgray">출고일자</th>
			<th colspan="4" class="text-center text-secondary fw-bold"><?=$outdate?>  </th>
		</tr>
		<tr>
			<th class="text-center align-middle lightgray">담당자</th>
			<th class="text-center"><?=$orderman?></th>
			<th class="text-center align-middle yellowBold">제품 LOT NO</th>
			<th class="text-center fw-bold text-primary"><?=$lotNum?></th>
			<th class="text-center align-middle yellowBold">인증번호 </th>
			<th class="text-center fw-bold text-primary"><?=$warrantyNum?></th>
		</tr>
		<tr>
			<th class="text-center align-middle lightgray">연락처</th>
			<th class="text-center text-dark fw-bold"><?=$_SESSION['hp']?> </th>                
			<th class="text-center align-middle lightgray">생산담당자</th>
			<th  colspan="4" class="text-center"> <?=$orderman?> </th>
		</tr>	
            <tr>
                <th class="text-center align-middle lightgray" >제품명 </th>
                <th class="text-center align-middle text-danger fw-bold"> <?=$prodCode?> &nbsp; &nbsp; <?=$prodname?> </th>
                <th class="text-center align-middle lightgray" >마감유형 </th>
                <th colspan="4" class="text-center align-middle text-danger fw-bold "> <?=$FinishMat?> </th>                
            </tr> 		
        </thead>
    </table>
</div>
</div>	
<div class="row mt-3">						
<div class="d-flex justify-content-center align-items-center mt-3">						
<table class="table table-bordered w-50" style="border: 2px solid brown;">
	<tbody>						
		<tr>
		<?php 	if($ACIcheck=='1') :?>	
			<td colspan="5" class="text-center"> <span  class="badge bg-danger fs-6" data-bs-toggle="tooltip" data-bs-placement="bottom" title="인정검사 요청이 오면 접수일자를 입력합니다." > 인정검사 </span>  </td>										
		<?php else: ?>			
			<td colspan="4" class="text-center"> <span  class="badge bg-danger fs-6" data-bs-toggle="tooltip" data-bs-placement="bottom" title="인정검사 요청이 오면 접수일자를 입력합니다." > 인정검사 </span>  </td>										
		<?php endif ; ?>			
			</td>                              															
		</tr>				
		<tr>										
			<td style="width:60px; background-color:lightgray;"> 접수 </td> 										
			<td style="width:60px; background-color:lightgray;"> 요청 </td> 										
			<td style="width:60px; background-color:lightgray;"> 완료 </td> 		
        <?php 	if($ACIcheck=='1') :?>		
			<td style="width:60px;  background-color:lightgray;"> 제외 </td> 										
		<?php endif ; ?>
			<td style="width:160px;  background-color:lightgray;"> 메모 </td> 										
		</tr>				
		<tr>
			<td> 
				<input type="date" id="ACIregDate" name="ACIregDate" class="form-control noborder-input text-center"  autocomplete="off"  value="<?=$ACIregDate?>" >				  									  
			</td>										
			<td> 
				<input type="date" id="ACIaskDate" name="ACIaskDate" class="form-control  noborder-input text-center"  autocomplete="off" readonly  value="<?=$ACIaskDate?>" >				  									  
			</td>										
			<td> 
				<input type="date" id="ACIdoneDate" name="ACIdoneDate" class="form-control  noborder-input text-center"  autocomplete="off" readonly  value="<?=$ACIdoneDate?>" >				  									  
			</td>		
        <?php 	if($ACIcheck=='1') :?>					
			<td> 
				<input type="checkbox" id="ACIcheck" name="ACIcheck"  checked >				  									  
			</td>										
		<?php endif ; ?>			
			<td> 
				<input type="text" id="ACImemo" name="ACImemo" class="form-control  noborder-input text-start"  autocomplete="off"  value="<?=$ACImemo?>" >				  									  			</td>										
		</tr>								
	</tbody>
</table>						
</div>	
</div>	
</div>	

<div class="container-fluid mt-3"> 	
<div id="screenWindow" >		 	
<div class="card align-middle ">	
<div class="card-body" >								
	<div class="d-flex p-1 justify-content-center align-items-center ">												  																	     
		<button type='button' id="loadOrderBtn" class='btn btn-warning btn-sm me-2' ><i class="bi bi-card-text"></i> 발주서 </button>
		<button type='button' id="loadScreenWorkBtn" class='btn btn-primary btn-sm me-2' ><i class="bi bi-card-text"></i> 스크린 작업일지 </button>
		<button type='button' id="loadBendingWorkBtn" class='btn btn-success btn-sm me-2' ><i class="bi bi-card-text"></i> 절곡 작업일지 </button>
		<button type='button' id="loadOutputWorkBtn" class='btn btn-secondary btn-sm me-2' ><i class="bi bi-card-text"></i> 출고증 </button>
		<button type='button' id="loadConfirmBtn" class='btn btn-secondary btn-sm me-2' ><i class="bi bi-card-text"></i> 납품확인서 </button> 
	</div>
	<br>
	<div class="d-flex justify-content-center align-items-center mt-5">																				     						
			<button type='button' id="loadmidInspectScreenBtn" class='btn btn-danger btn-sm me-2' ><i class="bi bi-card-text"></i> 스크린-중간검사 </button>
			<button type='button' id="loadmidInspectBendingBtn" class='btn btn-danger btn-sm me-2' ><i class="bi bi-card-text"></i> 절곡-중간검사 </button>
			<button type='button' id="requestBtn" class='btn btn-danger btn-sm me-2' ><i class="bi bi-card-text"></i> 제품검사 요청서(업체) </button>
			<button type='button' id="QCcertificateBtn" class='btn btn-danger btn-sm me-2' ><i class="bi bi-card-text"></i> 자동방화셔터 품질관리서 </button>
			<button type='button' id="screenACIBtn" class='btn btn-danger btn-sm me-2' ><i class="bi bi-card-text"></i> 인정검사 </button>							  	  
		</div>						
	</div>
			   			
   </div>	
</div> 

<!-- 철재(스라트) slat 작업일지 등  -->
<div id="slatWindow" >		
	<div class="card align-middle " >	
	<div class="card-body ">									
		<div class="d-flex justify-content-center align-items-center mb-2 mt-2">																				     													
					<button type='button' id="loadOrderBtn_slat" class='btn btn-warning-emphasis bg-warning-subtle border border-warning-subtle rounded-pill btn-sm fw-bold   me-2' ><i class="bi bi-card-text"></i> 발주서 </button>
					<button type='button' id="loadSlatWorkBtn" class='btn btn-info-emphasis bg-info-subtle border border-info-subtle rounded-pill btn-sm fw-bold me-2' ><i class="bi bi-card-text"></i> 작업일지 </button>
					<button type='button' id="loadBendingWorkBtn_slat" class='btn btn-success-emphasis bg-success-subtle border border-success-subtle rounded-pill btn-sm  fw-bold me-2' ><i class="bi bi-card-text"></i> 절곡 작업일지 </button>
					<button type='button' id="loadOutputWorkBtn_slat" class='btn btn-secondary-emphasis bg-secondary-subtle border border-secondary-subtle rounded-pill btn-sm fw-bold  me-2' ><i class="bi bi-card-text"></i> 출고증 </button>
					<button type='button' id="loadConfirmBtn_slat" class='btn btn-secondary-emphasis bg-secondary-subtle border border-secondary-subtle rounded-pill btn-sm fw-bold me-2' ><i class="bi bi-card-text"></i> 납품확인서 </button>				
				</div>								
				<br>
				<div class="d-flex justify-content-center align-items-center mt-5">		
					<button type='button' id="loadmidInspectSlatBtn" class='btn btn-danger-emphasis bg-danger-subtle border border-danger-subtle rounded-pill btn-sm  fw-bold me-2' ><i class="bi bi-card-text"></i> 슬랫-중간검사 </button>
					<button type='button' id="loadmidInspectJointbarBtn" class='btn btn-danger-emphasis bg-danger-subtle border border-danger-subtle rounded-pill btn-sm  fw-bold me-2' ><i class="bi bi-card-text"></i> 조인트바-중간검사 </button>
					<button type='button' id="loadmidInspectBendingBtn_slat" class='btn btn-danger-emphasis bg-danger-subtle border border-danger-subtle rounded-pill btn-sm  fw-bold me-2' ><i class="bi bi-card-text"></i> 절곡-중간검사 </button>
					<button type='button' id="requestBtn" class='btn btn-danger-emphasis bg-danger-subtle border border-danger-subtle rounded-pill btn-sm  fw-bold me-2' ><i class="bi bi-card-text"></i>  제품검사 요청서(업체) </button>
					<button type='button' id="QCcertificateBtn" class='btn btn-danger-emphasis bg-danger-subtle border border-danger-subtle rounded-pill btn-sm  fw-bold me-2' ><i class="bi bi-card-text"></i>  자동방화셔터 품질관리서 </button>
					<button type='button' id="slatACIBtn" class='btn btn-danger-emphasis bg-danger-subtle border border-danger-subtle rounded-pill btn-sm  fw-bold me-2' ><i class="bi bi-card-text"></i> 인정검사 </button>							  	  
			</div>						
		</div>				   
   </div>
</div>					

</div>
</form>

<?php  include $_SERVER['DOCUMENT_ROOT'] . '/output/write_form_script_sub.php';  // 스크린트연결 ?>

</body>
</html>
