<?php
session_start();
include '../includes/connection.php';
$id=base64_decode($_GET['id']);
$product_name=base64_decode($_GET['prodname']);
$sqledit=mysqli_fetch_array(mysqli_query($con,"select * from stock where product_name='$id'"));
$quantity=$sqledit['quantity'];
if ($quantity>0) {
	echo"<script>alert('Failed: The product cannot be deleted when it is in stock'),history.go(-1);
	window.location='products.php';
	</script>";
	}else{
$delete = mysqli_query($con,"update products set status =0 where id='$id'");
$update = mysqli_query($con,"update stock set status =0 where product_name='$id'");
if($delete){
	$id_user=$_SESSION['id'];
  $activity="Deleted a product ".$product_name;
  $log_sql=mysqli_query($con,"INSERT INTO logs(user_id, activity) VALUES 
('$id_user','$activity')");
if($log_sql){
	echo"
	<script> alert('product deleted successfully');
	window.location='products.php'</script>
	";
}
}
}
?>