<?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) {
	        $activity_query = $con->query("select * from attendance_activity where member_id = '$member_id' and status = '1' Order by id DESC");
	    } else {
	        $activity_query = $con->query("select * from attendance_activity where status = '1' Order by id DESC ");
	    }
		$activity_details = array();
		$all_activitys = array();
		while ($row1 = $activity_query->fetch_assoc()) {
			$activity_details['id'] = $row1['id'];
			$activity_details['member_id'] = $row1['member_id'];
			$memberid = $row1['created_by'];
			$member_query = $con->query("select * from app_users where member_id = '$memberid' Order by id DESC");
			if ($row2 = $member_query->fetch_assoc()) {
			    $activity_details['created_by'] = $row2['name'];
			}
			$activity_id = $row1['activity_id'];
			$act_query = $con->query("select * from activities where id = '$activity_id' Order by id DESC");
			if ($row3 = $act_query->fetch_assoc()) {
			    $activity_details['activity_name'] = $row3['name'];
			}
			$activity_details['name'] = $row1['name'];
			$activity_details['mobile'] = $row1['mobile'];
			$activity_details['description'] = $row1['description'];
			$all_activitys [] = $activity_details;
		}

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

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