<!--#include virtual="/manager/common/file/stats_top.asp"-->

<%
v_mid = InputValue(request("p_mid"))
v_yy = InputValue(request("p_yy"))
v_mm = InputValue(request("p_mm"))
v_type = InputValue(request("p_type"))

If v_yy="" then	v_yy = year(now)
If v_mm="" then	v_mm = month(now)
v_mm = Right("00"&v_mm,2)
If v_type="" then	v_type = "day"



Dim arrValue()
Dim arrValue_mms()
dataLength = 0
totalCount = 0
totalCount_mms = 0

If v_mid<>"" then

	If v_type="day" Then

		temp_d = DateAdd("m",1, v_yy&"-"&v_mm&"-01")
		dataLength = Right(DateAdd("d", -1, temp_d ),2)

		ReDim arrValue(dataLength)
		ReDim arrValue_mms(dataLength)


		tablename = "em_log_"&v_yy&v_mm

		sql = " SELECT day(tran_date), count(*) FROM "&tablename&" WHERE tran_id='"&v_mid&"' GROUP BY day(tran_date) "		
		Set rs = dbcon.execute(sql)
		Do While Not rs.eof 
			arrValue(rs(0)) = rs(1)
			totalCount = totalCount + CInt(rs(1))
			rs.movenext
		Loop
		rs.close : Set rs = Nothing
		

		'-----------mms 카운트---------------
		tablename = "sdk_mms_report_detail_" & Right(v_yy,2) & v_mm
		'//table 존재유무
		sql = "select count(*) as cnt from information_schema.tables where table_name = '" & tablename & "'"
		'Response.write sql
		Set rs = dbcon.execute( sql )
		rscount = rs("cnt")
		rs.close : Set rs = Nothing
		If rscount > 0 Then
			
			sql = " SELECT right(left(send_date,8), 2), count(*) FROM "&tablename&" WHERE user_id='"&v_mid&"' GROUP BY right(left(send_date,8), 2) "
			Set rs = dbcon.execute(sql)
			Do While Not rs.eof 
				arrValue_mms(rs(0)) = rs(1)
				totalCount_mms = totalCount_mms + CInt(rs(1))
				rs.movenext

			Loop
			rs.close : Set rs = Nothing


		End if
		'-----------mms 카운트끝---------------
	Else

		dataLength = 12
		ReDim arrValue(dataLength)
		ReDim arrValue_mms(dataLength)


		For i=1 To 12

			tablename = "em_log_" & v_yy & Right("00"&i,2)

			'//table 존재유무
			sql = "select count(*) as cnt from information_schema.tables where table_name = '" & tablename & "'"
			Set rs = dbcon.execute( sql )
			rscount = rs("cnt")
			rs.close : Set rs = Nothing
			
			If rscount > 0 Then

				sql = " SELECT count(*) FROM "&tablename&" WHERE tran_id='"&v_mid&"'"
				Set rs = dbcon.execute( sql )

				arrValue(i) = rs(0)
				totalCount = totalCount + CInt(rs(0))

			End If

			'-----------mms 카운트---------------
			tablename = "sdk_mms_report_detail_" & Right(v_yy,2) & Right("00"&i,2)
			'//table 존재유무
			sql = "select count(*) as cnt from information_schema.tables where table_name = '" & tablename & "'"
			'Response.write sql
			Set rs = dbcon.execute( sql )
			rscount = rs("cnt")
			rs.close : Set rs = Nothing

			If rscount > 0 Then
				sql = " SELECT count(*) FROM "&tablename&" WHERE user_id='"&v_mid&"'"
				Set rs = dbcon.execute( sql )

				arrValue_mms(i) = rs(0)
				If arrValue_mms(i) = 0 Then arrValue_mms(i) = ""
				totalCount_mms = totalCount_mms + CInt(rs(0))
			End if


			'-----------mms 카운트끝---------------
			
		next

	End If



End if

