<?php
session_start();
if (isset($_SESSION['session_empid'])) {
    header("Location:dashboard.php");
}
include 'database.php';

$error=''; 
if (isset($_POST['login']) && $_POST['login'] == 'login-user') 
{

    $adminusername = mysqli_real_escape_string($conn, $_POST['user_email']);
    $adminpassword = mysqli_real_escape_string($conn, $_POST['user_password']);
    $sql = "SELECT * FROM system_users WHERE ( BINARY username = '" . $adminusername . "' ) AND ( BINARY password = '" . $adminpassword . "') ";
    $query = mysqli_query($conn, $sql) or trigger_error("Query Failed: " . mysql_error());
    if (mysqli_num_rows($query) == 1) {
        $row = mysqli_fetch_assoc($query);

        $session_empid = $row['user_id'];
   
        if (isset($_SESSION['session_empid'])) {
            unset($_SESSION['session_empid']);
        }
        if (isset($_SESSION['login'])) {
            unset($_SESSION['login']);
        }

        $_SESSION['session_empid'] = $session_empid;
        $_SESSION['login'] = true;

        header("Location:dashboard.php");
    }else{
            $error = "Enter Correct Username and password";
    }
 }

?>
<!DOCTYPE html>

<html class="no-js" lang="en">
<head>
  <!-- title and meta -->
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0" />
<meta name="description" content="">
<meta name="keywords" content="De-Addiction Centers in Pune, E-Addiction Center, Pune Addiction, Mobile De-Addiction">
<link rel="shortcut icon" type="image/x-icon" href="../images/favicon.ico"> 
<title>Homepage | Anandvan</title>
  
<link href="css/stylesheet.css" type="text/css" rel="stylesheet" />
<link href="css/responsive.css" type="text/css" rel="stylesheet" />
<link href="css/bootstrap.min.css" type="text/css" rel="stylesheet">
  <link rel="stylesheet" href="css/style.css">

<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>

</head>

<body>

        <div class="login_page">
            <div class="container">
                <div class="row">
                    <div class="col-sm-12 text-center">
                        <a href="index.html"><img src="images/anandvan-logo.png"></a>
                        <div class="logo-name">Anandvan</div>
                    </div>
                </div>
            </div>

            <div class="container">
                <div class="row">
                    <div class="col-sm-6 col-sm-offset-3">
                        <form class="login-form" method="POST" action="" autocomplete="off">
                                    <?php if ($error != "") {
            echo '<h4 style="text-align:center;color:#bf0000;font-weight:bold;">' . $error . '</h4>';
        } ?>

                            <div class="form-group row">
                                <div class="col-sm-3"><label>Username</label></div>
                                <div class="col-sm-9"><input type="text" class="form-control jsEmail" placeholder="Username" name="user_email" required></div>
                            </div>
                            <div class="form-group row">
                                <div class="col-sm-3"><label>Password</label></div>
                                <div class="col-sm-9"><input type="password" class="form-control jsPassword" placeholder="Password"  name="user_password" required=""></div>
                            </div>
                            <div class="row">
                                <div class="col-sm-12 text-center">
                                    <input type="hidden" name="login" value="login-user" />
                                    <button type="submit" class="btn submitBtn btn-primary">Sign in</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>

    </body>
</html>