<?php

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

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

	$searchtype 	= $_REQUEST['searchtype'];
	$searchword 	= $_REQUEST['searchword'];
	$ds_status 		= $_REQUEST['ds_status'];
	$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'";

	// $ds_type = "D0";
	// $add_sql.= " AND ds_type = '$ds_type' ";

	if($searchword != ""){
		if($searchtype=="" || $searchtype==null){
			$add_sql.= " AND (nm_name like '$searchword%' or cd_dealerid like '$searchword%') ";
		}else{
			$add_sql.= " AND $searchtype like '$searchword%'";
		}
	}
	if($ds_status != ""){
		if($ds_status == "Z0"){
			$add_sql.= " AND ds_status = 'Z0' ";
		}else{
			$add_sql.= " AND (ds_status is null or ds_status != 'Z0') ";
		}
	}
	if($dt_start != "" && $dt_end != ""){
		$add_sql.= " AND dt_insert between '$dt_start' and '$dt_end' ";
	}
	$sql = "select count(*) from sa_master $add_sql";
	$totalrows = @mysql_result(mysql_query($sql),0,0);

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

<section id="contents">
	<h2>SA 회원관리</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="cd_dealerid"<? if($searchtype =="cd_dealerid"){?> selected<?}?>>아이디</option>
						<option value="nm_name"<? if($searchtype =="nm_name"){?> selected<?}?>>이름</option>
					</select>
				</span>
				<input type="text" class="inp_txt" style="width:60%;" id="searchword" name="searchword" value="<?=$searchword?>">
			</td>
			<th>가입승인</th>
			<td>
				<div class="radio_chk">
					<span class="check_wrap"><input type="radio" name="ds_status" id="radio1" value=""><i></i><label for="radio1">전체</label></span>
					<span class="check_wrap"><input type="radio" name="ds_status" id="radio2" value="Z0"><i></i><label for="radio2">승인</label></span>
					<span class="check_wrap"><input type="radio" name="ds_status" id="radio3" value="A0"><i></i><label for="radio3">미승인</label></span>
				</div>
			</td>
		</tr>
		<tr>
			<th>회원가입일</th>
			<td colspan="3">
				<input type="text" class="inp_txt" style="width:25%;" 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:25%;" 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="검색">

				<div class="btn_right" style="margin-top:-28px">
					<!-- <a href="javascript:;" id="btn_download_excel" class="rnd_btn black" style='width:110px;'>엑셀다운로드</a> -->
				</div>
			</td>
		</tr>
	</form>
	</table>

	<div class="select_view_type">
		<span class="select" style="width:160px;" id="selBox">
			<select id="page_size">
				<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">
		<table class="tbl_list">
			<colgroup>
				<col width="7%">
				<col width="20%">
				<col width="14%">
				<col width="*">
				<col width="18%">
				<col width="15%">
			</colgroup>
			<thead>
			<tr>
				<th>번호</th>
				<th>아이디</th>
				<th>이름</th>
				<th>연락처</th>
				<th>가입승인</th>
				<th>등록일</th>
			</tr>
			</thead>
<?
		if($totalrows>0) {

			$r = mysql_query("SELECT *
								FROM sa_master
								$add_sql
							ORDER BY cd_user desc
							LIMIT $pagestartpoint,$PageSize");
			$i=1;
			while($col = mysql_fetch_array($r)) {

				$tmpNum =$totalrows-($PageSize*($PageNo-1));
				$no = ($tmpNum - $i)+1;

?>
			<tr onclick="location.href='./sa_view.php?cd_user=<?=$col['cd_user']?>&PageNo=<?=$PageNo?>';" style="cursor: pointer; cursor: hand;">
				<td><?=$no?></td>
				<td><?=$col['cd_userid']?></td>
				<td><?=$col['nm_name']?></td>
				<td><?=$col['nm_hp']?></td>
				<td><?=($col['ds_status'] == "Z0") ? "승인":"미승인" ?></td>
				<td><?=$col['dt_insert']?></td>
			</tr>
<?
				$i++;
			}
		}else{
?>
			<tr>
				<td colspan="6">데이터가 존재 하지 않습니다.</td>
			</tr>
<?
		}
?>
		</table>
	</div>

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

	<div class="btn_right">
		<!-- <a href="dealer_form.php?mode=Add" class="rnd_btn gray">+ 회원등록</a> -->
	</div>
</section>

<script language="javascript" type="text/javascript">
	$("#dt_start").datepicker({ dateFormat: 'yy-mm-dd' });
	$("#dt_end").datepicker({ dateFormat: 'yy-mm-dd' });

	$(document).ready(function() {

		$("#btn_cal1").bind("click",function(){
			$("#dt_start").datepicker('show');
		});

		$("#btn_cal2").bind("click",function(){
			$("#dt_end").datepicker('show');
		});

		$("#selBox div.jq_sel ul li a").bind("click",function(){
//			alert(this.value);
//			alert($("#selBox option:selected").val());
//			alert($("#selBox option:selected").text());
//			$("#PageSize").val(this.value);
			$("#PageSize").val($("#selBox option:selected").val());

			$("#frmSearch").submit();

		});

		$("#sel_searchtype div.jq_sel ul li a").bind("click",function(){
			$("#searchtype").val($("#sel_searchtype option:selected").val());
		});
	});


	function fnSearch(){
		if($("#searchtype").val()!="" && $("#searchword").val()==""){
			alert("검색어를 입력하세요");
			return false;
		}
		$("#frmSearch").submit();
	}
	//엑셀 추가
	$("#btn_download_excel").click(function(e) {
		var url = "dealer_excel.php?"+$("#excelForm").serialize();
		window.open(url, "excelWin");
	});
</script>
<form name="excelForm" id="excelForm" method="GET">
<input type="hidden" name="dt_start" value="<?=$dt_start?>">
<input type="hidden" name="dt_end" value="<?=$dt_end?>">

<input type="hidden" name="searchtype" value="<?=$searchtype?>">
<input type="hidden" name="searchword" value="<?=$searchword?>">
<input type="hidden" name="ds_status" value="<?=$ds_status?>">
</form>
<? include("../inc/inc_footer.php") ?>
<? include("../inc/inc_bottom.php") ?>
<?
mysql_close($connect);
?>
