<!--#include virtual="/common/file/head_01message.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"
Where = " where user_id = '" & session("ss_m_id") & "' and schedule_type = 1"
Orderby = " order by msg_id desc "
sql = "select " & s_fields & " from " & table & Where & orderby
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		= "a.msg_id"			'기본키
	oreder_filed	= "a.send_date desc, a.msg_id desc"	'정렬기준 필드
	Query_Fields	= "a.msg_id, a.phone_number, a.result, a.send_date, b.mms_msg, a.report_res_date" '불러올 필드

	pagesize		= 10				'목록개수
	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_OrderBy = " ORDER BY "&oreder_filed
	'==================조합 쿼리문=======================
	
	'==================전체 레코드 수 뽑기===============
	sql="select count(*) from " & table & Query_Where
	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) & " "&idx_field&" 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();
	}
}
//]]>
</script>


<!-- 컨텐츠 부분-->
        <td width="720" align="left" valign="top">
		<table width="720" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td width="560" align="left" valign="top" style="padding-bottom:30px;"><img src="/sms_img/sub/stit_0104.gif" alt="보낸문자함(장문)" /></td>
            <td width="300" align="right" valign="bottom" style="padding-bottom:30px;"><img src="/sms_img/sub/home.gif" width="14" height="10" /><img src="/sms_img/sub/arrow.gif" width="14" height="10" /><span class="style9">문자메세지</span><img src="/sms_img/sub/arrow.gif" width="14" height="10" /><span class="style11">보낸문자함(장문)</span></td>
          </tr>

          <tr>
            <td colspan="2">





<!-- 리스트 -->
<link rel="Stylesheet" type="text/css" href="/content/board/nninc_simple/css/common.css" />
<div id="board" style="width:100%;">
<%
If Not(IsNull(ing_data)) Then
	ing_count = ubound(ing_data) + 1
%>
	<!-- 발송중 목록 -->
	<div class="board_total">
		<div class="board_total_left">
			<span style="font-weight:bold; color:;">발송중 메세지</span> 전체 <strong class="board_orange"><%=ing_count%></strong>개
		</div>
		<div class="board_total_right">
			<!-- 분류 -->
			<a href="index03.asp"><img src="/sms_img/common/btn_refresh.gif" alt="새로고침" /></a>
			<!-- //분류 -->
		</div>
	</div>
	<div class="table_blist">
		<table cellspacing="0" >
		<caption> (목록)</caption>
			<colgroup>
			<col width="50" />
			<col width="130" />
			<col width="" />
			<col width="110" />
			<col width="110" />
			<col width="50" />
			</colgroup>
		<thead>
			<tr>
				<th scope="col">번호</th>
				<th scope="col">동시발송</th>
				<th scope="col">내용</th>
				<th scope="col">작성시간</th>
				<th scope="col">전송시간</th>
				<th scope="col" class="th_none">결과</th>
			</tr>
		</thead>
		<tbody>
<%
	For i = 0 To UBound(ing_data)
		num = ing_count - i
		ST.arr2Value( ing_data(i) )
		write_date = createDate( send_date )
		dest_info_arr = Split(dest_info, "|")
		dest_info_count = ubound(dest_info_arr) + 1
		mms_msg = subject = StringToHTML( mms_msg, 50, false )
%>
			<tr>
				<td><%=num%></td>
				<td><%=dest_info_count%>건</td>
				<td class="title" style="padding-top:5px;padding-bottom:5px;white-space:normal;"><%=mms_msg%></td>
				<td><%=write_date%></td>
				<td>&nbsp;</td>
				<td>대기중</td>
			</tr>
<%
	next
%>
		</tbody>
		</table>
	</div><br /><br />
	<!-- 발송중 목록끝 -->
