<!--#include virtual="/common/lib/dbcon.asp"-->
<!--#include virtual="/common/lib/func.asp"-->
<%
security_ad_cms()
dateY = Trim(Request("dateY"))
dateM = Right("0"&Trim(Request("dateM")), 2)
dateD = Right("0"&Trim(Request("dateD")), 2)
excel = Request.QueryString("excel")

If dateY = "" Then
	dateY = Year(now)
End If
If dateM = "" Then
	dateM = month(now)
End if


If dateD = "" Or dateD = 0 Then
	datetitle = dateY & "-" & dateM
	thisDate = dateY & "-" & dateM & "-01"
	thisDate2 = DateSerial(dateY, dateM + 1, 1 - 1)
Else
	
	thisDate = dateY & "-" & dateM & "-" & dateD
	datetitle = thisDate
	thisDate2 = thisDate
End if
If excel = "ok" then
	Response.ContentType = "application/vnd.ms-excel"
	Response.AddHeader "Content-Disposition","attachment;filename=mms_log_"&dateY & dateM & dateD&".xls"
	border="1"
Else
	border="0"
End if


	'테이블 존재유무 확인 쿼리
	'log_table = "em_log_" & dateY & dateM
	log_table = "sdk_mms_report_detail_" & Right(dateY,2) & dateM
	sql = "select * from information_schema.tables where table_name = '" & log_table & "'"
	Set rs = Dbcon.Execute( sql )
	If rs.bof Or rs.eof Then
		Set rs = Nothing
		list_data = null
	Else


		Set rs = nothing
		
		'sql = "select tran_phone, tran_callback, tran_date, tran_msg, tran_id, tran_etc3, tran_etc4, tran_rslt from "&log_table&" where tran_rsltdate between '"&thisDate&"' and '"&thisDate&"'+ ' 23:59:59'"
		'sql = "select count(tran_pr), tran_callback, '"&thisDate&"' as tran_date, tran_msg, tran_id, tran_etc3, tran_etc4, tran_rslt from "&log_table&" where tran_rsltdate between '"&thisDate&"' and '"&thisDate2&"'+ ' 23:59:59' "&addqry&" group by  tran_callback, left(tran_date, 10), tran_msg, tran_id, tran_etc3, tran_etc4, tran_rslt"

		jointable = log_table & " as a left outer join sdk_mms_report_" & Right(dateY,2) & dateM & " as b on a.job_id = b.job_id"
		s_fields = "count(*) as cnt, b.callback, '"&thisDate&"' as tran_date, convert(varchar(3000), b.mms_msg) as mms_msg, a.user_id, b.reserved3, b.reserved4, a.result"
		Where = " where report_res_date like '" & Replace(thisDate,"-","") & "%' "
		groupby = " group by b.callback, left(a.send_date, 8), a.user_id, b.reserved3, b.reserved4, a.result, convert(varchar(3000), b.mms_msg) "
		sql = "select " & s_fields & " from " & jointable & Where & groupby
		'Response.write sql
		Set rs = Dbcon.Execute( sql )
		
		If rs.bof Or rs.eof Then
			list_data = null
		Else
			list_data = rs.getrows
		End if

		Set rs = Nothing
		'response.write weeksumYes & "/" & weeksumNo
	End if
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE><%=datetitle%> 발송로그</TITLE>
<%If Request.QueryString("excel") <> "ok" then%>
<link rel="Stylesheet" type="text/css" href="/manager/common/css/sub_layout.css" />
<style type="text/css">td {font-family: "돋움"; font-size: 11px;}</style>
<%End if%>
</HEAD>

<BODY topmargin="10" leftmargin="10" scroll="yes">



<%If Request.QueryString("excel") <> "ok" then%>
<table width ="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
	<td colspan="2" height="20"><font color="336BA1">상태가 <b>실패</b>일경우는 수신번호가 잘못되었거나 각 이통사의 일시적인 네트웍장애로 발생합니다.</font>
	</td>
</tr>
<tr>

	<td>
		<a href="mmsreport_detail.asp?dateY=<%=dateY%>&dateM=<%=dateM%>&dateD=<%=dateD%>&excel=ok"><img src="/sms_img/address/bt_excel1.gif" border="0"></a>
	</td>
