<?php use_helper( 'UrlFunctions' ); ?>
<?php use_helper( 'UtilFunctions' ); ?>
<?php use_helper( 'IncludePartial' ); ?>

<script type="text/javascript">
showAlertBootStrap = function( elm_id_content, class_default, message_alert )
{
    var html_alert = '<div class="alert ' + class_default + ' alert-dismissible fade show" role="alert"> ' +
            '' + message_alert +
            '<button type="button" class="close" data-dismiss="alert" aria-label="Close">' +
                '<span aria-hidden="true">&times;</span>' +
            '</button>' +
        '</div>';
    $( "#" + elm_id_content ).append( html_alert );
}

saveForm = function()
{
    //mostrarCargaImg();
    var strFormSerialize = $( 'form' ).serialize();
    
    executeAjaxJson
    ( 
        "<?php echo buildUrl( 'tipoubicacion/saveAddEdit', "" ) ?>", 
        strFormSerialize,
        function( o_json )
        {
            //console.log( o_json );
            //ocultarCargaImg();
            if( o_json.error )
            {
                showAlertBootStrap( 'content_alert', 'alert-danger', o_json.mensaje_error );
                //mostrarMensajeError( o_json.mensaje_error );
                return false;
            }
            //return false;
            location.href = "<?=buildUrl( 'tipoubicacion/list', "" )?>";
        } 
    );
    return false;
}
</script>

<div class="shadow-sm p-3 mb-2 bg-white rounded card card-body">
    <div class="row">
        <div class="col mb-1">
            <h4 class="text-info text-nowrap mb-0"><?=$s_Titulo?></h4>
        </div>
    </div>
</div>

<div id="content_alert" style=""></div>

<div class="card">
    <div class="container">

        <form class="was-validated" name="form1" id="form1" method="POST" action="" onsubmit="return saveForm();" enctype="multipart/form-data">
            <input type="hidden" name="i_Id" id="i_Id" value="<?=$o_ObjectBN->getIdTipoUbicacion()?>">
            <input type="hidden" name="s_TipoProc" id="s_TipoProc" value="<?=$s_TipoProc?>">

            <div class="form-group">
                <label for="Nombre" class="col-form-label">Nombre:</label>
                <input type="text" class="form-control form-control-sm" id="Nombre" placeholder="" name="Nombre" value="<?=$o_ObjectBN->getNombre()?>" onblur="this.value=this.value.toUpperCase();" required>
                <!--<div class="valid-feedback">Valido.</div>
                <div class="invalid-feedback">Por favor ingrese valor.</div>-->
            </div>
            <div class="form-row mx-0">
                <div class="col-md-4 mb-1">
                    <label class="col-form-label" for="Nivel">Nivel</label>
                    <select class="form-control form-control-sm custom-select my-0 mr-sm-2" id="Nivel" name="Nivel" required>
                        <option value=""> - Seleccione - </option>
                        <option value="0" <?php if( $o_ObjectBN->getNivel() == "0" ){ echo "selected"; } ?> > EXTERIOR </option>
                        <option value="1" <?php if( $o_ObjectBN->getNivel() == "1" ){ echo "selected"; } ?> > INTERIOR </option>
                    </select>
                </div>
            </div>
            <div class="form-row mx-0">
                <div class="col-md-4 mb-1">
                    <label class="col-form-label" for="Estado">Estado</label>
                    <select class="form-control form-control-sm custom-select my-0 mr-sm-2" id="Estado" name="Estado" required>
                        <option value=""> - Seleccione - </option>
                        <option value="A" <?php if( $o_ObjectBN->getEstado() == "A" ){ echo "selected"; } ?> > ACTIVO </option>
                        <option value="I" <?php if( $o_ObjectBN->getEstado() == "I" ){ echo "selected"; } ?> > INACTIVO </option>
                    </select>
                </div>
            </div>
        </form>

<div class="dropdown-divider" style="border-top: 1px solid #8c8b8b;"></div>

<?php if( $o_ObjectBN->getIdTipoUbicacion() ){ ?>

<form name="form2" id="form2" method="POST" action="<?php echo buildUrl( 'tipoubicacion/saveAddEdit' ) ?>" enctype="multipart/form-data">
    <input type="hidden" name="i_Id" id="i_Id" value="<?=$o_ObjectBN->getIdTipoUbicacion()?>">
    <input type="hidden" name="s_TipoProc" id="s_TipoProc" value="<?=$s_TipoProc?>">
    <input type="hidden" name="imagen_save" id="imagen_save" value="0">
    <table class="" >
        <tr>
            <td align="center">
                <input type="file" name="file_upload" id="file_upload" class="form-control-file">
                <input type="submit" class="button" value="Cargar Imagen" name="submit" onclick="$('#imagen_save').val('file_to_upload');">
            </td>
        </tr>

        <tr>
            <td align="center"><img src="<?=$o_ObjectBN->getImagenUbicacion()?>" border="1" width="100" ></td>
        </tr>
        <tr>
            <td align="center"><input type="submit" class="button" value="Eliminar Imagen" name="submit" onclick="$('#imagen_save').val('file_to_upload_del');"></td>
        </tr>

    </table>
</form>

<br>

<button type="button" class="btn btn-secondary btn-lg mb-2 mt-2" id="btnAudi">Auditoria</button>
<?=crearFuentePopupIframe( array( "div_id"=>"dialog", "iframe_id"=>"myIframe", "popup_title"=>"AUDITORIA", "modal"=>true ) )?>
<script>
$( "#btnAudi" )
.click
(
    function()
    {
        $( '#myIframe' ).attr( 'src', '<?=buildUrl( 'tipoubicacion/audi', 'i_Id='.$o_ObjectBN->getIdTipoUbicacion() )?>' );
        $( '#dialog' ).dialog( 'open' );
    }
)
</script>            
<?php } ?>

<div class="form-group col-14"><hr style="border-top: 1px solid #8c8b8b;"></div>

            <div class="form-row mx-0">
                <div class="col-md-6 mb-1">
                    <button type="button" class="btn btn-primary btn-lg btn-block" onclick="location.href='<?php echo buildUrl( 'tipoubicacion/list', '' ) ?>'">CANCELAR</button>
                </div>
                <div class="col-md-6 mb-1">
                    <button type="submit" class="btn btn-primary btn-lg btn-block" onclick="$('#form1').submit();">GRABAR Y SALIR</button>
                </div>
            </div>
        </form>
    </div>
</div>