<?php
//FUN��ES COM API NOVA DO NEXTBILLING


//api next consulta grava��es
function nextura($id_record, $date_ini, $date_end, $url, $token, $key)
{
	$data = '';
	$data_string = json_encode($data);
	$api = "cdrIvr";

	$ch = curl_init("http://$url/api/$api/$token/$key/$id_record?date_ini=$date_ini&date_end=$date_end&start=0");
	curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
	curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
	curl_setopt($ch, CURLOPT_TIMEOUT, 30);
	curl_setopt(
		$ch,
		CURLOPT_HTTPHEADER,
		array(
			"Content-Type: application/json",
			"Content-Length: " . strlen($data_string)
		)
	);
	$retorno = curl_exec($ch);
	$retorno = json_decode($retorno, true);
	if (is_null($retorno)) {
		$ch = curl_init("https://$url/api/$api/$token/$key/$id_record?date_ini=$date_ini&date_end=$date_end&start=0");
		curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
		curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
		curl_setopt($ch, CURLOPT_TIMEOUT, 30);
		curl_setopt(
			$ch,
			CURLOPT_HTTPHEADER,
			array(
				"Content-Type: application/json",
				"Content-Length: " . strlen($data_string)
			)
		);
		$retorno = curl_exec($ch);
		$retorno = json_decode($retorno, true);
	}
	return $retorno;
}
//FIM //api next consulta grava��es

//api click2call
function nextclick2call($dados, $url, $token, $key)
{
	$data_string = json_encode($dados);

	$ch = curl_init("http://$url/api/click2Call/$token/$key");
	curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
	curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
	curl_setopt($ch, CURLOPT_TIMEOUT, 30);
	curl_setopt(
		$ch,
		CURLOPT_HTTPHEADER,
		array(
			"Content-Type: application/json",
			"Content-Length: " . strlen($data_string)
		)
	);
	$retorno = curl_exec($ch);
	$retorno = json_decode($retorno, true);
	if (is_null($retorno)) {
		$ch = curl_init("https://$url/api/click2Call/$token/$key");
		curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
		curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
		curl_setopt($ch, CURLOPT_TIMEOUT, 30);
		curl_setopt(
			$ch,
			CURLOPT_HTTPHEADER,
			array(
				"Content-Type: application/json",
				"Content-Length: " . strlen($data_string)
			)
		);
		$retorno = curl_exec($ch);
		$retorno = json_decode($retorno, true);
	}
	return $retorno;
}
//FIM //api click2call

//api next via get para listar codecs
function nextcodecs()
{
	$data = '';
	$data_string = json_encode($data);
	$url = "http://177.11.50.202";
	$token = "224f0533-d990-59b9-83ee-1bd6f9281bef-3064";
	$key = "fa71451e-1664-59a5-996d-bb5b903ed695-7548";
	$api = "listCodecs";

	$ch = curl_init("$url/api/$api/$token/$key");
	curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
	curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
	curl_setopt($ch, CURLOPT_TIMEOUT, 30);
	curl_setopt(
		$ch,
		CURLOPT_HTTPHEADER,
		array(
			"Content-Type: application/json",
			"Content-Length: " . strlen($data_string)
		)
	);
	$retorno = curl_exec($ch);
	$retorno = json_decode($retorno, true);
	return $retorno;
}

//api next via delete dados
function nextdeletedados($api, $dados, $url, $token, $key)
{
	$data_string = json_encode($dados);

	$ch = curl_init("http://$url/api/$api/$token/$key");
	curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
	curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
	curl_setopt($ch, CURLOPT_TIMEOUT, 30);
	curl_setopt(
		$ch,
		CURLOPT_HTTPHEADER,
		array(
			"Content-Type: application/json",
			"Content-Length: " . strlen($data_string)
		)
	);
	$retorno = curl_exec($ch);
	$retorno = json_decode($retorno, true);
	if (is_null($retorno)) {
		$ch = curl_init("https://$url/api/$api/$token/$key");
		curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
		curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
		curl_setopt($ch, CURLOPT_TIMEOUT, 30);
		curl_setopt(
			$ch,
			CURLOPT_HTTPHEADER,
			array(
				"Content-Type: application/json",
				"Content-Length: " . strlen($data_string)
			)
		);
		$retorno = curl_exec($ch);
		$retorno = json_decode($retorno, true);
	}
	return $retorno;
}
//FIM //api next via delete dados

