Initial commit: 교육 프로젝트 배포
This commit is contained in:
@@ -0,0 +1,143 @@
|
||||
/**
|
||||
* legal_cert_print.js - 수료증 출력 클라이언트 스크립트
|
||||
*/
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
// 1. URL 쿼리 파라미터 파싱
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
const year = urlParams.get('year') || '';
|
||||
const comp = urlParams.get('comp') || '';
|
||||
const memberId = urlParams.get('member_id') || '';
|
||||
const categoryGroup = urlParams.get('category_group') || '';
|
||||
|
||||
// 파라미터 유효성 검사
|
||||
if (!year || !comp || !memberId || !categoryGroup) {
|
||||
alert('잘못된 접근이거나 필수 출력 정보 파라미터가 누락되었습니다.');
|
||||
document.body.innerHTML = `
|
||||
<div style="padding: 50px; text-align: center; font-family: 'Noto Sans KR', sans-serif;">
|
||||
<h2 style="color: #e11d48; margin-bottom: 20px;">출력 오류</h2>
|
||||
<p style="color: #4b5563; font-size: 16px;">수료증을 조회하기 위한 파라미터(년도, 회사코드, 사번, 교육과정코드)가 올바르지 않습니다.</p>
|
||||
<button onclick="window.close()" style="margin-top: 20px; padding: 10px 20px; background: #4b5563; color: white; border: none; border-radius: 6px; cursor: pointer; font-weight: bold;">창 닫기</button>
|
||||
</div>
|
||||
`;
|
||||
return;
|
||||
}
|
||||
|
||||
// API 요청 주소
|
||||
const requestUrl = `../bbs/get_legal_cert_print.php?year=${encodeURIComponent(year)}&comp=${encodeURIComponent(comp)}&member_id=${encodeURIComponent(memberId)}&category_group=${encodeURIComponent(categoryGroup)}`;
|
||||
|
||||
console.log('[CertPrint] Fetching certificate data from API...', requestUrl);
|
||||
|
||||
// 2. 백엔드 API에서 수료증 데이터 가져오기
|
||||
fetch(requestUrl)
|
||||
.then(response => {
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
return response.json();
|
||||
})
|
||||
.then(res => {
|
||||
console.log('[CertPrint] API Response:', res);
|
||||
|
||||
// 추출된 수료자 사번 리스트 (member_ids)를 개발자 도구 콘솔에 명시적으로 출력
|
||||
if (res.debug && res.debug.matched_member_ids) {
|
||||
console.log('[CertPrint] ★ 추출된 수료자 사번 리스트 (member_ids) ★:', res.debug.matched_member_ids);
|
||||
}
|
||||
|
||||
if (!res.success) {
|
||||
console.error('[CertPrint] Certificate load failed. Debug details:', res.debug || res);
|
||||
|
||||
let debugHtml = '';
|
||||
if (res.debug) {
|
||||
debugHtml = `
|
||||
<div style="margin-top: 20px; padding: 15px; background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 8px; text-align: left; max-width: 600px; margin-left: auto; margin-right: auto; font-family: monospace; font-size: 13px; color: #334155; line-height: 1.5; overflow-x: auto;">
|
||||
<strong>[서버 디버그 정보]</strong><br/>
|
||||
- 입력 연도: ${res.debug.api_params?.year || '-'}<br/>
|
||||
- 입력 법인: ${res.debug.api_params?.comp || '-'}<br/>
|
||||
- 입력 사번: ${res.debug.api_params?.member_id || '-'}<br/>
|
||||
- 입력 과정: ${res.debug.api_params?.category_group || '-'}<br/>
|
||||
- 대상 과정 교육수: ${res.debug.total_legal_cnt || 0}개<br/>
|
||||
- 조건 충족 수료자수: ${res.debug.matched_member_ids?.length || 0}명 (${res.debug.matched_member_ids?.join(', ') || '없음'})<br/>
|
||||
- 프로시저 호출 정보: ${res.debug.procedure_calls?.length || 0}건 호출 시도
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
document.body.innerHTML = `
|
||||
<div style="padding: 50px; text-align: center; font-family: 'Noto Sans KR', sans-serif;">
|
||||
<h2 style="color: #e11d48; margin-bottom: 20px; font-weight: bold;"><i class="fa-solid fa-triangle-exclamation mr-2"></i>수료증 조회 실패</h2>
|
||||
<p style="color: #4b5563; font-size: 16px;">${res.message || '수료증 정보를 조회할 수 없습니다.'}</p>
|
||||
<p style="color: #6b7280; font-size: 13px; margin-top: 10px;">자세한 쿼리 파라미터는 브라우저 콘솔로그(F12)에서도 확인하실 수 있습니다.</p>
|
||||
${debugHtml}
|
||||
<button onclick="window.close()" style="margin-top: 20px; padding: 10px 20px; background: #4b5563; color: white; border: none; border-radius: 6px; cursor: pointer; font-weight: bold; font-size: 14px;">창 닫기</button>
|
||||
</div>
|
||||
`;
|
||||
return;
|
||||
}
|
||||
|
||||
const items = Array.isArray(res.data) ? res.data : [res.data];
|
||||
|
||||
const templatePage = document.querySelector('.cert-page');
|
||||
const parent = templatePage.parentNode;
|
||||
|
||||
items.forEach((item, idx) => {
|
||||
let currentPage = templatePage;
|
||||
if (idx > 0) {
|
||||
currentPage = templatePage.cloneNode(true);
|
||||
parent.appendChild(currentPage);
|
||||
}
|
||||
|
||||
// 3. 성명 정제 (이름 뒤에 사번이 대괄호로 오는 경우 정제 ex. 홍길동[M24031] -> 홍길동)
|
||||
let rawName = item.name || '';
|
||||
let cleanName = rawName;
|
||||
if (rawName.includes('[')) {
|
||||
cleanName = rawName.split('[')[0].trim();
|
||||
}
|
||||
|
||||
// 4. 발급번호 매핑 (앞뒤에 '제', '호' 붙이기)
|
||||
let certIssueNo = item.cert_issue_no || '';
|
||||
let formattedCertNo = certIssueNo;
|
||||
if (certIssueNo && !certIssueNo.startsWith('제')) {
|
||||
formattedCertNo = `제 ${certIssueNo} 호`;
|
||||
}
|
||||
|
||||
// 5. 프론트엔드 DOM 요소 바인딩 (각 복사된 페이지 내부 요소 쿼리)
|
||||
currentPage.querySelector('#val-cert-no').textContent = formattedCertNo || '제 호';
|
||||
currentPage.querySelector('#val-name').textContent = cleanName || '-';
|
||||
currentPage.querySelector('#val-category').textContent = item.category_name || '-';
|
||||
currentPage.querySelector('#val-period').textContent = item.period || '-';
|
||||
currentPage.querySelector('#val-hours').textContent = item.total_content_tm || '-';
|
||||
currentPage.querySelector('#val-prt-date').textContent = item.prt_dt || '- 년 - 월 - 일';
|
||||
currentPage.querySelector('#val-company').textContent = item.belong_comp || '-';
|
||||
currentPage.querySelector('#val-ceo').textContent = item.ceo_name || '-';
|
||||
|
||||
// 6. 기업별 동적 스탬프 및 로고 워터마크 파일 바인딩
|
||||
const watermarkImg = currentPage.querySelector('#val-watermark');
|
||||
const stampImg = currentPage.querySelector('#val-stamp');
|
||||
|
||||
// 로고 워터마크 이미지 바인딩
|
||||
if (item.logo_url && item.logo_url.trim() !== '') {
|
||||
watermarkImg.src = item.logo_url;
|
||||
watermarkImg.style.display = 'block';
|
||||
console.log(`[CertPrint] Page ${idx+1} Logo Watermark loaded:`, item.logo_url);
|
||||
} else {
|
||||
watermarkImg.style.display = 'none';
|
||||
console.log(`[CertPrint] Page ${idx+1} No Logo Watermark.`);
|
||||
}
|
||||
|
||||
// 스탬프 직인 이미지 바인딩
|
||||
if (item.stamp_url && item.stamp_url.trim() !== '') {
|
||||
stampImg.src = item.stamp_url;
|
||||
stampImg.style.display = 'block';
|
||||
console.log(`[CertPrint] Page ${idx+1} Signature Stamp loaded:`, item.stamp_url);
|
||||
} else {
|
||||
stampImg.style.display = 'none';
|
||||
console.log(`[CertPrint] Page ${idx+1} No Signature Stamp.`);
|
||||
}
|
||||
});
|
||||
|
||||
})
|
||||
.catch(err => {
|
||||
console.error('[CertPrint] Fetch Error:', err);
|
||||
alert('데이터 통신 오류가 발생했습니다. 잠시 후 다시 시도해 주세요.');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user