first commit
This commit is contained in:
496
survey_to_pdf/survey_layout.asp
Normal file
496
survey_to_pdf/survey_layout.asp
Normal file
@@ -0,0 +1,496 @@
|
||||
|
||||
<!--#include Virtual="/include/Header.asp" -->
|
||||
<%
|
||||
Dim PRJCODE : PRJCODE = request("PRJCODE")
|
||||
Dim IDKEY : IDKEY = request("IDKEY")
|
||||
Dim HCV : HCV = request("HCV")
|
||||
Dim PAGENAME : PAGENAME = request("QID")
|
||||
%>
|
||||
<style>
|
||||
html,
|
||||
body {
|
||||
height: 100%;
|
||||
background-color: #f8f8f8e3;
|
||||
}
|
||||
|
||||
form>.container-fluid,
|
||||
body>form {
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
|
||||
|
||||
.rptext {
|
||||
margin-left: 5px;
|
||||
padding: 2px;
|
||||
background-color: rgba(255, 255, 0, 0.5);
|
||||
}
|
||||
|
||||
@media all and (min-width: 960px) {
|
||||
|
||||
table td,
|
||||
table th {
|
||||
font-size: 15px !important;
|
||||
}
|
||||
}
|
||||
|
||||
.scale_label {
|
||||
word-break: keep-all;
|
||||
}
|
||||
|
||||
.col-xl-9 {
|
||||
max-width: 1000px !important;
|
||||
}
|
||||
|
||||
#qmain-box {
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
#qmain-box::-webkit-scrollbar {
|
||||
width: 6px
|
||||
}
|
||||
|
||||
#qmain-box::-webkit-scrollbar-thumb {
|
||||
background-color: rgb(179, 179, 179);
|
||||
border-radius: 15px;
|
||||
background-clip: padding-box;
|
||||
border: 1px solid transparent;
|
||||
}
|
||||
</style>
|
||||
|
||||
<!-- 그리는 js -->
|
||||
<script src="/module/Qmodule/attr.js"></script>
|
||||
<script src="/module/Qmodule/single.js"></script>
|
||||
<script src="/module/Qmodule/com.js"></script>
|
||||
<script src="/module/Qmodule/open.js"></script>
|
||||
<script src="/module/Qmodule/multi.js"></script>
|
||||
<script src="/module/Qmodule/rank.js"></script>
|
||||
<script src="/module/Qmodule/scale.js"></script>
|
||||
<script src="/module/Qmodule/group.js"></script>
|
||||
<script src="/module/Qmodule/description.js"></script>
|
||||
<script src="/module/survey.js"></script>
|
||||
<script src="/store/store_.js"></script>
|
||||
|
||||
<!-- 문항 생성 및 문항 내부 로직 모듈화 -->
|
||||
<script src="/module/CreateQuestion.js"></script>
|
||||
|
||||
<body>
|
||||
<form name="survey" action="Question.asp" method="POST" onsubmit="return false">
|
||||
<div class="container-fluid">
|
||||
<div class="row justify-content-center h-100">
|
||||
<div class="col-sm-12 col-md-12 col-lg-10 col-xl-9 pt-1 pb-1 shadow-sm bg-white h-100" id="qmain-box">
|
||||
<div class="col-sm-12 col-md-12 col-lg-10 col-xl-9 p-1 bg-light text-dark border rounded">
|
||||
<div class="m-2 p-1 border rounded bg-white child-question" id="question_body" >
|
||||
</div>
|
||||
<input name="PCODE" type="hidden" value="<%=PRJCODE%>"/>
|
||||
<input name="PAGENAME" type="hidden" value="<%=PAGENAME%>"/>
|
||||
<input name="IDKEY" type="hidden" value="<%=IDKEY%>"/>
|
||||
<% IF IDKEY = "" THEN %>
|
||||
<input name="SURVEYTYPE" type="hidden" value="TEST"/>
|
||||
<% END IF %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</body>
|
||||
<script>
|
||||
(() => {
|
||||
const PRJ_ROOT = "/project/<%=PRJCODE%>/"; // 끝에 / 필수
|
||||
|
||||
const isAbsolute = (u) =>
|
||||
/^(?:[a-z][a-z0-9+.-]*:)?\/\//i.test(u) || u.startsWith("/");
|
||||
|
||||
const rewrite = (u) => {
|
||||
if (typeof u !== "string" || isAbsolute(u)) return u;
|
||||
// "./", "../", "include/..." 등 모든 "상대경로"를 프로젝트 루트 기준으로 해석
|
||||
return new URL(u, location.origin + PRJ_ROOT).toString();
|
||||
};
|
||||
|
||||
// fetch 리라이트
|
||||
if (window.fetch) {
|
||||
const _fetch = window.fetch;
|
||||
window.fetch = (input, init) => {
|
||||
if (typeof input === "string") input = rewrite(input);
|
||||
else if (input && typeof input.url === "string") {
|
||||
// Request는 immutable → 새 Request 생성
|
||||
input = new Request(rewrite(input.url), input);
|
||||
}
|
||||
return _fetch(input, init);
|
||||
};
|
||||
}
|
||||
|
||||
// XHR 리라이트 (jQuery ajax 포함)
|
||||
const _open = XMLHttpRequest.prototype.open;
|
||||
XMLHttpRequest.prototype.open = function (method, url, ...rest) {
|
||||
return _open.call(this, method, rewrite(url), ...rest);
|
||||
};
|
||||
|
||||
// 동적 src/href 세팅까지 커버 (script/img/link 등)
|
||||
const _setAttr = Element.prototype.setAttribute;
|
||||
Element.prototype.setAttribute = function (name, value) {
|
||||
if ((name === "src" || name === "href") && typeof value === "string") {
|
||||
value = rewrite(value);
|
||||
}
|
||||
return _setAttr.call(this, name, value);
|
||||
};
|
||||
})();
|
||||
</script>
|
||||
<script src="/project/<%=PRJCODE%>/js/hard_func.js?dt=<%=HCV%>"></script>
|
||||
<script>
|
||||
var src = "/module/Qmodule/"
|
||||
var ajaxurl = "/project/<%=PRJCODE%>/include/ajax.asp"
|
||||
var qinfo
|
||||
var qx
|
||||
var jx
|
||||
var g
|
||||
var defaultdesign = {
|
||||
"single": "SM1",
|
||||
"multi": "MM1",
|
||||
"com": "CM1",
|
||||
"scale": "SCM1",
|
||||
"rank": "RM1",
|
||||
"open": "OM1",
|
||||
"attr": "AM1"
|
||||
}
|
||||
var defaultjs = {
|
||||
"single": "SJ1",
|
||||
"multi": "MJ1",
|
||||
"com": "CJ1",
|
||||
"scale": "SCJ1",
|
||||
"rank": "RJ1",
|
||||
"open": "OJ1",
|
||||
"attr": "AJ1"
|
||||
}
|
||||
var page_logic = "";
|
||||
var match_language = ""
|
||||
|
||||
var logic_to_text = function(logic, vqid) {
|
||||
var html_txt = ""
|
||||
var item_to_text = function(item){
|
||||
var rtxt = item.condition.map(function(ele){
|
||||
var qid = ele.va.split("_")
|
||||
return (ele. cd ? ele.cd : "") + " " + (vqid[qid[0]] + (qid.length > 1 ? "_"+qid.slice(1).join("_") : "" )) + " " + ele.op + " " + ele.co
|
||||
})
|
||||
rtxt = rtxt.join(" ") + " ☞ " + vqid[item.nextpage];
|
||||
return rtxt;
|
||||
}
|
||||
if(!logic){
|
||||
return ""
|
||||
} else {
|
||||
logic = JSON.parse(logic);
|
||||
var p = logic["p"].length;
|
||||
var n = logic["n"].length;
|
||||
if(p) {
|
||||
var ptext = "진입 로직 : "
|
||||
logic["p"].forEach(function(item, i){
|
||||
if(i) ptext += " // "
|
||||
ptext += item_to_text(item);
|
||||
});
|
||||
html_txt += "<div class='prev_logic' style='font-weight:bold'>"+ ptext + "</div>"
|
||||
}
|
||||
|
||||
if(n) {
|
||||
var ntext = " 사후 로직 : "
|
||||
logic["n"].forEach(function(item, i){
|
||||
if(i) ntext += " // "
|
||||
ntext += item_to_text(item);
|
||||
});
|
||||
|
||||
html_txt += "<div class='after_logic' style='font-weight:bold'>"+ ntext + "</div>"
|
||||
}
|
||||
}
|
||||
return html_txt
|
||||
}
|
||||
|
||||
const replaceImgSrc = () => {
|
||||
const fromPrefix = "image/";
|
||||
const fromPrefix2 = "./image/";
|
||||
const toPrefix = "/project/<%=PRJCODE%>/image/";
|
||||
|
||||
document.querySelectorAll('img[src]').forEach(img => {
|
||||
const src = img.getAttribute('src') || "";
|
||||
if (src.startsWith(fromPrefix2)) {
|
||||
img.setAttribute('src', toPrefix + src.slice(fromPrefix2.length));
|
||||
}
|
||||
else if (src.startsWith(fromPrefix)) {
|
||||
img.setAttribute('src', toPrefix + src.slice(fromPrefix.length));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const setUserData = () => {
|
||||
if(!parent.userData) return false;
|
||||
|
||||
const pageName = $("input[name=PAGENAME]").val();
|
||||
const subData = parent.userData[pageName];
|
||||
|
||||
if(subData){
|
||||
try{
|
||||
Object.keys(subData).forEach(function (key) {
|
||||
var qData = subData[key];
|
||||
var $content = $("form");
|
||||
var $target = $content.find("[name=" + key + "]:eq(0)");
|
||||
|
||||
if ($target.length === 1) {
|
||||
if ($target.prop("tagName") === "INPUT") {
|
||||
switch ($target.attr("type")) {
|
||||
case "hidden":
|
||||
$content.find("input[id^=" + key.split("_")[0] + "]").val(qData).trigger("change");
|
||||
|
||||
if($("#file_"+key)){
|
||||
$(`#file_${key}`)
|
||||
.siblings("div")
|
||||
.first()
|
||||
.css("line-height", "");
|
||||
<%IF FALSE THEN%>
|
||||
const url =
|
||||
`${window.location.origin}/ProjectUpload/` +
|
||||
`${encodeURIComponent("<%=PRJCODE%>")}/` +
|
||||
`${encodeURIComponent("<%=IDKEY%>")}/` +
|
||||
`${encodeURIComponent(key)}/` +
|
||||
`${encodeURIComponent(qData)}`;
|
||||
|
||||
const $preview = $("#preview_Q8_1");
|
||||
const $img = $("<img>", {
|
||||
src: url,
|
||||
class: "img-fluid",
|
||||
css: {
|
||||
maxHeight: "600px",
|
||||
objectFit: "contain"
|
||||
}
|
||||
});
|
||||
|
||||
//신분증 같은 이미지기 있고 해당 페이지가 외부로 유출 될 수 있기 떄문에 주석
|
||||
$preview.empty().append($img).show();
|
||||
<%END IF%>
|
||||
}
|
||||
break;
|
||||
case "checkbox":
|
||||
$content.find("input[name=" + key + "][value=" + qData + "]").trigger("click").trigger("change")
|
||||
break;
|
||||
case "radio":
|
||||
$content.find("input[name=" + key + "][value=" + qData + "]").trigger("click").trigger("change")
|
||||
break;
|
||||
case "text":
|
||||
if (key.indexOf("AT") > -1) {
|
||||
$content.find("input[name=" + key + "]").closest("TD").find("input[type=checkbox]").trigger("click").trigger("change");
|
||||
}
|
||||
$content.find("input[name=" + key + "]").prop("disabled", false).val(qData).trigger("change")
|
||||
break;
|
||||
case "number":
|
||||
$content.find("input[name=" + key + "]").prop("disabled", false).val(qData).trigger("change")
|
||||
break;
|
||||
|
||||
}
|
||||
} else if ($target.prop("tagName") === "SELECT") {
|
||||
$content.find("SELECT[name=" + key + "]").val(qData).trigger("change")
|
||||
} else {
|
||||
$content.find("textarea[name=" + key + "]").prop("disabled", false).val(qData).trigger("change")
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
catch(ex){
|
||||
console.error(ex)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function waitNextTick() {
|
||||
return new Promise(function (resolve) {
|
||||
setTimeout(resolve, 0);
|
||||
});
|
||||
}
|
||||
|
||||
function waitAjaxIdle() {
|
||||
return new Promise(function (resolve) {
|
||||
if (!window.jQuery || typeof $.active !== "number") {
|
||||
setTimeout(resolve, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
if ($.active === 0) {
|
||||
setTimeout(resolve, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
$(document).one("ajaxStop", function () {
|
||||
setTimeout(resolve, 0);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async function runEfunc(qid) {
|
||||
try {
|
||||
efunc(qid);
|
||||
|
||||
// click 이벤트 안에서 ajax가 늦게 시작되는 경우 대비
|
||||
await waitNextTick();
|
||||
|
||||
await waitAjaxIdle();
|
||||
}
|
||||
catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
function notifyLayoutReadyWhenAjaxIdle(qid, maxWaitMs = 4000) {
|
||||
try {
|
||||
const send = () => {
|
||||
// paint 안정화(저사양에서 특히 중요)
|
||||
requestAnimationFrame(() => requestAnimationFrame(() => {
|
||||
if (window.parent && window.parent !== window) {
|
||||
window.parent.postMessage(
|
||||
{ type: "KON_LAYOUT_READY", qid: qid },
|
||||
location.origin
|
||||
);
|
||||
}
|
||||
}));
|
||||
};
|
||||
|
||||
// jQuery 없으면 그냥 보냄
|
||||
if (!window.jQuery || typeof jQuery.active !== "number") {
|
||||
send();
|
||||
return;
|
||||
}
|
||||
|
||||
const start = Date.now();
|
||||
const poll = () => {
|
||||
// iframe window 기준 Ajax가 모두 끝났을 때($.get, $.getJSON 포함)
|
||||
if (jQuery.active === 0) return send();
|
||||
|
||||
if (Date.now() - start > maxWaitMs) return send(); // 안전 타임아웃
|
||||
setTimeout(poll, 30);
|
||||
};
|
||||
|
||||
poll();
|
||||
} catch (e) {
|
||||
// 실패해도 페이지는 돌아가야 함
|
||||
try { /* noop */ } catch (_) {}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$("document").ready(function () {
|
||||
kon.survey.PKEY = "<%=PRJCODE%>"
|
||||
|
||||
$.when(
|
||||
$.getJSON("/project/<%=PRJCODE%>/include/var_qid.json"), /* 문항 ID - 문번 */
|
||||
$.getJSON("/store/hard_language.json"), /* Alert 창 */
|
||||
ajax_returnData(ajaxurl, { "COMMAND": "QINFO", "CODE": "<%=PRJCODE%>", "QCODE": "<%=PAGENAME%>","IDKEY":""}) /* 문항 정보 */
|
||||
).done(function (variable_qid, language_pack, qinfo) {
|
||||
qinfo = qinfo[0] /* 문항 정보 */
|
||||
language_pack = language_pack[0] /* 언어 팩 */
|
||||
variable_qid = variable_qid[0] /* 문항명과 QID 매칭 */
|
||||
var new_vqid = {
|
||||
"END" : "설문 완료",
|
||||
"SCREEN" : "대상자 아님",
|
||||
"QUOTA" : "할당 초과",
|
||||
}
|
||||
Object.keys(variable_qid).forEach(function(key){
|
||||
new_vqid[variable_qid[key]] = key
|
||||
})
|
||||
|
||||
const qid_1 = "<%=PAGENAME%>";
|
||||
const sel_1 = `#question_body [id^="${qid_1}_"]`;
|
||||
|
||||
var group_flag = false;
|
||||
var browername = isBrowerCheck();
|
||||
|
||||
kon.survey.global_flag = $("input[name=GLOBALSURVEY]").val();
|
||||
kon.survey.global_variable = $("input[name=GLOBALVARIABLE]").val();
|
||||
|
||||
|
||||
if (qinfo.qx.qgroup) group_flag = true;
|
||||
if (!group_flag) { /* 그룹 문항이 아닌 경우 */
|
||||
qx = qinfo["qx"]; // 문항 정보
|
||||
jx = qinfo["jx"] || false; // 로직
|
||||
$("#question_body").append(logic_to_text(jx, new_vqid))
|
||||
|
||||
/* 페이지에 타이틀, 안내문, 페이지 이름, 데이터, 데이터 그룹 포함시킴 */
|
||||
kon.qmake.setTitle(qx.title)
|
||||
kon.qmake.setDescription(qx.description)
|
||||
kon.qmake.setPageName("<%=PAGENAME%>")
|
||||
|
||||
kon.qmake.setData(qx.dataset);
|
||||
kon.qmake.setGroup(qx.datagroup[qx.qtype] || "");
|
||||
|
||||
/* 디자인 타입 세팅 */
|
||||
var a = kon.qmake[qx.qtype]();
|
||||
var designtype = qx.stype || defaultdesign[qx.qtype];
|
||||
qx.option.oflag = ""
|
||||
a[designtype](qx.option || "-");
|
||||
|
||||
} else {
|
||||
/* 그룹 문항 */
|
||||
var qgroup = qinfo.qx.qgroup;
|
||||
g = kon.qmake["group"]();
|
||||
var order = ""
|
||||
var setg = {
|
||||
"title": [],
|
||||
"description": [],
|
||||
"datagroup": [],
|
||||
"dataset": [],
|
||||
"variable": [],
|
||||
"qtype": [],
|
||||
"stype": [],
|
||||
"option": []
|
||||
}
|
||||
|
||||
qinfo = ajax_returnData(ajaxurl, { "COMMAND": "GROUP", "CODE": "<%=PRJCODE%>", "GROUP": qgroup });
|
||||
jx = qinfo.var[0].jx /* 그룹문항 로직 - 첫번째가 기준 */
|
||||
|
||||
$("#question_body").append(logic_to_text(jx, new_vqid))
|
||||
var varlist = qinfo.var.map(function (v) { return "'" + v.QID + "'" }).join(",");
|
||||
|
||||
kon.survey.translation_info(varlist, kon.survey.tv[kon.survey.global_variable], qinfo, true)
|
||||
qinfo.var.forEach(function (e, id) {
|
||||
if (regex_test(global.pattern.datalabel, e.qx.title) || regex_test(global.pattern.datalabel, e.qx.description))
|
||||
kon.survey.replace_responed_label(e.qx, variable_qid);
|
||||
setg["title"].push(e.qx.title)
|
||||
setg["description"].push(e.qx.description)
|
||||
setg["datagroup"].push(e.qx.datagroup.attr)
|
||||
setg["dataset"].push(e.qx.dataset)
|
||||
setg["variable"].push(e.QID)
|
||||
setg["qtype"].push(e.qx.qtype);
|
||||
setg["stype"].push(e.qx.stype);
|
||||
e.qx.option.oflag = ""
|
||||
setg["option"].push(e.qx.option);
|
||||
if (id === qinfo.var.length - 1) {
|
||||
$("input[name=PAGENAME]").val(e.QID);
|
||||
order = e.Qorder;
|
||||
}
|
||||
})
|
||||
|
||||
g.setVariable(setg["variable"])
|
||||
g.setData(setg["dataset"])
|
||||
g.setDatagroup(setg["datagroup"])
|
||||
g.setQtype(setg["qtype"])
|
||||
g.setStype(setg["stype"]);
|
||||
g.setTitle(setg["title"])
|
||||
g.setDescription(setg["description"])
|
||||
g.setOption(setg["option"])
|
||||
g[qinfo.stype](qinfo.option || "");
|
||||
}
|
||||
|
||||
(async function () {
|
||||
try {
|
||||
await runEfunc("ALL");
|
||||
await runEfunc("<%=PAGENAME%>");
|
||||
|
||||
replaceImgSrc();
|
||||
setUserData();
|
||||
}
|
||||
catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
finally {
|
||||
notifyLayoutReadyWhenAjaxIdle("<%=PAGENAME%>");
|
||||
}
|
||||
})();
|
||||
|
||||
}) /* when.done */
|
||||
}); /* document.ready */
|
||||
</script>
|
||||
374
survey_to_pdf/survey_layout_total.asp
Normal file
374
survey_to_pdf/survey_layout_total.asp
Normal file
@@ -0,0 +1,374 @@
|
||||
<!--#include Virtual="/Lib/Config.asp" -->
|
||||
<%
|
||||
Dim PTITLE : PTITLE = request("PTITLE")
|
||||
Dim PRJCODE : PRJCODE = request("PRJCODE")
|
||||
Dim SID : SID = request("SID")
|
||||
Dim ST : ST = request("ST")
|
||||
Dim FILENAME : FILENAME = PRJCODE
|
||||
Dim IsAutoDownload : IsAutoDownload = "1"
|
||||
|
||||
IF request("AD") = "FALSE" THEN
|
||||
IsAutoDownload = "0"
|
||||
END IF
|
||||
|
||||
IF SID <> "" THEN
|
||||
FILENAME = FILENAME & "_" & SID
|
||||
END IF
|
||||
|
||||
Dim HEIGHT : HEIGHT = 1320
|
||||
|
||||
Dim SQL : SQL = ""
|
||||
Dim Rcset : Set Rcset = Server.CreateObject("ADODB.Recordset")
|
||||
Call DBConnect2()
|
||||
SQL = " select QID,Qorder from QUESTION where Qorder in ( " &vbcrlf
|
||||
SQL = SQL & " select ISNULL(qx,Qorder) " &vbcrlf
|
||||
SQL = SQL & " from QUESTION as Qu " &vbcrlf
|
||||
SQL = SQL & " OUTER APPLY ( " &vbcrlf
|
||||
SQL = SQL & " select min(B.Qorder) as qx from [QUESTION] B where " &vbcrlf
|
||||
SQL = SQL & " PKEY = '"& PRJCODE &"' and " &vbcrlf
|
||||
SQL = SQL & " JSON_VALUE(QUESTIONJSON,'$.qgroup') = JSON_VALUE(Qu.QUESTIONJSON,'$.qgroup') and " &vbcrlf
|
||||
SQL = SQL & " JSON_VALUE(QUESTIONJSON,'$.qgroup') <> '' " &vbcrlf
|
||||
SQL = SQL & " group by JSON_VALUE(QUESTIONJSON,'$.qgroup') " &vbcrlf
|
||||
SQL = SQL & " ) RC " &vbcrlf
|
||||
SQL = SQL & " WHERE PKEY = '"& PRJCODE &"' " &vbcrlf
|
||||
SQL = SQL & " ) and PKEY = '"& PRJCODE &"' order by cast(Qorder as int) " &vbcrlf
|
||||
Rcset.Open SQL, DBConn, 3,1,1
|
||||
|
||||
SQL = "SELECT JSON_VALUE([PROJECTJSON], '$.must.title') AS PRJ_TITLE FROM [PROJECT] WHERE PKEY = '" & PRJCODE & "'"
|
||||
Dim Rcset2 : Set Rcset2 = Server.CreateObject("ADODB.Recordset")
|
||||
Rcset2.Open SQL, DBConn, 3,1,1
|
||||
|
||||
Dim PRJNAME : PRJNAME = Rcset2("PRJ_TITLE")
|
||||
|
||||
%>
|
||||
<!DOCTYPE html>
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
|
||||
<head>
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<meta http-equiv="Page-Enter" content="revealtrans(Duration=1,Transition=12)" />
|
||||
<meta name="viewport" content="width=device-width">
|
||||
|
||||
<title> KRI ONLINE</title>
|
||||
|
||||
<script src="/js/jquery-1.10.2.min.js"></script>
|
||||
|
||||
<link href="/bootstrap-4.4.1/css/bootstrap.min.css" rel="stylesheet" />
|
||||
<script src="/bootstrap-4.4.1/js/bootstrap.min.js"></script>
|
||||
|
||||
<!-- js 기능 모듈화 -->
|
||||
<script src="/js/kfunc.js"></script>
|
||||
<script src="/js/knode.js"></script>
|
||||
<script src="/js/polyfill.js"></script>
|
||||
<script src="/js/bluebird.min.js"></script>
|
||||
<script src="/module/survey.js"></script>
|
||||
<script src="/store/store_.js"></script>
|
||||
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.3.1/jspdf.umd.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/1.3.2/html2canvas.min.js"></script>
|
||||
<style>
|
||||
table td,
|
||||
table th {
|
||||
font-size: 15px !important;
|
||||
}
|
||||
|
||||
.scale_label {
|
||||
word-break: keep-all;
|
||||
}
|
||||
|
||||
.col-xl-9 {
|
||||
max-width: 1000px !important;
|
||||
}
|
||||
|
||||
.main_body {
|
||||
height: <%=HEIGHT%>px;
|
||||
}
|
||||
|
||||
#wrapper { position: fixed; inset: 0; height: 100dvh; }
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="wrapper" class="w-100 bg-white d-flex justify-content-center flex-column align-items-center" style="z-index: 100;">
|
||||
<span id="wrapperSpan"></span>
|
||||
<div id="surveyprogress" style="width:350px">
|
||||
<div class="progress m-2">
|
||||
<div id="surveyprogressbar" class="progress-bar progress-bar-striped progress-bar-animated"
|
||||
role="progressbar" aria-valuenow="75" aria-valuemin="0" aria-valuemax="100"> </div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<% IF PTITLE <> "NONE" THEN %>
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-sm-12 col-md-12 col-lg-10 col-xl-9 text-center">
|
||||
<div id="project-name" class="d-flex align-items-center justify-content-center" style="height:70px;">
|
||||
<h3 class="m-0"><%=PRJNAME%></h3>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<% END IF %>
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-sm-12 col-md-12 col-lg-10 col-xl-9 text-center">
|
||||
<div id="pdf-download" class="d-flex align-items-center justify-content-between px-3" style="height:70px;">
|
||||
<div class="d-flex align-items-center justify-content-start w-75 text-left">
|
||||
<input type='text' class="form-control d-inline-block w-50" id="txtSearch" value="<%=SID%>"/>
|
||||
<input type='button' class="btn btn-primary" id="btnSearch" value="SID 검색"/>
|
||||
</div>
|
||||
<% IF IsAutoDownload = "0" THEN %>
|
||||
<button type="button" class="btn btn-success ml-2" id="btnPdfDownload" style="display:none;">PDF 다운로드</button>
|
||||
<% END IF %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<form name="survey" action="Question.asp" method="POST" onsubmit="return false">
|
||||
<div class="container-fluid">
|
||||
<div class="row justify-content-center h-100">
|
||||
<div class="col-sm-12 col-md-12 col-lg-10 col-xl-9 bg-white h-100" id="qmain-box">
|
||||
<div class="col-sm-12 col-md-12 col-lg-10 col-xl-9">
|
||||
<div class="mb-2 border rounded bg-white main_body" >
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<iframe id="layout" class='d-none'></iframe>
|
||||
</body>
|
||||
<script>
|
||||
|
||||
function waitImagesLoaded(rootEl) {
|
||||
const imgs = Array.from(rootEl.querySelectorAll("img"));
|
||||
return Promise.all(
|
||||
imgs.map(img => {
|
||||
if (img.complete) return Promise.resolve();
|
||||
return new Promise(res => {
|
||||
img.onload = res;
|
||||
img.onerror = res;
|
||||
});
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
async function exportSurveyPdf() {
|
||||
$("#surveyprogressbar").css("width", "0%");
|
||||
$("#wrapperSpan").html("설문을 pdf로 변환하고 있습니다...<br/>파일명 : <%=FILENAME%>.pdf");
|
||||
$("#surveyprogressbar").html("변환중");
|
||||
|
||||
const pdf = new jspdf.jsPDF({ unit:"mm", format:"a4", orientation:"p", compress:true });
|
||||
const root = document.getElementById("qmain-box");
|
||||
const pages = Array.from(root.querySelectorAll(".main_body"));
|
||||
const pageW = pdf.internal.pageSize.getWidth();
|
||||
const pageH = pdf.internal.pageSize.getHeight();
|
||||
|
||||
let titleImg = null;
|
||||
let titleH = 0;
|
||||
const titleEl = document.getElementById("project-name");
|
||||
if (titleEl) {
|
||||
const titleCanvas = await html2canvas(titleEl, {
|
||||
scale: 1.2,
|
||||
backgroundColor: "#ffffff",
|
||||
useCORS: true,
|
||||
logging: false,
|
||||
});
|
||||
titleImg = titleCanvas.toDataURL("image/jpeg", 0.9);
|
||||
titleH = (titleCanvas.height * pageW) / titleCanvas.width; // mm 환산
|
||||
}
|
||||
|
||||
for (let i = 0; i < pages.length; i++) {
|
||||
await waitImagesLoaded(pages[i]);
|
||||
|
||||
const canvas = await html2canvas(pages[i], {
|
||||
scale: 1.2,
|
||||
useCORS: true,
|
||||
backgroundColor: "#ffffff",
|
||||
logging: false,
|
||||
removeContainer: true,
|
||||
});
|
||||
|
||||
const imgData = canvas.toDataURL("image/jpeg", 0.82);
|
||||
|
||||
if (i > 0) pdf.addPage();
|
||||
|
||||
let yStart = 0;
|
||||
if (i === 0 && titleImg) {
|
||||
pdf.addImage(titleImg, "JPEG", 0, 0, pageW, titleH, undefined, "FAST");
|
||||
yStart = titleH + 2; // 제목 아래 여백
|
||||
}
|
||||
|
||||
// 페이지 이미지를 남은 공간에 맞춰 넣기
|
||||
const availH = pageH - yStart;
|
||||
let imgW = pageW;
|
||||
let imgH = (canvas.height * imgW) / canvas.width;
|
||||
|
||||
if (imgH > availH) {
|
||||
imgH = availH;
|
||||
imgW = (canvas.width * imgH) / canvas.height;
|
||||
}
|
||||
|
||||
const x = (pageW - imgW) / 2;
|
||||
pdf.addImage(imgData, "JPEG", x, yStart, imgW, imgH, undefined, "FAST");
|
||||
|
||||
$("#surveyprogressbar").css("width", Math.ceil(((i + 1) / pages.length) * 100) + "%");
|
||||
await new Promise(r => setTimeout(r, 0));
|
||||
}
|
||||
|
||||
pdf.save(`<%=FILENAME%>.pdf`);
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<script>
|
||||
const heightLimit = <%=HEIGHT%>;
|
||||
var qcnt = 0
|
||||
var qid_list = [ <% while NOT Rcset.eof %> "<%=Rcset("QID")%>", <% Rcset.moveNext : wend %>]
|
||||
var qid_length = qid_list.length;
|
||||
var link = "/survey_to_pdf/survey_layout.asp?PRJCODE=<%=PRJCODE%>&IDKEY=<%=SID%>&HCV=<%=date_time()%>&QID="
|
||||
var now_url = "<%=request.servervariables("HTTP_url")%>"
|
||||
var bootstrap_css = ""
|
||||
var page_height = 0
|
||||
var userData = {}
|
||||
|
||||
if(qid_length === 0){
|
||||
alert("문항 먼저 등록해주세요.")
|
||||
window.close();
|
||||
}
|
||||
|
||||
$("#wrapperSpan").html("설문을 구현하고 있습니다...");
|
||||
$("#surveyprogressbar").html("구현중");
|
||||
|
||||
if("<%=SID%>" !== ""){
|
||||
const st = "<%=ST%>" == "TEST" ? "TEST" : "REAL";
|
||||
const dataAjaxUrl = "/include/ajax_crud.asp"
|
||||
param = setparam("s", "USER_DATA_ONE", { "PKEY": "<%=PRJCODE%>", "IDKEY": "<%=SID%>", "ST":st});
|
||||
userData = ajax_returnData(dataAjaxUrl, param);
|
||||
|
||||
if(userData.length === 0 ){
|
||||
alert("SID: <%=SID%>의 데이터가 없습니다.")
|
||||
}
|
||||
}
|
||||
|
||||
const frame = document.getElementById("layout");
|
||||
let pendingQid = null; // 현재 iframe에 로드해 둔 QID
|
||||
let pendingGuard = false; // 중복 메시지 방지
|
||||
|
||||
function showBody() {
|
||||
$("html, body").scrollTop(0);
|
||||
$("#wrapper").removeClass("d-flex").addClass("d-none");
|
||||
}
|
||||
|
||||
function doExportSurveyPdf() {
|
||||
$("#wrapper").removeClass("d-none").addClass("d-flex");
|
||||
|
||||
exportSurveyPdf()
|
||||
.catch((e) => {
|
||||
alert("PDF 생성 중 오류가 발생했습니다.")
|
||||
console.log(e)
|
||||
})
|
||||
.finally(() => {
|
||||
showBody();
|
||||
});
|
||||
}
|
||||
|
||||
function loadCurrentQid() {
|
||||
$("#surveyprogressbar").css("width", qcnt === 0 ? "0%" : Math.ceil((qcnt / qid_length) * 100) + "%");
|
||||
|
||||
if (qcnt === qid_length) {
|
||||
$("button[id^=refresh]").remove();
|
||||
$("input:not([id='txtSearch'])").attr("readonly", "readonly");
|
||||
$("input").on("click", () => false);
|
||||
|
||||
if(<%=IsAutoDownload%> == "1"){
|
||||
doExportSurveyPdf();
|
||||
}
|
||||
else{
|
||||
$("#btnPdfDownload").show();
|
||||
showBody();
|
||||
}
|
||||
|
||||
//$("html, body").scrollTop(0);
|
||||
//$("#wrapper").remove();
|
||||
frame.src = "";
|
||||
|
||||
$("#layout").remove();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
pendingQid = qid_list[qcnt];
|
||||
pendingGuard = false;
|
||||
frame.src = link + pendingQid;
|
||||
}
|
||||
|
||||
$("#btnPdfDownload").on("click", function(){
|
||||
doExportSurveyPdf();
|
||||
});
|
||||
|
||||
$("#btnSearch").on("click", function(){
|
||||
var sid = $("#txtSearch").val();
|
||||
|
||||
if (!sid) {
|
||||
alert("SID를 입력해주세요.");
|
||||
$("#txtSearch").focus();
|
||||
return;
|
||||
}
|
||||
|
||||
var url = new URL(window.location.href);
|
||||
url.searchParams.set("SID", sid);
|
||||
|
||||
window.location.href = url.toString();
|
||||
});
|
||||
|
||||
// iframe가 “ready” 신호를 보냈을 때만 DOM을 가져옴
|
||||
window.addEventListener("message", function (ev) {
|
||||
if (ev.origin !== location.origin) return;
|
||||
if (!ev.data || ev.data.type !== "KON_LAYOUT_READY") return;
|
||||
|
||||
// 반드시 현재 iframe에서 온 메시지인지 확인
|
||||
if (ev.source !== frame.contentWindow) return;
|
||||
|
||||
// 반드시 우리가 기다리는 QID인지 확인
|
||||
if (ev.data.qid !== pendingQid) return;
|
||||
|
||||
// 중복 실행 방지(저사양에서 메시지가 2번 들어오는 케이스 방어)
|
||||
if (pendingGuard) return;
|
||||
pendingGuard = true;
|
||||
|
||||
const doc = frame.contentDocument;
|
||||
if (!doc) return;
|
||||
|
||||
const qb = doc.getElementById("question_body");
|
||||
if (!qb) return;
|
||||
|
||||
// ★ ID 중복 방지: 부모로 옮기기 전에 고유 ID로 바꿔두면 안전
|
||||
qb.id = "question_body_" + pendingQid;
|
||||
|
||||
// 일단 현재 페이지에 붙이고 높이 측정
|
||||
$(".main_body:last")[0].appendChild(qb);
|
||||
|
||||
const this_height = $(qb).outerHeight(true) || 0;
|
||||
page_height += this_height;
|
||||
|
||||
if(page_height > heightLimit) {
|
||||
var main_body = createnode("div","",{"class":"mb-2 border rounded bg-white main_body"})
|
||||
var scale = 0.9;
|
||||
|
||||
$(".main_body:last").after(main_body);
|
||||
$(main_body).append(qb); // 이동
|
||||
|
||||
|
||||
if(this_height > heightLimit) {
|
||||
$(main_body).css("height", this_height +"px")
|
||||
}
|
||||
|
||||
page_height = this_height
|
||||
}
|
||||
|
||||
|
||||
qcnt++;
|
||||
loadCurrentQid();
|
||||
});
|
||||
// 시작 로드
|
||||
loadCurrentQid();
|
||||
|
||||
</script>
|
||||
Reference in New Issue
Block a user