<?php 
date_default_timezone_set('Asia/Kolkata');
$current_time = date('M d, Y, g:i:s A', time());
?>
<?php 
include('includes/config.php');
if(isset($_SESSION['loggedin']) == true){
  ?>
  <script> 
  window.setTimeout(function() {
  window.location.href = "crs/index";
  }, 1500);
  </script>
  
    <?php
}  
if(isset($_POST['secret']) && $_POST['secret'] == "ahkwebsolutions" && !empty($_POST['username']) && !empty($_POST['password'])){
  $username = mysqli_real_escape_string($conn,$_POST['username']);
  $password = mysqli_real_escape_string($conn,$_POST['password']);

  $res = mysqli_query($conn,"SELECT * FROM `usertable` WHERE phone='$username'  OR emailid='$username' OR userid='$username' ");

  if(mysqli_num_rows($res) == 1 ){
    $userdata = mysqli_fetch_assoc($res);
    $vpass = password_verify($password,$userdata['password']);
    if($vpass){
      if($userdata['status'] == "verified"){
        
        ?>
			<script>
				$(function(){
					Swal.fire(
						'Success!',
						'You Are Logged In Successfully!',
						'success'
					)
				});
			</script>
			<?php
      
      $_SESSION['loggedin'] = true;
      $_SESSION['userid'] = $userdata['userid'];
      $_SESSION['name'] = $userdata['name'];
      $_SESSION['emailid'] = $userdata['emailid'];
      $_SESSION['phone'] = $userdata['phone'];
      $_SESSION['walletamount'] = $userdata['walletamount'];
      $_SESSION['usertype'] = $userdata['usertype'];
     
      ?>
      <script>
      window.setTimeout(function() {
      window.location.href = "crs/index";
      }, 1500);
      </script>
      
        <?php

        // 
      }else{
        ?>
        <script>
          $(function(){
            Swal.fire(
              'Opps!',
              'Your Account is Blocked or inactive Please Contact With Admin',
              'error'
            )
          });
        </script>
        <?php

      }


    }else{
      ?>
      <script>
        $(function(){
          Swal.fire(
            'Opps!',
            'Password Wrong!',
            'error'
          )
        });
      </script>
      <?php
    }

  }else{
    ?>
    <script>
      $(function(){
        Swal.fire(
          'Opps!',
          'Entered username Wrong or Not Exist',
          'error'
        )

      });

    </script>
    <?php
  }



}
?>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login Panel</title>

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.2/css/all.min.css">

<style>
*{
    margin:0;
    padding:0;
    box-sizing:border-box;
    font-family:'Poppins',sans-serif;
}

body{
    display:flex;
    justify-content:center;
    align-items:center;
    min-height:100vh;
    background:linear-gradient(135deg,#0f172a,#1e293b);
}

.login-box{
    width:420px;
    background:#fff;
    border-radius:20px;
    padding:40px;
    box-shadow:0 20px 40px rgba(0,0,0,0.25);
}

.logo{
    text-align:center;
    margin-bottom:25px;
}

.logo h1{
    color:#2563eb;
    font-size:32px;
    font-weight:700;
}

.title{
    text-align:center;
    font-size:24px;
    margin-bottom:25px;
    color:#111827;
}

.input-group{
    position:relative;
    margin-bottom:18px;
}

.input-group input{
    width:100%;
    height:55px;
    border:1px solid #d1d5db;
    border-radius:12px;
    padding:0 50px 0 15px;
    font-size:15px;
    outline:none;
    transition:.3s;
}

.input-group input:focus{
    border-color:#2563eb;
}

.input-group i{
    position:absolute;
    right:18px;
    top:50%;
    transform:translateY(-50%);
    color:#6b7280;
}

.options{
    display:flex;
    justify-content:space-between;
    align-items:center;
    margin-bottom:20px;
    font-size:14px;
}

.options a{
    color:#2563eb;
    text-decoration:none;
}

.login-btn{
    width:100%;
    height:55px;
    border:none;
    border-radius:12px;
    background:#2563eb;
    color:#fff;
    font-size:17px;
    font-weight:600;
    cursor:pointer;
    transition:.3s;
}

.login-btn:hover{
    background:#1d4ed8;
}

.register{
    text-align:center;
    margin-top:20px;
    font-size:14px;
}

.register a{
    color:#2563eb;
    text-decoration:none;
    font-weight:600;
}

.footer-text{
    text-align:center;
    margin-top:15px;
    color:#6b7280;
    font-size:13px;
}
</style>
</head>

<body>

<div class="login-box">

    <div class="logo">
        <h1>Login</h1>
    </div>

    <h2 class="title">General Public Login</h2>

    <form method="POST">

        <div class="input-group">
            <input type="text" name="username"
                   placeholder="Email, Phone or Username" required>
            <i class="fas fa-user"></i>
        </div>

        <div class="input-group">
            <input type="password" name="password"
                   placeholder="Password" required>
            <i class="fas fa-lock"></i>
        </div>

        <div class="options">
            <label>
                <input type="checkbox"> Remember Me
            </label>

            <a href="forgot-password">Forgot Password?</a>
        </div>

        <input type="hidden" name="secret" value="ahkwebsolutions">

        <button type="submit" class="login-btn">
            <i class="fas fa-sign-in-alt"></i> Login
        </button>

    </form>

    <div class="register">
        Don't have an account?
        <a href="register">Register Now</a>
    </div>

    <div class="footer-text">
        © 2026 Login. All Rights Reserved.
    </div>

</div>

</body>
</html>