<!--#include virtual="/common/file/head_dsmc.asp"-->
<%
dim v_search, v_keyword, table, Query_Fields, Query_Where, Query_OrderBy
Dim recordcount
dim pagesize, v_totalpage, v_page, TotalCnt, v_block

Dim stat_date
stat_date = inputvalue( Request("stat_date") )
result_type = inputvalue( Request("result_type") )

'dsmc대구동산병원 채용만 보게하기
COMMON_WHERE = " AND tran_etc1='dsmc_daegu_recruit' "

'============================================처리중인 문자조회========================================
ing_fields = "tran_pr, tran_phone, tran_rslt, tran_date, tran_msg"
sql = "select " & ing_fields & " from em_tran where tran_id = '"&session("ss_dsmc_m_id")&"' and tran_date <= getdate() " & COMMON_WHERE &" ORDER BY tran_pr"
Set rs = Dbcon.Execute( sql )
If rs.bof Or rs.eof Then
	ing_data = Null
Else
	ing_data = rs.getrows
End If
Set rs = nothing
'============================================처리중인 문자조회========================================


'============================================로그테이블명 만들기========================================
If stat_date = "" Then stat_date = Year(now) & Right( "0" & Month(now), 2 )
'============================================로그테이블명 만들기========================================
v_search = inputValue( Request.querystring("p_search") )
v_keyword = inputValue( Request.querystring("p_keyword") )

table = "em_log_" & stat_date
'response.write table

sql = "select count(*) as cnt from information_schema.tables where table_name = '" & table & "'"
Set rs = dbcon.execute( sql )
table_cnt = rs(0)
Set rs = nothing


If table_cnt = 0 Then
	log_data = Null
	v_totalpage = 1
	v_page = 1
	pagesize = 12
	v_block = 10
else
	'v_search		= Request.QueryString("p_search")	'검색조건
	'v_keyword		= Request.QueryString("p_keyword")	'검색어
	prepage			= Request.ServerVariables("path_info") & "?" & Request.ServerVariables("query_string")	'현재페이지경로

	idx_field		= "tran_pr"			'기본키
	oreder_filed	= "tran_date desc, tran_pr desc"	'정렬기준 필드
	Query_Fields	= "tran_pr, tran_phone, tran_rslt, tran_date, tran_msg, tran_reportdate" '불러올 필드
	pagesize		= 12				'목록개수
	v_block			= 10				'페이지개수
	
	'==================조합 쿼리문=======================
	If v_keyword <> "" then
		Query_Where = " where tran_id = '" & session("ss_dsmc_m_id") & "' and " & v_search & " like '%" & v_keyword & "%' and ( tran_etc1 <> 'N' or tran_etc1 is null ) " & COMMON_WHERE
		andOrWhere	= " and "
	Else
		Query_Where = " where tran_id = '" & session("ss_dsmc_m_id") & "' and ( tran_etc1 <> 'N' or tran_etc1 is null ) " & COMMON_WHERE
		andOrWhere	= " and "
	End If
	If result_type = "success" Then
		Query_Where = Query_Where & andOrWhere & " tran_rslt = '0'"
	End If
	If result_type = "fail" Then
		Query_Where = Query_Where & andOrWhere & " tran_rslt <> '0'"
	End if
	Query_OrderBy = " ORDER BY "&oreder_filed
	'==================조합 쿼리문=======================
	
	'==================전체 레코드 수 뽑기===============
	sql="select count("&idx_field&") from " & table & Query_Where
	set rs = DbCon.execute(sql)
	recordcount=CInt( rs(0) ) '이 전체레코드갯수를 이용해서 페이지갯수를 뽑아 낼것이다.	
	Set rs = nothing
	'==================전체 레코드 수 뽑기===============
	
	v_totalpage=fix((recordcount-1)/pagesize)+1 '전체덩어리갯수 
	v_page = Request.QueryString("p_page")

	if v_page="" then
		v_page = 1
	elseif cint(v_page) < 1 then
		v_page = 1
	elseif cint(v_page)>cint(v_totalpage) then
		v_page=cint(v_totalpage)
	end if
	
	'========================리스트 출력 쿼리문 생성======================
	'MS-SQL
	sql = "select Top " & pagesize& " " & Query_Fields & " from " & table
	sql = sql & Query_Where & andOrWhere & " "&idx_field&" not in"
	sql = sql & "(select top " & pagesize * (v_page - 1) & " "&idx_field&" from " & table
	sql = sql & Query_Where & Query_OrderBy & ")"
	sql = sql & Query_OrderBy
	'========================리스트 출력 쿼리문 생성 끝======================
	'response.write sql

	Set rs = Dbcon.Execute( sql )
	If rs.bof Or rs.eof Then
		log_data = Null
		TotalCnt = 0
	else
		log_data = rs.getrows
		TotalCnt = recordcount
	End If
	Set rs = nothing

