<?php session_start();
include("../include/config.php");
include("../include/functions.php"); 
validate_admin();
$arr =$_POST['ids'];
//print_r($_REQUEST);
$Submit =$_POST['what'];
if(count($arr)>0){
	$str_rest_refs=implode(",",$arr);
	if($Submit=='Delete')
	{	
	    $imageArr=$obj->query("select photo from $tbl_product where id in ($str_rest_refs) "); 
		while($resultImage=$obj->fetchNextObject($imageArr)){
		@unlink("../upload_images/product/".$resultImage->photo); 
		@unlink("../upload_images/product/tiny/".$resultImage->photo);
		@unlink("../upload_images/product/thumb/".$resultImage->photo);
		}
		$imageArr=$obj->query("select pphoto,barcode from $tbl_productprice where product_id in ($str_rest_refs) "); 
		while($resultImage=$obj->fetchNextObject($imageArr)){
		@unlink("../upload_images/product/".$resultImage->pphoto); 
		@unlink("../upload_images/product/tiny/".$resultImage->pphoto);
		@unlink("../upload_images/product/thumb/".$resultImage->pphoto);
		@unlink("../upload_images/product/barcode/".$resultImage->barcode);
		}
		$sql="delete from $tbl_specialcatproduct where prod_id in ($str_rest_refs)"; 
		$obj->query($sql);
		$sql="delete from $tbl_productprice where product_id in ($str_rest_refs)"; 
		$obj->query($sql);
		$sql="delete from $tbl_features where product_id in ($str_rest_refs)"; 
		$obj->query($sql);
	    $sql="delete from $tbl_product where id in ($str_rest_refs)"; 
		$obj->query($sql);
		$sess_msg='Selected record(s) deleted successfully';
		$_SESSION['sess_msg']=$sess_msg;
    }
	elseif($Submit=='Make Latest')
	{	
		$sql="update $tbl_product set latest=1 where id in ($str_rest_refs)";
		$obj->query($sql);
		$sess_msg='Selected record(s) activated successfully';
		$_SESSION['sess_msg']=$sess_msg;
	}
	elseif($Submit=='Remove Latest')
	{	
		$sql="update $tbl_product set latest=0 where id in ($str_rest_refs)";
		$obj->query($sql);
		$sess_msg='Selected record(s) activated successfully';
		$_SESSION['sess_msg']=$sess_msg;
	}
	elseif($Submit=='Activate')
	{	
	     $check=$obj->query("select cat_id from $tbl_product where id in ($str_rest_refs)");
	    while($result=$obj->fetchNextObject($check))
	    {
	       
	           $section=getSection($result->cat_id); 
	           if($section==1)
	           {
	                $section='grocery';
             $parameter='grocery-store-product';
             clearlaravelcache($section,$parameter);
	           }
	    }
		$sql="update $tbl_product set status=1 where id in ($str_rest_refs)";
		$obj->query($sql);
		$sess_msg='Selected record(s) activated successfully';
		$_SESSION['sess_msg']=$sess_msg;
	}
	elseif($Submit=='Deactivate')
	{		
	     $check=$obj->query("select cat_id from $tbl_product where id in ($str_rest_refs)");
	    while($result=$obj->fetchNextObject($check))
	    {
	       
	           $section=getSection($result->cat_id); 
	           if($section==1)
	           {
	                $section='grocery';
             $parameter='grocery-store-product';
             clearlaravelcache($section,$parameter);
	           }
	    }
	    
		 $sql="update $tbl_product set status=0 where id in ($str_rest_refs)";
		$obj->query($sql);
		$sess_msg='Selected record(s) deactivated successfully';
		$_SESSION['sess_msg']=$sess_msg;
	}
		
	}
	
else{
	$sess_msg="Please select check box";
	$_SESSION['sess_msg']=$sess_msg;
	header("location: ".$_SERVER['HTTP_REFERER']);
	exit();
	}
	header("location: product-list.php");
	exit();
	
?>
