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

if ($is_guest) {
	$is_layer = isset($_GET['g5_layer']) && $_GET['g5_layer'];

	if ($is_layer) {
		$login_url = G5_BBS_URL.'/popup_login.php';
		if (isset($_GET['vpntheme']) && $_GET['vpntheme'] === 'dark') { $_g5_vpn_theme = 'dark'; }
		elseif (isset($_GET['vpntheme']) && $_GET['vpntheme'] === 'light') { $_g5_vpn_theme = 'light'; }
		elseif (!empty($_COOKIE['vpnlink_dark']) && $_COOKIE['vpnlink_dark'] === '1') { $_g5_vpn_theme = 'dark'; }
		else { $_g5_vpn_theme = 'light'; }
		?>
<!doctype html>
<html lang="ko" data-site-theme="<?php echo $_g5_vpn_theme; ?>">
<head>
<meta charset="utf-8">
<script>(function(){
/* 1순위: iframe 안에서는 부모 창의 data-site-theme을 직접 읽음 */
if(window.self!==window.top){try{var pt=window.parent.document.documentElement.getAttribute('data-site-theme');if(pt==='light'||pt==='dark'){document.documentElement.setAttribute('data-site-theme',pt);return;}}catch(e){}}
/* 2순위: vpntheme URL 파라미터 */
try{var vt=new URLSearchParams(window.location.search).get('vpntheme');if(vt==='light'||vt==='dark'){document.documentElement.setAttribute('data-site-theme',vt);return;}}catch(e){}
var eff='light';
try{
  var m=document.cookie.match(/(?:^|;\s*)vpnlink_dark=([01])/);
  if(m){eff=(m[1]==='1')?'dark':'light';}
  else{throw '';}
}catch(e){
  var t='system';
  try{t=localStorage.getItem('vpnlink_site_theme')||'system';}catch(e2){}
  var s=(window.matchMedia&&window.matchMedia('(prefers-color-scheme:dark)').matches)?'dark':'light';
  eff=(t==='system')?s:t;
}
document.documentElement.setAttribute('data-site-theme',eff);
}());</script>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>보유포인트 안내</title>
<style>
html[data-site-theme="light"] { color-scheme: light; }
html[data-site-theme="dark"] { color-scheme: dark; }
::-webkit-scrollbar{width:6px;height:6px}::-webkit-scrollbar-track{background:transparent}::-webkit-scrollbar-thumb{background:#c5cdd8;border-radius:3px}::-webkit-scrollbar-thumb:hover{background:#a0aabb}
[data-site-theme="dark"]::-webkit-scrollbar-track{background:#1a1b1e}[data-site-theme="dark"] ::-webkit-scrollbar-thumb{background:#3a3a52}
html, body { height:100%; margin:0; }
body { font-family:'Noto Sans KR', Arial, sans-serif; background:#f1f5f9; color:#0f172a; display:flex; align-items:center; justify-content:center; }
.point-guard { width:min(520px, calc(100% - 28px)); background:#fff; border:1px solid #dbe4f0; border-radius:14px; box-shadow:0 16px 42px rgba(15, 23, 42, 0.18); overflow:hidden; }
.point-guard-head { padding:16px 20px 14px; border-bottom:1px solid #e2e8f0; font-size:16px; font-weight:700; color:#1e293b; }
.point-guard-body { padding:22px 20px 10px; line-height:1.7; color:#334155; font-size:15px; }
.point-guard-foot { padding:16px 20px 20px; display:flex; justify-content:flex-end; gap:10px; }
.point-guard-btn { appearance:none; border:1px solid #2f4b7f; background:#2f4b7f; color:#fff; border-radius:10px; height:40px; padding:0 16px; font-size:14px; cursor:pointer; text-decoration:none; display:inline-flex; align-items:center; justify-content:center; }
.point-guard-btn:hover { background:#274170; border-color:#274170; color:#fff; }
.point-guard-btn.secondary { background:#fff; color:#35598d; border-color:#c4d4ef; }
.point-guard-btn.secondary:hover { background:#eef4ff; border-color:#93afd8; color:#274170; }
/* 다크모드 */
[data-site-theme="dark"] body { background:#1a1b1e; color:#e4e4e7; }
[data-site-theme="dark"] .point-guard { background:#252528; border-color:#3a3a42; box-shadow:0 16px 42px rgba(0,0,0,0.5); }
[data-site-theme="dark"] .point-guard-head { color:#e4e4e7; border-bottom-color:#3a3a42; }
[data-site-theme="dark"] .point-guard-body { color:#a1a1aa; }
[data-site-theme="dark"] .point-guard-btn.secondary { background:#252528; color:#90afd4; border-color:#3a4a5e; }
[data-site-theme="dark"] .point-guard-btn.secondary:hover { background:#2c2c32; border-color:#4a5a6e; color:#a0bfe4; }
</style>
</head>
<body>
	<div class="point-guard" role="alertdialog" aria-modal="true" aria-labelledby="point-guard-title">
		<div class="point-guard-head" id="point-guard-title">보유포인트 안내</div>
		<div class="point-guard-body">회원만 조회하실 수 있습니다.<br>로그인 후 보유포인트를 확인해 주세요.</div>
		<div class="point-guard-foot">
			<a href="<?php echo $login_url; ?>" class="point-guard-btn">로그인</a>
		</div>
	</div>
</body>
</html>
		<?php
		exit;
	}

	alert_close('회원만 조회하실 수 있습니다.');
}

$is_point_layer = isset($_GET['g5_layer']) && $_GET['g5_layer'];
$is_parent_refresh = $is_point_layer && isset($_GET['g5_parent_refresh']) && $_GET['g5_parent_refresh'];

// Page ID
$pid = ($pid) ? $pid : '';
$at = apms_page_thema($pid);
include_once(G5_LIB_PATH.'/apms.thema.lib.php');

// 스킨 체크
list($member_skin_path, $member_skin_url) = apms_skin_thema('member', $member_skin_path, $member_skin_url); 

// 설정값 불러오기
$is_point_sub = true;
@include_once($member_skin_path.'/config.skin.php');

$g5['title'] = get_text($member['mb_nick']).' 님의 '.AS_MP.' 내역';

if($is_point_sub) {
	include_once(G5_PATH.'/head.sub.php');
	if(!USE_G5_THEME) @include_once(THEMA_PATH.'/head.sub.php');
} else {
	include_once('./_head.php');
}

if ($is_parent_refresh) {
	?>
<script>
(function() {
	if (window.parent && window.parent !== window) {
		try {
			if (typeof window.parent.g5_refresh_lnb_menu_ajax === 'function') {
				window.parent.g5_refresh_lnb_menu_ajax();
			}
		} catch (e) {}
	}
})();
</script>
	<?php
}

$skin_path = $member_skin_path;
$skin_url = $member_skin_url;

$list = array();

//분류 (VPN 프로젝트 특성에 맞게 조정)
$where = '';
switch($sca) {
	case 'new_contract' : $where = "and po_rel_table = '' and po_rel_action = '' and po_point < 0"; break;
	case 'extend'       : $where = "and (po_rel_table like '@shopExtendPeriod|%' or po_rel_table = '@extendOrderApprove')"; break;
	case 'refund'       : $where = "and (po_rel_table like '@shoprefund|%' or po_rel_table like '@ikev2ProvRefund|%')"; break;
	case 'refundcancel' : $where = "and po_rel_table like '@shoprefundcancel|%'"; break;
	case 'topup'        : $where = "and po_rel_table = '@buyshoppoints'"; break;
	case 'withdraw'     : $where = "and po_content like '%출금%'"; break;
	case 'event'        : $where = "and po_rel_action in ('이벤트낙찰', '이벤트당첨', '이벤트참여', '이벤트협찬')"; break;
	case 'login'        : $where = "and po_rel_table in ('@login', '@chulsuk')"; break;
}

$sql_common = " from {$g5['point_table']} where mb_id = '".escape_trim($member['mb_id'])."' $where ";
$sql_order = " order by po_id desc ";

$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; // 시작 열을 구함

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

// 스킨설정
$wset = (G5_IS_MOBILE) ? apms_skin_set('member_mobile') : apms_skin_set('member');

$setup_href = '';
if(is_file($skin_path.'/setup.skin.php') && ($is_demo || $is_designer)) {
	$setup_href = './skin.setup.php?skin=member&amp;ts='.urlencode(THEMA);
}

include_once($skin_path.'/point.skin.php');

if($is_point_sub) {
	if(!USE_G5_THEME) @include_once(THEMA_PATH.'/tail.sub.php');
	include_once(G5_PATH.'/tail.sub.php');
} else {
	include_once('./_tail.php');
}
?>