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

auth_check($auth[$sub_menu], "r");

$g5['title'] = '상품관리';
include_once (G5_ADMIN_PATH.'/admin.head.php');

// 분류
$ca_list  = '<option value="">선택</option>'.PHP_EOL;
$sql = " select * from {$g5['g5_shop_category_table']} ";
if ($is_admin != 'super')
    $sql .= " where ca_mb_id = '{$member['mb_id']}' ";
$sql .= " order by ca_order, ca_id ";
$result = sql_query($sql);
for ($i=0; $row=sql_fetch_array($result); $i++)
{
    $len = strlen($row['ca_id']) / 2 - 1;
    $nbsp = '';
    for ($i=0; $i<$len; $i++) {
        $nbsp .= '&nbsp;&nbsp;&nbsp;';
    }

	if($row['as_line']) {
		$ca_list .= "<option value=\"\">".$nbsp."------------</option>\n";
	}

    $ca_list .= '<option value="'.$row['ca_id'].'">'.$nbsp.$row['ca_name'].'</option>'.PHP_EOL;
}

$where = " and ";
$sql_search = "";
if ($stx != "") {
    if ($sfl != "") {
        $sql_search .= " $where $sfl like '%$stx%' ";
        $where = " and ";
    }
    if ($save_stx != $stx)
        $page = 1;
}

if ($sca != "") {
    $sql_search .= " $where (a.ca_id like '$sca%' or a.ca_id2 like '$sca%' or a.ca_id3 like '$sca%') ";
}

$lock_only = (isset($lock_only) && (string)$lock_only === '1') ? '1' : '';
$lock_reason = isset($lock_reason) ? trim((string)$lock_reason) : '';
if($lock_reason !== 'paid' && $lock_reason !== 'cancelled') {
    $lock_reason = '';
}
if($lock_reason !== '') {
    $lock_only = '1';
}

$lock_subquery_paid = "
    select distinct c.it_id
    from {$g5['g5_shop_cart_table']} c
    left join {$g5['g5_shop_order_table']} o on (c.od_id = o.od_id)
    where c.ct_select = '1'
      and c.ct_status in ('입금','준비','배송','완료')
";

$lock_subquery_cancelled = "
    select distinct c.it_id
    from {$g5['g5_shop_cart_table']} c
    left join {$g5['g5_shop_order_table']} o on (c.od_id = o.od_id)
    where c.ct_select = '1'
      and c.ct_status in ('취소','반품')
      and (
            IFNULL(o.od_receipt_price, 0) > 0
            or IFNULL(o.od_receipt_point, 0) > 0
            or (
                IFNULL(o.od_receipt_time, '') <> ''
                and IFNULL(o.od_receipt_time, '') <> '0000-00-00 00:00:00'
            )
          )
";

$lock_subquery_all = "
    select distinct c.it_id
    from {$g5['g5_shop_cart_table']} c
    left join {$g5['g5_shop_order_table']} o on (c.od_id = o.od_id)
    where c.ct_select = '1'
      and (
            c.ct_status in ('입금','준비','배송','완료')
            or (
                c.ct_status in ('취소','반품')
                and (
                    IFNULL(o.od_receipt_price, 0) > 0
                    or IFNULL(o.od_receipt_point, 0) > 0
                    or (
                        IFNULL(o.od_receipt_time, '') <> ''
                        and IFNULL(o.od_receipt_time, '') <> '0000-00-00 00:00:00'
                    )
                )
            )
          )
";

if ($sfl == "")  $sfl = "it_name";

