<?php
session_start();
include("config.php");
include("funciones.php");
$validacion = validacion_usuario($con);
if($validacion == 1){
	$id_eli =$_POST['id'];
	$imagen_cabecera=$_POST['img1'];
	$id_eli_v = filter_var($id_eli,  FILTER_VALIDATE_INT);
	$imagen_cabecera_v = filter_var($imagen_cabecera,  FILTER_SANITIZE_STRING);
	if($id_eli_v){	
		if($imagen_cabecera_v){
			$sql_eli = "delete from exito where id=".mysqli_real_escape_string($con,$id_eli_v);		
			if (mysqli_query($con,$sql_eli)){				
				echo "Eliminando...";
				$directorio = "img/casosexito/";					
				chmod($directorio.$imagen_cabecera_v, 0777);
				unlink($directorio.$imagen_cabecera_v);
				?>	
					<script type="text/javascript">
						window.location.href = "casosexito.php";
					</script>
				<?php			
			}else{
				?>
				<script>
				alert("Por favor intente denuevo");
				window.location.href = "casosexito.php";
				</script>
				<?php
			}
		}elseif ($imagen_cabecera_v == "") {
			$sql_eli = "delete from exito where id='".$id_eli_v."'";		
			if (mysqli_query($con,$sql_eli)){				
				echo "Eliminando...";				
				?>	
					<script type="text/javascript">
						window.location.href = "casosexito.php";
					</script>
				<?php			
			}else{
				?>
				<script>
				alert("Por favor intente denuevo");
				window.location.href = "casosexito.php";
				</script>
				<?php
			}
		}
	}else{
		?>
		<script>
		alert("Por favor intente denuevo");
		window.location.href = "casosexito.php";
		</script>
		<?php
	}
}		

?>
