<!--#include file="../Lib/Config.asp"-->
<!--#include file="../Lib/DBConn.asp"-->
<!--#include file="../Lib/DBLib.asp"-->
<!--#include file="../Lib/func.asp"-->
<%
Dim thisFileStr, thisFileArr
thisFileStr = request.servervariables("PATH_INFO")
thisFileArr = Split(thisFileStr,"/")

'세로(1)-----------------
Dim QUOTA1
Dim QUOTA1_TEXT
Dim QUOTA1_VAL
Dim QUOTA1_TITLE

QUOTA1 = "SQ1A"
QUOTA1_TEXT = "20~29세,30~39세,40~49세,50~59세,60~65세"
QUOTA1_VAL = "2,3,4,5,6"
QUOTA1_TITLE = "연령"

'가로(2)-----------------
Dim QUOTA2
Dim QUOTA2_TEXT
Dim QUOTA2_VAL
Dim QUOTA2_TITLE

QUOTA2 = ""
QUOTA2_TEXT = ""
QUOTA2_VAL = ""
QUOTA2_TITLE = ""

'세로(1)&가로(2)&세로(3)---------------
Dim QUOTA3
Dim QUOTA3_TEXT
Dim QUOTA3_VAL
Dim QUOTA3_TITLE

QUOTA3 = ""
QUOTA3_TEXT = ""
QUOTA3_VAL = ""
QUOTA3_TITLE = ""

Dim Sum1,Sum2,Sum3,Sum4
Dim tmpStr

	Function getQuota(Qry)
		Dim SQL,Rs,i,j
		Dim limits

		If Qry="" Then
			SQL = "SELECT Count(idx) FROM " & TB_NAME & " WHERE [ResType]<>'TEST' AND status in (10) "
		Else
			SQL = "SELECT Count(idx) FROM " & TB_NAME & " WHERE [ResType]<>'TEST' AND status in (10) and " & Qry
		End If

		Set Rs = Server.CreateObject("ADODB.Recordset")

		DBConnect()
		Rs.Open SQL,DBConn,3,1,1

		if Not Rs.Eof OR Not Rs.Bof Then
			If Request.ServerVariables("REMOTE_ADDR")="106.255.228.98" Or Request.ServerVariables("REMOTE_ADDR")="14.52.107.60" Then
				getQuota = FormatNumber(Rs(0), 0)
			Else
				limits = getLimit(Qry)
				If Cint(limits) <= Cint(Rs(0)) Then
					getQuota = FormatNumber(limits, 0)
				Else
					getQuota = FormatNumber(Rs(0), 0)
				End If
			End IF
		Else
			getQuota = 0
		End if

		Rs.Close
		Set Rs = Nothing
			
		DBClose()
	End Function

	Function getLimit(Qry)
		Dim SQL,Rs,i,j
			
		If Qry="" Then
			SQL = "SELECT Sum(Limit) FROM " & QUOTA_TBNAME
		Else
			SQL = "SELECT Sum(Limit) FROM " & QUOTA_TBNAME & " WHERE " & Qry
		End If

		Set Rs = Server.CreateObject("ADODB.Recordset")

		DBConnect()
		Rs.Open SQL,DBConn,3,1,1


		if Not Rs.Eof OR Not Rs.Bof Then
			getLimit = FormatNumber(Rs(0), 0)
		Else
			getLimit = 0
		End if

		Rs.Close
		Set Rs = Nothing

		DBClose()
	End Function

%>

<html lang="kr">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title><%=SurveyTitle%> 현황페이지</title>
<link href="../css/bootstrap.min.css" rel="stylesheet">
<link href="../css/boot_style.css" rel="stylesheet" />
<link href="../css/font-awesome.css" rel="stylesheet" />

<script type="text/javascript" src="../js/jquery.1.12.4.min.js"></script>
<script type="text/javascript" src="../js/jquery.alphanumeric.pack.js"></script>
<script type="text/javascript" src="../js/survey.js"></script>
<style>
	@font-face {
		font-family:'NotoSansKR-Regular'; 
		src:url('../fonts/NotoSansKR-Regular.otf');
		font-weight: normal;
		font-style: normal;
	}
	body {
		font-family:'NotoSansKR-Regular'
	}
	tbody {
		background-color:#ffffff;
	}
	th {
		background-color:#C7D3EC;
		vertical-align:middle;
	}
