<!--#include file="Lib/Config.asp"-->
<!--#include file="Lib/DBConn.asp"-->
<!--#include file="Lib/DBLib.asp"-->
<!--#include file="Lib/Func.asp"-->
<!--#include file="Lib/PanelLib.asp"-->
<!--#include file="Lib/FileLib.asp"-->
<!--#include file="Lib/Quota_Setup.asp"-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><%=Surveytitle%></title>
<link rel="stylesheet" type="text/css" href="css/style.css" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script src="include/jquery.alphanumeric.pack.js"></script>
<script src="include/survey.js"></script>
</head>
<script language="javascript">
	$(document).ready(function(){

		$("#frmSurvey").submit();

	});
</script>
<body onload="switchScreen();">
<script type="text/javascript">
//<![CDATA[
function switchScreen() {
    document.getElementById("divLoading").style.display = "none";
}
//]]>
</script>

<div id="divLoading" style="position:absolute; top:35%; left:0; width:100%; text-align:center; margin:0 auto;">
    <img src="./images/ajax-loader.gif" alt="Loading"/><br>Loading..
</div>
<%
Dim IDKey,PAGENAME,NEXTPAGE,VC_ID,VARS,RESTYPE
Dim PAGE,NPAGE,VAR,FKey
PAGE=""
NPAGE=""
VARS=""
RESTYPE=""

'고칠 부분이 없습니다.
If Request("ST")<>"" Then

	FKey = Right(Request("userid_t"),Len(Request("userid_t"))-1)
	IDKey = SearchIDKey(FKey)
	XMLFolder = "/" & "20" & Mid(ProjectCode,2,2) & "/" & Mid(ProjectCode,4,2) & "/" & ProjectCode & "/Data/"& IDKey & ".XML"

	If Request("ST")="10" Then
		PAGENAME = ""
		NEXTPAGE = "SURVEY_END"
	ElseIf Request("ST")="99" Then
		PAGENAME = ""
		NEXTPAGE = "QUOTA"
	ElseIf Request("ST")="98" Then
		PAGENAME = ""
		NEXTPAGE = "SCREEN"
	End If

	RESTYPE = getIDValue("RESTYPE",IDKey)

Else
	IDKey = Trim(Request.Form("IDKey"))
	PAGENAME = Trim(Request.Form("PageName"))
	NEXTPAGE = Trim(Request.Form("NextPage"))
	RESTYPE = Trim(Request.Form("RESTYPE"))
	VC_ID = Trim(Request.Form("VC_ID"))
End If

PVALUE = CInt(Request.Form("PVALUE"))+1

If VarType(IDKey)=0 Or VarType(IDKey)=1 Or Trim(IDKey)="" Then
	Response.Redirect "URLError.asp"
	Response.End
End If

If VarType(NEXTPAGE)=0 Or VarType(NEXTPAGE)=1 Or Trim(NEXTPAGE)="" Then
	Response.Redirect "URLError.asp"
	Response.End
End If

'SAVEXML CDAT("PVALUE=" & PVALUE)
'If FileChecker("/" & ProjectCode & "/Data/"& IDKey & ".XML")=False Then
'End IF

'###########################################################################################
'설문 완료 여부 검사
'###########################################################################################

Dim RsMember								'레코드셋 변수1
Dim C_SQL,I_SQL								'설문 관련 쿼리문
Dim END_FLAG,Survey_FLAG,SAVE_FLAG			'설문 관련 플래그변수
	
	SAVE_FLAG = True

	I_SQL = ""

	Set RsMember = Server.CreateObject("ADODB.Recordset")	
	C_SQL = "SELECT Status FROM " & TB_NAME & " WHERE [KEY]='" & IDKey & "' "

	DBConnect()
	RsMember.Open C_SQL,DBConn,3,1,1
	
	If RsMember.Eof or RsMember.Bof Then
		END_FLAG = false
		Survey_FLAG = true
	Else
		If Cint(RsMember("Status"))=10 Then
			END_FLAG = true
			Survey_FLAG = false
		ElseIF Cint(RsMember("Status"))>90 Then
			END_FLAG = true
			Survey_FLAG = false
		End if
	End if
	
	RsMember.Close
	set RsMember = Nothing
	DBClose()

	If END_FLAG=true Then
		Call_Url "Survey_Prev_Response.asp",""
		Response.End
	End if
	
