<?php
session_start();
error_reporting(E_ALL ^ (E_NOTICE | E_WARNING));
include"../../../../inc/conn.php";

$id_unit	= str_replace("'","`",(isset($_POST['id_unit'])) ? $_POST['id_unit'] : "");

$qunit=mysqli_query($connect,"select * from tb_unit where id_unit='".$id_unit."'");
while($runit=mysqli_fetch_array($qunit)){

	$filefoto = $runit['banner'];
	unlink ("../../../../assets/banner/$filefoto");

	$delete1 = mysqli_query($connect,"delete from tb_materi where id_unit='".$runit['id_unit']."'")or die(mysqli_error($connect));
	$delete2 = mysqli_query($connect,"delete from tb_video where id_unit='".$runit['id_unit']."'")or die(mysqli_error($connect));
	$delete3 = mysqli_query($connect,"delete from tb_essai where id_unit='".$runit['id_unit']."'")or die(mysqli_error($connect));
	$delete4 = mysqli_query($connect,"delete from tb_jawaban where id_unit='".$runit['id_unit']."'")or die(mysqli_error($connect));

}



$delete 	= mysqli_query($connect,"delete from tb_unit where id_unit='$id_unit'")or die(mysqli_error($connect));


if($delete1){
	echo"<script>alert('Data unit berhasil dihapus !');</script>";
	echo"<script>document.location.href='datamodul'</script>";
}else{
	echo"<script>alert('Gagal mengeksekusi perintah ini !');history.go(-1)</script>";
}


?>