<?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();

    }

?>



<?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_once(ROOT_CONFIG);

    $Rol_Usuario_Logued_App=$_SESSION['Rol_appquadrata'];

    $Registrar_En_Modulo_App="";

    $Leer_En_Modulo_App="";

    $Editar_En_Modulo_App="";

    $Exportar_En_Modulo_App="";

    $Eliminar_En_Modulo_App="";

    $Id_Modulo_Fk_En_Modulo_App=0;

    try{    



        $Odbj_conexion = new odbconexion;

        $conexion=$Odbj_conexion->openconection();

        $consulta="SELECT p.Id_Permiso_App,p.Id_Fk_Rol,p.Id_Modulo_Fk,p.Registrar,p.Leer,p.Editar,p.Eliminar,p.Exportar,m.Id_Modulo_App,m.Titulo_Modulo,m.Descripcion_Modulo,m.Tipo_Menu,m.Href_Modulo,m.Tipo_Enlace,m.Icon_Fa_Modulo FROM permiso_app_appquadrata p JOIN modulo_app_appquadrata m ON Id_Modulo_Fk=Id_Modulo_App WHERE Id_Fk_Rol='$Rol_Usuario_Logued_App' AND Leer='Si' ORDER BY Id_Permiso_App DESC ";

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

        $conexion->close();

        while($Field_Permiso_Modulo=$Array_adapter_permiso_modulo->fetch_assoc())

        {

            $Id_Modulo_Fk_En_Modulo_App=$Field_Permiso_Modulo['Id_Modulo_Fk'];

            $Registrar_En_Modulo_App=$Field_Permiso_Modulo['Registrar'];

            $Leer_En_Modulo_App=$Field_Permiso_Modulo['Leer'];

            $Editar_En_Modulo_App=$Field_Permiso_Modulo['Editar'];

            $Exportar_En_Modulo_App=$Field_Permiso_Modulo['Exportar'];

            $Eliminar_En_Modulo_App=$Field_Permiso_Modulo['Eliminar'];

        }

    }catch (Exception $e) {

        echo 'Excepcion capturada: ',  $e->getMessage(), "";

    }





/*inicializamos valores para la configuracion del template*/

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

$variables=[];

$_Color='';

$_Template='';

$_Theme_Template='';

$_Css='';

$_Js='';

$_Css_Version='';

$_Js_Version='';

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['css_version'])) {

        $_Css_Version = $variables['css_version'];

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

    }

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

        $_Js_Version = $variables['js_version'];

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

    }

}

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

?>

<html style="background-color: rgb(241, 245, 249);"  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 SINAPSYS DEVOPS SA DE CV'>

<head>

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

    <link rel="stylesheet" type="text/css" href="../../../dist/css/tableresponsive.css?time=<?=$_Css_Version?>">

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

    <!-- BEGIN: CSS Assets-->

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

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

    <link rel="stylesheet" href="../../../dist/css/static_thead.css?time=<?=$_Css_Version?>" />

    <link rel="stylesheet" href="../../../dist/css/style_app.css?time=<?=$_Css_Version?>" />

    <!-- END: CSS Assets-->

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

    <!--Comienza plugins JTABLE--->

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

    <!--Termina plugins JTABLE--->



    <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />

    <style>

        ::-webkit-scrollbar {

            display: none;

        }

    </style>

    <script language='JavaScript'> 



        function SaveForm(frmid){



            $("#"+frmid).submit(); 



        }



        function SearchForm(){



            document.getElementById("SearchForm").submit(); 



        }



        function submitPagination(e){



            document.getElementById("formPagination").submit();

            loadingpage(); 



        }



        function pregunta(ideliminar){ 

            if (confirm("\u00BF Estas seguro que deseas eliminar el registro. ?")){

                var idelement = 'eliminartupla'+ideliminar;

                document.getElementById(idelement).submit();

                } 

        }



        function mostrarbusqueda()

        {

            if (document.getElementById('formulario_busquedaavanzada').style.display=='none') {

                document.getElementById('formulario_busquedaavanzada').style.display='block';

            }

            else {

                document.getElementById('formulario_busquedaavanzada').style.display='none';   

            }

        }

        function mostrarcampo(idmostrar)

        {

            if (document.getElementById(idmostrar).value=='!='||document.getElementById(idmostrar).value==(">") || document.getElementById(idmostrar).value=="IS NULL") 

            {

             document.getElementById(idmostrar+'uno').style.display='none';

             document.getElementById(idmostrar+'uno').value=''; 

            }

            else

            {

             document.getElementById(idmostrar+'uno').style.display='block';

            }



            if (document.getElementById(idmostrar).value=="BETWEEN" || document.getElementById(idmostrar).value=="NOT BETWEEN") {

            try {

                document.getElementById(idmostrar+'dos').style.display='block';      

            }

            catch(err) {

            }

             

            }

            else

            {

                try {

             document.getElementById(idmostrar+'dos').style.display='none'; 

             document.getElementById(idmostrar+'dos').value=''; 

            }

            catch(err) {

            }

            

            }

        }



        //CONFIGURACION PARA BOTONES DE PAGINACION

        function actbtn(id){

          loadingpage();

          $("#pagina").val(id);

          pags=$("#pagina").val();  

        }



        function loadbtn(){

          pags2=document.getElementById('pagina').value;

          document.getElementById('pg'+pags2).className = "page-item active";

          document.getElementById('pgm'+pags2).className = "page-item active";  

        }

        //TERMINA CONFIGURACION PARA BOTONES DE PAGINACION        

    </script> 

    <!--estilos search qr--->

    <link rel="stylesheet" href="../../../dist/css/style_qr_search.css?time=<?=$_Css_Version?>" />

    <!---end estilos search qr--> 

    <title>MÓDULO APP</title>

    </head>

    <center>

    <body onload="noback();loadbtn();">

    <?php

    //$TAMANIO_PAGINA = !empty($_REQUEST['TAMANIO_PAGINA'])?$_REQUEST['TAMANIO_PAGINA']:10;

    /*CONFIGURACION PARA EL NUMERO DE REGISTROS A MOSTRAR*/

    if (isset($_REQUEST["TAMANIO_PAGINA"])) {     

        

            $TAMANIO_PAGINA = $_REQUEST["TAMANIO_PAGINA"];

            $_SESSION['TAMANIO_PAGINA_appquadrata']=$TAMANIO_PAGINA;

    }else{

        if(isset($_SESSION['TAMANIO_PAGINA_appquadrata']))

        {

            

            $TAMANIO_PAGINA = !empty($_REQUEST['TAMANIO_PAGINA'])?$_REQUEST['TAMANIO_PAGINA']:$_SESSION['TAMANIO_PAGINA_appquadrata'];

        }

        else

        {

            

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

        }

    }

    /*TERMINA LA CONFIGURACION PARA EL NUMERO DE REGISTRS A MOSTRAR*/

        /*CONFIGURACION PARA EL Tipo DE VISTA*/

    if (isset($_REQUEST["TIPO_VISTA"])) {     

        

            $TIPO_VISTA = $_REQUEST["TIPO_VISTA"];

            $_SESSION['TIPO_VISTA_appquadrata']=$TIPO_VISTA;

    }else{

        if(isset($_SESSION['TIPO_VISTA_appquadrata']))

        {

            

            $TIPO_VISTA = !empty($_REQUEST['TIPO_VISTA'])?$_REQUEST['TIPO_VISTA']:$_SESSION['TIPO_VISTA_appquadrata'];

        }

        else

        {

            

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

        }

    }



    /*TERMINA LA CONFIGURACION PARA EL TIPO DE VISTA*/

    /* CONFIGURACION PARA PAGINACION */

    $TAMANO_PAGINA = $TAMANIO_PAGINA;

    if (isset($_GET["pagina"])) {                

      if (is_string($_GET["pagina"])) {            

        if (is_numeric($_GET["pagina"])) {                 

          if ($_GET["pagina"] == 1) {

            $pagina = $_GET["pagina"];

            $_SESSION['location_pg_appquadrata']=$pagina;

          } 

          else { 

            $pagina = $_GET["pagina"];

            $_SESSION['location_pg_appquadrata']=$pagina;

          }

        } 

        else { 

          header("Location: ./");

          die();

        }

      }

    } 

    else {

        /*if(isset($_SESSION['location_pg_appquadrata']))

        {

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

        }

        else

        {

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

        }*/

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

      //$pagina = 1;

    }

    $inicio=0;

    if($TAMANO_PAGINA!="Todos"){

        $inicio = ($pagina - 1) * $TAMANO_PAGINA;    

    }    

    /*TERMINA CONFIGURACION PARA PAGINACION*/

        //creamos un input para la paginacion

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

    ?>

    <!---Agregamos el codigo para el buscador-->