//api next delete
function nextdelete($api, $id, $url, $token, $key)
{
	$data = '';
	$data_string = json_encode($data);

	$ch = curl_init("http://$url/api/$api/$token/$key/$id");
	curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
	curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
	curl_setopt($ch, CURLOPT_TIMEOUT, 30);
	curl_setopt(
		$ch,
		CURLOPT_HTTPHEADER,
		array(
			"Content-Type: application/json",
			"Content-Length: " . strlen($data_string)
		)
	);
	$retorno = curl_exec($ch);
	$retorno = json_decode($retorno, true);
	if (is_null($retorno)) {
		$ch = curl_init("https://$url/api/$api/$token/$key/$id");
		curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
		curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
		curl_setopt($ch, CURLOPT_TIMEOUT, 30);
		curl_setopt(
			$ch,
			CURLOPT_HTTPHEADER,
			array(
				"Content-Type: application/json",
				"Content-Length: " . strlen($data_string)
			)
		);
		$retorno = curl_exec($ch);
		$retorno = json_decode($retorno, true);
	}

	return $retorno;
}
//FIM //api next delete

//api next via post
function nextpost($api, $dados, $url, $token, $key)
{
	$data_string = json_encode($dados);

	$ch = curl_init("http://$url/api/$api/$token/$key");
	curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
	curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
	curl_setopt($ch, CURLOPT_TIMEOUT, 30);
	curl_setopt(
		$ch,
		CURLOPT_HTTPHEADER,
		array(
			"Content-Type: application/json",
			"Content-Length: " . strlen($data_string)
		)
	);
	$retorno = curl_exec($ch);
	$retorno = json_decode($retorno, true);
	if (is_null($retorno)) {
		$ch = curl_init("https://$url/api/$api/$token/$key");
		curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
		curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
		curl_setopt($ch, CURLOPT_TIMEOUT, 30);
		curl_setopt(
			$ch,
			CURLOPT_HTTPHEADER,
			array(
				"Content-Type: application/json",
				"Content-Length: " . strlen($data_string)
			)
		);
		$retorno = curl_exec($ch);
		$retorno = json_decode($retorno, true);
	}
	return $retorno;
}
//FIM //api next via post

//api next via put
function nextput($api, $dados, $url, $token, $key)
{
	$data_string = json_encode($dados);
	$ch = curl_init("http://$url/api/$api/$token/$key");
	curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
	curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
	curl_setopt($ch, CURLOPT_TIMEOUT, 30);
	curl_setopt(
		$ch,
		CURLOPT_HTTPHEADER,
		array(
			"Content-Type: application/json",
			"Content-Length: " . strlen($data_string)
		)
	);
	$retorno = curl_exec($ch);
	$retorno = json_decode($retorno, true);
	if (is_null($retorno)) {
		$ch = curl_init("https://$url/api/$api/$token/$key");
		curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
		curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
		curl_setopt($ch, CURLOPT_TIMEOUT, 30);
		curl_setopt(
			$ch,
			CURLOPT_HTTPHEADER,
			array(
				"Content-Type: application/json",
				"Content-Length: " . strlen($data_string)
			)
		);
		$retorno = curl_exec($ch);
		$retorno = json_decode($retorno, true);
	}
	return $retorno;
}
//FIM //api next via put

//api next via post altera assinante
function nextpostAltera($api, $dados, $url, $token, $key, $id_plataforma)
{
	$data_string = json_encode($dados);

	$ch = curl_init("http://$url/api/$api/$token/$key/$id_plataforma");
	curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
	curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
	curl_setopt($ch, CURLOPT_TIMEOUT, 30);
	curl_setopt(
		$ch,
		CURLOPT_HTTPHEADER,
		array(
			"Content-Type: application/json",
			"Content-Length: " . strlen($data_string)
		)
	);
	$retorno = curl_exec($ch);
	$retorno = json_decode($retorno, true);
	if (is_null($retorno)) {
		$ch = curl_init("https://$url/api/$api/$token/$key/$id_plataforma");
		curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
		curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
		curl_setopt($ch, CURLOPT_TIMEOUT, 30);
		curl_setopt(
			$ch,
			CURLOPT_HTTPHEADER,
			array(
				"Content-Type: application/json",
				"Content-Length: " . strlen($data_string)
			)
		);
		$retorno = curl_exec($ch);
		$retorno = json_decode($retorno, true);
	}
	return $retorno;
}
//FIM //api next via post altera assinante

