<!--#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 nameSort1, nameSort2

nameSort1		= inputValue( Request.QueryString("nameSort1") )
nameSort2		= inputValue( Request.QueryString("nameSort2") )
sh_bdm_idx		= inputValue( Request.QueryString("sh_bdm_idx") )

v_search		= inputValue( Request.QueryString("p_search") )		'검색조건
v_keyword		= inputValue( Request.QueryString("p_keyword") )	'검색어
oreder_filed	= inputValue( Request.QueryString("oreder_filed") )	'검색어
If oreder_filed = "" Then oreder_filed = "adr_name asc, adr_idx asc"

prepage			= Request.ServerVariables("path_info") & "?" & Request.ServerVariables("query_string")	'현재페이지경로

table			= "view_address_member"		'테이블
idx_field		= "adr_idx"			'기본키
'oreder_filed	= "adr_name asc, adr_idx asc"	'정렬기준 필드
Query_Fields	= "adr_idx, bdm_idx, adr_m_id, adr_name, adr_mobile1, adr_mobile2, adr_mobile3, adr_c_memo, bdm_menuname" '불러올 필드
pagesize		= 10				'목록개수
v_block			= 10				'페이지개수

'==================조합 쿼리문=======================
If v_keyword <> "" then
	Query_Where = " where adr_m_id = '" & session("ss_m_id") & "' and " & v_search & " like '%" & v_keyword & "%'"
	andOrWhere	= " and "
Else
	Query_Where = " where adr_m_id = '" & session("ss_m_id") & "'"
	andOrWhere	= " and "
End If

If nameSort1 <> "" And nameSort2 <> "" Then
	Query_Where = Query_Where & andOrWhere & " adr_name between '" & nameSort1 & "' and '" & nameSort2 & "'"
End if
If sh_bdm_idx <> "" Then
	Query_Where = Query_Where & andOrWhere & " bdm_idx = '" & sh_bdm_idx & "'"
End if

Query_OrderBy = " ORDER BY "&oreder_filed
'==================조합 쿼리문=======================

'==================전체 레코드 수 뽑기===============
sql="select count("&idx_field&") from " & table & Query_Where
'Response.write sql
'Response.end
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
	List_data = Null
	TotalCnt = 0
else
	List_data = rs.getrows
	TotalCnt = recordcount
End if


'=======================주소그룹============================
sql = "select a.bdm_idx, bdm_menuname, b.Cnt from bd_address as a left outer join view_bd_memTotal as b on a.bdm_idx = b.bdm_idx where bdm_id = '"&session("ss_m_id")&"' order by bdm_code"
Set rs = DbCon.Execute( sql )
If rs.bof Or rs.eof Then
	addr_list = Null
Else
	addr_list = rs.getrows
End If
'=======================주소그룹============================


Set rs = Nothing
DbCon.close
Set DbCon = Nothing



sortkeyword = "가;나;다;라;마;바;사;아;자;차;카;타;파;하;히"
sortkeyword2 = "ㄱ;ㄴ;ㄷ;ㄹ;ㅁ;ㅂ;ㅅ;ㅇ;ㅈ;ㅊ;ㅋ;ㅌ;ㅍ;ㅎ;"
sortkeyword_arr = Split(sortkeyword, ";")
sortkeyword2_arr = Split(sortkeyword2, ";")
%>
<script type="text/javascript">
//<![CDATA[
//정렬
function doSort(nameSort1, nameSort2){
	location.href="?nameSort1="+encodeURIComponent(nameSort1)+"&nameSort2="+encodeURIComponent(nameSort2);
}



