<?php
include_once('./_common.php');

//include_once(G5_LIB_PATH.'/mailer.lib.php');

//이니시스 lpay 요청으로 왔다면 $default['de_pg_service'] 값을 이니시스로 변경합니다.
if( $od_settle_case == 'lpay' ){
    $default['de_pg_service'] = 'inicis';
}

if(($od_settle_case != '무통장' && $od_settle_case != 'KAKAOPAY') && $default['de_pg_service'] == 'lg' && !$_POST['LGD_PAYKEY'])
    alert('결제등록 요청 후 주문해 주십시오.');

$i_price     = (double)$_POST['od_price'];
//$i_price     = (double)$_POST['od_fx_amount'];
$tot_ct_price = $i_price; // cart 테이블을 사용하지 않으므로 order 테이블에는 상품금액을 강제로 $tot_ct_price 변수에 저장함

$i_send_cost  = (double)$_POST['od_send_cost'];
$i_send_cost2  = (double)$_POST['od_send_cost2'];
$i_send_coupon  = (double)$_POST['od_send_coupon'];
$i_temp_point = (double)$_POST['od_temp_point'];

$i_sns_name = $_POST['od_sns_name'];
$i_sns_id = $_POST['od_sns_id'];
$i_hp_nation = $_POST['od_hp_nation'];

$i_price = $i_price + $i_send_cost + $i_send_cost2 - $i_temp_point - $i_send_coupon;
$order_price = $i_price;

// 입력값과 충전 한도 비교 체크
?>

<?php
    // 포인트 충전/출금 한도 정보를 가져오는 파일입니다.
    require_once(G5_PATH.'/mylib/point_charge_withdraw_info_inc.php');
?>

<?php
$try_remain = $row_point_limit_info['point_limit_charge_1try']-$row_point_limit_info['point_limit_charge_1try_used'];
$day_remain = $row_point_limit_info['point_limit_charge_1day']-$row_point_limit_info['point_limit_charge_1day_used'];
$month_remain = $row_point_limit_info['point_limit_charge_1month']-$row_point_limit_info['point_limit_charge_1month_used'];
$year_remain = $row_point_limit_info['point_limit_charge_1year']-$row_point_limit_info['point_limit_charge_1year_used'];

if ($order_price > $try_remain) {
    alert('1회 충전 잔여한도를 초과하였습니다.\n포인트 충전 한도 표를 참조하십시오.', $page_return_url);
}

if ($order_price > $day_remain) {
    alert('1일 충전 잔여한도를 초과하였습니다.\n포인트 충전 한도 표를 참조하십시오.', $page_return_url);
}

if ($order_price > $month_remain) {
    alert('1개월 충전 잔여한도를 초과하였습니다.\n포인트 충전 한도 표를 참조하십시오.', $page_return_url);
}

if ($order_price > $year_remain) {
    alert('1년 충전 잔여한도를 초과하였습니다.\n포인트 충전 한도 표를 참조하십시오.', $page_return_url);
}

$i_od_fx_type = $_POST['od_fx_type'];
$i_od_fx_rate = (double)$_POST['od_fx_rate'];
$i_od_fx_amount = (double)$_POST['od_fx_amount'];

