<?php

    //validamos si la session no ha sido declarada, para incicializarla

    if (session_status() === PHP_SESSION_NONE) {

      session_start();

    }

    if(empty($_SESSION['login_appquadrata'])){

        echo"<script language='javascript'>window.location='../../../login'</script>;";

        exit();

    }



/*inicializamos valores para la configuracion del template*/

$setting_template='../../../settings_template.txt';

$variables=[];

$_Color='';

$_Template='';

$_Theme_Template='';

$_Css='';

$_Js='';

if (file_exists($setting_template)) {

    $lines = file($setting_template, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);

    foreach ($lines as $line) {

        list($nombre_variable, $valor) = explode('=', $line);

        $variables[$nombre_variable] = $valor;

    }

    /*recogemos los valores de las variables*/

    if (isset($variables['Color'])) {

        $_Color = $variables['Color'];



        //echo "El color es: $_Color";

    }

    if (isset($variables['Template'])) {

        $_Template = $variables['Template'];

        //echo "El Template es: $_template";

    }

    if (isset($variables['Theme_Template'])) {

        $_Theme_Template = $variables['Theme_Template'];

        //echo "El Theme_Template es: $_Theme_Template";

    }

    if (isset($variables['css'])) {

        $_Css = $variables['css'];

        //echo "El css es: $_Css";

    }

    if (isset($variables['js'])) {

        $_Js = $variables['js'];

        //echo "El js es: $_Js";

    }



    if (isset($variables['Rows_Columns'])) {

        $_Rows_Columns = $variables['Rows_Columns'];

    }else{

        $_Rows_Columns=4;

    }

}

/*terminan valores de configuracion pára el template*/

?>

<html  style="background-color: rgb(241, 245, 249);" lang="es" class="<?php if($_Color!=''){ echo 'theme-user'; }else{ echo $_Theme_Template; }?>">

<meta http-equiv='Content-Type' content='text/html; charset=ISO-8859-1'>

<meta name='description' content='Información sobre contenido de tu pagina'>

<meta name='keywords' content='aqui van los tags para ser encontrados por los boots de google ejemplo fibora,ti hyper solutions'>



<head>



<?php

//Declaramos la variable time, para que al modificar un archivo, este no se guarde en cache y se vizualicen los cambios

    $time_log_assets=time();

    include('../../path.php');

    //require('../modelo/rol.php');

    require(ROOT_CONTROLLER.'rol.php');

    $Obj_rol = new rol();   

?>



    <link href='http://netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap.min.css' rel='stylesheet'>

    <script src='http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.js'></script>

    <meta name="viewport" content="width=device-width,initial-scale=1">

    <!-- BEGIN: CSS Assets-->

    <link rel="stylesheet" href="../../../dist/css/<?=$_Css;?>?time=<?=$time_log_assets;?>" />

    <link rel="stylesheet" href="../../../dist/css/app_style.css?time=<?=$time_log_assets;?>" />

    <!-- END: CSS Assets-->

    <script src="../../../dist/js/noback.js?time=<?=$time_log_assets;?>" type="text/javascript"></script>

    <!--Comienza plugins JTABLE--->

    <script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>

    <!--Termina plugins JTABLE--->

        

<?php



$action=!empty($_REQUEST['action'])?$_REQUEST['action']:'';

$pagina=!empty($_REQUEST['pagina'])?$_REQUEST['pagina']:'';

$_ScrollTo=!empty($_REQUEST['_ScrollTo'])?$_REQUEST['_ScrollTo']:'';



$Id_Rol=!empty($_REQUEST['Id_Rol'])?$_REQUEST['Id_Rol']:'';



$Titulo_Rol='';

$Fecha_Registro='';

$Fecha_Modifico='';



switch ($action) {

    case 'editar':



        echo"<TITLE>Editar rol</TITLE>";

        break;



    default:

        echo"<TITLE>Registrar rol</TITLE>";

        break;

}

require_once(ROOT_CHARACTER_FIX);

$Obj_fix_characters = new fix_characters();



//lee las variables del formulario.

if (!empty($_POST))

