<?php
	include $_SERVER['DOCUMENT_ROOT'].'/common/lib/comm.php';
	include $_SERVER['DOCUMENT_ROOT'].'/common/user_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_06.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_user = $_SESSION['s_cd_user'];

	$sql ="SELECT
				*
				FROM member_master
				WHERE cd_user='$cd_user' AND ds_delind='N'";

	$mode = "Add";

	$col=mysql_fetch_array(mysql_query($sql));
	if (!empty($col[cd_user])){
		$cd_user = $col[cd_user];
		$cd_userid = $col[cd_userid];
		$nm_email = $col[nm_email];
		$nm_pass = $col[nm_pass];
		$nm_join = $col[nm_join];
		$ds_type = $col[ds_type];
		$ds_level = $col[ds_level];
		$nm_birth = $col[nm_birth];
		$nm_name = $col[nm_name];
		$nm_company = $col[nm_company];
		$nm_hp = $col[nm_hp];
		$nm_hp_01 = $col[nm_hp_01];
		$nm_hp_02 = $col[nm_hp_02];
		$nm_hp_03 = $col[nm_hp_03];
		$nm_tel = $col[nm_tel];
		$nm_tel_01 = $col[nm_tel_01];
		$nm_tel_02 = $col[nm_tel_02];
		$nm_tel_03 = $col[nm_tel_03];
		$nm_fax = $col[nm_fax];
		$nm_fax_01 = $col[nm_fax_01];
		$nm_fax_02 = $col[nm_fax_02];
		$nm_fax_03 = $col[nm_fax_03];
		$nm_zip = $col[nm_zip];
		$nm_addr = $col[nm_addr];
		$nm_addr_sub = $col[nm_addr_sub];
		$ds_area = $col[ds_area];
		$ds_area_sub = $col[ds_area_sub];
		$nm_etc_01 = $col[nm_etc_01];
		$nm_etc_02 = $col[nm_etc_02];
		$nm_etc_03 = $col[nm_etc_03];
		$nm_etc_04 = $col[nm_etc_04];
		$nm_etc_05 = $col[nm_etc_05];
		$ds_agree1 = $col[ds_agree1];
		$ds_agree2 = $col[ds_agree2];
		$ds_agree3 = $col[ds_agree3];
		$ds_agree4 = $col[ds_agree4];
		$ds_agree5 = $col[ds_agree5];
		$ds_status = $col[ds_status];
		$ds_status_agree = $col[ds_status_agree];
		$dt_insert = $col[dt_insert];
		$nm_insert = $col[nm_insert];
		$dt_update = $col[dt_update];
		$nm_update = $col[nm_update];
		$dt_delind = $col[dt_delind];
		$nm_delind = $col[nm_delind];
		$ds_delind = $col[ds_delind];
/*
		$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];
*/
		$mode = "Update";
	}else{
		$ds_level = "1";
	}

?>

		<div class="tit_wrap">
			<h3>회원정보</h3>
			<a href="modify.php" class="button">정보수정</a>
		</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><?=$nm_name?></td>
				<th>아이디</th>
				<td><?=$nm_email?></td>
			</tr>
			<tr>
				<th>회원가입일</th>
				<td><?=$dt_insert?></td>
				<th>연락처</th>
				<td><?=$nm_hp?></td>
			</tr>
			<!--tr>
				<th>주소</th>
				<td colspan="3">서울 마포구 서교동</td>
			</tr-->
		</table>

		<div class="tit_wrap">
			<h3>입찰내역</h3>
			<a href="sell_list.php" class="button">+더보기</a>
		</div>
		<table class="tbl_v">
			<colgroup>
				<col width="7%">
				<col width="*">
				<col width="10%">
				<col width="10%">
				<col width="15%">
				<col width="15%">
			</colgroup>
			<thead>
			<tr>
				<th>번호</th>
				<th>차종</th>
				<th>년식</th>
				<th>지역</th>
				<th>판매일</th>
				<th>처리상태</th>
			</tr>
			<!--colgroup>
				<col width="7%">
				<col width="20%">
				<col width="16%">
				<col width="*">
				<col width="15%">
				<col width="15%">
			</colgroup>
			<thead>
			<tr>
				<th>번호</th>
				<th>매입자</th>
				<th>판매금액</th>
				<th>차종</th>
				<th>판매일</th>
				<th>처리상태</th>
			</tr-->
			</thead>
			<tbody>
