<?php
 require "../commonincludefiles.php";

// The ext grid script will send  a task field which will specify what it wants to do
$task = '';
if (isset($_POST['task'])){
	$task = $_POST['task'];
}

$IssueDetail_Ids = $_POST['ids1'];
$Book_Ids = $_POST['ids2'];
$Issue_Ids = $_POST['ids3'];

$deleteIssue_Id = 0;
$deleteIssueDetail_Id = 0;
$updateBook_Id = 0;

$deleteIssue_Id = json_decode(stripslashes($Issue_Ids));
$deleteIssueDetail_Id = json_decode(stripslashes($IssueDetail_Ids));
$updateBook_Id = json_decode(stripslashes($Book_Ids));

if(sizeof($deleteIssue_Id<1 && $deleteIssueDetail_Id)<1 && sizeof($updateBook_Id)<1){
	echo '0';
}
else{
	/** Update Book Available **/
	$objBookMgmt = new BookMgmt();
	$objBookMgmt->book_available = "1";
	$objBookMgmt->book_id = implode(",",$updateBook_Id);
	$objBookMgmt->edit_availabelbook();

	$objIssueMgmt = new IssueMgmt();
	$objIssueDetailMgmt = new IssueDetailMgmt();
	
	$issue_ids = implode(",",$deleteIssue_Id);
	
	$condition = " AND issue_id in ($issue_ids) ";
	$count_issue_id = $objIssueDetailMgmt->getCountRecords(0,0,$condition,"","");
	
	if($count_issue_id > 1 && $count_issue_id != count($deleteIssueDetail_Id)){
		$objIssueDetailMgmt->deletissuedetail_Id = implode(",",$deleteIssueDetail_Id);
		$objIssueDetailMgmt->delete();
	}
	else{
		$objIssueMgmt->deletissue_Id = implode(",",$deleteIssue_Id);
		$objIssueDetailMgmt->deletissuedetail_Id = implode(",",$deleteIssueDetail_Id);

		$objIssueMgmt->delete();
		$objIssueDetailMgmt->delete();
	}
	echo '1';
}        
?>