<?php

	include $_SERVER['DOCUMENT_ROOT'].'/common/lib/comm.php';
	include $_SERVER['DOCUMENT_ROOT'].ADMIN_PATH.'common/auth_chk.php';

	$mp = "23";	//set top nav

	$searchtype 	= $_REQUEST['searchtype'];
	$searchword 	= $_REQUEST['searchword'];
	$dt_start 		= $_REQUEST['dt_start'];
	$dt_end 		= $_REQUEST['dt_end'];

	$PageNo 		= $_REQUEST['pageno'];
	$PageSize =$_REQUEST['PageSize'];
	if (empty($PageNo)) {$PageNo=1;}else{$PageNo=$PageNo;}
	if (empty($PageSize)) {
		$PageSize=10; //목록개수설정
	}else{$PageSize=$PageSize;}

	$pagestartpoint=($PageNo-1)*$PageSize;
	$add_sql = " WHERE ds_delind='N'";	//삭제하지 않은
	$add_sql.= " AND ds_status = 'B0' "; //활동 중인 - A0:활동,B0:휴면

//echo $_REQUEST['searchtype'];
//echo "<BR>";


	if($searchword != ""){
		if($searchtype=="" || $searchtype==null){
			$add_sql.= " AND (nm_name like '$searchword%' or nm_email like '$searchword%') ";
		}else{
			$add_sql.= " AND $searchtype like '$searchword%'";
		}
	}
	if($dt_start != "" && $dt_end != ""){
		$add_sql.= " AND dt_dormant between '$dt_start' and '$dt_end' ";
	}

	$sql = "select count(*) from member_master $add_sql";
//	echo $sql;
	$totalrows = @mysql_result(mysql_query($sql),0,0);

?>
<? include("../inc/inc_top.php") ?>
<? include("../inc/inc_header.php") ?>

<section id="contents">
	<h2>휴면 회원관리</h2>
	<h3><em>▶</em> 회원검색</h3>

	<table class="tbl_search">
		<colgroup>
			<col width="10%">
			<col width="38%">
			<col width="10%">
			<col width="*">
		</colgroup>
	<form id="frmSearch" name="frmSearch" method="post">
	<input type="hidden" id="PageSize" name="PageSize">
	<input type="hidden" id="searchtype" name="searchtype">
		<tr>
			<th>검색어</th>
			<td>
				<span class="select2" style="margin-right:5px;width:100px;" id="sel_searchtype">
					<select>
						<option value="">전체</option>
						<option value="nm_email"<? if($searchtype =="nm_email"){?> selected<?}?>>E-Mail</option>
						<option value="nm_name"<? if($searchtype =="nm_name"){?> selected<?}?>>이름</option>
					</select>
				</span>
				<input type="text" class="inp_txt" style="width:60%;">
			</td>
			<th>휴면회원 전환일</th>
			<td colspan="3">
				<input type="text" class="inp_txt" style="width:34%;" id="dt_start" name="dt_start" value="<?=$dt_start?>">
				<span class="btn_cal" id="btn_cal1">달력보기</span>
				~
				<input type="text" class="inp_txt" style="width:34%;" id="dt_end" name="dt_end" value="<?=$dt_end?>">
				<span class="btn_cal" id="btn_cal2">달력보기</span>
				<input type="submit" class="rnd_btn ty3 gray" value="검색" title="검색">
			</td>
		</tr>
	</form>
	</table>

	<div class="select_view_type">
		<span class="select" style="width:160px;" id="selBox">
			<select>
				<option value="10"<? if($PageSize==10){ ?> selected<? } ?>>10개 보기</option>
				<option value="20"<? if($PageSize==20){ ?> selected<? } ?>>20개 보기</option>
				<option value="30"<? if($PageSize==30){ ?> selected<? } ?>>30개 보기</option>
			</select>
		</span>
	</div>

	<div class="tbl_wrap">
	<form id="frmMember" name="frmMember" method="post" action="member_proc.php" enctype="multipart/form-data">
	<input type="hidden" name="mode" id="mode" value="DeleteArr"/>
		<table class="tbl_list" id="layout_table">
			<colgroup>
				<col width="7%">
				<col width="7%">
				<col width="*">
				<col width="13%">
				<col width="18%">
				<col width="18%">
				<col width="15%">
			</colgroup>
			<thead>
			<tr>
				<th>선택</th>
				<th>번호</th>
				<th>아이디</th>
				<th>이름</th>
				<th>연락처</th>
				<th>휴면해제</th>
				<th>등록일</th>
			</tr>
			</thead>
