<?php
include('extension/connect.php');
require "extension/config.php";
?>
<?php
    
    if (!isset($_SESSION['userid'])) {

    }else{
        header("location:dashboard");
    }
?>
<?php
$status = '';
if(isset($_POST['login'])){
  $user_name = mysqli_real_escape_string($con,$_POST['user_name']);
  $user_pass = mysqli_real_escape_string($con,$_POST['user_pass']);

  if($user_name!='' && $user_pass!=''){


  $query =mysqli_query($con,"select * from users where user_name='$user_name' and user_pass='$user_pass' and is_freeze='0' and user_rank!='normal' and user_rank!='export'");
  $qry = mysqli_fetch_array($query);
  $user_id = $qry['user_id'];
  if(mysqli_num_rows($query)>0){
  session_start();
  $_SESSION['id'] = session_id();
  $_SESSION['userid'] = $user_id;
  $_SESSION['login_type'] = "users";
  
  $ip = $db->get_client_ip();
  $descript = 'Login successful, IP: '.$ip.'';
  $update = mysqli_query($con,"insert into credit_log(`user_id`,`description`) values('$user_id','$descript')");
  
  echo "<script>
  window.location.href = 'dashboard';</script>";
} else {

  $status = '<p class="mt-20 mb-0 text-danger">Login Failed : Invalid Credentials or Account Blocked</p>';

}

  }
  else{

    $status = '<p class="mt-20 mb-0 text-danger">Please fill-out all forms</p>';
 
  }

}else{
    
}
?>

<!DOCTYPE html>
<?php
    $query = mysqli_query($con,"SELECT copyright_name from admin");
    $res = mysqli_fetch_assoc($query);
    $copyright_name = $res['copyright_name'];
?>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title><?php include('extension/title.php'); ?> | Login</title>
  <link rel="shortcut icon" href="<?php include('extension/logo.php'); ?>" />
  <!-- Google Font: Source Sans Pro -->
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700&display=fallback">
  <!-- Font Awesome -->
  <link rel="stylesheet" href="/assets/plugins/fontawesome-free/css/all.min.css">
  <!-- icheck bootstrap -->
  <link rel="stylesheet" href="/assets/plugins/icheck-bootstrap/icheck-bootstrap.min.css">
  <!-- Theme style -->
  <link rel="stylesheet" href="/assets/dist/css/adminlte.min.css">
</head>
<body class="hold-transition login-page">
<div class="login-box">
  <!-- /.login-logo -->
  <div class="card card-outline">
    <div class="card-header text-center">
      <a href="login" class="h1" style="font-weight: bold;"><?php include('extension/title.php');?></a>
    </div>
    <div class="text-center">
      <img class="mb-2 mt-4" src="<?php include('extension/logo.php'); ?>" alt="" height="100px" width="100px">
    </div>
    <div class="card-body">
      <p class="login-box-msg">Sign in to start your session</p>

      <form method="post">
        <div class="input-group mb-3">
          <input type="text" name="user_name" id="user_name" class="form-control" placeholder="Username">
          <div class="input-group-append">
            <div class="input-group-text">
              <span class="fas fa-user"></span>
            </div>
          </div>
        </div>
        <div class="input-group mb-3">
          <input type="password" name="user_pass" id="user_pass" 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="text-center mb-3">
            <?php echo $status; ?>
        </div>
        <div class="row">
          <!-- /.col -->
          <div class="col-12">
            <button name="login" type="submit" class="btn btn-block" style="color: <?php include('extension/theme_text.php'); ?>; background-color: <?php include('extension/theme.php'); ?>;">Sign In</button>
          </div>
          <!-- /.col -->
        </div>
        <div class="mt-2 text-center">
          <a href="privacy_pub"><u>Privacy Policy</u></a>
          <a href="terms_pub"><u>Terms & Conditions</u></a>
        </div>
      </form>

    </div>
    <!-- /.card-body -->
  </div>
  <!-- /.card -->
</div>
<!-- /.login-box -->

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