<?php
session_start(); 

	if(!isset($_SESSION['tulsilogin']))
	{
		header('Location: index.php');
		return;
	}
	$usermid = $_SESSION['umid'];

	
include("connect.php");
	
	date_default_timezone_set("Asia/Kolkata");
	$mdate= date('Y-m-d H:i:s');

	
	$bidid=$_GET['id'];
	
	
	
		$_SESSION['msg'] = "Book Returned Successfull";
		
	    $eve2 = "update res_bookissue_detail set ibstatus='Lost',biupdatedon='$mdate',biupdatedby=$usermid where bidid=$bidid";
		$re2 = mysqli_query($conn, $eve2);
		
		$eve4 = "select * from res_bookissue_detail,res_book_master where res_book_master.bookmid= res_bookissue_detail.bookmid and res_bookissue_detail.bidid=$bidid";
						$re4 = mysqli_query($conn, $eve4);
						while($rt4 = mysqli_fetch_assoc($re4))
						{
						
							$stiqmid=$rt4['stiqmid'];
							$bookmid=$rt4['bookmid'];
							$bookprice=$rt4['bookprice'];
						}
						$imid=0;
						$eve2 = "select imid from res_studentinquiry_detail where stiqmid=$stiqmid";
	$re2 = mysqli_query($conn, $eve2);
	while($rt2 = mysqli_fetch_assoc($re2))

	{
		$imid = $rt2['imid'];
	}
						$ptype = 'Book Lost';
						
						 $eve2 = "insert into res_inquiryservice_detail (imid,isaddedby,isaddedon,isupdatedby,isupdatedon,stiqmid,ispendingamount,packagefees,servicefinalrate,spaymenttype,servicepayamount,linkmid,ptype) values ($imid,$usermid,'$mdate',$usermid,'$mdate','$stiqmid','$bookprice','$bookprice','$bookprice','Full Payment','$bookprice','$bookmid','$ptype')";

	if ($conn->query($eve2) === TRUE)
	{
		$isdid = $conn->insert_id;
		 $eve1 = "INSERT INTO res_payments_detail (imid,isdid, paidamount,pdaddedon,pdaddedby,pdupdatedon,pdupdatedby,paycurrency,paycurrencyvalue) VALUES('$imid','$isdid','$bookprice','$mdate','$usermid','$mdate','$usermid','INR','$bookprice')";
		
		$re1 = mysqli_query($conn, $eve1);
	}
		
			
		header("Location: coachinginquirydetail.php?id=$stiqmid");
		
		
		
		
		
		
			
		
		

?>	