<?php



    //Llama a la clase modulo_app

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

    require_once(ROOT_CONTROLLER.'modulo_app.php');

    $Obj_modulo_app = new modulo_app();

    $Obj_modulo_app2 = new modulo_app();

    $Obj_modulo_app3 = new modulo_app();

                        

    require_once(ROOT_CHARACTER_FIX);

    $Obj_fix_characters = new fix_characters();



    $action ='';

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

    $Buscar ='';

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

    $Buscar=$Obj_fix_characters->fix($Buscar);

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

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

    if (!empty($_POST))

    {



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

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

            

    }



?>

    <!---Termina el codigo para el buscador-->

    <!--<div class="intro-y" style="float: center;text-align: center !important;">

     <h1 style="font-size: 200% !important;">MODULO_APP</h1>

    </div>-->

<div style="display:flex;justify-content: space-between;">

    <h2 class="intro-y text-lg font-medium mt-0 ml-4" style="text-align: left;">MÓDULO APP</h2>

    <!--Comienza el codigo prueba para el tipo de vista--->

    <div class="md:block text-slate-500 h-5" style="display:flex;">

        <form style=" display: inline-block;">

            <input type="hidden" name="TIPO_VISTA" value="">

            <button class="btn btn-info" <?php if($TIPO_VISTA==''){ echo "style='background-color:lightblue;'"; } ?>>

                <svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-monitor-smartphone"><path d="M18 8V6a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2v7a2 2 0 0 0 2 2h8"/><path d="M10 19v-3.96 3.15"/><path d="M7 19h5"/><rect width="6" height="10" x="16" y="12" rx="2"/></svg>

            </button>

        </form>

        <form style=" display: inline-block;">

            <input type="hidden" name="TIPO_VISTA" value="Tabla">

            <button class="btn btn-info" <?php if($TIPO_VISTA=='Tabla'){ echo "style='background-color:lightblue;'"; } ?>>

                <svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-monitor"><rect width="20" height="14" x="2" y="3" rx="2"/><line x1="8" x2="16" y1="21" y2="21"/><line x1="12" x2="12" y1="17" y2="21"/></svg>

            </button>

        </form>

        <form style=" display: inline-block;">

            <input type="hidden" name="TIPO_VISTA" value="Tarjeta">

            <button class="btn btn-info" <?php if($TIPO_VISTA=='Tarjeta'){ echo "style='background-color:lightblue;'"; } ?>>

                <svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-tablet-smartphone"><rect width="10" height="14" x="3" y="8" rx="2"/><path d="M5 4a2 2 0 0 1 2-2h12a2 2 0 0 1 2 2v16a2 2 0 0 1-2 2h-2.4"/><path d="M8 18h.01"/></svg>

            </button>

        </form>



    </div>

    <!---termina codigo de prueba para el tipo de vista-->

</div>

