<?php
###################################### Login Validate ###################################################################
//fetching data from index.html
$username=strtoupper($_POST['username']);
$password=$_POST['password'];
if($username=='' || $password=='')
	{  		
		echo "<script type='text/javascript'>alert('Please Enter Username Or Password!')</script>";
		echo '<script language="JavaScript"> window.location.href ="index.php" </script>';		
	}
//including database file
require_once('connection/db.php');
session_start();
//sql query
$qry="SELECT * FROM login WHERE login_id='$username' AND password='$password'";
$rs=mysql_query($qry);

//validating resultset
$count=mysql_num_rows($rs);

if($count==0)
	{	
		echo "<script type='text/javascript'>alert('Invalid User Name or Password!!..')</script>";
		echo '<script language="JavaScript"> window.location.href ="index.php" </script>';			
	}
	
else
{	
while($row=mysql_fetch_array($rs))
	{	
	  
				 if($row['user_type']=="BDO")
					{
						$_SESSION['logged_in'] = true;
						$_SESSION['User_Name'] = strtoupper($_POST['username']);
						echo '<script language="JavaScript"> window.location.href ="bdo_home.php" </script>';
						exit;
					}
				######################## If User Is Desk ##########################
				if($row['user_type']=="Desk")
					{
						$_SESSION['logged_in'] = true;
						$_SESSION['User_Name'] = strtoupper($_POST['username']);
						
						echo '<script language="JavaScript"> window.location.href ="deskacceptletter.php" </script>';
						exit;
					}
				######################## If User Is Tapal ##########################
				 if($row['user_type']=="Tapal")
					{
						$_SESSION['logged_in'] = true;
						$_SESSION['User_Name'] = strtoupper($_POST['username']);
							
						echo '<script language="JavaScript"> window.location.href ="tapal_home.php" </script>';
						exit;
					}
						
				######################## If User Is BDO ##########################
			
				######################## If User Is Department ##########################
				 if($row['user_type']=="Department")
					{
						$_SESSION['logged_in'] = true;
						$_SESSION['User_Name'] = strtoupper($_POST['username']);
						echo '<script language="JavaScript"> window.location.href ="dept_home.php" </script>';
						exit;
					}
		
	}
}
?>