<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
global $server;
$country = getVisitorCountry();
global $LANG;

if(isset($_GET['ref']) && !empty($_GET['ref'])) {
	$referrer = mysqli_real_escape_string($server,$_GET['ref']);
	mysqli_query($server, "UPDATE  `users` SET  `refered_visits` =  `refered_visits`+'1' WHERE `referrer` = '$referrer'");
} 
?>
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title><?php echo $siteName = getSetting('businessName');?> | <?=$LANG['Log in']?></title>
  <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
  <meta name="google-signin-client_id" content="<?=getSetting('GOOGLE_OAUTH_CLIENT_ID')?>.apps.googleusercontent.com">
  <!-- Styles -->
    <link href="http://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
	<link href="assets/css/font-awesome.min.css" rel="stylesheet" type="text/css" />
    <link href="assets/plugins/material-preloader/css/materialPreloader.min.css" rel="stylesheet">        
	<link href="assets/plugins/sweetalert/sweetalert.css" rel="stylesheet" type="text/css"/> 
   <!-- Theme Styles -->
   <link href="assets/css/alpha.min.css" rel="stylesheet" type="text/css"/>
         
  <link rel="stylesheet" href="bootstrap/css/bootstrap.min.css">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.5.0/css/font-awesome.min.css">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/ionicons/2.0.1/css/ionicons.min.css">
  <link rel="stylesheet" href="dist/css/AdminLTE.min.css?<?=time()?>">
  <link rel="stylesheet" href="plugins/iCheck/square/blue.css">

  <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
  <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
  <!--[if lt IE 9]>
  <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
  <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
  <![endif]-->
  <style>
 .login-box,.register-box, .btn .primary {border: 3px solid <?=getSetting('headerColor')?>; background: <?=getSetting('headerColor')?>;}
 body, .login-page {background: url(files/temp/<?=getSetting('siteBackground')?>);}