End If

dbcon.close
Set dbcon = nothing

%>

<script type="text/javascript">
//<![CDATA[
function DelOk(){
	var eForm = document.getElementById("log_List");
	if (confirm("삭제하시겠습니까?")){
		eForm.submit();
	}return;
}


function checkAll(){
	var eForm = document.getElementById('log_List');
	if(eForm.chk_all.value == "") {
		eForm.chk_all.value="Y";
		checkboxChk(eForm.tran_pr, true);
	}else {
		eForm.chk_all.value="";
		checkboxChk(eForm.tran_pr, false);
	}
}

function checkboxChk(chkObj, type){
	var field = chkObj;//buseo_mem.document.mem_list.check;
	if(field.length == null){
		field.checked = type;
	}else{
		for (i = 0; i < field.length; i++){
			field[i].checked = type;
		}
	}
}


function delCount( num ){
	$("input[name='tran_pr']").attr("checked", false);
	$("#tran_pr_"+num).attr("checked", true);
	if(confirm("해당 예약문자를 삭제하시겠습니까?")){
		document.getElementById("log_List").submit();
	}else{
		$("#tran_pr_"+num).attr("checked", false);
	}
}

function reSend(num){
	if(confirm("이 메세지를 재발송하시겠습니까?")){
		var eForm = document.getElementById("resendFrm");
		var number = document.getElementById("number_"+num).value;
		var message = document.getElementById("message_"+num).value;
		
		eForm.number.value = number;
		eForm.message.value = message;
		eForm.submit();
	}
}


function searchGo(){
	var stat_date = $("#stat_date").val();
	var result_type = $("#result_type").val();
	location.href="?stat_date="+stat_date+"&result_type="+result_type;
}
//]]>
</script>

<!-- 타이틀 -->
<div id="cont_head" style="padding-bottom:0px;">
	<h2>보낸문자함</h2>
</div>
<!-- //타이틀 -->
<!-- 내용 -->
<div id="cont_wrap">
<%
If Not(IsNull(ing_data)) Then
%>
	<!-- 발송중 -->
	<div class="s0103" style="border-bottom:1px solid #D0D0d0;margin-bottom:20px;">
		<div class="topbox">
			<ul class="icotip">
				<li class="ing_s">발송중</li>
			</ul>
		</div>
		<ul class="sentlist">
<%
	For i = 0 To UBound(ing_data, 2)
		Call arr2Value(ing_fields, "ing_data", i)
		write_date = formatdatetime(tran_date,2)&" "&formatdatetime(tran_date,4)
		tran_msg_str = Replace(tran_msg, vbcrlf, "<br />")
%>
			<li>
				<span class="ico_ing">발송중</span>
				<div class="ct"><%=tran_msg_str%></div>
				<dl class="info">
					<dt>수신자</dt>
					<dd class="receiver"><%=tran_phone%></dd>
					<dt>발송일시</dt>
					<dd><%=write_date%></dd>
				</dl>
			</li>
<%
	next
%>
		</ul>
	</div>
	<!-- //발송중 -->
