<div class="right_col" role="main">
	<div class="">
		<div class="page-title">
			<div class="title_left">
				<table>
					<tr>
						<td width="200px"><h3>Reservation List</h3></td>
						<td>
							<a href="index.php?pagecontent=reservation_new"><button type="button" class="btn btn-dark">Add Reservation</button></a>
							<a href="index.php?pagecontent=reservation_list&date=today"><button type="button" class="btn btn-dark">Today</button></a>
						</td>
				</table>
			</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_content">
						<table id="datatable" class="table table-striped table-bordered">
							<thead>
								<tr>
								    <th>Reservation</th>
									<th>Guest</th>
									<th>Room</th>
									<th>Check In</th>
									<th>Night</th>
									<th>Check Out</th>
									<th>Total</th>
									<th>Status</th>
									<th>Action</th>
								</tr>
							</thead>
							<tbody>
								<?php
									$result=mysqli_query($conn, "SELECT * FROM reservation as RV LEFT JOIN room as R ON RV.r_id=R.r_id
									LEFT JOIN users as U ON RV.u_id=U.u_id") or die (mysql_error());
									
									while($row = mysqli_fetch_array($result))
									{
								?>
								<tr>
								    <td><a href="index.php?pagecontent=reservation_view&rvid=<?php echo $row['rv_id']; ?>">20190201001SAMPLE</a></td>
									<td width=""><a href="index.php?pagecontent=guestid&id=<?php echo $row['u_id'];?>"><?php echo $row['u_fullname'];?></a></td>
									<td><?php echo $row['r_no'];?></td>
									<td><?php echo $row['rv_ci_date'];?></br><?php echo $row['rv_ci_time'];?></td>
									<td><?php echo $row['rv_night'];?></td>
									<td><?php echo $row['rv_co_date'];?></br><?php echo $row['rv_co_time'];?></td>
									<td>RM <?php $night = $row['rv_night'];
									          $amount = $row['rv_amount'];
									          $tax = $row['rv_tax'];
									          echo number_format($total = (($amount * $night) * (1.0 + ($tax / 100))),2)
									   ;?></td>
									<td><?php	switch($row['rv_status'])
															{
																case 0: echo '<span style="color:purple;font-weight:bold;">New</span>';
																break;
																case 1: echo '<span style="color:orange;font-weight:bold;">Pending</span>';
																break;
																case 2: echo '<span style="color:lime;font-weight:bold;">Confirmed</span>';
																break;
																case 3: echo '<span style="color:green;font-weight:bold;">Arrived</span>';
																break;
																case 4: echo '<span style="color:red;font-weight:bold;">No Show</span>';
																break;
																default: echo '<span style="color:blue;font-weight:bold;">Check Out</span>';
															}
													;?></td>
									<td>
										<a href="?pagecontent=reservation_update&id=<?php echo $row['rv_id']; ?>"><button class="btn btn-xs btn-primary">Update</button></a>
										
										<a href="?pagecontent=reservation_list&remove=<?php echo $row['rv_id']; ?>"><button class="btn btn-xs btn-danger">Remove</button></a>
									</td>
								</tr>
								<?php
									}
								?>
						</table>
					</div>
				</div>
			</div>
        </div>
    </div>
</div>

<?php
	if(isset($_REQUEST['remove'])){
		$reservationID = $_REQUEST['remove'];
		
		mysqli_query($conn, "DELETE FROM reservation WHERE rv_id=$reservationID");
		
		header('Location: index.php?pagecontent=reservation_list');
	}

	if(isset($_REQUEST['rvstatusn'])){
		
		$id=$_REQUEST['rvstatusn'];
		
		mysqli_query($conn,"UPDATE reservation SET rv_status=0 WHERE rv_id=$id") or die (mysql_error());
		
		header('Location: index.php?pagecontent=reservationlist');  
	}

	if(isset($_REQUEST['rvstatusp'])){
		
		$id=$_REQUEST['rvstatusp'];
		
		mysqli_query($conn,"UPDATE reservation SET rv_status=1 WHERE rv_id=$id") or die (mysql_error());
		
		header('Location: index.php?pagecontent=reservationlist');  
	}

	if(isset($_REQUEST['rvstatusc'])){
		
		$id=$_REQUEST['rvstatusc'];
		
		mysqli_query($conn,"UPDATE reservation SET rv_status=2 WHERE rv_id=$id") or die (mysql_error());
		
		header('Location: index.php?pagecontent=reservationlist');  
	}

	if(isset($_REQUEST['rvstatusa'])){
		
		$id=$_REQUEST['rvstatusa'];
		
		mysqli_query($conn,"UPDATE reservation SET rv_status=3 WHERE rv_id=$id") or die (mysql_error());
		
		header('Location: index.php?pagecontent=reservationlist');  
	}

	if(isset($_REQUEST['rvstatusns'])){
		
		$id=$_REQUEST['rvstatusns'];
		
		mysqli_query($conn,"UPDATE reservation SET rv_status=4 WHERE rv_id=$id") or die (mysql_error());
		
		header('Location: index.php?pagecontent=reservationlist');  
	}

	if(isset($_REQUEST['rvstatuco'])){
		
		$id=$_REQUEST['rvstatuco'];
		
		mysqli_query($conn,"UPDATE reservation SET rv_status=5 WHERE rv_id=$id") or die (mysql_error());
		
		header('Location: index.php?pagecontent=reservationlist');  
	}
?>