<?php 

session_start();
$usuarioSession = $_SESSION['USUARIO'];
$grupo = $_SESSION['GRUPO'];
$contacto = $_SESSION['CONTACTO'];
$awa_session_id = $_SESSION['AWA_SESION_ID'];

include('../../lg/config_vo.php');
include('../../includes/conex.php');
include('../../includes/eat.php');
include('../../class/Schema.php');

$cookieUser = filter_input(INPUT_COOKIE, 'usuario') ?? null; 
$cookieIdioma = filter_input(INPUT_COOKIE, 'idioma') ?? null; 
if((!isset($usuarioSession) or $awa_session_id != $awa_id) or (isset($cookieUser) AND $cookieUser != $staticUsu )){
    eatCookies();
    header('Location:../../index.php');}
empty($cookieIdioma)?
    include('../../lg/LG_' . $cookieIdioma . '.php'):
    include('../../lg/LG_SP.php');

$usuario     = filter_input(INPUT_POST, 'usuarioskey') ?? null;
$tipocambio  = filter_input(INPUT_POST, 'cambiar') ?? null; 
$perfilactual= filter_input(INPUT_POST, 'actual') ?? null; 

$html = '';
$html .= '<div class="modal-header">';
    $html .= '<h5 class="modal-title text-dark">' . $seleccion_perfil_lg . ": <span class='font-weight-light'>" . $usuario . "</span>" . '</h5>';
    $html .= '<button type="button" class="close" data-dismiss="modal" aria-label="Close">';
        $html .= '<span aria-hidden="true">&times;</span>';
    $html .= '</button>';
$html .= '</div>';

$html .= '<div class="modal-body">';
$html .= '<table class="table table-bordered"  style="border:none">';
$res = $con->query("SELECT USUARIOS_GRUPOS.CODIGO, USUARIOS_GRUPOS.DESCRIPCION FROM USUARIOS_GRUPOS" );
    $html .= '<tbody style="border:none">';
    while($row = $res->fetch_array()) { 
        $checked =  ($perfilactual === $row['DESCRIPCION'] ) ? " checked='checked' " : "";
        $html .= '<tr style="border:none; align:center;">';
            $html .= '<td style="border:none; text-align:center; width:10%; "  ><input type="radio" id="'.$row['CODIGO'].'" name="radiobtn-perfil" '.$checked.' value="'.$row['CODIGO'].'"></td>';
            $html .= '<td style="border:none"><label for="'.$row['CODIGO'].'">'.$row['DESCRIPCION'].'</label></td>';
        $html .= '</tr>';
    }
    $html .= '</tbody>';
$html .= '</table>';
$html .= '</div>';
//
//$html .= '<div class="modal-footer">';
//$html .=    '<button type="button" class="btn btn-primary" data-dismiss="modal">' . $guardar_cerrar_lg . '</button>';
//$html .= '</div>';

echo $html;

?>
    
<script>
    $("input[name='radiobtn-perfil']").change(function(){
        //console.log("Cambio en el radiobutton de cambio de perfil");
        $.post('ajax/ajustes-permisos-update-perfil.php', {usuario:'<?=$usuario?>', codigonuevoperfil: this.value });
    });
</script>