<?php
	
	ini_set("display_startup_errors", 1);
    ini_set("display_errors", 1);
    error_reporting(E_ALL);
	if(isset($_REQUEST['ajax'])){

		if(!isset($_REQUEST['refer_id']) || empty($_REQUEST['refer_id'])){
		 $validErr = "Please Enter Sponsor Id";
		}

		if(isset($validErr)){
			$result['status']=0;
			$result['message']=$validErr;
			return json_encode($result);
			exit();
		}
	
		$apiName = "API_check_refer_idV2.php";

		$params['refer_id'] = $_POST['refer_id'];

	}else{

		if(!isset($_REQUEST['firstName']) || empty($_REQUEST['firstName'])){
			$validErr = "Please Enter First Name";
		} else if(!isset($_REQUEST['lastName']) || empty($_REQUEST['lastName'])){
			$validErr = "Please Enter Last Name";
		} else if(!isset($_REQUEST['mobileNumber']) || empty($_REQUEST['mobileNumber'])){
			$validErr = "Please Enter Mobile Number";
		} else if(!isset($_REQUEST['emailID']) || empty($_REQUEST['emailID'])){
			$validErr = "Please Enter Email Address";
		} else if(!isset($_REQUEST['countryCode']) || empty($_REQUEST['countryCode'])){
			$validErr = "Please Enter country Code";
		} else if(!isset($_REQUEST['sponsorID']) || empty($_REQUEST['sponsorID'])){
			$validErr = "Please Enter Sponsor Id";
		}

		if(isset($validErr)){
			$result['status']=0;
			$result['message']=$validErr;
			echo json_encode($result);
			exit();
		}

		$apiName = "API_registrationv2.php";

		$params['first_name'] = $_POST['firstName'];
		$params['last_name'] =  $_POST['lastName'];
		$params['mobile_number']  =  $_POST['mobileNumber'];
		$params['email_address'] =  $_POST['emailID'];
		$params['sponsor_id'] = empty($_POST['placementID']) ? $_POST['sponsorID'] : $_POST['placementID'];
		$params['verified'] = 0;// ( 1 for yes and 0 for no )
		$params['Source'] = 1; // ( If member add by self then send 1 else 0)
		$params['country_code'] = empty($_REQUEST['countryCode']) ? '91' : $_REQUEST['countryCode'];
		$params['sponsor_by'] = $_POST['sponsorID'];
		$params['right_node'] = $_POST['cmbPlacement']=='right' ? 1 : 0;
		$params['left_node'] = $_POST['cmbPlacement']=='left' ? 1 : 0;
		$params['account_type'] = $_POST['membershipRadios'];
		$params['page_type'] = 0;

	}

	
	$url = "http://localhost/MyBooster/API/".$apiName;
    //$url = "localhost/marvel/API/".$apiName;
	$data_string = http_build_query($params);

    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_VERBOSE, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $output = curl_exec($ch);
    $status = curl_getinfo($ch, CURLINFO_HTTP_CODE);

    print $output;


    ?>