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

	$mode = $_REQUEST['mode'];

//	Auth -> Step 단계에 따른 정상적인 요청 체크
	if($mode != "Step2" || $mode == null)
		AlertBack("지정되지 않은 요청입니다.");

//	$s_cd_sale = $_SESSION['s_cd_sale'];
	$s_cd_car = $_SESSION['s_cd_car'];

	$ds_cate = $_REQUEST['ds_cate'];
	if(!$ds_cate) $ds_cate='A0';

	$ds_model_cate= $ds_cate;

	if($s_cd_car !="" || $s_cd_car != null){

		$sql ="SELECT *
			FROM car_master mst
			WHERE  cd_car='$s_cd_car' AND ds_delind='N'";
/*
		$sql ="SELECT *
			FROM car_master mst
				inner join sale_master s
				on (
					mst.cd_car = s.cd_car
					AND mst.ds_delind='N'
					AND s.cd_sale = '$s_cd_sale'
				) ";
*/

		$col=mysql_fetch_array(mysql_query($sql));

		if (!empty($col['cd_car'])){

			$cd_car 			= $col['cd_car'];
			$cd_brand  			= $col['cd_brand'];
			$cd_category  		= $col['cd_category'];
			$cd_model  			= $col['cd_model'];
			$cd_model_sub  		= $col['cd_model_sub'];
			$cd_grade  			= $col['cd_grade'];
			$cd_car_history  	= $col['cd_car_history'];
			$car_report  		= $col['car_report'];
			$ds_type  			= $col['ds_type'];
			$ds_year  			= $col['ds_year'];
			$nm_mileage  		= $col['nm_mileage'];
			$ds_driving_system  = $col['ds_driving_system'];
			$ds_transmission  	= $col['ds_transmission'];
			$ds_oil  			= $col['ds_oil'];
			$nm_gearbox  		= $col['nm_gearbox'];
			$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'];
			$ds_open  			= $col['ds_open'];
			$ds_status  		= $col['ds_status'];
			$ds_logo  			= $col['ds_logo'];
			$nm_price 			= $col['nm_price'];
			$nm_name  			= $col['nm_name'];
			$nm_color 			= $col['nm_color'];
			$nm_incolor			= $col['nm_incolor'];
			$nm_cc 				= $col['nm_cc'];
			$nm_number 			= $col['nm_number'];
			$ds_trade 			= $col['ds_trade'];
			$nm_regdate_yyyy  	= $col['nm_regdate_yyyy'];
			$nm_regdate_mm  	= $col['nm_regdate_mm'];
			$nm_regdate_dd  	= $col['nm_regdate_dd'];
			$nm_guide  			= $col['nm_guide'];
			$ds_main  			= $col['ds_main'];
			$ds_cate 			= $col['ds_cate'];

			$nm_chk_carno  		= $col['nm_chk_carno'];
			$nm_chk_cnt  		= $col['nm_chk_cnt'];
			$nm_chk_s1 			= $col['nm_chk_s1'];
			$nm_chk_s2 			= $col['nm_chk_s2'];
			$nm_chk_s3 			= $col['nm_chk_s3'];
			$nm_chk_s4 			= $col['nm_chk_s4'];
			$nm_chk_advisor 	= $col['nm_chk_advisor'];
			$nm_chk_date 		= $col['nm_chk_date'];
			$nm_chk_p1 			= $col['nm_chk_p1'];
			$nm_chk_p2 			= $col['nm_chk_p2'];
			$nm_chk_p3 			= $col['nm_chk_p3'];
			$nm_file_chk 		= $col['nm_file_chk'];
			$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_file_act 		= $col['nm_file_act'];


			$upload_file_report_name = $col['nm_file_report'];
			$upload_file_report_back_name = $col['nm_file_report_back'];

			$upload_file_main_name = $col['nm_file_main'];
			$upload_file_list_name = $col['nm_file_list'];

		}else{
			AlertBack("게시물을 가져오지 못하였습니다.");
		}
		$PageNo = $PageNo;
//		$mode = "Update";
	}else{
//		$mode="Add";
	}

	if ($mode=="Add"){
//		$cd_userid = $_SESSION[admin_cd_userid];
	}

	if($ds_open==""){$ds_open="Y";}
	if($cd_category==""){$cd_category="1";}

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

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


	<section>
		<div class="top--nav--wrap">
			<div class="contents--inner">
				<div class="breadcrumbs--wrap">
					<span></span>
					<span>차량 판매하기</span>
					<span>차량 판매하기</span>
				</div>
			</div>
		</div>
	</section>

	<section class="mt60">
		<form id="frmForm" name="frmForm" method="post" action="proc.php" enctype="multipart/form-data">
		<input type="hidden" name="car_report" id="car_report" value="<?=$car_report?>"/>
		<input type="hidden" name="ds_cate" id="ds_cate" value="<?=$ds_cate?>"/>
		<input type="hidden" name="cd_car" id="cd_car" value="<?=$cd_car?>"/>
		<input type="hidden" name="mode" id="mode" value="<?=$mode?>"/>
		<input type="hidden" name="cd_userid" id="cd_userid" value="<?=$cd_userid?>"/>
		<input type="hidden" name="PageNo" id="PageNo" value="<?=$PageNo?>"/>
		<input type="hidden" name="upload_file_report_name" id="upload_file_report_name" value="<?=$upload_file_report_name?>"/>
		<input type="hidden" name="upload_file_report_back_name" id="upload_file_report_back_name" value="<?=$upload_file_report_back_name?>"/>
		<input type="hidden" name="upload_file_main_name" id="upload_file_report_name" value="<?=$upload_file_main_name?>"/>
		<input type="hidden" name="upload_file_list_name" id="upload_file_list_name" value="<?=$upload_file_list_name?>"/>
		<input type="hidden" name="cd_category" id="cd_category" value="<?=$cd_category?>"/>
		<div class="options--wrapper">
			<h2>옵션정보</h2>
			<div class="options--list">
			<?php
				$option_insert = true;
				include_once("../common/inc/inc_car_option.php");
			?>
			</div>
		</div>
		</form>
	</section>

	<div class="btn--wrapper car--btn--wrapper">
		<button type='button' class="next--btn" id='btn_write'>다음(옵션 입력)<i class="next--ic"></i></button>
	</div>

	<!-- loading -->
	<div class="loading_wrap hide">
		<?php include("../include/loading_dim.html") ?>
	</div>
	<!-- // loading -->
