- URL 하드코딩 → .env APP_URL 기반 동적 URL로 변경 - DB 연결 하드코딩 → .env 기반으로 변경 - MySQL strict mode DATE 오류 수정
390 lines
14 KiB
PHP
390 lines
14 KiB
PHP
<script>
|
|
|
|
var ajaxRequest_write = null;
|
|
var ajaxRequest = null;
|
|
var ajaxRequest5 = null;
|
|
var ajaxRequest6 = null;
|
|
var ajaxRequest7 = null;
|
|
var isDisplaying = false;
|
|
|
|
$(document).ready(function () {
|
|
displayFileLoad(); // 기존 파일 로드
|
|
// displayImageLoad(); // 기존 이미지 로드
|
|
var tablename = $("#tablename").val();
|
|
|
|
// 드롭 영역 설정
|
|
const dropArea = $("#dropArea");
|
|
dropArea.on("dragover", function (e) {
|
|
e.preventDefault();
|
|
dropArea.css("border-color", "blue"); // 드래그 중 표시
|
|
});
|
|
|
|
dropArea.on("dragleave", function (e) {
|
|
e.preventDefault();
|
|
dropArea.css("border-color", "#ccc"); // 드래그 해제 시 원래대로
|
|
});
|
|
|
|
dropArea.on("drop", function (e) {
|
|
e.preventDefault();
|
|
dropArea.css("border-color", "#ccc"); // 드롭 시 원래대로
|
|
|
|
const files = e.originalEvent.dataTransfer.files;
|
|
if (files.length > 0) {
|
|
processFiles(files, tablename, "attached", "upfile");
|
|
}
|
|
});
|
|
|
|
// 파일 선택 이벤트 처리
|
|
$("#upfile").change(function (e) {
|
|
processFiles(this.files, tablename, "attached", "upfile");
|
|
});
|
|
|
|
// // 이미지 선택 이벤트 처리
|
|
// $("#upfileimage").change(function (e) {
|
|
// processFiles(this.files, tablename, "image", "upfileimage");
|
|
// });
|
|
|
|
// 파일 업로드 및 처리 함수
|
|
function processFiles(files, tablename, item, upfilename) {
|
|
var num = $("#num").val();
|
|
if (!files || files.length === 0) {
|
|
console.warn("파일이 선택되지 않았습니다.");
|
|
return;
|
|
}
|
|
|
|
showMsgModal(3); // 파일처리중
|
|
const formData = new FormData();
|
|
for (const file of files) {
|
|
formData.append(upfilename + "[]", file);
|
|
}
|
|
|
|
// 추가 데이터 설정
|
|
formData.append("tablename", tablename);
|
|
formData.append("item", item);
|
|
formData.append("upfilename", upfilename);
|
|
formData.append("folderPath", "uploads");
|
|
formData.append("DBtable", "picuploads");
|
|
formData.append("num", num);
|
|
|
|
// AJAX 요청
|
|
$.ajax({
|
|
url: "/filedrive/fileprocess.php",
|
|
type: "POST",
|
|
enctype: "multipart/form-data",
|
|
processData: false,
|
|
contentType: false,
|
|
data: formData,
|
|
success: function (response) {
|
|
console.log("응답 데이터:", response);
|
|
|
|
let successCount = 0;
|
|
let errorCount = 0;
|
|
let errorMessages = [];
|
|
|
|
response.forEach((item) => {
|
|
if (item.status === "success") {
|
|
successCount++;
|
|
} else if (item.status === "error") {
|
|
errorCount++;
|
|
errorMessages.push(`파일: ${item.file}, 메시지: ${item.message}`);
|
|
}
|
|
});
|
|
|
|
if (successCount > 0) {
|
|
Toastify({
|
|
text: `${successCount}개의 파일이 성공적으로 업로드되었습니다.`,
|
|
duration: 2000,
|
|
close: true,
|
|
gravity: "top",
|
|
position: "center",
|
|
backgroundColor: "#4fbe87",
|
|
}).showToast();
|
|
}
|
|
|
|
if (errorCount > 0) {
|
|
Toastify({
|
|
text: `오류 발생: ${errorCount}개의 파일 업로드 실패\n상세 오류: ${errorMessages.join("\n")}`,
|
|
duration: 5000,
|
|
close: true,
|
|
gravity: "top",
|
|
position: "center",
|
|
backgroundColor: "#f44336",
|
|
}).showToast();
|
|
}
|
|
|
|
setTimeout(function () {
|
|
hideMsgModal();
|
|
if (item === "attached") displayFile();
|
|
if (item === "image") displayImage();
|
|
}, 1000);
|
|
},
|
|
error: function (jqxhr, status, error) {
|
|
console.error("업로드 실패:", jqxhr, status, error);
|
|
},
|
|
});
|
|
}
|
|
|
|
// 파일 불러오기
|
|
function displayFile() {
|
|
fetchFiles(tablename, "attached", "#displayFile");
|
|
}
|
|
|
|
// 이미지 불러오기
|
|
function displayImage() {
|
|
fetchFiles(tablename, "image", "#displayImage");
|
|
}
|
|
// 파일/이미지 데이터 가져오기
|
|
function fetchFiles(tablename, item, targetSelector) {
|
|
var tablename = $("#tablename").val();
|
|
const params = $("#num").val();
|
|
if (!params) {
|
|
console.error("ID 값이 없습니다. 데이터를 불러올 수 없습니다.");
|
|
return;
|
|
}
|
|
|
|
$.ajax({
|
|
url: "/filedrive/fileprocess.php",
|
|
type: "GET",
|
|
data: { num: params, tablename: tablename, item: item, folderPath: "uploads" },
|
|
dataType: "json",
|
|
success: function (data) {
|
|
console.log("데이터:", data);
|
|
$(targetSelector).html(""); // 기존 내용 초기화
|
|
|
|
if (Array.isArray(data) && data.length > 0) {
|
|
data.forEach(function (fileData, index) {
|
|
const realName = fileData.realname || "다운로드 파일";
|
|
const link = fileData.link || "#";
|
|
const fileId = fileData.fileId || null;
|
|
|
|
if (!fileId) {
|
|
console.error("fileId가 누락되었습니다. index: " + index, fileData);
|
|
$(targetSelector).append(
|
|
"<div class='text-danger'>파일 ID가 누락되었습니다.</div>"
|
|
);
|
|
return;
|
|
}
|
|
|
|
$(targetSelector).append(
|
|
"<div class='row mt-1 mb-2'>" +
|
|
"<div class='d-flex align-items-center justify-content-center'>" +
|
|
"<span id='file" + index + "'>" +
|
|
"<a href='#' onclick=\"popupCenter('" + link + "', 'filePopup', 800, 600); return false;\">" + realName + "</a>" +
|
|
"</span> " +
|
|
"<button type='button' class='btn btn-danger btn-sm' id='delFile" + index + "' onclick=\"deleteFile('" + index + "', '" + fileId + "', '" + tablename + "', '" + item + "')\">" +
|
|
"<i class='bi bi-trash'></i>" +
|
|
"</button>" +
|
|
"</div>" +
|
|
"</div>"
|
|
);
|
|
|
|
|
|
});
|
|
} else {
|
|
$(targetSelector).append(
|
|
""
|
|
);
|
|
}
|
|
},
|
|
error: function (error) {
|
|
console.error("파일 불러오기 오류:", error);
|
|
},
|
|
});
|
|
}
|
|
|
|
// 파일 삭제
|
|
window.deleteFile = function (index, fileId, tablename, item) {
|
|
Swal.fire({
|
|
title: "삭제 확인",
|
|
text: "정말 삭제하시겠습니까?",
|
|
icon: "warning",
|
|
showCancelButton: true,
|
|
confirmButtonText: "삭제",
|
|
cancelButtonText: "취소",
|
|
reverseButtons: true,
|
|
}).then((result) => {
|
|
if (result.isConfirmed) {
|
|
showMsgModal(3); // 파일처리중
|
|
$.ajax({
|
|
url: "/filedrive/fileprocess.php",
|
|
type: "DELETE",
|
|
data: JSON.stringify({
|
|
fileId: fileId,
|
|
tablename: tablename,
|
|
item: item,
|
|
folderPath: "uploads",
|
|
DBtable: "picuploads",
|
|
}),
|
|
contentType: "application/json",
|
|
dataType: "json",
|
|
success: function (response) {
|
|
hideMsgModal();
|
|
if (response.status === "success") {
|
|
console.log("삭제 완료:", response);
|
|
$("#file" + index).remove();
|
|
$("#delFile" + index).remove();
|
|
}
|
|
},
|
|
error: function (error) {
|
|
console.error("삭제 실패:", error);
|
|
},
|
|
});
|
|
}
|
|
});
|
|
};
|
|
|
|
});
|
|
// 기존 파일 로드 함수
|
|
function displayFileLoad() {
|
|
const data = <?php echo json_encode($savefilename_arr); ?>; // PHP에서 전달된 파일 배열
|
|
var tablename = $("#tablename").val();
|
|
|
|
$("#displayFile").html(""); // 기존 내용 초기화
|
|
|
|
if (Array.isArray(data) && data.length > 0) {
|
|
data.forEach(function (fileData, index) {
|
|
const realName = fileData.realname || "다운로드 파일";
|
|
const link = fileData.link || "#";
|
|
const fileId = fileData.fileId || null;
|
|
|
|
if (!fileId) {
|
|
console.error("fileId가 누락되었습니다. index: " + index, fileData);
|
|
$("#displayFile").append(
|
|
"<div class='text-danger'>파일 ID가 누락되었습니다.</div>"
|
|
);
|
|
return;
|
|
}
|
|
$("#displayFile").append(
|
|
"<div class='row mt-1 mb-2'>" +
|
|
"<div class='d-flex align-items-center justify-content-center'>" +
|
|
"<span id='file" + index + "'>" +
|
|
"<a href='#' onclick=\"popupCenter('" + link + "', 'filePopup', 800, 600); return false;\">" + realName + "</a>" +
|
|
"</span> " +
|
|
"<button type='button' class='btn btn-danger btn-sm' id='delFile" + index + "' onclick=\"deleteFile('" + index + "', '" + fileId + "', '" + tablename + "', 'attached')\">" +
|
|
"<i class='bi bi-trash'></i>" +
|
|
"</button>" +
|
|
"</div>" +
|
|
"</div>"
|
|
);
|
|
|
|
|
|
});
|
|
} else {
|
|
$("#displayFile").append(
|
|
""
|
|
);
|
|
}
|
|
}
|
|
|
|
// 기존 이미지 로드 함수
|
|
function displayImageLoad() {
|
|
const data = <?php echo json_encode($saveimagename_arr); ?>; // PHP에서 전달된 이미지 배열
|
|
var tablename = $("#tablename").val();
|
|
|
|
$("#displayImage").html(""); // 기존 내용 초기화
|
|
|
|
if (Array.isArray(data) && data.length > 0) {
|
|
data.forEach(function (fileData, index) {
|
|
const realName = fileData.realname || "다운로드 파일";
|
|
const thumbnail = fileData.thumbnail || "/assets/default-thumbnail.png";
|
|
const link = fileData.link || "#";
|
|
const fileId = fileData.fileId || null;
|
|
|
|
if (!fileId) {
|
|
console.error("fileId가 누락되었습니다. index: " + index, fileData);
|
|
$("#displayImage").append(
|
|
"<div class='text-danger'>파일 ID가 누락되었습니다.</div>"
|
|
);
|
|
return;
|
|
}
|
|
$("#displayImage").append(
|
|
"<div class='row mb-3'>" +
|
|
"<div class='d-flex align-items-center justify-content-center'>" +
|
|
"<a href='#' onclick=\"popupCenter('" + link + "', 'imagePopup', 800, 600); return false;\">" +
|
|
"<img id='image" + index + "' src='" + thumbnail + "' style='width:150px; height:auto;'>" +
|
|
"</a> " +
|
|
"<button type='button' class='btn btn-danger btn-sm' id='delImage" + index + "' onclick=\"deleteFile('" + index + "', '" + fileId + "', '" + tablename + "', 'image')\">" +
|
|
"<i class='bi bi-trash'></i>" +
|
|
"</button>" +
|
|
"</div>" +
|
|
"</div>"
|
|
);
|
|
|
|
});
|
|
} else {
|
|
$("#displayImage").append(
|
|
""
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 초기화 버튼 클릭 이벤트
|
|
$(document).ready(function() {
|
|
$('.initialBtn').on('click', function() {
|
|
// 초기화 확인 알림
|
|
Swal.fire({
|
|
title: '초기화',
|
|
text: "모든 데이터를 초기화하시겠습니까?",
|
|
icon: 'warning',
|
|
showCancelButton: true,
|
|
confirmButtonColor: '#3085d6',
|
|
cancelButtonColor: '#d33',
|
|
confirmButtonText: '예, 초기화합니다',
|
|
cancelButtonText: '취소'
|
|
}).then((result) => {
|
|
if (result.isConfirmed) {
|
|
// iList 값을 빈 배열로 초기화
|
|
const initialData = JSON.stringify([]); // 빈 배열로 초기화
|
|
|
|
// iList hidden input에 초기화된 데이터 설정
|
|
$('#iList').val(initialData);
|
|
|
|
// 초기화된 데이터 저장 요청
|
|
$.ajax({
|
|
url: 'insert_iList.php', // 데이터를 저장할 PHP 파일 경로
|
|
type: 'POST',
|
|
data: {
|
|
num: $('#num').val() ,
|
|
tablename: $('#tablename').val() ,
|
|
update_log: $('#update_log').val() ,
|
|
iList: initialData },
|
|
success: function(response) {
|
|
Swal.fire({
|
|
title: '초기화 완료',
|
|
text: "모든 데이터가 초기화되었습니다.",
|
|
icon: 'success',
|
|
confirmButtonText: '확인'
|
|
}).then(() => {
|
|
// 페이지 새로고침
|
|
setTimeout(function () {
|
|
hideMsgModal();
|
|
location.reload();
|
|
}, 1000);
|
|
});
|
|
},
|
|
error: function(jqxhr, status, error) {
|
|
Swal.fire({
|
|
title: '오류',
|
|
text: "초기화 중 오류가 발생했습니다.",
|
|
icon: 'error',
|
|
confirmButtonText: '확인'
|
|
});
|
|
console.log("AJAX Error: ", status, error);
|
|
}
|
|
});
|
|
}
|
|
});
|
|
});
|
|
});
|
|
|
|
// 부트스트랩 툴팁
|
|
$(document).ready(function() {
|
|
var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'));
|
|
var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {
|
|
return new bootstrap.Tooltip(tooltipTriggerEl);
|
|
});
|
|
});
|
|
|
|
</script>
|