<?php
$socialInstalled = is_file($g['path_module'].'social/var/var.php');
$socialProviders = array(
	'naver' => array('네이버','https://developers.naver.com/apps/#/register'),
	'google' => array('구글','https://console.cloud.google.com/apis/credentials'),
	'facebook' => array('페이스북','https://developers.facebook.com/apps/'),
	'x' => array('X(트위터)','https://console.x.com/')
);
if ($socialInstalled) include $g['path_module'].'social/var/var.php';
$socialCallback = $g['url_root'].'/?r='.$r.'&m=social&page=oauth&provider=';
?>

<div class="guide social-guide">
	<span class="b">소셜 로그인 모듈과 연결된 통합 설정입니다.</span><br /><br />
	여기에서 저장한 제공자와 인증 정보는 관리자 &gt; 소셜링크 설정 및 실제 로그인 화면에 동일하게 적용됩니다.<br />
	<?php if($socialInstalled):?>
	<span class="social-state social-state-on">소셜링크 모듈이 정상적으로 연결되어 있습니다.</span>
	<?php else:?>
	<span class="social-state social-state-off">소셜링크 모듈이 설치되어 있지 않습니다.</span>
	<?php endif?>
</div>

<?php if($socialInstalled):?>
<form name="socialConfigForm" method="post" action="<?php echo $g['s']?>/" onsubmit="return socialConfigCheck(this);">
	<input type="hidden" name="r" value="<?php echo $r?>" />
	<input type="hidden" name="m" value="social" />
	<input type="hidden" name="a" value="config" />

	<div class="social-general">
		<label><input type="checkbox" name="auto_join" value="1"<?php if(!empty($d['social']['auto_join'])):?> checked="checked"<?php endif?> /> 최초 소셜 로그인 시 회원을 자동으로 생성합니다.</label>
	</div>

	<div class="social-provider-list">
	<?php foreach($socialProviders as $providerKey => $providerInfo):?>
		<section class="social-provider">
			<div class="social-provider-head">
				<label><input type="checkbox" name="use_<?php echo $providerKey?>" value="1"<?php if(!empty($d['social']['use_'.$providerKey])):?> checked="checked"<?php endif?> /> <strong><?php echo $providerInfo[0]?></strong> 로그인 사용</label>
				<a href="<?php echo $providerInfo[1]?>" target="_blank" rel="noopener">개발자센터</a>
			</div>
			<div class="social-provider-body">
				<label class="social-field"><span>Client ID</span><input type="text" name="client_<?php echo $providerKey?>" value="<?php echo htmlspecialchars(isset($d['social']['client_'.$providerKey])?$d['social']['client_'.$providerKey]:'',ENT_QUOTES,'UTF-8')?>" autocomplete="off" /></label>
				<label class="social-field"><span>Client Secret</span><input type="password" name="secret_<?php echo $providerKey?>" value="" autocomplete="new-password" placeholder="<?php echo !empty($d['social']['secret_'.$providerKey])?'저장됨 · 변경할 때만 입력':'입력 필요'?>" /></label>
				<div class="social-callback"><span>Callback URL</span><code><?php echo htmlspecialchars($socialCallback.$providerKey,ENT_QUOTES,'UTF-8')?></code></div>
			</div>
		</section>
	<?php endforeach?>
	</div>

	<div class="social-submit">
		<input type="submit" value="설정 저장" class="btnblue" />
		<a class="social-admin-link" href="<?php echo $g['s']?>/?r=<?php echo $r?>&amp;m=admin&amp;module=social">소셜링크 관리자 열기</a>
	</div>
</form>

<script type="text/javascript">
function socialConfigCheck(f)
{
	getIframeForAction(f);
	return confirm('소셜 로그인 설정을 저장하시겠습니까?');
}
</script>
<?php endif?>
