<?php
require_once($_SERVER['DOCUMENT_ROOT'] . "/session.php");  

$mode = isset($_POST['mode']) ? $_POST['mode'] : '';
$num = isset($_POST['num']) ? $_POST['num'] : '';
$tablename = isset($_POST['tablename']) ? $_POST['tablename'] : '';

require_once($_SERVER['DOCUMENT_ROOT'] . "/lib/mydb.php");
$pdo = db_connect();

if(!isset($DB))
	$DB = 'chandj';

if ($mode === 'modify' && $num) {
    try {
        $sql = "SELECT * FROM {$DB}.$tablename WHERE num=? ";
        $stmh = $pdo->prepare($sql);
        $stmh->bindValue(1, $num, PDO::PARAM_INT);      
        $stmh->execute();
        $row = $stmh->fetch(PDO::FETCH_ASSOC);

        include '_row.php';
    } catch (PDOException $Exception) {
        echo "오류: ".$Exception->getMessage();
        exit;
    }
} else {
    include '_request.php';
    $mode = 'insert';    
    $reg_date = date('Y-m-d');
	$author = $user_name;
	$num = '';
}

$title_message = ($mode === 'modify') ? '기타절곡품 등 수정' : '기타절곡품 등 등록';

// 기존에 저장된 값이 있는 경우 해당 값을 설정
$selected_prod_model = isset($row['prod_model']) ? $row['prod_model'] : '연기차단재(짜부가스켓)80*20';
?>

<input type="hidden" id="update_log" name="update_log" value="<?=$update_log?>">   
<input type="hidden" id="selected_prod_model" name="selected_prod_model" value="<?=$selected_prod_model?>">   

<style>
	.image-container {
		position: relative;
		display: inline-block;
	}
	.image-container img {
		display: block;
	}
	.input-overlay {
		position: absolute;
		background: rgba(255, 255, 255, 0.5);
		border: 1px solid blue;
		width: 50px;
		color: blue;
		/* font-weight: bold; */
	}
	
.modal-body {
    max-height: 750px; /* 원하는 높이 설정 */
    max-width: 1380px; /* 원하는 너비 설정 */
    overflow-x: auto; /* 가로 스크롤 가능 */
    overflow-y: auto; /* 세로 스크롤 가능 */
}
	
</style>

<div class="container-fluid">
    <div class="d-flex align-items-center justify-content-center">
        <div class="card justify-content-center">
            <div class="card-header text-center">			  
				<div class="row">
					<div class="col-sm-2">
					</div>
					<div class="col-sm-8">
						<div class="d-flex align-items-center justify-content-center">
							<span class="text-center fs-5 me-5"><?=$title_message?></span>						
						
							<button type="button" id="saveBtn" class="btn btn-dark btn-sm me-3">
								<ion-icon name="save-outline"></ion-icon> 저장 
							</button>
							<?php if($mode != 'insert') { ?>
							<button type="button" id="deleteBtn" class="btn btn-danger btn-sm me-3">
								<ion-icon name="trash-outline"></ion-icon> 삭제
							</button>
							<?php } ?>                    
						</div>	
					</div>
					<div class="col-sm-2">
					<div class="d-flex align-items-center justify-content-end">
						<button type="button" class="btn btn-outline-dark btn-sm me-2 closeBtn"> <ion-icon name="close-circle-outline"></ion-icon> 닫기 </button>				
					</div>
					</div>
			</div>
		</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 class="text-center fs-6 fw-bold" style="width:150px;">등록일</td>
					<td class="text-center w100px" >
						<input type="date" class="form-control fs-6 " id="reg_date" name="reg_date" value="<?=$reg_date?>">
					</td>
					<td class="text-center fs-6 fw-bold" >작성자</td>
					<td class="text-center" style="width:100px;">
					   <div class="d-flex">
							<input class="form-control fs-6" id="author" name="author" value="<?=$author?>" autocomplete="off">
						</div>
					</td>                                
					<td class="text-center fs-6 fw-bold" >비고</td>
					<td colspan="3" class="text-center">
						<input type="text" class="form-control fs-6 text-start" id="remark" name="remark" value="<?=$remark?>" autocomplete="off">
					</td>
				</tr>                               	
				<tr>
<td class="text-center fs-6 fw-bold" colspan="6" >
    <div class="col text-center">
        <label class="me-3">
            제품코드 :
            <select name="prod_model" class="form-select d-inline w-auto">
                <option value="연기차단재(짜부가스켓)80*20" <?php if($selected_prod_model === '연기차단재(짜부가스켓)80*20') echo 'selected'; ?>>연기차단재(짜부가스켓)80*20</option>
                <option value="연기차단재(짜부가스켓)40*10" <?php if($selected_prod_model === '연기차단재(짜부가스켓)40*10') echo 'selected'; ?>>연기차단재(짜부가스켓)40*10</option>         
            </select>
        </label>
    </div>
</td>
	</tr>
	</tbody>
	</table>
	</div>
	</div>		

<!-- 이미지 표시 부분 -->
<div class="d-flex align-items-center justify-content-center mb-5 mt-2 m-2">
	<div class="image-container mb-5">
			<img id="checkImage"  src="<?php 						
				switch ($selected_prod_model) {
					case '연기차단재(짜부가스켓)80*20':
						echo '../img/somkeban/80x20.png';
						break;
					case '연기차단재(짜부가스켓)40*10':
						echo '../img/somkeban/40x10.png';
						break;					
				}							
		?>" alt="Image">
         									
</div>
</div>		
<div class="d-flex align-items-center justify-content-center mb-5 mt-2 m-2">
</div>		
<br>
</div>
</div>
</div>
</div>
