<?php
/*
* date last modified 03-10-2017
* Edited by PI-Digi Logical Solutions
* HTML Files - manage_staff.html.php
* Mysql Tables - tbl_admin, tbl_user, tbl_admin_type
*/

// admin login as user
if(isset($_GET['action']) && $_GET['action']=='admin_login') {	
	$userId = trim($_GET['user_id']);	
	$select = "SELECT * FROM tbl_user WHERE id=".$userId;								 
	$checkUser = mysqli_query($con, $select);											 
	if(mysqli_num_rows($checkUser) >0) {
						
		$resUser = mysqli_fetch_array($checkUser);
						
		$userId = $resUser['id'];
		$_SESSION['user_id'] = $userId;
		$_SESSION['user_name'] = $resUser['name'];
		//unset all other user types
		$_SESSION['tech_id'] = '';	unset($_SESSION['tech_id']);	
		$_SESSION['tech_name'] = ''; unset($_SESSION['tech_name']);
		$_SESSION['purchase_id'] = '';	unset($_SESSION['purchase_id']);	
		$_SESSION['purchase_name'] = ''; unset($_SESSION['purchase_name']);
		header("Location:".BASE_URL."html/index.php?page=user_profile");		
	}	else {
		echo 'Not found';
	}
} else if(isset($_GET['action']) && $_GET['action']=='tech_login') {	
	$userId = trim($_GET['tech_id']);	
	$select = "SELECT * FROM tbl_technician WHERE id=".$userId;								 
	$checkUser = mysqli_query($con, $select);											 
	if(mysqli_num_rows($checkUser) >0) {						
		$resUser = mysqli_fetch_array($checkUser);						
		$userId = $resUser['id'];
		$_SESSION['tech_id'] = $userId;
		$_SESSION['tech_name'] = $resUser['name'];
		//unset all other user types
		$_SESSION['user_id'] = '';	unset($_SESSION['user_id']);	
		$_SESSION['user_name'] = ''; unset($_SESSION['user_name']);
		$_SESSION['purchase_id'] = '';	unset($_SESSION['purchase_id']);	
		$_SESSION['purchase_name'] = ''; unset($_SESSION['purchase_name']);
		header("Location:".BASE_URL."html/index.php?page=tech_dashboard");		
	}	else {
		echo 'Not found';
	}
} else if(isset($_GET['action']) && $_GET['action']=='shop_login') {	
	$userId = trim($_GET['shop_id']);	
	$select = "SELECT * FROM tbl_purchase_partner WHERE id=".$userId;								 
	$checkUser = mysqli_query($con, $select);											 
	if(mysqli_num_rows($checkUser) >0) {						
		$resUser = mysqli_fetch_array($checkUser);						
		$userId = $resUser['id'];
		$_SESSION['purchase_id'] = $userId;
		$_SESSION['purchase_name'] = $resUser['name'];	
		//unset all other user types
		$_SESSION['user_id'] = '';	unset($_SESSION['user_id']);	
		$_SESSION['user_name'] = ''; unset($_SESSION['user_name']);
		$_SESSION['tech_id'] = '';	unset($_SESSION['tech_id']);	
		$_SESSION['tech_name'] = ''; unset($_SESSION['tech_name']);
		header("Location:".BASE_URL."index.php?page=purchase_profile");		
	}	else {
		echo 'Not found';
	}
}

?>