<?php
if (!defined('_GNUBOARD_')) exit;
include_once(G5_LIB_PATH.'/apms.lib.php');

// APMS Version
define('APMS_VERSION', 'APMS 1.3.6 - G5.0.40/YC5.0.41');

// USE YC5
if (!defined('G5_USE_SHOP') || !G5_USE_SHOP) {
	define('IS_YC', false);
	define('USE_PARTNER', false);
	@include_once(G5_LIB_PATH.'/thumbnail.lib.php');
} else {
	define('IS_YC', true);
	@include_once(G5_EXTEND_PATH.'/shop.extend.php');
	if($default['as_partner']) {
		define('USE_PARTNER', true);
	} else {
		define('USE_PARTNER', false);
	}
	@include_once(G5_LIB_PATH.'/apms.shop.lib.php');
}

// APMS DB Table
if(IS_YC) {
	$g5['apms'] = G5_TABLE_PREFIX.'apms';
	$g5['apms_partner'] = G5_TABLE_PREFIX.'apms_partner';
	$g5['apms_payment'] = G5_TABLE_PREFIX.'apms_payment';
	$g5['apms_file'] = G5_TABLE_PREFIX.'apms_file';
	$g5['apms_form'] = G5_TABLE_PREFIX.'apms_form';
	$g5['apms_rows'] = G5_TABLE_PREFIX.'apms_rows';
	$g5['apms_comment'] = G5_TABLE_PREFIX.'apms_comment';
	$g5['apms_use_log'] = G5_TABLE_PREFIX.'apms_use_log';
	$g5['apms_sendcost'] = G5_TABLE_PREFIX.'apms_sendcost';
	$g5['apms_good'] = G5_TABLE_PREFIX.'apms_good';
}
$g5['apms_tag'] = G5_TABLE_PREFIX.'apms_tag';
$g5['apms_tag_log'] = G5_TABLE_PREFIX.'apms_tag_log';
$g5['apms_like'] = G5_TABLE_PREFIX.'apms_like';
$g5['apms_xp'] = G5_TABLE_PREFIX.'apms_xp';
$g5['apms_page'] = G5_TABLE_PREFIX.'apms_page';
$g5['apms_data'] = G5_TABLE_PREFIX.'apms_data';
$g5['apms_cache'] = G5_TABLE_PREFIX.'apms_cache';
$g5['apms_shingo'] = G5_TABLE_PREFIX.'apms_shingo';
$g5['apms_response'] = G5_TABLE_PREFIX.'apms_response';
$g5['apms_event'] = G5_TABLE_PREFIX.'apms_event';
$g5['apms_playlist'] = G5_TABLE_PREFIX.'apms_playlist';
$g5['cache_auto_menu'] = (int)$config['cf_9']; //메뉴
$g5['cache_stats_time'] = (int)$config['cf_10_subj']; //통계
$g5['cache_newpost_time'] = (int)$config['cf_10']; //새글

// Demo Config
$demo_config = array('bo_table' => '', 'ca_id' => '', 'ev_id' => '', 'bn_id' => '');

if(G5_IS_MOBILE) {
	define('MOBILE_', 'mobile_');
    $board_skin_path    = G5_SKIN_PATH.'/board/'.$board['bo_mobile_skin'];
    $board_skin_url     = G5_SKIN_URL.'/board/'.$board['bo_mobile_skin'];
    $member_skin_path   = G5_SKIN_PATH.'/member/'.$config['cf_mobile_member_skin'];
    $member_skin_url    = G5_SKIN_URL.'/member/'.$config['cf_mobile_member_skin'];
    $new_skin_path      = G5_SKIN_PATH.'/new/'.$config['cf_mobile_new_skin'];
    $new_skin_url       = G5_SKIN_URL.'/new/'.$config['cf_mobile_new_skin'];
    $search_skin_path   = G5_SKIN_PATH.'/search/'.$config['cf_mobile_search_skin'];
    $search_skin_url    = G5_SKIN_URL.'/search/'.$config['cf_mobile_search_skin'];
    $connect_skin_path  = G5_SKIN_PATH.'/connect/'.$config['cf_mobile_connect_skin'];
    $connect_skin_url   = G5_SKIN_URL.'/connect/'.$config['cf_mobile_connect_skin'];
    $faq_skin_path      = G5_SKIN_PATH.'/faq/'.$config['cf_mobile_faq_skin'];
    $faq_skin_url       = G5_SKIN_URL.'/faq/'.$config['cf_mobile_faq_skin'];
} else {
	define('MOBILE_', '');
}

// APMS Common ---------------------------------------------------------------------------
$as_href = array();
$at = array();
$xp = array();

// Load XP
$xp = sql_fetch("select * from {$g5['apms_xp']} ", false);

// Define Term
define('AS_XP', $config['as_xp']);
define('AS_MP', $config['as_mp']);

define('APMS_PLUGIN_PATH', G5_PLUGIN_PATH.'/apms');
define('APMS_PLUGIN_URL', G5_PLUGIN_URL.'/apms');

