<?php
ob_start();
//error_reporting(0);
session_start();
require_once('../include/dbconnect.php');
if(isset($_GET['signout']))
{
	//session_destroy();
    unset($_SESSION['uid']);
}

$error="";

if( isset($_POST['log']) ) 
{
$uname=$_POST['un'];
$pass=$_POST['pw'];									
$sql="SELECT * FROM users WHERE (email='".mysqli_real_escape_string($conn, $uname)."' and pass='".mysqli_real_escape_string($conn, $pass)."') or (memID='".mysqli_real_escape_string($conn, $uname)."' and pass='".mysqli_real_escape_string($conn, $pass)."')";
$res=mysqli_query($conn,$sql);
$row=mysqli_fetch_array($res);
$count = mysqli_num_rows($res); // if uname/pass correct it returns must be 1 row
		
if($count == 1) 
{
    $id = $row['uID'];
    $tfa = $row['2fa'];
    $acc_status = $row['status'];
    
    if($acc_status == 1){
        $_SESSION['uid'] = $id;
                    
        $dt = date("Y-m-d h:i:s");		
        $sl="update users set LLogin='".$dt."' where uID='".$id."'";
    
        $result=mysqli_query($conn,$sl);
            
        if($tfa == 1){
            $token = chr(rand(97,122))."".rand(1,9)."".chr(rand(97,122))."".rand(1,9)."".rand(11,99);
            $_SESSION['token'] = $token;
            
          echo "<meta http-equiv='refresh' content='3; url=processing.php?request=signin' >";
        }elseif($tfa == 0){
          echo "<meta http-equiv='refresh' content='3; url=processing.php?request=dashboard' >";
        }
        $error = "<p style='color: limegreen;'>Login attempt successful. Redirecting to dashboard...</p>";	
    }else{
        $error = "<p style='color: indianred;'>Failed sign-in attempt. Account Disabled!</p>";	
    }
}else {
	$error = "<span style='color: indianred;'>Failed sign-in attempt. Incorrect credentials!</span>";
}
		
}				
?>	
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1.0, shrink-to-fit=no">
<link href="images/favicon.png" rel="icon" />
<title> Signin Portal </title>

<meta name="author" content="">

<!-- Web Fonts
============================================= -->
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Rubik:ital,wght@0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap">

<!-- Stylesheet
============================================= -->
<link rel="stylesheet" type="text/css" href="vendor/bootstrap/css/bootstrap.min.css" />
<link rel="stylesheet" type="text/css" href="vendor/font-awesome/css/all.min.css" />
<link rel="stylesheet" type="text/css" href="css/stylesheet.css" />
<!-- Colors Css -->
<link id="color-switcher" type="text/css" rel="stylesheet" href="#" />
 


</head>
<body>

<!-- Preloader
<div id="preloader">
  <div data-loader="dual-ring"></div>
</div>
Preloader End -->
<div id="google_translate_element"></div>

<script type="text/javascript">
function googleTranslateElementInit() {
  new google.translate.TranslateElement({pageLanguage: 'en', layout: google.translate.TranslateElement.InlineLayout.HORIZONTAL}, 'google_translate_element');
}
</script>

<script type="text/javascript" src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>
<div id="main-wrapper">
  <div class="container-fluid px-0">
    <div class="row g-0 min-vh-100"> 
      <!-- Welcome Text
      ============================================= -->
      <div class="col-md-6">
        <div class="hero-wrap d-flex align-items-center h-100">
          <div style="background:#0000;" class="hero-mask opacity-8 "></div>
          <div class="hero-bg hero-bg-scroll" style="background-image:url('images/bg/image-3.jpg');"></div>
          <div class="hero-content mx-auto w-100 h-100 d-flex flex-column">
            <div class="row g-0">
              <div class="col-10 col-lg-9 mx-auto">
                <div class="logo mt-5 mb-5 mb-md-0"> <a class="d-flex" href="../" title=""><img src="images/newage.png" style="width: 200px;" alt=""></a> </div>
              </div>
            </div>
            <div class="row g-0 my-auto">
              <div class="col-10 col-lg-9 mx-auto">
                <h1 class="text-11 text-white mb-4">Welcome back!</h1>
                <p class="text-4 text-white lh-base mb-5">We are glad to see you again! Sign In to access your Online Banking portal.</p>
              </div>
            </div>
          </div>
        </div>
      </div>
      <!-- Welcome Text End --> 
      
      <!-- Login Form
      ============================================= -->
      <div class="col-md-6 d-flex align-items-center">
        <div class="container my-4">
          <div class="row g-0">
            <div class="col-11 col-lg-9 col-xl-8 mx-auto">
              <h3 class="fw-400 mb-4">Sign In</h3>
              <p><?php echo $error; ?></p>
              <form id="loginForm" method="post" action="login.php">
                <div class="mb-3">
                  <label for="emailAddress" class="form-label">Email / Login ID</label>
                  <input type="text" name="un" class="form-control" id="emailAddress" required placeholder="Enter Your Email / Login ID">
                </div>
                <div class="mb-3">
                  <label for="loginPassword" class="form-label">Password</label>
                  <input type="password" name="pw" class="form-control" id="loginPassword" required placeholder="Enter Password">
                </div>
                <div class="row mb-3">
                  <div class="col-sm text-end"><a class="btn-link" href="forgot-password.php">Forgot Password ?</a></div>
                </div>
                <div class="d-grid mb-3"><button style="background:#23233f; color:#ffff;" class="btn" name="log" type="submit">Login</button></div>
              </form>
              <p class="text-3 text-center text-muted">Don't have an account? <a style="color:#23233f;" class="btn-link" href="register.php">Sign Up</a></p>
            </div>
          </div>
        </div>
      </div>
      <!-- Login Form End --> 
    </div>
  </div>
</div>

<!-- Back to Top
============================================= --> 
<a id="back-to-top" data-bs-toggle="tooltip" title="Back to Top" href="javascript:void(0)"><i class="fa fa-chevron-up"></i></a> 

<!-- Styles Switcher -->

<!-- Styles Switcher End --> 

<!-- Script --> 
<script src="vendor/jquery/jquery.min.js"></script> 
<script src="vendor/bootstrap/js/bootstrap.bundle.min.js"></script> 
<!-- Smartsupp Live Chat script -->
<!-- Smartsupp Live Chat script -->
<script type="text/javascript">
var _smartsupp = _smartsupp || {};
_smartsupp.key = '28bf529905701ee28207d99d49cd6e736a87a742';
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><!-- Smartsupp Live Chat script -->
<!-- Style Switcher --> 
<script src="js/switcher.min.js"></script> 
<script src="js/theme.js"></script>
</body>
</html>