<?php
	include $_SERVER['DOCUMENT_ROOT'].'/common/lib/comm.php';
	include $_SERVER['DOCUMENT_ROOT'].'/common/dealer_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">
		<ul class="location">
			<li><a href="/" class="home">홈</a></li>
			<li><span class="depth1">마이페이지</span>
				<ul class="sub_depth">
					<li><a href="#">마이페이지</a></li>
					<li><a href="#">입찰정보</a></li>
					<li><a href="#">차량정보</a></li>
					<li><a href="#">문의내역</a></li>
				</ul>
			</li>
			<li><span class="depth2">딜러</span></li>
		</ul>

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


<?
	$s_cd_dealer = $_SESSION['s_cd_dealer'];
	$s_cd_dealer_p = $_SESSION['s_cd_dealer_p'];
	$s_ds_type = $_SESSION['s_ds_type'];
	$s_ds_status_p = $_SESSION['s_ds_status_p'];

	if($s_ds_type == "D0"){	//딜러
		$sql_ds_type = " cd_dealer_p = '$s_cd_dealer' ";
	}else{	//딜러-관리자
		$sql_ds_type = " cd_dealer = '$s_cd_dealer' ";
	}

	$rq_ds_status = $_REQUEST['ds_status'];	//요청받은 상태값 : request ds_status	(naming request->rq, response->rs)

	if($rq_ds_status == "E0"){
		$nm_title = "입찰대기 상세";
	}else if($rq_ds_status == "F0"){
		$nm_title = "입찰중 상세";
	}else if($rq_ds_status == "Z0"){
		$nm_title = "낙찰 상세";
	}else if($rq_ds_status == "ZE"){
		$nm_title = "유찰 상세";
	}else if($rq_ds_status == "ZS"){
		$nm_title = "구매확정 상세";
	}

	$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('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
						, getRemainTime(".LIMIT_TIME_TENDER.", s.dt_approve, now()) as time_limit_tender
						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_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_area_user = $col[nm_area_user];
		$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_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];

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

	$sql ="SELECT *
		FROM car_history_master mst
		WHERE  cd_car='$cd_car' AND ds_delind='N' and ds_type = 'user'";
	$history_col=mysql_fetch_array(mysql_query($sql));

	$r000  		= $history_col["r000"];
	$r001  		= $history_col["r001"];
	$r002  		= $history_col["r002"];
	$r004  		= $history_col["r004"];
	$r005  		= $history_col["r005"];
	$r101  		= $history_col["r101"];
	$r102  		= $history_col["r102"];
	$r103  		= $history_col["r103"];
	$r104  		= $history_col["r104"];
	$r105  		= $history_col["r105"];
	$r106  		= $history_col["r106"];
	$r107  		= $history_col["r107"];
	$r108  		= $history_col["r108"];
	$r109  		= $history_col["r109"];
	$r401  		= $history_col["r401"];
	$r402  		= $history_col["r402"];
	$r403  		= $history_col["r403"];
	$r404  		= $history_col["r404"];
	$r405  		= $history_col["r405"];
	$r406_01  	= $history_col["r406_01"];
	$r407  		= $history_col["r407"];
	$r408_01  	= $history_col["r408_01"];
	$r409  		= $history_col["r409"];
	$r410_01  	= $history_col["r410_01"];
	$r201  		= $history_col["r201"];
	$r202  		= $history_col["r202"];
	$r203  		= $history_col["r203"];
	$r204  		= $history_col["r204"];
	$r205  		= $history_col["r205"];
	$r510  		= $history_col["r510"];
	$r511_01  	= $history_col["r511_01"];
	$r501  		= $history_col["r501"];
	$r502  		= $history_col["r502"];
	$r301  		= $history_col["r301"];
	$r302  		= $history_col["r302"];
	$r303  		= $history_col["r303"];
	$r601  		= $history_col["r601"];
	$r602  		= $history_col["r602"];
