	<?php include ('header.php'); ?>

        <div class="page-title">
            <div class="title_left">
                <h3>
					<small>Home /</small> Returned Book Reports
                </h3>
            </div>
        </div>
        <div class="clearfix"></div>
 
        <div class="row">
            <div class="col-md-12 col-sm-12 col-xs-12">
                <div class="x_panel">
                    <div class="x_title">
                        <h2><i class="fa fa-file"></i> Returned Book Report</h2>
                        
						
                        <div class="clearfix"></div>
						
						<?php
							$user_result= mysqli_query($conn,"select * from report 
							LEFT JOIN book ON report.book_id = book.book_id 
							LEFT JOIN user ON report.user_id = user.user_id 
							where report.detail_action='Returned Book' group by user.user_id order by report.report_id DESC ") or die (mysqli_error());
							
							?>
						
						<form method="POST" action="return_book_report_by_name.php" class="form-inline">
                               
                                <div class="control-group">
                                    <div class="controls">
                                        <div class="col-md-4">
											<select class="form-control" name="status" style="color:black;">
												<option>---Choose Issued Name---</option>
												<?php 
												while ($row= mysqli_fetch_array ($user_result) ){
												$id=$row['report_id'];
												$book_id=$row['book_id'];
												$user_name=$row['firstname']." ".$row['middlename']." ".$row['lastname'];
												$user_id = $row['user_id'];
												//echo "<pre>";print_r($row);
												?>
												<option value="<?php echo $user_id; ?>"><?php echo $user_name; ?></option>
												<?php } ?>
												
											</select>
                                        </div>
                                    </div>
                                </div>
								
								<button type="submit" name="search" class="btn btn-primary btn-outline"><i class="fa fa-calendar-o"></i> Search User</button>
								
						</form>
						
						<span style="float:left;">
					<?php 
				//	$count = mysql_fetch_array(mysql_query("SELECT COUNT(*) as total FROM `report`")) or die(mysql_error());
				//	$count1 = mysql_fetch_array(mysql_query("SELECT COUNT(*) as total FROM `report` WHERE `detail_action` = 'Borrowed Book'")) or die(mysql_error());
				//	$count2 = mysql_fetch_array(mysql_query("SELECT COUNT(*) as total FROM `report` WHERE `detail_action` = 'Returned Book'")) or die(mysql_error());
					?>
				<!---			<a href="report.php"><button class="btn btn-primary"><i class="fa fa-info"></i> All Reports <?php // echo $count['total']; ?></button></a>
							<a href="borrowed_report.php"><button class="btn btn-success btn-outline"><i class="fa fa-info"></i> Borrowed Reports (<?php //echo $count1['total']; ?>)</button></a>
							<a href="returned_report.php"><button class="btn btn-danger btn-outline"><i class="fa fa-info"></i> Returned Reports (<?php //echo $count2['total']; ?>)</button></a>
				-->
				</span>
                        <div class="clearfix"></div>
                    </div>
                    <div class="x_content">
                        <!-- content starts here -->

						<div class="table-responsive">
							
						<?php
							if(isset($_POST['search'])):
							$user_id = $_POST['status'];
							
							$user_status= mysqli_query($conn,"select * from user 
							where user_id='$user_id' order by user_id DESC ") or die (mysqli_error());
							$user_detail = mysqli_fetch_array ($user_status);

							$result= mysqli_query($conn,"select * from report 
							LEFT JOIN book ON report.book_id = book.book_id 
							LEFT JOIN user ON report.user_id = user.user_id 
							where report.detail_action='Returned Book' and user.user_id='$user_id' order by report.report_id DESC ") or die (mysqli_error());
							
							
							?>
							<table cellpadding="0" cellspacing="0" border="0" class="table table-striped table-bordered" id="example">
								<caption><strong>GP BLGR LIBRARY</strong></caption>
							<tbody>
							<tr>
								<td width="50%" colspan="2"><strong>Registration No:</strong> <?php echo $user_detail['school_number']; ?></td>
								
							</tr>
							<tr>
								<td colspan="2"><strong>Name:</strong> <?php echo $user_detail['firstname'].' '.$user_detail['middlename'].' '.$user_detail['lastname']; ?></td>
							</tr>
							<tr>
								<td colspan="2"><strong>Branch:</strong> <?php echo $user_detail['section']; ?></td>
							</tr>
							<?php while($row= mysqli_fetch_array ($result)){ ?>
							<tr>
								<td><strong>Book Name:</strong> <?php echo $row['book_title']; ?></td>
								<td><strong>Returned Date:</strong> <?php echo $row['date_transaction']; ?></td>
							</tr>
							<?php } ?>
							</tbody>
							<tfoot>
							<tr>
								<td>Signature of <br>Student:</td>
								<td>Signature of <br>Staff:</td>
							</tr>
								</tfoot>
							
							</table>
							<div class="print_btn">
								<form method="post" action="print_returned_book_name.php" target="_blank">
									<button class="btn btn-danger"><i class="fa fa-print"></i> Print Receipt</button>
								<input type="hidden" name="print_user_id" value="<?php echo $user_id; ?>">
								</form>
							</div>
							<?php else: ?>
							<table cellpadding="0" cellspacing="0" border="0" class="table table-striped table-bordered" id="example">
								<caption><strong>GP BLGR LIBRARY</strong></caption>
							<tbody>
								<td><center>No Result Found!</center></td>
								</tbody>
							</table>
							<?php endif; ?>
						</div>
						
                        <!-- content ends here -->
                    </div>
                </div>
            </div>
        </div>

<?php include ('footer.php'); ?>