<?

	$cd_user = $_SESSION['s_cd_user'];

	$PageNo = $_REQUEST['pageno'];
	$PageSize = $_REQUEST['PageSize'];
	if (empty($PageNo)) {$PageNo=1;}else{$PageNo=$PageNo;}
	if (empty($PageSize)) {
		$PageSize=8; //목록개수설정
	}else{$PageSize=$PageSize;}

	$pagestartpoint=($PageNo-1)*$PageSize;
	$sql = "where s.ds_delind='N'";

	$sql = $sql. "	and s.cd_user='$cd_user' ";

	$searchtype = $_REQUEST['searchtype'];
	$searchword = $_REQUEST['searchword'];
	$ds_usertype = $_REQUEST['ds_usertype'];
	$ds_status = 'Z0';

	$ds_type = "A0";	//A0 : 매입
	$sql = $sql. "	and s.ds_type = '$ds_type' ";

	if($searchword != ""){
		if($searchtype=="" || $searchtype==null){
			$sql = $sql. "	and (s.nm_name like '$searchword%' or a.nm_number like '$searchword%') ";
		}else{
			$sql = $sql. "	and $searchtype like '$searchword%'";
		}
	}

	if($ds_usertype != ""){
		$sql = $sql. "	and s.ds_usertype = '$ds_usertype'";
	}

	$sql = $sql. "	and s.ds_status in ('B0','C0','D0','E0','F0','G0','Z0')";

//	$sql = $sql. "	and s.dt_approve >=  DATE_ADD(now(), INTERVAL '-".LIMIT_TIME_SELL."' HOUR) ";

	$totalrows = @mysql_result(mysql_query("select count(*) from sale_master s inner join car_master a on (	s.cd_car = a.cd_car ) $sql"),0,0);

$orderby = "order by s.dt_insert desc";

if($totalrows>0) {

$r = mysql_query("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_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('member_master','ds_area',s.ds_area) as nm_area
						, getCode('sale_master','ds_status',s.ds_status) as nm_status
						, s.cd_sale
						, s.nm_name nm_name_sale
						, s.nm_price nm_price_sale
						, s.ds_status ds_status_sale
						, case when s.ds_status in ('B0','C0') then '미승인' when s.ds_status in ('D0') then '반려' when s.ds_status in ('E0','F0') then '입찰중' when s.ds_status in ('G0') then '입찰마감' when s.ds_status in ('Z0') then '낙찰' when s.ds_status in ('ZS') then '구매확정' else '' end as nm_status_sale
						, case when a.nm_act_yn in ('Y') then '유'  else '무' end as nm_act_yn_name
						, 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)
							$sql $orderby LIMIT 0,2");

$i=1;
while($col = mysql_fetch_array($r)) {

	$tmpNum =$totalrows-($PageSize*($PageNo-1));
	$no = ($tmpNum - $i)+1;

?>

			<tr onclick="location.href='./sell_view.php?list_url=<?=$list_url?>&cd_sale=<?=$col[cd_sale]?>&ds_status_sale=<?=$col[ds_status_sale]?>&ListPageNo=<?=$PageNo?>';" style="cursor:pointer;">
				<td><?=$no?></td>
				<td><?=$col[nm_brand]." ".$col[nm_model]?></td>
				<td><?=$col[ds_year]?>년</td>
				<td><?=$col[nm_area]?></td>
				<td><?=$col[dt_insert]?></td>
				<td><? if($col[time_limit_sell]=="0분" && ($col[ds_status_sale] == "E0" || $col[ds_status_sale] == "F0")){ ?>거래마감<? }else{ ?><?=$col[nm_status_sale]?><? } ?></td>
			</tr>
			<!--tr onclick="location.href='./sell_view.php?list_url=<?=$list_url?>&cd_sale=<?=$col[cd_sale]?>&ds_status_sale=<?=$col[ds_status_sale]?>&ListPageNo=<?=$PageNo?>';" style="cursor:pointer;">
				<td><?=$no?></td>
				<td><?=$col[nm_name_sale]?></td>
				<td><?=$col[nm_price_sale]?></td>
				<td><?=$col[nm_brand]." ".$col[nm_model]?></td>
				<td><?=$col[dt_insert]?></td>
				<td><?=$col[nm_status_sale]?></td>
			</tr-->
<?
	$i++;
}
}else{
?>
			<tr>
				<td colspan="6">등록된 정보가 없습니다.</td>
			</tr>
<?
}
?>
			</tr>
			</tbody>
		</table>

		<div class="tit_wrap">
			<h3>문의내역</h3>
			<a href="/mypage/qna_list.php?cd_board=02&ds_kind=A" class="button">+더보기</a>
		</div>
		<table class="tbl_v">
			<colgroup>
				<col width="7%">
				<col width="*">
				<col width="15%">
				<col width="15%">
			</colgroup>
			<thead>
			<tr>
				<th>번호</th>
				<th>제목</th>
				<th>작성일</th>
				<th>답변여부</th>
			</tr>
			</thead>
			<tbody>
