204 lines
7.4 KiB
PHP
204 lines
7.4 KiB
PHP
|
|
<?php
|
||
|
|
// modelslist.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
|
||
|
|
// modelslist.php 에서 관리할 JSON 파일 경로 (파일명: models.json, 폴더: /models)
|
||
|
|
$jsonFile = $_SERVER['DOCUMENT_ROOT'] . '/models/models.json';
|
||
|
|
|
||
|
|
// JSON 파일이 존재하면 읽어오고, 없으면 빈 배열 생성
|
||
|
|
$models = [];
|
||
|
|
if (file_exists($jsonFile)) {
|
||
|
|
$jsonContent = file_get_contents($jsonFile);
|
||
|
|
$models = json_decode($jsonContent, true);
|
||
|
|
if (!is_array($models)) {
|
||
|
|
$models = [];
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// POST 요청 처리: 추가, 수정, 삭제
|
||
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||
|
|
$action = isset($_POST['action']) ? $_POST['action'] : '';
|
||
|
|
// 수정 또는 삭제 시 사용되는 인덱스 (배열의 키)
|
||
|
|
$index = isset($_POST['index']) ? intval($_POST['index']) : -1;
|
||
|
|
// 입력 모델명
|
||
|
|
$model_name = isset($_POST['model_name']) ? trim($_POST['model_name']) : '';
|
||
|
|
$pair = isset($_POST['pair']) ? trim($_POST['pair']) : '';
|
||
|
|
// 새로 추가: prefix 값 (slatitem)
|
||
|
|
$slatitem = isset($_POST['slatitem']) ? trim($_POST['slatitem']) : '';
|
||
|
|
|
||
|
|
if ($action === 'insert' && $model_name !== '') {
|
||
|
|
// 신규 추가: 배열 끝에 객체 형태로 추가
|
||
|
|
$models[] = array(
|
||
|
|
"model_name" => $model_name,
|
||
|
|
"pair" => $pair,
|
||
|
|
"slatitem" => $slatitem
|
||
|
|
);
|
||
|
|
} elseif ($action === 'update' && $model_name !== '' && $index >= 0 && $index < count($models)) {
|
||
|
|
// 수정: 해당 인덱스의 값을 변경 (모델명과 prefix 모두 업데이트)
|
||
|
|
$models[$index]["model_name"] = $model_name;
|
||
|
|
$models[$index]["pair"] = $pair;
|
||
|
|
$models[$index]["slatitem"] = $slatitem;
|
||
|
|
} elseif ($action === 'delete' && $index >= 0 && $index < count($models)) {
|
||
|
|
// 삭제: 해당 요소 제거
|
||
|
|
array_splice($models, $index, 1);
|
||
|
|
}
|
||
|
|
// JSON 파일에 저장
|
||
|
|
file_put_contents($jsonFile, json_encode($models, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
|
||
|
|
}
|
||
|
|
?>
|
||
|
|
<div class="container mt-3">
|
||
|
|
<div class="card">
|
||
|
|
<div class="card-header d-flex justify-content-center align-items-center text-center">
|
||
|
|
<h3 class="mb-0 text-center"><?= $title_message ?></h3>
|
||
|
|
<button type="button" class="btn btn-dark btn-sm mx-2" onclick='location.reload();' > <i class="bi bi-arrow-clockwise"></i> </button>
|
||
|
|
<button type="button" class="btn btn-dark btn-sm mx-2" onclick='window.close();' > × 닫기 </button>
|
||
|
|
</div>
|
||
|
|
<div class="card-body">
|
||
|
|
<!-- 신규 모델 추가 폼 -->
|
||
|
|
<div class="mb-3">
|
||
|
|
<form id="addModelForm" method="post" action="modelslist.php" class="row g-3">
|
||
|
|
<input type="hidden" name="action" id="action" value="insert">
|
||
|
|
<input type="hidden" name="index" id="index" value="-1">
|
||
|
|
<div class="d-flex justify-content-center align-items-center text-center">
|
||
|
|
<!-- Prefix 선택 select 추가 -->
|
||
|
|
<div class="col-auto mx-1">
|
||
|
|
<select name="slatitem" id="slatitem" class="form-select " style="font-size: 0.8rem; height: 32px;">
|
||
|
|
<option value=""> (구분) </option>
|
||
|
|
<option value="스크린">스크린</option>
|
||
|
|
<option value="철재">철재</option>
|
||
|
|
</select>
|
||
|
|
</div>
|
||
|
|
<!-- 모델명 입력 -->
|
||
|
|
<div class="col-auto mx-2">
|
||
|
|
<input type="text" name="model_name" id="model_name" class="form-control p-1" placeholder="모델명을 입력하세요" autocomplete="off" >
|
||
|
|
</div>
|
||
|
|
<!-- pair 두문자 입력 -->
|
||
|
|
<div class="col-auto mx-2">
|
||
|
|
<input type="text" name="pair" id="pair" class="form-control p-1" placeholder="두문자를 입력하세요" autocomplete="off" >
|
||
|
|
</div>
|
||
|
|
<div class="col-auto">
|
||
|
|
<button type="submit" class="btn btn-primary btn-sm mx-1" id="submitBtn">등록</button>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
</form>
|
||
|
|
</div>
|
||
|
|
<hr>
|
||
|
|
<div class="d-flex justify-content-center align-items-center text-center">
|
||
|
|
</div>
|
||
|
|
<div class="table-responsive">
|
||
|
|
<table class="table table-bordered">
|
||
|
|
<thead>
|
||
|
|
<tr>
|
||
|
|
<th>순번</th>
|
||
|
|
<th>종류</th>
|
||
|
|
<th>모델명</th>
|
||
|
|
<th>로트번호사용 약자 두문자</th>
|
||
|
|
<th>수정/삭제</th>
|
||
|
|
</tr>
|
||
|
|
</thead>
|
||
|
|
<tbody>
|
||
|
|
<?php if (!empty($models)): ?>
|
||
|
|
<?php foreach ($models as $i => $model): ?>
|
||
|
|
<tr>
|
||
|
|
<td><?= $i + 1 ?></td>
|
||
|
|
<td>
|
||
|
|
<?php
|
||
|
|
// 모델 데이터가 배열이면 'slatitem' 값, 아니면 빈 문자열 출력
|
||
|
|
echo is_array($model) && isset($model["slatitem"])
|
||
|
|
? htmlspecialchars($model["slatitem"], ENT_QUOTES, 'UTF-8')
|
||
|
|
: '';
|
||
|
|
?>
|
||
|
|
</td>
|
||
|
|
<td>
|
||
|
|
<?php
|
||
|
|
// 모델 데이터가 배열이면 'model_name' 값, 아니면 그대로 출력
|
||
|
|
echo is_array($model) && isset($model["model_name"])
|
||
|
|
? htmlspecialchars($model["model_name"], ENT_QUOTES, 'UTF-8')
|
||
|
|
: htmlspecialchars($model, ENT_QUOTES, 'UTF-8');
|
||
|
|
?>
|
||
|
|
</td>
|
||
|
|
<td>
|
||
|
|
<?php
|
||
|
|
// 모델 데이터가 배열이면 'pair' 값, 아니면 그대로 출력
|
||
|
|
echo is_array($model) && isset($model["pair"])
|
||
|
|
? htmlspecialchars($model["pair"], ENT_QUOTES, 'UTF-8')
|
||
|
|
: '' ;
|
||
|
|
?>
|
||
|
|
</td>
|
||
|
|
<td>
|
||
|
|
<button type="button" class="btn btn-sm btn-outline-primary editBtn" data-index="<?= $i ?>">수정</button>
|
||
|
|
<button type="button" class="btn btn-sm btn-outline-danger deleteBtn" data-index="<?= $i ?>">삭제</button>
|
||
|
|
</td>
|
||
|
|
</tr>
|
||
|
|
<?php endforeach; ?>
|
||
|
|
<?php else: ?>
|
||
|
|
<tr><td colspan="4">등록된 모델이 없습니다.</td></tr>
|
||
|
|
<?php endif; ?>
|
||
|
|
</tbody>
|
||
|
|
</table>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
</div><!-- card-body -->
|
||
|
|
</div><!-- card -->
|
||
|
|
</div><!-- container -->
|
||
|
|
|
||
|
|
<!-- 반드시 새로운 페이지에 들어가야 하는 로더 숨김 스크립트 -->
|
||
|
|
<script>
|
||
|
|
$(document).ready(function(){
|
||
|
|
var loader = document.getElementById('loadingOverlay');
|
||
|
|
if(loader)
|
||
|
|
loader.style.display = 'none';
|
||
|
|
});
|
||
|
|
// jQuery 이벤트 처리
|
||
|
|
$(document).ready(function(){
|
||
|
|
// 수정 버튼 클릭 시: 해당 행의 모델명을 폼에 채워 수정 모드로 전환
|
||
|
|
$('.editBtn').on('click', function(){
|
||
|
|
var index = $(this).data('index');
|
||
|
|
var modelItem = $(this).closest('tr').find('td:eq(1)').text().trim();
|
||
|
|
var modelName = $(this).closest('tr').find('td:eq(2)').text().trim();
|
||
|
|
var Pair = $(this).closest('tr').find('td:eq(3)').text().trim();
|
||
|
|
$('#slatitem').val(modelItem);
|
||
|
|
$('#model_name').val(modelName);
|
||
|
|
$('#pair').val(Pair);
|
||
|
|
$('#index').val(index);
|
||
|
|
$('#action').val('update');
|
||
|
|
$('#submitBtn').text('수정');
|
||
|
|
});
|
||
|
|
// 삭제 버튼 클릭 시: 확인 후 폼 제출하여 삭제 처리
|
||
|
|
$('.deleteBtn').on('click', function(){
|
||
|
|
var index = $(this).data('index');
|
||
|
|
Swal.fire({
|
||
|
|
title: '모델 삭제',
|
||
|
|
text: "모델 삭제는 신중하셔야 합니다. 정말 삭제 하시겠습니까?",
|
||
|
|
icon: 'warning',
|
||
|
|
showCancelButton: true,
|
||
|
|
confirmButtonColor: '#3085d6',
|
||
|
|
cancelButtonColor: '#d33',
|
||
|
|
confirmButtonText: '삭제',
|
||
|
|
cancelButtonText: '취소'
|
||
|
|
}).then((result) => {
|
||
|
|
if (result.isConfirmed) {
|
||
|
|
$('#index').val(index);
|
||
|
|
$('#action').val('delete');
|
||
|
|
$('#addModelForm').submit();
|
||
|
|
}
|
||
|
|
});
|
||
|
|
});
|
||
|
|
|
||
|
|
});
|
||
|
|
</script>
|
||
|
|
</body>
|
||
|
|
</html>
|