<?php date_default_timezone_set('ASIA/Kuala_Lumpur');
$getReservationId = $_GET['id'];
?>
        <!-- page content -->
        <div class="right_col" role="main">
          <div class="">
            <div class="page-title">
              <div class="title_left">
                <h3><?php echo getDetailByTable('reservation',$getReservationId)['rv_guest']; ?> - Status</h3>
              </div>

            </div>

            <div class="clearfix"></div>

            <div class="row">

              <div class="col-md-6 col-sm-6 col-xs-12">
                <div class="x_panel">
                  <div class="x_title">
                    <h2>ENTRANCE</h2>
                    <div class="clearfix"></div>
                  </div>
                  <div class="x_content">
					  <a href="?pagecontent=reservation_status&id=<?php echo $getReservationId; ?>&status=0"><button class="btn btn-warning btn-block">PENDING</button></a>
					  
					  <a href="?pagecontent=reservation_status&id=<?php echo $getReservationId; ?>&status=1"><button class="btn btn-danger btn-block">CANCELLED</button></a>
					  
					  <a href="?pagecontent=reservation_status&id=<?php echo $getReservationId; ?>&status=2"><button class="btn btn-primary btn-block">CONFIRMED</button></a>
					  
					  <a href="?pagecontent=reservation_status&id=<?php echo $getReservationId; ?>&status=3"><button class="btn btn-danger btn-block">ARRIVING</button></a>
					  
					  <a href="?pagecontent=reservation_status&id=<?php echo $getReservationId; ?>&status=4"><button class="btn btn-danger btn-block">ARRIVED</button></a>
					  
					  <a href="?pagecontent=reservation_status&id=<?php echo $getReservationId; ?>&status=5"><button class="btn btn-success btn-block">CHECKED IN</button></a>
					  
					  <a href="?pagecontent=reservation_status&id=<?php echo $getReservationId; ?>&status=6"><button class="btn btn-primary btn-block">CHECKED OUT</button></a>
					  
					  <a href="?pagecontent=reservation_status&id=<?php echo $getReservationId; ?>&status=7"><button class="btn btn-success btn-block">COMPLETED</button></a>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
        <!-- /page content -->
<?php
	if(isset($_REQUEST['status'])){
		$reservationId = $_GET['id'];
		$status = $_GET['status'];
		$getDate = getDetailByTable('reservation',$reservationId)['rv_ci_date'];
		$nightNo = getDetailByTable('reservation',$reservationId)['rv_night'];
		$roomId = getDetailByTable('reservation',$reservationId)['r_id'];
		
		mysqli_query($conn,"UPDATE reservation SET rv_status=$status WHERE rv_id=$reservationId");
		
		//request for housekeeing next day
		if($roomId && $status>1){
			$adminId = isset($_SESSION['admin']['a_id']) ? $_SESSION['admin']['a_id'] : 0;
			$tomorrowDate = date('Y-m-d', strtotime($getDate." +".$nightNo." day"));
			mysqli_query($conn,"DELETE FROM housekeep WHERE rv_id=$reservationId");
			mysqli_query($conn,"INSERT INTO housekeep (r_id,rv_id,hk_date,a_id) VALUES ($roomId,$reservationId,'$tomorrowDate',$adminId)");		
		}else{
			mysqli_query($conn,"DELETE FROM housekeep WHERE rv_id=$reservationId");
		}
		
		//reservation log
		switch($status){
			case "0": $statusTitle = 'PENDING'; break;
			case "1": $statusTitle = 'CANCELLED'; break;
			case "2": $statusTitle = 'CONFIRMED'; break;
			case "3": $statusTitle = 'ARRIVING'; break;
			case "4": $statusTitle = 'ARRIVED'; break;
			case "5": $statusTitle = 'CHECKED IN'; break;
			case "6": $statusTitle = 'CHECKED OUT'; break;
			case "7": $statusTitle = 'COMPLETED'; break;
		}
		reservationLog($reservationId,$_SESSION['admin']['a_username']." update status to ".$statusTitle); //to be removed
		logs("Admin ".$_SESSION['admin']['a_username']." updates reservation status into ".$statusTitle,$reservationId);
		
		
		header('Location: ?pagecontent=reservation_communication&rv='.$reservationId);
		//header("Location: ?pagecontent=reservations&date=$getDate");
		
		if(date("Y-m-d")==$getDate){telegramHousekeepingUpdate($getDate);}

		telegramUpdateAvailability($getDate);
	}
?>