<?
//DB연결
$dblink = SetConn($_conf_db["main_db"]);

//로그인확인
if(!$_SESSION[$_SITE["DOMAIN"]]["GUEST"]["NAME"]){//비회원로그인도 하지 않았다면
	include $_SERVER[DOCUMENT_ROOT] . "/module/member/auth.php";
}

//회원의 경우 회원아이디로 로그인 전이라면 세션 아이디로
if($_SESSION[$_SITE["DOMAIN"]]["MEMBER"]["ID"]){
	$tp = "1";
}else{
	$tp = "2";
}	
$arrList = getPreOrderList($_SESSION[$_SITE["DOMAIN"]]["SESSIONID"], $_SESSION[$_SITE["DOMAIN"]]["MEMBER"]["ID"],$tp);

//재고체크
checkPreOderStock($arrList);

//회원정보 가져오기
$arrMemInfo = getUserInfo($_SESSION[$_SITE["DOMAIN"]]["MEMBER"]["ID"]);
if(!$_SESSION[$_SITE["DOMAIN"]]["GUEST"]["MOBILE"]){
	$arrPhone = explode("-",$arrMemInfo["list"][0][phone]);
	$arrMobile = explode("-",$arrMemInfo["list"][0][mobile]);
	$arrZip = explode("-",$arrMemInfo["list"][0][zip]);
}else{
	$arrMobile = explode("-",$_SESSION[$_SITE["DOMAIN"]]["GUEST"]["MOBILE"]);
}

$nowPoint = getNowPoint($_SESSION[$_SITE["DOMAIN"]]["MEMBER"]["ID"]);
/*
$u_agent = $_SERVER['HTTP_USER_AGENT']; 
if(preg_match('/Chrome/i',$u_agent)) {
	$bname = 'Google Chrome'; $ub = "Chrome";
	jsMsg("결제를 지원하지 않는 브라우저입니다. 무통장입금을 제외한 결제는 Internet Explore에서 진행해주시기 바랍니다.");
	//jsGo("/main/main.php");
} 
*/