//api next via get
function nextget($api, $id, $url, $token, $key)
{
	$data = '';
	$data_string = json_encode($data);

	$ch = curl_init("http://$url/api/$api/$token/$key/$id");
	curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
	curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
	curl_setopt($ch, CURLOPT_TIMEOUT, 30);
	curl_setopt(
		$ch,
		CURLOPT_HTTPHEADER,
		array(
			"Content-Type: application/json",
			"Content-Length: " . strlen($data_string)
		)
	);
	$retorno = curl_exec($ch);
	$retorno = json_decode($retorno, true);
	if (is_null($retorno)) {
		$ch = curl_init("https://$url/api/$api/$token/$key/$id");
		curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
		curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
		curl_setopt($ch, CURLOPT_TIMEOUT, 30);
		curl_setopt(
			$ch,
			CURLOPT_HTTPHEADER,
			array(
				"Content-Type: application/json",
				"Content-Length: " . strlen($data_string)
			)
		);
		$retorno = curl_exec($ch);
		$retorno = json_decode($retorno, true);
	}

	return $retorno;
}
//FIM //api next via get

//api next via get //consulta de saldo
function nextsaldo($id, $url, $token, $key)
{
	$api = "getCustomerBalance";
	$curl = curl_init();
	curl_setopt_array($curl, [
		CURLOPT_URL => "http://$url/api/$api/$token/$key/$id",
		CURLOPT_RETURNTRANSFER => true,
		CURLOPT_MAXREDIRS => 10,
		CURLOPT_TIMEOUT => 30,
		CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
		CURLOPT_CUSTOMREQUEST => "GET",
	]);
	$response = curl_exec($curl);
	$return = json_decode($response, true);
	if (is_null($return)) {
		$curl = curl_init();
		curl_setopt_array($curl, [
			CURLOPT_URL => "https://$url/api/$api/$token/$key/$id",
			CURLOPT_RETURNTRANSFER => true,
			CURLOPT_MAXREDIRS => 10,
			CURLOPT_TIMEOUT => 30,
			CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
			CURLOPT_CUSTOMREQUEST => "GET",
		]);
		$retorno = curl_exec($curl);
		$return = json_decode($retorno, true);
	}
	return $return;
}
//FIM //api next via get //consulta de saldo

//api next via cdr
function nextcdr($id_record, $date_ini, $date_end, $inicio, $total_por_pagina, $url, $token, $key)
{
	$data = '';
	$data_string = json_encode($data);
	$api = "cdr";
	if ($inicio > '0') $offset = "&offset=$inicio";
	else $offset = "";

	$ch = curl_init("http://$url/api/$api/$token/$key/$id_record?date_ini=$date_ini&date_end=$date_end&start=0&limit=$total_por_pagina.$offset");
	curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
	curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
	curl_setopt($ch, CURLOPT_TIMEOUT, 30);
	curl_setopt(
		$ch,
		CURLOPT_HTTPHEADER,
		array(
			"Content-Type: application/json",
			"Content-Length: " . strlen($data_string)
		)
	);
	$retorno = curl_exec($ch);
	$retorno = json_decode($retorno, true);
	if (is_null($retorno)) {
		$ch = curl_init("https://$url/api/$api/$token/$key/$id_record?date_ini=$date_ini&date_end=$date_end&start=0&limit=$total_por_pagina.$offset");
		curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
		curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
		curl_setopt($ch, CURLOPT_TIMEOUT, 30);
		curl_setopt(
			$ch,
			CURLOPT_HTTPHEADER,
			array(
				"Content-Type: application/json",
				"Content-Length: " . strlen($data_string)
			)
		);
		$retorno = curl_exec($ch);
		$retorno = json_decode($retorno, true);
	}
	return $retorno;
}
//FIM //api next via cdr

//api next via  cdrDID - ligações recebidas
function nextDIDcdr($id_record, $date_ini, $date_end, $inicio, $total_por_pagina, $url, $token, $key)
{
	$data = '';
	$data_string = json_encode($data);
	$api = "cdrDid";
	if ($inicio > '0') $offset = "&offset=$inicio";
	else $offset = "";

	$ch = curl_init("http://$url/api/$api/$token/$key/$id_record?date_ini=$date_ini&date_end=$date_end&start=0&limit=$total_por_pagina.$offset");
	curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
	curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
	curl_setopt($ch, CURLOPT_TIMEOUT, 30);
	curl_setopt(
		$ch,
		CURLOPT_HTTPHEADER,
		array(
			"Content-Type: application/json",
			"Content-Length: " . strlen($data_string)
		)
	);
	$retorno = curl_exec($ch);
	$retorno = json_decode($retorno, true);
	if (is_null($retorno)) {
		$ch = curl_init("https://$url/api/$api/$token/$key/$id_record?date_ini=$date_ini&date_end=$date_end&start=0&limit=$total_por_pagina.$offset");
		curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
		curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
		curl_setopt($ch, CURLOPT_TIMEOUT, 30);
		curl_setopt(
			$ch,
			CURLOPT_HTTPHEADER,
			array(
				"Content-Type: application/json",
				"Content-Length: " . strlen($data_string)
			)
		);
		$retorno = curl_exec($ch);
		$retorno = json_decode($retorno, true);
	}
	return $retorno;
}
//FIM //api next via cdrDID