{

    //require_once($context_rol.'odbconexion/config.php');

    require_once(ROOT_CONFIG);      

    $Odbj_conexion = new odbconexion;

    $conexion=$Odbj_conexion->openconection();

    $consulta="SELECT * FROM rol_appquadrata WHERE Id_Rol='$Id_Rol' ORDER BY Id_Rol DESC";

    $Array_adapter_rol=$conexion->query($consulta);

    $conexion->close();

    while($field_rol=$Array_adapter_rol->fetch_assoc())

    {

    $Titulo_Rol=$field_rol['Titulo_Rol'];

   $Fecha_Registro=$field_rol['Fecha_Registro'];

   $Fecha_Modifico=$field_rol['Fecha_Modifico'];

   

    }

}?>    



<?php  

    $arreglo_registers = array();

    $Odbj_conexion = new odbconexion;

    $conexion=$Odbj_conexion->openconection();

    $consulta="SELECT * FROM rol_appquadrata where Id_Rol !=1 AND Id_Rol!=2 ORDER BY Id_Rol ASC";

    $Array_adapter_rol_registers=$conexion->query($consulta);

    $conexion->close();

    $rows_registers=$Array_adapter_rol_registers->num_rows;

    $row_registers=0;

    while($field_rol_register=$Array_adapter_rol_registers->fetch_assoc())

    {

        $row_registers++;

        array_push($arreglo_registers, array("id" => $field_rol_register['Id_Rol'], "numero" => $row_registers));

   

    }

?> 

<script language='JavaScript'> 

var statSend = false;

function checkSubmit() {

    if (!statSend) {

        statSend = true;

        return true;

    } else {

        alert('La Informaci\u00F3n ya se est\u00E1 enviando, por favor espere...');

        return false;

    }

}

</script> 

<style>

    ::-webkit-scrollbar {

        display: none;

    }



    .btn-navigation-registers{



      background: none;

      border: 0;

      color: inherit;

      /* cursor: default; */

      font: inherit;

      line-height: normal;

      overflow: visible;

      padding: 0;

        -webkit-user-select: none; /* for button */

        -webkit-appearance: button; /* for input */

        -moz-user-select: none;

        -ms-user-select: none;

    }

</style>

</head>

<center>

<body onload="noback();">



  <?php



    //Comienza form del formulario