$od_status = '주문';
$od_tno    = '';
if ($od_settle_case == "무통장")
{
    $od_receipt_point   = $i_temp_point;
    $od_receipt_price   = 0;
    $od_misu            = $i_price - $od_receipt_price;
    if($od_misu == 0) {
        $od_status      = '입금';
        $od_receipt_time = G5_TIME_YMDHIS;
    }
}
else if ($od_settle_case == "포인트")
{
    $od_receipt_point   = $i_temp_point;
    $od_receipt_price   = 0;
    $od_misu            = $i_price - $od_receipt_price;
    if($od_misu == 0) {
        $od_status      = '입금';
        $od_receipt_time = G5_TIME_YMDHIS;
    }
}
else if ($od_settle_case == "계좌이체")
{
    switch($default['de_pg_service']) {
        case 'lg':
            include G5_PATH.'/shoppoint/lg/xpay_result.php';
            break;
        case 'inicis':
            include G5_PATH.'/shoppoint/inicis/inistdpay_result.php';
            break;
        default:
            include G5_PATH.'/shoppoint/kcp/pp_ax_hub.php';
            $bank_name  = iconv("cp949", "utf-8", $bank_name);
            break;
    }

    $od_tno             = $tno;
    $od_receipt_price   = $amount;
    $od_receipt_point   = $i_temp_point;
    $od_receipt_time    = preg_replace("/([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})/", "\\1-\\2-\\3 \\4:\\5:\\6", $app_time);
    $od_bank_account    = $od_settle_case;
    $od_deposit_name    = $od_name;
    $od_bank_account    = $bank_name;
    $pg_price           = $amount;
    $od_misu            = $i_price - $od_receipt_price;
    if($od_misu == 0)
        $od_status      = '입금';
}
else if ($od_settle_case == "가상계좌")
{
    switch($default['de_pg_service']) {
        case 'lg':
            include G5_PATH.'/shoppoint/lg/xpay_result.php';
            break;
        case 'inicis':
            include G5_PATH.'/shoppoint/inicis/inistdpay_result.php';
            $od_app_no = $app_no;
            break;
        default:
            include G5_PATH.'/shoppoint/kcp/pp_ax_hub.php';
            $bankname   = iconv("cp949", "utf-8", $bankname);
            $depositor  = iconv("cp949", "utf-8", $depositor);
            break;
    }

    $od_receipt_point   = $i_temp_point;
    $od_tno             = $tno;
    $od_receipt_price   = 0;
    $od_bank_account    = $bankname.' '.$account;
    $od_deposit_name    = $depositor;
    $pg_price           = $amount;
    $od_misu            = $i_price - $od_receipt_price;

    // 가상계좌 입금시 자동 입금처리가 안되는 문제 해결을 위해 영카트 기본엔 없는 코드 추가 { JSLEE
    if($od_misu == 0)
    {
        $od_status      = '입금';
    }
    // 가상계좌 입금시 자동 입금처리가 안되는 문제 해결을 위해 영카트 기본엔 없는 코드 추가 } JSLEE
}
else if ($od_settle_case == "휴대폰")
{
    switch($default['de_pg_service']) {
        case 'lg':
            include G5_PATH.'/shoppoint/lg/xpay_result.php';
            break;
        case 'inicis':
            include G5_PATH.'/shoppoint/inicis/inistdpay_result.php';
            break;
        default:
            include G5_PATH.'/shoppoint/kcp/pp_ax_hub.php';
            break;
    }

    $od_tno             = $tno;
    $od_receipt_price   = $amount;
    $od_receipt_point   = $i_temp_point;
    $od_receipt_time    = preg_replace("/([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})/", "\\1-\\2-\\3 \\4:\\5:\\6", $app_time);
    $od_bank_account    = $commid . ($commid ? ' ' : '').$mobile_no;
    $pg_price           = $amount;
    $od_misu            = $i_price - $od_receipt_price;
    if($od_misu == 0)
        $od_status      = '입금';
}
else if ($od_settle_case == "신용카드")
{
    switch($default['de_pg_service']) {
        case 'lg':
            include G5_PATH.'/shoppoint/lg/xpay_result.php';
            break;
        case 'inicis':
            include G5_PATH.'/shoppoint/inicis/inistdpay_result.php';
            break;
        default:
            include G5_PATH.'/shoppoint/kcp/pp_ax_hub.php';
            $card_name  = iconv("cp949", "utf-8", $card_name);
            break;
    }

    $od_tno             = $tno;
    $od_app_no          = $app_no;
    $od_receipt_price   = $amount;
    $od_receipt_point   = $i_temp_point;
    $od_receipt_time    = preg_replace("/([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})/", "\\1-\\2-\\3 \\4:\\5:\\6", $app_time);
    $od_bank_account    = $card_name;
    $pg_price           = $amount;
    $od_misu            = $i_price - $od_receipt_price;
    if($od_misu == 0)
        $od_status      = '입금';
}
else if ($od_settle_case == "간편결제" || ($od_settle_case == "lpay" && $default['de_pg_service'] === 'inicis') )
{
    switch($default['de_pg_service']) {
        case 'lg':
            include G5_PATH.'/shoppoint/lg/xpay_result.php';
            break;
        case 'inicis':
            include G5_PATH.'/shoppoint/inicis/inistdpay_result.php';
            break;
        default:
            include G5_PATH.'/shoppoint/kcp/pp_ax_hub.php';
            $card_name  = iconv("cp949", "utf-8", $card_name);
            break;
    }

    $od_tno             = $tno;
    $od_app_no          = $app_no;
    $od_receipt_price   = $amount;
    $od_receipt_point   = $i_temp_point;
    $od_receipt_time    = preg_replace("/([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})/", "\\1-\\2-\\3 \\4:\\5:\\6", $app_time);
    $od_bank_account    = $card_name;
    $pg_price           = $amount;
    $od_misu            = $i_price - $od_receipt_price;
    if($od_misu == 0)
        $od_status      = '입금';
}
else if ($od_settle_case == "KAKAOPAY")
{
    include G5_PATH.'/shoppoint/kakaopay/kakaopay_result.php';

    $od_tno             = $tno;
    $od_app_no          = $app_no;
    $od_receipt_price   = $amount;
    $od_receipt_point   = $i_temp_point;
    $od_receipt_time    = preg_replace("/([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})/", "\\1-\\2-\\3 \\4:\\5:\\6", $app_time);
    $od_bank_account    = $card_name;
    $pg_price           = $amount;
    $od_misu            = $i_price - $od_receipt_price;
    if($od_misu == 0)
        $od_status      = '입금';
}
else
{
    die("od_settle_case Error!!!");
}