?>

		<h3><?=$nm_title?></h3>
		<div class="car_model">
			<? if($ds_status_sale == "E0" || $ds_status_sale == "F0"){ ?>
			<p class="fr">입찰 마감 시간 : <em><?=$time_limit_tender?></em></p>
			<? } ?>
		</div>
		<table class="tbl_h">
			<colgroup>
				<col width="16%">
				<col width="34%">
				<col width="16%">
				<col width="*">
			</colgroup>
			<!--tr>
				<th>이름</th>
				<td>홍**</td>
				<th>회원</th>
				<td>비회원</td>
			</tr>
			<tr>
				<th>연락처</th>
				<td>010-****-****</td>
				<th>아이디</th>
				<td>dkjslfslfskg;ls@naver.com</td>
			</tr>
			<tr>
				<th>주소</th>
				<td>서울마포구 서교동*****</td>
				<th>판매지역</th>
				<td>서울</td>
			</tr-->
			<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 colspan="3"><?=$nm_accident?>
		    &nbsp;<?=$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_area_user?>
				</td>
				<!-- 판매 희망지역 추가 -->
			</tr>
			<tr>
				<th>필수사진</th>
				<td colspan="3">
					<ul class="photo_list">
						<li>
							<!-- img src="<?=UPLOAD_PATH_CAR?>nm_file_main/ratio/<?=$nm_file_front?>" onclick="viewPhoto('<?=UPLOAD_PATH_CAR?>nm_file_main/ratio/<?=$nm_file_front?>')" -->
							<img data-sgallery="group1" data-full="<?=UPLOAD_PATH_CAR?>nm_file_main/ratio/<?=$nm_file_front?>" data-thumb="<?=UPLOAD_PATH_CAR?>nm_file_main/ratio/<?=$nm_file_front?>" src="<?=UPLOAD_PATH_CAR?>nm_file_main/ratio/<?=$nm_file_front?>" title="차량전면">
							<span>차량전면</span>
						</li>
						<li>
							<img data-sgallery="group1" data-full="<?=UPLOAD_PATH_CAR?>nm_file_main/ratio/<?=$nm_file_back?>" data-thumb="<?=UPLOAD_PATH_CAR?>nm_file_main/ratio/<?=$nm_file_back?>" src="<?=UPLOAD_PATH_CAR?>nm_file_main/ratio/<?=$nm_file_back?>" title="차량후면">
							<span>차량후면</span>
						</li>
						<li>
							<img data-sgallery="group1" data-full="<?=UPLOAD_PATH_CAR?>nm_file_main/ratio/<?=$nm_file_side1?>" data-thumb="<?=UPLOAD_PATH_CAR?>nm_file_main/ratio/<?=$nm_file_side1?>" src="<?=UPLOAD_PATH_CAR?>nm_file_main/ratio/<?=$nm_file_side1?>" title="운전석 측면">
							<span>운전석 측면</span>
						</li>
						<li>
							<img data-sgallery="group1" data-full="<?=UPLOAD_PATH_CAR?>nm_file_main/ratio/<?=$nm_file_side2?>" data-thumb="<?=UPLOAD_PATH_CAR?>nm_file_main/ratio/<?=$nm_file_side2?>" src="<?=UPLOAD_PATH_CAR?>nm_file_main/ratio/<?=$nm_file_side2?>" title="조수석 측면">
							<span>조수석 측면</span>
						</li>
						<li>
							<img data-sgallery="group1" data-full="<?=UPLOAD_PATH_CAR?>nm_file_main/ratio/<?=$nm_file_dashboard?>" data-thumb="<?=UPLOAD_PATH_CAR?>nm_file_main/ratio/<?=$nm_file_dashboard?>" src="<?=UPLOAD_PATH_CAR?>nm_file_main/ratio/<?=$nm_file_dashboard?>" title="계기판">
							<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 data-sgallery="group2" data-full="<?=UPLOAD_PATH_CAR?><?=$imgs[cd_car]?>_detail/<?=$imgs[nm_file]?>" data-thumb="<?=UPLOAD_PATH_CAR?><?=$imgs[cd_car]?>_detail/<?=$imgs[nm_file]?>" src="<?=UPLOAD_PATH_CAR?><?=$imgs[cd_car]?>_detail/<?=$imgs[nm_file]?>"></li>
					<?
							}
						}else{
					?>
					<?
						}
					?>
					</ul>
				</td>
			</tr>
			<tr>
				<th>담당자코멘트</th>
				<td colspan="3"><?=$nm_guide?></td>
			</tr>
		</table>

		<h3>사고이력정보</h3>
		<?
		/*
		<table class="tbl_h">
			<colgroup>
				<col width="16%">
				<col width="*">
			</colgroup>
			<tr>
				<th>차량번호 변경</th>
				<td><?=$nm_act_chgno?> 회</td>
			</tr>
			<tr>
				<th>소유자 변경</th>
				<td><?=$nm_act_chgnm?> 회</td>
			</tr>
			<tr>
				<th>자동차 보험 특수 사고</th>
				<td>전손 : <?=$nm_act_s1?>회 / 침수전손 : <?=$nm_act_s2?>회 / 침수분손 : <?=$nm_act_s3?>회 / 도난 : <?=$nm_act_s4?>회</td>
			</tr>
			<tr>
				<th>보험사고 (내차피해)</th>
				<td><?=$nm_act_my?> 회(<?=$nm_act_my_amt?> 원)</td>
			</tr>
			<tr>
				<th>보험사고 (타차가해)</th>
				<td><?=$nm_act_other?> 회(<?=$nm_act_other_amt?> 원)</td>
			</tr>
			<!--tr>
				<th>사고이력 조회일</th>
				<td>2018-12-05 </td>
			</tr-->
		</table>
		*/
		?>
		<table class="tbl_h">
			<colgroup>
				<col width="16%">
				<col width="*">
			</colgroup>
			<tr>
				<th>차량번호 변경</th>
				<td><?=number_format($r201)?> 회</td>
			</tr>
			<tr>
				<th>소유자 변경</th>
				<td><?=number_format($r204)?> 회</td>
			</tr>
			<tr>
				<th>자동차 보험 특수 사고</th>
				<td>전손 : <?=number_format($r405)?>회 / 침수전(분)손 : <?=number_format($r407)?>회 / 도난 : <?=number_format($r409)?>회</td>
			</tr>
			<tr>
				<th>보험사고 (내차피해)</th>
				<td><?=number_format($r401)?> 회(<?=number_format($r402)?> 원)</td>
			</tr>
			<tr>
				<th>보험사고 (타차가해)</th>
				<td><?=number_format($r403)?> 회(<?=number_format($r404)?> 원)</td>
			</tr>
			<!--tr>
				<th>사고이력 조회일</th>
				<td>2018-12-05 </td>
			</tr-->
		</table>

		<div class="btn_right">
			<a href="#" class="button" onclick="openLayer('car'); return false;">사고이력 정보 조회 보기</a>
		</div>

		<!-- layer popup -->
		<div class="layer_popup car_popup">
			<h3>중고차 보험처리 이력정보 보고서</h3>
			<p class="close">레이어팝업닫기</p>
			<?
				//차량 보험처리 이력 정보
				include_once($_SERVER['DOCUMENT_ROOT'].'/common/inc/inc_car_history.php');
			?>
		</div>
		<!-- // layer popup -->
