<?php
include '../config.php';  include '../checkSession.php';
$id = $_GET['id'];
$new = $_GET['new'];
$lang = $_GET['lang'];


if($new == 1){
    $textoacepta ="newok";
}

if($new == 0){
    $textoacepta ="ok";
}

$textoacepta = $new;
$endpoint =  $endpoint_graph_cms;
if(strlen($id)>10){

    $curl = curl_init();

    if($lang=='es'){

        curl_setopt_array($curl, array(
            CURLOPT_URL => $endpoint,
            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',

            CURLOPT_POSTFIELDS =>'{"query":"mutation MyMutation {\\r\\n  updateUsuarioSitioPrivado(data: {localizations: {update: {data: {tycAceptados: \\"'.$textoacepta.'\\"}, locale: es_MX}}}, where: {id: \\"'.$id.'\\"}) {\\r\\n    id\\r\\n  }\\r\\n  unpublishUsuarioSitioPrivado(where: {id: \\"'.$id.'\\"}) {\\r\\n    id\\r\\n  }\\r\\n publishUsuarioSitioPrivado(where: {id: \\"'.$id.'\\"}, locales: es_MX, to: PUBLISHED) {\\r\\n    id\\r\\n  }\\r\\n}\\r\\n","variables":{}}',
            CURLOPT_HTTPHEADER => array(
              'Content-Type: application/json',
              'Cookie: __cfduid=da2693cdfd39b7377a8a05e305da45b8f1613001694'
            ),
          ));

    }
    
    if($lang=='en'){

        curl_setopt_array($curl, array(
            CURLOPT_URL => $endpoint,
            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',

            CURLOPT_POSTFIELDS =>'{"query":"mutation MyMutation {\\r\\n  updateUsuarioSitioPrivado(data: {tycAceptados: \\"'.$textoacepta.'\\"}, where: {id: \\"'.$id.'\\"}) {\\r\\n    id\\r\\n  }\\r\\n  unpublishUsuarioSitioPrivado(where: {id: \\"'.$id.'\\"}) {\\r\\n    id\\r\\n  }\\r\\n publishUsuarioSitioPrivado(where: {id: \\"'.$id.'\\"}, locales: es_MX, to: PUBLISHED) {\\r\\n    id\\r\\n  }\\r\\n}\\r\\n","variables":{}}',
            CURLOPT_HTTPHEADER => array(
              'Content-Type: application/json',
              'Cookie: __cfduid=da2693cdfd39b7377a8a05e305da45b8f1613001694'
            ),
          ));

    }


    $modeloupdate = 'updateUsuarioSitioPrivado';
    $response = curl_exec($curl);
    curl_close($curl);
    //echo $response;
    
    $jsonrespuesta = json_decode($response, true);
    $id = $jsonrespuesta['data'][$modeloupdate]['id'];

    //echo $id;

    $sucess = "<p class='successmensaje'>Status actualizado correctamente</p>";
    $fail = "<p class='errormensaje'>Falló la actualización de status..</p> ";


    if(strlen($id)>10){

        
        echo $success;


    }

    else{
        echo $fail;
    }


}