<?php
	include $_SERVER['DOCUMENT_ROOT'].'/common/lib/comm.php';
	include $_SERVER['DOCUMENT_ROOT'].'/common/user_chk.php';

	$list_url = "sell_list.php";

	$cd_user = $_SESSION['s_cd_user'];
	$s_cd_car = $_SESSION['s_cd_car'];
	$s_nomem_hp = $_SESSION['s_nomem_hp'];
	$s_nm_name = $_SESSION['s_nm_name'];

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

	$pagestartpoint=($PageNo-1)*$PageSize;
	$sql = "where s.ds_delind='N'";

	if($cd_user != ""){
		$sql = $sql. "	and s.cd_user='$cd_user' ";
	}else if($s_nomem_hp != ""){
		$sql = $sql. "	and s.nm_hp='$s_nomem_hp' ";
		$sql = $sql. "	and s.nm_name='$s_nm_name' ";
		$sql = $sql. "	and a.cd_car='$s_cd_car' ";
	}else{
		$sql = $sql. "	and 1!=1 ";
	}

	$searchtype = $_REQUEST['searchtype'];
	$searchword = $_REQUEST['searchword'];
	$ds_usertype = $_REQUEST['ds_usertype'];
//	$ds_status = 'Z0';

	$ds_type = "A0";	//A0 : 매입
	$sql = $sql. "	and s.ds_type = '$ds_type' ";

	if($searchword != ""){
		if($searchtype=="" || $searchtype==null){
			$sql = $sql. "	and (s.nm_name like '$searchword%' or a.nm_number like '$searchword%') ";
		}else{
			$sql = $sql. "	and $searchtype like '$searchword%'";
		}
	}

	if($ds_usertype != ""){
		$sql = $sql. "	and s.ds_usertype = '$ds_usertype'";
	}

	if($ds_status != ""){
		if($ds_status == "Z0"){
			$sql = $sql. "	and s.ds_status in ('E0','F0','G0','Z0')";
		}else{
			$sql = $sql. "	and s.ds_status in ('B0','C0','D0')";
		}
	}

	$orderby = " order by s.cd_sale desc ";
	$totalrows = @mysql_result(mysql_query("select count(*) from sale_master s inner join car_master a on (	s.cd_car = a.cd_car ) $sql"),0,0);

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

<section id="wrap">
	<section id="visual" class="visual_mypage">
		<h2>마이페이지</h2>
		<p>쉽고 간편한 내차팔기, 견적산출, 최종 매각까지 어떤 수수료도 요구하지 않습니다.</p>
	</section>

	<section id="content">
		<?
			// /common/lib/func.php 1662에 정의됨
			$is_upro_member = getUproMember($_SESSION['s_cd_user']);
			$depth_info = array("NAME" => array("차량정보", "차량정보"));
			if($is_upro_member) {
				include_once($_SERVER['DOCUMENT_ROOT']."/mypage/inc_menu_member_company.php");
			}else {
				include_once($_SERVER['DOCUMENT_ROOT']."/mypage/inc_menu_main_member.php");
			}
		?>
		<!-- <ul class="location">
			<li><a href="/" class="home">홈</a></li>
			<li><span class="depth1">차량정보</span>
            	<ul class="sub_depth">
					<li><a href="/mypage/mypage.php">마이페이지</a></li>
					<li><a href="/mypage//sell_list.php">입찰정보</a></li>
					<li><a href="/sell/sell_list.php">차량정보</a></li>
					<li><a href="/mypage/qna_list.php?cd_board=02&ds_kind=A">문의내역</a></li>
				</ul>

            </li>
			<li><span class="depth2">차량정보</span></li>
		</ul> -->

		<ul class="car_list">
<?
if($totalrows>0) {

$r = mysql_query("SELECT
						a.*
						, b.nm_model
						, c.nm_grade
						, d.nm_brand
						, e.nm_model_sub
						, getCode('car_master','ds_type',a.ds_type) as nm_type
						, getCode('car_master','ds_open',a.ds_open) as nm_open
						, getCode('car_master','ds_sales',a.ds_sales) as nm_sales
						, getCode('car_master','ds_transmission',a.ds_transmission) as nm_transmission
						, getCode('member_master','ds_area',s.ds_area) as nm_area
						, getCode('sale_master','ds_status',s.ds_status) as nm_status
						, s.cd_sale
						, s.nm_name nm_name_sale
						, s.ds_status ds_status_sale
						, case when s.ds_status in ('B0','C0') then '미승인' when s.ds_status in ('D0') then '반려' when s.ds_status in ('E0','F0') then '입찰중' when s.ds_status in ('G0') then '입찰마감' when s.ds_status in ('Z0') and s.ds_status_contract in ('B0') then '거래연기' when s.ds_status in ('Z0') and s.ds_status_contract in ('C0') then '거래실패' when s.ds_status in ('Z0') then '낙찰' when s.ds_status in ('ZE') then '거래실수' when s.ds_status in ('ZS') then '구매확정' else '' end as nm_status_sale
						, case when a.nm_act_yn in ('Y') then '유'  else '무' end as nm_act_yn_name
						FROM sale_master s
							inner join car_master a
							on (s.cd_car = a.cd_car)
							left outer join car_model b
							on (a.cd_model = b.cd_model)
							left outer join car_grade c
							on (a.cd_grade = c.cd_grade)
							left outer join car_brand d
							on (a.cd_brand = d.cd_brand)
							left outer join car_model_sub e
							on (a.cd_model_sub = e.cd_model_sub)
							$sql $orderby LIMIT $pagestartpoint,$PageSize");

$i=1;
while($col = mysql_fetch_array($r)) {

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

?>
			<li onclick="location.href='./sell_view.php?list_url=<?=$list_url?>&cd_sale=<?=$col[cd_sale]?>&ds_status_sale=<?=$col[ds_status_sale]?>&ListPageNo=<?=$PageNo?>';" style="cursor:pointer;">
				<span class="thumb"><img src="<?=UPLOAD_PATH_CAR?>nm_file_main/ratio/<?=$col[nm_file_front]?>" alt=""></span>
				<dl>
					<dt><?=$col[nm_model]." ".$col[nm_model_sub]." ".$col[nm_grade]?></dt>
					<dd>주행거리 : <?=$col[nm_mileage]?>km</dd>
					<dd>최초등록일 : <?=$col[nm_regdate_mm]?> / <?=$col[nm_regdate_yyyy]?></dd>
					<dd>사고유무 : <?=$col[nm_act_yn_name]?></dd>
					<dd>판매지역 : <?=$col[nm_area]?></dd>
				</dl>
				<div class="flag"><?=$col[nm_status_sale]?></div>
			</li>
<?
	$i++;
}
}else{
?>
				등록된 정보가 없습니다.
<?
}
?>

		</ul>
	</section>
</section>

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