<?php
$sub_menu = '400900';
include_once('./_common.php');

//print_r2($_POST); exit;

check_admin_token();

for ($i=0; $i<count($_POST['chk']); $i++)
{
    // 실제 번호를 넘김
    $k     = $_POST['chk'][$i];
    $od_id = $_POST['od_id'][$k];

    $od = sql_fetch(" select * from g5_shoppoint_order where od_id = '$od_id' ");
    if (!$od) continue;

    // 주문상태가 주문이거나 취소금액이 없는 취소건만 처리
    if($od['od_status'] == '주문' || ($od['od_status'] == '취소' && !$od['od_receipt_price'])) {
		;
	} else {
		continue;
	}

    $data = serialize($od);

    $sql = " insert g5_shoppoint_order_delete set de_key = '$od_id', de_data = '".addslashes($data)."', mb_id = '{$member['mb_id']}', de_ip = '{$_SERVER['REMOTE_ADDR']}', de_datetime = '".G5_TIME_YMDHIS."' ";
    sql_query($sql, true);

    // cart 테이블의 상품 상태를 삭제로 변경
    $sql = " update g5_shoppoint_cart set ct_status = '삭제' where od_id = '$od_id' and ct_status IN('주문', '취소') ";
    sql_query($sql);

    $sql = " delete from g5_shoppoint_order where od_id = '$od_id' ";
    sql_query($sql);

	// 개별배송비에서 삭제 - APMS 추가
    $sql = " delete from {$g5['apms_sendcost']} where od_id = '$od_id' ";
    sql_query($sql);
}

$qstr  = "sort1=$sort1&amp;sort2=$sort2&amp;sel_field=$sel_field&amp;search=$search";
$qstr .= "&amp;od_status=$search_od_status";
$qstr .= "&amp;od_settle_case=$od_settle_case";
$qstr .= "&amp;od_misu=$od_misu";
$qstr .= "&amp;od_cancel_price=$od_cancel_price";
$qstr .= "&amp;od_receipt_price=$od_receipt_price";
$qstr .= "&amp;od_receipt_point=$od_receipt_point";
$qstr .= "&amp;od_receipt_coupon=$od_receipt_coupon";

goto_url("./orderlist4shoppoint.php?$qstr");
?>