- URL 하드코딩 → .env APP_URL 기반 동적 URL로 변경 - DB 연결 하드코딩 → .env 기반으로 변경 - MySQL strict mode DATE 오류 수정
294 lines
11 KiB
PHP
294 lines
11 KiB
PHP
<?php
|
|
// /member/initsettings.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>
|
|
<?php if($chkMobile==true) { ?>
|
|
<style>
|
|
@media (max-width: 1000px) {
|
|
body { font-size: 25px; }
|
|
.form-control, .fw-bold, .table td, .table th { font-size: 25px; }
|
|
button { font-size: 30px; }
|
|
.modal-body, .modal-title { font-size: 30px; }
|
|
}
|
|
</style>
|
|
<?php } ?>
|
|
</head>
|
|
<body>
|
|
|
|
<?php
|
|
|
|
// 이전에 저장한 소속이 있다면 불러오기
|
|
$corpSelect = $_REQUEST['corpSelect'] ?? '' ;
|
|
|
|
// JSON 파일 경로 (member 폴더 내)
|
|
$corpFile = $_SERVER['DOCUMENT_ROOT'] . '/member/corp.json';
|
|
$partFile = $_SERVER['DOCUMENT_ROOT'] . '/member/part.json';
|
|
|
|
// 소속 데이터 로드 (corp.json)
|
|
$corpData = [];
|
|
if(file_exists($corpFile)){
|
|
$corpJson = file_get_contents($corpFile);
|
|
$corpData = json_decode($corpJson, true);
|
|
if(!is_array($corpData)) { $corpData = []; }
|
|
}
|
|
|
|
// 부서 데이터 로드 (part.json)
|
|
// 이제 부서 데이터는 각 요소가 ['corp' => ..., 'part' => ...] 형식의 배열임
|
|
$partData = [];
|
|
if(file_exists($partFile)){
|
|
$partJson = file_get_contents($partFile);
|
|
$partData = json_decode($partJson, true);
|
|
if(!is_array($partData)) { $partData = []; }
|
|
}
|
|
|
|
// POST 요청 처리 (소속 또는 부서)
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$entity = isset($_POST['entity']) ? $_POST['entity'] : '';
|
|
$action = isset($_POST['action']) ? $_POST['action'] : '';
|
|
$index = isset($_POST['index']) ? intval($_POST['index']) : -1;
|
|
$name = isset($_POST['name']) ? trim($_POST['name']) : '';
|
|
|
|
if ($entity === 'corp') {
|
|
// 소속 처리 (기존 코드 그대로)
|
|
if ($action === 'insert' && $name !== '') {
|
|
$corpData[] = $name;
|
|
} elseif ($action === 'update' && $name !== '' && $index >= 0 && $index < count($corpData)) {
|
|
$corpData[$index] = $name;
|
|
} elseif ($action === 'delete' && $index >= 0 && $index < count($corpData)) {
|
|
array_splice($corpData, $index, 1);
|
|
}
|
|
file_put_contents($corpFile, json_encode($corpData, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
|
|
} elseif ($entity === 'part') {
|
|
// 부서 처리: 부서 정보는 소속(corp)과 부서명(part)을 함께 저장
|
|
$dept = [
|
|
'corp' => isset($_POST['corpSelect']) ? trim($_POST['corpSelect']) : '',
|
|
'part' => $name
|
|
];
|
|
if ($action === 'insert' && $dept['part'] !== '') {
|
|
$partData[] = $dept;
|
|
} elseif ($action === 'update' && $dept['part'] !== '' && $index >= 0 && $index < count($partData)) {
|
|
$partData[$index] = $dept;
|
|
} elseif ($action === 'delete' && $index >= 0 && $index < count($partData)) {
|
|
array_splice($partData, $index, 1);
|
|
}
|
|
file_put_contents($partFile, json_encode($partData, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
|
|
}
|
|
// header("Location:" . $WebSite . "member/initsettings.php");
|
|
}
|
|
?>
|
|
|
|
<div class="container mt-3">
|
|
<!-- 소속 관리 카드 (기존 그대로) -->
|
|
<div class="card mb-4">
|
|
<div class="card-header d-flex justify-content-between align-items-center">
|
|
<h3 class="mb-0">소속 관리</h3>
|
|
<div>
|
|
<button type="button" class="btn btn-dark btn-sm mx-1" onclick="location.reload();">
|
|
<i class="bi bi-arrow-clockwise"></i>
|
|
</button>
|
|
<button type="button" class="btn btn-dark btn-sm mx-1" onclick="window.close();">
|
|
<i class="bi bi-x-square"></i> 닫기
|
|
</button>
|
|
</div>
|
|
</div>
|
|
<div class="card-body">
|
|
<!-- 소속 추가/수정 폼 -->
|
|
<form id="corpForm" method="post" action="initsettings.php" class="row g-3 mb-1">
|
|
<input type="hidden" name="entity" value="corp">
|
|
<input type="hidden" name="action" id="corpAction" value="insert">
|
|
<input type="hidden" name="index" id="corpIndex" value="-1">
|
|
<div class="d-flex mt-3 mb-1 justify-content-center align-items-center">
|
|
<input type="text" name="name" id="corpName" class="form-control mx-1 w150px" placeholder="소속명 입력" autocomplete="off">
|
|
<button type="submit" class="btn btn-primary btn-sm mx-1" id="corpSubmitBtn">등록</button>
|
|
</div>
|
|
</form>
|
|
<!-- 소속 목록 테이블 -->
|
|
<div class="table-responsive">
|
|
<table class="table table-bordered">
|
|
<thead>
|
|
<tr>
|
|
<th>순번</th>
|
|
<th>소속명</th>
|
|
<th>액션</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php if (!empty($corpData)): ?>
|
|
<?php foreach ($corpData as $i => $corp): ?>
|
|
<tr>
|
|
<td><?= $i + 1 ?></td>
|
|
<td><?= htmlspecialchars($corp, ENT_QUOTES, 'UTF-8') ?></td>
|
|
<td>
|
|
<button type="button" class="btn btn-sm btn-outline-primary corpEditBtn" data-index="<?= $i ?>">수정</button>
|
|
<button type="button" class="btn btn-sm btn-outline-danger corpDeleteBtn" data-index="<?= $i ?>">삭제</button>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
<?php else: ?>
|
|
<tr><td colspan="3">등록된 소속이 없습니다.</td></tr>
|
|
<?php endif; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div><!-- card-body -->
|
|
</div><!-- card -->
|
|
|
|
<!-- 부서 관리 카드 (수정됨) -->
|
|
<div class="card">
|
|
<div class="card-header d-flex justify-content-between align-items-center">
|
|
<h3 class="mb-0">부서 관리</h3>
|
|
<div>
|
|
<button type="button" class="btn btn-dark btn-sm mx-1" onclick="location.reload();">
|
|
<i class="bi bi-arrow-clockwise"></i>
|
|
</button>
|
|
<button type="button" class="btn btn-dark btn-sm mx-1" onclick="window.close();">
|
|
<i class="bi bi-x-square"></i> 닫기
|
|
</button>
|
|
</div>
|
|
</div>
|
|
<div class="card-body">
|
|
<!-- 부서 추가/수정 폼 -->
|
|
<form id="partForm" method="post" action="initsettings.php" class="row g-3 mb-3">
|
|
<input type="hidden" name="entity" value="part">
|
|
<input type="hidden" name="action" id="partAction" value="insert">
|
|
<input type="hidden" name="index" id="partIndex" value="-1">
|
|
<div class="d-flex mt-3 mb-1 justify-content-center align-items-center">
|
|
소속
|
|
<select id="corpSelect" name="corpSelect" class="form-select d-flex align-items-center w100px ms-2 me-5" style="font-size: 0.9rem; height: 32px;" >
|
|
<?php foreach($corpData as $corp): ?>
|
|
<option value="<?= htmlspecialchars($corp, ENT_QUOTES, 'UTF-8') ?>"
|
|
<?= ($corpSelect === $corp) ? 'selected' : '' ?>>
|
|
<?= htmlspecialchars($corp, ENT_QUOTES, 'UTF-8') ?>
|
|
</option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
부서명
|
|
<input type="text" name="name" id="partName" class="form-control d-flex align-items-center w120px ms-2 me-3" placeholder="부서명 입력" autocomplete="off">
|
|
|
|
<button type="submit" class="btn btn-primary btn-sm mx-1" id="partSubmitBtn">등록</button>
|
|
</div>
|
|
|
|
</form>
|
|
<!-- 부서 목록 테이블 -->
|
|
<div class="table-responsive">
|
|
<table class="table table-bordered">
|
|
<thead>
|
|
<tr>
|
|
<th>순번</th>
|
|
<th>소속</th>
|
|
<th>부서명</th>
|
|
<th>액션</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php if (!empty($partData)): ?>
|
|
<?php foreach ($partData as $i => $dept): ?>
|
|
<tr>
|
|
<td><?= $i + 1 ?></td>
|
|
<td><?= isset($dept['corp']) ? htmlspecialchars($dept['corp'], ENT_QUOTES, 'UTF-8') : '' ?></td>
|
|
<td><?= isset($dept['part']) ? htmlspecialchars($dept['part'], ENT_QUOTES, 'UTF-8') : '' ?></td>
|
|
<td>
|
|
<button type="button" class="btn btn-sm btn-outline-primary partEditBtn" data-index="<?= $i ?>">수정</button>
|
|
<button type="button" class="btn btn-sm btn-outline-danger partDeleteBtn" 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';
|
|
});
|
|
</script>
|
|
|
|
<script>
|
|
// jQuery 이벤트 처리
|
|
$(document).ready(function(){
|
|
// 소속 수정 버튼 클릭
|
|
$('.corpEditBtn').on('click', function(){
|
|
var index = $(this).data('index');
|
|
var corpName = $(this).closest('tr').find('td:eq(1)').text().trim();
|
|
$('#corpName').val(corpName);
|
|
$('#corpIndex').val(index);
|
|
$('#corpAction').val('update');
|
|
// 폼 제출 버튼 텍스트 변경 (필요시)
|
|
});
|
|
// 소속 삭제 버튼 (Swal.fire 사용)
|
|
$('.corpDeleteBtn').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) {
|
|
$('#corpIndex').val(index);
|
|
$('#corpAction').val('delete');
|
|
$('#corpForm').submit();
|
|
}
|
|
});
|
|
});
|
|
|
|
// 부서 수정 버튼 클릭
|
|
$('.partEditBtn').on('click', function(){
|
|
var index = $(this).data('index');
|
|
var row = $(this).closest('tr');
|
|
var corpValue = row.find('td:eq(1)').text().trim();
|
|
var partValue = row.find('td:eq(2)').text().trim();
|
|
$('#corpSelect').val(corpValue);
|
|
$('#partName').val(partValue);
|
|
$('#partIndex').val(index);
|
|
$('#partAction').val('update');
|
|
$('#partSubmitBtn').text('수정');
|
|
});
|
|
// 부서 삭제 버튼 클릭 (Swal.fire 사용)
|
|
$('.partDeleteBtn').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) {
|
|
$('#partIndex').val(index);
|
|
$('#partAction').val('delete');
|
|
$('#partForm').submit();
|
|
}
|
|
});
|
|
});
|
|
});
|
|
</script>
|
|
|
|
<?php include $_SERVER['DOCUMENT_ROOT'] . '/common/modal.php'; ?>
|
|
</body>
|
|
</html>
|