<?php
	session_start();

	if(!isset($_SESSION['latcsuperloginsesion']))
	{
		header('Location: index.php');
		return;
	}
	include("connect.php");
	$mumid=$_SESSION['latcmumid'];
	$umid=(int)mysqli_real_escape_string($conn,$_GET['id']);
	if($_SESSION['latcutype']=='mainadmin'){
		$eve = "select * from res_user_master where umid=$umid";
	}
	else{
		$eve = "select * from res_user_master where umid=$umid and mumid=$mumid";
	}
	$re = mysqli_query($conn, $eve);
	if(mysqli_num_rows($re)==0)
	{
		date_default_timezone_set("Asia/Kolkata");
		$mdate= date('Y-m-d H:i:s');
		$latcuemail = $_SESSION['latcuemail'];
		$ipaddress = "";

		if (getenv('HTTP_CLIENT_IP'))
			$ipaddress = getenv('HTTP_CLIENT_IP');
		else if(getenv('HTTP_X_FORWARDED_FOR'))
			$ipaddress = getenv('HTTP_X_FORWARDED_FOR');
		else if(getenv('HTTP_X_FORWARDED'))
			$ipaddress = getenv('HTTP_X_FORWARDED');
		else if(getenv('HTTP_FORWARDED_FOR'))
			$ipaddress = getenv('HTTP_FORWARDED_FOR');
		else if(getenv('HTTP_FORWARDED'))
			$ipaddress = getenv('HTTP_FORWARDED');
		else if(getenv('REMOTE_ADDR'))
			$ipaddress = getenv('REMOTE_ADDR');
		else
			$ipaddress = 'UNKNOWN';
		$userserver=$_SERVER['HTTP_USER_AGENT'];
		$eve_logentry= "insert into res_user_log (lid,mobile,lastupdatedtime,pagename,taskname,ipaddress,useragentdetail) values(NULL,'$latcuemail','$mdate','TelecallerDelete','Invalid access userdelete','$ipaddress','$userserver')";
		$re_logentry = mysqli_query($conn, $eve_logentry);
		unset($_SESSION['latcsuperloginsesion']);
		session_destroy();
		header("Location:index.php");
		return;
	}
	if($_SESSION['latcutype']=='mainadmin'){
		$eve2 = "select * from res_user_master where umid=$umid";
	}
	else{
		$eve2 = "select * from res_user_master where umid=$umid and mumid='$mumid'";
	}
	$re2 = mysqli_query($conn, $eve2);
	if(mysqli_num_rows($re2) > 0)
	{
		if($_SESSION['latcutype']=='mainadmin'){
			$query="delete from res_user_master where umid=$umid";
		}
		else{
			$query="delete from res_user_master where umid=$umid and mumid='$mumid'";
		}
		$result= mysqli_query($conn, $query) or die("Error");
	}
	$_SESSION['msg'] = "Record deleted successfully";
	header('Location: user.php');
	
?>