<?php 
  date_default_timezone_set('ASIA/Kuala_Lumpur');
  $_GET['date'] ? $getDate = $_GET['date'] : header("Location: ?pagecontent=housekeep_cleaning_list&date=".date("Y-m-d"));
?>
        <!-- page content -->
        <div class="right_col" role="main">
          <div class="">
            <div class="page-title">
              <div class="title_left">
                <h3>Housekeeping Schedule - <?php echo $getDate; ?></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>ACTION</h2>
                    <div class="clearfix"></div>
                  </div>
                  <div class="x_content">
					 
					  	<a href="?pagecontent=housekeep_cleaning_list&refresh=y&date=<?php echo $getDate; ?>"><button class="btn btn-primary btn-block">REFRESH FOR TODAY</button></a>
					  
					  	<a href="?pagecontent=housekeep_cleaning_list&refresh=y&date=<?php echo addDaysToDate($getDate,1,"+"); ?>"><button class="btn btn-primary btn-block">REFRESH FOR <?php echo addDaysToDate($getDate,1,"+"); ?></button></a>
					  
                  </div>
					
                  <div class="x_title">
                    <h2>PENDING</h2>
                    <div class="clearfix"></div>
                  </div>
                  <div class="x_content">
					  <?php
					  	$result = mysqli_query($conn,"SELECT * FROM housekeep AS HK LEFT JOIN rooms AS R ON HK.r_id=R.r_id WHERE HK.hk_date='$getDate' AND HK.hk_status<9 ORDER BY R.p_id ASC, R.r_no ASC");
					  while($row = mysqli_fetch_assoc($result)){
					  ?>
					  	<a href="?pagecontent=housekeep_cleaning_update&hk=<?php echo $row['hk_id']; ?>"><button class="btn <?php if($row['hk_start'] == NULL){echo "btn-primary";}else{echo "btn-success";} ?> btn-block"><?php echo getDetailFromTable('properties',getDetailFromTable('rooms',$row['r_id'])['p_id'])['pty_code']." ".getDetailByTable('rooms',$row['r_id'])['r_no']; ?></button></a>
					  <?php } ?>
                  </div>
					
                  <div class="x_title">
                    <h2>COMPLETED</h2>
                    <div class="clearfix"></div>
                  </div>
                  <div class="x_content">
					  <?php
					  	$result = mysqli_query($conn,"SELECT * FROM housekeep AS HK LEFT JOIN rooms AS R ON HK.r_id=R.r_id WHERE HK.hk_date='$getDate' AND HK.hk_status>8 ORDER BY R.p_id ASC, R.r_no ASC");
					  while($row = mysqli_fetch_assoc($result)){
					  ?>
					  	<a href="?pagecontent=housekeep_cleaning_update&hk=<?php echo $row['hk_id']; ?>"><button class="btn btn-default btn-block"><?php echo getDetailFromTable('properties',getDetailFromTable('rooms',$row['r_id'])['p_id'])['pty_code']." ".getDetailByTable('rooms',$row['r_id'])['r_no']; ?></button></a>
					  <?php } ?>
                  </div>

                  <div class="x_title">
                    <h2>IMCOMPLETED</h2>
                    <div class="clearfix"></div>
                  </div>
                  <div class="x_content">
					  <?php
					  	$result = mysqli_query($conn,"SELECT * FROM housekeep AS HK LEFT JOIN rooms AS R ON HK.r_id=R.r_id WHERE HK.hk_date<'$getDate' AND HK.hk_status<9 ORDER BY R.p_id ASC, R.r_no ASC");
					  while($row = mysqli_fetch_assoc($result)){
					  ?>
					  	<a href="?pagecontent=housekeep_cleaning_update&hk=<?php echo $row['hk_id']; ?>"><button class="btn btn-danger btn-block"><?php echo getDetailFromTable('properties',getDetailFromTable('rooms',$row['r_id'])['p_id'])['pty_code']." ".getDetailByTable('rooms',$row['r_id'])['r_no']; ?></button></a>
					  <?php } ?>
                  </div>

                </div>
              </div>
            </div>
          </div>
        </div>
        <!-- /page content -->
<?php
	if(isset($_REQUEST['status'])){
		$housekeepId = $_GET['hk'];
		$status = $_GET['status'];
		
		$currentDateTime = date('Y-m-d H:i:s');
		if($status==8){
			mysqli_query($conn,"UPDATE housekeep SET hk_start='$currentDateTime' WHERE hk_id=$housekeepId");
		}
		if($status==11){
			mysqli_query($conn,"UPDATE housekeep SET hk_end='$currentDateTime' WHERE hk_id=$housekeepId");
		}
		
		mysqli_query($conn,"UPDATE housekeep SET hk_status=$status WHERE hk_id=$housekeepId");
		
		header("Location: ?pagecontent=cleaninglist&date=$getDate");
		
		telegramHousekeepingUpdate($getDate);
	}

	if(isset($_REQUEST['refresh'])){
		
		if(isMobile()){
			header("Location: https://t.me/joinchat/P-rPsh1-1VUJBji3");}else{
			header("Location: ?pagecontent=cleaninglist&date=$getDate");}
		
		telegramHousekeepingUpdate($getDate);
	}
?>