<?php
require 'config_db.php';
$data = json_decode(file_get_contents('php://input'), true);
$user_type = $data['user_type'];
$mode = $data['mode'];
$member_id = $data['member_id'];

if ($user_type == '' || $member_id == '') {
	$returnArr = array("ResponseCode" => "401", "Result" => "false", "ResponseMsg" => "Something Went wrong try again !");
} else {
    // get all visitors
	if ($mode == 1) {
	    if($user_type == 2) {
	        $visitor_query = $con->query("select * from visitors where member_id = '$member_id' Order by id DESC");
	    } else {
	        $visitor_query = $con->query("select * from visitors Order by id DESC ");
	    }
		$visitor_details = array();
		$all_visitors = array();
		while ($row1 = $visitor_query->fetch_assoc()) {
			$visitor_details['id'] = $row1['id'];
			$visitor_details['member_id'] = $row1['member_id'];
			$member_id = $row1['member_id'];
			$member_query = $con->query("select * from app_users where member_id = '$member_id' Order by id DESC");
			if ($row2 = $member_query->fetch_assoc()) {
			    $visitor_details['member_name'] = $row2['name'];
			}
			$visitor_details['name'] = $row1['name'];
			$visitor_details['mobile'] = $row1['mobile'];
			$visitor_details['category'] = $row1['category'];
			$visitor_details['company'] = $row1['company'];
			$visitor_details['area'] = $row1['area'];
			$visitor_details['district'] = $row1['district'];
			$all_visitors [] = $visitor_details;
		}

		$returnArr = array(
			"ResponseCode" => "200",
			"Result" => "true",
			"ResponseMsg" => "Success",
			"data" => $all_visitors
		);
	}
}

echo json_encode($returnArr);
mysqli_close($con);
?>