//api next consulta grava��es
function nextgravacoes($id_record, $date_ini, $date_end, $url, $token, $key)
{
	$data = '';
	$data_string = json_encode($data);
	$api = "recording";

	$ch = curl_init("http://$url/api/$api/$token/$key/$id_record?date_ini=$date_ini&date_end=$date_end&start=0");
	curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
	curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
	curl_setopt($ch, CURLOPT_TIMEOUT, 30);
	curl_setopt(
		$ch,
		CURLOPT_HTTPHEADER,
		array(
			"Content-Type: application/json",
			"Content-Length: " . strlen($data_string)
		)
	);
	$retorno = curl_exec($ch);
	$retorno = json_decode($retorno, true);
	if (is_null($retorno)) {
		$ch = curl_init("https://$url/api/$api/$token/$key/$id_record?date_ini=$date_ini&date_end=$date_end&start=0");
		curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
		curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
		curl_setopt($ch, CURLOPT_TIMEOUT, 30);
		curl_setopt(
			$ch,
			CURLOPT_HTTPHEADER,
			array(
				"Content-Type: application/json",
				"Content-Length: " . strlen($data_string)
			)
		);
		$retorno = curl_exec($ch);
		$retorno = json_decode($retorno, true);
	}
	return $retorno;
}
//FIM //api next consulta grava��es

//api next via get //lista assinantes
function nextassinantes($id, $url, $token, $key)
{
	$data = '';
	$data_string = json_encode($data);
	$api = "listCustomers";

	$ch = curl_init("http://$url/api/$api/$token/$key/$id");
	curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
	curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
	curl_setopt($ch, CURLOPT_TIMEOUT, 30);
	curl_setopt(
		$ch,
		CURLOPT_HTTPHEADER,
		array(
			"Content-Type: application/json",
			"Content-Length: " . strlen($data_string)
		)
	);
	$retorno = curl_exec($ch);
	$retorno = json_decode($retorno, true);
	if (is_null($retorno)) {
		$ch = curl_init("https://$url/api/$api/$token/$key/$id");
		curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
		curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
		curl_setopt($ch, CURLOPT_TIMEOUT, 30);
		curl_setopt(
			$ch,
			CURLOPT_HTTPHEADER,
			array(
				"Content-Type: application/json",
				"Content-Length: " . strlen($data_string)
			)
		);
		$retorno = curl_exec($ch);
		$retorno = json_decode($retorno, true);
	}
	return $retorno;
}
//FIM //api next via get //lista assinantes

//api next via get //lista contatos
function nextcontatos($limit, $offset, $url, $token, $key)
{
	$data = '';
	$data_string = json_encode($data);
	$api = "contacts";

	$ch = curl_init("http://$url/api/$api/$token/$key?limit=$limit&offset=$offset");
	curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
	curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
	curl_setopt($ch, CURLOPT_TIMEOUT, 30);
	curl_setopt(
		$ch,
		CURLOPT_HTTPHEADER,
		array(
			"Content-Type: application/json",
			"Content-Length: " . strlen($data_string)
		)
	);
	$retorno = curl_exec($ch);
	$retorno = json_decode($retorno, true);
	if (is_null($retorno)) {
		$ch = curl_init("https://$url/api/$api/$token/$key?limit=$limit&offset=$offset");
		curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
		curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
		curl_setopt($ch, CURLOPT_TIMEOUT, 30);
		curl_setopt(
			$ch,
			CURLOPT_HTTPHEADER,
			array(
				"Content-Type: application/json",
				"Content-Length: " . strlen($data_string)
			)
		);
		$retorno = curl_exec($ch);
		$retorno = json_decode($retorno, true);
	}
	return $retorno;
}
//FIM //api next via get //lista contatos

