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

	$list_url = "sell_list.php";

	$cd_user = $_SESSION['s_cd_user'];

	$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'";

	$sql = $sql. "	and s.cd_user='$cd_user' ";

	$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'";
	}

	$sql = $sql. "	and s.ds_status in ('E0')";
	$sql = $sql. "	and s.dt_approve > '' and getRemainTimeByPhase('".LIMIT_TIME_TENDER."', '".LIMIT_TIME_SELL."', s.dt_approve, now()) = '0분'"; //승인이 된 후 입찰시간이 지난 건

	$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);

?>
<!DOCTYPE html>
<HTML lang="ko">
<head>
<meta charset="utf-8">
<title>UPRO</title>
<meta name="viewport" content="user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, width=device-width">
<meta name="format-detection" content="telephone=no">
<link rel="stylesheet" type="text/css" href="/m/css/common.css">
<link rel="stylesheet" type="text/css" href="/m/css/sub.css">
<script type="text/javascript" charset="utf-8" src="/m/js/jquery-1.11.2.min.js"></script>
<script type="text/javascript" charset="utf-8" src="/m/js/ui.js"></script>
<script type="text/javascript" src="<?=JS_PATH?>"></script>
</head>

<body>
<!-- s : header -->
<? include("../inc/inc_header.php"); ?>
<!-- // e : header -->

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

	<section id="content">
		<ul class="tab">
			<li><a href="/m/mypage/modify.php">정보수정</a></li>
			<li><a href="#" class="on">입찰정보</a></li>
			<li><a href="/m/mypage/qna_list.php?cd_board=02&ds_kind=A">문의내역</a></li>
		</ul>
		<?
			//유프로직원일 경우에만 아래 메뉴 출력
			// /common/lib/func.php 1662에 정의됨
			$buy_menu = "06";			//메뉴 active 용
			$is_upro_member = getUproMember($_SESSION['s_cd_user']);
			if($is_upro_member) {
				include_once($_SERVER['DOCUMENT_ROOT']."/m/mypage/inc_menu_member_company.php");
			}
		?>

		<h3>유찰내역</h3>
		<p class="sort">
			<select style="width:100%;">
				<option value="">최근순</option>
			</select>
		</p>
		<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
						, getRemainTime(".LIMIT_TIME_SELL.", s.dt_approve, now()) as time_limit_sell
						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='./<? if($col[ds_status_sale]=="ZS"){ ?>sell_view2.php<? }else{ ?>sell_view_fail.php<? } ?>?list_url=<?=$list_url?>&cd_sale=<?=$col[cd_sale]?>&ds_status_sale=<?=$col[ds_status_sale]?>&ListPageNo=<?=$PageNo?>';" style="cursor:pointer;">
				<div>
					<span class="thumb"><img src="<?=UPLOAD_PATH_CAR?>nm_file_main/ratio/<?=$col[nm_file_front]?>" alt=""></span>
					<dl>
						<dt><?=$col[nm_brand]." ".$col[nm_model]?></dt>
						<dd>차량번호 : <?=$col[nm_number]?></dd>
						<dd>주행거리 : <?=$col[nm_mileage]?>km</dd>
						<dd>년식 : <?=$col[ds_year]?>년</dd>
						<dd>사고유무 : <?=$col[nm_act_yn_name]?></dd>
						<dd>판매지역 : <?=$col[nm_area]?></dd>
					</dl>
					<div class="flag"><p><? if($col[time_limit_sell]=="0분" && ($col[ds_status_sale] == "E0" || $col[ds_status_sale] == "F0")){ ?>
				거래마감
				<? }else{ ?>
				<?=$col[nm_status_sale]?>
				<? } ?></p></div>




				</div>
			</li>


            <?
	$i++;
}
}else{
?>

			<li>
				등록된 정보가 없습니다.
			</li>
            <?
}
?>


		</ul>

<!--		<div class="paging">
			<span>
				<a href="#" class="first">맨처음</a>
				<a href="#" class="prev">이전</a>
			</span>
			<strong>1</strong>
			<a href="#">2</a>
			<a href="#">3</a>
			<a href="#">4</a>
			<a href="#">5</a>
			<span>
				<a href="#" class="next">다음</a>
				<a href="#" class="last">맨마지막</a>
			</span>
		</div>-->
        	<div class="paging">
			<?
					$url = "./sell_list.php?searchtype=$searchtype&searchword=$searchword&ds_status=$ds_status&ds_usertype=$ds_usertype";
					ListPg1($url ,$PageNo,$PageSize,10,$totalrows,$leftboard[1],$rootpath);
			?>
		</div>

		<div class="btn_center">
			<!-- <a href="/m/sell/sell.php" class="button">내차팔기</a> -->
		</div>
	</section>
</section>
<!-- e : container -->

<!-- s : footer -->
<? include("../inc/inc_footer.php"); ?>
<!-- // e : footer -->

</body>
</html>
<?
mysql_close($connect);
?>
