<?php
	session_start();
	require_once('../Db/dbconfig.php');


     if(isset($_POST['submit']))
    {
        $username = $_POST['username'];
        $password = $_POST['password'];
        
        $query = "select * from user where user_name = '".$username."' and password = '".$password."'";
        $queryrun = mysqli_query($con, $query);
        if(mysqli_num_rows($queryrun) > 0)
        {

			if("superadmin" == $username)
			{
				$_SESSION['user_name'] = $username;
				 echo"<script>window.location.href='../nav/header.php';</script>";
			}elseif("purchase" == $username)
			{
				$_SESSION['user_name'] = $username;
				 echo"<script>window.location.href='../nav/header.php';</script>";
			}elseif("storage" == $username)
			{
				$_SESSION['user_name'] = $username;
				 echo"<script>window.location.href='../nav/header.php';</script>";
			}elseif("Admin" == $username)
			{
				$_SESSION['user_name'] = $username;
				 echo"<script>window.location.href='../nav/header.php';</script>";
			}elseif("stock" == $username)
			{
				$_SESSION['user_name'] = $username;
				 echo"<script>window.location.href='../nav/header.php';</script>";
			}elseif("lab" == $username)
			{
				 echo"<script>window.location.href='../nav/header.php';</script>";
			}elseif("account" == $username)
			{
				 echo"<script>window.location.href='../nav/header.php';</script>";
			}elseif("dispatch" == $username)
			{
				 echo"<script>window.location.href='../nav/header.php';</script>";
			}
			else
			{
            echo "<script>alert('Not register Username Or Password'); window.location.href='../index.php';</script>";
			}
           
        }
        else
        {
            echo "<script>alert('Invalid Username Or Password'); window.location.href='../index.php';</script>";
        }
    }
    mysqli_close($con);
?>