first commit
This commit is contained in:
294
survey_to_pdf/survey_layout_total.asp
Normal file
294
survey_to_pdf/survey_layout_total.asp
Normal file
@@ -0,0 +1,294 @@
|
||||
<!--#include Virtual="/Lib/Config.asp" -->
|
||||
<%
|
||||
Dim PRJCODE : PRJCODE = request("PRJCODE")
|
||||
Dim SID : SID = request("SID")
|
||||
Dim FILENAME : FILENAME = PRJCODE
|
||||
|
||||
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> KiwiSurvey</title>
|
||||
<link rel="shortcut icon" type="image/x-icon" href="../../img/favicon-16x16.png" />
|
||||
|
||||
<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>
|
||||
|
||||
<link href="/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
|
||||
<link href='//spoqa.github.io/spoqa-han-sans/css/SpoqaHanSansNeo.css' rel='stylesheet' type='text/css'>
|
||||
<link rel="stylesheet" href="style.css">
|
||||
<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>
|
||||
<div>
|
||||
<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>
|
||||
</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() {
|
||||
$("#wrapperSpan").html("설문을 pdf로 변환하고 있습니다...<br/>파일명 : <%=FILENAME%>.pdf");
|
||||
$("#surveyprogressbar").css("width", "0%");
|
||||
$("#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%>&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 dataAjaxUrl = "/include/ajax_crud.asp"
|
||||
param = setparam("s", "USER_DATA_ONE", { "PKEY": "<%=PRJCODE%>", "IDKEY": "<%=SID%>" });
|
||||
userData = ajax_returnData(dataAjaxUrl, param)
|
||||
}
|
||||
|
||||
$("#layout").on("load", function (e) {
|
||||
$("#surveyprogressbar").css("width",qcnt == 0 ? "0%" : Math.ceil((qcnt / qid_length) * 100) + "%" )
|
||||
if (qcnt === qid_length) {
|
||||
$("button[id^=refresh]").remove();
|
||||
$("input").attr("readonly","readonly");
|
||||
$("input").on("click", () => {return false})
|
||||
|
||||
exportSurveyPdf()
|
||||
.catch((e) => {
|
||||
alert("PDF 생성 중 오류가 발생했습니다.")
|
||||
console.log(e)
|
||||
})
|
||||
.finally(() => {
|
||||
$("html, body").scrollTop(0);
|
||||
$("#wrapper").remove();
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
var frameTarget = e.target;
|
||||
setTimeout(function () {
|
||||
var $content = $(frameTarget.contentDocument);
|
||||
var $target = $content.find("#question_body");
|
||||
|
||||
$(".main_body:last").append($target);
|
||||
var this_height = $("#qmain-box").find(".child-question:eq("+qcnt+")").outerHeight(true);
|
||||
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).append($target);
|
||||
$(".main_body:last").after(main_body);
|
||||
|
||||
if(this_height > heightLimit) {
|
||||
$(main_body).css("height", this_height +"px")
|
||||
}
|
||||
|
||||
page_height = this_height
|
||||
}
|
||||
|
||||
qcnt++
|
||||
if(qid_list[qcnt]){
|
||||
$("#layout").attr("src", link + qid_list[qcnt])
|
||||
} else {
|
||||
$("#layout").attr("src", "")
|
||||
}
|
||||
}, 10)
|
||||
})
|
||||
|
||||
|
||||
if (window.location.href.indexOf(now_url) > -1) {
|
||||
$.when($.get("/bootstrap-4.4.1/css/bootstrap.min.css"))
|
||||
.done(function(response) {
|
||||
bootstrap_css = response
|
||||
// 시작 !
|
||||
$("#layout").attr("src", link + qid_list[qcnt])
|
||||
});
|
||||
|
||||
} else {
|
||||
$("#layout").remove();
|
||||
}
|
||||
|
||||
</script>
|
||||
Reference in New Issue
Block a user