.dropdown { position: absolute; display: inline-block; top: 5px; right: 7px; }
.dropdown span{ color: #fff; background: #000; padding: 3px 10px; font-size: 13px; font-weight: bold; border: 1px solid #fff; }
.dropdown-content {  display: none;  position: absolute; right: 1px;  background-color: #ffffff;  min-width: 160px;   padding: 7px 16px;  z-index: 1999; }

.dropdown:hover .dropdown-content {
    display: block;
}
.site-logo {
	width: 99.99%;
	padding: 40px 0;
	padding-bottom: 15px;
	text-align: center;
}
.site-logo img {
	width: 80%;
	display:block;
    margin:auto;
	max-width: 210px;
}
@media (min-width:961px)  { .site-logo {padding-bottom: 0px;} }
@media (min-width:1025px) { .site-logo {padding-bottom: 0px;} }
@media (min-width:1281px) { .site-logo {padding-bottom: 0px;} }
</style>
</head>
<?php
$Config = new CI_Config();
$server=mysqli_connect($Config->db_host(), $Config->db_username(), $Config->db_password());
$db=mysqli_select_db($server, $Config->db_name()); 


$boxTitle = $LANG['Sign In'];
if(isset($_REQUEST['join'])) {
	$boxTitle = $LANG["Sign Up"];
}
if(isset($_REQUEST['reset'])) {
	$boxTitle = $LANG["Reset Password"];
}
if(isset($_REQUEST['verify'])) {
	$boxTitle = $LANG["Activate Account"];
}
?>
<body class="hold-transition login-page"> 
<div class="dropdown">
  <span><i class="fa fa-language"></i> Change Language</span>
  <div class="dropdown-content">
    <?=loadLanguages()?>
  </div>
</div>  

<div class="site-logo"><img src="files/temp/<?=getLogo()?>" /></div>

<div class="login-box">
  <div class="login-logo" style="">
    <strong><a href=""><?php echo $boxTitle;?></a></strong>
  </div>
  
  <!-- /.login-logo -->
 <?php if(isset($_GET['reset'])) { ?>
  <div class="login-box-body">
    <form action="index.php" id="reset-form" method="post">
    <p class="login-box-msg"><?=$LANG['PLease enter your account email to get a new password']?></p>
	
      <div class="form-group has-feedback">
        <input type="email" name="userEmail" id="emaila" class="form-control" placeholder="<?=$LANG['Email Address']?>">
        <span class="glyphicon glyphicon-envelope form-control-feedback"></span>
      </div>
      <div class="row">
        <div class="col-xs-2">
        </div>
        <div class="col-xs-8">
          <button type="submit" id="reset-button" class="btn btn-info btn-block btn-flat"><?=$LANG['Recover Password']?></button>
          <span id="login-spin" class="spinners" style="display: none;"><i class="fa fa-spinner fa-spin"></i> <strong><?=$LANG['Please wait']?>...</strong></span>
        </div>
      </div>
       <div class="row">
        <div class="col-xs-8">
          <div class="checkbox icheck">
         <?=$LANG['Want to try login again']?>? <a href="index.php"><strong><?=$LANG['Sign In']?></strong></a>
         </div>
        </div>
       </div>  
    </form>
<?php } elseif(isset($_GET['verify'])) { ?>
  <div class="login-box-body">
    <form action="index.php" id="verify-form" method="post">
     <?php if (isset($_GET['error'])) { ?>
     <p class="login-box-msg" style="color: red;"><?=$LANG['Sorry but your verification token is invalid. Please use the exact link sent to your email address or enter your email address to get a new one']?>.</p>
     <?php } else if (isset($_GET['error2'])) { ?>
     <p class="login-box-msg" style="color: red;"><?=$LANG['Sorry but we couldn\'t find your account. Please check your email address and try again']?>.</p>
     <?php } else if (isset($_GET['error3'])) { ?>
     <p class="login-box-msg" style="color: green;"><?=$LANG['We have just sent a new verification link to your email address']?>.</p>
     <?php }else { ?>
    <p class="login-box-msg"><?=$LANG['Enter your registered email address to get a new link']?></p>
	<?php } ?>
      <div class="form-group has-feedback">
        <input type="number" name="verif_email" class="form-control" placeholder="<?=$LANG['Email Address']?>">
        <span class="glyphicon glyphicon-envelope form-control-feedback"></span>
      </div>
      <div class="row">
        <div class="col-xs-2">
        </div>
        <div class="col-xs-8">
          <button type="submit" class="btn btn-primary btn-block btn-flat"><?=$LANG['Resend Link']?></button>
        </div>
        <!-- /.col -->
       </div>
    </form>
 <?php } elseif(isset($_GET['join'])) { ?>
  <div class="login-box-body">
    <form id="register-form"> 
      <p class="login-box-msg" style="color: red; display: none;"></p>
      <div class="form-group has-feedback">
        <input type="text" name="first_name" id="first_name" required id="register-form" class="form-control" placeholder="<?=$LANG['First Name']?>">
        <span class="glyphicon glyphicon-user form-control-feedback"></span>
      </div>
      
      <div class="form-group has-feedback">
        <input type="text" name="last_name" id="last_name" required class="form-control" placeholder="<?=$LANG['Last Name']?>">
        <span class="glyphicon glyphicon-user form-control-feedback"></span>
      </div>
      
       <div class="form-group has-feedback">
        <input type="email" name="email" required id="email" value="<?=@$_REQUEST['email']?>" class="form-control" placeholder="<?=$LANG['Email Address']?>">
        <span class="glyphicon glyphicon-envelope form-control-feedback"></span>
      </div>

      <div class="form-group has-feedback">
        <input type="text" name="phone" required id="phone" class="form-control" placeholder="<?=$LANG['Phone Number']?>">
        <span class="glyphicon glyphicon-phone form-control-feedback"></span>
      </div>
            
      <div class="form-group has-feedback">
        <select name="country_id" required id="country" class="form-control">
        	<option disabled ><?=$LANG['Select your country']?></option>
        	<?=getCountryList($country)?>
        </select>
        <span class="glyphicon glyphicon-globe form-control-feedback"></span>
      </div>
      
       <div class="form-group has-feedback">
        <input type="password" id="password1" required name="password" class="form-control" placeholder="<?=$LANG['Choose A Password']?>">
        <span class="glyphicon glyphicon-lock form-control-feedback"></span>
      </div>
      
      <div class="form-group has-feedback">
        <input type="password" id="password2" required name="password2" class="form-control" placeholder="<?=$LANG['Re-type Password']?>">
        <span class="glyphicon glyphicon-lock form-control-feedback"></span>
      </div>
      <?php if(!empty(getSetting('google_recaptcha_sitekey',0))) {?>
       <div class="form-group" style="overflow-x: hidden;"><?php echo get_recaptcha_button(); ?></div> 
      <?php }?> 
      <div class="row">
        <div class="col-xs-2">
        </div>
        <div class="col-xs-8">
           <div id="reset" style="display: none"><button type="button" id="reset2" class="btn btn-disabled btn-block btn-flat"><?=$LANG['Sign-in']?></button></div>
          <input type="hidden" name="join">
          <button type="submit" id="register-button" class="btn btn-success btn-block btn-flat"><?=$LANG['Create Account']?></button>
          <span id="login-spin" class="spinners" style="display: none;"><i class="fa fa-spinner fa-spin"></i> <strong><?=$LANG['Please wait']?>...</strong></span>
        </div>
        <!-- /.col -->
       </div>
    </form>
    <?=$LANG['Already have an account']?>? <a href="index.php"><strong><?=$LANG['Sign In']?></strong></a><br>
 <?php } elseif(isset($_POST['verif_email'])) { 
		foreach ($_POST as $key => $value ){
			${$key} = $value = mysqli_real_escape_string($server,$value);
		}
		
	  	$query="SELECT * FROM users WHERE email = '$verif_email'"; 
		$result = mysqli_query($server,$query);  
		$row = mysqli_fetch_assoc($result); 
		$num = mysqli_num_rows($result);
		if($num < 1) {
			header('location: index.php?verify&error2=1');	
		} else {
			$track = $row['email_verified'];
			$mail = "<h2 align='center'>Verify your email address</h2>";
			$mail .= "<hr>";
			$mail .= "<p align='center'>In order to start using your ".getSetting('businessName')." account, you need to confirm your email address.</p>";
			$mail .= '<p align="center"><a href="'.home_base_url().'?vf='.$track.'"><button style="margin: 5px auto; border: 0; color: white; padding: 10px; background: #036" >Very Email Address</button></a></p>';
			$mail .= "<hr><p align='center'>If you did not sign up for this account, you can ignore this email and the account will be deleted.</p>";
			$sender = getSetting('businessName');
			$subject = "Please Verify Your Email Address";
			$from = getSetting('smtpUsername');
			sendEmail($from,$sender,$subject,$email,$mail);
			header('location: index.php?verify&error3=1');	
		}
 } elseif(isset($_GET['vf'])) { 
	foreach ($_GET as $key => $value ){
		${$key} = $value = mysqli_real_escape_string($server,$value);
	}
  	$query="SELECT * FROM users WHERE email_verified = '$vf'"; 
	$result = mysqli_query($server,$query);  
	$row = mysqli_fetch_assoc($result); 
	$num = mysqli_num_rows($result);
	if($num < 1) {
		header('location: index.php?verify&error=1');	
	} else {
		$user_id = $row['id'];
		mysqli_query($server, "UPDATE  `users` SET  `email_verified` =  '0' WHERE `id` = '$user_id'");
		logEvent($user_id,' Account activation was completed');
		createNotice($user_id,"Welcome to ".getSetting('businessName').". Remember to setup your Account Preferences!");
		//login user 
		$_SESSION['MOBIKETA'] = md5($row['email'].'%'.$row['password']);
		setcookie("MOBIKETA", $user_id, $timeout, '/'); 
		$day = time();
		logEvent($user_id,'Logged into '.getSetting('businessName'));
		mysqli_query($server, "UPDATE  `users` SET  `last_login` =  '$day' WHERE `id` ='$user_id'");
		$ip = getUserIP();
		mysqli_query($server, "UPDATE  `users` SET  `last_ip` =  '$ip' WHERE `id` ='$user_id'");
		header('location: index.php?dologin');	
	}
} else { ?>
  <div class="login-box-body">
    <form action="index.php"  id="login-form" method="post">
  	<p class="login-box-msg" style="color: red; display: none;"></p>
      <div class="form-group has-feedback">
        <input type="email" name="access_login" class="form-control" id="emails" placeholder="<?=$LANG['Email']?>">
        <span class="glyphicon glyphicon-user form-control-feedback"></span>
      </div>
      <div class="form-group has-feedback">
        <input type="password" name="access_password" class="form-control" id="password" placeholder="<?=$LANG['Password']?>">
        <span class="glyphicon glyphicon-lock form-control-feedback"></span>
      </div>
      <div class="row">
        <div class="col-xs-7">
          <div class="checkbox icheck">
            <label>
              <a href="index.php?reset"><?=$LANG['Lost your Password']?>?</a>
            </label>
          </div>
        </div>
        <div class="col-xs-5">
          <button type="submit" id="login-button" class="btn btn-info btn-block btn-flat"><?=$LANG['Sign In']?></button>
          <span id="login-spin" class="spinners" style="display: none;"><i class="fa fa-spinner fa-spin"></i> <strong><?=$LANG['Please wait']?>...</strong></span>
        </div>
      </div>
     <?php if(!empty(getSetting('facebook_api',0))) {?>
      <div class="row">      	
        <div class="col-xs-12">
          <button type="button" onclick="fbLogin()" id="fb-login" class="btn btn-primary btn-block btn-flat"><i class="fa fa-facebook"></i> <?=$LANG['Sign-in with Facebook']?></button>
          <span id="fb-spin" class="spinners" style="display: none;"><i class="fa fa-spinner fa-spin"></i> <strong><?=$LANG['Please wait']?>...</strong></span>
        </div>
      </div>
      <?php } else { ?>
      <br>
      <?php } ?>
      <?php if(!empty(getSetting('GOOGLE_OAUTH_CLIENT_ID',0))) {?>
       <div class="row">  
        <div class="col-xs-12">
          <button type="button" id="go-login" class="btn btn-danger btn-block btn-flat" 
          		data-scope="https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/userinfo.email"
                data-requestvisibleactions="http://schemas.google.com/AddActivity"
                data-clientId="<?=getSetting('GOOGLE_OAUTH_CLIENT_ID',0)?>.apps.googleusercontent.com"
                data-accesstype="offline"
                data-callback="mycoddeSignIn"
                data-theme="dark"
                data-cookiepolicy="single_host_origin"><i class="fa fa-google-plus"></i> <?=$LANG['Sign-in with Google']?></button>
          <span id="go-spin" class="spinners" style="display: none;"><i class="fa fa-spinner fa-spin"></i> <strong><?=$LANG['Please wait']?>...</strong></span>
        </div>
      </div>
      <?php } else {?>
      <br>
      <?php } ?>
    </form>
    <?=$LANG['New to']?> <?=getSetting('businessName')?>? <a href="index.php?join"><b><?=$LANG['Sign Up']?></b></a><br>
<?php } ?>
  </div>
  <!-- /.login-box-body -->
</div>
<!-- /.login-box -->

<script src="plugins/jQuery/jQuery-2.2.0.min.js"></script>
<script src="bootstrap/js/bootstrap.min.js"></script>
<script src="plugins/iCheck/icheck.min.js"></script>

<script src="assets/plugins/materialize/js/materialize.min.js"></script>
<script src="assets/plugins/material-preloader/js/materialPreloader.min.js"></script>
<script src="assets/plugins/sweetalert/sweetalert.min.js"></script>
<script src="assets/plugins/jquery-blockui/jquery.blockui.js"></script>
<script src="assets/plugins/google-code-prettify/prettify.js"></script>
<?php if(!isset($_GET['join'])) { echo '<script src="assets/js/alpha.min.js"></script>'; } ?>
<?php if(!empty(getSetting('google_recaptcha_sitekey',0))) {?>
<?php echo get_recaptcha_script() ?>
<?php } ?>
<script>
  $(function () {
    $('input').iCheck({
      checkboxClass: 'icheckbox_square-blue',
      radioClass: 'iradio_square-blue',
      increaseArea: '20%' // optional
    });
  });
  
$("#email").blur(function(){
 	$.ajax({
       type        : 'POST', 
       url         : 'API?checkUser='+$('#email').val(),
       data        : '', 
       dataType    : 'json',
       encode      : true
   }).done(function(data) {
       if ( ! data.success) {
			if (data.errors) {
				$('.login-box-msg').text('<?=$LANG['Sorry but your email address is already registered. Please login or use a different one']?>');
				$('.login-box-msg').css('color', 'red');
				$('.login-box-msg').show('slow');
				swal("Oops!", '<?=$LANG['Sorry but your email address is already registered. Please login or use a different one']?>', "warning");
				$("#submit").hide();
				$("#reset").show();
			}
		} else {
			$("#submit").show(); 
			$("#reset").hide(); 
		}
    }).fail(function (jqXHR,status,err) {
	});	 
});

$("#password2").blur(function(){ 
	var pass1 = document.getElementById('password1').value;
	var pass2 = document.getElementById('password2').value;
  if (pass1 == pass2) {
	    $('.login-box-msg').hide('slow');
	   	$("#submit").show(); 
		$("#reset").hide();
	} else {
		$('.login-box-msg').text('<?=$LANG['Your password fields does not match']?>.');
		$('.login-box-msg').css('color', 'red');
		$('.login-box-msg').show('slow');
		$("#submit").hide();
		$("#reset").show();
  }
}) 

  $('#login-form').submit(function(event) { 
		$('#login-button').hide();
		$('#login-spin').show();
        var formData = {
            'access_login'    		: $('#emails').val(),
            'access_password'     	: $('#password').val()
        };
        $.ajax({
            type        : 'POST', 
            url         : 'API',
            data        : formData, 
            dataType    : 'json',
            encode      : true
        }).done(function(data) { 
			//var data = JSON.parse(data);
            if ( ! data.success) {
				if (data.errors) {
					swal("Oops!", data.errors, "warning");
					$('#login-button').show();
					$('#login-spin').hide();
				}
			} else {
				window.location = 'index.php'; 
			}
            }).fail(function (jqXHR,status,err) { 
				swal("Oops!", '<?=$LANG['Login failed']?>! '+err, "warning");
				$('#login-button').show();
				$('#login-spin').hide();
			});
        event.preventDefault();
    });	

//reser pass
  $('#reset-form').submit(function(event) { 
		$('#reset-button').hide();
		$('#login-spin').show();
        var formData = {
            'userEmail'     	: $('#emaila').val(),
            'reset'    		: '1'
        };

        $.ajax({
            type        : 'POST', 
            url         : 'API',
            data        : formData, 
            dataType    : 'json',
            encode      : true
        }).done(function(data) {
            if ( ! data.success) {
				if (data.errors) {
					swal("Oops!", data.errors, "warning");
					$('#reset-button').show();
					$('#login-spin').hide();
				}
			} else {
				alert('<?=$LANG['We have reset your account password. A new one has been sent to your email address']?>.');
				window.location = 'index.php?rst'; 
			}
            }).fail(function (jqXHR,status,err) {
				swal("Oops!", '<?=$LANG['Request failed']?>! '+err, "warning");
				$('#reset-button').show();
				$('#login-spin').hide();
			});
        event.preventDefault();
    });	
	
//register
  $('#register-form').submit(function(event) {
        event.preventDefault();	  
		$('#register-button').hide();
		$('#login-spin').show();
		<?php if(!empty(getSetting('google_recaptcha_sitekey',0))) {?>
		var v = grecaptcha.getResponse();
		if(v.length == 0){
			swal("Oops!", "<?=$LANG['Captcha validation failed, we need to be sure you\'re a human']?>", "warning");
			$('#register-button').show();
			$('#login-spin').hide();
			return false;
		} else {
			$('.login-box-msg').hide('slow');
			//keep working
		}
		<?php } ?>
        var formData = {
            'first_name'  : $('#first_name').val(),
			'last_name'  : $('#last_name').val(),
            'email'    : $('#email').val(),
			'phone'  : $('#phone').val(),
			'country_id'  : $('#country').val(),
			'password'  : $('#password1').val(),
			'password2'  : $('#password2').val(),
			'join'	: '1'
        };

        $.ajax({
            type        : 'POST', 
            url         : 'API',
            data        : formData, 
            dataType    : 'json',
            encode      : true
        }).done(function(data) {
            if ( ! data.success) { 
				if (data.errors) {
					swal("Oops!", data.errors, "warning");
					$('#register-button').show();
					$('#login-spin').hide();
				}
			} else { 
				window.location = 'index.php?joined'; 
			}
            }).fail(function (jqXHR,status,err) {
				swal("Oops!", '<?=$LANG['Sign-up failed']?>! '+err, "warning");
				$('#register-button').show();
				$('#login-spin').hide();
			});
    });		

<?php if(isset($_GET['dologin'])) { ?>
	swal("Done!", '<?=$LANG['You have successfully verified your email address. Enjoy!']?>! ', "success");
<?php } ?>

<?php	
if(isset($_GET['joined'])) {
	$message = $LANG['Your account is almost ready. Follow the instructions sent to your email address to activate your account'];
	echo '$(document).ready(function(){';
	echo 'swal("Congratulations", "'.$message.'", "success");';
	echo '});';
}
?>	
<?php	
if(isset($_GET['rst'])) {
	$message = $LANG['We have sent a new password to your email address. Use it to login and set a new password'];
	echo '$(document).ready(function(){';
	echo 'swal("Great!", "'.$message.'", "success");';
	echo '});';
}
?>	

<?php if(!empty(getSetting('facebook_api',0))) {?>
//Facebook Login
window.fbAsyncInit = function() {
    FB.init({
      appId      : '<?=getSetting('facebook_api',0)?>', 
      cookie     : true,  
      xfbml      : true,  
      version    : 'v2.8' 
    });
    
    FB.getLoginStatus(function(response) {
        if (response.status === 'connected') {}
    });
};

(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/en_US/sdk.js";
    fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));

function saveUserData(response){
	 var formData = {
		'facebook_auth'	:	'011',
		'userData'  	: 	JSON.stringify(response)
	 };
	
	 $.ajax({
		type        : 'POST', 
		url         : 'API',
		data        : formData, 
		dataType    : 'json',
		encode      : true
	}).done(function(data) { 
		window.location = 'index.php?1'; 
		return true;
    }).fail(function (jqXHR,status,err) { 
		swal("Oops!", '<?=$LANG['Authentication failed! Please try again later']?>', "warning");
		$('#fb-login').show('slow');
		$('#fb-spin').hide();
	});
}
		
function fbLogin() {
	$('.login-box-msg').hide('slow');
	$('#fb-login').hide('slow');
	$('#fb-spin').show();
    FB.login(function (response) {
        if (response.authResponse) {
            getFbUserData();
			window.location = 'index.php?1'; 
        } else {
			swal("Oops!", '<?=$LANG['Authentication failed! Please login to your Facebook account and try again']?>', "warning");
			$('#fb-login').show('slow');
			$('#fb-spin').hide();
        }
    }, {scope: 'email'});
}

function getFbUserData(){ 
    FB.api('/me', {locale: 'en_US', fields: 'id,first_name,last_name,email,link,gender,locale,picture'},
    function (response) { 
		saveUserData(response);
    });
}

function fbLogout() {
    FB.logout(function() {
        //to be done later
    });
}
<?php } ?>

<?php if(!empty(getSetting('GOOGLE_OAUTH_CLIENT_ID',0))) {?>
	$('#go-login').click(function() {
		$('.login-box-msg').hide('slow');
		$('#go-login').hide('slow');
		$('#go-spin').show();
	});
	
  (function() {
    var po = document.createElement('script');
    po.type = 'text/javascript'; po.async = true;
    po.src = 'https://plus.google.com/js/client:plusone.js';
    var s = document.getElementsByTagName('script')[0];
    s.parentNode.insertBefore(po, s);
  })();

	var gpclass = (function(){ 
		var response = undefined;
		return {
			//Class functions / Objects
			mycoddeSignIn:function(response){
				// The user is signed in
				if (response['access_token']) {
					//Get User Info from Google Plus API
					gapi.client.load('plus','v1',this.getUserInformation);
				} else if (response['error']) {
					swal("Oops!", '<?=$LANG['Authentication failed! Please login to your Google account and try again']?>', "warning");
					$('#go-login').show('slow');
					$('#go-spin').hide();
				}
			},
			
			getUserInformation: function(){
				var request = gapi.client.plus.people.get( {'userId' : 'me'} );
				request.execute( function(profile) {
					var email = profile['emails'].filter(function(v) {
						return v.type === 'account'; // Filter out the primary email
					})[0].value;
					var fName = profile.displayName;
					var id = profile.id;
					//we will complete this in future version
				});
			}
		}; //End of Return
    })();
    
    function mycoddeSignIn(gpSignInResponse){
        gpclass.mycoddeSignIn(gpSignInResponse);
    }
<?php } ?>
</script>

</body>
</html>

<?php 
if(isset($_GET['1'])) header('location: index.php');
mysqli_close($server); die() 
?>