<?php
include "../conexion.php";
$cotd_id=$_GET['id']; 
$can1=mysqli_query($con,"SELECT * from cotizacion_detalle where cotd_id='$cotd_id'") or die(mysqli_error($con)); 
$row1=mysqli_fetch_array($can1);
$cotd_art_id=$row1['cotd_art_id'];  
$cot_id=$row1['cotizacion_cot_id'];  
?>
<div id="resultados_sab"></div> 
<form role="form" id="sabores" >      
    <?php
        $can2=mysqli_query($con,"SELECT * from sabores_productos where articulo_art_id='$cotd_art_id' ") or die(mysqli_error($con)); 
        while ($row=mysqli_fetch_array($can2))
        {
            $sab_id=$row['sab_id'];
            $can3=mysqli_query($con,"SELECT * from cotizacion_sabores_producto where sab_id='$sab_id' and cotd_id='$cotd_id'") or die(mysqli_error($con)); 
            $num=mysqli_num_rows($can3);
            if($num>0)
            {
                $checked='checked';
            }
            else
            {
                $checked='';
            }
    ?>
            <input type="checkbox" id="sabor<?php echo $sab_id; ?>" name="sabor[]" value="<?php  echo $sab_id; ?>" <?php echo $checked; ?>>
            <label class="lab" for="sabor<?php echo $sab_id; ?>"><?php echo mb_strtoupper($row['sab_nombre']); ?></label>
    <?php } ?>
    <input type="hidden" name="cotd_art_id" value="<?php echo $cotd_art_id; ?>">
    <input type="hidden" name="cotd_id" value="<?php echo $cotd_id; ?>">
    <input type="hidden" name="cot_id" value="<?php echo $cot_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_cotizaciones/z_registrar_sabor_articulo.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>
<link href="css/checkbox.css" rel="stylesheet" media="all"> 