<?
	$cd_board = "02";
	$ds_kind = "A";
	$s_cd_user = $_SESSION['s_cd_user'];
	$s_cd_dealer = $_SESSION['s_cd_dealer'];

	if($ds_kind == "D"){
		$cd_user = $s_cd_dealer;
	}else{
		$cd_user = $s_cd_user;
	}

	if (empty($PageNo)) {$PageNo=1;}else{$PageNo=$PageNo;}
	$PageSize=2; //목록개수설정
	$pagestartpoint=($PageNo-1)*$PageSize;
	$sql = "where cd_board='$cd_board' and ds_delind='N'";
	$sql = $sql." and ds_kind='$ds_kind' ";
	$sql = $sql." and cd_user='$cd_user' ";

	if($searchword != ""){
		if($searchtype=="" || $searchtype==null){
			$sql = $sql. "	and (nm_title like '$searchword%' or nm_content like '$searchword%' or cd_userid like '$searchword%')";
		}else{
			$sql = $sql. "	and $searchtype like '$searchword%'";
		}
	}

	$totalrows = @mysql_result(mysql_query("select count(*) from board_master $sql"),0,0);

		if($totalrows>0) {
			$r = mysql_query("SELECT * FROM board_master  $sql ORDER BY ds_top desc, no_famally ASC, no_order ASC  LIMIT 0,2");
			$i=1;
			while($col = mysql_fetch_array($r)) {
				$date = strtotime ($col[dt_insert]);
				$view_date = strtotime ("-1 day",time());
				if($date >= $view_date) {
					$newicon = " <img src='".ADMIN_PATH."img/i_new.gif' style='margin-top:1px;' /> ";
				} else {
					$newicon = "";
				}

				if($col[no_step]>0){
					$padding = $col[no_step] * 8;
					$step = "<span style=\"padding-left:".$padding."px\"/>";
				}

				$tmpNum =$totalrows-($PageSize*($PageNo-1));
				$no = ($tmpNum - $i)+1;

?>

			<tr onclick="location.href='./qna_view.php?cd_board=<?=$cd_board?>&ds_kind=<?=$ds_kind?>&cd_seq=<?=$col[cd_seq]?>&PageNo=1';" style="cursor: pointer; cursor: hand;">
				<td><?=$no?></td>
				<? if($cd_board=="99"){?>
				<td width="10%" align="center" class="list03"><img src="<?=UPLOAD_PATH?>board/board_<?=$cd_board?>/<?=$col[nm_file]?>" width="50"/></td>
				<?}?>
				<td class="al"><?=text_cut($col[nm_title],50)?></td>
				<td><?=$col[dt_insert]?></td>
				<? if($cd_board=="02"){?>
				<td><?=($col[nm_reply] == "") ? "미답변" : "답변완료" ?></td>
				<?}?>
			</tr>
<?
	$i++;
}
}else{
?>
			<tr>
				<td colspan="4">등록된 정보가 없습니다.</td>
			</tr>
<?
}
?>
			</tbody>
		</table>
	</section>
</section>

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