//DB해제
//SetDisConn($dblink);
?>
<!--
<script type="text/javascript">
var agt = navigator.userAgent.toLowerCase();
if (agt.indexOf("chrome") != -1){
	alert("결제를 지원하지 않는 브라우저입니다. Internet Explore에서 진행해주시기 바랍니다.");
	document.location.href ="/main/main.php";
	//return 'Chrome'; 
}
</script>
<script>document.domain="xn--2j1bpqq3r0zal45a5qcgzk.com";</script>
-->

	<div class="real-cont">
		<!--// content -->
		<div class="order-step step2">
			<h2><img src="../images/shop/order_step_tit2.png" alt="주문서작성/결제"></h2>
		</div>
		<div class="shop-table mgb20">
			<table>
				<colgroup>
					<col width="*">
					<col width="110">
					<col width="80">
					<col width="70">
					<col width="90">
					<col width="110">
				</colgroup>
				<thead>
					<tr>
						<th scope="col">상품명</th>
						<th scope="col">판매가</th>
						<th scope="col">적립금</th>
						<th scope="col">수량</th>
						<!-- <th scope="col">배송비</th> -->
						<th scope="col">합계/추가금</th>
					</tr>
				</thead>
				<tbody>
					<?
					$sold_chk = "";
					if($arrList["total"]>0){
						for($i=0;$i<$arrList["total"];$i++){
							$arrOpt1[$i] = explode("|",$arrList["list"][$i][opt_1]);
							$arrOpt2[$i] = explode("|",$arrList["list"][$i][opt_2]);
							$arrOpt3[$i] = explode("|",$arrList["list"][$i][opt_3]);
							$arrOpt4[$i] = explode("|",$arrList["list"][$i][opt_4]);
							$arrOpt5[$i] = explode("|",$arrList["list"][$i][opt_5]);
							$arrOptRel1[$i] = explode("|",$arrList["list"][$i][opt_rel_1]);

							//추가금액 계산
							$optionPrice = $arrOpt1[$i][1] + $arrOpt2[$i][1] + $arrOpt3[$i][1] + $arrOpt4[$i][1] + $arrOpt5[$i][1];

							//적립금계산
							if($arrList["list"][$i][point_unit]=="P"){
								$thisPoint = (($arrList["list"][$i][point]*($arrList["list"][$i][price]+$optionPrice))/100) * $arrList["list"][$i][qty];
							}else{
								$thisPoint = $arrList["list"][$i][point] * $arrList["list"][$i][qty];
							}

							//합계금액 계산
							$totalPrice += ($arrList["list"][$i][price]*$arrList["list"][$i][qty])+($optionPrice * $arrList["list"][$i][qty]);
					?>
					<tr>
						<td class="space-left">
							<div class="prod-info">
								<div class="img"><a href="<?=$_SERVER[PHP_SELF]?>?goPage=GoodDetail&idx=<?=$arrList["list"][$i][idx]?>"><img src="/uploaded/shop_good/<?=$arrList["list"][$i][idx]?>/<?=$arrList["list"][$i][image_s]?>" width="70" height="70" alt="" class="" /></a></div>
								<div class="info">
									<div class="tit"><a href="<?=$_SERVER[PHP_SELF]?>?goPage=GoodDetail&idx=<?=$arrList["list"][$i][idx]?>"><?=stripslashes($arrList["list"][$i][g_name])?></a></div>
									<div class="opt">
										<? if ($arrOptList["list"][$j][op_type] == "1") { ?>
										<?=$arrOpt1[$j][0]?"| ".$arrOpt1[$j][0]:""?><?=$arrOpt1[$j][1]?" +".number_format($arrOpt1[$j][1]):""?>
										<?=$arrOpt2[$j][0]?"| ".$arrOpt2[$j][0]:""?><?=$arrOpt2[$j][1]?" +".number_format($arrOpt2[$j][1]):""?>
										<?=$arrOpt3[$j][0]?"| ".$arrOpt3[$j][0]:""?><?=$arrOpt3[$j][1]?" +".number_format($arrOpt3[$j][1]):""?>
										<?=$arrOpt4[$j][0]?"| ".$arrOpt4[$j][0]:""?><?=$arrOpt4[$j][1]?" +".number_format($arrOpt4[$j][1]):""?>
										<?=$arrOpt5[$j][0]?"| ".$arrOpt5[$j][0]:""?><?=$arrOpt5[$j][1]?" +".number_format($arrOpt5[$j][1]):""?>
										<?}else{?>
										<?=$arrOpt1[$j][0]?>
										<?}?>
									</div>
								</div>
							</div>
						</td>
						<td><?=number_format($arrList["list"][$i][price]+$optionPrice)?>원</td>
						<td><?=number_format($thisPoint)?></td>
						<td><?=$arrList["list"][$i][qty]?></td>
						<!-- <td><?=number_format($shipPrice)?>원</td> -->
						<td><span class="price"><?=number_format(($arrList["list"][$i][price]*$arrList["list"][$i][qty])+($optionPrice * $arrList["list"][$i][qty]))?>원</span></td>
					</tr>
					<?	
						}
						//배송비 계산
						if($totalPrice < $_SITE["SHOP"]["SHIP"]["FREE_PRICE"]){
							$shipPrice = $_SITE["SHOP"]["SHIP"]["SHIP_PRICE"];
						}else{
							$shipPrice = 0;
						}
					}else{
					?>
					<tr height="100">
						<td colspan="8" align="center">장바구니가 비었습니다.</td>
					</tr>
					<?}
					//DB해제
					SetDisConn($dblink);
					?>	
				</tbody>
                </table>
            </div>
            
            <div class="total-price mgb30">총상품금액 : <?=number_format($totalPrice)?>원 + [배송비 : <?=number_format($shipPrice)?>원] = <strong><?=number_format($totalPrice+$shipPrice)?>원</strong></div>
            
