<?php

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

	$list_url = "grade.php";
	$mp = "13";	//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 mst.cd_model_sub desc ";

	/*$ds_cate = $_REQUEST[ds_cate];
	if(!$ds_cate) $ds_cate='A0';
	$sql = $sql. "	and cd_model in(select  cd_model from car_model where ds_cate ='$ds_cate')";
	*/

	$cd_category = $_REQUEST['cd_category'];
	$cd_brand = $_REQUEST['cd_brand'];
	if($cd_brand){
		$sql = $sql. "	and mst.cd_model_sub in (select cd_model_sub from car_model_sub where cd_model in (select cd_model from car_model where cd_brand = '$cd_brand')) ";
	}

	if($searchword != ""){
		if($searchtype=="" || $searchtype==null){
			$sql = $sql. "	and (nm_grade like '$searchword%')";
		}else{
			$sql = $sql. "	and $searchtype like '$searchword%'";
		}
	}

	$totalrows = @mysql_result(mysql_query("select count(*) from car_grade mst  $sql"),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 class="select" style="width:200px;" id="sel_cd_category">
				<select id="cd_category" name="cd_category" onchange="cd_category_chg(this.value)"></select>
			</span>
			<span class="select" style="width:200px;" id="sel_cd_brand">
				<select id="cd_brand" name="cd_brand" onchange="cd_brand_chg(this.value)"></select>
			</span>
		</div>
	</div>
	</form>
	<div class="tbl_wrap">
		<table class="tbl_list ty2">
			<colgroup>
				<col width="7%">
				<col width="20%">
				<col width="20%">
				<col width="*">
				<col width="13%">
			</colgroup>
			<thead>
			<tr>
				<th>번호</th>
				<th>제조사</th>
				<th>모델</th>
				<th>세부모델</th>
				<th>등급</th>
				<th>정보수정</th>
			</tr>
			</thead>
<?
		if($totalrows>0) {

			$r = mysql_query("select T.*
								,(select nm_model from car_model tsub1 where tsub1.cd_model = T.cd_model) nm_model
								,(select nm_brand from car_brand tsub where tsub.cd_brand = T.cd_brand) nm_brand
								,(select nm_category from car_category tsub where tsub.cd_category = T.cd_category) nm_category
							from
								(SELECT mst.*, (select nm_model_sub from car_model_sub where cd_model_sub = mst.cd_model_sub ) as nm_model_sub
								, (select cd_category from car_model_sub where cd_model_sub = mst.cd_model_sub ) as cd_category
								, (select cd_model from car_model_sub sub1 where sub1.cd_model_sub = mst.cd_model_sub ) cd_model
								, (select cd_brand from car_model sub where sub.cd_model = (select cd_model from car_model_sub sub where sub.cd_model_sub = mst.cd_model_sub ) ) cd_brand
								FROM car_grade mst   $sql $orderby LIMIT $pagestartpoint,$PageSize )
 								T ");

			$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><?=$col['nm_model_sub']?></td>
				<td><?=$col['nm_grade']?></td>
				<td><a href="./grade_form.php?ds_cate=<?=$ds_cate?>&cd_grade=<?=$col['cd_grade']?>&PageNo=<?=$PageNo?>" class="rnd_s_btn">수정</a></td>
				</tr>
<?
				$i++;
			}
		}else{

?>
                <tr>
                  <td align="center" colspan="7" class="list03">등록된 정보가 없습니다.</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>
						<span class="select ty2" style="width:320px;">
							<select>
								<option value="">K3</option>
								<option value="">K5</option>
							</select>
						</span>
					</td>
				</tr>
				<tr>
					<th>세부모델</th>
					<td><input type="text" class="inp_txt" style="width:320px;" value="3시리즈 (F30) (12년~현재)"></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&cd_category=$cd_category&cd_brand=$cd_brand";
				ListPg1($url ,$PageNo,$PageSize,10,$totalrows,$leftboard[1],$rootpath);
		?>
	</div>

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

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

	});
</script>

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