<?php
require_once '../../library/config.php';
require_once '../library/functions.php';
require_once '../library/logged.php';
require_once '../../library/validation.php';


if (isset($_POST['delete_items'])){
	$a = explode(",", $_POST['delete_items']);
	
	foreach ($a  as $id) : 
	$p_id = isNumber(trim($id));
	$sql_del_subimg  = mysql_query("SELECT `image` FROM `photo` WHERE `p_product_id` = ".$p_id);
	$row_del_subimg = mysql_fetch_assoc($sql_del_subimg);
	if($row_del_subimg){
		do {
			$delete_subimg = $row_del_subimg['image'];
			unlink('../../upload/photos/'.$delete_subimg);
		} while ($row_del_subimg = mysql_fetch_assoc($sql_del_subimg));
		mysql_query('DELETE FROM `photo` WHERE `p_product_id` ='.$id);
	}
	
	$sql = mysql_query("select `p_image` FROM product_list WHERE p_id =".$id);
	$row = mysql_fetch_assoc($sql);
	$deleteImage = '../../upload/product_images/'.$row['p_image'];
	unlink($deleteImage);
	
	mysql_query('DELETE FROM product_list WHERE p_id ='.$id);
	endforeach;
}


?>
<b style="color:red;">Product(s) Deleted!!!!</b>
<script type="text/javascript">
	setTimeout(function(){location.reload()}, 1000);
</script>