$od_pg = $default['de_pg_service'];
if($od_settle_case == 'KAKAOPAY')
    $od_pg = 'KAKAOPAY';

// 주문금액과 결제금액이 일치하는지 체크
if($tno) {
    if((int)$order_price !== (int)$pg_price) {
        $cancel_msg = '결제금액 불일치';
        switch($od_pg) {
            case 'lg':
                include G5_PATH.'/shoppoint/lg/xpay_cancel.php';
                break;
            case 'inicis':
                include G5_PATH.'/shoppoint/inicis/inipay_cancel.php';
                break;
            case 'KAKAOPAY':
                $_REQUEST['TID']               = $tno;
                $_REQUEST['Amt']               = $amount;
                $_REQUEST['CancelMsg']         = $cancel_msg;
                $_REQUEST['PartialCancelCode'] = 0;
                include G5_PATH.'/shoppoint/kakaopay/kakaopay_cancel.php';
                break;
            default:
                include G5_PATH.'/shoppoint/kcp/pp_ax_hub_cancel.php';
                break;
        }

        die("Receipt Amount Error");
    }
}

if ($is_member)
    $od_pwd = $member['mb_password'];
else
    $od_pwd = get_encrypt_string($_POST['od_pwd']);

// 주문번호를 얻는다.
$od_id = get_session('ss_order_id');

$od_escrow = 0;
if($escw_yn == 'Y')
    $od_escrow = 1;

// 복합과세 금액
$od_tax_mny = round($i_price / 1.1);
$od_vat_mny = $i_price - $od_tax_mny;
$od_free_mny = 0;
if($default['de_tax_flag_use']) {
    $od_tax_mny = (int)$_POST['comm_tax_mny'];
    $od_vat_mny = (int)$_POST['comm_vat_mny'];
    $od_free_mny = (int)$_POST['comm_free_mny'];
}