$sql_common = " from {$g5['g5_shop_item_table']} a ,
                     {$g5['g5_shop_category_table']} b
               where (a.ca_id = b.ca_id";
if ($is_admin != 'super')
    $sql_common .= " and b.ca_mb_id = '{$member['mb_id']}'";
$sql_common .= ") ";
$sql_common .= $sql_search;
if($lock_only === '1') {
    if($lock_reason === 'paid') {
        $sql_common .= " and a.it_id in ( $lock_subquery_paid ) ";
    } else if($lock_reason === 'cancelled') {
        $sql_common .= " and a.it_id in ( $lock_subquery_cancelled ) ";
    } else {
        $sql_common .= " and a.it_id in ( $lock_subquery_all ) ";
    }
}

$lock_stats = array('locked' => 0, 'paid' => 0, 'cancelled' => 0);
$row_lock = sql_fetch(" select count(distinct a.it_id) as cnt $sql_common and a.it_id in ( $lock_subquery_all ) ");
$row_paid = sql_fetch(" select count(distinct a.it_id) as cnt $sql_common and a.it_id in ( $lock_subquery_paid ) ");
$row_cancelled = sql_fetch(" select count(distinct a.it_id) as cnt $sql_common and a.it_id in ( $lock_subquery_cancelled ) ");
$lock_stats['locked'] = isset($row_lock['cnt']) ? (int)$row_lock['cnt'] : 0;
$lock_stats['paid'] = isset($row_paid['cnt']) ? (int)$row_paid['cnt'] : 0;
$lock_stats['cancelled'] = isset($row_cancelled['cnt']) ? (int)$row_cancelled['cnt'] : 0;

// 테이블의 전체 레코드수만 얻음
$sql = " select count(*) as cnt " . $sql_common;
$row = sql_fetch($sql);
$total_count = $row['cnt'];

$rows = $config['cf_page_rows'];
$total_page  = ceil($total_count / $rows);  // 전체 페이지 계산
if ($page < 1) { $page = 1; } // 페이지가 없으면 첫 페이지 (1 페이지)
$from_record = ($page - 1) * $rows; // 시작 열을 구함

if (!$sst) {
	$sst = "it_id";
    $sod = "desc";
}

if($sst == 'it_id') {
	$pth = "a.pt_num desc,";
	$ptt = "";
} else {
	$pth = "";
	$ptt = ", a.pt_num desc";
}

$sql_order = "order by $pth $sst $sod $ptt";

$sql  = " select *
           $sql_common
           $sql_order
           limit $from_record, $rows ";
$result = sql_query($sql);

//$qstr  = $qstr.'&amp;sca='.$sca.'&amp;page='.$page;
$qstr  = $qstr.'&amp;sca='.$sca.'&amp;page='.$page.'&amp;save_stx='.$stx.'&amp;lock_only='.$lock_only.'&amp;lock_reason='.$lock_reason;

$filter_common_qs = 'sca='.urlencode($sca)
    .'&amp;sfl='.urlencode($sfl)
    .'&amp;stx='.urlencode($stx)
    .'&amp;save_stx='.urlencode($stx)
    .'&amp;sst='.urlencode($sst)
    .'&amp;sod='.urlencode($sod);
$url_lock_all = $_SERVER['SCRIPT_NAME'].'?'.$filter_common_qs.'&amp;lock_only=1';
$url_lock_paid = $_SERVER['SCRIPT_NAME'].'?'.$filter_common_qs.'&amp;lock_only=1&amp;lock_reason=paid';
$url_lock_cancelled = $_SERVER['SCRIPT_NAME'].'?'.$filter_common_qs.'&amp;lock_only=1&amp;lock_reason=cancelled';

$listall = '<a href="'.$_SERVER['SCRIPT_NAME'].'" class="ov_listall">전체목록</a>';

// APMS - 2014.07.25
include_once(G5_ADMIN_PATH.'/apms_admin/apms.admin.lib.php');
$flist = array();
$flist = apms_form(1,0);

?>

<script src="<?php echo G5_ADMIN_URL;?>/apms_admin/apms.admin.js"></script>
<link rel="stylesheet" href="<?php echo G5_URL; ?>/css/lock_filter_loading.css">

<div class="local_ov01 local_ov">
    <?php echo $listall; ?>
    <span class="btn_ov01"><span class="ov_txt">등록된 상품</span><span class="ov_num"> <?php echo $total_count; ?>건</span></span>
    <span class="btn_ov01"><span class="ov_txt"><a href="<?php echo $url_lock_all; ?>">영구잠금(현재검색)</a></span><span class="ov_num"> <?php echo number_format($lock_stats['locked']); ?>건</span></span>
    <span class="btn_ov01"><span class="ov_txt"><a href="<?php echo $url_lock_paid; ?>">결제완료형</a></span><span class="ov_num"> <?php echo number_format($lock_stats['paid']); ?>건</span></span>
    <span class="btn_ov01"><span class="ov_txt"><a href="<?php echo $url_lock_cancelled; ?>">결제후 취소/반품형</a></span><span class="ov_num"> <?php echo number_format($lock_stats['cancelled']); ?>건</span></span>
</div>

<form name="flist" class="local_sch01 local_sch">
<input type="hidden" name="save_stx" value="<?php echo $stx; ?>">

<label for="sca" class="sound_only">분류선택</label>
<select name="sca" id="sca">
    <option value="">전체분류</option>
    <?php
    $sql1 = " select ca_id, ca_name, as_line from {$g5['g5_shop_category_table']} order by ca_order, ca_id ";
    $result1 = sql_query($sql1);
    for ($i=0; $row1=sql_fetch_array($result1); $i++) {
        $len = strlen($row1['ca_id']) / 2 - 1;
        $nbsp = '';
        for ($i=0; $i<$len; $i++) $nbsp .= '&nbsp;&nbsp;&nbsp;';

		if($row1['as_line']) {
			echo "<option value=\"\">".$nbsp."------------</option>\n";
		}

		echo '<option value="'.$row1['ca_id'].'" '.get_selected($sca, $row1['ca_id']).'>'.$nbsp.$row1['ca_name'].'</option>'.PHP_EOL;
    }
    ?>
</select>

<label for="sfl" class="sound_only">검색대상</label>
<select name="sfl" id="sfl">
    <option value="it_name" <?php echo get_selected($sfl, 'it_name'); ?>>상품명</option>
    <option value="it_id" <?php echo get_selected($sfl, 'it_id'); ?>>상품코드</option>
    <option value="it_maker" <?php echo get_selected($sfl, 'it_maker'); ?>>제조사</option>
    <option value="it_origin" <?php echo get_selected($sfl, 'it_origin'); ?>>원산지</option>
    <option value="it_sell_email" <?php echo get_selected($sfl, 'it_sell_email'); ?>>판매자 e-mail</option>
	<!-- APMS - 2014.07.20 -->
	    <option value="pt_id" <?php echo get_selected($sfl, 'pt_id'); ?>>판매자센터 아이디</option>
	<!-- // -->
</select>

<label for="stx" class="sound_only">검색어</label>
<input type="text" name="stx" value="<?php echo $stx; ?>" id="stx" class="frm_input">
<label for="lock_only" style="margin-left:8px;">
    <input type="checkbox" name="lock_only" id="lock_only" value="1" <?php echo ($lock_only === '1') ? 'checked' : ''; ?>> 영구잠금만
</label>
<span style="margin-left:8px;">잠금사유:</span>
<label for="lock_reason_all" style="margin-left:4px; font-weight:normal;">
    <input type="radio" name="lock_reason" id="lock_reason_all" value="" <?php echo ($lock_reason === '') ? 'checked' : ''; ?>> 전체
</label>
<label for="lock_reason_paid" style="margin-left:4px; font-weight:normal;">
    <input type="radio" name="lock_reason" id="lock_reason_paid" value="paid" <?php echo ($lock_reason === 'paid') ? 'checked' : ''; ?>> 결제완료형
</label>
<label for="lock_reason_cancelled" style="margin-left:4px; font-weight:normal;">
    <input type="radio" name="lock_reason" id="lock_reason_cancelled" value="cancelled" <?php echo ($lock_reason === 'cancelled') ? 'checked' : ''; ?>> 결제후 취소/반품형
</label>
<input type="submit" value="검색" class="btn_submit">

</form>

<div id="lockFilterLoadingAdmin" class="lock-filter-loading" style="display:none;">
    <span class="lock-filter-loading__badge">
        <span class="lock-filter-loading__spinner"></span>
        <span>필터 적용 중...</span>
    </span>
</div>

<script>
$(function() {
    var $form = $('form[name="flist"]');
    var $loading = $('#lockFilterLoadingAdmin');
    if(!$form.length) return;

    $form.on('submit', function() {
        $loading.show();
    });

    $('#lock_only, input[name="lock_reason"]').on('change', function() {
        if($(this).attr('name') === 'lock_reason') {
            var val = $('input[name="lock_reason"]:checked').val() || '';
            if(val !== '') {
                $('#lock_only').prop('checked', true);
            }
        }
        $form.trigger('submit');
    });
});
</script>

<form id="fitemlistupdate" name="fitemlistupdate" method="post" action="./itemlistupdate.php" onsubmit="return fitemlist_submit(this);" autocomplete="off">
<input type="hidden" name="sca" value="<?php echo $sca; ?>">
<input type="hidden" name="sst" value="<?php echo $sst; ?>">
<input type="hidden" name="sod" value="<?php echo $sod; ?>">
<input type="hidden" name="sfl" value="<?php echo $sfl; ?>">
<input type="hidden" name="stx" value="<?php echo $stx; ?>">
<input type="hidden" name="lock_only" value="<?php echo $lock_only; ?>">
<input type="hidden" name="lock_reason" value="<?php echo $lock_reason; ?>">
<input type="hidden" name="page" value="<?php echo $page; ?>">

<div class="tbl_head01 tbl_wrap">
    <table>
    <caption><?php echo $g5['title']; ?> 목록</caption>
    <thead>
    <tr>
        <th scope="col" rowspan="3">
            <label for="chkall" class="sound_only">상품 전체</label>
            <input type="checkbox" name="chkall" value="1" id="chkall" onclick="check_all(this.form)">
        </th>
        <th scope="col" rowspan="3"><?php echo subject_sort_link('it_id', 'sca='.$sca); ?>상품코드</a></th>
        <th scope="col" colspan="8">분류</th>
        <th scope="col" rowspan="3"><?php echo subject_sort_link('pt_main', 'sca='.$sca); ?>메인</a></th>
		<th scope="col" rowspan="3"><?php echo subject_sort_link('it_order', 'sca='.$sca); ?>순서</a></th>
        <th scope="col" rowspan="3"><?php echo subject_sort_link('it_use', 'sca='.$sca, 1); ?>판매</a></th>
        <th scope="col" rowspan="3"><?php echo subject_sort_link('it_soldout', 'sca='.$sca, 1); ?>품절</a></th>
        <th scope="col" rowspan="3">영구잠금</th>
        <th scope="col" rowspan="3"><?php echo subject_sort_link('it_hit', 'sca='.$sca, 1); ?>조회</a></th>
        <th scope="col" rowspan="3">관리</th>
    </tr>
    <tr>
        <th scope="col" rowspan="2" id="th_img">이미지</th>
        <th scope="col" rowspan="2" id="th_pc_title"><?php echo subject_sort_link('it_name', 'sca='.$sca); ?>상품명</a></th>
		<th scope="col" id="th_amt"><?php echo subject_sort_link('it_price', 'sca='.$sca); ?>판매가격</a></th>
        <th scope="col" id="th_camt"><?php echo subject_sort_link('it_cust_price', 'sca='.$sca); ?>시중가격</a></th>
		<!-- APMS - 2014.07.20 -->
			<th scope="col" id="th_fee"><?php echo subject_sort_link('pt_commission', 'sca='.$sca); ?>수수료(%)</a></th>
			<th scope="col" id="th_start"><?php echo subject_sort_link('pt_reserve', 'sca='.$sca); ?>예약일</a></th>
	        <th scope="col" id="th_type">상품종류</a></th>
		<!-- // -->
    </tr>
    <tr>
		<th scope="col" id="th_pt"><?php echo subject_sort_link('it_point', 'sca='.$sca); ?>포인트</a></th>
        <th scope="col" id="th_qty"><?php echo subject_sort_link('it_stock_qty', 'sca='.$sca); ?>재고</a></th>
		<!-- APMS - 2014.07.20 -->
			<th scope="col" id="th_icnt"><?php echo subject_sort_link('pt_incentive', 'sca='.$sca); ?>인센티브(%)</a></th>
			<th scope="col" id="th_end"><?php echo subject_sort_link('pt_end', 'sca='.$sca); ?>종료일</a></th>
	        <th scope="col" id="th_cmt">댓글사용</th>
		<!-- // -->
    </tr>
    </thead>
    <tbody>
    <?php
    for ($i=0; $row=sql_fetch_array($result); $i++)
    {
        $href = G5_SHOP_URL.'/item.php?it_id='.$row['it_id'];
        $bg = 'bg'.($i%2);

        $lock_info = function_exists('get_item_permanent_lock_info') ? get_item_permanent_lock_info($row['it_id']) : array('locked' => false);
        $is_permanent_locked = !empty($lock_info['locked']);
        if($is_permanent_locked) {
            $row['it_soldout'] = 1;
        }
        $lock_reason = ($is_permanent_locked && isset($lock_info['reason'])) ? get_text($lock_info['reason']) : '';
        $lock_first_od_id = ($is_permanent_locked && isset($lock_info['first_od_id'])) ? get_text($lock_info['first_od_id']) : '';
        $lock_first_paid_time = ($is_permanent_locked && isset($lock_info['first_paid_time'])) ? get_text($lock_info['first_paid_time']) : '';

        $it_point = $row['it_point'];
        if($row['it_point_type'])
            $it_point .= '%';
    ?>
    <tr class="<?php echo $bg; ?>">
        <td rowspan="3" class="td_chk">
            <label for="chk_<?php echo $i; ?>" class="sound_only"><?php echo get_text($row['it_name']); ?></label>
            <input type="checkbox" name="chk[]" value="<?php echo $i ?>" id="chk_<?php echo $i; ?>">
        </td>
		<!-- APMS - 2014.07.20 -->
		<td rowspan="3" class="td_num" style="white-space:nowrap">
            <input type="hidden" name="it_id[<?php echo $i; ?>]" value="<?php echo $row['it_id']; ?>">
			<?php if($row['pt_it']) { ?>
				<div style="font-size:11px; letter-spacing:-1px;"><?php echo apms_pt_it($row['pt_it'],1);?></div>
			<?php } ?>
			<b><?php echo $row['it_id']; ?></b>
			<?php if($row['pt_id']) { ?>
				<div style="font-size:11px; letter-spacing:-1px;"><?php echo $row['pt_id'];?></div>
			<?php } ?>
        </td>
		<!-- // -->
		<td colspan="8" class="td_sort">
            <label for="ca_id_<?php echo $i; ?>" class="sound_only"><?php echo get_text($row['it_name']); ?> 기본분류</label>
            <select name="ca_id[<?php echo $i; ?>]" id="ca_id_<?php echo $i; ?>" required>
                <?php echo conv_selected_option($ca_list, $row['ca_id']); ?>
            </select>
            <label for="ca_id2_<?php echo $i; ?>" class="sound_only"><?php echo get_text($row['it_name']); ?> 2차분류</label>
            <select name="ca_id2[<?php echo $i; ?>]" id="ca_id2_<?php echo $i; ?>">
                <?php echo conv_selected_option($ca_list, $row['ca_id2']); ?>
            </select>
            <label for="ca_id3_<?php echo $i; ?>" class="sound_only"><?php echo get_text($row['it_name']); ?> 3차분류</label>
            <select name="ca_id3[<?php echo $i; ?>]" id="ca_id3_<?php echo $i; ?>">
                <?php echo conv_selected_option($ca_list, $row['ca_id3']); ?>
            </select>
        </td>
        <td rowspan="3" class="td_mngsmall">
            <label for="main_<?php echo $i; ?>" class="sound_only">메인상품</label>
            <input type="checkbox" name="pt_main[<?php echo $i; ?>]" <?php echo ($row['pt_main'] ? 'checked' : ''); ?> value="1" id="main_<?php echo $i; ?>">
        </td>
		<td rowspan="3" class="td_mngsmall">
            <label for="order_<?php echo $i; ?>" class="sound_only">순서</label>
            <input type="text" name="it_order[<?php echo $i; ?>]" value="<?php echo $row['it_order']; ?>" id="order_<?php echo $i; ?>" class="frm_input" size="3">
        </td>
        <td rowspan="3" class="td_mngsmall">
            <label for="use_<?php echo $i; ?>" class="sound_only">판매여부</label>
            <input type="checkbox" name="it_use[<?php echo $i; ?>]" <?php echo ($row['it_use'] ? 'checked' : ''); ?> value="1" id="use_<?php echo $i; ?>">
        </td>
        <td rowspan="3" class="td_mngsmall">
            <label for="soldout_<?php echo $i; ?>" class="sound_only">품절</label>
            <?php if($is_permanent_locked) { ?>
                <input type="hidden" name="it_soldout[<?php echo $i; ?>]" value="1">
            <?php } ?>
            <input type="checkbox" name="it_soldout[<?php echo $i; ?>]" <?php echo ($row['it_soldout'] ? 'checked' : ''); ?> value="1" id="soldout_<?php echo $i; ?>" <?php echo ($is_permanent_locked ? 'disabled' : ''); ?>>
        </td>
        <td rowspan="3" class="td_left" style="min-width:200px;">
            <?php if($is_permanent_locked) { ?>
                <div style="font-weight:700; color:#d9534f;">영구잠금</div>
                <div style="font-size:11px; color:#333;">사유: <?php echo $lock_reason; ?></div>
                <div style="font-size:11px; color:#333;">최초 구매주문번호: <?php echo $lock_first_od_id; ?></div>
                <?php if($lock_first_paid_time) { ?><div style="font-size:11px; color:#666;">최초 결제시각: <?php echo $lock_first_paid_time; ?></div><?php } ?>
            <?php } else { ?>
                -
            <?php } ?>
        </td>
        <td rowspan="3" class="td_num"><?php echo $row['it_hit']; ?></td>
        <td rowspan="3" class="td_mng td_mng_s">
            <a href="./itemform.php?w=u&amp;it_id=<?php echo $row['it_id']; ?>&amp;fn=<?php echo $row['pt_form'];?>&amp;ca_id=<?php echo $row['ca_id']; ?>&amp;<?php echo $qstr; ?>" class="btn btn_03"><span class="sound_only"><?php echo htmlspecialchars2(cut_str($row['it_name'],250, "")); ?> </span>수정</a>
            <a href="./itemcopy.php?it_id=<?php echo $row['it_id']; ?>&amp;ca_id=<?php echo $row['ca_id']; ?>" class="itemcopy btn btn_02" target="_blank"><span class="sound_only"><?php echo htmlspecialchars2(cut_str($row['it_name'],250, "")); ?> </span>복사</a>
            <a href="<?php echo $href; ?>" class="btn btn_02"><span class="sound_only"><?php echo htmlspecialchars2(cut_str($row['it_name'],250, "")); ?> </span>보기</a>
        </td>
    </tr>
    <tr class="<?php echo $bg; ?>">
        <td rowspan="2" class="td_img"><a href="<?php echo $href; ?>"><?php echo get_it_image($row['it_id'], 50, 50); ?></a></td>
        <td headers="th_pc_title" rowspan="2" class="td_input td_left">
			<?php echo help("상품등록폼 : ".apms_form_option('name', $flist, $row['pt_form']));?>
            <label for="name_<?php echo $i; ?>" class="sound_only">상품명</label>
            <input type="text" name="it_name[<?php echo $i; ?>]" value="<?php echo htmlspecialchars2(cut_str($row['it_name'],250, "")); ?>" id="name_<?php echo $i; ?>" required class="frm_input required" size="30">
        </td>
        <td headers="th_amt" class="td_numbig td_input">
            <label for="price_<?php echo $i; ?>" class="sound_only">판매가격</label>
            <input type="text" name="it_price[<?php echo $i; ?>]" value="<?php echo $row['it_price']; ?>" id="price_<?php echo $i; ?>" class="frm_input sit_amt" size="7">
        </td>
        <td headers="th_camt" class="td_numbig td_input">
            <label for="cust_price_<?php echo $i; ?>" class="sound_only">시중가격</label>
            <input type="text" name="it_cust_price[<?php echo $i; ?>]" value="<?php echo $row['it_cust_price']; ?>" id="cust_price_<?php echo $i; ?>" class="frm_input sit_camt" size="7">
        </td>
		<td headers="th_amt" class="td_numbig td_input">
			<label for="commission_<?php echo $i; ?>" class="sound_only">수수료</label>
			<input type="text" name="pt_commission[<?php echo $i; ?>]" value="<?php echo $row['pt_commission']; ?>" id="commission_<?php echo $i; ?>" class="frm_input sit_amt" size="3">
		</td>
		<td headers="th_amt" class="td_numbig td_input">
			<?php echo ($default['pt_reserve_cache'] > 0 && $row['pt_reserve_use'] && $row['pt_reserve']) ? date("Y.m.d", $row['pt_reserve']) : '-'; ?>
		</td>
		<td headers="th_amt" class="td_numbig td_input">
			<?php if(!$row['pt_it']) $row['pt_it'] = 1; ?>
			<select name="pt_it[<?php echo $i; ?>]" id="pt_it_[<?php echo $i; ?>]">
				<option value="">종류선택</option>
				<?php echo apms_pt_it($row['pt_it']); ?>
			</select>
		</td>
    </tr>
    <tr class="<?php echo $bg; ?>">
        <td headers="th_pt" class="td_numbig td_input"><?php echo $it_point; ?></td>
        <td headers="th_qty" class="td_numbig td_input">
            <label for="stock_qty_<?php echo $i; ?>" class="sound_only">재고</label>
            <input type="text" name="it_stock_qty[<?php echo $i; ?>]" value="<?php echo $row['it_stock_qty']; ?>" id="stock_qty_<?php echo $i; ?>" class="frm_input sit_qty" size="7">
        </td>
		<!-- APMS - 2014.07.14 -->
			<td headers="th_amt" class="td_numbig td_input">
				<label for="incentive_<?php echo $i; ?>" class="sound_only">인센티브</label>
				<input type="text" name="pt_incentive[<?php echo $i; ?>]" value="<?php echo $row['pt_incentive']; ?>" id="incentive_<?php echo $i; ?>" class="frm_input sit_camt" size="3">
			</td>
			<td headers="th_amt" class="td_numbig td_input">
				<?php echo ($default['pt_reserve_cache'] > 0 && $row['pt_end']) ? date("Y.m.d", $row['pt_end']) : '-'; ?>
			</td>
			<td headers="th_amt" class="td_numbig td_input">
				<select name="pt_comment_use[<?php echo $i; ?>]" id="pt_comment_use_<?php echo $i; ?>">
					<option value="0"<?php echo get_selected('0', $row['pt_comment_use']); ?>>사용안함</option>
					<option value="1"<?php echo get_selected('1', $row['pt_comment_use']); ?>>모두등록</option>
					<option value="2"<?php echo get_selected('2', $row['pt_comment_use']); ?>>나만등록</option>
				</select>
			</td>
		<!-- // -->
    </tr>
    <?php
    }
    if ($i == 0)
        echo '<tr><td colspan="17" class="empty_table">자료가 한건도 없습니다.</td></tr>';
    ?>
    </tbody>
    </table>
</div>

<div class="btn_fixed_top">
    <a href="./itemform.php" class="btn btn_01">상품등록</a>
    <a href="./itemexcel.php" onclick="return excelform(this.href);" target="_blank" class="btn btn_02">상품일괄등록</a>
    <input type="submit" name="act_button" value="선택수정" onclick="document.pressed=this.value" class="btn btn_02">
    <?php if ($is_admin == 'super') { ?>
    <input type="submit" name="act_button" value="선택삭제" onclick="document.pressed=this.value" class="btn btn_02">
    <?php } ?>
</div>
<!-- <div class="btn_confirm01 btn_confirm">
    <input type="submit" value="일괄수정" class="btn_submit" accesskey="s">
</div> -->
</form>

<?php echo get_paging(G5_IS_MOBILE ? $config['cf_mobile_pages'] : $config['cf_write_pages'], $page, $total_page, "{$_SERVER['SCRIPT_NAME']}?$qstr&amp;page="); ?>

<script>
function fitemlist_submit(f)
{
    if (!is_checked("chk[]")) {
        alert(document.pressed+" 하실 항목을 하나 이상 선택하세요.");
        return false;
    }

    if(document.pressed == "선택삭제") {
        if(!confirm("선택한 자료를 정말 삭제하시겠습니까?")) {
            return false;
        }
    }

    return true;
}

$(function() {
    $(".itemcopy").click(function() {
        var href = $(this).attr("href");
        window.open(href, "copywin", "left=100, top=100, width=300, height=200, scrollbars=0");
        return false;
    });
});

function excelform(url)
{
    var opt = "width=600,height=450,left=10,top=10";
    window.open(url, "win_excel", opt);
    return false;
}
</script>

<?php
include_once (G5_ADMIN_PATH.'/admin.tail.php');
?>
