<?php
	include_once 'connect.php';

	    //------------------------------------------------DELETE QUERIES---------------------------------------------------------------

	//banners table delete
	if(count($_POST)>0){
		if($_POST['type']=='delbanner'){
			$id=$_POST['id'];

			$sql1 = "SELECT * FROM tbl_banners WHERE banner_id=$id ";
	    	$result = mysqli_query($con, $sql1);
			$row = mysqli_fetch_assoc($result);
			$filePath = $row['banner_image'];
			$sql = "DELETE FROM `tbl_banners` WHERE banner_id=$id ";
			if (mysqli_query($con, $sql)) {
				unlink($filePath);
				echo $id;
			} 
			else {
					echo "Error: " . $sql . "<br>" . mysqli_error($con);
			}
			mysqli_close($con);
		}
	}
	//ends-------------------------------------------

	//notifications table delete
	if(count($_POST)>0){
		if($_POST['type']=='delnotification'){
			$id=$_POST['id'];

			$sql1 = "SELECT * FROM tbl_notification WHERE notification_id=$id ";
	    	$result = mysqli_query($con, $sql1);
			$row = mysqli_fetch_assoc($result);
			$sql = "DELETE FROM `tbl_notification` WHERE notification_id=$id ";
			if (mysqli_query($con, $sql)) {
				echo $id;
			} 
			else {
					echo "Error: " . $sql . "<br>" . mysqli_error($con);
			}
			mysqli_close($con);
		}
	}
	//ends-------------------------------------------

	//gallery table delete
	if(count($_POST)>0){
		if($_POST['type']=='delgallery'){
			$id=$_POST['id'];

			$sql1 = "SELECT * FROM tbl_gallery WHERE gallery_id=$id ";
	    	$result = mysqli_query($con, $sql1);
			$row = mysqli_fetch_assoc($result);
			$filePath = $row['gallery_image'];
			$sql = "DELETE FROM `tbl_gallery` WHERE gallery_id=$id ";
			if (mysqli_query($con, $sql)) {
				unlink($filePath);
				echo $id;
			} 
			else {
					echo "Error: " . $sql . "<br>" . mysqli_error($con);
			}
			mysqli_close($con);
		}
	}
	//ends-------------------------------------------

	//generalinfo table delete
	if(count($_POST)>0){
		if($_POST['type']=='delgeneralinfo'){
			$id=$_POST['id'];

			$sql1 = "SELECT * FROM tbl_generalinfo WHERE generalinfo_id=$id ";
	    	$result = mysqli_query($con, $sql1);
			$row = mysqli_fetch_assoc($result);
			$sql = "DELETE FROM `tbl_generalinfo` WHERE generalinfo_id=$id ";
			if (mysqli_query($con, $sql)) {
				echo $id;
			} 
			else {
					echo "Error: " . $sql . "<br>" . mysqli_error($con);
			}
			mysqli_close($con);
		}
	}
	//ends-------------------------------------------

	//services table delete
	if(count($_POST)>0){
		if($_POST['type']=='delservice'){
			$id=$_POST['id'];

			$sql1 = "SELECT * FROM tbl_services WHERE service_id=$id ";
	    	$result = mysqli_query($con, $sql1);
			$row = mysqli_fetch_assoc($result);
			$filePath = $row['service_icon'];
			$filePath1 = $row['service_image'];
			$filePaths = [$filePath, $filePath1];
			$sql = "DELETE FROM `tbl_services` WHERE service_id=$id ";
			if (mysqli_query($con, $sql)) {
			    foreach ($filePaths as $file) {
                    if (file_exists($file)) {
                        unlink($file);
                    }
                }
				echo $id;
			} 
			else {
					echo "Error: " . $sql . "<br>" . mysqli_error($con);
			}
			mysqli_close($con);
		}
	}
	//ends-------------------------------------------
	
	

	
	

	//service details table delete
	if(count($_POST)>0){
		if($_POST['type']=='delservicedetails'){
			$id=$_POST['id'];

			$sql1 = "SELECT * FROM tbl_servicedetails WHERE servicedetails_id=$id ";
	    	$result = mysqli_query($con, $sql1);
			$row = mysqli_fetch_assoc($result);
			$filePath = $row['servicedetails_image'];
			$sql = "DELETE FROM `tbl_servicedetails` WHERE servicedetails_id=$id ";
			if (mysqli_query($con, $sql)) {
				unlink($filePath);
				echo $id;
			} 
			else {
					echo "Error: " . $sql . "<br>" . mysqli_error($con);
			}
			mysqli_close($con);
		}
	}
	//ends-------------------------------------------

	//service details Image table delete
	if(count($_POST)>0){
		if($_POST['type']=='delservicedetailsimage'){
			$id=$_POST['id'];

			$sql1 = "SELECT * FROM tbl_servicedetailsimage WHERE servicedetails_imgid=$id ";
	    	$result = mysqli_query($con, $sql1);
			$row = mysqli_fetch_assoc($result);
			$filePath = $row['servicedetails_image'];
			$sql = "DELETE FROM `tbl_servicedetailsimage` WHERE servicedetails_imgid=$id ";
			if (mysqli_query($con, $sql)) {
				unlink($filePath);
				echo $id;
			} 
			else {
					echo "Error: " . $sql . "<br>" . mysqli_error($con);
			}
			mysqli_close($con);
		}
	}
	//ends-------------------------------------------
	
	//tc table delete
	if(count($_POST)>0){
		if($_POST['type']=='deltc'){
			$id=$_POST['id'];

			$sql1 = "SELECT * FROM tbl_tc WHERE tc_id=$id ";
	    	$result = mysqli_query($con, $sql1);
			$row = mysqli_fetch_assoc($result);
			$filePath = $row['tc_link'];
			$sql = "DELETE FROM `tbl_tc` WHERE tc_id=$id ";
			if (mysqli_query($con, $sql)) {
				unlink($filePath);
				echo $id;
			} 
			else {
					echo "Error: " . $sql . "<br>" . mysqli_error($con);
			}
			mysqli_close($con);
		}
	}
	//ends-------------------------------------------

	

?>