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

?>
<? 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="/sell/sell_step1.php">내찰팔기</a></li>
					<li><a href="/mypage/sell_list.php">전체 입찰내역</a></li>
                      <li><a href="/mypage/sell_list_04.php">낙찰내역</a></li>
                      <li><a href="/mypage/sell_list_03.php">거래완료</a></li>
                    <li><a href="/mypage/sell_list_02.php">유찰내역</a></li>
					<li><a href="/mypage/sell_list_05.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> -->

<?
	$cd_sale = $_REQUEST["cd_sale"];

	$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('sale_master','ds_area',s.ds_area) as nm_area
						, 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_contract_date nm_contract_date_sale
						, 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)
						WHERE s.cd_sale='$cd_sale' ";

	$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];
		$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_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_contract_date_sale = $col[nm_contract_date_sale];

		$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_recommend_sale = $col[nm_recommend_sale];
		$nm_cont_return_sale = $col[nm_cont_return_sale];
		$time_limit_sell = $col[time_limit_sell];

		//보험처리
		$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];

/*
		$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("지정되지않은 요청입니다");
	}

?>

		<h3>차량기본정보</h3>
		<div class="car_model">
			<p class="fl"><?=$nm_brand." ".$nm_model." ".$nm_model_sub." ".$nm_grade?></p>
			<!--p class="fr">입찰 마감 시간 : <em><?=$time_limit_sell?></p-->
		</div>
		<table class="tbl_h">
			<colgroup>
				<col width="16%">
				<col width="34%">
				<col width="16%">
				<col width="*">
			</colgroup>
			<tr>
				<th>차량번호</th>
				<td><?=$nm_number?></td>
				<th>제조사</th>
				<td><?=$nm_brand?></td>
			</tr>
			<tr>
				<th>모델</th>
				<td><?=$nm_model?></td>
				<th>세부모델</th>
				<td><?=$nm_model_sub?></td>
			</tr>
			<tr>
				<th>등급</th>
				<td><?=$nm_grade?></td>
				<th>연식(최초등록일)</th>
				<td><?=$nm_regdate_yyyy."년 ".$nm_regdate_mm."월"?></td>
			</tr>
			<tr>
				<th>형식연도</th>
				<td><?=$nm_year?>년</td>
				<th>배기량</th>
				<td><?=$nm_cc?>cc</td>
			</tr>
			<tr>
				<th>변속기</th>
				<td><?=$nm_transmission?></td>
				<th>연료</th>
				<td><?=$nm_oil?></td>
			</tr>
			<tr>
				<th>색상</th>
				<td><?=$nm_color?></td>
				<th>주행거리</th>
				<td><?=$nm_mileage?>km</td>
			</tr>
			<tr>
				<th>사고유무</th>
				<td><?=$nm_accident?><?=($ds_accident == "A0") ? " - ".$nm_cont_accident : "" ?></td>
				<th>추천인</th>
				<td><?= ($nm_recommend_sale == "") ? "없음":$nm_recommend_sale ?></td>
			</tr>
			<tr>
				<th>옵션</th>
				<td colspan="3"><?=$nm_cont?></td>
			</tr>
            <tr>
				<th>거래확정일</th>
				<td colspan="3"><?=$nm_contract_date_sale?></td>
			</tr>
			<tr>
				<th>필수사진</th>
				<td colspan="3">
					<ul class="photo_list">
						<li>
							<img src="<?=UPLOAD_PATH_CAR?>nm_file_main/<?=$nm_file_front?>" onclick="viewPhoto('<?=UPLOAD_PATH_CAR?>nm_file_main/<?=$nm_file_front?>')">
							<span>차량전면</span>
						</li>
						<li>
							<img src="<?=UPLOAD_PATH_CAR?>nm_file_main/<?=$nm_file_back?>" onclick="viewPhoto('<?=UPLOAD_PATH_CAR?>nm_file_main/<?=$nm_file_back?>')">
							<span>차량후면</span>
						</li>
						<li>
							<img src="<?=UPLOAD_PATH_CAR?>nm_file_main/<?=$nm_file_side1?>" onclick="viewPhoto('<?=UPLOAD_PATH_CAR?>nm_file_main/<?=$nm_file_side1?>')">
							<span>운전석 측면</span>
						</li>
						<li>
							<img src="<?=UPLOAD_PATH_CAR?>nm_file_main/<?=$nm_file_side2?>" onclick="viewPhoto('<?=UPLOAD_PATH_CAR?>nm_file_main/<?=$nm_file_side2?>')">
							<span>조수석 측면</span>
						</li>
						<li>
							<img src="<?=UPLOAD_PATH_CAR?>nm_file_main/<?=$nm_file_dashboard?>" onclick="viewPhoto('<?=UPLOAD_PATH_CAR?>nm_file_main/<?=$nm_file_dashboard?>')">
							<span>계기판</span>
						</li>
					</ul>
				</td>
			</tr>
			<tr>
				<th>추가사진</th>
				<td colspan="3">
					<ul class="photo_list">
					<?
						if(!empty($col[cd_car])){
							$r = mysql_query("SELECT * FROM car_file WHERE cd_car = '$cd_car' and ds_type='' and ds_delind='N' Order by no_sort asc ,  cd_car ASC ");
							$i=1;
							while($imgs = mysql_fetch_array($r)) {
					?>
						<li><img src="<?=UPLOAD_PATH_CAR?><?=$imgs[cd_car]?>_detail/<?=$imgs[nm_file]?>" onclick="viewPhoto('<?=UPLOAD_PATH_CAR?><?=$imgs[cd_car]?>_detail/<?=$imgs[nm_file]?>')"></li>
					<?
							}
						}else{
					?>
					<?
						}
					?>
					</ul>
				</td>
			</tr>
		</table>

<?
	$cd_sale = $_REQUEST["cd_sale"];

	$sql = "SELECT
				t.*
				, d.nm_name nm_name_dealer_p
				, d.nm_zip nm_zip_dealer_p
				, d.nm_addr nm_addr_dealer_p
				, d.nm_addr_sub nm_addr_sub_dealer_p
				, d.nm_area nm_area_dealer_p
				, p.nm_name nm_name_dealer
				, p.nm_hp_01+'-'+p.nm_hp_02+'-'+p.nm_hp_03 nm_hp_dealer
				, p.nm_file nm_file_dealer
				, report.cd_dealer_p_min
				, report.cd_dealer_p_max
				, report.nm_price_min
				, report.nm_price_max
				, report.nm_price_avg
				, report.nm_name_min
				, report.nm_name_max
				, report.cnt
				, s.nm_price_final
				, s.nm_score_postscript
				, s.nm_cont_postscript
			FROM tender_master t
				inner join dealer_master d
				on (t.cd_dealer_p = d.cd_dealer
					and t.cd_sale = '$cd_sale'
					and t.ds_delind = 'N'
					and t.ds_status = 'Z0'
				)
				inner join dealer_master p
				on (t.cd_dealer = p.cd_dealer
				)
				inner join (
					select
					ff.cd_sale
					, ff.cd_dealer_p_min
					, ff.cd_dealer_p_max
					, ff.nm_price_min
					, ff.nm_price_max
					, ff.nm_price_avg
					, ff.cnt
					, d1.nm_name nm_name_min
					, d2.nm_name nm_name_max
					from (
						select
							max(cc.cd_sale) cd_sale
							, max(cc.cd_dealer_p_min) cd_dealer_p_min
							, max(cc.cd_dealer_p_max) cd_dealer_p_max
							, max(cc.nm_price_min) nm_price_min
							, max(cc.nm_price_max) nm_price_max
							, max(cc.nm_price_avg) nm_price_avg
							, max(cc.cnt) cnt
						from (
							select
								aa.cd_sale
								, case when aa.nm_price = bb.nm_price_min then aa.cd_dealer_p else 0 end cd_dealer_p_min
								, case when aa.nm_price = bb.nm_price_max then aa.cd_dealer_p else 0 end cd_dealer_p_max
								, bb.nm_price_min
								, bb.nm_price_max
								, bb.nm_price_avg
								, bb.cnt
							from (select * from tender_master where cd_sale = '$cd_sale' and ds_delind = 'N') aa
							, (
							select
								min(nm_price) nm_price_min
								, max(nm_price) nm_price_max
								, avg(nm_price) nm_price_avg
								, count(*) cnt
							from tender_master
							where cd_sale = '$cd_sale' and ds_delind = 'N'
							) bb
						) cc
					) ff
					inner join dealer_master d1
					on (ff.cd_dealer_p_min = d1.cd_dealer)
					inner join dealer_master d2
					on (ff.cd_dealer_p_max = d2.cd_dealer)
				) report
				on (t.cd_sale = report.cd_sale
				)
				inner join sale_master s
				on (t.cd_sale = s.cd_sale
				)
				";

	$col=mysql_fetch_array(mysql_query($sql));
	if (!empty($col[cd_sale])){

		$cd_sale = $col[cd_sale];
		$nm_price = $col[nm_price];

		$nm_name_dealer_p = $col[nm_name_dealer_p];
		$nm_zip_dealer_p = $col[nm_zip_dealer_p];
		$nm_addr_dealer_p = $col[nm_addr_dealer_p];
		$nm_addr_sub_dealer_p = $col[nm_addr_sub_dealer_p];
		$nm_area_dealer_p = $col[nm_area_dealer_p];
		$nm_name_dealer = $col[nm_name_dealer];
		$nm_hp_dealer = $col[nm_hp_dealer];
		$nm_file_dealer = $col[nm_file_dealer];
		$cd_dealer_p_min = $col[cd_dealer_p_min];
		$cd_dealer_p_max = $col[cd_dealer_p_max];
		$nm_price_min = $col[nm_price_min];
		$nm_price_max = $col[nm_price_max];
		$nm_price_avg = $col[nm_price_avg];
		$nm_name_min = $col[nm_name_min];
		$nm_name_max = $col[nm_name_max];
		$cnt = $col[cnt];

		$nm_price_final = $col[nm_price_final];
		$nm_score_postscript = $col[nm_score_postscript];
		$nm_cont_postscript = $col[nm_cont_postscript];

/*
		$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("지정되지않은 요청입니다");
	}

?>

		<h3>낙찰업체</h3>
		<div class="tender_business">
			<dl class="info">
				<dt><?=$nm_name_dealer_p?></dt>
				<dd class="thumb" style="background-image:url('<?=UPLOAD_PATH?>dealer/nm_file/<?=$nm_file_dealer?>');background-size:cover;"></dd>
				<dd>약속드립니다.<br>정직하게 일하겠습니다.</dd>
				<dd class="price">
					<span>참여업체 : <?=$cnt?></span>
					<span>평균견적 : <?=$nm_price_avg?> 만원</span>
					<span>낙찰가 <em><?=$nm_price_final?> 만원</em></span>
					<!--a href="#" class="button td_btn ty2">딜러 정보 보기</a-->
				</dd>
			</dl>

<form name="frmForm" id="frmForm" method="post" action="dealer_proc.php">
	<input type="hidden" name="mode" id="mode" value="WritePostscript">
	<input type="hidden" name="cd_sale" id="cd_sale" value="<?=$cd_sale?>">
	<input type="hidden" name="nm_contract_date_year" id="nm_contract_date_year" value="<?=$nm_contract_date_year?>">
	<input type="hidden" name="nm_contract_date_month" id="nm_contract_date_month" value="<?=$nm_contract_date_month?>">
			<div class="review_write">
				<p class="customer_grade">
					<label for="customer_score">고객만족도</label>
					<span id="customer_score">
						<select name="nm_score_postscript" id="nm_score_postscript" class="select" style="width:130px;">
						</select>
					</span>
					<em>점</em>
				</p>
				<p><textarea cols="90" rows="8" name="nm_cont_postscript" id="nm_cont_postscript"><?=$nm_cont_postscript?></textarea></p>
			</div>
</form>

		</div>

		<div class="btn_center">
			<a href="#" class="button" id="btn_write">후기쓰기</a>
      <a href="./sell_list_03.php?PageNo=<?=$ListPageNo?>&nm_contract_date_year=<?=$nm_contract_date_year?>&nm_contract_date_month=<?=$nm_contract_date_month?>" class="button">목록가기</a>
		</div>

    <!-- <div class="btn_right">


		</div> -->

		<!-- layer popup3 -->
		<div class="layer_popup photo_popup">
			<div class="popup_wrap">
				<img src="/img/sell/ic_car_photo1.png" id="photoBig">
			</div>
			<div class="close" onclick="closeLayer('photo');">레이어팝업 닫기</div>
		</div>
		<!-- // layer popup3 -->

	</section>
</section>

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

	function viewPhoto(arg1){

		$("#photoBig").attr("src", arg1);

		openLayer('photo'); return false;

	}

    $(document).ready(function() {

        setCodeSelect("listcode","nm_score_postscript", "sale_master","nm_score_postscript","<?=$nm_score_postscript?>","선택하세요","");

        $("#btn_write").bind("click",function(){

            var fieldlist = [["nm_score_postscript","고객만족도"],["nm_cont_postscript","내용"]]

            if (!fnCheckForm(fieldlist)){
                return false;
            }

			var c=confirm("정보를 등록하시겠습니까?");
			if(c){
				$("#btn_write").hide();
				$("#frmForm").submit();
			}else{
				$("#btn_write").show();
				return false;
			}

		});
    });

</script>

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