<?php //ob_start();  // Output buffering start karo
session_start(); ?>
<?php

if(isset($_POST["btlogin"])){
 if(!empty($_POST['txtname']) && !empty($_POST['txtpassword'])){
 $user = $_POST['txtname'];
 $password = $_POST['txtpassword'];
 //$pass = md5($password); 
 //DB Connection
 
 include('includes/config.php');
 //Selecting database
 $query = mysqli_query($con, "SELECT * FROM `user_info` WHERE `email`='".$user."' AND `password`='".$password."' AND `us_status`='0' ");
 $numrows = mysqli_num_rows($query);
 if($numrows !=0)
 {
 while($row = mysqli_fetch_assoc($query))
 {
 $dbuser_id =$row['user_id'];
  $dbname=$row['name'];
 $dbusername=$row['email'];
 $dbpassword=$row['password'];
 $role = $row['role'];

 }
 if($user == $dbusername && $password == $dbpassword)
 {
     

 $_SESSION['sess_user_id']=$dbuser_id;
 $_SESSION['sess_user']=$dbname;
 $_SESSION['sess_email']=$dbusername;
 $_SESSION['sess_role']=$role;


 //Redirect Browser
 //header("Location: dashboard.php");
 ?>
 <?php if($role =='Admin' || $role =='User') {
  echo "<div class='container'><div class='custom-alert'>Successfully Logged in</div></div>";
        echo "<script>setTimeout(function() { window.location.href='dashboard.php'; }, 1000);</script>";
        exit(); // Prevent the rest of the code from executing
 
 ?>
 
    
    <?php } ?>
    
    
    <?php //if($role =='User') { ?>
    
 <!--- <script>
        alert('Successfully Logged in');
        window.location.href='dashboard.php';
    </script>-->
    
    <?php //} ?>
    
    
    
    
    
 <?php
 }
 }
 else
 {
 //echo "Invalid Username or Password!";
 
 //echo"<script type='text/javascript'>alert('Invalid Username or Password!');</script>";
//   echo "<div class='container'><div class='custom-alert'>Invalid Username or Password!</div></div>";
//         echo "<script>setTimeout(function() { window.location.href='index.php'; }, 2000);</script>";
 
 }
 }
 else
 {
 //echo "Required All fields!";
 //echo"<script type='text/javascript'>alert('Required All fields!');</script>";
// echo "<div class='container'><div class='custom-alert'>Required All fields!</div></div>";
//   echo "<script>setTimeout(function() { window.location.href='index.php'; }, 2000);</script>";

 }
}
?>

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>Madina Construction | Log in</title>
  <!-- Tell the browser to be responsive to screen width -->
  <meta name="viewport" content="width=device-width, initial-scale=1">

  <!-- Font Awesome -->
  <link rel="stylesheet" href="plugins/fontawesome-free/css/all.min.css">
  <!-- Ionicons -->
  <link rel="stylesheet" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css">
  <!-- icheck bootstrap -->
  <link rel="stylesheet" href="plugins/icheck-bootstrap/icheck-bootstrap.min.css">
  <!-- Theme style -->
  <link rel="stylesheet" href="dist/css/adminlte.min.css">
  <!-- Google Font: Source Sans Pro -->
  <link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700" rel="stylesheet">
  <link rel="shortcut icon" href="images/logos/soft-lg-1-withname copy.png" type="image/x-icon" >

<style>
    .container {
        position: relative;
        width: 50%; /* Adjust the width of the container */
        margin: 0 auto; /* Center the container */
        padding: 20px;
        border: 1px solid #ddd; /* Optional: Add a border to the container */
    }

    .custom-alert {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        background-color: #f44336;
        color: white;
        text-align: center;
        padding: 15px;
        z-index: 9999;
    }
</style>
</head>

<body class="hold-transition login-page">
    
    <div  class="header">
       <div class="row">
            <div class="col-md-6" style="margin-left:4%; margin-top:20px;"><img src="images/logos/madinaconst-lgnew.png
" height="300" width="350"></div>
            
              <div class="col-md-4"></div>
              
              <div class="col-md-2"></div>
        </div>
        
    </div>
<div class="login-box">
  <div class="login-logo">
    <!--<a href="#"><b>Dumper</b>MS
    
    </a>--> 
  </div>
  <!-- /.login-logo -->
  
  
 
  <div class="bg-danger card">
    <div class="card-body login-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="email" name="txtname" class="form-control" placeholder="Email">
          <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="txtpassword" 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="checkbox" id="remember">
              <label for="remember">
                Remember Me
              </label>
            </div>-->
          </div>
          <!-- /.col -->
          <div class="col-4">
            <button type="submit" name="btlogin" class="btn btn-danger btn-block">Sign In</button>
          </div>
          <!-- /.col -->
        </div>
      </form>

      <!--<div class="social-auth-links text-center mb-3">
        <p>- OR -</p>
        <a href="#" class="btn btn-block btn-primary">
          <i class="fab fa-facebook mr-2"></i> Sign in using Facebook
        </a>
        <a href="#" class="btn btn-block btn-danger">
          <i class="fab fa-google-plus mr-2"></i> Sign in using Google+
        </a>
      </div>-->
      <!-- /.social-auth-links -->

     <!-- <p class="mb-1">
        <a href="forgot-password.html">I forgot my password</a>
      </p>
      <p class="mb-0">
        <a href="register.html" class="text-center">Register a new membership</a>
      </p>-->
    </div>
    <!-- /.login-card-body -->
  </div>
</div>
<!-- /.login-box -->

<br><br>
<div class="row">
  <footer class="footer">
      <hr>
    <strong >Copyright &copy; 2023. Developed By <a  onclick="window.open(this.href); return false;"  href="https://jsntechsolution.com">JsnTech Solution</a>.</strong>
 
    <div class="float-right d-none d-sm-inline-block">
      <b></b>   All rights reserved.
    </div>
  </footer>

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

</body>
</html>