//api next via get //chamadas ativas
function nextchamadas($id_record, $url, $token, $key)
{
	$data = '';
	$data_string = json_encode($data);
	$api = "onlineCalls";

	$ch = curl_init("http://$url/api/$api/$token/$key?id_record=$id_record");
	curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
	curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
	curl_setopt($ch, CURLOPT_TIMEOUT, 30);
	curl_setopt(
		$ch,
		CURLOPT_HTTPHEADER,
		array(
			"Content-Type: application/json",
			"Content-Length: " . strlen($data_string)
		)
	);
	$retorno = curl_exec($ch);
	$retorno = json_decode($retorno, true);
	if (is_null($retorno)) {
		$ch = curl_init("https://$url/api/$api/$token/$key?id_record=$id_record");
		curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
		curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
		curl_setopt($ch, CURLOPT_TIMEOUT, 30);
		curl_setopt(
			$ch,
			CURLOPT_HTTPHEADER,
			array(
				"Content-Type: application/json",
				"Content-Length: " . strlen($data_string)
			)
		);
		$retorno = curl_exec($ch);
		$retorno = json_decode($retorno, true);
	}
	return $retorno;
}
//FIM //api next via get //chamadas ativas

//api next via get //download grava��es
function nextdownloadgravacoes($id_assinante, $id_gravacao, $url, $token, $key)
{
	$api = "recording";
	$retorno = "http://$url/api/$api/$token/$key/$id_assinante?id_record=$id_gravacao&is_download=1";
	if (is_null($retorno)) {
		$retorno = "https://$url/api/$api/$token/$key/$id_assinante?id_record=$id_gravacao&is_download=1";
	}
	return $retorno;
}
//FIM //api next via get //download grava��es

//api next adiciona
function next_adiciona($api, $id_assinante, $dados, $url, $token, $key)
{
	$data_string = json_encode($dados);

	$ch = curl_init("http://$url/api/$api/$token/$key/$id_assinante");
	curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
	curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
	curl_setopt($ch, CURLOPT_TIMEOUT, 30);
	curl_setopt(
		$ch,
		CURLOPT_HTTPHEADER,
		array(
			"Content-Type: application/json",
			"Content-Length: " . strlen($data_string)
		)
	);
	$retorno = curl_exec($ch);
	$retorno = json_decode($retorno, true);
	if (is_null($retorno)) {
		$ch = curl_init("https://$url/api/$api/$token/$key/$id_assinante");
		curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
		curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
		curl_setopt($ch, CURLOPT_TIMEOUT, 30);
		curl_setopt(
			$ch,
			CURLOPT_HTTPHEADER,
			array(
				"Content-Type: application/json",
				"Content-Length: " . strlen($data_string)
			)
		);
		$retorno = curl_exec($ch);
		$retorno = json_decode($retorno, true);
	}
	return $retorno;
}
//FIM //api next adiciona

//api next delete
function next_delete($api, $id, $id_record, $url, $token, $key)
{
	$data = '';
	$data_string = json_encode($data);

	$ch = curl_init("http://$url/api/$api/$token/$key/$id?id_record=$id_record");
	curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
	curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
	curl_setopt($ch, CURLOPT_TIMEOUT, 30);
	curl_setopt(
		$ch,
		CURLOPT_HTTPHEADER,
		array(
			"Content-Type: application/json",
			"Content-Length: " . strlen($data_string)
		)
	);
	$retorno = curl_exec($ch);
	$retorno = json_decode($retorno, true);
	if (is_null($retorno)) {
		$ch = curl_init("https://$url/api/$api/$token/$key/$id?id_record=$id_record");
		curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
		curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
		curl_setopt($ch, CURLOPT_TIMEOUT, 30);
		curl_setopt(
			$ch,
			CURLOPT_HTTPHEADER,
			array(
				"Content-Type: application/json",
				"Content-Length: " . strlen($data_string)
			)
		);
		$retorno = curl_exec($ch);
		$retorno = json_decode($retorno, true);
	}
	return $retorno;
}
//FIM //api next delete

//api next altera
function next_altera($api, $id, $id_record, $dados, $url, $token, $key)
{
	$data_string = json_encode($dados);

	$ch = curl_init("http://$url/api/$api/$token/$key/$id?id_record=$id_record");
	curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
	curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
	curl_setopt($ch, CURLOPT_TIMEOUT, 30);
	curl_setopt(
		$ch,
		CURLOPT_HTTPHEADER,
		array(
			"Content-Type: application/json",
			"Content-Length: " . strlen($data_string)
		)
	);
	$retorno = curl_exec($ch);
	$retorno = json_decode($retorno, true);
	if (is_null($retorno)) {
		$ch = curl_init("https://$url/api/$api/$token/$key/$id?id_record=$id_record");
		curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
		curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
		curl_setopt($ch, CURLOPT_TIMEOUT, 30);
		curl_setopt(
			$ch,
			CURLOPT_HTTPHEADER,
			array(
				"Content-Type: application/json",
				"Content-Length: " . strlen($data_string)
			)
		);
		$retorno = curl_exec($ch);
		$retorno = json_decode($retorno, true);
	}
	return $retorno;
}
//FIM //api next altera