<div class="intro-y col-span-12 flex flex-wrap sm:flex-nowrap items-center mt-0 ml-0">

    <button id="new-register" onclick="location.href = 'formulario.php'; " class="btn btn-primary shadow-md mr-2">Nuevo registro</button>

    <button class="dropdown-toggle btn px-2 box mr-2" aria-expanded="false" data-tw-toggle="dropdown" onclick="location.href = 'exportar.php'; ">

    Exportar

    </button>
    <form style="margin:0;" method="post" action="./" id='formPagination' onsubmit='loadingpage();'>

        <select class='form-select' name='TAMANIO_PAGINA' onchange="submitPagination(this.value);">

            <option value="5" <?php if($TAMANIO_PAGINA==5){echo "selected";} ?> >5</option>

            <option value="10" <?php if($TAMANIO_PAGINA==10){echo "selected";} ?> >10</option>

            <option value="25" <?php if($TAMANIO_PAGINA==25){echo "selected";} ?> >25</option>

            <option value="35" <?php if($TAMANIO_PAGINA==35){echo "selected";} ?> >35</option>

            <option value="50" <?php if($TAMANIO_PAGINA==50){echo "selected";} ?> >50</option>

            <option value="100" <?php if($TAMANIO_PAGINA==100){echo "selected";} ?> >100</option>

            <option value="200" <?php if($TAMANIO_PAGINA==200){echo "selected";} ?> >200</option>

            <option value="500" <?php if($TAMANIO_PAGINA==500){echo "selected";} ?> >500</option>

            <option value="Todos" <?php if($TAMANIO_PAGINA=="Todos"){echo "selected";} ?> >Todos</option>

        </select>

        <input type="hidden" name="buscar" value='<?php echo $Buscar; ?>'>

        <input type="hidden" name="pagina" value='1'>

        <?php if($Buscar!=''){

            echo "<input type=\"hidden\" name=\"action\" value='buscar'>";

        }?>

    </form>

    <div class="md:block mx-auto text-slate-500">

    <!---Este es un separador para los botones y el buscador-->

    <?php

      //Detecta si es un mobil, tablet o pc.

        include(ROOT_MOTORMOBIL);

      //include($context_modulo_app.'motormobil/motormobil.php');

             switch ($action) {

           

              case 'orderby':

                      $Adapter_modulo_app = $Obj_modulo_app->getorderby_modulo_app($Nombre,$Orderby);

                      $Adapter_modulo_app2 = $Obj_modulo_app2->getorderby_modulo_apppg($Nombre,$Orderby,$inicio,$TAMANO_PAGINA);$Adapter_modulo_app3 = $Obj_modulo_app3->getorderby_modulo_apppg($Nombre,$Orderby,$inicio,$TAMANO_PAGINA);



              break;    



              case 'buscar':

                      //echo"<form name='mostrar_todos' action='./#' ><input type='submit' method='POST'  value='Mostrar todos los registros'/></form>";

                      $Adapter_modulo_app = $Obj_modulo_app->search_modulo_app($Buscar);

                      $Adapter_modulo_app2 = $Obj_modulo_app2->search_modulo_apppg($Buscar,$inicio,$TAMANO_PAGINA);$Adapter_modulo_app3 = $Obj_modulo_app3->search_modulo_apppg($Buscar,$inicio,$TAMANO_PAGINA);

              break;

              

              default:

                      $Adapter_modulo_app = $Obj_modulo_app->get_modulo_app();

                      $Adapter_modulo_app2 = $Obj_modulo_app2->get_modulo_apppg($inicio,$TAMANO_PAGINA);$Adapter_modulo_app3 = $Obj_modulo_app3->get_modulo_apppg($inicio,$TAMANO_PAGINA);  

              break;

            }



                        /*INICIA CONFIGURACION DE PAGINACION*/

                        $TAMANO_PAGINA=$TAMANIO_PAGINA;                      

                            // $row =$Adapter_modulo_app->num_rows;

                            while ($Field_modulo_apprg=$Adapter_modulo_app->fetch_assoc())

                            { 

                              $row =$Field_modulo_apprg['numregis'];

                            }

                            $row2 =$Adapter_modulo_app2->num_rows;

                            if($TAMANIO_PAGINA!="Todos"){

                                $total_paginas = ceil($row / $TAMANO_PAGINA);

                                $pagina_registros=(($pagina-1)*$TAMANIO_PAGINA)+1;

                                $total_registros_pagina=$TAMANIO_PAGINA*$pagina;

                            }else{

                                $total_paginas=1;

                                $pagina_registros=1;

                                $total_registros_pagina=$row;

                            }

                            echo"<div class='md:block mx-auto text-slate-500'>Mostrando $pagina_registros a $total_registros_pagina de <p id='numregis_pagina' style='display:inline;'>$row</p> registros</div>";



                        /**/ 

                        global $actions, $buscars;  

                        echo " <div class='intro-y flex flex-wrap sm:flex-row items-center mt-0' style='justify-content:space-around !important;margin-top:3px;margin-bottom:3px;'>

                                <center>

                                    <nav class='w-full sm:w-auto sm:mr-auto items-center'>

                                        <ul class='pagination'>

                                            <li class='page-item'>

                                                <a class='page-link' href='?pagina=1&action=$actions&buscar=$buscars&TAMANIO_PAGINA=$TAMANIO_PAGINA' onclick='actbtn('1);'> <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='chevrons-left' class='lucide lucide-chevrons-left w-4 h-4' data-lucide='chevrons-left'><polyline points='11 17 6 12 11 7'></polyline><polyline points='18 17 13 12 18 7'></polyline></svg> </a>

                                            </li>

                            ";

                            if ($pagina > 1) {

                                echo "

                                    <li class='page-item'>

                                        <a class='page-link' href='?pagina=" . ($pagina - 1) . "&action=$actions&buscar=$buscars&TAMANIO_PAGINA=$TAMANIO_PAGINA'  onclick='actbtn(".($pagina - 1).");' style='margin-bottom: 5px;'> <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' class='lucide lucide-chevron-left w-4 h-4' data-lucide='chevron-left'><polyline points='15 18 9 12 15 6'></polyline></svg> </a>

                                    </li>

                                ";



                            }else{

                                echo "

                                    <li class='page-item'>

                                        <a class='page-link' style='margin-bottom: 5px;'> <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' class='lucide lucide-chevron-left w-4 h-4' data-lucide='chevron-left'><polyline points='15 18 9 12 15 6'></polyline></svg> </a>

                                    </li>

                                ";

                            }   



                            for ($i = max(1, $pagina - 2); $i <= min($pagina + 2, $total_paginas); $i++) 

                              {   

                                echo "<li class='page-item' id='pg".$i."'> <a class='page-link' href='?pagina=".$i."&action=$actions&buscar=$buscars&TAMANIO_PAGINA=$TAMANIO_PAGINA' >".$i."</a> </li>";                      

                              }



                            if ($pagina < $total_paginas) {

                                echo "

                                    <li class='page-item'>

                                        <a class='page-link' href='?pagina=" . ($pagina + 1) . "&action=$actions&buscar=$buscars&TAMANIO_PAGINA=$TAMANIO_PAGINA' onclick='actbtn(".($pagina - 1).");' > <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' class='lucide lucide-chevron-right w-4 h-4' data-lucide='chevron-right'><polyline points='9 18 15 12 9 6'></polyline></svg> </a>

                                    </li>

                                ";

                            }else{

                                echo "

                                    <li class='page-item'>

                                        <a class='page-link'> <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' class='lucide lucide-chevron-right w-4 h-4' data-lucide='chevron-right'><polyline points='9 18 15 12 9 6'></polyline></svg> </a>

                                    </li>

                                ";

                            }

                        echo  "             

                                            <li class='page-item'>

                                                <a class='page-link' href='?pagina=$total_paginas&action=$actions&buscar=$buscars&TAMANIO_PAGINA=$TAMANIO_PAGINA' onclick='actbtn(".$total_paginas.");'> <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='chevrons-right' class='lucide lucide-chevrons-right w-4 h-4' data-lucide='chevrons-right'><polyline points='13 17 18 12 13 7'></polyline><polyline points='6 17 11 12 6 7'></polyline></svg> </a>

                                            </li>";

                                        echo "

                                        </ul>

                                    </nav>

                                </center>

                            </div>";

                        /*TERMINA CONFIGURACION DE PAGINACION*/

    ?>

    </div>

    <div class="w-full sm:w-auto mt-3 sm:mt-0 sm:ml-auto md:ml-0">

        <div class="w-56 relative text-slate-500">

            <!--<form name='buscar' action='./' method='Post' id='SearchForm'>

                <input type='hidden' name='action' value='buscar'/>

                <input type="hidden" name="TAMANIO_PAGINA" value="<?php echo $TAMANIO_PAGINA;?>">

                <input type="text" class="form-control w-56 box pr-10" id="search" name="buscar" placeholder="Buscar..."  onkeypress="if(event.key === 'Enter'){ SearchForm();loadingpage(); }" value='<?php echo $Buscar; ?>'>

                <svg style="margin-right:30px;" 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="search" class="lucide lucide-search w-4 h-4 absolute my-auto inset-y-0 mr-3 right-0" data-lucide="search"><circle cx="11" cy="11" r="8"></circle><line x1="21" y1="21" x2="16.65" y2="16.65"></line></svg>

            </form>-->



            <div class="search-container">

                <form name='buscar' action='./' method='Post' id='SearchForm' style="width: 100%;">

                    <input type='hidden' name='action' value='buscar'/>

                    <input type="hidden" name="TAMANIO_PAGINA" value="<?php echo $TAMANIO_PAGINA;?>">

                    <input type='hidden' name='_IdFk' value='<?php echo $_IdFk;?>'>

                    <input type='hidden' name='_Clausula_Fk' value='<?php echo $_Clausula_Fk;?>'>

                    <input type="text" id="search" name="buscar" class="form-control py-3 px-4 border-transparent bg-slate-100 pr-10 w-100" placeholder="Buscar"  onkeypress="if(event.key === 'Enter'){ SearchForm();loadingpage(); }" value='<?php echo $Buscar; ?>'>

                </form>

                <div class="qr-icon" onclick="openQRReader()">

                    <img src="../../../dist/images/iconqrsearch.gif" alt="QR">

                </div>

            </div>

            <!-- Modal para el lector QR -->

            <div id="qrReaderModal" style="display: none; position: fixed; top: 0; left: 0; width: 100%; height: 95vh; background: rgba(0, 0, 0, 1); z-index: 1000; justify-content: center; align-items: center; flex-direction: column;">

                <h3 style="color: white; text-align: center;">Lector QR y Código de Barras</h3>

                <div style="width: 300px; height: 300px; border-radius: 50%; overflow: hidden; position: relative; border: 5px solid white; box-shadow: 0 0 15px rgba(255, 255, 255, 0.5);">

                    <video id="video" autoplay style="width: 100%; height: 100%; object-fit: cover;"></video>

                </div>

                <div id="output" style="margin-top: 10px; text-align: center; font-size: 14px; color: white;">Apunte su cámara al código</div>

                <button onclick="closeQRReader()" style="margin-top: 20px; background: red; color: white; border: none; border-radius: 50%; width: 40px; height: 40px; cursor: pointer;">&times;</button>

            </div>

            <!---End Mpdal para el qr-->

        </div>

    </div>

    <!--agregamos el boton para mostrar todos los registros--->

    <?php if($Buscar!=''){ ?>

    <div class="w-full sm:w-auto mt-3 sm:mt-0 sm:ml-auto md:ml-0">

        <div class="w-40 relative text-slate-500">

            <form name='buscar' action='./' method='Post' onsubmit="loadingpage();">

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

                <input type="hidden" name="TAMANIO_PAGINA" value="<?php echo $TAMANIO_PAGINA;?>">

                <input type="hidden" name="buscar" value="">

                <button id='mostrartodosbutton' type='submit'  class='btn btn-outline-danger flex items-center mr-1'>Mostrar todos <i data-lucide='x-circle' class='w-4 h-4 ml-2'></i></button>

            </form>

        </div>

    </div>

    <?php } ?>

    <!--termina el codigo para mostrar el boton-->

</div>



    <?php

        $time=time();

        $actions=$action;

        $buscars=$Buscar;

    ?>

    <!--continar con el framewok especificamente en el switch. de busqueda avanzada. nota mental-->

    <!--<div><input onclick='mostrarbusqueda()' type='button' class='btn btn-primary' name='busquedaavanzada' value='Busqueda Avanzada'></div><br>-->



                                <div id='formulario_busquedaavanzada' style='display:none;'>

                                        <form name='buscar' action='./#' method='Post'>

                                            <table borde='3'>

                                            <?php 

                                        // programar old version.

                                        // include('../odbconexion/config.php');       

                                        // $consulta="show full columns from modulo_app";

                                        $Adapter_modulo_app_search=$Obj_modulo_app->execute_modulo_app("show full columns from modulo_app_appquadrata"); 

                                    try{



                                        // $Adapter_modulo_app_search=$conexion->query($consulta); old version

                                        $row = $Adapter_modulo_app_search->num_rows;

                                        $agrupacion=0;

                                        $group=2;

                                        //lee los field_user_search

                                        while($field_user_search=$Adapter_modulo_app_search->fetch_assoc())

                                            {

                                                $agrupacion++;

                                                if ($agrupacion==$group) {

                                                    echo"<tr>";

                                                    $agrupacion=0;          

                                                }

                                                    echo"<td>";

                                                    $field="{$field_user_search['Field']}";

                                                    echo "$field";

                                                    echo"</td>";

                                                    echo"<td>";

                                                    $cadena = "$field_user_search[Type]";

                                                    echo"<select id='$field_user_search[Field]' name='criteria$field_user_search[Field]' onchange='mostrarcampo(\"$field_user_search[Field]\")'>";

                                                    

                                                    echo "<option value ='=' selected>Igual a</option>";

                                                    

                                                    if (strstr($field_user_search['Type'],"decimal")) {

                                                        echo "<option value ='>'>Mayor que</option>";

                                                        echo "<option value ='<'>Menor que</option>";

                                                        echo "<option value ='!='>Diferente de</option>";

                                                        echo"<option value='IS NULL'>Sin</option>";

                                                        echo"<option value='>'>Con</option>";

                                                    }                                                    

                                                   

                                                    if ($field_user_search['Type']=='datetime' || $field_user_search['Type']=='date') {

                                                        echo"<option value='BETWEEN'>Entre</option>";

                                                        echo"<option value='NOT BETWEEN'>No esta entre</option>";

                                                        echo"<option value='IS NULL'>Sin</option>";

                                                        echo"<option value='>'>Con</option>";

                                                    }

                                                    if (strstr($field_user_search['Type'],"varchar")) {

                                                        echo "<option value ='LIKE%'>Contiene</option>";

                                                    }



                                                    if (strstr($field_user_search['Type'],"varchar")) {

                                                        echo "<option value ='!='>Sin</option>";

                                                    }

                                                    



                                                    echo"</select>";

                                                    echo"</td>";





                                                    echo"<td>";

                                                    



                                                        if ($field_user_search['Type']=='datetime' || $field_user_search['Type']=='date') {

                                                echo "<input id='$field"."uno'" ; echo"type='date' name='$field'/>";

                                                echo "<input id='$field"."dos'" ; echo"type='date' style='display: none;' name='$field"."dos' />";

                                                    }    

                                                        else{

                                                        echo "<input id='$field"."uno' style='display: block;' type ='text' name='$field'/>";

                                                    }    

                                                        



                                                    echo"</td>";

                                                    

                                                    if ($agrupacion==$group) {

                                                    $agrupacion=0;

                                                    echo"</tr>";            

                                                }

                                            }

                                        }

                                        catch (Exception $e) {

                                        echo'Excepcion capturada: ',  $e->getMessage(), '\n';

                                        }



                                       ?>

                                            </table>

                                            <input type='hidden' name='action' value='busquedaavanzada'/>

                                            <br>

                                            <input type='submit' name='find' value='Realizar Busqueda Avanzada' class="btn btn-primary" />

                                            <br>

                                        </form>

                                </div>

