<!--#include virtual="/common/lib/dbcon.asp"-->
<!--#include virtual="/common/lib/func.asp"-->
<%


Set ST = New SelectTable

'단문 테이블명
stat_date = Year(now) & Right( "0" & Month(now), 2 )
stat_date = "201708"
table_1 = "em_log_" & stat_date

sql = "select count(*) as cnt from information_schema.tables where table_name = '" & table_1 & "'"
table_cnt = ST.selectQueryColumn( sql )
If table_cnt = 0 Then
	table_1 = ""
End if

'장문 테이블명
stat_date2 = Right(Year(now),2) & Right( "0" & Month(now), 2 )
stat_date2 = "1708"
table_2 = "sdk_mms_report_detail_" & stat_date2
sql = "select count(*) as cnt from information_schema.tables where table_name = '" & table_2 & "'"
table_cnt = ST.selectQueryColumn( sql )
If table_cnt = 0 Then
	table_2 = ""
End if

tmp_select_1 = ""
If table_1 <> "" then
	tmp_select_1 = tmp_select_1 & "	select * from ("
	tmp_select_1 = tmp_select_1 & "		select tran_msg, tran_phone, convert(varchar, tran_date,112)+replace(convert(varchar, tran_date,108), ':', '') as tran_date, '"&table_1&"' as logname, tran_pr as idx"
	tmp_select_1 = tmp_select_1 & "		from " & table_1
	tmp_select_1 = tmp_select_1 & "		where tran_id = '" & session("ss_m_id") & "'"
	tmp_select_1 = tmp_select_1 & "	) tbl_1"
End if

tmp_select_2 = ""
If table_2 <> "" then
	tmp_select_2 = tmp_select_2 & "	select * from ("
	tmp_select_2 = tmp_select_2 & "		select b.mms_msg, a.phone_number, a.send_date, '"&table_2&"' as logname, a.job_id"
	tmp_select_2 = tmp_select_2 & "		from " & table_2 & " as a left outer join sdk_mms_report_" & stat_date2 & " as b on a.job_id = b.job_id"
	tmp_select_2 = tmp_select_2 & "		where a.user_id = '" & session("ss_m_id") & "'"
	tmp_select_2 = tmp_select_2 & "	) tbl_2"
End if

table = ""
If tmp_select_1 <> "" or tmp_select_2 <> "" Then

	table = table & "("
	table = table & tmp_select_1
	If tmp_select_2 <> "" Then 
		If tmp_select_1 <> "" Then 
			table = table & "	union all"
		End If
		table = table & tmp_select_2
	End if
	table = table & ") tbl3"		'테이블
Else
	Response.write "이달에 발송기록이 없습니다."
	Response.end
End if


sql = "select top 21 tran_msg, tran_phone, tran_date from " & table & " order by tran_date"
'Response.write sql
rs = ST.selectQueryTable( sql )
If isnull(rs) Then
	Response.write "이달에 발송기록이 없습니다."
	Response.end
Else
	For i = 0 To ubound( rs )
		ST.arr2Value( rs(i) )
		tran_msg_str = Replace(tran_msg, vbcrlf, "<br />")
%>
				<li>
					<textarea style="display:none;" id="new_message_<%=i%>"><%=tran_msg%></textarea>
					<div class="ct"><%=tran_msg_str%></div>
					<div class="btngroup">
						<ul class="btn_sm">
							<li><a href="#set_message" onclick="setNewMessage($('#new_message_<%=i%>').val());closeArea();" class="sm1">사용</a></li>
							<!-- <li><a href="#" class="sm2">삭제</a></li> -->
						</ul>
					</div>
				</li>
<%
	next
End if
%>