echo "<div class='intro-y box form-box'>";

    

    switch ($action) {

    case 'editar':

        echo "

            <div class='flex items-center p-5 border-b border-slate-200/60 dark:border-darkmode-400'>

                <h2 class='font-medium text-base mr-auto'>

                    EDITAR ROL

                </h2>";

            foreach ($arreglo_registers as $elemento) {

                    if ($elemento["id"] === $Id_Rol) {

                        $numeroEncontrado = $elemento["numero"];

                        break; // Detén el bucle una vez que se encuentre el elemento

                    }

                }

                echo "<p class='mr-3'>".$numeroEncontrado."/".$rows_registers."</p>";



                if($numeroEncontrado>1){

                    $registerPrev=$numeroEncontrado-1;

                    

                    foreach ($arreglo_registers as $elemento) {

                        if ($elemento["numero"] === $registerPrev) {

                            $idEncontradoPrev = $elemento["id"];

                            break; // Detén el bucle una vez que se encuentre el elemento

                        }

                    }

                    echo "<form action='./formulario.php' method='Post' onsubmit='loadingpage();'>

                        <input type='hidden' value='$idEncontradoPrev' name='Id_Rol'>

                        <input name='action' value='editar' type='hidden'>

                        <button type='submit' class='btn-navigation-registers'><svg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' icon-name='chevron-left' data-lucide='chevron-left' class='lucide chevron-left w-6 h-6 mr-1 mt-1'><path d='M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z'></path><circle cx='12' cy='12' r='3'></circle></svg></button>

                    </form>";

                }



                if($numeroEncontrado<$row_registers){

                    $registerNext=$numeroEncontrado+1;

                    

                    foreach ($arreglo_registers as $elemento) {

                        if ($elemento["numero"] === $registerNext) {

                            $idEncontradoNext = $elemento["id"];

                            break; // Detén el bucle una vez que se encuentre el elemento

                        }

                    }

                    echo "<form action='./formulario.php' method='Post' onsubmit='loadingpage();'>

                        <input type='hidden' value='$idEncontradoNext' name='Id_Rol'>

                        <input name='action' value='editar' type='hidden'>

                        <button type='submit' class='btn-navigation-registers'><svg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' icon-name='chevron-right' data-lucide='chevron-right' class='lucide chevron-right w-6 h-6 mr-1 mt-1'><path d='M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z'></path><circle cx='12' cy='12' r='3'></circle></svg></button>

                    </form>";

                }

        echo "</div>";

        break;

    

    default:

        echo"

            <div class='flex items-center p-5 border-b border-slate-200/60 dark:border-darkmode-400'>

                <h2 class='font-medium text-base mr-auto'>

                    REGISTRAR ROL

                </h2>

            </div>";

        break;

    }



    switch($_Rows_Columns){

        case 1:

        $cols_columns=12;

        break;

        case 2:

        $cols_columns=6;

        break;

        case 3:

        $cols_columns=4;

        break;

        case 4:

        $cols_columns=3;

        break;

        default:

        $cols_columns=12;

        break;



    }



    echo "<div class='p-5'>

            <form name='registrar'onsubmit='loadingpage();return checkSubmit();' action='../bussines/guardar.php' method='Post'>      

            <div class='grid grid-cols-12 gap-x-5'>

                <div class='col-span-12'>";



                    echo "<input type='hidden' name='Id_Rol' value='$Id_Rol'>";

                    echo "<input type='hidden' name='pagina' value='$pagina'>";

                    echo "<input type='hidden' name='_ScrollTo' value='$_ScrollTo'>";

                    echo "<div class='grid grid-cols-12 gap-x-5'>";

                      echo " 

                                <div class='mt-3 col-span-12 lg:col-span-$cols_columns xl:col-span-$cols_columns'>

                                    <label for='update-profile-form-7' class='form-label'>Titulo Rol: </label>

                                    <input id='Titulo_Rol' name='Titulo_Rol' value='$Titulo_Rol' type='text' class='form-control'>

                                </div>";

                    echo "</div>";

                                                   

echo "              

                </div>

            </div>";

         switch ($action) {

            case 'editar':



          echo "<div class='flex justify-end mt-4'>

                    <input type='hidden' name='action' value='editar'>

                    <a href='./?pagina=$pagina&_Id_Registro=$Id_Rol&_ScrollTo=$_ScrollTo#$Id_Rol' class='btn btn-danger w-20 mr-auto'> Cancelar</a>

                    <button type='submit' class='btn btn-primary flex items-center'>Guardar</button>

                </div>";

            break;

            case 'duplicar':

        echo   "<div class='flex justify-end mt-4'>

                    <input type='hidden' name='action' value='Duplicar'>

                    <a href='./?pagina=$pagina&_Id_Registro=$Id_Rol&_ScrollTo=$_ScrollTo' class='btn btn-danger w-20 mr-auto'> Cancelar</a>

                    <button type='submit' class='btn btn-primary flex items-center'>Guardar</button>

                </div>";

            break;

            default:

        echo   "<div class='flex justify-end mt-4'>

                    <input type='hidden' name='action' value='registrar'>

                    <a href='./?pagina=$pagina&_Id_Registro=$Id_Rol&_ScrollTo=$_ScrollTo' class='btn btn-danger w-20 mr-auto'> Cancelar</a>

                    <button type='submit' class='btn btn-primary flex items-center'>Guardar</button>

                </div>";

            break;

        }                

            

echo "  </form>

        </div>

    </div>";





    //Termina form del formulario

?>



<script src="../../../dist/js/app.js?time=<?=$time_log_assets;?>"></script> 

<script type="text/javascript">

  window.onload=function(){

    parent.document.getElementById('loadingpage').style.display='none';

  }



  function loadingpage(){

      parent.document.getElementById('loadingpage').style.display='block';                     

   }

</script>  

</center>

</body>

</html>