<!--#include virtual="/common/file/inc_head.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") )

Set ST = New SelectTable

'============================================처리중인 문자조회========================================
s_fields = "dest_info, mms_msg, send_status, send_date "
table = "sdk_mms_send"
now_date = Replace( Date(), "-", "" ) & Right("0"&hour(now), 2) & Right("0"&minute(now), 2) & Right("0"&second(now), 2)
Where = " where user_id = '" & session("ss_m_id") & "' and send_date <= '" & now_date & "' "
Orderby = " order by msg_id asc "
sql = "select " & s_fields & " from " & table & Where & orderby
'Response.write sql
ing_data = ST.selectQueryTable( sql )
'============================================처리중인 문자조회========================================


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

table = "sdk_mms_report_detail_" & stat_date

sql = "select count(*) as cnt from information_schema.tables where table_name = '" & table & "'"
table_cnt = ST.selectQueryColumn( sql )

If table_cnt = 0 Then
	log_data = Null
	v_totalpage = 1
	v_page = 1
	pagesize = 10
	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")	'현재페이지경로


	table			= table & " as a left outer join sdk_mms_report_" & stat_date & " as b on a.job_id = b.job_id"
	idx_field		= "convert(varchar, a.msg_id)+'_'+convert(varchar, a.subjob_id)"			'기본키
	oreder_filed	= "a.send_date desc, a.msg_id desc"	'정렬기준 필드
	Query_Fields	= "a.msg_id, a.subjob_id, a.phone_number, a.result, a.send_date, b.mms_msg, a.report_res_date" '불러올 필드

	pagesize		= 12				'목록개수
	v_block			= 10				'페이지개수
	
	'==================조합 쿼리문=======================
	If v_keyword <> "" then
		Query_Where = " where a.user_id = '" & session("ss_m_id") & "' and " & v_search & " like '%" & v_keyword & "%' and ( b.reserved1 <> 'N' or b.reserved1 is null )"
		andOrWhere	= " and "
	Else
		Query_Where = " where a.user_id = '" & session("ss_m_id") & "' and ( b.reserved1 <> 'N' or b.reserved1 is null )"
		andOrWhere	= " and "
	End If
	Query_Where = Query_Where & andOrWhere & " convert(varchar, a.msg_id)+'_'+convert(varchar, a.subjob_id) not in (select convert(varchar, d_msg_id)+'_'+convert(varchar, d_subjob_id) from sdk_mms_delete_log where d_ym = '" & stat_date & "')"


	Query_OrderBy = " ORDER BY "&oreder_filed
	'==================조합 쿼리문=======================
	
	'==================전체 레코드 수 뽑기===============
	sql="select count(*) from " & table & Query_Where
	'Response.write sql
	recordcount = ST.selectQueryColumn( sql )
	recordcount = CLng(recordcount)
	'==================전체 레코드 수 뽑기===============
	
	v_totalpage=fix((recordcount-1)/pagesize)+1 '전체덩어리갯수 
	v_page = InputValue( 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) & " convert(varchar, a.msg_id)+'_'+convert(varchar, a.subjob_id) from " & table
	sql = sql & Query_Where & Query_OrderBy & ")"
	sql = sql & Query_OrderBy
	'========================리스트 출력 쿼리문 생성 끝======================
	'response.write sql

	log_data = ST.selectQueryTable( sql )
	If isnull(log_data) Then
		TotalCnt = 0
	Else
		TotalCnt = recordcount
	End if
End If
%>