<?
//주문번호 확인 => 주문번호가 있어야만 주문가능
if($arrList["list"][0][order_no] !=""){

//아래 결제대행사 파일에서 사용하는 변수
//주문요약 정보
if($arrList["total"]==1){
	$order_summary = $arrList["list"][0]["g_name"];
}else{
	$order_summary = $arrList["list"][0]["g_name"] . " 외 " . ($arrList["total"]-1). "건";
}

//결제금액
$payPrice = $totalPrice+$shipPrice;

//주문번호
$order_no = $arrList["list"][0][order_no];
?>

<form name="frmOrderForm" method="post">
<input type="hidden" name="order_no" value="<?=$order_no?>">
<!-- 상품권 결제시 필요한 항목 -->
<input type='hidden' name='PRODUCTNAME' value='<?=stripslashes($order_summary)?>'>
<input type='hidden' name='USERID' value='<?=$_SESSION[$_SITE["DOMAIN"]]["MEMBER"]["ID"]?>'>

            <div class="mgb30">
				<div class="order-info-title">
					<h3><img src="../images/shop/order_tit1.png" alt="결제"></h3>
				</div>
				<table class="order-info-table">
                <colgroup>
                    <col width="120px" />
					<col width="*" />
                </colgroup>
                <tr>
					<th>결제방식</th>
					<td>
						<?if(preg_match('/iphone|ipod|ios|blackberry|android|windows ce|lg|mot|samsung|sonyericsson|nokia/i', $_SERVER['HTTP_USER_AGENT'])){?>
						<?foreach($_SITE["SHOP"]["PAY_TYPE_MOBILE"] AS $key => $val){?>
						<input id="lbl<?=$key?>" type=radio name="pay_type" value="<?=$key?>" onclick="javascript:check_pay_type('<?=$key?>')"><label for="lbl<?=$key?>"><?=$val?></label> 
						<?}?>
						<?}else{?>
						<?foreach($_SITE["SHOP"]["PAY_TYPE"] AS $key => $val){?>
						<input id="lbl<?=$key?>" type=radio name="pay_type" value="<?=$key?>" onclick="javascript:check_pay_type('<?=$key?>')"><label for="lbl<?=$key?>"><?=$val?></label> 
						<?}?>
						<?}?>
						<!-- <input id="lblgifttest" type=radio name="pay_type" value="gifttest" onclick="javascript:check_pay_type('gifttest')"><label for="lblgifttest">test</label>  -->
					</td>
				</tr>
				<tr style="display:none">
					<th>쿠폰사용</th>
					<td><input type="text" name="coupon_price" id="coupon_price" size="12" value="0" class="input" style="text-align:right" onfocus="blur()" readonly>원 <a href="/module/shop/coupon_list.php" class="couponUsePop"><img src="/images/shop/coupon_btn.gif"></a></td>
					<input type="hidden" name="coupon_idx" id="coupon_idx" value="">
				</tr>
				<?
				if($_SESSION[$_SITE["DOMAIN"]]["MEMBER"]["ID"]){//회원 로그인 시에만

					// 포인트 사용제한 처리
					// 관리자 설정포인트보다 작을 경우
					if ($nowPoint[nowpoint]==0 || $nowPoint[nowpoint]<$_SITE["SHOP"]["POINT"]["LOW_ACCOUNT"]){
					//if ($nowPoint[nowpoint]==0 || $payPrice < 50000){
						$temp_point_use="disabled";
					}else{
						$temp_point_use="";
					}														
				?>	
				<tr>
					<th>현재 보유 적립금</th>
					<td><b><font color="#ea4343"><?=number_format($nowPoint[nowpoint])?>원</font></b></td>
				</tr>
				<tr>
					<th>적립금 사용</th>
					<td>
						적립금으로 결재할 금액 <select name="using_point"  id="using_point" <?=$temp_point_use?> onchange="calUsingPoint(this.form, this.value);" class="select">
							<? for($i=0; $i<=$nowPoint[nowpoint];$i+=1000) {?>
							<option value="<?=$i?>"><?=number_format($i)?></option>
							<?}?>
						<select>원 <!-- <a href="#"><img src="../images/shop/btn_use_point.gif" alt="포인트 사용" /></a> --><br />
						* 적림금의 경우 보유 적립금이 <span class="point"><?=number_format($_SITE["SHOP"]["POINT"]["LOW_ACCOUNT"])?>점</span> 이상 될 경우에만 사용가능합니다. (1,000점씩 사용가능합니다.)
						<!-- * 구입금액이 50,000원 이상 될 경우 사용 가능합니다. -->
					</td>
				</tr>
				<?} else {?>
				<input type="hidden" name="using_point" id="using_point" value="0">
				<?}?>
				<tr>
					<th>결제금액 산출</th>
					<td>상품구매금액(<?=number_format($totalPrice)?>원) + 배송비(<span id="ship_change"><?=number_format($shipPrice)?></span>원)</td>
				</tr>
				<tr>
					<th>결제하실 금액</th>
					<td class="prd_price" id="showPriceTotal"><font color="#ea4343"><strong id="tt_price"><?=number_format($payPrice)?>원</strong></font></td>
				</tr>
				<input type="hidden" id="hiddenMyPoint" name="hiddenMyPoint" value="<?=$nowPoint[nowpoint]?>">
				<input type="hidden" id="hiddenPayAmount" name="hiddenPayAmount" value="<?=$payPrice?>">
				<input type="hidden" id="hiddenPayAmount1" name="hiddenPayAmount1" value="<?=$totalPrice?>">
                </table>
				<table class="order-info-table" style="display:none" id="tblPayInfo">
					<colgroup>
					<col width="120px" />
					<col width="*" />
					</colgroup>
					<tbody>
					<tr>
						<th>입금계좌</th>
						<td>
						<select name="bank_type" class="select">
						<option value=''>== 선택 ==</option>
						<?
						foreach ($_SITE["SHOP"]["BANK"] AS $VAL){
						?>
						<option value="<?=$VAL?>"><?=$VAL?></option>
						<?}?>
						</select></td>
					</tr>
					<tr>
						<th>입금자명</th>
						<td><input type="text" class="input" name="bank_name" value="<?=$_SESSION[$_SITE["DOMAIN"]]["MEMBER"]["NAME"]?$_SESSION[$_SITE["DOMAIN"]]["MEMBER"]["NAME"]:$_SESSION[$_SITE["DOMAIN"]]["GUEST"]["NAME"]?>" maxlength="15" size="25" /></td>
					</tr>
					<tr>
						<th>입금예정일</th>
						<td><input type="text" class="input" name="bank_date" value="<?=date("Y-m-d",strtotime("+1 day"))?>" maxlength="10" size="10" onclick="popUpCalendar(this, bank_date, 'yyyy-mm-dd')" style="width:150px;"/></td>
					</tr>
				</tbody>
				</table>
            </div>
            
            
            <div class="mgb30 clearfix">
				<div class="fl" style="width:49%">
					<div class="order-info-title">
						<h3><img src="../images/shop/order_tit2.png" alt="주문하시는 분 정보"></h3>
					</div>
					<table class="order-info-table">
                    <colgroup>
						<col width="120">
						<col width="*">
					</colgroup>
                    <tr>
						<th>이름</th>
						<td><input type="text" class="input" name="order_name" size="15" value="<?=$_SESSION[$_SITE["DOMAIN"]]["MEMBER"]["NAME"]?$_SESSION[$_SITE["DOMAIN"]]["MEMBER"]["NAME"]:$_SESSION[$_SITE["DOMAIN"]]["GUEST"]["NAME"]?>" style="width:120px;"/></td>
					</tr>
					<tr>
						<th>이메일</th>
						<td><input type="text" class="input" name="order_email" size="25"value="<?=$_SESSION[$_SITE["DOMAIN"]]["GUEST"]["EMAIL"]?$_SESSION[$_SITE["DOMAIN"]]["GUEST"]["EMAIL"]:$arrMemInfo["list"][0][email]?>" style="width:70%;" /></td>
					</tr>
					<tr>
						<th>주소</th>
						<td>
							<div class="mgb4">
							<input type="text" name="order_zip" id="order_postcode" class="input" size="8"  value="<?=$arrMemInfo["list"][0][zip]?>" maxlength="8" style="width:60px;"/>
							<a href="javascript:execDaumPostcode(1);" class="btn-pack medium">우편번호검색</a>
							<!-- <a href="javascript:execDaumPostcode(1);"><img src="/images/member/btn_zip.gif" alt="우편번호검색" /></a><br /> -->
							</div>
							<div class="mgb4">
							<input type="text" name="order_address" id="order_address" class="input" size="32" value="<?=$arrMemInfo["list"][0][address]?>" style="width:95%;" /><br />
							</div>
							<div>
							<input type="text" name="order_address_ext" id="order_address2" class="input" size="32" value="<?=$arrMemInfo["list"][0][address_ext]?>" style="width:95%;" />
							</div>
						</td>
					</tr>
					<tr>
						<th>전화번호</th>
						<td>
						<input type="text" class="input" name="order_phone1" size="8" maxlength=4 value="<?=$arrPhone[0]?>" style="width:85px;"/> - 
						<input type="text" class="input" name="order_phone2" size="8" maxlength=4 value="<?=$arrPhone[1]?>" style="width:85px;"/> - 
						<input type="text" class="input" name="order_phone3" size="8 "maxlength=4 value="<?=$arrPhone[2]?>" style="width:85px;"/>
						</td>
					</tr>
					<tr>
						<th>휴대폰번호</th>
						<td>
						<input type="text" class="input" size="8" name="order_mobile1" maxlength=4 value="<?=$arrMobile[0]?>" style="width:85px;"/> - 
						<input type="text" class="input" size="8" name="order_mobile2" maxlength=4 value="<?=$arrMobile[1]?>" style="width:85px;"/> - 
						<input type="text" class="input" size="8" name="order_mobile3" maxlength=4 value="<?=$arrMobile[2]?>" style="width:85px;"/>
						</td>
					</tr>
                    </table>
				</div>

				<div class="fr" style="width:49%">
					<div class="order-info-title">
						<h3><img src="../images/shop/order_tit3.png" alt="받으시는 분 정보"></h3>
						<span class="chk"><input type="checkbox" name="idShipAssing" id="idShipAssing" onclick="shipInfoAssign(this.checked);"><label for="idShipAssing">주문자 정보와 동일</label></span>
					</div>
					<table class="order-info-table">
                    <colgroup>
						<col width="120">
						<col width="*">
					</colgroup>
                    <tr>
						<th>이름</th>
						<td><input type="text" class="input" name="ship_name" size="15" style="width:120px;"></td>
					</tr>
					<tr>
						<th>주소</th>
						<td>
							<div class="mgb4">
							<input type="text" name="ship_zip" id="ship_postcode" class="input" size="8"  value="" maxlength="8" style="width:60px;"/>
							<a href="javascript:execDaumPostcode(2);" class="btn-pack medium">우편번호검색</a>
							<!-- <a href="javascript:execDaumPostcode(2);"><img src="/images/member/btn_zip.gif" alt="우편번호검색" /></a><br /> -->
							</div>
							<div class="mgb4">
							<input type="text" name="ship_address" id="ship_address" class="input" size="32" value="" style="width:95%;" /><br />
							</div>
							<div>
							<input type="text" name="ship_address_ext" id="ship_address2" class="input" size="32" value="" style="width:95%;" />
							</div>
						</td>
					</tr>
					<tr>
						<th>전화번호</th>
						<td>
						<input type="text" class="input" size="8" name="ship_phone1" maxlength=4 style="width:85px;"/> - 
						<input type="text" class="input" size="8" name="ship_phone2" maxlength=4 style="width:85px;"/> - 
						<input type="text" class="input" size="8" name="ship_phone3" maxlength=4 style="width:85px;"/>
						</td>
					</tr>
					<tr>
						<th>휴대폰번호</th>
						<td>
						<input type="text" class="input" size="8" name="ship_mobile1" maxlength=4 style="width:85px;"/> - 
						<input type="text" class="input" size="8" name="ship_mobile2" maxlength=4 style="width:85px;"/> - 
						<input type="text" class="input" size="8" name="ship_mobile3" maxlength=4 style="width:85px;"/>
						</td>
					</tr>
					<tr>
						<th>남기실 내용</th>
						<td><input type="text" class="input" size="40" name="order_comment" style="width:95%;"></td>
					</tr>
                    </table>
				</div>
            </div>
			
			<div class="guest-private-agree">
				<div class="order-info-title">
					<h3><img src="../images/shop/order_tit7.png" alt="개인정보 수집 및 활용 동의"></h3>
				</div>
				<div class="scroll-box" tabindex="0">
					oooo에서는 기업/단체 및 개인의 정보 수집 및 이용 등 처리에 있어 아래의 사항을 관계법령에 따라 고지하고 안내해 드립니다.<br>
					<br>
					1. 정보수집의 이용 목적 <br>
					물품 및 서비스 상품에 대한 주문 및 접수, 대금 결제를 이용하고 주문 상품 배송 및 회원에게 제공되는 각종 편의 서비스를 이용<br>
					<br>
					2. 수집/이용 항목 <br>
					이름, 주소, 전화번호, 핸드폰번호<br>
					<br>
					3. 보유 및 이용기간<br>
					개인정보 수집 및 이용목적이 달성된 후에는 예외 없이 해당 정보를 지체 없이 파기.<br>
					<br>
					4. 개인정보처리담당<br>
					이름 : ooo<br>
					이메일 : test@naver.com<br>   
					전화 : 000-111-2222
				</div>
				<input type="checkbox" name="chkAgree" value="Y" id="guestPrivateAgree"><label for="guestPrivateAgree">개인정보 수집 및 이용에 동의합니다.</label>
			</div>

			<div class="buttons">
				<div class="cen">
					<a href="javascript:check_order_form(document.frmOrderForm,'<?=$_SITE["SHOP"]["PG"]["COMPANY"]?>', 0)" class="btn-pack xlarge focus">결제하기</a>
					<a href="javascript:history.back();" class="btn-pack xlarge dark">취소하기</a>
				</div>
			</div>
            <!-- <div class="total_btn_c">
                <span class="btn_set"><a href="javascript:check_order_form(document.frmOrderForm,'<?=$_SITE["SHOP"]["PG"]["COMPANY"]?>', 0)"><img src="/images/shop/btn_payment.gif" alt="결제하기" /></a></span>
                <span class="btn_set"><a href="javascript:history.back();"><img src="/images/shop/btn_cancel2.gif" border="0" alt="취소" /></a></span>
            </div> -->
	</form>
<iframe name="hiddenFrame" frameborder=0 width=0 height=0 border=0></iframe>

		</div>
<?
}//주문번호 확인 => 주문번호가 있어야만 주문가능
?>
