<?php
 if($row!=-1 && $row['is_enabled']!='0'){ 
		
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $object=new class_setting($database);
        $filter='login_type=16 and domain_id='.VIS_DOMAIN;
        $rowfb=$object->get_single_login_details($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);		
		
		$appid 	  = $rowfb[0]['host_name'];
		$appsecret  = $rowfb[0]['user_name'];
		$callback_url  = $rowfb[0]['db_password'];		
		require_once './plugins/fb_login/fbConfig.php';	
		
		$loginURL = $helper->getLoginUrl($redirectURL, $fbPermissions);
?>  
	
 <?php }
if($row2!=-1 && $row2['is_enabled']!='0'){
########## Google Settings.. Client ID, Client Secret from https://cloud.google.com/console #############
	$google_client_id 		= $row2['host_name'];
	$google_client_secret 	= $row2['user_name'];
	$google_redirect_url 	 = $row2['db_password']; //path to your script
	$google_developer_key 	= $row2['db_name'];
################################################################### 

//include google api files
	include(VIS_PATH_PLUGINS.'gmail_login/src/Google_Client.php');
	include(VIS_PATH_PLUGINS.'gmail_login/src/contrib/Google_Oauth2Service.php');
	$gClient = new Google_Client();
	$gClient->setApplicationName('Login to vision.com');
	$gClient->setClientId($google_client_id);
	$gClient->setClientSecret($google_client_secret);
	$gClient->setRedirectUri($google_redirect_url);
	$gClient->setDeveloperKey($google_developer_key);
	
	$google_oauthV2 = new Google_Oauth2Service($gClient);
	
	//For Guest user, get google login url
	$authUrl = $gClient->createAuthUrl();
}

if($row5!=-1 && $row5['is_enabled']!='0'){
//sso windows/office 365
?>
<script src="https://secure.aadcdn.microsoftonline-p.com/lib/1.0.12/js/adal.min.js"></script>

<script>
  var ADAL = new AuthenticationContext({
      instance: 'https://login.microsoftonline.com/',
      tenant: '<?php echo $row5['user_name']; ?>', //COMMON OR YOUR TENANT ID

      clientId: '<?php echo $row5['host_name']; ?>', //This is your client ID
      redirectUri: '<?php echo $row5['db_password']; ?>', //This is your redirect URI

      callback: userSignedIn,
      popUp: true
  });

  function signIn() {
      ADAL.login();
  }

  function userSignedIn(err, token) {
      console.log('userSignedIn called');
      if (!err) { 
          //console.log("token: " + token);		  
          showWelcomeMessage();
      }
      else {
          console.error("error: " + err);
      }
  }

  function showWelcomeMessage() {
      var user = ADAL.getCachedUser(); 
      //var divWelcome = document.getElementById('WelcomeMessage');
      divWelcome = "Welcome " + user.profile.name+" --"+user.userName+"----"+user.profile.unique_name; 
	  //console.log("divWelcome: " + divWelcome);		
	  //alert(JSON.stringify(user));
	  set_cook(user.profile.name,user.userName,user.profile.unique_name,user.profile.oid);
	  //ADAL.logOut();
  }
  /* //url: 'http://iamdemo.com/vision4/amoln/nicolas/index.php?/client/windows_login',
		url: 'index.php',
        dataType: 'json',*/
  function set_cook(profile_name,userName,unique_name,oid){ 
		$.ajax({       
		url: 'index.php',
        //dataType: 'json',	
        data: {'vis_module':'client', 'vis_operation':'windows_login','profile_name':profile_name,'userName':userName,'unique_name':unique_name,'oid':oid},
        type: "POST",
        success: function(data) {  //alert(data);			
			window.location.reload();
           // $("#ajax_subcategory").html(data);
        } 
    });
  }

</script>
<?php } ?>