<?php
	$id = $_GET['gid'];
	$result = mysqli_query($conn,"SELECT * FROM guest WHERE g_id=$id");
	$row = mysqli_fetch_array($result);
?>

<div class="right_col" role="main">
    <div class="">
        <div class="row">
            <div class="col-md-12 col-sm-12 col-xs-12">
                <div class="x_panel">
					<div class="x_title">
						<h2>Reservation</h2>
						<div class="clearfix"></div>
					</div>
					<div class="x_content">
						<form class="form-horizontal form-label-left" method="post">
							<div class="form-group">
								<label class="control-label col-md-3 col-sm-3 col-xs-12">Guest Name</label>
								<div class="col-md-6 col-sm-6 col-xs-12">
									<input id="guestname" class="form-control col-md-7 col-xs-12" name="guestname" type="text" value="<?php echo $row['g_full_name'];?>" disabled>
								</div>
							</div>
							<div class="form-group">
								<label class="control-label col-md-3 col-sm-3 col-xs-12">Room No</label>
								<div class="col-md-6 col-sm-6 col-xs-12">
									<select class="form-control" name="roomno">
										<option>Choose option</option>
										<?php
											$result=mysqli_query($conn, "SELECT * FROM room") or die (mysql_error());
											while($row = mysqli_fetch_array($result))
											{
										?>
										<option value="<?php echo $row['r_id'];?>"><?php echo $row['r_no'];?></option>
										<?php
											}
										?>
									</select>
								</div>
							</div>
							<div class="item form-group">
								<label class="control-label col-md-3 col-sm-3 col-xs-12" for="">Check In Date
								</label>
								<div class="col-md-4 col-sm-3 col-xs-12">
									<?php $today= date("Y-m-d");?>
									<input id="night" class="form-control col-md-4 col-xs-12" name="checkindate" type="date" value="<?php echo $today;?>">
								</div>
							</div>
							<div class="clearfix"></div>
							
							<!-- 
							<div class="item form-group">
								<label class="control-label col-md-3 col-sm-3 col-xs-12" for="checkintime">Check In Time
								</label>
								<div class='col-sm-4'>
									<div class="form-group">
										<div class='input-group date' id='myDatepicker3'>
											<input type='text' class="form-control" name="checkintime" value="3:00 PM" />
											<span class="input-group-addon">
												<span class="glyphicon glyphicon-calendar"></span>
											</span>
										</div>
									</div>
								</div>
							</div>
							-->
							
							<div class="item form-group">
								<label class="control-label col-md-3 col-sm-3 col-xs-12" for="night">Nights <span class="required">*</span>
								</label>
								<div class="col-md-3 col-sm-3 col-xs-12">
									<input id="night" class="form-control col-md-3 col-xs-12" name="night" type="number" value="1">
								</div>
							</div>
							
							<!-- 
							<div class="item form-group">
								<label class="control-label col-md-3 col-sm-3 col-xs-12" for="">Check Out Date
								</label>
								<div class="col-md-4 col-sm-3 col-xs-12">
									<input id="night" class="form-control col-md-4 col-xs-12" name="checkoutdate" type="date" value="<?php echo $today;?>">
								</div>
							</div>
							<div class="item form-group">
								<label class="control-label col-md-3 col-sm-3 col-xs-12" for="checkouttime">Check Out Time
								</label>
								<div class='col-sm-4'>
									<div class="form-group">
										<div class='input-group date' id='myDatepicker31'>
											<input type='text' class="form-control" name="checkouttime" value="12:00 PM"/>
											<span class="input-group-addon">
												<span class="glyphicon glyphicon-calendar"></span>
											</span>
										</div>
									</div>
								</div>
							</div>
							-->
							
							<div class="item form-group">
								<label class="control-label col-md-3 col-sm-3 col-xs-12" for="amount">Amount (RM) <span class="required">*</span>
								</label>
								<div class="col-md-6 col-sm-6 col-xs-12">
									<input id="name" class="form-control col-md-7 col-xs-12" name="amount"  placeholder="rate per night" type="text" value="130" required>
								</div>
							</div>
							<div class="item form-group">
								<label class="control-label col-md-3 col-sm-3 col-xs-12" for="tax">Tax (%) <span class="required">*</span>
								</label>
								<div class="col-md-6 col-sm-6 col-xs-12">
									<input id="name" class="form-control col-md-7 col-xs-12" name="tax" type="text" value="0" required>
								</div>
							</div>
							<div class="item form-group">
								<label class="control-label col-md-3 col-sm-3 col-xs-12" for="tax">Service Tax (%) <span class="required">*</span>
								</label>
								<div class="col-md-6 col-sm-6 col-xs-12">
									<input id="name" class="form-control col-md-7 col-xs-12" name="tax" type="text" value="0" required>
								</div>
							</div>
						<!--<div class="item form-group">
								<label class="control-label col-md-3 col-sm-3 col-xs-12" for="total">Total <span class="required">*</span>
								</label>
								<div class="col-md-6 col-sm-6 col-xs-12">
									<input id="name" class="form-control col-md-7 col-xs-12" name="total" type="text" value="" required>
								</div>
							</div>-->
							<div class="item form-group">
								<label class="control-label col-md-3 col-sm-3 col-xs-12" for="reservationbooking">Booking
								</label>
								<div class="col-md-6 col-sm-6 col-xs-12">
									<select class="form-control" name='reservationbooking'>
										<option value="1" checked>Booking.com</option>
										<option value="2">Airbnb</option>
										<option value="0" selected>Directed</option>
									</select>
								</div>
							</div>
							<div class="item form-group">
								<label class="control-label col-md-3 col-sm-3 col-xs-12" for="note">Note</span>
								</label>
								<div class="col-md-6 col-sm-6 col-xs-12">
									<textarea id="message" class="form-control" name="note"></textarea>
								</div>
							</div>
						<!--<div class="item form-group">
								<label class="control-label col-md-3 col-sm-3 col-xs-12" for="reservationstatus">Status
								</label>
								<div class="col-md-6 col-sm-6 col-xs-12">
									<select class="form-control" name='reservationstatus'>
										<option>Choose option</option>
										<option value="0">New</option>
										<option value="1">Pending</option>
										<option value="2">Confirmed</option>
										<option value="3">Arrived</option>
										<option value="4">No Show</option>
										<option value="5">Checkout</option>
									</select>
								</div>
							</div>-->
							<div class="ln_solid"></div>
							<div class="form-group">
								<div class="col-md-6 col-md-offset-3">
									<button id="send" type="submit" class="btn btn-success" name="submit">Submit</button>
									<button type="reset" class="btn btn-primary" onclick="javascript:window.location='index.php?pagecontent=dashboard'">Cancel</button>
								</div>
							</div>
						</form>
					</div>
                </div>
            </div>
        </div>
    </div>
</div>

<?php 
	if(isset($_POST['submit']))
	{
	    $reservationNo = date(Ymdhis); //reservation no obtained by date & time
	/*	$guestid=$_POST['guestname'];*/
		$roomno=$_POST['roomno'];
		$checkindate=$_POST['checkindate'];
		$checkintime=$_POST['checkintime'];
		$night=$_POST['night'];
		$checkoutdate=$_POST['checkoutdate'];
		$checkouttime=$_POST['checkouttime'];
		$amount=$_POST['amount'];
		$tax=$_POST['tax'];
	/*	$total=$_POST['total'];*/
		$booking=$_POST['reservationbooking'];
		$note=$_POST['note'];
	/*	$status=$_POST['reservationstatus'];*/
		
		mysqli_query($conn, "INSERT INTO reservation (rv_no, g_id, r_id, rv_ci_date, rv_night, rv_amount, rv_tax, 
		rv_booking, rv_notes) VALUES ('$reservationNo', '$id', '$roomno', '$checkindate', $night, $amount, $tax, 
		'$booking', '$note')") or die (mysql_error());
		
		header('Location: index.php?pagecontent=guestid&id='.$id);  
	}

?>