<?php



        

          function mostrar($Adapter_modulo_app,$Adapter_modulo_app2,$Adapter_modulo_app3,$TAMANIO_PAGINA,$pagina,$TIPO_VISTA,$Buscar,$_Clausula_Fk,$_IdFk,$device)

                    {

                        $_Display_Tarjeta='modulotarg';

                        $_Display_Tabla='modulotab';

                        if($TIPO_VISTA!=''){

                           $_Display_Tarjeta=''; 

                           $_Display_Tabla='';

                        }

                        global $Orderby;

                         $_contentDiv='contentDiv1';

                        if($_Clausula_Fk!='' && $_IdFk!=''){

                            $_contentDiv='contentDiv2';

                        }

                        echo "<div class='overflow-x-auto $_contentDiv' id='contentDiv'>";

                        if($TIPO_VISTA=='' || $TIPO_VISTA=='Tarjeta'){

                        //Comienza Device Mobil

                        echo "<div class='$_Display_Tarjeta'>";

                        echo "<div class='no-seleccionable grid grid-cols-12 mt-4'>";

                        try{

                        while ($Field_modulo_app=$Adapter_modulo_app2->fetch_assoc())

                          {

                        echo "<div class='intro-y col-span-12 md:col-span-4 lg:col-span-4 mt-2 ml-0.5 mr-0.5' id='target{$Field_modulo_app['Id_Modulo_App']}'>

                        <div class='box' id='box{$Field_modulo_app['Id_Modulo_App']}'>

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

                        <!--<div class='w-24 h-24 lg:w-12 lg:h-12 image-fit lg:mr-1'>

                        <img alt='Midone - HTML Admin Template' class='rounded-full' src='http://rubick.left4code.com/dist/images/profile-13.jpg'>

                        </div>-->

                        <div class='text-center mt-3'>";

                            echo "<div class='target-contenedor-color'>

                                    <label for='colorInputTarget{$Field_modulo_app['Id_Modulo_App']}'>

                                      <img class='target-input-color' src='../../../dist/images/colors_default.png' alt='Imagen' id='activadorColor' onclick=\"document.getElementById('colorInputTarget{$Field_modulo_app['Id_Modulo_App']}').click();\"  style='z-index:5;'>

                                    </label>

                                    <input id='colorInputTarget{$Field_modulo_app['Id_Modulo_App']}' type='color' style='z-index:0;' class='target-input-color' onchange='colorearRowByMenuContext({$Field_modulo_app['Id_Modulo_App']},this.value);'>

                                  </div>";

                            echo "<p align='center' class='ptargettitle'>Id Modulo App:</p>";

                               echo"<p class='ptarget'>{$Field_modulo_app['Id_Modulo_App']}</p>";

                            echo "<p align='center' class='ptargettitle'>Titulo Modulo:</p>";

                               echo"<p class='ptarget'>{$Field_modulo_app['Titulo_Modulo']}</p>";

                            echo "<p align='center' class='ptargettitle'>Descripcion Modulo:</p>";

                               echo"<p class='ptarget'>{$Field_modulo_app['Descripcion_Modulo']}</p>";

                            echo "<div id='more{$Field_modulo_app['Id_Modulo_App']}' style='display:none;margin-top:auto;'>";echo "<p align='center' class='ptargettitle'>Tipo Menu:</p>";

                               echo"<p class='ptarget'>{$Field_modulo_app['Tipo_Menu']}</p>";

                            echo "<p align='center' class='ptargettitle'>Href Modulo:</p>";

                               echo"<p class='ptarget'>{$Field_modulo_app['Href_Modulo']}</p>";

                            echo "<p align='center' class='ptargettitle'>Icon Fa Modulo:</p>";

                               echo"<p class='ptarget'>{$Field_modulo_app['Icon_Fa_Modulo']}</p>";

                            echo "<p align='center' class='ptargettitle'>Status Modulo:</p>";

                               echo"<p class='ptarget'>{$Field_modulo_app['Status_Modulo']}</p>";

                            echo "<p align='center' class='ptargettitle'>Fecha Registro:</p>";

                               echo"<p class='ptarget'>{$Field_modulo_app['Fecha_Registro']}</p>";

                            echo "<p align='center' class='ptargettitle'>Fecha Modifico:</p>";

                               echo"<p class='ptarget'>{$Field_modulo_app['Fecha_Modifico']}</p>";

                            

                       echo "

                                </div> 

                            </div>

                        </div>

                        <div class='items-center justify-center p-5'  style='background-color:white;'>

                        <div class='w-full mb-4 mr-auto flex'  style='justify-content: space-evenly;'>";

                        echo "<button type='button' id='btnmostrarmas{$Field_modulo_app['Id_Modulo_App']}' class='flex items-center text-success' onclick=\"seemore('Mostrar +',{$Field_modulo_app['Id_Modulo_App']});\" value='Mostrar +'><i data-lucide='plus-circle' class='w-4 h-4 mr-2'></i>Mostrar</button>";

                         echo " <button type='button' style='display:none;' id='btnmostrarmenos{$Field_modulo_app['Id_Modulo_App']}' class='flex items-center text-danger' onclick=\"seemore('Mostrar -',{$Field_modulo_app['Id_Modulo_App']});\" value='Mostrar -'><i data-lucide='minus-circle' class='w-4 h-4 mr-2'></i>Mostrar</button>";

                        echo "<form name='editar' action='formulario.php' method='post' onsubmit='loadingpage();' style='all:unset;'>

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

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

                        echo "<input type='hidden' name='Id_Modulo_App' value='{$Field_modulo_app['Id_Modulo_App']}' >";

                        echo "<button type='submit' class='flex items-center mr-3'><i data-lucide='edit' class='w-4 h-4 mr-2'></i>Editar</button></form>";

                        echo "<form action='../bussines/guardar.php'  id='eliminartupla{$Field_modulo_app['Id_Modulo_App']}' value='Eliminar' method='post' target='deletemoduloapp' style='all:unset;'>

                            <input type='hidden' name='action'  value='eliminar'>";

                            echo "<input type='hidden' name='Id_Modulo_App' value='{$Field_modulo_app['Id_Modulo_App']}' >";

                        echo "<button type='button'  class='flex items-center text-danger' onclick='openModalDelete({$Field_modulo_app['Id_Modulo_App']});' value = 'Eliminar' ><i data-lucide='trash' class='w-4 h-4 mr-2'></i>Eliminar</button></form ></td>";

                          

                        

                        echo "</div>

                        </div>

                        </div>

                        </div>";

                                    }

                                }catch (Exception $e) {

                           echo 'Excepcion capturada: ',  $e->getMessage(), '\n';

           

                          } 

                        echo "</div>";

                        echo "</div>";

                        //TERMINA Device Mobil

                        }

                        if($TIPO_VISTA=='' || $TIPO_VISTA=='Tabla'){

                        //comienza Device PC

                        echo "<div class='table-container'>";

                        echo "<table id='tabla_modulo' class='$_Display_Tabla table table-report -mt-2'>";

                        echo "<thead>";

                        echo "<tr>";echo "<th colspan='2' style='text-align:center;'>Acciones</th>";echo "<th  class='whitespace-nowrap' align='center'><form name='orederby' action='./#' method='post' ><input type='hidden' name='action' value='orderby' /><input type='hidden' name='orderby'"; 

                                                    //Indica en que orden se mostrará la informacón dependiendo de la columna seleccionada.

                                                    switch ($Orderby)

                                                    {

                                                    case 'ASC':

                                                     echo"value='DESC'";

                                                     break;

                                                    case 'DESC':

                                                     echo"value='ASC'";

                                                     break;

                                                     default:

                                                     echo"value='ASC'";

                                                     break;

                                                    }

                                                     echo"/><input type='hidden' name='nombre' value='Titulo_Modulo'/><input type='submit' value='Titulo Modulo'/></form></th>";

                               echo "<th  class='whitespace-nowrap' align='center'><form name='orederby' action='./#' method='post' ><input type='hidden' name='action' value='orderby' /><input type='hidden' name='orderby'"; 

                                                    //Indica en que orden se mostrará la informacón dependiendo de la columna seleccionada.

                                                    switch ($Orderby)

                                                    {

                                                    case 'ASC':

                                                     echo"value='DESC'";

                                                     break;

                                                    case 'DESC':

                                                     echo"value='ASC'";

                                                     break;

                                                     default:

                                                     echo"value='ASC'";

                                                     break;

                                                    }

                                                     echo"/><input type='hidden' name='nombre' value='Descripcion_Modulo'/><input type='submit' value='Descripcion Modulo'/></form></th>";

                               echo "<th  class='whitespace-nowrap' align='center'><form name='orederby' action='./#' method='post' ><input type='hidden' name='action' value='orderby' /><input type='hidden' name='orderby'"; 

                                                    //Indica en que orden se mostrará la informacón dependiendo de la columna seleccionada.

                                                    switch ($Orderby)

                                                    {

                                                    case 'ASC':

                                                     echo"value='DESC'";

                                                     break;

                                                    case 'DESC':

                                                     echo"value='ASC'";

                                                     break;

                                                     default:

                                                     echo"value='ASC'";

                                                     break;

                                                    }

                                                     echo"/><input type='hidden' name='nombre' value='Tipo_Menu'/><input type='submit' value='Tipo Menu'/></form></th>";

                               echo "<th  class='whitespace-nowrap' align='center'><form name='orederby' action='./#' method='post' ><input type='hidden' name='action' value='orderby' /><input type='hidden' name='orderby'"; 

                                                    //Indica en que orden se mostrará la informacón dependiendo de la columna seleccionada.

                                                    switch ($Orderby)

                                                    {

                                                    case 'ASC':

                                                     echo"value='DESC'";

                                                     break;

                                                    case 'DESC':

                                                     echo"value='ASC'";

                                                     break;

                                                     default:

                                                     echo"value='ASC'";

                                                     break;

                                                    }

                                                     echo"/><input type='hidden' name='nombre' value='Href_Modulo'/><input type='submit' value='Href Modulo'/></form></th>";

                               echo "<th  class='whitespace-nowrap' align='center'><form name='orederby' action='./#' method='post' ><input type='hidden' name='action' value='orderby' /><input type='hidden' name='orderby'"; 

                                                    //Indica en que orden se mostrará la informacón dependiendo de la columna seleccionada.

                                                    switch ($Orderby)

                                                    {

                                                    case 'ASC':

                                                     echo"value='DESC'";

                                                     break;

                                                    case 'DESC':

                                                     echo"value='ASC'";

                                                     break;

                                                     default:

                                                     echo"value='ASC'";

                                                     break;

                                                    }

                                                     echo"/><input type='hidden' name='nombre' value='Icon_Fa_Modulo'/><input type='submit' value='Icon Fa Modulo'/></form></th>";

                               echo "<th colspan='2' style='text-align:center;'>Acciones</th>";            echo "</tr>";

                    echo "</thead>";

                    echo "<tbody style='background-color:white;'>";

                      try{

                        $row =$Adapter_modulo_app3->num_rows;

                        while ($Field_modulo_app=$Adapter_modulo_app3->fetch_assoc())

                          {

                            echo "<tr id='{$Field_modulo_app['Id_Modulo_App']}'  oncontextmenu=\"mostrarMenuTable(event,{$Field_modulo_app['Id_Modulo_App']})\">";

                            echo "<td align='left' colspan='2' class='hiddencard'>";

                            echo "<form  action='../bussines/datos.php' method='post' target='seemoduloapp' id='form-see-datos{$Field_modulo_app['Id_Modulo_App']}'>";

                            echo "<input type='hidden' name='Id_Modulo_App' value='{$Field_modulo_app['Id_Modulo_App']}' >";

                            echo "<button type='submit' data-tw-toggle='modal' data-tw-target='#verRegistro' type='button' onclick='ver_modal_detalle({$Field_modulo_app['Id_Modulo_App']})' class='flex items-center mr-6'> <i data-lucide='eye' class='w-5 h-5 mr-2'></i> Ver </button>";

                            echo "</form>";

                            echo "<form name='editar' action='formulario.php' method='post' onsubmit='loadingpage();'>

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

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

                            echo "<input type='hidden' name='Id_Modulo_App' value='{$Field_modulo_app['Id_Modulo_App']}' >";

                            echo "<button type='submit'  class='flex items-center mr-3' value='Editar'> <i data-lucide='edit' class='w-4 h-4 mr-2'></i> Editar</button></form>";

                            echo "<form action='../bussines/guardar.php'  id='eliminartupla{$Field_modulo_app['Id_Modulo_App']}' value='Eliminar' method='post' target='deletemoduloapp'>

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

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

                            echo "<input type='hidden' name='Id_Modulo_App' value='{$Field_modulo_app['Id_Modulo_App']}' >";

                            echo "<button type='button'  class='flex items-center text-danger'  onclick = 'openModalDelete({$Field_modulo_app['Id_Modulo_App']})' value = 'Eliminar' ><i data-lucide='trash' class='w-4 h-4 mr-2'></i>Eliminar</button></form ></td>";

                            

                            echo "<td class='titlehidden  {$Field_modulo_app['Id_Modulo_App']}' align='center' >Titulo Modulo:</td>";

                            

                            echo "<td align='center' class=' {$Field_modulo_app['Id_Modulo_App']} activate-edit'>";

                                echo "<span>{$Field_modulo_app['Titulo_Modulo']}</span>";

                                echo "<form style='display: none; align-items: center; justify-content: center; gap: 20px; margin-top: 20px;' action='../bussines/guardar.php' method='post' target='savemoduloapp'>";

                                echo "<center>";

                                    echo"

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

                                        <input type='hidden' name='Field' value='Titulo_Modulo'>

                                        <input type='hidden' name='Type' value='text'>

                                        <input type='hidden' name='Id_Modulo_App' value='{$Field_modulo_app['Id_Modulo_App']}'>";

                                  echo "<input type='text' name='Value' id='Titulo_Modulo_editfront{$Field_modulo_app['Id_Modulo_App']}' class='form-control' value='{$Field_modulo_app['Titulo_Modulo']}' style='min-width:250px;' required/>";

                                echo "</center>";

                                echo "<button type='submit'  class='btn-primary' style='border:none; border-radius: 100%;cursor: pointer; min-height:40px; min-width:40px;height:40px; width:40px; max-height:40px; max-width:40px; display: flex; align-items: center; justify-content: center;'>

                                      <i data-lucide='save' class='w-4 h-4'></i>

                                    </button>";

                            echo "</form>";

                            echo "</td>";

                            

                            echo "<td class='titlehidden  {$Field_modulo_app['Id_Modulo_App']} activate-edit' align='center' >Descripcion Modulo:</td>";

                            echo"<td align='center' class=' {$Field_modulo_app['Id_Modulo_App']}'>";

                                echo "<span>{$Field_modulo_app['Descripcion_Modulo']}</span>";

                                echo "<form style='display: none; align-items: center; justify-content: center; gap: 20px; margin-top: 20px;' action='../bussines/guardar.php' method='post' target='savemoduloapp'>";

                                echo "<center>";

                                    echo"

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

                                        <input type='hidden' name='Field' value='Descripcion_Modulo'>

                                        <input type='hidden' name='Type' value='text'>

                                        <input type='hidden' name='Id_Modulo_App' value='{$Field_modulo_app['Id_Modulo_App']}'>";

                                  echo "<input type='text' name='Value' id='Titulo_Modulo_editfront{$Field_modulo_app['Id_Modulo_App']}' class='form-control' value='{$Field_modulo_app['Descripcion_Modulo']}' style='min-width:250px;' required/>";

                                echo "</center>";

                                echo "<button type='submit'  class='btn-primary' style='border:none; border-radius: 100%;cursor: pointer; min-height:40px; min-width:40px;height:40px; width:40px; max-height:40px; max-width:40px; display: flex; align-items: center; justify-content: center;'>

                                      <i data-lucide='save' class='w-4 h-4'></i>

                                    </button>";

                            echo "</form>";

                            echo "</td>";



                            echo "<td class='titlehidden  {$Field_modulo_app['Id_Modulo_App']}' align='center' >Tipo Menu:</td>";

                               echo"<td align='center' class=' {$Field_modulo_app['Id_Modulo_App']}'>{$Field_modulo_app['Tipo_Menu']}</td>";

                            echo "<td class='titlehidden mostrarmasoculto mostrarmasoculto{$Field_modulo_app['Id_Modulo_App']}' align='center' >Href Modulo:</td>";

                               echo"<td class='mostrarmasocultos mostrarmasocultos{$Field_modulo_app['Id_Modulo_App']}'>{$Field_modulo_app['Href_Modulo']}</td>";

                            echo "<td class='titlehidden mostrarmasoculto mostrarmasoculto{$Field_modulo_app['Id_Modulo_App']}' align='center' >Icon Fa Modulo:</td>";

                               echo"<td align='center' class='mostrarmasocultos mostrarmasocultos{$Field_modulo_app['Id_Modulo_App']}'><i data-lucide='{$Field_modulo_app['Icon_Fa_Modulo']}' ></i></td>";

                               //echo"<td align='center' class='mostrarmasocultos mostrarmasocultos{$Field_modulo_app['Id_Modulo_App']}'>{$Field_modulo_app['Icon_Fa_Modulo']}</td>";

                         

                            echo "<td align='left' colspan'2'>";

                            echo "<form  action='../bussines/datos.php' method='post' target='seemoduloapp' id='form-see-datos{$Field_modulo_app['Id_Modulo_App']}'>";

                        echo "<input type='hidden' name='Id_Modulo_App' value='{$Field_modulo_app['Id_Modulo_App']}' >";

                        echo "<button type='submit' data-tw-toggle='modal' data-tw-target='#verRegistro' type='button' onclick='ver_modal_detalle({$Field_modulo_app['Id_Modulo_App']})' class='flex items-center mr-6'> <i data-lucide='eye' class='w-5 h-5 mr-2'></i> Ver </button>";

                        echo "</form>";

                             echo "<form name='editar' class='form-btn-card' action='formulario.php' method='post' onsubmit='loadingpage();'>

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

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

                        echo "<input type='hidden' name='Id_Modulo_App' value='{$Field_modulo_app['Id_Modulo_App']}' >";

                        echo "<button type='submit'  class='flex items-center mr-3'  value='Editar'> <i data-lucide='edit' class='w-4 h-4 mr-2'></i> Editar</button></form>";

                        

                        echo "<form action='../bussines/guardar.php' class='form-btn-card' id='eliminartupla{$Field_modulo_app['Id_Modulo_App']}' value='Eliminar' method='post' target='deletemoduloapp'>

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

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

                            echo "<input type='hidden' name='Id_Modulo_App' value='{$Field_modulo_app['Id_Modulo_App']}' >";

                        echo "<button type='button'  class='flex items-center text-danger'  onclick = 'openModalDelete({$Field_modulo_app['Id_Modulo_App']})' value = 'Eliminar' ><i data-lucide='trash' class='w-4 h-4 mr-2'></i>Eliminar</button></form ></td>";

                            echo "</tr>";                   

                          }



                    }catch (Exception $e) {

                       echo 'Excepcion capturada: ',  $e->getMessage(), '\n';

       

                      } 

                    echo "</tbody>"; 

                    echo "</table>";

                    //Termina la Tabla

                    echo "</div>";

                    //Codigo de toño 2024

                        if ($row==0) {

                            if ($Buscar!='') {

                            echo "<br><h2 class='intro-y text-lg font-medium mt-0 ml-4' style='text-align: center;'>SIN RESULTADOS: $Buscar.</h2><br><img  onclick=\"document.getElementById('mostrartodosbutton').click();\" width='30%' height='30%' src='../../../dist/images/nosearchdata.png'/><br><span>CLICK EN LA IMAGEN PARA REGRESAR.</span>";    

                            }

                            else{

                                if($device=='pc'){

                                echo "<br><h2 class='intro-y text-lg font-medium mt-0 ml-4' style='text-align: center;'>SIN DATOS PARA MOSTRAR</h2><br><img  onclick=\"document.getElementById('new-register').click();\" width='35%' height='35%' src='../../../dist/images/no_data.png'/><span>CLICK EN LA IMAGEN PARA UN NUEVO REGISTRO.</span>";

                                }else{

                                 echo "<br><h2 class='intro-y text-lg font-medium mt-0 ml-4' style='text-align: center;'>SIN DATOS PARA MOSTRAR</h2><br><img  onclick=\"document.getElementById('new-register').click();\" width='70%' height='70%' src='../../../dist/images/no_data.png'/><span>CLICK EN LA IMAGEN PARA UN NUEVO REGISTRO.</span>";       

                                }   

                            }

                            

                        }

                    //end Codigo de toño 2024

                }

                echo"</div>";     

                

                }                 



       

    mostrar($Adapter_modulo_app,$Adapter_modulo_app2,$Adapter_modulo_app3,$TAMANIO_PAGINA,$pagina,$TIPO_VISTA,$Buscar,$_Clausula_Fk,$_IdFk,$device);

                              /*COMIENZA CONFIGURACION DE PAGINA FOOTER*/ 

                        global $actions, $buscars;                       

                         echo " <div class='intro-y flex flex-wrap sm:flex-row items-center mt-3' style='justify-content:space-around !important;'>

                                <center>

                                    <nav class='w-full sm:w-auto sm:mr-auto items-center'>

                                        <ul class='pagination'>

                                            <li class='page-item'>

                                                <a class='page-link' href='?pagina=1&action=$actions&buscar=$buscars&TAMANIO_PAGINA=$TAMANIO_PAGINA' onclick='actbtn('1);'> <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='chevrons-left' class='lucide lucide-chevrons-left w-4 h-4' data-lucide='chevrons-left'><polyline points='11 17 6 12 11 7'></polyline><polyline points='18 17 13 12 18 7'></polyline></svg> </a>

                                            </li>

                            ";

                            if ($pagina > 1) {

                                echo "

                                    <li class='page-item'>

                                        <a class='page-link' href='?pagina=" . ($pagina - 1) . "&action=$actions&buscar=$buscars&TAMANIO_PAGINA=$TAMANIO_PAGINA'  onclick='actbtn(".($pagina - 1).");' style='margin-bottom: 5px;'> <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' class='lucide lucide-chevron-left w-4 h-4' data-lucide='chevron-left'><polyline points='15 18 9 12 15 6'></polyline></svg> </a>

                                    </li>

                                ";



                            }else{

                                echo "

                                    <li class='page-item'>

                                        <a class='page-link' style='margin-bottom: 5px;'> <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' class='lucide lucide-chevron-left w-4 h-4' data-lucide='chevron-left'><polyline points='15 18 9 12 15 6'></polyline></svg> </a>

                                    </li>

                                ";

                            }   



                            for ($i = max(1, $pagina - 2); $i <= min($pagina + 2, $total_paginas); $i++) 

                              {   

                                echo "<li class='page-item' id='pgm".$i."'> <a class='page-link' href='?pagina=".$i."&action=$actions&buscar=$buscars&TAMANIO_PAGINA=$TAMANIO_PAGINA' >".$i."</a> </li>";                      

                              }



                            if ($pagina < $total_paginas) {

                                echo "

                                    <li class='page-item'>

                                        <a class='page-link' href='?pagina=" . ($pagina + 1) . "&action=$actions&buscar=$buscars&TAMANIO_PAGINA=$TAMANIO_PAGINA' onclick='actbtn(".($pagina - 1).");' > <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' class='lucide lucide-chevron-right w-4 h-4' data-lucide='chevron-right'><polyline points='9 18 15 12 9 6'></polyline></svg> </a>

                                    </li>

                                ";

                            }else{

                                echo "

                                    <li class='page-item'>

                                        <a class='page-link'> <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' class='lucide lucide-chevron-right w-4 h-4' data-lucide='chevron-right'><polyline points='9 18 15 12 9 6'></polyline></svg> </a>

                                    </li>

                                ";

                            }

                        echo  "             

                                            <li class='page-item'>

                                                <a class='page-link' href='?pagina=$total_paginas&action=$actions&buscar=$buscars&TAMANIO_PAGINA=$TAMANIO_PAGINA' onclick='actbtn(".$total_paginas.");'> <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='chevrons-right' class='lucide lucide-chevrons-right w-4 h-4' data-lucide='chevrons-right'><polyline points='13 17 18 12 13 7'></polyline><polyline points='6 17 11 12 6 7'></polyline></svg> </a>

                                            </li>

                                        </ul>

                                    </nav>

                                </center>

                            </div>";

                        /*TERMINA CONFIGURACION DE PAGINACION FOOTER*/

