<?php
session_start();
require_once("utilities.php");

$url = "API_check_refer_idV2.php?";
$data = array();

if(!empty($_REQUEST['txtType']) && !empty($_REQUEST['txtMemberID']) && !empty($_REQUEST['txtLeg']))
{

   
	if($_REQUEST['txtType']==1)
	{
		$data = json_decode(callAPI("API_check_refer_idV2.php","refer_id=". $_REQUEST['txtMemberID']));
		$_SESSION['parentID'] = $_REQUEST['txtMemberID'];
        $_SESSION['parentName'] = $data->user_info->name . " " . $data->user_info->last_name;
	    $_SESSION['leg'] = $_REQUEST['txtLeg'];

    	if($_SESSION['parentID']==$_SESSION['refer_id'])
			header('Location: ../add-new-member.php?viewType=1');

		else
			header('Location: ../add-new-member.php?viewType=2');

	}

	else
	{
		$data = json_decode(callAPI("API_check_refer_idV2.php","refer_id=". $_REQUEST['txtMemberID']));
		$_SESSION['parentID'] = $data->user_info->sponsor_id;
	    $_SESSION['leg'] = $_REQUEST['txtLeg'];

		if($data->status)
		{
			$data = json_decode(callAPI("API_check_refer_idV2.php?","refer_id=". $_SESSION['parentID']));
			$_SESSION['parentName'] = $data->user_info->name;
		}

		header('Location: ../add-new-member.php?viewType=2');

	}



}


else
{

  header('Location: ../logout.php');

}





?>