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

if(USE_G5_THEME && defined('G5_THEME_PATH')) {
    require_once(G5_SHOP_PATH.'/yc/personalpay.php');
    return;
}

$pid = ($pid) ? $pid : 'ppay';
$at = apms_page_thema($pid);
if(!defined('THEMA_PATH')) {
	include_once(G5_LIB_PATH.'/apms.thema.lib.php');
}

$skin_row = array();
$skin_row = apms_rows('order_'.MOBILE_.'skin, order_'.MOBILE_.'set');
$order_skin_path = G5_SKIN_PATH.'/apms/order/'.$skin_row['order_'.MOBILE_.'skin'];
$order_skin_url = G5_SKIN_URL.'/apms/order/'.$skin_row['order_'.MOBILE_.'skin'];

// 스킨설정
$wset = array();
if($skin_row['order_'.MOBILE_.'set']) {
	$wset = apms_unpack($skin_row['order_'.MOBILE_.'set']);
}

$list_mods = $skin_row['ppay_'.MOBILE_.'mods'];
$list_rows = $skin_row['ppay_'.MOBILE_.'rows'];
if(!$list_mods) $list_mods = 3;
if(!$list_rows) $list_rows = 5;

$sql_common = " from {$g5['g5_shop_personalpay_table']}	where pp_use = '1' and pp_tno = '' ";

// 리스트
$list = array();

// 총몇개 = 한줄에 몇개 * 몇줄
$items = $list_mods * $list_rows;

$sql = "select COUNT(*) as cnt $sql_common ";
$row = sql_fetch($sql);
$total_count = $row['cnt'];

// 전체 페이지 계산
$total_page  = ceil($total_count / $items);

// 페이지가 없으면 첫 페이지 (1 페이지)
if ($page < 1) $page = 1;

// 시작 레코드 구함
$from_record = ($page - 1) * $items;

$num = $total_count - ($page - 1) * $items;
$result = sql_query(" select * $sql_common order by pp_id desc limit $from_record, $items");
for ($i=0; $row=sql_fetch_array($result); $i++) { 
	$list[$i] = $row;
	$list[$i]['pp_href'] = G5_SHOP_URL.'/personalpayform.php?pp_id='.$row['pp_id'].'&amp;page='.$page;
	$list[$i]['pp_num'] = $num;
	$num--;
}

$write_pages = G5_IS_MOBILE ? $config['cf_mobile_pages'] : $config['cf_write_pages'];
$list_page = $_SERVER['SCRIPT_NAME'].'?'.$qstr.'&amp;page=';

$g5['title'] = '개인결제 리스트';
include_once('./_head.php');

$skin_path = $order_skin_path;
$skin_url = $order_skin_url;

// 셋업
$setup_href = '';
if(is_file($skin_path.'/setup.skin.php') && ($is_demo || $is_admin == 'super')) {
	$setup_href = './skin.setup.php?skin=order';
}

include_once($skin_path.'/personalpay.skin.php');
include_once('./_tail.php');
?>