</style>
</head>
<body>
    <nav class="navbar navbar-inverse navbar-fixed-top">
		<div class="container">
			<div class="row" style="width:100%">
				<div class="col-8 col-sm-8 col-md-8">
					<a class="navbar-brand text-light" href="<%=thisFileArr(Ubound(thisFileArr))%>">조사 현황표</a>
				</div>
				<div class="col-4 col-sm-4 col-md-4 text-right">
					
				</div>
			</div>
		</div>
    </nav>

    <div class="jumbotron">
      <div class="container">

      </div>
    </div>

    <div class="container">
		<div class="row">
			<div class="col-md-12">
				<h3><%=SurveyTitle%></h3>
				<p></p>
				<!-- <p><a class="btn btn-default" href="down.asp" target="_blank"><span class="glyphicon glyphicon-download-alt" aria-hidden="true"></span> Data Download</a></p> -->
			</div>
		</div>

    	<div class="row">
    		<div class="col-md-12">
				<form name="frmSearch" id="frmSearch" method="post" action="index.asp">
					<div class="table-responsive">
					<% 
					Dim ForCnt,ForCnt1
					Dim QT1
					Dim QT1_VAL
					Dim QT2
					Dim QT2_VAL
					Dim QT3
					Dim QT3_VAL
					'------------------------------------------------------1개의 쿼터
					%>
					<% If QUOTA3 = "" And QUOTA2 = "" And QUOTA1 <> "" Then %>
						<table class="table table-bordered table-hover table-sm" cellpadding="5" cellspacing="0">
							<tbody>
								<tr>
									<th class="text-center" colspan="2">			
									<%=QUOTA1_TITLE%>
									</th>
								</tr>	
								<% 
								QT1 = Split(QUOTA1_TEXT,",")
								QT1_VAL = Split(QUOTA1_VAL,",")
								Sum1 = 0
								For ForCnt=0 To UBound(QT1)
								%> 
								<tr>
									<td class="text-center">			
										<%=QT1(ForCnt)%>
									</td>
									<%
										tmpStr = getQuota(QUOTA1 & "=" & "'" & QT1_VAL(ForCnt) & "'")
										Sum1 = Sum1 + tmpStr
									%>
									<td class="text-center" <% if Cint(tmpStr) >= Cint(getLimit(QUOTA1 & "=" & "'" & QT1_VAL(ForCnt) & "'")) then%> style='background-color:#ffe5e5' <% end if %>>			
										<%
										Response.Write FormatNumber(tmpStr, 0)
										%>
										/<%=getLimit(QUOTA1 & "=" & "'" & QT1_VAL(ForCnt) & "'")%>
									</td>
								</tr>		
								<%
								Next
								%>
								<tr>
									<td class="text-center">			
										합계
									</td>
									<td class="text-center" <% if Cint(Sum1) >= Cint(getLimit("")) then%> style='background-color:#ffe5e5' <% end if %>>			
										<%=FormatNumber(Sum1, 0)%>/<%=getLimit("")%>
									</td>
								</tr>
							</tbody>		
						</table>
					<% ElseIf QUOTA3 = "" And QUOTA2 <> "" And QUOTA1 <> "" Then %>
					<%
						QT1 = Split(QUOTA1_TEXT,",")
						QT1_VAL = Split(QUOTA1_VAL,",")
						QT2 = Split(QUOTA2_TEXT,",")
						QT2_VAL = Split(QUOTA2_VAL,",")
						ReDim Sum2(UBound(QT2_VAL) + 1)
						ReDim Sum3(UBound(QT1_VAL) + 1)

						For forcnt = Lbound(Sum2) To UBound(Sum2)
							Sum2(forCnt)=0
						Next

						For forcnt = Lbound(Sum3) To UBound(Sum3)
							Sum3(forCnt)=0
						Next
						Sum4=0
						'------------------------------------------------------2개의 쿼터
					%>
						<table class="table table-bordered table-hover table-sm" cellpadding="5" cellspacing="0">
							<tbody>
								<tr>
									<th class="text-center">　</th>
										<% For ForCnt=0 To UBound(QT2) %> 
									<th class="text-center"><%=QT2(ForCnt)%></th>
										<% Next %>
									<th class="text-center">합계</th>
								</tr>	
								<% 
								For ForCnt=0 To UBound(QT1) %> 
								<tr>
									<td class="text-center">			
										<%=QT1(ForCnt)%>
									</td>
									<% For ForCnt1=0 To UBound(QT2)  %>
									<%
										tmpStr = getQuota(QUOTA1 & "=" & "'" & QT1_VAL(ForCnt) & "'" & " AND " & QUOTA2 & "=" & "'" & QT2_VAL(ForCnt1) & "'" )
										Sum2(ForCnt1) = Sum2(ForCnt1) + CLng(tmpStr)
										Sum3(forCnt) = Sum3(forCnt)+CLng(tmpStr)
										Sum4 = Sum4+CLng(tmpStr)
									%>
									<td class="text-center" <% if Cint(tmpStr) >= Cint(getLimit(QUOTA1 & "=" & "'" & QT1_VAL(ForCnt) & "'" & " AND " & QUOTA2 & "=" & "'" & QT2_VAL(ForCnt1) & "'" )) then%> style='background-color:#ffe5e5' <% end if %>>			
										<%
										Response.Write FormatNumber(tmpStr, 0)
										%>/<%=getLimit(QUOTA1 & "=" & "'" & QT1_VAL(ForCnt) & "'" & " AND " & QUOTA2 & "=" & "'" & QT2_VAL(ForCnt1) & "'" )%>
									</td>
									<% Next %>
									<td class="text-center" <% if Cint(Sum3(ForCnt)) >= Cint(getLimit(QUOTA1 & "=" & "'" & QT1_VAL(ForCnt) & "'" )) then%> style='background-color:#ffe5e5' <% end if %>>			
										<%
										'Response.write getQuota(QUOTA1 & "=" & "'" & QT1_VAL(ForCnt) & "'" )
										'Response.Write "<BR>"
										Response.Write FormatNumber(Sum3(ForCnt), 0)
										%>/<%=getLimit(QUOTA1 & "=" & "'" & QT1_VAL(ForCnt) & "'" )%>
									</td>
								</tr>		
								<%
								Next
								%>
								<tr>
									<td class="text-center">			
										합계
									</td>
									<% For ForCnt1=0 To UBound(QT2) %>
									<td class="text-center" <% if Cint(Sum2(Forcnt1)) >= Cint(getLimit(QUOTA2 & "=" & "'" & QT2_VAL(ForCnt1) & "'" )) then%> style='background-color:#ffe5e5' <% end if %>>			
										<%
										'getQuota(QUOTA2 & "=" & "'" & QT2_VAL(ForCnt1) & "'" )
										Response.Write FormatNumber(Sum2(Forcnt1), 0)
										%>/<%=getLimit(QUOTA2 & "=" & "'" & QT2_VAL(ForCnt1) & "'" )%>
									</td>
									<% Next %>
									<td class="text-center" <% if Cint(Sum4) >= Cint(getLimit("")) then%> style='background-color:#ffe5e5' <% end if %>>			
										<%
										Response.Write FormatNumber(Sum4, 0)
										'getQuota("")%>/<%=getLimit("")
										%>
									</td>
								</tr>	
							</tbody>	
						</table>
					<% ElseIf QUOTA3 <> "" And QUOTA2 <> "" And QUOTA1 <> "" Then %>
						<%
						Dim RtCnt
						QT1 = Split(QUOTA1_TEXT,",")
						QT1_VAL = Split(QUOTA1_VAL,",")
						QT2 = Split(QUOTA2_TEXT,",")
						QT2_VAL = Split(QUOTA2_VAL,",")

						QT3 = Split(QUOTA3_TEXT,",")
						QT3_VAL = Split(QUOTA3_VAL,",")
						'------------------------------------------------------3개의 쿼터
					%>
						<table class="table table-bordered table-hover table-sm" cellpadding="5" cellspacing="0">
							<tbody>
								<tr>
									<th class="text-center" style='vertical-align:middle' rowspan=2>　</th>
									<% For ForCnt=0 To UBound(QT2) %> 
									<th class="text-center" style='vertical-align:middle' colspan=<%=Ubound(QT3)+1%>><%=QT2(ForCnt)%></th>
									<% Next %>
									<th class="text-center" style='vertical-align:middle' rowspan=2>합계</th>
								</tr>	
								<tr>
								<% For RtCnt=0 To Ubound(QT2) %>
									<% For ForCnt=0 To Ubound(QT3) %>
										<th style="text-align:center;"><%=QT3(ForCnt)%></th>
									<% Next %>
								<% Next %>
								</tr>
								<% 
								For ForCnt=0 To UBound(QT1) %> 
								<tr>
									<td class="text-center">			
									<%=QT1(ForCnt)%>
									</td>
									<% For ForCnt1=0 To UBound(QT2)  %>
										<% For RtCnt=0 To Ubound(QT3) %>
									<td class="text-center" <% if Cint(getQuota(QUOTA1 & "=" & "'" & QT1_VAL(ForCnt) & "'" & " AND " & QUOTA2 & "=" & "'" & QT2_VAL(ForCnt1) & "'" & " AND " & QUOTA3 & "=" & "'" & QT3_VAL(RtCnt) & "'" )) >= Cint(getLimit(QUOTA1 & "=" & "'" & QT1_VAL(ForCnt) & "'" & " AND " & QUOTA2 & "=" & "'" & QT2_VAL(ForCnt1) & "'" & " AND " & QUOTA3 & "=" & "'" & QT3_VAL(RtCnt) & "'" )) then%> style='background-color:#ffe5e5' <% end if %>>			
										<%=getQuota(QUOTA1 & "=" & "'" & QT1_VAL(ForCnt) & "'" & " AND " & QUOTA2 & "=" & "'" & QT2_VAL(ForCnt1) & "'" & " AND " & QUOTA3 & "=" & "'" & QT3_VAL(RtCnt) & "'" )%>/<%=getLimit(QUOTA1 & "=" & "'" & QT1_VAL(ForCnt) & "'" & " AND " & QUOTA2 & "=" & "'" & QT2_VAL(ForCnt1) & "'" & " AND " & QUOTA3 & "=" & "'" & QT3_VAL(RtCnt) & "'" )%>
									</td>
										<% Next %>
									<% Next %>
									<td class="text-center" <% if Cint(getQuota(QUOTA1 & "=" & "'" & QT1_VAL(ForCnt) & "'" )) >= Cint(getLimit(QUOTA1 & "=" & "'" & QT1_VAL(ForCnt) & "'" )) then%> style='background-color:#ffe5e5' <% end if %>>			
										<%=getQuota(QUOTA1 & "=" & "'" & QT1_VAL(ForCnt) & "'" )%>/<%=getLimit(QUOTA1 & "=" & "'" & QT1_VAL(ForCnt) & "'" )%>
									</td>
								</tr>		
								<%
								Next
								%>
								<tr>
									<td class="text-center">			
										합계
									</td>
									<% For ForCnt1=0 To UBound(QT2) %>
										<% For RtCnt=0 To Ubound(QT3) %>
									<td class="text-center" <% if Cint(getQuota(QUOTA2 & "=" & "'" & QT2_VAL(ForCnt1) & "'" & " AND " & QUOTA3 & "=" & "'" & QT3_VAL(RtCnt) & "'")) >= Cint(getLimit(QUOTA2 & "=" & "'" & QT2_VAL(ForCnt1) & "'" & " AND " & QUOTA3 & "=" & "'" & QT3_VAL(RtCnt) & "'")) then%> style='background-color:#ffe5e5' <% end if %>>			
										<%=getQuota(QUOTA2 & "=" & "'" & QT2_VAL(ForCnt1) & "'" & " AND " & QUOTA3 & "=" & "'" & QT3_VAL(RtCnt) & "'")%>/<%=getLimit(QUOTA2 & "=" & "'" & QT2_VAL(ForCnt1) & "'" & " AND " & QUOTA3 & "=" & "'" & QT3_VAL(RtCnt) & "'")%>
									</td>
										<% Next %>
									<% Next %>
									<td class="text-center" <% if Cint(getQuota("")) >= Cint(getLimit("")) then%> style='background-color:#ffe5e5' <% end if %>>			
										<%=getQuota("")%>/<%=getLimit("")%>
									</td>
								</tr>
							</tbody>
						</table>
					<% End If %>
					</div>
				</form>
    		</div>
    	</div>

    	<hr>

    	<footer>
    		<p></p>
    	</footer>
	</div>
</body>
</html>