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

	$cd_user 		= $_SESSION['s_cd_user'];
	$cd_sale 		= $_REQUEST['cd_sale'];
	$ds_status_sale = $_REQUEST['ds_status'];

	switch($ds_status_sale) {


		//입찰중	: "E0" : "승인", "F0" : "입찰중", "G0" : "입찰마감"
		case "E0":
		case "F0":
		case "G0":
			$mp = "31";	//set top nav
			$STitle			= "입찰중";		//: 페이지 제목
			$bViewCar		= true;		//: 차 내용
			$bViewSuccess	= false;	//: 낙찰 내용
			$bViewTender		= true;	//: 입찰업체 내용
			$bViewBtn		= false;	//: 버튼&실행 내용
			$bViewContract		= false;	//: 계약 내용

		break;

		//입찰완료	: "Z0" : "낙찰"
		case "Z0":

			if($ds_status_contract_sale == "Z0"){
				$mp = "33";	//set top nav
				//거래마감	: "Z0" : "거래마감"
				$STitle			= "거래중";		//: 페이지 제목
				$bViewCar		= false;		//: 차 내용
				$bViewSuccess	= true;	//: 낙찰 내용
				$bViewTender		= false;	//: 입찰업체 내용
				$bViewBtn		= false;	//: 버튼&실행 내용
				$bViewContract		= true;	//: 계약 내용
			}else if($ds_status_contract_sale == "B0"){
				$mp = "35";	//set top nav
				//거래연기	: "B0" : "거래연기"
				$STitle			= "거래연기 리스트";		//: 페이지 제목
				$bViewCar		= false;		//: 차 내용
				$bViewSuccess	= true;	//: 낙찰 내용
				$bViewTender		= false;	//: 입찰업체 내용
				$bViewBtn		= false;	//: 버튼&실행 내용
				$bViewContract		= true;	//: 계약 내용
			}else if($ds_status_contract_sale == "C0"){
				$mp = "37";	//set top nav
				//거래실패	: "C0" : "거래실패"
				$STitle			= "거래실패 리스트";		//: 페이지 제목
				$bViewCar		= false;		//: 차 내용
				$bViewSuccess	= true;	//: 낙찰 내용
				$bViewTender		= false;	//: 입찰업체 내용
				$bViewBtn		= false;	//: 버튼&실행 내용
				$bViewContract		= true;	//: 계약 내용
			}else if($ds_status_contract_step1_sale == "Y"){
				$mp = "33";	//set top nav
				//거래중	: ds_status_contract_step1 == "Y" : "거래중"
				$STitle			= "거래중 리스트";		//: 페이지 제목
				$bViewCar		= false;		//: 차 내용
				$bViewSuccess	= true;	//: 낙찰 내용
				$bViewTender		= false;	//: 입찰업체 내용
				$bViewBtn		= false;	//: 버튼&실행 내용
				$bViewContract		= true;	//: 계약 내용
			}else{
				$mp = "32";	//set top nav

				$STitle			= "입찰완료 리스트";		//: 페이지 제목
				$bViewCar		= true;		//: 차 내용
				$bViewSuccess	= true;	//: 낙찰 내용
				$bViewTender		= true;	//: 입찰업체 내용
				$bViewBtn		= false;	//: 버튼&실행 내용
				$bViewContract		= false;	//: 계약 내용
			}

		break;

		//견적실수	: "ZE" : "견적실수"
		case "ZE":
			$mp = "36";	//set top nav
			$STitle			= "견적실수 리스트";		//: 페이지 제목
			$bViewCar		= true;		//: 차 내용
			$bViewSuccess	= true;	//: 낙찰 내용
			$bViewTender		= true;	//: 입찰업체 내용
			$bViewBtn		= false;	//: 버튼&실행 내용
			$bViewContract		= false;	//: 계약 내용

		break;

		//거래마감	: "ZS" : "거래마감"
		case "_ZS":

			$STitle			= "거래마감 리스트";		//: 페이지 제목
			$bViewCar		= false;		//: 차 내용
			$bViewSuccess	= false;	//: 낙찰 내용
			$bViewTender		= false;	//: 입찰업체 내용
			$bViewBtn		= false;	//: 버튼&실행 내용
			$bViewContract		= true;	//: 계약 내용

		break;

		case 'ZS':
			$mp = "34";	//set top nav
	//			AlertBack("지정되지않은 요청입니다");
			$STitle			= "판매완료";		//: 페이지 제목
			$bViewCar		= false;		//: 차 내용
			$bViewSuccess	= true;	//: 낙찰 내용
			$bViewTender		= true;	//: 입찰업체 내용
			$bViewBtn		= false;	//: 버튼&실행 내용
			$bViewContract		= true;	//: 계약 내용
			break;
		default :

		//$ds_status - "A0" : "입력중", "B0" : "입력완료", "C0" : "승인대기", "D0" : "반려", "E0" : "승인", "F0" : "입찰중", "G0" : "입찰마감", "Z0" : "낙찰"
		//입찰대기	: "A0" : "입력중", "B0" : "입력완료", "C0" : "승인대기", "D0" : "반려"
		// case "A0":
		// case "B0":
		// case "C0":
		// case "D0":
			$mp = "30";	//set top nav
			$STitle			= "입찰대기";		//: 페이지 제목
			$bViewCar		= true;		//: 차 내용
			$bViewSuccess	= false;	//: 낙찰 내용
			$bViewTender		= false;	//: 입찰업체 내용
			$bViewBtn		= true;	//: 버튼&실행 내용
			$bViewContract		= false;	//: 계약 내용

		// break;
		break;
	}


	//차량 정보는 여기서 가져오도록 수정
	$sql ="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_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('member_master','ds_area',s.ds_area_user) as nm_area_user
						, getCode('sale_master','ds_status',s.ds_status) as nm_status
						, 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
						, s.nm_file_chk1 nm_file_chk1_sale
						, s.nm_file_chk2 nm_file_chk2_sale
						, s.nm_file_chk3 nm_file_chk3_sale
						, s.nm_file_chk4 nm_file_chk4_sale
						, s.nm_file_chk5 nm_file_chk5_sale
						, s.ds_sale_period ds_sale_period
						, s.nm_cont_return nm_cont_return
						, aap.nm_name aap_nm_name
						, chm.cd_car_history
						FROM sale_master s
							inner join car_master a on (s.cd_car = a.cd_car)
							left outer join car_history_master chm on chm.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)
							left outer join aap_master aap on (aap.cd_dealer = s.cd_aap_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'];
		$cd_model_sub 		= $col['cd_model_sub'];
		$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'];
		$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_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'];
		$ds_sale_period		= $col['ds_sale_period'];
		$nm_brand 			= $col['nm_brand'];
		$nm_model 			= $col['nm_model'];
		$nm_model_sub 		= $col['nm_model_sub'];
		$nm_grade 			= $col['nm_grade'];

		$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_area_user 		= $col['nm_area_user'];

		$ds_business_num	= $col['ds_business_num'];

		$nm_recommend_sale 	= $col['nm_recommend_sale'];
		$nm_cont_return_sale = $col['nm_cont_return_sale'];

		//보험처리
		$nm_act_chgno 		= $col['nm_act_chgno'];
		$nm_act_chgnm 		= $col['nm_act_chgnm'];
		$nm_act_s1 			= $col['nm_act_s1'];
		$nm_act_s2 			= $col['nm_act_s2'];
		$nm_act_s3 			= $col['nm_act_s3'];
		$nm_act_s4 			= $col['nm_act_s4'];
		$nm_act_my 			= $col['nm_act_my'];
		$nm_act_my_amt 		= $col['nm_act_my_amt'];
		$nm_act_other 		= $col['nm_act_other'];
		$nm_act_other_amt 	= $col['nm_act_other_amt'];
		$nm_act_searchdt 	= $col['nm_act_searchdt'];
		$nm_act_cnt 		= $col['nm_act_cnt'];
		$nm_act_general_spec = $col['nm_act_general_spec'];
		$nm_act_use_record 	= $col['nm_act_use_record'];
		$nm_act_use_record_lend = $col['nm_act_use_record_lend'];
		$nm_act_use_record_biz = $col['nm_act_use_record_biz'];
		$nm_act_use_record_official = $col['nm_act_use_record_official'];
		$nm_act_ins_loss 	= $col['nm_act_ins_loss'];
		$nm_act_ins_wet 	= $col['nm_act_ins_wet'];
		$nm_act_ins_robbery = $col['nm_act_ins_robbery'];
		$nm_file_act 		= $col['nm_file_act'];
		$nm_act_yn 			= $col['nm_act_yn'];
		$nm_cont_return		= $col['nm_cont_return'];
		$aap_nm_name 		= $col['aap_nm_name'];

		$cd_car_history		= $col['cd_car_history'];

		$ds_g1_01 			= $col['ds_g1_01'];
		$ds_g1_02 			= $col['ds_g1_02'];
		$ds_g1_03 			= $col['ds_g1_03'];
		$ds_g1_04 			= $col['ds_g1_04'];
		$ds_g1_05 			= $col['ds_g1_05'];
		$ds_g2_01 			= $col['ds_g2_01'];
		$ds_g2_02 			= $col['ds_g2_02'];
		$ds_g2_03 			= $col['ds_g2_03'];
		$ds_g2_04 			= $col['ds_g2_04'];
		$ds_g2_05 			= $col['ds_g2_05'];
		$ds_g3_01 			= $col['ds_g3_01'];
		$ds_g3_02 			= $col['ds_g3_02'];
		$ds_g3_03 			= $col['ds_g3_03'];
		$ds_g3_04 			= $col['ds_g3_04'];
		$ds_g3_05 			= $col['ds_g3_05'];
		$ds_g4_01 			= $col['ds_g4_01'];
		$ds_g4_02 			= $col['ds_g4_02'];
		$ds_g4_03 			= $col['ds_g4_03'];
		$ds_g4_04 			= $col['ds_g4_04'];
		$ds_g4_05 			= $col['ds_g4_05'];

/*
		$arr_nm_info1 = explode("-",$nm_info1);
		if(count($arr_nm_info1) == 3){
			$nm_info11 = $arr_nm_info1[0];
			$nm_info12 = $arr_nm_info1[1];
			$nm_info13 = $arr_nm_info1[2];
		}else{
			$nm_info11 = "";
			$nm_info12 = "";
			$nm_info13 = "";
		}

		$arr_nm_info3 = explode("@",$nm_info3);
		if(count($arr_nm_info3) == 2){
			$nm_info31 = $arr_nm_info3[0];
			$nm_info32 = $arr_nm_info3[1];
		}else{
			$nm_info31 = "";
			$nm_info32 = "";
		}
		$nm_info3 = $col[nm_info3];
*/

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

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

	//입찰대기, 입찰중 화면에서는 차량 정보가 수정 가능함
	$able_status = array("A0", "B0", "C0", "D0", "E0", "F0", "G0");
	$able_modify = false;

	if(in_array($ds_status_sale, $able_status)) {
		$able_modify = true;
	}
?>
<?php include("include/header.php") ?>

<main class="pb123">
	<section>
		<div class="sub--top--visual">
			<div class="contents--inner">
				<h2><?=$STitle?></h2>
				<p>이차조아에서는 사고 이력 조회 후 최고가 내차를 판매할 수 있습니다.</p>
			</div>
		</div>
	</section>


	<section>
		<div class="top--nav--wrap">
			<div class="contents--inner">
				<div class="breadcrumbs--wrap">
					<span></span>
					<span><?=$STitle?></span>
					<span><?=$STitle?></span>
				</div>
			</div>
		</div>
	</section>

<?php

	if($bViewCar){
		include("./inc_ViewCar.php");
	}

	if($bViewSuccess){
		include("./inc_ViewSuccess.php");
	}

	if($bViewContract){
		include("./inc_ViewContract.php");
	}

	if($bViewTender){
		include("./inc_ViewTender.php");
	}

	if($bViewBtn){
		include("./inc_ViewBtn.php");
	}
?>

</main>

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

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