<?php
session_start();

include "dbconnect.php";
if(isset($_SESSION['user'])) {
	header("location: feedback/feedback_dashboard.php");
	exit;
}

if(isset($_POST['login'])) {
	$uname = $_POST['username'];
	$pass = $_POST['password'];
	
	// $qry = mysql_query("SELECT `username`, `pass`, `status` FROM `admin` WHERE `username` = '$uname' AND `pass` = '$pass'");
	//echo "SELECT `LoginName`, `Password`, `IsActive`, `client_id` FROM `staff_master` WHERE `LoginName` = '$uname' AND `Password` = '$pass'";
	$qry = mysql_query("SELECT `LoginName`, `Password`, `IsActive` FROM `staff_master` WHERE `LoginName` = '$uname' AND `Password` = '$pass'");
	$row = mysql_fetch_array($qry);
	$num = mysql_num_rows($qry);
	
	if($num == 1 && $row['Password'] == $pass) {
		if($row['IsActive'] == 1) {
			$_SESSION['user'] = $row['LoginName'];
			header("location: feedback/feedback_dashboard.php");
		} else {
			$error = "You have not permission to access...Contact to administrator";
		}
	} else {
		$error = "<b>Wrong login credential</b>...please try again";
	}
}


?>
<!DOCTYPE html>
<html lang="en">

<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="Feedback Admin Panel">
    <meta name="author" content="SCPL">
    <meta name="keyword" content="Feedback, Feedback Dashboard, Customer Review, CRM">
    <link rel="shortcut icon" href="assets/img/favicon.ico">

    <title>Rezol POS</title>

    <!-- Icons -->
    <link href="assets/css/font-awesome.min.css" rel="stylesheet">
    <link href="assets/css/simple-line-icons.css" rel="stylesheet">

    <!-- Main styles for this application -->
    <link href="assets/css/style.css" rel="stylesheet">

</head>

<body class="app flex-row align-items-center">
    <div class="container">
        <div class="row justify-content-center">
            <div class="col-md-6">
                <div class="card-group mb-0">
                    <div class="card p-4">
                        <div class="card-body">
                            <form action="" method="post">
								<div class="text-danger"><?php if(isset($error)) { echo $error; } ?></div>
								<h1>Login</h1>
								<p class="text-muted">Sign In to your account</p>
								<div class="input-group mb-3">
									<span class="input-group-addon"><i class="icon-user"></i>
									</span>
									<input type="text" name="username" class="form-control" placeholder="Username">
								</div>
								<div class="input-group mb-4">
									<span class="input-group-addon"><i class="icon-lock"></i>
									</span>
									<input type="password" name="password" class="form-control" placeholder="Password">
								</div>
								<div class="row">
									<div class="col-6">
										<button type="submit" name="login" class="btn btn-primary px-4">Login</button>
									</div>
									<div class="col-6 text-right">
										<button type="button" class="btn btn-link px-0">Forgot password?</button>
									</div>
								</div>
							</form>
                        </div>
                    </div>
                    <!--div class="card text-white bg-primary py-5 d-md-down-none" style="width:44%">
                        <div class="card-body text-center">
                            <div>
                                <h2>Sign up</h2>
                                <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
                                <button type="button" class="btn btn-primary active mt-3">Register Now!</button>
                            </div>
                        </div>
                    </div-->
                </div>
            </div>
        </div>
    </div>

    <!-- Bootstrap and necessary plugins -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
    <script src="assets/js/dist/js/tether.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
	
</body>

</html>