<?php
session_start();
error_reporting(0);


if(isset($_SESSION["user_type"]))
{
    if($_SESSION["user_type"]=="admin")
    {
        header("location:index.php");
    }
    if($_SESSION["user_type"]=="customer")
    {
        header("location:customer.php");
    }
    
}
else{
   
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Sign In</title>

    <!-- Font Icon -->
    <link rel="stylesheet" href="SignUp&Login/fonts/material-icon/css/material-design-iconic-font.min.css">

    <!-- Main css -->
    <link rel="stylesheet" href="SignUp&Login/css/style.css">
</head>
<body>

    <div class="main">

      
        <!-- Sing in  Form -->
        <section class="sign-in">
            <div class="container">
                <div class="signin-content">
                    

                    <div class="signin-form">
                        <h2 class="form-title">Sign In</h2>
                        <form method="POST" class="register-form" id="login-form">
                            <div class="form-group">
                                <label for="your_name"><i class="zmdi zmdi-account material-icons-name"></i></label>
                                <input type="text" name="Email" id="your_name" placeholder="Your Email"/>
                            </div>
                            <div class="form-group">
                                <label for="your_pass"><i class="zmdi zmdi-lock"></i></label>
                                <input type="password" name="Password" id="your_pass" placeholder="Password"/>
                            </div>
                           
                            <div class="form-group form-button">
                                <input type="submit" name="login" id="signin" class="form-submit" value="Log in"/>
                            </div>
                        </form>
                      
                    </div>
                </div>
            </div>
        </section>

    </div>

    <!-- JS -->
    <script src="SignUp&Login/vendor/jquery/jquery.min.js"></script>
    <script src="SignUp&Login/js/main.js"></script>
</body>
</html>
<?php
}
?>


<?php


include("db_con.php");



if(isset($_POST["login"]))
{
  
    $Email=$_POST["Email"];
    $Password=$_POST["Password"];
    $Qry="SELECT * FROM `user` WHERE `email`='$Email' AND `password`='$Password'";
    $Run=mysqli_query($con,$Qry);
    $Row=mysqli_num_rows($Run);
 
    echo $Row;
    if($Row<1)
    {
        ?>
        <script>
        alert("Email or password is not exist");
       // window.open("login.php","_self");
        </script>
        <?php   
    }
    else{
      ?>
      <script>
    //   alert("Login successfully");
     // window.open("Login.php","_self");
      </script>
      <?php   
        $Data=mysqli_fetch_assoc($Run);
         $user_id=$Data["user_id"];
        
        $_SESSION["user_id"]=$Data["user_id"];
        $_SESSION["user_type"]=$Data["user_type"];
       
         
         if($Data["user_type"]=="admin")
         {
             // header("location:index.php?user_id=".$_SESSION['user_id']."&user_type=".$_SESSION['user_type']);
         ?>
         <script>
        location.href = "index.php";
         //  location.href = "index.php?user_id=<?php echo $user_id;?>&user_type=<?php echo $Data["user_type"];?>";
         
         </script>
         <?php
         }
               
    }
}
else{
   
}