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

	$HEADER_LOC = 'main';
	$nav_title = "입찰중";

	$list_url 		= "prepare_list.php";

	$cd_sale 		= $_REQUEST['cd_sale'];

	$s_cd_dealer 	= $_SESSION['s_cd_dealer'];
	$s_cd_dealer_p 	= $_SESSION['s_cd_dealer_p'];
	$s_aap_ds_type 	= $_SESSION['s_aap_ds_type'];
	$s_ds_status_p 	= $_SESSION['s_ds_status_p'];

	$ds_status_proc = 'E0';


	$sql ="SELECT
						a.*
						, b.nm_model
						, d.nm_brand
						, getCode('car_master','ds_type',a.ds_type) as nm_type
						, getCode('car_master','ds_year',a.ds_year) as nm_year
						, 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('car_master','ds_oil',a.ds_oil) as nm_oil
						, getCode('car_master','ds_accident',a.ds_accident) as nm_accident
						, getCode('sale_master','ds_usertype',s.ds_usertype) as nm_usertype
						, getCode('member_master','ds_area',s.ds_area) as nm_area
						, getCode('sale_master','ds_status',s.ds_status) as nm_status
						, getCode('car_master','ds_business_num',a.ds_business_num) as nm_business_num
						, s.nm_name nm_name_sale
						, s.ds_status ds_status_sale
						, s.nm_hp nm_hp_sale
						, s.nm_email nm_email_sale
						, s.ds_area ds_area_sale
						, s.nm_recommend nm_recommend_sale
						, s.nm_cont_return nm_cont_return_sale
						-- , getRemainTime(".LIMIT_TIME_TENDER.", s.dt_approve, now()) as time_limit_tender
						, getRemainTime(s.ds_auction_time, s.dt_approve, now()) as time_limit_tender
						, s.cd_user cd_user_sale
						, s.ds_sale_period ds_sale_period
						, s.is_staff is_staff
						, s.ds_tradein ds_tradein
						, s.ds_buy_method ds_buy_method
						, s.ds_auction_time ds_auction_time
						, aap.nm_name aap_nm_name
						, getCode('member_master','ds_branch',(select ds_branch from sa_master sm where s.cd_user = sm.cd_user limit 1)) as nm_branch
						, getCode('member_master','ds_company_bp',(select ds_company_bp from sa_master sm where s.cd_user = sm.cd_user limit 1)) as nm_company_bp
						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_brand d on (a.cd_brand = d.cd_brand)
							left outer join aap_master aap on s.cd_aap_dealer = aap.cd_dealer
						WHERE s.cd_sale='$cd_sale' ";
	// echo $sql;
	// exit;
	$col=mysql_fetch_array(mysql_query($sql));
	if (!empty($col['cd_car'])){

		$cd_car 			= $col['cd_car'];
		$cd_model 			= $col['cd_model'];
		$cd_brand 			= $col['cd_brand'];
		$ds_logo 			= $col['ds_logo'];
		$cd_category 		= $col['cd_category'];
		$cd_grade 			= $col['cd_grade'];
		$ds_cate 			= $col['ds_cate'];
		$ds_type 			= $col['ds_type'];
		$ds_year 			= $col['ds_year'];
		$nm_name 			= $col['nm_name'];
		$nm_price 			= $col['nm_price'];
		$nm_mileage 		= $col['nm_mileage'];
		$ds_driving_system 	= $col['ds_driving_system'];
		$ds_transmission 	= $col['ds_transmission'];
		$nm_file_list 		= $col['nm_file_list'];
		$nm_file_main 		= $col['nm_file_main'];
		$nm_file_report 	= $col['nm_file_report'];
		$nm_file_report_back = $col['nm_file_report_back'];
		$nm_file_front 		= $col['nm_file_front'];
		$nm_file_back 		= $col['nm_file_back'];
		$nm_file_side1 		= $col['nm_file_side1'];
		$nm_file_side2 		= $col['nm_file_side2'];
		$nm_file_dashboard 	= $col['nm_file_dashboard'];
		$nm_file_engine 	= $col['nm_file_engine'];
		$nm_file_registration = $col['nm_file_registration'];
		$ds_oil 			= $col['ds_oil'];
		$nm_gearbox 		= $col['nm_gearbox'];
		$nm_color 			= $col['nm_color'];
		$nm_incolor 		= $col['nm_incolor'];
		$ds_accident 		= $col['ds_accident'];
		$nm_cont_accident  	= $col['nm_cont_accident'];
		$nm_regdate 		= $col['nm_regdate'];
		$ds_sales 			= $col['ds_sales'];
		$nm_btitle 			= $col['nm_btitle'];
		$nm_stitle 			= $col['nm_stitle'];
		$nm_ltitle 			= $col['nm_ltitle'];
		$nm_cont 			= $col['nm_cont'];
		$nm_cont_pac 		= $col['nm_cont_pac'];
		$nm_cont_detail 	= $col['nm_cont_detail'];
		$nm_desc 			= $col['nm_desc'];
		$nm_business_num 	= $col['nm_business_num'];
		$ds_sale_period 	= $col['ds_sale_period'];

		$nm_guide 			= $col['nm_guide'];
		$ds_open 			= $col['ds_open'];
		$ds_status 			= $col['ds_status'];
		$dt_insert 			= $col['dt_insert'];
		$nm_insert 			= $col['nm_insert'];
		$dt_update 			= $col['dt_update'];
		$nm_update 			= $col['nm_update'];
		$ds_delind 			= $col['ds_delind'];
		$nm_number 			= $col['nm_number'];
		$nm_cc 				= $col['nm_cc'];
		$ds_trade 			= $col['ds_trade'];
		$ds_main 			= $col['ds_main'];
		$nm_regdate_yyyy 	= $col['nm_regdate_yyyy'];
		$nm_regdate_mm 		= $col['nm_regdate_mm'];
		$nm_regdate_dd 		= $col['nm_regdate_dd'];

		$nm_brand 			= $col['nm_brand'];
		$nm_model 			= $col['nm_model'];
		$nm_model_sub 		= $col['nm_model_sub'];
		$nm_grade 			= $col['nm_grade'];

		$cd_car_history		= $col['cd_car_history'];

		$nm_year 			= $col['nm_year'];
		$nm_type 			= $col['nm_type'];
		$nm_open 			= $col['nm_open'];
		$nm_sales 			= $col['nm_sales'];
		$nm_transmission 	= $col['nm_transmission'];
		$nm_oil 			= $col['nm_oil'];
		$nm_usertype 		= $col['nm_usertype'];
		$nm_accident 		= $col['nm_accident'];
		$nm_area 			= $col['nm_area'];
		$nm_name_sale 		= $col['nm_name_sale'];
		$ds_status_sale 	= $col['ds_status_sale'];
		$nm_hp_sale 		= $col['nm_hp_sale'];
		$nm_email_sale 		= $col['nm_email_sale'];
		$ds_area_sale 		= $col['ds_area_sale'];
		$nm_recommend_sale 	= $col['nm_recommend_sale'];
		$nm_cont_return_sale = $col['nm_cont_return_sale'];

		$time_limit_tender 	= $col['time_limit_tender'];

		$nm_file_act 		= $col['nm_file_act'];
		$nm_act_yn 			= $col['nm_act_yn'];

		$aap_nm_name 		= $col['aap_nm_name'];
		$nm_branch 			= $col['nm_branch'];
		$is_staff 			= $col['is_staff'];
		$nm_company_bp 		= $col['nm_company_bp'];
		$ds_business_num	= $col['ds_business_num'];

		$ds_tradein 		= $col['ds_tradein'];
		$ds_buy_method 		= $col['ds_buy_method'];
		$ds_auction_time 	= $col['ds_auction_time'];

		$ds_accident_check	= $col['ds_accident_check'];
		$ds_damage_check	= $col['ds_damage_check'];

		//SA 등록이면 SA 저보를 가져옴
		if($is_staff == "Y") {
			// $sa_sql = "select * from sa_master where cd_user = '{$col['cd_user_sale']}' limit 1 ";
			// $sa = mysql_fetch_array(mysql_query($sa_sql));
			// $sa_name = $staff['nm_name'];
			// $sa_nm_np = $staff['nm_hp'];
		}

		list($nm_hp_sale1, $nm_hp_sale2, $nm_hp_sale3) = explode("-", $nm_hp_sale);

	}else{
			AlertBack("지정되지않은 요청입니다");
	}

	$aap_sql = "SELECT * FROM aap_master a WHERE cd_dealer = '$s_cd_dealer' LIMIT 1";
	$aap_res = mysql_query($aap_sql);
	$aap = mysql_fetch_array($aap_res);
	// print_r($aap);

	//부관리자로 로그인시 입찰 정보
	$bid_price = "";
	if($aap['ds_type'] == 'D1') {

		$manager_tender_sql = "SELECT *
									FROM tender_master
									WHERE ds_delind ='N'
										AND cd_sale = '$cd_sale'
										AND cd_dealer = '{$_SESSION['s_cd_dealer']}' ";
		$manager_tender_col = mysql_fetch_array(mysql_query($manager_tender_sql));

		if(!empty($manager_tender_col['nm_price'])) {
			$bid_price = $manager_tender_col['nm_price'];
		}
	}
?>
<?php include("include/header.php") ?>


<main class="pb123">
	<section>
		<div class="sub--top--visual">
			<div class="contents--inner">
				<h2>입찰중</h2>
				<p>이차조아에서는 사고 이력 조회 후 최고가 내차를 판매할 수 있습니다.</p>
			</div>
		</div>
	</section>
<?php
	include("./inc_ViewCar.php");
	include("./inc_ViewTender.php");
	include("./inc_ViewBtn.php");
?>
</main>

<?php
	include("./inc_Popup.php");
?>

<?php include("include/footer.php") ?>