<%
End if
%>
	<div class="board_total">
		<div class="board_total_left">
			전체 <strong><%=recordcount%></strong>개 (페이지 <strong class="board_orange"><%=v_page%></strong>/<%=v_totalpage%>)
		</div>
		<div class="board_total_right">
			<!-- 분류 -->
			<select id="stat_date" onChange="location.href='?stat_date='+this.value;">
			<%
				For i = 12 To 0 Step -1
					date_value = DateSerial(Year(now), Month(now)-i, Day(now))
					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>
			<!-- //분류 -->
		</div>
	</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>
	<div class="table_blist">
			<table cellspacing="0" >
			<caption> (목록)</caption>
				<colgroup>
				<col width="50" />
				<col width="50" />
				<col width="80" />
				<col width="" />
				<col width="110" />
				<col width="110" />
				<col width="50" />
				</colgroup>
			<thead>
				<tr>
					<th scope="col">선택</th>
					<th scope="col">번호</th>
					<th scope="col">수신자번호</th>
					<th scope="col">내용</th>
					<th scope="col">발송요청</th>
					<th scope="col">발송완료</th>
					<th scope="col" class="th_none">결과</th>
				</tr>
			</thead>
			<tbody>
				<!-- 공지기능 -->
				<!-- //공지기능 -->
<%
If Not(IsNull(log_data)) Then
	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 = "성공"
		Else
			result_str = "실패(" & result & ")"
		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 = StringToHTML( remove_tags(mms_msg), 50, false )
%>
				<tr>
					<td>
					<input type="checkbox" name="msg_id" value="<%=msg_id%>" title="해당 게시글 선택"  />
					<input type="hidden" id="number_<%=num%>" value="<%=phone_number%>" />
					<textarea id="message_<%=num%>" style="display:none;"><%=mms_msg%></textarea>
					</td>
					<td><%=num%></td>
					<td><%=phone_number%></td>
					<td class="title" style="padding-top:5px;padding-bottom:5px;white-space:normal;"><%=mms_msg_str%>&nbsp;<a href="#resend" onclick="reSend(<%=num%>);">[재발송]</a></td>
					<td><%=write_date%></td>
					<td><%=res_date%></td>
					<td><%=result_str%></td>
				</tr>
<%
	next
Else
%>
				<tr>
					<td colspan="7">내역이 없습니다.</td>
				</tr>
<%
End if
%>
 
			</tbody>
			</table>
	</div>
	<!-- //리스트 테이블 -->

	<!-- 버튼 -->
	<div class="board_button">
		
		<div class="fl">
			<ul>
			<li class="pl"><img src="/manager/img/line01.gif" width="36" height="21" alt="" /></li>
			<li class="pt">
				<div class="board_bt01"><a href="#chk" onclick="checkAll();" ><span>전체 선택/해제</span></a></div>
				<div class="board_bt01"><a href="#del" onclick="DelOk();"><span>선택문자 삭제</span></a></div>
			</li>
			</ul>
		</div>
		
		<div class="fr">&nbsp;
		</div>
 
	</div>
	</form>
	<!-- //버튼 -->
	
 
 
	<!-- 페이징 -->
	<div class="board_paginate">
		<%
		query_string = "?stat_date=" & stat_date
		page2("index04.asp" & query_string)
		%>
	</div>
	<!-- //페이징 -->
 
	<!-- 게시물 검색 -->
	<div class="board_search">
		<form id="frm_sch" action="<%=Request.ServerVariables("path_info")%>"  method="get">
		<div>
		<input type="hidden" name="stat_date" value="<%=stat_date%>" />
		</div>
			<fieldset>
			<legend>게시물 검색</legend>
			<ul>
			<li class="board_search_start"></li>
			<li><img src="/content/board/nninc_simple/img/search_ic.gif" width="21" height="25" alt="" /></li>
			<li><select id="p_search" name="p_search" title="검색형태 선택" >
				<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></li>
			<li><input type="text" size="20" title="검색어를 입력하세요" id="p_keyword" name="p_keyword" class="board_input" value="<%=v_keyword%>"  /></li>
			<li><input type="image" src="/content/board/nninc_simple/img/search_bt.gif" id="search_bt" name="search_bt" class="search_bt" alt="검색" /></li>
			<li class="board_search_end"></li>
			</ul>
			</fieldset>
		</form>
	</div>
	<!-- //게시물 검색 -->
 
 
</div>
<!-- //리스트 -->







			</td>
          </tr>
        </table>
		</td>
      </tr>
    </table>
<form id="resendFrm" method="post" action="/content/01message/index.asp">
<input type="hidden" name="number" value="" />
<input type="hidden" name="message" value="" />
</form>
<!--#include virtual="/common/file/bottom.asp"-->