<?php

    session_start();

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

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

        exit();

    }

?>

<!DOCTYPE html>

<?php

/*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'>

<meta charset="UTF-8" />

<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/lote_qr.php');

    require(ROOT_CONTROLLER.'lote_qr.php');

    $Obj_lote_qr = new lote_qr(); 

?>



    <!--<link href='https://netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap.min.css' rel='stylesheet'> se comento esta linea porque altera el estilo del formulario-->

    <!--<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"><!--se agrego esta dependencia para los iconos de lado izquierdo en los inputs-->

    <script src='https://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;?>" />

    <!-- END: CSS Assets-->

    <link rel="stylesheet" href="../../../dist/css/input_file.css?time=<?=$time_log_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--->

    <!---llamamos la libreria de tinymce--->

    <script defer src="../../../dist/tinymce/tinymce/main.js?time=<?=$time_log_assets;?>"></script>

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

    <script src="../../../dist/tinymce/tinymce/tinymce.min.js?time=<?=$time_log_assets;?>" referrerpolicy="origin"></script>

    <!---Terminamos de agregar editor tinymce--->



    <!---incluimos dependencias para el select con buscador-->

    <script src="https://code.jquery.com/jquery-3.7.1.js" integrity="sha256-eKhayi8LEQwp4NKxN+CfCh+3qOVUtJn3QNZ0TciWLP4=" crossorigin="anonymous"></script>

    <link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet" />

    <script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script>

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

    <!--termina dependencias para el select con buscador--->

        

<?php



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

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

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

$_Action = $_Buscar!='' ? 'buscar' : '';

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

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

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

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

// Obtener el REQUEST_URI

$_Request_Uri = $_SERVER['REQUEST_URI'];

// Dividir el REQUEST_URI en segmentos

$_Uri_Segments = explode('/', trim($_Request_Uri, '/'));

// Obtener el primer segmento

$_First_Segment = $_Uri_Segments[0];

$baseUri = dirname(dirname(dirname(dirname($_SERVER['REQUEST_URI']))));

$_URL_Default= (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$baseUri/qr";

$Qr_Icon_Image='';

$Cantidad_Qrs='';

$Color_Fondo='';

$Imprimir_Codigo='';

$Url_Base='';

$Lote='';

$Borrado_Logico='';

$Status='';

$Usuario_Registro='';

$Id_Fk_Usuario_Registro='';

$Usuario_Modifico='';

$Id_Fk_Usuario_Modifico='';

$Veces_Impreso='';

$Fecha_Registro='';

$Fecha_Modificacion='';



switch ($action) {

    case 'editar':



        echo"<TITLE>Editar lote qr</TITLE>";

        break;



    default:

        echo"<TITLE>Registrar lote qr</TITLE>";

        break;

}



require_once(ROOT_CHARACTER_FIX);

$Obj_fix_characters = new fix_characters();

require_once(ROOT_CONTROLLER.'lote_qr.php');

$Obj_lote_qr = new lote_qr();//para los datos del formulario

$Obj_lote_qr2 = new lote_qr();//para los datos del paginador



//lee las variables del formulario.

if (!empty($_POST))

{

    /*require_once(ROOT_CONFIG);      

    $Odbj_conexion = new odbconexion;

    $conexion=$Odbj_conexion->openconection();

    $consulta="SELECT * FROM lote_qr_appquadrata WHERE Id_Lote_Qr='$Id_Lote_Qr'";

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

    $conexion->close();*/

    $Array_adapter_lote_qr=$Obj_lote_qr->getbyid_lote_qr($Id_Lote_Qr);

    while($field_lote_qr=$Array_adapter_lote_qr->fetch_assoc())

    {

    $Qr_Icon_Image=$field_lote_qr['Qr_Icon_Image'];

    $Cantidad_Qrs=$field_lote_qr['Cantidad_Qrs'];

    $Color_Fondo=$field_lote_qr['Color_Fondo'];

    $Imprimir_Codigo=$field_lote_qr['Imprimir_Codigo'];

    $Url_Base=$field_lote_qr['Url_Base'];

    $Lote=$field_lote_qr['Lote'];

    $Borrado_Logico=$field_lote_qr['Borrado_Logico'];

    $Status=$field_lote_qr['Status'];

    $Usuario_Registro=$field_lote_qr['Usuario_Registro'];

    $Id_Fk_Usuario_Registro=$field_lote_qr['Id_Fk_Usuario_Registro'];

    $Usuario_Modifico=$field_lote_qr['Usuario_Modifico'];

    $Id_Fk_Usuario_Modifico=$field_lote_qr['Id_Fk_Usuario_Modifico'];

    $Veces_Impreso=$field_lote_qr['Veces_Impreso'];

    $Fecha_Registro=$field_lote_qr['Fecha_Registro'];

    $Fecha_Modificacion=$field_lote_qr['Fecha_Modificacion'];

   

    }

}

