<?php
require "../commonincludefiles.php";	
if($_SESSION["aCollegeId"]!="" && isset($_SESSION["aCollegeId"])){
	
		$condition ="";
		$bookreg_no	= 	Escape($_REQUEST['bookreg_no']); // for book
		$bookregid	 = 	Escape($_REQUEST['bookreg_id']);
		
		if($bookreg_no!=""){
			$condition .= " and book_registerno='$bookreg_no' ";
		}
		if($bookregid!=""){
			$condition .= " and book_registerid='$bookregid' ";
		}
		$count=0;
		$objBookMgmt=new BookMgmt();
		$out=$objBookMgmt->getAllRecords(1,0,$condition,"","");
		$count=dbRows($out);
		
		if($count > 0){
			while($row=dbArray($out)){
				$book_id = $row['book_id'];
				$book_name = $row['book_name'];
				$book_price = $row['book_price'];
				
			}
			dbResult($out);
			
		 	$condition ="";
			$condition .= " and lid.book_id='$book_id'";
			$condition .= " and lid.issue_isreturned = '0'";
			
			$objIssueMgmt = new IssueMgmt();	
			$out2 = $objIssueMgmt->getAllRecords(1,0,$condition,"","");
			
			if(dbRows($out2) > 0){
				
				$row2=dbArray($out2);
				
				extract($row2);
				
				if($_REQUEST['type'] == 'lost')
				{
				$str = "{success:true,data:{book_id:'".$book_id."',txtbookname:'".$book_name
					   ."',book_returnlastdate:'".FormatDate($issue_returnlastdate,'d/m/Y')
					   ."',bookissueno:'".$issuedetail_id
					   ."',fineamount:'".$book_price
					   ."',memberid1:'".$member_id
					   ."',issuedate:'".$issue_date;
				}
				else
				{
					$str = "{success:true,data:{book_id:'".$book_id."',txtbookname:'".$book_name
					   ."',book_returnlastdate:'".FormatDate($issue_returnlastdate,'d/m/Y')
					   ."',bookissueno:'".$issuedetail_id
					   ."',memberid1:'".$member_id
					   ."',issuedate:'".$issue_date;
				}
				if($member_type==1){ // student
					$objMemberMgmt = new MemberMgmt();
					$limit=0;
					$start=0;
					$condition=" AND student_id = '$member_id' ";
					$order_field="";
					$order_type="";
					$outMember = $objMemberMgmt->getStudentRecords($limit,$start,$condition,$order_field,$order_type);
					if(dbRows($outMember) >0) {
						$row=dbArray($outMember);
						extract($row);
						$str .= "',membername:'".$student_surname." ".$student_firstname." ".$student_lastname
					   		."',memberid:'".$student_grno 
					   		."'}}";						
					}else {
						$str .= "',membername:'',memberid:''}}";						
					}
					echo $str;					
				}
				else if($member_type==2){ // employee
					$objMemberMgmt = new MemberMgmt();
					$limit=0;
					$start=0;
					$condition=" AND employee_id = '$member_id' ";
					$order_field="";
					$order_type="";
					$outMember= $objMemberMgmt->getEmployeeRecords($limit,$start,$condition,$order_field,$order_type);
					if(dbRows($outMember) >0) {
						$row=dbArray($outMember);
						extract($row);
						$str .= "',membername:'".$employee_name
					   		."',memberid:'".$employee_id
					   		."'}}";
					}else {
						$str .= "',membername:'',memberid:''}}";						
					}
					echo $str;
				}
				else if($member_type==3){ // Other
				
				    $objMemberMgmt = new MemberMgmt();
					$limit=0;
					$start=0;
					$condition=" AND member_id = '$member_id' ";
					$order_field="";
					$order_type="";
					$outMember= $objMemberMgmt->getAllRecords($limit,$start,$condition,$order_field,$order_type);
					if(dbRows($outMember) >0) {
						$row=dbArray($outMember);
						$member_name=$row['member_name'];
					 }
					
					echo "{success:true,data:{book_id:'".$book_id."',txtbookname:'".$book_name
					   ."',book_returnlastdate:'".FormatDate($issue_returnlastdate,'d/m/Y')
					   ."',bookissueno:'".$issuedetail_id
					   ."',issuedate:'".$issue_date
					   ."',membername:'".$member_name
					   ."',memberid:'".$member_id
					   ."'}}";
					  
				}	
				
				dbResult($out2);	
				
			}
			else {
				echo '{"success":"false","msg":"1"}';
			}
		}
		else{
			echo '{"success":"false","msg":"2"}';
		}
	}
?>