<?php
session_start();
require_once('../conexion.php');
require_once('../include/sesiones.php');
require_once('../php_api/api.php');

 $tipo = $_GET['tipo'] ?? '';
 $estado = $_GET['estado'] ?? '';

if (isset($_GET['estado'])) 
{
    
    if($tipo=='ele')
    {
        $registros=mysqli_query($con,"UPDATE configuracion_electronica Set ele_ambiente_ele='$estado' Where empresa='$empresa'") or die(mysqli_error($con));
        if($estado=='produccion')
        {
            $json = array(
                "type_environment_id" => 1
            );
        }
        else
        {
            $json = array(
                "type_environment_id" => 2
            );
        }
    }
    else if($tipo=='pos')
    {
        $registros=mysqli_query($con,"UPDATE configuracion_electronica Set ele_ambiente_pos='$estado' Where empresa='$empresa'") or die(mysqli_error($con));
        if($estado=='produccion')
        {
            $json = array(
                "eqdocs_type_environment_id" => 1
            );
        }
        else
        {
            $json = array(
                "eqdocs_type_environment_id" => 2
            );
        }
    }
    else if($tipo=='nom')
    {
        $registros=mysqli_query($con,"UPDATE configuracion_electronica Set ele_ambiente_nom='$estado' Where empresa='$empresa'") or die(mysqli_error($con));
        if($estado=='produccion')
        {
            $json = array(
                "payroll_type_environment_id" => 1
            );
        }
        else
        {
            $json = array(
                "payroll_type_environment_id" => 2
            );
        }
    }
   
}
$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "{$configuration->base_url}ubl2.1/config/environment",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'PUT',
  CURLOPT_POSTFIELDS =>json_encode($json),
  CURLOPT_HTTPHEADER => array(
    'Authorization: Bearer '.$token,
    'Content-Type: application/json',
    'Accept: application/json'
  ),
));

$response = curl_exec($curl);

curl_close($curl);
$response; 
?>