$od_email         = get_email_address($od_email);
$od_name          = clean_xss_tags($od_name);
$od_tel           = clean_xss_tags($od_tel);
$od_hp            = clean_xss_tags($od_hp);
$od_zip           = preg_replace('/[^0-9]/', '', $od_zip);
$od_zip1          = substr($od_zip, 0, 3);
$od_zip2          = substr($od_zip, 3);
$od_addr1         = clean_xss_tags($od_addr1);
$od_addr2         = clean_xss_tags($od_addr2);
$od_addr3         = clean_xss_tags($od_addr3);
$od_addr_jibeon   = preg_match("/^(N|R)$/", $od_addr_jibeon) ? $od_addr_jibeon : '';
$od_b_name        = clean_xss_tags($od_b_name);
$od_b_tel         = clean_xss_tags($od_b_tel);
$od_b_hp          = clean_xss_tags($od_b_hp);
$od_b_addr1       = clean_xss_tags($od_b_addr1);
$od_b_addr2       = clean_xss_tags($od_b_addr2);
$od_b_addr3       = clean_xss_tags($od_b_addr3);
$od_b_addr_jibeon = preg_match("/^(N|R)$/", $od_b_addr_jibeon) ? $od_b_addr_jibeon : '';
$od_memo          = clean_xss_tags($od_memo);
// 무통장: 입금자명을 주문번호 끝 4자리 + 실명(prefix)으로 강제 설정
    if ($od_settle_case === '무통장') {
        $od_deposit_name = substr($od_id, -4) . $od_name;
    }
    $od_deposit_name  = clean_xss_tags($od_deposit_name);
$od_tax_flag      = $default['de_tax_flag_use'];


// 주문서에 입력
$sql = " insert g5_shoppoint_order
            set od_id             = '$od_id',
                mb_id             = '{$member['mb_id']}',
                od_pwd            = '$od_pwd',
                od_name           = '$od_name',
                od_email          = '$od_email',
                od_tel            = '$od_tel',
                od_hp             = '$od_hp',
                od_zip1           = '$od_zip1',
                od_zip2           = '$od_zip2',
                od_addr1          = '$od_addr1',
                od_addr2          = '$od_addr2',
                od_addr3          = '$od_addr3',
                od_addr_jibeon    = '$od_addr_jibeon',
                od_b_name         = '$od_b_name',
                od_b_tel          = '$od_b_tel',
                od_b_hp           = '$od_b_hp',
                od_b_zip1         = '$od_b_zip1',
                od_b_zip2         = '$od_b_zip2',
                od_b_addr1        = '$od_b_addr1',
                od_b_addr2        = '$od_b_addr2',
                od_b_addr3        = '$od_b_addr3',
                od_b_addr_jibeon  = '$od_b_addr_jibeon',
                od_deposit_name   = '$od_deposit_name',
                od_memo           = '$od_memo',
                od_cart_count     = '$cart_count',
                od_cart_price     = '$tot_ct_price',
                od_cart_coupon    = '$tot_it_cp_price',
                od_send_cost      = '$od_send_cost',
                od_send_coupon    = '$tot_sc_cp_price',
                od_send_cost2     = '$od_send_cost2',
                od_coupon         = '$tot_od_cp_price',
                od_receipt_price  = '$od_receipt_price',
                od_receipt_point  = '$od_receipt_point',
                od_bank_account   = '$od_bank_account',
                od_receipt_time   = '$od_receipt_time',
                od_misu           = '$od_misu',
                od_pg             = '$od_pg',
                od_tno            = '$od_tno',
                od_app_no         = '$od_app_no',
                od_escrow         = '$od_escrow',
                od_tax_flag       = '$od_tax_flag',
                od_tax_mny        = '$od_tax_mny',
                od_vat_mny        = '$od_vat_mny',
                od_free_mny       = '$od_free_mny',
                od_status         = '$od_status',
                od_shop_memo      = '',
                od_hope_date      = '$od_hope_date',
                od_time           = '".G5_TIME_YMDHIS."',
                od_ip             = '$REMOTE_ADDR',
                od_settle_case    = '$od_settle_case',
                od_test           = '{$default['de_card_test']}',
                od_sns_name       = '$i_sns_name',
                od_sns_id         = '$i_sns_id',
                od_hp_nation         = '$i_hp_nation',
                od_fx_type        = '$i_od_fx_type',
                od_fx_rate        = '$i_od_fx_rate',
                od_fx_amount        = '$i_od_fx_amount'
                ";
$result = sql_query($sql, false);