$mode = apms_escape('mode', 0);
$pid = apms_escape('pid', 0);
$pim = apms_escape('pim', 0);

define('APMS_PIM', $pim);

// Member
$member = apms_member($member['mb_id']);

if(USE_PARTNER && $member['as_partner']) {
	define('IS_PARTNER', true);
} else {
	define('IS_PARTNER', false);
}

// Auth
if($is_admin == 'super' || $is_admin == 'group') {
	;
} else {
	$chk_auth = '';
	if($gr_id) {
		if($group['as_partner'] && !IS_PARTNER) $chk_auth = '파트너만 이용가능합니다.';
		if(!$chk_auth) $chk_auth = apms_auth($group['as_grade'], $group['as_equal'], $group['as_min'], $group['as_max'], 1);
	}

	if(!$chk_auth && !$is_admin && $bo_table) {
		if($board['as_partner'] && !IS_PARTNER) $chk_auth = '파트너만 이용가능합니다.';
		if(!$chk_auth) $chk_auth = apms_auth($board['as_grade'], $board['as_equal'], $board['as_min'], $board['as_max'], 1);
	}

	if($chk_auth) {
		include_once(G5_BBS_PATH.'/alert.header.php');
		alert($chk_auth, G5_URL);
		exit;
	}
}

// Index
$is_index = false;

// Meta
$is_seometa = '';

// Cross Domain jQuery Error
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST, GET, OPTIONS');
header('Access-Control-Max-Age: 1000');
if(array_key_exists('HTTP_ACCESS_CONTROL_REQUEST_HEADERS', $_SERVER)) {
    header('Access-Control-Allow-Headers: '
           . $_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']);
} else {
    header('Access-Control-Allow-Headers: *');
}
 
if("OPTIonS" == $_SERVER['REQUEST_METHOD']) {
    exit(0);
}

// Link Href
$at_href['css'] = (isset($chk_host['path']) && $chk_host['path']) ? $_SERVER['HTTP_HOST'].$chk_host['path'] : $_SERVER['HTTP_HOST'];
$at_href['reg'] = G5_BBS_URL.'/register.php';
$at_href['login'] = ($urlencode) ? G5_BBS_URL.'/login.php?url='.$urlencode : G5_BBS_URL.'/login.php';
$at_href['login_check'] = G5_HTTPS_BBS_URL.'/login_check.php';
$at_href['logout'] = G5_BBS_URL.'/logout.php';
$at_href['point'] = G5_BBS_URL.'/point.php';
$at_href['coupon'] = G5_SHOP_URL.'/coupon.php';
$at_href['memo'] = G5_BBS_URL.'/memo.php';
$at_href['scrap'] = G5_BBS_URL.'/scrap.php';
$at_href['edit'] = G5_BBS_URL.'/member_confirm.php?url=register_form.php';
$at_href['leave'] = G5_BBS_URL.'/member_confirm.php?url=member_leave.php';
$at_href['lost'] = G5_BBS_URL.'/password_lost.php';
$at_href['response'] = G5_BBS_URL.'/response.php';
$at_href['follow'] = G5_BBS_URL.'/follow.php';
$at_href['myphoto'] = G5_BBS_URL.'/myphoto.php';
$at_href['mypost'] = G5_BBS_URL.'/mypost.php';
$at_href['connect'] = G5_BBS_URL.'/current_connect.php';
$at_href['secret'] = G5_BBS_URL.'/qalist.php';
$at_href['switcher_submit'] = G5_BBS_URL.'/switcher.update.php';
$at_href['faq'] = G5_BBS_URL.'/faq.php';
$at_href['new'] = G5_BBS_URL.'/new.php';
$at_href['search'] = G5_BBS_URL.'/search.php';
$at_href['mypage'] = (IS_YC) ? G5_SHOP_URL.'/mypage.php' : G5_BBS_URL.'/mypage.php';
$at_href['tag'] = G5_BBS_URL.'/tag.php';
$at_href['example'] = G5_URL.'/example.php';
if(IS_YC) {
	$at_href['myshop'] = G5_SHOP_URL.'/myshop.php';
	$at_href['cart'] = G5_SHOP_URL.'/cart.php';
	$at_href['wishlist'] = G5_SHOP_URL.'/wishlist.php';
	$at_href['shopping'] = G5_SHOP_URL.'/shopping.php';
	$at_href['inquiry'] = G5_SHOP_URL.'/orderinquiry.php';
	$at_href['ppay'] = G5_SHOP_URL.'/personalpay.php';
	$at_href['event'] = G5_SHOP_URL.'/event.php';
	$at_href['itype'] = G5_SHOP_URL.'/listtype.php';
	$at_href['home_shop'] = G5_SHOP_URL;
	$at_href['isearch'] = G5_SHOP_URL.'/search.php';
	$at_href['iuse'] = G5_SHOP_URL.'/itemuselist.php';
	$at_href['iqa'] = G5_SHOP_URL.'/itemqalist.php';
	$at_href['partner'] = G5_SHOP_URL.'/partner';
}

?>