</main>

<script language="javascript" type="text/javascript">

	$(document).ready(function() {

		$("#btn_write").bind("click",function(){
			var custom_opts = {
				title : '',
				btn_close_show : false,
			}


			// var necessary_li = $("#car_option_list li[code='E0']").length;
			// //있을 경우에만
			// if(necessary_li > 0) {
			// 	var necessary_checked_length = $("#car_option_list li[code='E0'] input[type=checkbox]:checked").length;
			// 	if(necessary_checked_length < 1) {
          // fnCheckForm_normal("필수항목 중 최소 한개이상 선택하셔야 합니다.");
			// 		//alert("필수항목 중 최소 한개이상 선택하셔야 합니다.");
			// 		$("#car_option_list li[code='E0'] input[type=checkbox]").eq(0).focus();
			// 		return false;
			// 	}
			// }

		custom_opts.title = '정보를 등록하시겠습니까?';
		custom_modal_confirm(custom_opts, function(confirm) {
			if(confirm) {
				custom_modal_confirm_close();

				$(".loading_wrap").removeClass("hide");

				$("#btn_write").hide();
				var data = $("#frmForm").serialize();
				$.ajax({
					url : 'proc.php',
					type: 'POST',
					dataType : 'json',
					data: data,
					success: function(res) {
						$("#btn_write").show();

						custom_modal_confirm_close();

						$(".loading_wrap").addClass("hide");

						//세션 종료시 로그인 페이지로 이동
						if(res.CODE != "0000") {
							custom_opts.title = res.MSG;

							if(res.CODE == "4444") {
								window.location.href = res.DATAS.URL;
							}
							custom_modal_alert(custom_opts);
							return false;
						}
						link("sell_step3.php?mode=Step3");
					},
					error:function(request,status,error){
						$("#btn_write").show();

						$(".loading_wrap").addClass("hide");

						custom_modal_confirm_close();

						alert("code:"+request.status+"\n"+"message:"+request.responseText+"\n"+"error:"+error);
					}
				});

			}else {
				$("#btn_write").show();
				return false;
			}
		  });
		});

	});
</script>


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