<?php include("config.inc.php"); ?>
<?php
$maquina = $_GET['maquina'];

if($maquina == ""){
    header("Location: ".$arrConfig['url_site']."erro.php");
    exit();
}
$numTerminal = $_SESSION['numTerminal'];
$curl = curl_init();
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt_array($curl, array(
  CURLOPT_URL => $arrConfig["url_api"].'verificaMaquina?codigo='.$maquina.'&numTerminal='.$numTerminal,
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'POST',
  
));

$response = curl_exec($curl);

curl_close($curl);

$array = json_decode($response, true);
$resposta = $array['Resposta'][0];

$erro = $array['Erro'];
if($erro){
    echo "ola";
}
echo $erro;

echo $resposta;





if(!$erro){
   
 
$curl = curl_init();
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt_array($curl, array(
  CURLOPT_URL => $arrConfig["url_api"].'atualizaDados?numTerminal='.$numTerminal.'&CodMaquina='.$resposta,
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'POST',
  
));

$response = curl_exec($curl);

curl_close($curl);
echo "A";
$array = json_decode($response, true);





    $_SESSION['maquina'] = $resposta;
    //PEDIDO PHP API PARA ATUALIZAR INFORMAÇÕES NA TABELA
   
    header("Location: ".$arrConfig['url_site']."producao.php");
    exit();
}
else{
  
    header("Location: ".$arrConfig['url_site']."erro.php?lastPage=maquina.php&tipo=Máquina Inválida&descricao=O código de máquina que introduziu está incorreto.");
    exit();
}





?>