<form name="frm" method = "post" action="mmsreport_detail.asp">
	<td align="right">
						<!--년도 선택을 위한 선택 박스 만들기 -->
						<SELECT NAME="dateY" style="behavior: url('/include/css/selectBox21.htc');">
							<% 
							for intYear = Year(date()) - 2 to Year(date()) + 10 ' 현재에서 앞 뒤 10년간의 목록을 표시한다.
								if intYear = CInt(dateY) then %>
									<OPTION value="<%=intYear%>" SELECTED><%=intYear%> 년
							<%	else %>
									<OPTION value="<%=intYear%>"><%=intYear%> 년
							<% end if
							next %>
						</SELECT>

						<!--월 선택을 위한 선택박스 만들기 -->
						<SELECT NAME="dateM" style="behavior: url('/include/css/selectBox21.htc');">
						<% 
						for intMonth = 1 to 12
						 if intMonth = CInt(dateM) then %>
							 <OPTION value="<%=intMonth%>" SELECTED><%=intMonth%> 월
						 <% else %>
							 <OPTION value="<%=intMonth%>"><%=intMonth%> 월
						 <% end if
						next %>
						</SELECT>

						<!--일 선택을 위한 선택박스 만들기 -->
						<%
							If dateD >= 1 Then

						%>
						<SELECT NAME="dateD" style="behavior: url('/include/css/selectBox21.htc');display:">
						<% 
						for intDay = 1 to 31
						 if intDay = CInt(dateD) then %>
							 <OPTION value="<%=intDay%>" SELECTED><%=intDay%> 일
						 <% else %>
							 <OPTION value="<%=intDay%>"><%=intDay%> 일
						 <% end if
						next %>
						</SELECT>
						<%
							End if
						%>
						<input type="image" src="/content/board/nninc_simple/img/search_bt.gif" align="absmiddle">&nbsp;
	</td>
</tr>
</form>
</table>

<table width ="100%" border="0" cellpadding="0" cellspacing="0">
	
</table>	
<%End if%>
<table width ="100%" border="<%=border%>" cellpadding="0" cellspacing="1" bgcolor="#D0D0D0">
	<tr bgcolor="#EEEEEE" align="center" height="25">
		<td>
			발송건수
		</td>
		<td>
			발신번호
		</td>
		<td>
			발송일자
		</td>
		<td>
			메세지
		</td>
		<td>
			발신자
		</td>
		<td>
			발신자 부서
		</td>
		<td>
			상태
		</td>
	</tr>
<%
If Not(IsNull(list_data)) then
	For i = 0 To UBound(list_data, 2)
		tran_phone		= list_data(0, i)
		tran_callback	= list_data(1, i)
		tran_date		= list_data(2, i)
		tran_msg		= inputValue3( list_data(3, i) )
		tran_name		= get_name(list_data(4, i))
		tran_etc3		= get_buseo(list_data(5, i))
		tran_etc4		= get_buseo(list_data(6, i))
		If list_data(7, i) = "2" then
			tran_rslt = "성공"
		Else
			tran_rslt = "실패(" & tran_rslt & ")"
		End If
		
		If excel <> "ok" then
			tran_msg		= StringToHTML( remove_tags(tran_msg), 50, false )
		End if
%>
	<tr height="25" bgcolor="#FFFFFF" align="center" onMouseOver="this.style.backgroundColor='#D0D0D0'" onMouseOut="this.style.backgroundColor='#FFFFFF'">
		<td>
			<%=FormatNumber(tran_phone,0)%>건
		</td>
		<td>
			<%=tran_callback%>
		</td>
		<td>
			<%=tran_date%>
		</td>
		<td align="left" style="padding-left:5px">
			<%=inputValue( tran_msg )%>
		</td>
		<td>
			<%=tran_name%>
		</td>
		<td align="left" style="padding-left:2px">
			<%=tran_etc4&">"&tran_etc3%>
		</td>
		<td>
			<%=tran_rslt%>
		</td>
	</tr>
<%
	Next
End if
%>
</table>

</BODY>
</HTML>

