

<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<div id="status">
</div>

<? if(!$_SESSION['b_email']){
    //echo $naver->login(array("width"=>"200"));?>
<div id=b_fblogin>
    <fb:login-button scope="public_profile,email" onlogin="checkLoginState();">페이스북으로 로그인</fb:login-button>
</div>

<?}?>


<a href="<?=$path?>/manager.php">관리자</a>
<a href="#" class="fblogout">LOGOUT</a>
</div>



<script>
function notLogin(){
    document.getElementById('status').innerHTML = '이벤트에 참여하시려면 <font style="color:#4c69ba;font-weight:bold;">>페이스북</font> 또는 <font style="color:#22b600;font-weight:bold;">네이버아이디</font>로 로그인 해주세요.';
    $('#b_event').css('display','none');
}
//로그인시 화면
function okLogin(mb_email,mb_name,mb_picture,mb_type){
    document.f1.fb_id.value = mb_email;
    document.f1.mb_name.value = mb_name;
    document.f1.mb_type.value = mb_type;
    document.f1.mb_picture.value = mb_picture;
    document.getElementById('status').innerHTML = mb_name + '님으로 로그인되었습니다.('+mb_type+')';
    $('#b_event').css('display','block');
    $('#b_fblogin').css('display','none');
    $('.nv_login_btn1').css('display','none');
}




//페이스북 API 기본연결 및 로그인
//https://developers.facebook.com/docs/facebook-login/web
//==================================================================================
  window.fbAsyncInit = function() {
  FB.init({
    appId      : '280686338998871',
    cookie     : true,  // enable cookies to allow the server to access
                        // the session
    xfbml      : true,  // parse social plugins on this page
    version    : 'v2.5' // use graph api version 2.5
  });

  FB.getLoginStatus(function(response) {
<? if(!$_SESSION['b_email']){?>
    statusChangeCallback(response);
<?}else{?>
    okLogin('<?=$_SESSION[b_email]?>','<?=$_SESSION[b_name]?>','<?=$_SESSION[b_image]?>','NAVER');
<?}?>
  });
};


    // Load the SDK asynchronously
  (function(d, s, id){
     var js, fjs = d.getElementsByTagName(s)[0];
     if (d.getElementById(id)) {return;}
     js = d.createElement(s); js.id = id;
     js.src = "//connect.facebook.net/ko_KR/sdk.js";
     fjs.parentNode.insertBefore(js, fjs);
   }(document, 'script', 'facebook-jssdk'));

  // This is called with the results from from FB.getLoginStatus().
  function statusChangeCallback(response) {

    console.log('statusChangeCallback');
    console.log(response);
    // The response object is returned with a status field that lets the
    // app know the current login status of the person.
    // Full docs on the response object can be found in the documentation
    // for FB.getLoginStatus().
    if (response.status === 'connected') {
      // Logged into your app and Facebook.

        var uid = response.authResponse.userID;
        var accessToken = response.authResponse.accessToken;

      testAPI();
    } else if (response.status === 'not_authorized') {
      // The person is logged into Facebook, but not your app.
        notLogin();
    } else {
      // The person is not logged into Facebook, so we're not sure if
      // they are logged into this app or not.
        notLogin();
    }
  }

  // This function is called when someone finishes with the Login
  // Button.  See the onlogin handler attached to it in the sample
  // code below.
  function checkLoginState() {
    FB.getLoginStatus(function(response) {
      statusChangeCallback(response);
    });
  }

  // Here we run a very simple test of the Graph API after login is
  // successful.  See statusChangeCallback() for when this call is made.
  function testAPI() {
    console.log('Welcome!  Fetching your information.... ');
    FB.api('/me',
        { locale: 'ko_KR', fields: 'name, email, picture' },
        function(response) {
            console.log('Successful login for: ' + response.name);
            okLogin(response.email,response.name,response.picture.data.url,'facebook');
        }
    );
  }

  
  
  
</script>