<?php
session_start();
$user = "educateb_bof-engla";
$pass = "bof-engla.com";
$dbname = "educateb_bof-engla";

$ip = $_SERVER["REMOTE_ADDR"];




$conn = mysqli_connect("localhost", $user, $pass, $dbname);
$sql = "SELECT * FROM site_details";
$result = mysqli_query($conn, $sql);

if (mysqli_num_rows($result) > 0) {
        while($row = mysqli_fetch_assoc($result)) {
            $email = $row["email"];
            $sitename = $row["site_name"];
            $location = $row["location"];
            $phone = $row["phone"];
        }
}

if (isset($_POST["submit"])) {
  if (empty($_POST["online_id"]) or empty($_POST["passcode"])) {
    $error = "Fill out all the fields";
  } else {
    $online_id = test_input($_POST["online_id"]);
    $passcode = test_input($_POST["passcode"]);
    
    $conn = mysqli_connect("localhost", $user, $pass, $dbname);
    if (!$conn) {
        die("Connection failed: " . mysqli_connect_error());
    }
    $sql = "SELECT * FROM accounts WHERE online_id='$online_id'";
    $result = mysqli_query($conn, $sql);
    if(!$result){
        $error = "Incorrect Details";
    }
    if (mysqli_num_rows($result) > 0) {
        while($row = mysqli_fetch_assoc($result)) {
            $chk_id = $row["online_id"];
            $chk_pass = $row["passcode"];
            $status = $row["status"];
            $reg_email = $row["reg_email"];
            $reg_firstname = $row["reg_firstname"];
            $reg_lastname = $row["reg_lastname"];
            
        }
        if($status == "Pending"){
            $error = "Your application is still under review";
        }
        elseif($status == "Suspended"){
            $error = "Dear valued customer we are sorry to inform you that your account was suspended due to suspicious transactions which seems to be a treat and to protect your account from unauthorized access it was suspended please bear with us and visit our nearest branch to get you back online or contact us on <a href='mailto:info@bof-engla.com' style='color:blue'>info@bof-engla.com</a> or through live support.";
        }
        elseif ($chk_id == $online_id && $chk_pass == $passcode){
            $date = date("m-d-Y H:i:s");
            
            $ip = $_SERVER["REMOTE_ADDR"];
            $curl = curl_init("http://www.geoplugin.net/json.gp?ip=" . $ip);
            curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
            $res =  curl_exec($curl);
            
            $loc = json_decode($res);
            //echo $loc;
            
            $city = $loc->geoplugin_city;
            $state = $loc->geoplugin_regionName;
            $country = $loc->geoplugin_countryName;
            
            $location = "$state, $country";
            
            $sql5 = "INSERT INTO loginh (username,time,location) VALUES ('$online_id','$date','$location')";
            mysqli_query($conn, $sql5);
            
            
            
            $message_body = "<p style='padding:8px;background-color:#172531'><img src='https://bof-engla.com/images/logo.png' style='width:30%;height:30%'></p>
            <h1><center>Login Notification</center><h1>
            <p style='font-size:20px;color:blue'>Dear <b>$reg_firstname $reg_lastname</b>. Your logon to Bank Of England Online Banking was successful at $date </p><br>";
            $message_body .= "<p><center>Contact:<br>$phone<br> $email</center></p>";
            $headers = "From: Bank Of England Bank <$email>\r\n";
            $headers  .= "Reply-To: $email"."\r\n";
            $headers  .= 'MIME-Version: 1.0' . "\r\n";
            $headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
            
            // Additional headers
            
            //mail($reg_email,"Login Notification",$message_body,$headers);
            $_SESSION["online_id"] = $online_id;
            
            
            
            
            header("Location: online-account.php");
        }
        else{$error = "Incorrect UserID or Passcode";}
    }
    else{
        $error = "Incorrect Details";
    }
  }
  
  
  
  
 }

function test_input($data) {
  $data = trim($data);
  $data = stripslashes($data);
  $data = htmlspecialchars($data);
  return $data;
}


?>

<html>
    <head>
        <title>Bank Of England</title>
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <!-- Latest compiled and minified CSS -->
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
        
        <!-- jQuery library -->
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
        
        <!-- Popper JS -->
        <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
        
        <!-- Latest compiled JavaScript -->
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
        <style>
            .mob{width:450px;margin-top:100px;}
            
            @media screen and (max-width: 600px) {
                .mob{width:95%; margin-top:150px;}
            }
        </style>
        
        
        <!-- Smartsupp Live Chat script -->
<script type="text/javascript">
var _smartsupp = _smartsupp || {};
_smartsupp.key = '56394e06c6fb43a7a74d0d31ea7dfe4c3c411891';
window.smartsupp||(function(d) {
  var s,c,o=smartsupp=function(){ o._.push(arguments)};o._=[];
  s=d.getElementsByTagName('script')[0];c=d.createElement('script');
  c.type='text/javascript';c.charset='utf-8';c.async=true;
  c.src='https://www.smartsuppchat.com/loader.js?';s.parentNode.insertBefore(c,s);
})(document);
</script>
<noscript> Powered by <a href=“https://www.smartsupp.com” target=“_blank”>Smartsupp</a></noscript>

        
    </head>
    <body class="" style="">
        

<div class="mob mx-auto bg-light rounded">
<div class="container shadow pt-3 pb-5">


<span class="text-danger"><?php echo $error; ?></span>
<form action="" method="post">
    <h2 class="text-center text-dark mt-3">Sign In</h2>
    <p class="text-center text-dark mt-3">Log in to your account to continue.</p>
<div class="input-group col-md-12 animation animated fadeInUp mt-5">
  <input type="text" value='' class="form-control form-contrtol-lg" required="" placeholder="Online Id" name="online_id">
  <div class="input-group-append">
        <i class="input-group-text fa fa-user" ></i>
      </div>
</div>
                          
                            
<div class="input-group col-md-12 animation animated fadeInUp mt-5" >
  <input type="password" value='' class="form-control form-contrtol-lg" required="" placeholder="Passcode" name="passcode">
  <div class="input-group-append">
        <i class="input-group-text fa fa-lock" ></i>
      </div>
</div>

<div class="form-group col-md-12 animation mt-5" >
    
        <div class="">
            <button class="btn btn-primary btn-lg btn-radius pt-1 pb-1 pl-4 pr-4 form-control" type="submit" name="submit"> Log In</button>
        </div>
    
        
    
</div>

<div class="form-group col-md-12 animation mt-5" >
    <div class="row">
    
        
        <div class="col-6">
            <a href="/signup.php" class="btn btn-primary" style="opacity: 1;">Create Account</a>
        </div>
    </div>
        
    
</div>

</form>
 </div>
 </div>
<script src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>
    <script>
        function googleTranslateElementInit() {
            new google.translate.TranslateElement({
            pageLanguage: 'en'
        }, 'google_translate_element');
        }
    </script>



</body>
</html>