<?php
session_start();
include "../conexion.php";
require_once('../include/sesiones.php'); 
if(!empty($_GET))
{
    $art_id=$_GET["art_id"];
    $can1=mysqli_query($con,"SELECT * FROM combos_articulos where coma_art_id='$art_id'") or die(mysqli_error($con)); 
    $result = mysqli_num_rows($can1);
    if ($result>=1) 
    { 
        echo '<div class="alert alert-warning alert-dismissable">
                <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
                <strong>NO!</strong> Se puede eliminar articulos asociados a combos.
          </div>'; 
    }
    else
    { 
        $files = glob("../img/articulos/$art_id.jpg");
        if(count($files) > 0) 
        { 
            foreach($files as $file) 
            { 
                unlink ("../img/articulos/$art_id.jpg");//eliminar img de la carpeta 
            } 
        } 

        $borrar_sql=mysqli_query($con,"DELETE FROM articulos_presentacion WHERE pres_art_id='$art_id'") or die(mysqli_error($con));
        $borrar_sql=mysqli_query($con,"DELETE FROM atributos1 WHERE atri_art_id='$art_id'") or die(mysqli_error($con));
        $borrar_sql=mysqli_query($con,"DELETE FROM atributos2 WHERE atri_art_id2='$art_id'") or die(mysqli_error($con));
        $borrar_sql=mysqli_query($con,"DELETE FROM seriales_articulos WHERE articulos_art_id='$art_id'") or die(mysqli_error($con));
        $borrar_sql=mysqli_query($con,"DELETE FROM articulos_has_bodegas WHERE articulos_art_id='$art_id' and empresa='$empresa'") or die(mysqli_error($con));
        $borrar_sql=mysqli_query($con,"DELETE FROM precio WHERE articulos_art_id='$art_id' and empresa='$empresa'") or die(mysqli_error($con));
        $borrar_sql=mysqli_query($con,"DELETE FROM articulos WHERE art_id='$art_id' and empresa='$empresa'") or die(mysqli_error($con));

        echo '<div class="alert alert-danger alert-dismissable">
                    <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
                    <strong>Articulo!</strong> Eliminado correctamente.
              </div>';
    }
}
?>