<?php 
require_once '../Server/connection.php';
session_start();
if($_POST){
	
	$login_type = $_POST['login_type'];
	
	if($login_type=='Customer Login'){
		
	$client_tin = addslashes($_POST['client_tin']);
	$pass_word = $_POST['password'];
	$password = md5($pass_word);
		
			$status = 1;
			$mainSql = "SELECT users.role_id,users.user_id,users.staff_id FROM users inner join clients on users.staff_id=clients.client_id WHERE clients.client_tin = '$client_tin' AND users.password = '$password' AND users.status='$status'";
			$mainResult = $conn->query($mainSql);
			$value = $mainResult->fetch_assoc();
			if($mainResult->num_rows == 1){
				
				$user_id = $value['user_id'];
				$role_id = $value['role_id'];
				$staff_id = $value['staff_id'];
				
				// set session
				$_SESSION['user_id'] = $user_id;
				$_SESSION['role_id'] = $role_id;
				$_SESSION['staff_id'] = $staff_id;
				
					   
				header('location: ../user/dashboard.php');
			           
				
			}else{
				
			
				
				echo "<script>alert('Wrong TIN or Password Access Denied3 !!! Try Again');
						window.location='../index.php';
						</script>";
				
				
			}	
		
		
		
		
	}else{
		
	$email = strtolower(addslashes($_POST['email']));
	$pass_word = $_POST['password'];
	$password = md5($pass_word);
	
		
			$status = 1;
			$mainSql = "SELECT users.role_id,users.user_id,users.staff_id FROM users inner join staff on users.staff_id=staff.staff_id WHERE staff.email = '$email' AND users.password = '$password' AND users.status='$status'";
			$mainResult = $conn->query($mainSql);
			$value = $mainResult->fetch_assoc();
			if($mainResult->num_rows == 1){
				
				$user_id = $value['user_id'];
				$role_id = $value['role_id'];
				$staff_id = $value['staff_id'];
				
				// set session
				$_SESSION['user_id'] = $user_id;
				$_SESSION['role_id'] = $role_id;
				$_SESSION['staff_id'] = $staff_id;
				
					   
				header('location: ../user/dashboard.php');
			           
				
			}else{
				
			
				
				echo "<script>alert('Wrong Email Address or Password Access Denied3 !!! Try Again');
						window.location='../index.php';
						</script>";
				
				
			}
		
	}
		
} // /if $_POST
?>