?>    



<?php  

    $row_registers=0;

    $arreglo_registers = array();

    /*$Odbj_conexion = new odbconexion;

    $conexion=$Odbj_conexion->openconection();

    $consulta="SELECT * FROM lote_qr_appquadrata";

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

    $conexion->close();*/

    $Array_adapter_lote_qr_registers=$Obj_lote_qr2->get_lote_qr_paginador_frm();

    $rows_registers=$Array_adapter_lote_qr_registers->num_rows;

    while($field_lote_qr_register=$Array_adapter_lote_qr_registers->fetch_assoc())

    {

        $row_registers++;

        array_push($arreglo_registers, array("id" => $field_lote_qr_register['Id_Lote_Qr'], "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;

    }



</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 LOTE QR

                </h2>";

            if($rows_registers>1){

                foreach ($arreglo_registers as $elemento) {

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

                        $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_Lote_Qr'>

                        <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_Lote_Qr'>

                        <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 LOTE QR

                </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' enctype='multipart/form-data'>      

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

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

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

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

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

                    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'>Qr Icon Image: </label>";

                                        if ($Qr_Icon_Image=='') {

                                            echo"<img id='blahQr_Icon_Image' src='../../../dist/images/upload.png' style='border-style: inset;width:140px;height:140px;border-radius:150px;padding:7px;' />";

                                        }else{

                                            $time=time();

                                            $time=filectime($Qr_Icon_Image);

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

                                            echo"<img id='blahQr_Icon_Image' src='$Qr_Icon_Image?dummy=$time' alt='Empresa' style='border-style: inset;width:140px;height:140px;border-radius:150px;padding:7px;' />";

                                        }

                            /*echo "

                                <br>

                                <input class='btn btn-primary' name='Qr_Icon_Image_file'  capture='camera'  accept='image/x-png,image/gif,image/jpeg' type='file' onchange=\"document.getElementById('blahQr_Icon_Image').src = window.URL.createObjectURL(this.files[0]);\" style='max-width:80%;'/>";*/

                             echo "<input type='file' name='Qr_Icon_Image_file' id='Qr_Icon_Image_file' class='inputfile inputfile-2' accept='image/x-png,image/gif,image/jpeg' onchange=\"document.getElementById('spanQr_Icon_Image').innerHTML=this.files[0].name;document.getElementById('blahQr_Icon_Image').src = window.URL.createObjectURL(this.files[0]);\"  style='max-width:80%;'/>

                                  <label for='Qr_Icon_Image_file'><svg xmlns='http://www.w3.org/2000/svg' class='iborrainputfile' width='20' height='17' viewBox='0 0 20 17'><path d='M10 0l-5.2 4.9h3.3v5.1h3.8v-5.1h3.3l-5.2-4.9zm9.3 11.5l-3.2-2.1h-2l3.4 2.6h-3.5c-.1 0-.2.1-.2.1l-.8 2.3h-6l-.8-2.2c-.1-.1-.1-.2-.2-.2h-3.6l3.4-2.6h-2l-3.2 2.1c-.4.3-.7 1-.6 1.5l.6 3.1c.1.5.7.9 1.2.9h16.3c.6 0 1.1-.4 1.3-.9l.6-3.1c.1-.5-.2-1.2-.7-1.5z'></path></svg><span class='iborrainputfile' id='spanQr_Icon_Image'>Seleccionar archivo</span>

                                  </label>";

                            echo "</div>";

                            

                                 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'>Cantidad Qrs: </label>

                                   <input id='Cantidad_Qrs' name='Cantidad_Qrs' value='$Cantidad_Qrs' type='number' class='form-control' " . ($action == 'editar' ? 'disabled' : '') . ">

                                </div>";

                                 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'>Url Base: </label>

                                   <input id='Url_Base' name='Url_Base' value='".(($Url_Base == '') ? $_URL_Default : $Url_Base)."' type='text' class='form-control'>

                                </div>";

                                /*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'>Color Fondo: </label>

                                   <input id='Color_Fondo' name='Color_Fondo' value='$Color_Fondo' type='color' style='width: 25px;height: 25px;border-radius: 50%;overflow: hidden;'>

                                </div>";

                                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'>Imprimir Codigo: </label>

                                    <div style='display: flex;flex-wrap: wrap'>

                                        <div class='form-check form-switch mr-2'>

                                            <input type='checkbox' class='form-check-input' id='Imprimir_Codigo' name='Imprimir_Codigo' value='activa' " . ($Imprimir_Codigo == 'activa' ? 'checked' : '') . ">

                                            <label class='form-check-label' for='Imprimir_Codigo'>Activa</label>

                                        </div>

                                    </div>    

                                </div>";*/

                                                   

echo "          

                   </div><!---Este div cierra el grid para los campos del formulario -->     

                </div>

            </div>";

         switch ($action) {

            case 'editar':

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

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

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

                    <a href='./?_Clausula_Fk=$_Clausula_Fk&_IdFk=$_IdFk&pagina=$_Pagina&buscar=$_Buscar&action=$_Action&_Id_Registro=$Id_Lote_Qr&_ScrollTo=$_ScrollTo' class='btn btn-danger flex items-center w-20 mr-auto'> Cancelar</a>

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

                </div>";

            }else{

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

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

                    <a href='./?pagina=$_Pagina&buscar=$_Buscar&action=$_Action&_Id_Registro=$Id_Lote_Qr&_ScrollTo=$_ScrollTo' class='btn btn-danger flex items-center w-20 mr-auto'> Cancelar</a>

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

                </div>";

            }

            break;

            case 'duplicar':

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

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

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

                    <a href='./?_Clausula_Fk=$_Clausula_Fk&_IdFk=$_IdFk&pagina=$_Pagina&buscar=$_Buscar&action=$_Action&_Id_Registro=$Id_Lote_Qr&_ScrollTo=$_ScrollTo' class='btn btn-danger flex items-center w-20 mr-auto'> Cancelar</a>

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

                </div>";

            }else{

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

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

                    <a href='./?pagina=$_Pagina&buscar=$_Buscar&action=$_Action&_Id_Registro=$Id_Lote_Qr&_ScrollTo=$_ScrollTo' class='btn btn-danger flex items-center w-20 mr-auto'> Cancelar</a>

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

                </div>";

            }

            break;

            default:

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

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

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

                    <a href='./?_Clausula_Fk=$_Clausula_Fk&_IdFk=$_IdFk&pagina=$_Pagina&buscar=$_Buscar&action=$_Action&_Id_Registro=$Id_Lote_Qr&_ScrollTo=$_ScrollTo' class='btn btn-danger flex items-center w-20 mr-auto'> Cancelar</a>

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

                </div>";

            }else{

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

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

                    <a href='./?pagina=$_Pagina&buscar=$_Buscar&action=$_Action&_Id_Registro=$Id_Lote_Qr&_ScrollTo=$_ScrollTo' class='btn btn-danger flex items-center w-20 mr-auto'> Cancelar</a>

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

                </div>";

            }

            break;

        }                

echo "

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

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

";

echo "  </form>

        </div>

    </div>";





    //Termina form del formulario

?>



    </BODY>

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

<script src="https://mozilla.github.io/pdf.js/build/pdf.js"></script>

<script type="text/javascript">

    // Loaded via <script> tag, create shortcut to access PDF.js exports.

    var pdfjsLib = window['pdfjs-dist/build/pdf'];

    // The workerSrc property shall be specified.

    pdfjsLib.GlobalWorkerOptions.workerSrc = 'https://mozilla.github.io/pdf.js/build/pdf.worker.js';

</script>

       

<script type="text/javascript">

    window.onload=function(){

        window.scrollTo(0,0);

        window.parent.scrollTo(0,0);

        if(parent.document.getElementById('loadingpage')){

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

        }

    }



    function loadingpage(){

        if(parent.document.getElementById('loadingpage')){

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

        }

    }

</script>

<script>

    //document.getElementsByClassName('').select2();

    $('.select-search').select2();

</script>   



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

    </center>

</HTML>