<?php
require "../commonincludefiles.php";
$task = '';
if ( isset($_POST['task'])){
	$task = $_POST['task'];
}
switch($task){
    case "LISTING":
        getList();
        break;
    case "DELETESTU":
        deletePresidents();
        break;
    default:
        echo "{failure:true}";
        break;
}
function deletePresidents(){
   	
	////
	$Member_Ids = $_POST['ids'];
	$deleteMember_Id = json_decode(stripslashes($Member_Ids)); 
	
	if(sizeof($deleteMember_Id)<1){
	  	echo '0';
    } else{
	
		$deleteMember_Id = implode(",",$deleteMember_Id);
		$str_issueid = "";
		$str_bookid = "";
	
		$qry1 = "select group_concat(issue_id) AS issue_id from lms_issuemaster where member_id in ($deleteMember_Id) And school_id='".$_SESSION["aCollegeId"]."'";
		$result_issueid = dbQuery($qry1);
		if(dbRows($result_issueid) > 0){
			$record = dbArray($result_issueid);
			$str_issueid = $record['issue_id'];
			if($str_issueid != ""){
				$qry2 = "select group_concat(book_id) AS book_id from lms_issuedetail where issue_isreturned = '0' AND issue_id in ($str_issueid) AND school_id='".$_SESSION["aCollegeId"]."'";
				$result_bookid = dbQuery($qry2);
				if(dbRows($result_bookid) > 0){
					$record = dbArray($result_bookid);
					$str_bookid = $record['book_id'];
					
					$qry3 = "UPDATE lms_bookmaster SET book_available = '1' WHERE book_id in ($str_bookid) And school_id='".$_SESSION["aCollegeId"]."'";
					dbQuery($qry3);
				}
			}
		}
		
		$qry4 = "delete from lms_membermaster where member_id in ($deleteMember_Id) And school_id='".$_SESSION["aCollegeId"]."'";
		dbQuery($qry4);	

		if($str_issueid != ""){		
			$qry5 = "delete from lms_issuemaster where issue_id in ($str_issueid) And school_id='".$_SESSION["aCollegeId"]."'";
			dbQuery($qry5);
			$qry6 = "delete from lms_issuedetail where issue_id in ($str_issueid) And school_id='".$_SESSION["aCollegeId"]."'";
			dbQuery($qry6);
		}
		echo '1';
	}
	////
}
?> 