<?php require_once("header.php");

$_SESSION['error_msg'] = "";
if(isset($_POST['login'])) 
{
   $username = $_POST['username'];
   $password = md5($_POST['password']);
   $ex = $obj->login($username,$password);
   if(mysqli_num_rows($ex))
   {
       $row = mysqli_fetch_array($ex);
       $_SESSION['login_id'] = $row['login_id'];
       $_SESSION['role'] = $row['role'];
        $_SESSION['username'] = $username;
        header("Location:dashboard.php");
   }
   else
   {
        $_SESSION['error_msg'] = "Invalid Username & Password...";
   }
}
?>
<body class="no-footer">
    <div id="layoutAuthentication">
        <div id="layoutAuthentication_content">
            <main>
                <div class="container">
                    <div class="row justify-content-center">
                        <div class="col-lg-5">
                            <div class="card shadow-lg border-0 rounded-lg mt-4 my-card">
                                <div class="card-header" style="background: #99c2e580;">
                                <h2 class="text-center font-weight-light login-logo"><img src="css/logo.png"></h2>
                                <h3 class="text-center font-weight-light">Login</h3></div>
                                <div class="card-body">
                                    <form method="POST">
                                        <p class="text-danger"><?php echo $_SESSION['error_msg'];?></p>
                                        <div class="form-group">
                                            <label class="small mb-1">Username</label>
                                            <input autocomplete="username" class="form-control py-4"  type="text" placeholder="Enter Username" name="username"   value="<?php echo $username;?>" />
                                        </div>
                                        <div class="form-group">
                                            <label class="small mb-1">Password</label>
                                            <input autocomplete="password" class="form-control py-4" type="password" id="psw" name="password"  required placeholder="Enter password" name="password" <?php echo $password;?>/>
                                        </div>
                                    
                        
                                        <!-- <div class="form-group">
                                            <div class="custom-control custom-checkbox"><input class="custom-control-input" id="rememberPasswordCheck" type="checkbox" /><label class="custom-control-label text-right" for="rememberPasswordCheck">Remember password</label></div>
                                        </div> -->
                                        <div class="form-group d-flex align-items-center justify-content-between mt-4 mb-0">
                                            <button class="btn btn-primary" type="submit" name="login">Login</button>
                                            <!-- <a class="small" href="#">Forgot Password?</a> -->
                                    </div>   
                                    </form>
                                </div>
                                <!-- <div class="card-footer text-center">
                                    <div class="small"><a href="registration.php">Need an account? Sign up!</a></div>
                                </div> -->
                            </div>
                        </div>
                    </div>
                </div>
            </main>
        </div>
        
    </div>
    
<!-- <script src="js/validate.js"></script> -->
<?php require_once("footer.php");?>