<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.msg_id, true);
	}else {
		eForm.chk_all.value="";
		checkboxChk(eForm.msg_id, 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 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 delCount( num ){
	$("input[name='msg_id']").attr("checked", false);
	$("#msg_id_"+num).attr("checked", true);
	if(confirm("해당 예약문자를 삭제하시겠습니까?")){
		document.getElementById("log_List").submit();
	}else{
		$("#msg_id_"+num).attr("checked", false);
	}
}
//]]>
</script>


<!-- 타이틀 -->
<div id="cont_head">
	<h2>보낸문자함</h2>
</div>
<!-- //타이틀 -->
<!-- 내용 -->
<div id="cont_wrap">
	<!-- 탭 -->
	<ul class="con_tab fl">
		<li><a href="./03_01.asp">단문</a></li>
		<li><a href="#" class="on">장문</a></li>
	</ul>
	<!-- //탭 -->

<%
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)
		num = ing_count - i
		ST.arr2Value( ing_data(i) )
		write_date = createDate( send_date )
		dest_info_count = 0
		If dest_info <> "" then
			dest_info_arr = Split(dest_info, "|")
			dest_info_count = ubound(dest_info_arr) + 1
		End if
		mms_msg_str = Replace(mms_msg, vbcrlf, "<br />")
		mms_msg_str = Replace(mms_msg_str, "  ", "&nbsp;&nbsp;")
		'mms_msg = subject = StringToHTML( mms_msg, 50, false )
%>
			<li>
				<span class="ico_ing">발송중</span>
				<div class="ct"><%=mms_msg_str%></div>
				<dl class="info">
					<dt>동시발송</dt>
					<dd class="receiver"><%=dest_info_count%>건</dd>
					<dt>발송일시</dt>
					<dd><%=write_date%></dd>
				</dl>
			</li>
<%
	next
%>

		</ul>
	</div>
	<!-- //발송중 -->
<%
End if
%>




	<!-- 보낸문자함 -->
	<div class="s0103">
		<div class="topbox">
			<select id="stat_date" onChange="location.href='?stat_date='+this.value;" class="s_month" style="width:150px;">
			<%
				For i = 12 To 0 Step -1
					date_value = DateSerial(Year(now), Month(now)-i, 1)
					i_value = Left( Replace(date_value, "-", "" ), 6 )
					i_value2 = Right(i_value, 4)
			%>
				<option value="<%=i_value2%>" <%=chkSelect( i_value2, stat_date )%>><%=Left(i_value, 4)%>년 <%=right(i_value, 2)%>월</option>
			<%
				Next
			%>
			</select>
			<ul class="icotip">
				<li class="success_s">발송성공</li>
				<li class="fail_s">발송실패</li>
				<li class="ing_s">발송중</li>
			</ul>
		</div>
	<form id="log_List" name="log_List" method="post" action="log_del_ok_mms.asp">
	<div>
	<input type="hidden" name="chk_all" value="" />
	<input type="hidden" name="d_ym" value="<%=stat_date%>" />
	</div>

		<ul class="sentlist">
<%
If IsNull(log_data) Then
%>
			<li><dl class="info">
					<dt>발송내역 없음</dt>
				</dl></li>
<%
else
	For i = 0 To UBound(log_data)
		num = (TotalCnt - pagesize * (v_page - 1)) - i
		ST.arr2Value( log_data(i) )

		If result = "2" Then
			result_str = "성공"
			result_str_icon = "ico_success"
		Else
			result_str = "실패(" & result & ")"
			result_str_icon = "ico_fail"
		End If

		write_date = createDate( send_date )
		If report_res_date = null Or report_res_date = "" Then
			res_date = ""
		Else
			res_date = createDate( report_res_date )
		End If
		
		mms_msg_str = Replace(mms_msg, vbcrlf, "<br />")
		mms_msg_str = Replace(mms_msg_str, "  ", "&nbsp;&nbsp;")
		'mms_msg_str = StringToHTML( remove_tags(mms_msg), 50, false )
%>

			<li>
				<span class="<%=result_str_icon%>"><%=result_str%></span>
				<div class="ct"><%=mms_msg_str%></div>
				<dl class="info">
					<dt>수신자</dt>
					<dd class="receiver"><%=phone_number%></dd>
					<dt>발송날짜</dt>
					<dd><%=write_date%></dd>
					<dt>발송완료</dt>
					<dd><%=res_date%></dd>
				</dl>
				<input type="checkbox" id="msg_id_<%=num%>" class="vam" name="msg_id" value="<%=msg_id%>_<%=subjob_id%>" />
				<input type="hidden" id="number_<%=num%>" value="<%=phone_number%>" />
				<textarea id="message_<%=num%>" style="display:none;"><%=mms_msg%></textarea>
				<div class="btngroup">
					<ul class="btn_sm">
						<li><a href="#resend" onclick="reSend(<%=num%>);" class="sm1">재발송</a></li>
						<li><a href="#del" onclick="delCount(<%=num%>);" class="sm2">삭제</a></li>
					</ul>
				</div>
			</li>
<%
	Next
End if
%>

		</ul>
	</form>
		<div class="paginate">
			<%
			query_string = "?stat_date=" & server.urlencode( stat_date )
			page_url = "04_01.asp" & query_string
			pageStyle2( page_url )
			%>
		</div>
		<div class="f_board">
			<div class="btngroup">
				<ul class="btn_nrm_bor column2">
					<li><a href="#chk" onclick="checkAll();">전체선택/해제</a></li>
					<li><a href="#del" onclick="DelOk();">선택삭제</a></li>
				</ul>
			</div>
			<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="b.mms_msg" <%=chkSelect(v_search, "b.mms_msg")%>>내용</option>
							<option value="a.phone_number" <%=chkSelect(v_search, "a.phone_number")%>>수신번호</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"-->