<?php
include_once('./_common.php');
include_once(G5_LIB_PATH.'/login_guard.lib.php');

if( function_exists('social_check_login_before') ){
    $social_login_html = social_check_login_before();
}

// Page ID
$pid = ($pid) ? $pid : 'login';
$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_login_sub = false;
@include_once($member_skin_path.'/config.skin.php');

$url = isset($_GET['url']) ? strip_tags($_GET['url']) : '';

// url 체크
check_url_host($url);

$is_layer_login = (isset($_GET['g5_layer']) && $_GET['g5_layer']) ? true : false;
if (!$is_layer_login && $url) {
	$url_query = parse_url($url, PHP_URL_QUERY);
	parse_str((string)$url_query, $url_params);
	if (!empty($url_params['g5_layer'])) {
		$is_layer_login = true;
	}
}
if ($is_layer_login) {
	$is_login_sub = true;
}

$g5['title'] = '로그인';

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

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

// 이미 로그인 중이라면
if ($is_member) {
    if ($url)
        goto_url($url);
    else
        goto_url(G5_URL);
}

$login_url        = login_url($url);
$login_action_url = G5_HTTPS_BBS_URL."/login_check.php";

$login_guard_state = login_guard_get_state();
$login_captcha_required = login_guard_is_captcha_required($login_guard_state);
$login_captcha_lock_seconds = login_guard_get_remaining_lock_seconds($login_guard_state);
$login_captcha_html = '';
if ($login_captcha_required && defined('G5_CAPTCHA_PATH')) {
	@include_once(G5_CAPTCHA_PATH.'/captcha.lib.php');
	if (function_exists('captcha_html')) {
		$login_captcha_html = captcha_html('captcha login-captcha');
	}
}

// 스킨설정
$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);
}

// 로그인 스킨이 없는 경우 관리자 페이지 접속이 안되는 것을 막기 위하여 기본 스킨으로 대체
$login_file = $skin_path.'/login.skin.php';
if (!is_file($login_file))
    $skin_path   = G5_SKIN_PATH.'/member/basic';

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

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