'###########################################################################################
'설문 완료 여부 검사 끝
'###########################################################################################

'###########################################################################################
'데이터 입력
'###########################################################################################

PageInfo = Trim(Request.Form("VAR"))

If ProgressBar="1" Then
	PCount= Request("PCount") + 1
End if

If PageInfo<>"" AND VarType(PageInfo)<>0 AND VarType(PageInfo)<>1 Then
	Dim FLogStr,FNamess,ic
	'단일 응답인지 복수 응답인지 확인
	
	If InStr(PageInfo,",")>0 Then
		VarList = Split(PageInfo,",")	
'		SurveyType = false
	Else
		VarList = Split(PageInfo & ",",",")
'		SurveyType = true		
	End if

	FLogStr = ""

	For iC=0 To UBound(VarList)
		If VarType(varList(ic))<>0 And VarType(varList(ic))<>1 And VarList(ic)<>"" Then
				FLogStr = FLogStr & varList(ic) & DB1STR & request.Form(varList(ic)) & DB2STR
		End IF
	Next

	if FLogStr<>"" Then
		FLogStr = Left(FLogStr,Len(FLogStr)-1)
	End if
	 
	SAVE_FLAG = SAVEData(FLogStr)
	Survey_Flag = False

'SurveyType = false
End If

If SAVE_FLAG = False Then

	If SURVEYSTATUS<>"3" Then
		On Error Resume Next
	End IF

	Err.Raise 1,"사용자 지정오류","Data저장 실패"
	ErrorMail Err
	Server.Transfer "Survey_Error.asp"
End IF

'###########################################################################################
'로직 처리
'###########################################################################################

Select Case PAGENAME

End Select

If Request.Form("STFLAG")<>"S" Then
	SavePage(NEXTPAGE)
Else
	SAVEXML CDAT("KEY=" & IDKEY)
End IF

'###########################################################################################
'로직 처리 완료
'###########################################################################################

'###########################################################################################
'* 설문조사 종료 처리
'###########################################################################################
	Select Case NEXTPAGE
		Case "SURVEY_END"
			'SaveXML CDAT("Status=10")
			EndProcess ""
			If RESTYPE<>"TEST" Then
				If SURVEYTYPE = "2" Or SURVEYTYPE = "6" Then
					getListStatus(10)
				End If
			End if
			NEXTPAGE = SURVEY_FINISH
		Case "SCREEN"
			'	SaveXML CDAT("Status=98")				
			If RESTYPE<>"TEST" Then
				EndProcess "98"
				NEXTPAGE = SCREEN_PAGE
				If SURVEYTYPE = "2" Then
					getListStatus(98)
				End if
			Else
				NEXTPAGE = CSCREEN_PAGE
			End IF			
		Case "QUOTA"
			'SaveXML CDAT("Status=99")
			EndProcess "99"
			NEXTPAGE = QUOTA_PAGE
			If RESTYPE<>"TEST" Then
				If SURVEYTYPE = "2" Or SURVEYTYPE = "6" Then
					getListStatus(99)
				End If
			End if
		Case "MEDIA"
			NEXTPAGE = "Media_Out"
		Case "SURVEY_SENDER"
			NEXTPAGE = "Survey_OutBound_Sender"
	End Select

	
%>
<form name="Survey" id="frmSurvey" method="post" action="<%=NEXTPAGE%>.asp">
<!--#include file="Lib/IIVariable.asp"-->
</form>
</body>
</html>