?>

<!--Modal ver registro--->

        <div id="verRegistro" class="modal fade" role="dialog">

            <div class="modal-dialog modal-xl">

                <!-- Modal content-->

                <div class="modal-content">

                    <div class="modal-header">

                        <h4 class="modal-title">DATOS DEL REGISTRO</h4>

                        <span onclick="closeModal();" style="position:absolute;right:30px;color: black;float: right;font-size: 30px;font-weight: bold;">&times;</span>

                    </div>

                    <div class="modal-body">

                        <iframe name="seemoduloapp" id="seemoduloapp" style="width:100%;min-height: 250px;"></iframe>

                        <div class="modal-footer">

                            <button type="button" onclick="closeModal();" class="btn btn-danger close" data-dismiss="modal">Cerrar</button>

                        </div>

                    </div>



                </div>

            </div>

        </div>

<!--termina modal ver registro--->

<!--creamos un menu-->

<div id="menu-context" class="context-menu">

    <ul>

        <!--<li><button data-tw-toggle='modal' id="menu-context-ver" data-tw-target='#verRegistro' type='button'  class='flex items-center mr-6'> <i data-lucide='eye' class='w-5 h-5 mr-2'></i> Ver</button></li>-->

        <li>

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

                <input type='hidden' name='_IdFk' value='<?=$_IdFk;?>'>

                <input type='hidden' name='_Clausula_Fk' value='<?=$_Clausula_Fk;?>'>

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

                <button type='submit' class='flex items-center mr-3'><i data-lucide='file-text' class='w-4 h-4 mr-2'></i>Nuevo registro</button>

            </form >

        </li>

        <li>

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

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

                <input type='hidden' name='Id_Modulo_App' id='menu-context-duplicar'>

                <input type='hidden' name='pagina' value='1'>

                <button type='submit' class='flex items-center mr-3'><i data-lucide='copy' class='w-4 h-4 mr-2'></i>Duplicar registro</button>

            </form >

        </li>

        <li>

            <form action='../bussines/datos.php' method='post' target="seemoduloapp">

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

                <input type='hidden' name='Id_Modulo_App' id='menu-context-ver'>

                <button type="submit" data-tw-toggle='modal' id="menu-context-ver-btn" data-tw-target='#verRegistro' class='flex items-center mr-6'> <i data-lucide='eye' class='w-5 h-5 mr-2'></i> Ver</button>

            </form>

        </li>

        <li>

            <form name='editar' action='formulario.php' method='post' onsubmit='loadingpage();'>

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

                <input type='hidden' name='Id_Modulo_App' id='menu-context-editar'>

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

                <input type='hidden' name='_ScrollTo' value=''>

                <button type='submit' class='flex items-center mr-3'><i data-lucide='edit' class='w-4 h-4 mr-2'></i>Editar</button>

            </form>

        </li>

        <li>

            <form action='../bussines/guardar.php'  class="menu-context-eliminar-li" value='Eliminar' method='post' target='deletemoduloapp'>

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

                <input type='hidden' name='Id_Modulo_App' id="menu-context-eliminar" >

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

                <input type='hidden' name='_ScrollTo' value=''>

                <button type='submit' id="menu-context-eliminar-btn" class='flex items-center text-danger' value = 'Eliminar' ><i data-lucide='trash' class='w-4 h-4 mr-2'></i>Eliminar</button>

            </form >

        </li>

        <li class="submenu"  onclick="closeSubmenu('submenu1');toggleSubmenu('submenu2')">

            <div style="display: flex;">

            <i data-lucide='aperture' class='w-4 h-4 mr-2'></i>Marcar registro

            </div>

            <ul class="submenu-horizontal" id="submenu2">

                <li><input class="color-input" type="color" id="menu-context-colorear-row"></li>

            </ul>

        </li>

        <li class="submenu"  onclick="closeSubmenu('submenu2');toggleSubmenu('submenu1')">

            <div style="display: flex;">

            <i data-lucide='aperture' class='w-4 h-4 mr-2'></i>Marcar columna

            </div>

            <ul class="submenu-horizontal" id="submenu1">

                <li><input class="color-input" type="color" id='menu-context-colorear-columna'></li>

            </ul>

        </li>

    </ul>