<%
End if
%>
	<!-- 보낸문자함 -->
	<div class="s0103">
		<div class="topbox">
			<select class="s_month" style="width:150px;" id="stat_date" onChange="searchGo();">
			<%
				For i = 12 To 0 Step -1
					date_value = DateSerial(Year(now), Month(now)-i, 1)
					i_value = Left( Replace(date_value, "-", "" ), 6 )
			%>
				<option value="<%=i_value%>" <%=chkSelect( i_value, stat_date )%>><%=Left(i_value, 4)%>년 <%=right(i_value, 2)%>월</option>
			<%
				Next
			%>
			</select>
			<select class="s_month" id="result_type" name="result_type" style="width:150px;"  onChange="searchGo();">
				<option value="">발송결과선택</option>
				<option value="success" <%=chkSelect(result_type, "success")%>>발송성공</option>
				<option value="fail" <%=chkSelect(result_type, "fail")%>>발송실패</option>
			</select>
			<ul class="icotip">
				<li class="success_s">발송성공</li>
				<li class="fail_s">발송실패</li>
			</ul>
		</div>

	<form id="log_List" name="log_List" method="post" action="log_del_ok.asp">
	<div>
	<input type="hidden" name="chk_all" value="" />
	<input type="hidden" name="table" value="<%=table%>" />
	</div>

		<ul class="sentlist">
<%
If Not(IsNull(log_data)) Then
	For i = 0 To UBound(log_data, 2)
		num = (TotalCnt - pagesize * (v_page - 1)) - i
		Call arr2Value(Query_Fields, "log_data", i)

		If tran_rslt = "0" Then
			tran_rslt_str = "성공"
			tran_rslt_icon = "ico_success"
		Else
			tran_rslt_str = "실패"
			tran_rslt_icon = "ico_fail"
		End If

		write_date = formatdatetime(tran_date,2)&" "&formatdatetime(tran_date,4)
		If (IsNull( tran_reportdate ) Or tran_reportdate = "") or tran_rslt <> "0" Then
			send_date = ""
		Else
			send_date = formatdatetime(tran_reportdate,2)&" "&formatdatetime(tran_reportdate,4)
		End If
		
		tran_msg_str = Replace(tran_msg, vbcrlf, "<br />")
%>


			<li>
				<span class="<%=tran_rslt_icon%>"><%=tran_rslt_str%></span>
				<div class="ct"><%=tran_msg_str%></div>
				<dl class="info">
					<dt>수신자</dt>
					<dd class="receiver"><%=tran_phone%></dd>
					<dt>발송일시</dt>
					<dd><%=write_date%></dd>
					<dt>발송완료</dt>
					<dd><%=send_date%></dd>
				</dl>
			</li>
<%
	next
End if
%>

		</ul>
	</form>
		<div class="paginate">
			<%
			query_string = "?stat_date=" & server.urlencode( stat_date )
			query_string = query_string & "&result_type=" & server.urlencode( result_type )
			page_url = "03_01_dsmc.asp" & query_string
			pageStyle2( page_url )
			%>
		</div>
		<div class="f_board">
			<div class="search_frm">
				<ul>
					<li class="s_word">
					<form id="frm_sch" action="<%=Request.ServerVariables("path_info")%>"  method="get">
					<div>
					<input type="hidden" name="stat_date" value="<%=stat_date%>" />
					</div>
						<select id="p_search" name="p_search" style="width:100px;">
							<option value="tran_msg" <%=chkSelect(v_search, "tran_msg")%>>내용</option>
							<option value="tran_phone" <%=chkSelect(v_search, "tran_phone")%>>수신번호</option>
						</select>
						<input type="text"  id="p_keyword" name="p_keyword" value="<%=v_keyword%>" class="w_text" placeholder="검색어를 입력하세요." />
						<input type="image" src="/img/sub/btn_search.png" title="검색" class="btn_search" />
					</form>
					</li>
				</ul>
			</div>
		</div>
	</div>
	<!-- //보낸문자함 -->
</div>
<!-- //내용 -->


<form id="resendFrm" method="post" action="/content/01message/01_01.asp">
<input type="hidden" name="number" value="" />
<input type="hidden" name="message" value="" />
</form>

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