<?php include("config.inc");

$isError=false;
$usrname=$_REQUEST["username"];
$password=$_REQUEST["password"];

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    
    $qry=mysqli_query($connect, "SELECT * FROM app_users WHERE email='".$_REQUEST["username"]."' AND Password='".$_REQUEST["password"]."' AND emailverified='1' ") or die("Error " .mysqli_error());
    $data1=mysqli_fetch_assoc($qry);
    

    if(mysqli_num_rows($qry)>0){
            if(isset($data1["DriverId"])){
        $driverqry = mysqli_query($connect, "SELECT * FROM driver WHERE driver_id =" .$data1["DriverId"]);
        $driverdata = mysqli_fetch_assoc($driverqry);
        $driverenable = $driverdata["driver_enable"];
        
        if($driverenable =="enable"){
        $_SESSION['userid']=$data1['Id'];
        $_SESSION['name']=$data1['Name'];
        $_SESSION['email']=$data1["Email"];
        $_SESSION['password']=$data1['Password'];
        $_SESSION['image']=$data1["Image"];
        $_SESSION['driverid']=$data1['DriverId'];
		
		$_SESSION['customerlogged'] = true;
		
		    if (isset($_POST['id'])) {
                $_SESSION['carid'] = $_POST['id'];
                header("location: booknow.php"); //redirect to booking page
            } else {
                // header("location: index.php#cars"); // Redirecting To Index Page for Car Selection
                header("location:index.php");
            }
        }
        elseif($driverenable =="disable"){
                    $isError=true;
		$error_msg = "Your account is currently disabled";
        }
    
            }
        } else {
        $isError=true;
		$error_msg = "Your username or password is invalid";
        }
}

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

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Login</title>
<?php include("head-tag.php");?>

</head>
<body>

<div class="inner-wrapper login-body">
<div class="login-wrapper">
<div class="container">
<div class="loginbox shadow-sm">
<div class="login-left">
<?php echo $companylogo;?>
</div>
<div class="login-right">
<div class="login-right-wrap">
<h1><?php echo $companylogosmall;?> </h1>     
<h1>Login</h1>
<p class="account-subtitle">Booking Dashboard</p>
<?php
if($isError == true){?>
	<span class="text-danger text-center"><?php echo $error_msg;?></span>
<?php }
?>
<form action="" method="POST">
<div class="form-group">
<input class="form-control" type="text" placeholder="Email" name="username" required="" autofocus="">
</div>
<div class="form-group">
<input class="form-control" type="password" placeholder="Password" name="password" required="" autofocus="">
</div>
<div class="form-group">
<!--<button class="btn btn-theme button-1 text-white ctm-border-radius btn-block" type="submit">Login</button>-->
<button class="btn btn-theme text-white ctm-border-radius btn-block" type="submit">Login</button>
</div>
</form>
<div class="text-center forgotpass"><a href="forgot-password.php">Forgot Password?</a></div>
<!--<div class="login-or">
<span class="or-line"></span>
<span class="span-or">or</span>
</div>-->
<!--<div class="social-login">
<span>Login with</span>
<a href="javascript:void(0)" class="facebook"><i class="fa fa-facebook"></i></a><a href="javascript:void(0)" class="google"><i class="fa fa-google"></i></a>
</div>
-->
<!--<div class="text-center dont-have">Don’t have an account? <a href="register.php">Register</a></div>
--></div>
</div>
</div>
</div>
</div>
</div>

<?php include("scripts.php");?>

</body>

</html>