<?
		if($totalrows>0) {

			$r = mysql_query("SELECT *
								FROM member_master $add_sql
								ORDER BY cd_user desc
								LIMIT $pagestartpoint,$PageSize");
			$i=1;
			while($col = mysql_fetch_array($r)) {
?>
			<tr>
				<td class="chk"><span class="check_wrap"><input type="checkbox" name="arr_cd_user[]" id="arr_cd_user[]" value="<?=$col['cd_user']?>"><i></i></span></td>
				<td><?=$i?></td>
				<td><?=$col['nm_email']?></td>
				<td><?=$col['nm_name']?></td>
				<td><?=$col['nm_hp']?></td>
				<td><a href="#" class="rnd_s_btn btn_cancel" value="<?=$col['cd_user']?>">해제하기</a></td>
				<td><?=$col['dt_insert']?></td>
			</tr>
<?
				$i++;
			}
		}else{
?>
			<tr>
				<td colspan="7">데이터가 존재 하지 않습니다.</td>
			</tr>
<?
		}
?>
		</table>
</form>
	</div>

	<div class="paging">
		<?
			$url = "./dormant.php?searchtype=$searchtype&searchword=$searchword&dt_start=$dt_start&dt_end=$dt_end";
			ListPg1($url ,$PageNo,$PageSize,10,$totalrows,$leftboard[1],$rootpath);
		?>
	</div>

	<div class="btn_right">
		<a href="#" class="rnd_btn gray" id="btn_write">탈퇴처리</a>
	</div>
</section>
<form name="frmCancel" id="frmCancel" method="post" action="member_proc.php">
	<input type="hidden" name="mode" id="mode_cancel" value="cancelDormant">
	<input type="hidden" name="cd_user" id="cd_user_cancel">
</form>

<script laguage="javascript" type="text/javascript">
    $(document).ready(function() {

        $(".btn_cancel").bind("click",function(){
			$("#cd_user_cancel").val($(this).attr("value"));
			var custom_opts = {
				title : '',
				btn_close_show : false,
			}

			custom_opts.title = '휴면 해제하시겠습니까?';
			custom_modal_confirm(custom_opts, function(confirm) {
				if(confirm) {
					$(".btn_cancel").hide();
					var data = $("#frmCancel").serialize();
					$.ajax({
						url : 'member_proc.php',
						type: 'POST',
						dataType : 'json',
						data: data,
						success: function(res) {
							custom_modal_confirm_close();

							$(".btn_cancel").show();

							//세션 종료시 로그인 페이지로 이동
							if(res.CODE != "0000") {
								custom_opts.title = res.MSG;

								if(res.CODE == "4444") {
									window.location.href = res.DATAS.URL;
								}
								custom_modal_alert(custom_opts);
								return false;
							}

							custom_opts.title = '휴면 해제가 완료되었습니다.';
							custom_opts.event_esc_key = false;

							custom_modal_alert(custom_opts, function() {
								reload();
							});
						},
						error:function(request,status,error){
							$(".btn_cancel").show();

							custom_modal_confirm_close();

							alert("code:"+request.status+"\n"+"message:"+request.responseText+"\n"+"error:"+error);
						}
					});

				}else {
					$(".btn_cancel").show();
					return false;
				}
			});

//			alert($("#btn_cancel").attr('value'));
            // if(confirm("해제하시겠습니까?")){
			// 	$("#cd_user_cancel").val($("#btn_cancel").attr('value'));
            //     $("#frmCancel").submit();
            // }
        });

        $("#btn_write").bind("click",function(){

			var custom_opts = {
				title : '',
				btn_close_show : false,
			}

			var checked_length = $("#layout_table tbody input[type=checkbox]:checked").length;
			if(checked_length < 1) {
				custom_opts.title = '탈퇴처리하려는 회원을 선택해 주세요.';

				custom_modal_alert(custom_opts);
				return false;
			}



			custom_opts.title = '탈퇴 처리하시겠습니까?';
			custom_modal_confirm(custom_opts, function(confirm) {
				if(confirm) {
					$("#btn_write").hide();
					var data = $("#frmMember").serialize();
					$.ajax({
						url : 'member_proc.php',
						type: 'POST',
						dataType : 'json',
						data: data,
						success: function(res) {
							custom_modal_confirm_close();

							$("#btn_write").show();

							//세션 종료시 로그인 페이지로 이동
							if(res.CODE != "0000") {
								custom_opts.title = res.MSG;

								if(res.CODE == "4444") {
									window.location.href = res.DATAS.URL;
								}
								custom_modal_alert(custom_opts);
								return false;
							}

							custom_opts.title = '탈퇴처리가 완료되었습니다.';
							custom_opts.event_esc_key = false;

							custom_modal_alert(custom_opts, function() {
								reload();
							});
						},
						error:function(request,status,error){
							$("#btn_write").show();

							custom_modal_confirm_close();

							alert("code:"+request.status+"\n"+"message:"+request.responseText+"\n"+"error:"+error);
						}
					});

				}else {
					$("#btn_write").show();
					return false;
				}
			});

			// var c=confirm("정보를 등록하시겠습니까?");
			// if(c){
			// 	$("#btn_write").hide();
			// 	$("#frmMember").submit();
			// }else{
			// 	$("#btn_write").show();
			// 	return false;
			// }

		});
    });
</script>

<? include("../inc/inc_footer.php") ?>
<? include("../inc/inc_bottom.php") ?>
<?
mysql_close($connect);
?>