function checkAll(){
	var eForm = document.getElementById('mem_List');
	if(eForm.chk_all.value == "") {
		eForm.chk_all.value="Y";
		checkboxChk(eForm.adr_idx, true);
	}else {
		eForm.chk_all.value="";
		checkboxChk(eForm.adr_idx, 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 DelOk(){
	if (confirm("삭제하시겠습니까?")){
		document.getElementById("mem_List").submit();
	}return;
}

//그룹이동
function grpChange(){
	var obj = document.getElementById("bdm_idx_select");
	var eForm = document.getElementById("mem_List");

	eForm.bdm_idx.value = obj.value;

	if (confirm("선택된 주소록을 그룹이동 하시겠습니까?")){
		eForm.action = "addr_grp_change_ok.asp";
		eForm.submit();
	}return;
}


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 sendit(eForm){
	if(!valueChk(eForm.adr_name, "이름")){return false;}
	if(!valueChk(eForm.adr_mobile, "휴대폰번호")){return false;}
	if(CheckLen( eForm.adr_mobile, 10, 11 )){return false;}
	//alert("OK");
}

function valueChk(obj, objName){	//text필드
	if(obj.value.split(" ").join("") == ""){
		alert(objName+"을(를) 입력하세요");
		try{
			obj.focus();
			return false;
		}catch(e){
			return false;
		}
	}else{
		return true;
	}
}

function SetNum(obj){			//숫자만 입력
	val=obj.value;
	re=/[^0-9]/gi;
	obj.value=val.replace(re,"");
}


function addrModify( adr_idx ){
	$("#detaillayer10 div.popct").load("ajax_addr_modify.asp?adr_idx="+adr_idx);
}

function orderByChange( oreder_filed ){
	var query_string = "nameSort1=<%=server.urlencode(nameSort1)%>";
	query_string += "&nameSort2=<%=server.urlencode(nameSort2)%>";
	query_string += "&oreder_filed="+encodeURIComponent(oreder_filed);
	location.href = "?"+query_string;
}

function setGroupChange(){
	var cnt = $("table.table1 tbody tr td input[name='adr_idx']:checked").size();
	$("#detaillayer8 div.popct p strong").text("‘"+cnt+"건’");
	clickArea(detaillayer8,0);
}
//]]>
</script>
<!-- 타이틀 -->
<div id="cont_head">
	<h2>주소록</h2>
	<p class="imp">기본적으로 가나다 순으로 나오며, 정렬설정은 아래의 선택으로 지정하실 수 있습니다.</p>
</div>
<!-- //타이틀 -->
<!-- 내용 -->
<div id="cont_wrap">
	<!-- 주소록 -->
	<div class="s0201">
		<div class="h_board">
			<div class="float_l">
				<select class="select_basic" style="width:140px;" id="oreder_filed" name="oreder_filed" onchange="orderByChange(this.value);">
					<option value="">정렬기준</option>
					<option value="adr_name asc, adr_idx asc" <%=chkSelect(oreder_filed, "adr_name asc, adr_idx asc")%>>가나다순</option>
					<option value="adr_idx desc" <%=chkSelect(oreder_filed, "adr_idx desc")%>>등록순</option>
				</select>
				<ul class="k_alpa">
					<li><a href="#all" onclick="doSort('','');" <%If nameSort1 = "" Then Response.write "class='active'"%>>전체</a></li><%
For i = 1 To 14
					%><li><a href="#sort" onclick="doSort('<%=sortkeyword_arr(i-1)%>','<%=sortkeyword_arr(i)%>');"  <%If nameSort1 = sortkeyword_arr(i-1) Then Response.write "class='active'"%>><%=sortkeyword2_arr(i-1)%></a></li><%
next
					%><li><a href="#sort" onclick="doSort('A','Z');" <%If nameSort1 = "A" Then Response.write "class='active'"%>>A-Z</a></li>

				</ul>
			</div>
			<div class="float_r">
				<a href="excelprint.asp" class="c_gray">엑셀저장</a>
				<a href="excelinput.asp" onclick="window.open(this.href,'','fullscreen=no, width=580, height=450');return false;" class="c_gray">엑셀등록</a>
				<a href="#input" onclick="clickArea(detaillayer9,0);" class="c_mint">주소록 등록</a>
			</div>
		</div>

	<form id="mem_List" name="mem_List" method="post" action="del_ok.asp">
	<div>
	<input type="hidden" name="chk_all" value="" />
	<input type="hidden" name="table" value="<%=table%>" />
	<input type="hidden" name="prepage" value="<%=prepage%>" />
	<input type="hidden" name="bdm_idx" value="" />
	</div>
		<table class="table1" summary="주소록">
			<colgroup>
				<col width="5%" />
				<col width="8%" />
				<col width="15%" />
				<col width="20%" />
				<col width="12%" />
				<col width="20%" />
				<col width="*" />
			</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">메모</th>
				</tr>
			</thead>
			<tbody>
<%
If isnull( list_data ) Then
%>
<%
Else
	For i = 0 To Ubound(list_data, 2)
		num			= (TotalCnt - pagesize * (v_page - 1)) - i
		Call arr2Value(Query_Fields, "List_data", i)
		If bdm_menuname = "" Or isnull(bdm_menuname) Then bdm_menuname = "그룹미지정"
%>
				<tr>
					<td><input type="checkbox" name="adr_idx" value="<%=adr_idx%>" /></td>
					<td><%=num%></td>
					<td><a href="#modify" onclick="addrModify('<%=adr_idx%>');"><%=adr_name%></a></td>
					<td><a href="#modify" onclick="addrModify('<%=adr_idx%>');"><%=adr_mobile1&"-"&adr_mobile2&"-"&adr_mobile3%></a></td>
					<td>
						<div class="btngroup">
						<input type="hidden" id="number_<%=num%>" value="<%=adr_mobile1 & adr_mobile2 & adr_mobile3%>" />
							<ul class="btn_sm">
								<li><a href="#resend" onclick="reSend(<%=num%>);" class="sm1">발송</a></li>
							</ul>
						</div>
					</td>
					<td><%=bdm_menuname%></td>
					<td><%=adr_c_memo%></td>
				</tr>
<%
	next
End if
%>
			</tbody>
		</table>
	</form>
		<div class="paginate">
			<%
			query_string = "?nameSort1=" & server.urlencode( nameSort1 )
			query_string = query_string & "&nameSort2=" & server.urlencode( nameSort2 )
			query_string = query_string & "&oreder_filed=" & server.urlencode( oreder_filed )
			query_string = query_string & "&sh_bdm_idx=" & server.urlencode( sh_bdm_idx )
			url = "01_01.asp" & query_string
			pageStyle2(url)
			%>
		</div>
		<div class="f_board">
			<div class="btngroup">
				<ul class="btn_nrm_bor column3">
					<li><a href="#chk" onclick="checkAll();" >전체선택/해제</a></li>
					<li><a href="#del" onclick="DelOk();">선택삭제</a></li>
					<li><a href="javascript:;" onclick="setGroupChange();">선택 주소록 그룹설정</a></li>
				</ul>
			</div>
			<form id="frm_sch" action="<%=Request.ServerVariables("path_info")%>"  method="get">
			<div class="search_frm">
				<ul>
					<li class="s_month">
						<select style="width:150px;" id="bdmSearch" name="sh_bdm_idx">
							<option value="">그룹전체</option>
							<option value="0">그룹미지정</option>
<%
If Not(IsNull(addr_list)) then
	For i = 0 To UBound(addr_list, 2)
		If IsNull(addr_list(2,i)) Or addr_list(2,i) = "" Then addr_list(2,i) = 0
%>
				<option value="<%=addr_list(0,i)%>" <%=chkSelect( addr_list(0,i), sh_bdm_idx )%>><%=addr_list(1,i) & "("&addr_list(2,i)&"명)"%></option>
<%
	next
End If
%>
						</select>
					</li>
					<li class="s_word">
					
						<select style="width:100px;" id="p_search" name="p_search">
							<option value="adr_name" <%=chkSelect(v_search, "adr_name")%>>이름</option>
							<option value="adr_c_memo"  <%=chkSelect(v_search, "adr_c_memo")%>>메모</option>
						</select>
						<input type="text" class="w_text" id="p_keyword" name="p_keyword" value="<%=v_keyword%>" placeholder="검색어를 입력하세요." />
						<input type="image" src="/img/sub/btn_search.png" title="검색" class="btn_search" />
					
					</li>
				</ul>
			</div>
			</form>
		</div>
	</div>
	<!-- //주소록 -->
</div>
<!-- //내용 -->

<!-- 그룹설정 -->
<div id="detaillayer8" class="maskpopbox" style="display:none;">
	<div class="popbox">
		<div class="poptit">
			<h4>그룹설정</h4>
			<span class="popcls"><img src="/img/sub/btn_popcls.gif" alt="닫기" /></span>
		</div>
		<div class="popct">
			<p>선택한 <strong>&nbsp;</strong> 주소록을<br/>아래의 그룹으로 이동합니다.</p>
			<div class="sl_box">
				<select id="bdm_idx_select">
					<option value="0">그룹미지정</option>
<%
If Not(IsNull(addr_list)) then
	For i = 0 To UBound(addr_list, 2)
		If IsNull(addr_list(2,i)) Or addr_list(2,i) = "" Then addr_list(2,i) = 0
%>
					<option value="<%=addr_list(0,i)%>"><%=addr_list(1,i)%></option>
<%
	next
End If
%>
				</select>
			</div>
			<div class="btngroup">
				<ul class="btn_nrm column2">
					<li><a href="#change" onclick="grpChange();" class="nrm1">그룹이동</a></li>
					<li><a href="#close" onclick="closeArea();" class="nrm2">취소</a></li>
				</ul>
			</div>
		</div>
	</div>
</div>
<!-- //그룹설정 -->

<!-- 주소록등록 -->
<div id="detaillayer9" class="maskpopbox" style="display:none;">
	<div class="popbox">
		<div class="poptit">
			<h4>주소록등록</h4>
			<span class="popcls"><img src="/img/sub/btn_popcls.gif" alt="닫기" /></span>
		</div>
	<form action="addr_write_ok.asp" method="post" id="frm_pw" name="frm_pw" onsubmit="return sendit(this);">
	<div>
	<input type="hidden" name="prepage" value="<%=NOWPAGE%>" />
	</div>
		<div class="popct">
			<p class="essential"><strong>필수항목</strong></p>
			<ul class="frm">
				<li><input type="text" id="adr_name" name="adr_name" maxlength="30" class="inp_basic ess" placeholder="이름"/></li>
				<li><input type="text" class="inp_basic ess" id="adr_mobile" name="adr_mobile" placeholder="연락처" maxlength="12" onkeyup="SetNum(this);" /></li>
				<li><input type="text" class="inp_basic" id="adr_c_memo" name="adr_c_memo" placeholder="메모" maxlength="100" /></li>
				<li>
					<select class="select_basic ess" id="bdm_idx" name="bdm_idx">
						<option value="0">그룹미지정</option>
						<%
							If Not(IsNull(addr_list)) then
								For i = 0 To UBound(addr_list, 2)
						%>
								<option value="<%=addr_list(0,i)%>"><%=addr_list(1,i)%></option>
						<%
								Next
							End if
						%>
					</select>
				</li>
			</ul>
			<div class="btngroup">
				<ul class="btn_nrm column2">
					<li><input type="submit" class="nrm1" value="저장" style="width:160px;" /></li>
					<li><a href="#close" onclick="closeArea();" class="nrm2">취소</a></li>
				</ul>
			</div>
		</div>
	</form>
	</div>
</div>
<!-- //주소록등록 -->

<!-- 주소록수정 -->
<div id="detaillayer10" class="maskpopbox" style="display:none;">
		<div class="poptit">
			<h4>주소록수정</h4>
			<span class="popcls"><img src="/img/sub/btn_popcls.gif" alt="닫기" /></span>
		</div>
	<div class="popbox">
	<form action="addr_write_ok.asp" method="post" id="frm_pw" name="frm_pw" onsubmit="return sendit(this);">
	<div>
	<input type="hidden" name="prepage" value="<%=NOWPAGE%>" />
	</div>
		<div class="popct">
			&nbsp;
		</div>
	</form>
	</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"-->