<?php

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

	$list_url = "model.php";
	$mp = "11";	//set top nav

	$PageNo =$_REQUEST['pageno'];
	if (empty($PageNo)) {$PageNo=1;}else{$PageNo=$PageNo;}

	$PageSize=10; //목록개수설정
	$pagestartpoint=($PageNo-1)*$PageSize;

	$sql = "where ds_delind='N'";
	$orderby = "order by cd_model desc";
	
	/*
	$ds_cate = $_REQUEST[ds_cate];
	
	if($ds_cate){	
		$sql = $sql. "	and ds_cate = '$ds_cate'";
	}
	*/
	
	$cd_category = $_REQUEST[cd_category];
	$cd_brand = $_REQUEST[cd_brand];
	if($cd_brand){	
		$sql = $sql. "	and cd_brand = '$cd_brand'";
	}
	
	if($searchword != ""){
		if($searchtype=="" || $searchtype==null){
			$sql = $sql. "	and (nm_model like '$searchword%')";
		}else{
			$sql = $sql. "	and $searchtype like '$searchword%'";
		}
	}

	$totalrows = @mysql_result(mysql_query("select count(*) from car_model  $sql order by cd_model desc "),0,0);

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

<section id="contents">
	<form id="frmSearch" name="frmSearch" method="post">
	<div class="area_title">
		<h2>모델</h2>
		<div class="area_select">
			<span>
				<select id="cd_category" name="cd_category"></select>
			</span>
			<span>
				<select id="cd_brand" name="cd_brand"></select>
			</span>
		</div>
	</div>
	</form>
	<div class="tbl_wrap">
		<table class="tbl_list ty2">
			<colgroup>
				<col width="7%">
				<col width="30%">
				<col width="*">
				<col width="13%">
			</colgroup>
			<thead>
			<tr>
				<th>번호</th>
				<th>제조사</th>
				<th>모델</th>
				<th>정보수정</th>
			</tr>
			</thead>
<?
		if($totalrows>0) {

			$r = mysql_query("SELECT *
								, getCode('car_model','ds_status',ds_status) nm_status 
								, getCode('car_model','ds_cate',ds_cate) nm_cate
								, (select nm_brand from car_brand sub where sub.cd_brand = mst.cd_brand limit 1) nm_brand
								, (select nm_category from car_category where car_category.cd_category = mst.cd_category ) nm_category
							FROM car_model mst  $sql order by cd_model desc  LIMIT $pagestartpoint,$PageSize");
				
		
			$i=1;
			while($col = mysql_fetch_array($r)) { 

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

?>

                <tr>
				<td><?=$no?></td>
				<td><?=$col[nm_brand]?></td>
				<td><?=$col[nm_model]?></td>
				<td><a href="./model_form.php?cd_category=<?=$cd_category?>&cd_model=<?=$col[cd_model]?>&PageNo=<?=$PageNo?>" class="rnd_s_btn">수정</a></td>
				</tr>
<?
				$i++;
			}
		}else{
?>
                <tr>
                  <td colspan="4">등록된 정보가 없습니다.</td>
                </tr>
<?
		}
?>
		</table>
	</div>

	<!-- layer popup -->
	<div class="layer_popup modify_popup">
		<div class="close">팝업닫기</div>
		<div class="cont2">
			<table class="tbl_list2" style="width:460px;">
				<colgroup>
					<col width="20%">
					<col width="*">
				</colgroup>
				<tr>
					<th>구분</th>
					<td>
						<div class="radio_chk">
							<span class="check_wrap"><input type="radio" name="radiobutton" id="domestic"><i></i><label for="domestic">국내</label></span>
							<span class="check_wrap"><input type="radio" name="radiobutton" id="overseas"><i></i><label for="overseas">해외</label></span>
						</div>
					</td>
				</tr>
				<tr>
					<th>제조사</th>
					<td>
						<span class="select ty2" style="width:320px;">
							<select>
								<option value="">현대</option>
								<option value="">기아</option>
							</select>
						</span>
					</td>
				</tr>
				<tr>
					<th>모델</th>
					<td><input type="text" class="inp_txt" style="width:320px;" value="K7"></td>
				</tr>
			</table>
			<div class="btn_center">
				<a href="#" class="rnd_btn ty2 gray">수정</a>
				<a href="#" class="rnd_btn ty2 black">삭제</a>
			</div>
		</div>
	</div>
	<!-- // layer popup -->

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

	<div class="btn_right">
		<a href="#" class="rnd_btn gray" onclick="location.replace('./model_form.php');">+ 모델 등록</a>
	</div>
</section>

<script language="javascript" type="text/javascript">
	
	$(document).ready(function() {
		setCodeSelect("listcategory","cd_category","car_category","cd_category","<?=$cd_category?>","선택하세요","");
		setCodeSelect("listBrandBycate","cd_brand","car_brand","cd_brand",'<?=$cd_brand?>','선택하세요','<?=$cd_category?>');
		
		$("#cd_category").change(function(){
			setCodeSelect("listBrandBycate","cd_brand","car_brand","cd_brand",'<?=$cd_brand?>','선택하세요',$(this).val());			
		});

		$("#cd_brand").change(function(){
			$("#frmSearch").submit();
			//location.href = "./model.php?cd_brand="+$(this).val();			
		});
		

	});
</script>

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