// 입력값을 충전신청 한도에서 공제시킬 변수 생성
$after_point_limit_charge_1try_used = $member['point_limit_charge_1try_used']+$tot_ct_price;
$after_point_limit_charge_1day_used = $member['point_limit_charge_1day_used']+$tot_ct_price;
$after_point_limit_charge_1month_used = $member['point_limit_charge_1month_used']+$tot_ct_price;
$after_point_limit_charge_1year_used = $member['point_limit_charge_1year_used']+$tot_ct_price;

// g5_member 테이블의 포인트 충전정보를 최근의 정보로 업데이트 한다. JSLEE
$sql_member = " update {$g5['member_table']} set
                point_limit_charge_1try_used = '{$after_point_limit_charge_1try_used}',
                point_limit_charge_1day_used = '{$after_point_limit_charge_1day_used}',
                point_limit_charge_1month_used = '{$after_point_limit_charge_1month_used}',
                point_limit_charge_1year_used = '{$after_point_limit_charge_1year_used}'
                where mb_id = '{$member['mb_id']}' ";
$result_member = sql_query($sql_member, false);

// 주문정보 입력 오류시 결제 취소
if(!$result) {
    if($tno) {
        $cancel_msg = '주문정보 입력 오류';
        switch($od_pg) {
            case 'lg':
                include G5_PATH.'/shoppoint/lg/xpay_cancel.php';
                break;
            case 'inicis':
                include G5_PATH.'/shoppoint/inicis/inipay_cancel.php';
                break;
            case 'KAKAOPAY':
                $_REQUEST['TID']               = $tno;
                $_REQUEST['Amt']               = $amount;
                $_REQUEST['CancelMsg']         = $cancel_msg;
                $_REQUEST['PartialCancelCode'] = 0;
                include G5_PATH.'/shoppoint/kakaopay/kakaopay_cancel.php';
                break;
            default:
                include G5_PATH.'/shoppoint/kcp/pp_ax_hub_cancel.php';
                break;
        }
    }

    // 관리자에게 오류 알림 메일발송
    $error = 'order';
    //include G5_PATH.'/shoppoint/ordererrormail.php';

    die('<p>고객님의 주문 정보를 처리하는 중 오류가 발생해서 주문이 완료되지 않았습니다.</p><p>'.strtoupper($od_pg).'를 이용한 전자결제(신용카드, 계좌이체, 가상계좌 등)은 자동 취소되었습니다.');
}

if ($od_status == "입금") {
    // 장바구니에 ct_status 주문상태 데이터가 변경된 상태에서 아래 내용 처리해야 함에 주의 (현재 이 위치가 적당함) [유의사항] orderformupdate.php 와 settle_kcp_common.php 에 동일한 내용으로 들어가야 함. 단 $od_receipt_time 만 settle_kcp_common.php 에서는 현재 시각을 사용함.
    // PG사 자동결제시스템에 의해 미수금 없는 결제완료여부는 $od_misu == "0" && $od_status == "입금"이면 충족되므로 렌탈개시로 제반등록을 하면 됨.
    // ComViewers를 위한 코드 JSLEE
    // 장바구니 주문정보 입력 오류시 결제 취소 및 주문삭제처리
    $now = G5_TIME_YMDHIS;
    $log ="\n입금완료처리|{$member['mb_id']}|$now|{$_SERVER['REMOTE_ADDR']}";

    // order table 용
    // cart의 오더번호와 it_id 가 일치하는 주문의 statu를 변경함.
    if ($member['mb_id']) {
        $action_mbid = $member['mb_id'];
        $action_mbname = $member['mb_name'];
    } else {
        $action_mbid = $mb_id;
        $action_mbname = '';
    }
    if ($action_mbname != '') {
        $od_mod_history = date('Y-m-d H:i:s').' ID:'.$action_mbid.' NAME:'.$action_mbname . ' [신규주문입금] '.'PG자동처리';
    } else {
        $od_mod_history = date('Y-m-d H:i:s').' ID:'.$action_mbid. ' [신규주문입금] '.'PG자동처리';
    }
    $query_ordere_history_check = "SELECT * FROM g5_shoppoint_order WHERE od_mod_history LIKE '%$od_mod_history%' AND od_id = '$od_id' ";
    $result_ordere_history_check=mysqli_query($db,$query_ordere_history_check);
    $rowTotal_ordere_history_check=mysqli_num_rows($result_ordere_history_check);
    if ($rowTotal_ordere_history_check == 0) { // 이미 등록된 것이 없으면... 이 코드 없으면 여러개의 경우 여러개가 중복해서 등록됨
        $sql = " UPDATE g5_shoppoint_order SET od_mod_history = CONCAT(ifnull(od_mod_history,''),'$od_mod_history') WHERE od_id = '$od_id' ";
        sql_query($sql);
    }

    // 오더 테이블에서 입금액 확인용 {
    $sql81B = " select od_receipt_price, od_receipt_point from g5_shoppoint_order where od_id = '$od_id' order by od_id desc limit 1 ";
    $result81B = sql_fetch($sql81B);
    $od_receipt_price = $result81B['od_receipt_price'];

    insert_point($action_mbid, $od_receipt_price, '주문번호 '.$od_id. ' 결제 - 포인트구매', $rel_table='', $rel_id='', $od_id, $expire=0);
    // 오더 테이블에서 입금액 확인용 }

}