<?
	// $sql ="select count(*) cnt, max(case when ".$sql_ds_type." then nm_price else 0 end) nm_price_max from tender_master where cd_sale = $cd_sale ";

	$sql ="select count(*) cnt
					, max(case when ".$sql_ds_type." then cast(nm_price as UNSIGNED) else 0 end) nm_price_max
					, min(cast(nm_price as UNSIGNED)) min_price
					, avg(cast(nm_price as UNSIGNED)) avg_price
					, max(cast(nm_price as UNSIGNED)) max_price
				from tender_master where cd_sale = $cd_sale ";
	// echo $sql;
	$col1=mysql_fetch_array(mysql_query($sql));

	// $col1=mysql_fetch_array(mysql_query($sql));
?>

<?
	#유찰의 경우만 visible
	if($rq_ds_status == "ZE") {
?>
		<!-- 2020-01-23 유찰상세추가 -->
		<div class="price_info">
			<ul class="price_list">
				<li><strong>최고가 입찰금액 : <?=number_format($col1[max_price])?>만원</strong></li>
				<li><strong>최저가 입찰금액 : <?=number_format($col1[min_price])?>만원</strong></li>
				<li>평균 입찰금액 : <?=number_format($col1[avg_price])?>만원</li>
				<li>입찰자 수 : <?=$col1[cnt]?>곳</li>
			</ul>
			<ul class="ranking">
			<?
				$col2_cnt = 1;
				$col2_ord = 65;
				$sql2 =mysql_query("select nm_price
							,(select nm_company from dealer_master a where a.cd_dealer = b.cd_dealer_p limit 1) as nm_company
						from tender_master b where cd_sale = $cd_sale
							order by cast(nm_price as UNSIGNED) desc limit 3");
				while($col2 = mysql_fetch_array($sql2)) {
			?>
				<li><span class="rank"><?=$col2_cnt?>위</span> <?=number_format($col2[nm_price])?>만원 / <?=chr($col2_ord)?>상사<?//$col2[nm_company]?></li>
			<?
					$col2_ord++;
					$col2_cnt++;
				}
			?>
				<!-- <li><span class="rank">1위</span> 3,000만원 / A상사</li>
				<li><span class="rank">2위</span> 2,850만원 / B상사</li>
				<li><span class="rank">3위</span> 2,500만원 / C상사</li> -->
			</ul>
		</div>
<?
		if($col1[nm_price_max]>0) {
?>
		<div class="bidding_board">
			<p class="my_price">나의 입찰금액은 <strong><?=number_format($col1[nm_price_max])?></strong>만원입니다.</p>
		</div>
<?
		}
?>

		<!-- // 2020-01-23 유찰상세추가 -->
<?
	}else {
?>
		<div class="bidding_board<? if($col1[nm_price_max]>0) { ?> ty2<? } ?>">

			<dl>
				<dt>입찰 진행 중</dt>
				<dd><strong><?=$col1[cnt]?></strong>명의 딜러가 입찰하였습니다.</dd>
			</dl>
<?
		if($col1[nm_price_max]>0) {
?>
			<p>나의 입찰가는 <strong><?=$col1[nm_price_max]?></strong>만원입니다.</p>
<?
		}
?>
		</div>

<?
//select count(*) cnt_tender, sum(case when cd_dealer = '55' then 1 else 0 end) cnt_tender_dealer from tender_master where ds_delind ='N' and cd_sale = '73' and cd_dealer_p = '52'
//	$cd_tender = @mysql_result(mysql_query("select cd_tender from tender_master where ds_delind ='N' and cd_sale = '$cd_sale' and cd_dealer = '$s_cd_dealer' "),0,0);
	$cd_tender = mysql_fetch_array(mysql_query("select count(*) cnt_tender, sum(case when cd_dealer = '$s_cd_dealer' then 1 else 0 end) cnt_tender_dealer from tender_master where ds_delind ='N' and cd_sale = '$cd_sale' and cd_dealer_p = '$s_cd_dealer_p' "));

		//입찰하기 : 입찰대기건/부관리자/현재미입찰건(부관리자본인)
//		if($rq_ds_status == "E0" && $s_ds_type == "D1" && empty($cd_tender) && $time_limit_tender != "0분"){	//딜러-관리자
		//입찰하기 : 입찰대기건/부관리자/소속딜러입찰건1건이하일경우만(2건이상일경우제한)/현재미입찰건(부관리자본인)/소속총괄관리자 관리자에게 승인 받은 경우
		if($rq_ds_status == "E0" && $s_ds_type == "D1" && ($cd_tender[cnt_tender] < 2 && $cd_tender[cnt_tender_dealer] == 0) && $time_limit_tender != "0분" && $s_ds_status_p == "Z0"){	//딜러-관리자
?>

		<div class="btn_right">
			<a href="#" class="button" onclick="openLayer('price'); return false;">입찰하기</a>
			<!-- a href="#" class="button">목록가기</a -->
		</div>

		<!-- layer_popup -->
		<div class="layer_popup price_popup">
			<div class="popup_wrap">
				<p class="msg">
					내 입찰금액은<br>
					<input type="text" class="inp_txt" style="width:355px;" name="nm_price_pop" id="nm_price_pop"> 만원입니다.
					<span class="sub_txt">(※ 입력 예시 : 1500만원일 경우 1500입력,  500만원일 경우 500입력)</span>
				</p>
				<div class="btn_center">
					<a href="#" class="button" id="btn_write">입찰하기</a>
				</div>
				<!-- p class="msg2">입찰금액은<br><strong>2500</strong>만원입니다.</p>
				<div class="btn_center">
					<a href="#" class="button">확인</a>
					<a href="#" class="button gray" onclick="closeLayer('price'); return false;">취소</a>
				</div -->
			</div>
			<div class="close">레이어팝업 닫기</div>
		</div>
		<!-- // layer_popup -->
<? } ?>


<?
		//입찰금액 수정은 딱히 정해 진게 없어서 정의 후 작업
		/*
		*	딜러가 입찰한 내역이 있어야 하고
		*	현재 sale 상태가 입찰대기(E0)여야 하며
		*	수정 내역이 3번까지만 가능
		*	낙찰 마감일이 안지나야 가능
		*/
		$cd_tender_sql = "select cd_tender, nm_modify_cnt
							, (select ds_status from sale_master s where s.cd_sale = t.cd_sale) as sale_ds_status
								from tender_master t
									where t.ds_delind ='N'
										and t.cd_sale = '$cd_sale'
										and t.cd_dealer_p = '$s_cd_dealer_p'
										limit 1";
		// echo $cd_tender_sql;
		$cd_tender = mysql_fetch_array(mysql_query($cd_tender_sql));
		if($rq_ds_status == "F0" && $s_ds_type == "D1" && $cd_tender[sale_ds_status] == 'E0' && !empty($cd_tender[cd_tender]) && $cd_tender[nm_modify_cnt] < 3 && $time_limit_tender != "0분" && $s_ds_status_p == "Z0"){	//딜러-관리자
?>
<style>
.mod_price_popup{width:570px;}
.mod_price_popup .msg{padding:25px 30px 0;font-size:23px;line-height:45px;}
.mod_price_popup .msg .inp_txt{font-size:18px;color:#000;text-align:right;}
.mod_price_popup .msg strong{font-size:30px;color:#0496bb;}
.mod_price_popup .msg .sub_txt{display:block;font-size:13px;color:#b30303;}
.mod_price_popup .msg2{padding-top:40px;font-size:28px;line-height:45px;text-align:center;}
.mod_price_popup .msg2 strong{font-size:36px;color:#0496bb;vertical-align:bottom;}
.mod_price_popup .btn_center{margin-top:40px;}
</style>
		<div class="btn_right">
			<a href="#" class="button" onclick="openLayer('mod_price'); return false;">가격수정</a>
			<!-- a href="#" class="button">목록가기</a -->
		</div>

		<!-- layer_popup -->
		<div class="layer_popup mod_price_popup">
			<div class="popup_wrap">
				<p class="msg">
					내 입찰금액은<br>
					<input type="text" class="inp_txt" style="width:355px;" name="mod_nm_price_pop" id="mod_nm_price_pop"> 만원입니다.
					<span class="sub_txt">(※ 입력 예시 : 1500만원일 경우 1500입력,  500만원일 경우 500입력)</span>
				</p>
				<div class="btn_center">
					<a href="#" class="button" id="btn_mod_write">수정하기</a>
				</div>
				<!-- p class="msg2">입찰금액은<br><strong>2500</strong>만원입니다.</p>
				<div class="btn_center">
					<a href="#" class="button">확인</a>
					<a href="#" class="button gray" onclick="closeLayer('price'); return false;">취소</a>
				</div -->
			</div>
			<div class="close">레이어팝업 닫기</div>
		</div>
		<!-- // layer_popup -->
<? } ?>

<form id="frmForm" name="frmForm" method="post" action="./dealer_proc.php">
	<input type="hidden" name="mode" id="mode" value="Tender"/>
	<input type="hidden" name="cd_sale" id="cd_sale" value="<?=$cd_sale?>"/>
	<input type="hidden" name="nm_price" id="nm_price"/>
	<input type="hidden" name="ListPageNo" value="<?=$ListPageNo?>"/>
</form>
<script language="javascript" type="text/javascript">

	var ds_mode ="<?=$mode?>";

	$(document).ready(function() {

		$("#btn_write").bind("click",function(){
			var fieldlist = [["nm_price_pop","입찰금액"]]
			if (!fnCheckForm(fieldlist)){
				return false;
			}

			$("#nm_price").val($("#nm_price_pop").val());

			var c = confirm("처리하시겠습니까?");
			if(c){
				$("#frmForm").submit();
			}else{
				return false;
			}
		});

		$("#btn_mod_write").bind("click",function(){
			var fieldlist = [["mod_nm_price_pop","입찰 수정금액"]]
			if (!fnCheckForm(fieldlist)){
				return false;
			}

			$("#nm_price").val($("#mod_nm_price_pop").val());

			var c = confirm("처리하시겠습니까?");
			if(c){
				$("#mode").val("TenderModify");
				$("#frmForm").submit();
			}else{
				return false;
			}
		});

	});
</script>
<?
		}
?>

		<!-- 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 -->

	</div>

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

	function viewPhoto(arg1){

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

		openLayer('photo'); return false;

	}

</script>

	</section>
</section>

<script type="text/javascript" charset="utf-8" src="/js/jquery.sumogallery.js"></script>

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