<?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
  }



}
?>

<?php 
include('a.php');
?>



  <!-- /.login-logo -->
  <div class="container right-panel-active">
    <div class="form-container sign-in-container d-block">
     <h1 _ngcontent-kpr-c267="" class="is-title fw-bold">General Public Login</h1>

      <form action="" method="post" class="ng-untouched ng-pristine ng-invalid">
        <div class="input-group mb-3">
          <input type="text" name="username" required class="form-control" placeholder="Email phone or Username">
          <div class="input-group-append">
            <div class="input-group-text">
              <span class="fas fa-envelope"></span>
            </div>
          </div>
        </div>
        <div class="input-group mb-3">
          <input type="password" name="password" required class="form-control" placeholder="Password">
          <div class="input-group-append">
            <div class="input-group-text">
              <span class="fas fa-lock"></span>
            </div>
          </div>
        </div>
        <div class="row">
          <div class="col-8">
            <div class="icheck-primary">
              <input type="hidden" name="secret" value="ahkwebsolutions">
              <input type="checkbox" id="remember">
              <label for="remember">
                Remember Me
              </label>
            </div>
          </div>
          <!-- /.col -->
          <div class="col-4">
            <button type="submit" class="btn btn-primary btn-block">Login</button>
          </div>
          <!-- /.col -->
        </div>
      </form>

  

      <p class="mb-1">
        <a href="recover-password">Forgot Password?</a>
      </p>
      <p class="mb-0">
        <a href="register" class="text-center">Register</a>
      </p>
    </div>
    <!-- /.login-card-body -->
  </div>

<!-- /.login-box -->

<!-- jQuery -->
<script src="./crs/plugins/jquery/jquery.min.js"></script>
<!-- Bootstrap 4 -->
<script src="./crs/plugins/bootstrap/js/bootstrap.bundle.min.js"></script>
<!-- AdminLTE App -->
<script src="./crs/dist/js/adminlte.min.js"></script>



<?php 
include('k.php');
?>