$od_memo = nl2br(htmlspecialchars2(stripslashes($od_memo))) . "&nbsp;";

//include_once(G5_PATH.'/shoppoint/ordermail1.inc.php');
//include_once(G5_PATH.'/shoppoint/ordermail2.inc.php');

// SMS BEGIN --------------------------------------------------------
// 주문고객과 쇼핑몰관리자에게 SMS 전송
if($config['cf_sms_use'] && ($default['de_sms_use2'] || $default['de_sms_use3'])) {
    $is_sms_send = false;

    // 충전식일 경우 잔액이 있는지 체크
    if($config['cf_icode_id'] && $config['cf_icode_pw']) {
        $userinfo = get_icode_userinfo($config['cf_icode_id'], $config['cf_icode_pw']);

        if($userinfo['code'] == 0) {
            if($userinfo['payment'] == 'C') { // 정액제
                $is_sms_send = true;
            } else {
                $minimum_coin = 100;
                if(defined('G5_ICODE_COIN'))
                    $minimum_coin = intval(G5_ICODE_COIN);

                if((int)$userinfo['coin'] >= $minimum_coin)
                    $is_sms_send = true;
            }
        }
    }

    if($is_sms_send) {
        $sms_contents = array($default['de_sms_cont2'], $default['de_sms_cont3']);
        $recv_numbers = array($od_hp, $default['de_sms_hp']);
        $send_numbers = array($default['de_admin_company_tel'], $default['de_admin_company_tel']);

        $sms_count = 0;
        $sms_messages = array();

        for($s=0; $s<count($sms_contents); $s++) {
            $sms_content = $sms_contents[$s];
            $recv_number = preg_replace("/[^0-9]/", "", $recv_numbers[$s]);
            $send_number = preg_replace("/[^0-9]/", "", $send_numbers[$s]);

            $sms_content = str_replace("{이름}", $od_name, $sms_content);
            $sms_content = str_replace("{보낸분}", $od_name, $sms_content);
            $sms_content = str_replace("{받는분}", $od_b_name, $sms_content);
            $sms_content = str_replace("{주문번호}", $od_id, $sms_content);
            $sms_content = str_replace("{주문금액}", number_format($tot_ct_price + $od_send_cost + $od_send_cost2), $sms_content);
            $sms_content = str_replace("{회원아이디}", $member['mb_id'], $sms_content);
            $sms_content = str_replace("{회사명}", $default['de_admin_company_name'], $sms_content);

            $idx = 'de_sms_use'.($s + 2);

            if($default[$idx] && $recv_number) {
                $sms_messages[] = array('recv' => $recv_number, 'send' => $send_number, 'cont' => $sms_content);
                $sms_count++;
            }
        }

        // 무통장 입금 때 고객에게 계좌정보 보냄
        if($od_settle_case == '무통장' && $default['de_sms_use2'] && $od_misu > 0) {
            $sms_content = $od_name."님의 입금계좌입니다.\n금액:".number_format($od_misu)."원\n계좌:".$od_bank_account."\n".$default['de_admin_company_name'];

            $recv_number = preg_replace("/[^0-9]/", "", $od_hp);
            $send_number = preg_replace("/[^0-9]/", "", $default['de_admin_company_tel']);

            $sms_messages[] = array('recv' => $recv_number, 'send' => $send_number, 'cont' => $sms_content);
            $sms_count++;
        }

        // SMS 전송
        if($sms_count > 0) {
            if($config['cf_sms_type'] == 'LMS') {
                include_once(G5_LIB_PATH.'/icode.lms.lib.php');

                $port_setting = get_icode_port_type($config['cf_icode_id'], $config['cf_icode_pw']);

                // SMS 모듈 클래스 생성
                if($port_setting !== false) {
                    $SMS = new LMS;
                    $SMS->SMS_con($config['cf_icode_server_ip'], $config['cf_icode_id'], $config['cf_icode_pw'], $port_setting);

                    for($s=0; $s<count($sms_messages); $s++) {
                        $strDest     = array();
                        $strDest[]   = $sms_messages[$s]['recv'];
                        $strCallBack = $sms_messages[$s]['send'];
                        $strCaller   = iconv_euckr(trim($default['de_admin_company_name']));
                        $strSubject  = '';
                        $strURL      = '';
                        $strData     = iconv_euckr($sms_messages[$s]['cont']);
                        $strDate     = '';
                        $nCount      = count($strDest);

                        $res = $SMS->Add($strDest, $strCallBack, $strCaller, $strSubject, $strURL, $strData, $strDate, $nCount);

                        $SMS->Send();
                        $SMS->Init(); // 보관하고 있던 결과값을 지웁니다.
                    }
                }
            } else {
                include_once(G5_LIB_PATH.'/icode.sms.lib.php');

                $SMS = new SMS; // SMS 연결
                $SMS->SMS_con($config['cf_icode_server_ip'], $config['cf_icode_id'], $config['cf_icode_pw'], $config['cf_icode_server_port']);

                for($s=0; $s<count($sms_messages); $s++) {
                    $recv_number = $sms_messages[$s]['recv'];
                    $send_number = $sms_messages[$s]['send'];
                    $sms_content = iconv_euckr($sms_messages[$s]['cont']);

                    $SMS->Add($recv_number, $send_number, $config['cf_icode_id'], $sms_content, "");
                }

                $SMS->Send();
                $SMS->Init(); // 보관하고 있던 결과값을 지웁니다.
            }
        }
    }
}
// SMS END   --------------------------------------------------------