%>

		
		<!-- 내용영역 -->
		<div id="contents">

			<div id="contents_head"> 
				<div id="contents_title">
					<img src="/manager/img/tit_ic08.gif" width="22" height="21" class="<%=skin%> center" alt="" /> <h1><span>회원별 메세지 통계</span></h1>
				</div>
				<div id="location">
					<a href="/manager/" >Home</a> &gt; <a href="/manager/content/05stats/h.asp" >통계자료</a> &gt; <a href="/manager/content/05stats/sms_d.asp" >메세지 통계</a> &gt; <a href="/manager/content/05stats/member.asp" class="now" >회원별 메세지 통계</a>
				</div>
			</div>

			<!-- 내용들어가는곳 -->
			<div id="contents_area">

				<h2 class="space"></h2>

				<div class="write_info">

					<div class="write_form pt7">
						<form id="frm" name="frm" action="member.asp" method="get">

						<ul>
							<li class="search"><label for="p_mid">검색 회원 ID</label></li>
							<li>
								<input type="text" name="p_mid" id="p_mid" value="<%=v_mid%>" style="width:80px;" class="input_box input" onfocus="focus_on1_<%=skin%>(this);" onblur="focus_off1(this);"/>
							</li>
							<li style="padding-left:15px;">
								<select id="p_yy" name="p_yy" class="stats" >
									<% For z=2009 To Year(now)%>
									<option value="<%=z%>"<%=chkSelect(z, CInt(v_yy))%>><%=z%>년</option>
									<%next%>
								</select>
							</li>
							<li style="padding-left:5px;">
								<select id="p_mm" name="p_mm" class="stats"<%If v_type="month" then%> disabled=disabled<%End if%> >								
									<% For z=1 To 12%>
									<option value="<%=z%>"<%=chkSelect(z, CInt(v_mm))%>><%=z%>월</option>
									<%next%>
								</select>
							</li>
							<li style="padding-left:10px;">
								<input type="radio" name="p_type" id="p_type_month" value="month" <%=chkRadio(v_type, "month")%> /><label for="p_type_month">월별</label>&nbsp;&nbsp;
								<input type="radio" name="p_type" id="p_type_day" value="day" <%=chkRadio(v_type, "day")%>  /><label for="p_type_day">일별</label>
							</li>
							<li style="padding-left:10px;"><div id="<%=skin%>_bt"><span class="button"><input type="submit" value="보기" /></span></div></li>
						</ul>

						</form>
					</div>

				</div>



					<div class="list_count pb2">
						&nbsp;
					</div>

					<fieldset>
						<legend>월별 방문자 통계</legend>
						<table cellspacing="0" class="bbs_<%=skin%>" summary="월별 방문자를 확인합니다.">
						<caption>월별 방문자 통계 서식</caption>
						<colgroup>
						<col width="60" />
						<col width="45%" />
						<col width="45%" />
						</colgroup>

						<thead>
						<tr>
							<th scope="col"><%If v_type="day" Then%>일자<%else%>월<%End if%></th>
							<th scope="col">SMS발송</th>
							<th scope="col">MMS발송</th>
						</tr>
						</thead>

						<tbody>
					<%
					If dataLength>0 Then
					
						For z=1 To ubound(arrValue)

							If v_type="day" Then
								v_dd = z
							Else
								v_mm = z
							End if

					%>

						<tr>
							<td scope="row" class="center"><%=z%>&nbsp;<%If v_type="day" Then%>일<%else%>월<%End if%></td>
							<td scope="row" style="text-align:right;padding-right:100px;">
								<%=FormatNumber(arrValue(z), 0)%>
								<a href="smsReport_detail2.asp?p_mid=<%=v_mid%>&dateY=<%=v_yy%>&dateM=<%=v_mm%>&dateD=<%=v_dd%>" onclick="window.open(this.href,'','width=1000,height=600,resizable=yes');return false;">[상세보기]</a>
							</td>
							<td scope="row"  style="text-align:right;padding-right:100px;">
								<%
								If arrValue_mms(z) <> "" Then
									Response.write FormatNumber(arrValue_mms(z), 0)
								%>
								<a href="mmsReport_detail2.asp?p_mid=<%=v_mid%>&dateY=<%=v_yy%>&dateM=<%=v_mm%>&dateD=<%=v_dd%>" onclick="window.open(this.href,'','width=1000,height=600,resizable=yes');return false;">[상세보기]</a>
								<%
								End if
								%>
							</td>

						</tr>
					<%
						Next
						
						mms_usecount = totalCount_mms*3
					%>
						<tr>
							<td scope="row" class="center">합계</td>
							<td scope="row" style="text-align:right;padding-right:100px;font-weight:bold;"><%=FormatNumber(totalCount,0)%></td>
							<td scope="row" style="text-align:right;padding-right:100px;font-weight:bold;"><%=FormatNumber(totalCount_mms,0)%> (차감건수 : <%=FormatNumber(mms_usecount,0)%>)</td>
						</tr>
					<%
					Else
					%>
						<tr><td colspan="4" class="center">검새 회원 ID를 입력하세요</td></tr>
					<%					
					End if
					%>

						</tbody>
						</table>
					</fieldset>

			

			</div>
			<!-- 내용들어가는곳 -->

		</div>
		<!-- ' 내용영역 -->

<!--#include virtual="/manager/common/file/sub_bottom.asp"-->

<script type="text/javascript">
$(function(){
	$("input[name='p_type']").click(function(){
		if($(this).val()=="month"){
			$("#p_mm").attr("disabled",true);
		}else{
			$("#p_mm").attr("disabled",false);
		}
	});

});
</script>