</div>

<!--termina el menu-->

<iframe name="savemoduloapp" id="savemoduloapp" style="display: none;"></iframe>

<iframe name="deletemoduloapp" id="deletemoduloapp" style="display: none;"></iframe>

    <script src="../../../dist/js/resaltarText.js?<?=$_Js_Version?>"></script>

    <script type="text/javascript">

        <?php if ($action == 'buscar') {

            echo"buscarYResaltar();"; 

        } ?>



    </script>

    <script type="text/javascript">

        function seemore(event,idmostrar){

            if(event=="Mostrar +"){

                $('#more'+idmostrar).css('display','block');

                $('#btnmostrarmas'+idmostrar).css('display','none');

                $('#btnmostrarmenos'+idmostrar).css('display','flex');



            }else{

                $('#more'+idmostrar).css('display','none');

                $('#btnmostrarmenos'+idmostrar).css('display','none');

                $('#btnmostrarmas'+idmostrar).css('display','flex');

            }

        }

    </script>

    <script src="../../../dist/js/app.js"></script>



    <script src="../../../dist/js/colorear_tabla.js?time=<?=$_Js_Version?>"></script>

<script src="https://code.jquery.com/jquery-3.6.4.min.js"></script>

    <script type="text/javascript">

        function openModalDelete(ideliminar){ 

            swal({

              title: "Eliminar",

              position: 'top',

              text: "¿ Estas seguro que deseas eliminar el registro. ?",

              icon: "warning",

              buttons: true,

              dangerMode: true,

            })

            .then((willDelete) => {

              if (willDelete) {

                

                var idelement = 'eliminartupla'+ideliminar;

                document.getElementById(idelement).submit();

                document.getElementById(ideliminar).remove();

                registros=document.getElementById('numregis_pagina').innerText;

                document.getElementById('numregis_pagina').innerText = parseInt(registros)-1;

                document.getElementById('target'+ideliminar).remove();

                swal("Registro eliminado exitosamente!", {

                  icon: "success",

                });

              } else {

                //no hacemos nada

              }

            });



        }

        function handleModalScroll(event) {

            // Manejar el desplazamiento dentro de la ventana modal

            event.stopPropagation();

        }

    </script>         

    <script type="text/javascript">

        function ver_modal_detalle(id){

            document.getElementById("verRegistro").style.display='block';

            setTimeout(function() {

                document.getElementById('verRegistro').style.opacity = '1';

            }, 10);

        }

        

        function closeModal() {

            var modalId = $('#verRegistro');

            modalId.fadeOut('slow');

            document.body.style.overflow = 'auto';

        }

    </script>

    <script type="text/javascript">

          window.onload=function(){

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

            loadbtn();

            cargarColoresTabla();

          }



          function loadingpage(){

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

           }

    </script>

    <script>

        function mostrarMenuTable(event,idtupla){

            event.preventDefault(); // Evita el menú contextual predeterminado del navegador

            document.getElementById('submenu1').style.display = 'none';

            document.getElementById('submenu2').style.display = 'none';

            document.getElementById('menu-context-ver-btn').setAttribute("onclick", "ver_modal_detalle("+idtupla+");closeMenuOptions();");

            document.getElementById('menu-context-ver').value=idtupla

            document.getElementById('menu-context-duplicar').value=idtupla;

            document.getElementById('menu-context-editar').value=idtupla;

            var elementosConClase = document.getElementsByClassName('menu-context-eliminar-li');

            // Iterar sobre los elementos y agregar un id

            for (var i = 0; i < elementosConClase.length; i++) {

                var elemento = elementosConClase[i];

                elemento.id = "eliminartupla"+idtupla;

            }

            document.getElementById('menu-context-eliminar-btn').setAttribute("onclick", "openModalDelete("+idtupla+");closeMenuOptions();");

            document.getElementById('menu-context-eliminar').value=idtupla;

            /*tomamos el indice de ubicacion sobre la tabla*/

            var inputClickeado = event.target;

            // Obtiene la celda (td) que contiene el input

            var celda = inputClickeado.closest('td');

            // Obtiene el índice de la celda dentro de su fila

            var indiceColumna = Array.from(celda.parentNode.children).indexOf(celda);

            document.getElementById('menu-context-colorear-columna').setAttribute("onchange", "colorearColumnaByMenuContext("+indiceColumna+",this.value);closeMenuOptions();");



            document.getElementById('menu-context-colorear-row').setAttribute("onchange", "colorearRowByMenuContext("+idtupla+",this.value);closeMenuOptions();");

            const menu = document.getElementById("menu-context");



            const elementoPadre = document.getElementById("tabla_modulo"); 

            //const coordenadaY = event.clientY - elementoPadre.getBoundingClientRect().top;

            const coordenadaY = event.clientY;

            menu.style.display = "block";

           if(event.clientX<995){

                menu.style.left = event.clientX + "px";

            }else{

                menu.style.left = (event.clientX-171) + "px";

            }

            //menu.style.top = (coordenadaY+190) + "px";

            menu.style.top = (coordenadaY) + "px";

        }



        const tabla = document.getElementById('tabla_modulo');

        // ocultar el menu de herramientas de la tabla

        tabla.addEventListener("click", function() {

            if (document.getElementById('menu-context').style.display === 'block') {

                document.getElementById('menu-context').style.display='none';

            }

        });



        function closeMenuOptions(){

            document.getElementById('menu-context').style.display='none';

        }



        function closeSubmenu(idSubmenu){

            var submenu = document.getElementById(idSubmenu);

            if(submenu){

                submenu.style.display = 'none';

            }

        }

        

        function toggleSubmenu(idSubmenu) {

            var submenu = document.getElementById(idSubmenu);

            

            if (submenu.style.display === 'none' || submenu.style.display === '') {

                submenu.style.display = 'block';

                var miContenedor = document.getElementById('menu-context');

                // Obtener el tamaño del contenedor



                const elementoPadre = document.getElementById("tabla_modulo"); 

                

                var distanciaDerecha = elementoPadre.offsetWidth - (miContenedor.offsetLeft + miContenedor.offsetWidth);

                var ancho = miContenedor.clientWidth;

                if(distanciaDerecha>70){

                    submenu.style.marginLeft = ancho+'px';

                }else{

                    submenu.style.marginLeft = -60+'px';    

                }

                submenu.style.marginTop = '-37px';

            } else {

                submenu.style.display = 'none';

            }

        }

    </script>

    <script>

      // Obtener el div de contenido

      /*var contentDiv = document.getElementById('contentDiv');

      // Obtener la altura disponible de la ventana del navegador

      var windowHeight = window.innerHeight;

      // Establecer la altura del div de contenido igual a la altura disponible de la ventana

      contentDiv.style.height = (windowHeight-140) + 'px';*/

    </script>

    <script>

        /*$(document).ready(function() {

            // Obtener la parte de la URL después del símbolo #

            var nuevoRegistroId = window.location.hash;

            // Eliminar el símbolo # del valor obtenido

            nuevoRegistroId = nuevoRegistroId.substring(1);

            if (nuevoRegistroId) {

                if(document.getElementById(nuevoRegistroId)){

                    document.getElementById(nuevoRegistroId).classList.add('nuevo-registro');

                }



                if(document.getElementById('box'+nuevoRegistroId)){

                    document.getElementById('box'+nuevoRegistroId).classList.add('nuevo-registro');

                }



            }

        });*/

    </script>

    <script>

    

        function manejarScroll() {

            var scrollY = document.getElementById('contentDiv').scrollTop;

            var camposScrollTo = document.getElementsByName('_ScrollTo');

            for (var i = 0; i < camposScrollTo.length; i++) {

                camposScrollTo[i].value = scrollY;

              }

        }

    

        document.getElementById('contentDiv').addEventListener('scroll', manejarScroll);

        $(document).ready(function() {

            //var scrollTo = obtenerValorGET('_ScrollTo');

            //var nuevoRegistroId = obtenerValorGET('_Id_Registro');

            const urlParams = new URLSearchParams(window.location.search);

            const id = urlParams.get('_Id_Registro');

            const scrollTo = urlParams.get('_ScrollTo');

            if (scrollTo !== null) {

                const boxRegistro = document.getElementById('box'+id);

                if(boxRegistro){

                    document.getElementById('contentDiv').scrollTop =scrollTo;

                    boxRegistro.classList.add('nuevo-registro');

                }

            }

            if(id !==null){

                const rowRegistro = document.getElementById(id);

                if(rowRegistro){

                    rowRegistro.scrollIntoView({ behavior: 'smooth', block: 'start' });

                    rowRegistro.classList.add('nuevo-registro');

                }

            }

        });

    </script>

    <!-- codigo toño -->

    <div onclick="document.getElementById('new-register').click();" class="btn-primary floating-button">

        <!-- <i style="z-index: 100;" class="fa fa-plus-circle" aria-hidden="true"></i> -->

        <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" class="lucide lucide-circle-plus"><circle cx="12" cy="12" r="10"/><path d="M8 12h8"/><path d="M12 8v8"/></svg>

    </div>

    <div class="btn-primary floating-button-search"  onclick="window.scrollTo({top: 0,behavior: 'smooth'});document.getElementById('search').focus();">

            <!-- <i style="z-index: 100;" class="fa fa-search" aria-hidden="true"></i> -->

            <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" class="lucide lucide-search"><circle cx="11" cy="11" r="8"/><path d="m21 21-4.3-4.3"/></svg>

    </div>

    <!-- codigo toño -->

    <!-- CODIGO TOÑO -->



    <script src="../../../dist/js/edit_front.js?time=<?=$_Js_Version?>"></script>

    <!-- CODIGO TOÑO -->

    <!--Script para el lector de Qr--->

    <script src="../../../dist/js/jsQR.js"></script>

    <script src="../../../dist/js/quagga.min.js"></script> <!-- QuaggaJS cargado localmente -->

    <script>

        let qrStream;



        function openQRReader() {

            const modal = document.getElementById('qrReaderModal');

            modal.style.display = 'flex';

            startQRReader();

        }



        function closeQRReader() {

            const modal = document.getElementById('qrReaderModal');

            modal.style.display = 'none';

            stopQRReader(); // Asegúrate de que se detenga todo correctamente

        }



        async function startQRReader() {

            const video = document.getElementById('video');

            const output = document.getElementById('output');



            try {

                qrStream = await navigator.mediaDevices.getUserMedia({ video: { facingMode: 'environment' } });

                video.srcObject = qrStream;



                video.onloadedmetadata = () => {

                    video.play();

                    scanQRCodeAndBarcode();

                };

            } catch (err) {

                console.error("Error accessing camera: ", err);

                output.textContent = 'Error al acceder a la cámara';

            }

        }



        function stopQRReader() {

            const video = document.getElementById('video');



            // Detener las pistas de video activas

            if (qrStream) {

                qrStream.getTracks().forEach(track => {

                    if (track.readyState === 'live') {

                        track.stop();

                    }

                });

            }



            // Detener QuaggaJS si está activo

            if (Quagga && Quagga.isRunning()) {

                Quagga.stop();

            }



            // Limpiar la fuente del elemento video

            video.srcObject = null;

            qrStream = null; // Limpiar la referencia al flujo

        }



        function scanQRCodeAndBarcode() {

            const video = document.getElementById('video');

            const canvas = document.createElement('canvas');

            const context = canvas.getContext('2d');

            const output = document.getElementById('output');



            function scanQR() {

                canvas.width = video.videoWidth;

                canvas.height = video.videoHeight;

                context.drawImage(video, 0, 0, canvas.width, canvas.height);



                const imageData = context.getImageData(0, 0, canvas.width, canvas.height);

                const code = jsQR(imageData.data, imageData.width, imageData.height);



                if (code) {

                    const detectedValue = code.data;



                    // Verificar si es URL o texto

                    if (isValidURL(detectedValue)) {

                        // Abrir enlace directamente en una nueva pestaña

                        window.open(detectedValue, '_blank');

                    } else {

                        document.getElementById('search').value = detectedValue; // Asignar al campo de búsqueda

                        document.getElementById('SearchForm').submit(); // Hacer submit automáticamente

                    }



                    closeQRReader(); // Cerrar lector

                    return;

                }



                requestAnimationFrame(scanQR);

            }



            Quagga.init({

                inputStream: {

                    type: "LiveStream",

                    target: video,

                    constraints: {

                        facingMode: "environment"

                    }

                },

                decoder: {

                    readers: ["code_128_reader", "ean_reader", "ean_8_reader", "upc_reader", "upc_e_reader"]

                }

            }, (err) => {

                if (err) {

                    console.error(err);

                    return;

                }

                Quagga.start();

            });



            Quagga.onDetected((data) => {

                if (data && data.codeResult && data.codeResult.code) {

                    document.getElementById('search').value = data.codeResult.code; // Asignar código al campo de búsqueda

                    document.getElementById('SearchForm').submit(); // Hacer submit automáticamente

                    closeQRReader(); // Cerrar lector

                    Quagga.stop();

                }

            });



            scanQR();

        }



        function isValidURL(string) {

            try {

                new URL(string);

                return true;

            } catch (_) {

                return false;

            }

        }

    </script>

    <!--End script para el lector de Qr--->

    </body>

    </center>

</HTML>   

