<?php

$data = array();


if (isset($_POST['token']))	$data['token'] = $_POST['token'];

if (isset($_POST['ida']))	$data['ida'] = $_POST['ida'];
if (isset($_POST['code']))	$data['code'] = $_POST['code'];

if (isset($_POST['active']))	$data['active'] = $_POST['active'];
if (isset($_POST['term']))	$data['term'] = $_POST['term'];

if (isset($_POST['phone']))	$data['phone'] = $_POST['phone'];
if (isset($_POST['email']))	$data['email'] = $_POST['email'];
if (isset($_POST['rub']))	$data['rub'] = $_POST['rub'];
if (isset($_POST['type_home']))	$data['type_home'] = $_POST['type_home'];
if (isset($_POST['extri']))	$data['extri'] = $_POST['extri'];

if (isset($_POST['tv']))	$data['tv'] = $_POST['tv'];
if (isset($_POST['tt']))	$data['tt'] = $_POST['tt'];

if (isset($_POST['hide_pp_info']))	$data['hide_pp_info'] = $_POST['hide_pp_info'];

if (isset($_POST['er']))	$data['er'] = $_POST['er'];
if (isset($_POST['etmax']))	$data['etmax'] = $_POST['etmax'];
if (isset($_POST['extinfo']))	$data['extinfo'] = $_POST['extinfo'];
if (isset($_POST['type_build']))	$data['type_build'] = $_POST['type_build'];

if (isset($_POST['year_build']))	$data['year_build'] = $_POST['year_build'];
if (isset($_POST['nwclg']))	$data['nwclg'] = $_POST['nwclg'];
if (isset($_POST['town']))	$data['town'] = $_POST['town'];
if (isset($_POST['craion']))	$data['craion'] = $_POST['craion'];
//"mraion": "43.22475,27.881022,0",

if (isset($_POST['price_type']))	$data['price_type'] = $_POST['price_type'];
if (isset($_POST['currency']))	$data['currency'] = $_POST['currency'];
if (isset($_POST['price']))	$data['price'] = $_POST['price'];
$data['price_dds'] = 2;


if (isset($_POST['area']))	$data['area'] = $_POST['area'];
if (isset($_POST['areah']))	$data['areah'] = $_POST['areah'];




// var_dump($data);
// return;

if (isset($_POST['token'])) {

	$ida = $_POST['ida'];
	$url = 'https://api.imot.bg/import_api/adverts/pub/?token=' . $_POST['token'];


	// Prepare new cURL resource
	$ch = curl_init($url);
	curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, $data);
	//curl_setopt($handle, CURLOPT_POSTFIELDS, $data);
	$result = curl_exec($ch);
	curl_close($ch);

	$response = json_decode($result, true);
	//    print_r('<br/>');
	//    print_r('111');
	//    print_r('<br/>');

	header("Content-type: application/json; charset=utf-8");
	print_r(json_encode($response));
} else {
	// print_r('<br/>');
	print_r('no');
}

//include_once("token.php");
// echo(1);
// echo('<br>');
//echo $_GET['ids'];
//var_dump($_GET['ida']);

//print_r($response);

// if(!empty($response) && isset($response['status']) && $response['status'] == 'success'){
// 	 $token = $response['data']['token'];
// 	 $property_post_id = $_POST['ida']; //change this value to property ID
// 	 $url = 'https://api.imot.bg/import_api/adverts/del/' . $token . '?ida=' . $property_post_id;
	
// 	// Prepare new cURL resource
// 	$ch = curl_init($url);
// 	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// 	$result = curl_exec($ch);
// 	curl_close($ch);     

// 	$response = json_decode($result, true);

// 	print_r($response);
// }
