<?php
include "../conexion.php";
$vent_id=$_GET['id']; 
$can1=mysqli_query($con,"SELECT * from venta_detalle_temp where vent_id='$vent_id'") or die(mysqli_error($con)); 
$row1=mysqli_fetch_array($can1);
$vent_art_id=$row1['vent_art_id'];  
?>
<div id="resultados_sab"></div> 
<form role="form" id="sabores" >      
    <?php
        $can2=mysqli_query($con,"SELECT * from sabores_productos where articulo_art_id='$vent_art_id'") or die(mysqli_error($con)); 
        while ($row=mysqli_fetch_array($can2))
        {
            $sab_id=$row['sab_id'];
            $can3=mysqli_query($con,"SELECT * from venta_detalle_sabores_temp where sab_id='$sab_id' and vend_id='$vent_id'") or die(mysqli_error($con)); 
            $num=mysqli_num_rows($can3);
            if($num>0)
            {
                $checked='checked';
            }
            else
            {
                $checked='';
            }
    ?>
        <input type="checkbox" id="<?php echo $row['sab_id']; ?>" name="sabor[]" value="<?php echo $row['sab_id']; ?>" <?php echo $checked; ?>>
        <label class="lab" for="<?php echo $row['sab_id']; ?>"><?php echo $row['sab_nombre']; ?></label>
    <?php } ?>
        <input type="hidden" name="vent_art_id" value="<?php echo $vent_art_id; ?>">
        <input type="hidden" name="vent_id" value="<?php echo $vent_id; ?>">
    <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Cerrar</button>
        <button type="submit" id="sab" class="btn btn-primary">Registrar</button>
    </div>
</form>
<script>
$( "#sabores" ).submit(function( event ) {
$('#sab').attr("disabled", true);
var parametros = $(this).serialize();
$.ajax({
    type: "POST",
    url: "php_facturar/registrar_sabor_producto_temp.php",
    data: parametros,
        beforeSend: function(objeto){
        $('#resultados_sab').html('<center><img src="./img/ajax-loader.gif"> CARGANDO...</center>');
        },
    success: function(datos){
    $("#resultados_sab").html(datos);
    $('#sab').attr("disabled", false);
    $('#sabores_Modal').modal('hide');
    $('body').removeClass('modal-open');
    $('.modal-backdrop').remove();
    loadTabla();
    }
});
event.preventDefault();
})
</script>