// orderview 에서 사용하기 위해 session에 넣고
$uid = md5($od_id.G5_TIME_YMDHIS.$REMOTE_ADDR);
set_session('ss_orderview_uid', $uid);

// 주문 정보 임시 데이터 삭제
if($od_pg == 'inicis') {
    $sql = " delete from g5_shoppoint_order_data where od_id = '$od_id' and dt_pg = '$od_pg' ";
    sql_query($sql);
}

// 주문번호제거
set_session('ss_order_id', '');

// 기존자료 세션에서 제거
if (get_session('ss_direct'))
    set_session('ss_cart_direct', '');

goto_url(G5_URL.'/shoppoint/orderinquiryview.php?od_id='.$od_id.'&amp;uid='.$uid);
?>

<html>
    <head>
        <title>주문정보 기록</title>
        <script>
            // 결제 중 새로고침 방지 샘플 스크립트 (중복결제 방지)
            function noRefresh()
            {
                /* CTRL + N키 막음. */
                if ((event.keyCode == 78) && (event.ctrlKey == true))
                {
                    event.keyCode = 0;
                    return false;
                }
                /* F5 번키 막음. */
                if(event.keyCode == 116)
                {
                    event.keyCode = 0;
                    return false;
                }
            }

            document.onkeydown = noRefresh ;
        </script>
    </head>
</html>