<?php date_default_timezone_set('ASIA/Kuala_Lumpur'); 
	//sendMessage3(26236173,date('Y-m-d').' '.date('H:ia'));
	$getRoomId = $_GET['room'];
?>
        <!-- page content -->
        <div class="right_col" role="main">
          <div class="">
            <div class="page-title">
              <div class="title_left">
                <h3>Room List</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>ITEMS</h2>
                    <div class="clearfix"></div>
                  </div>
                  <div class="x_content">
					  <?php
							$result = mysqli_query($conn,"SELECT * FROM rooms WHERE r_status=1");
							while($row = mysqli_fetch_assoc($result)){
                                if(filterRoomAdmin($row['r_id'],$_SESSION['admin'][0])==true){continue;};
                                ?>
								
					  				<a class="col-xs-10" href="?pagecontent=room_item&room=<?php echo $row['r_id']; ?>"><button class="btn btn-primary btn-block"><?php echo getDetailByTable('properties',$row['p_id'])['pty_code']; ?> <?php echo $row['r_no']; ?></button></a>
						<?php	} ?>
                  </div>
                </div>
              </div>

				
            </div>
          </div>
        </div>
        <!-- /page content -->
<?php

	if(isset($_REQUEST['item'])){
		
		$getItemId = $_GET['item'];
		
		$adminId = $_SESSION['admin'][0] ?: 0;
		$staffId = $_SESSION['staff']['s_id'] ?: 0;
		
		mysqli_query($conn,"DELETE FROM room_item WHERE r_id=$getRoomId AND i_id=$getItemId");
		mysqli_query($conn,"INSERT INTO room_item (r_id,i_id,s_id,a_id) VALUES ($getRoomId,$getItemId,$staffId,$adminId)");
		
		header("Location: ?pagecontent=room_item&room=$getRoomId");
		telegramItemUpdate();
	}

	if(isset($_REQUEST['remove'])){
		$getRoomItemId = $_GET['remove'];
		mysqli_query($conn,"DELETE FROM room_item WHERE ri_id=$getRoomItemId");
		header("Location: ?pagecontent=room_item&room=$getRoomId");
		telegramItemUpdate();
	}

	if(isset($_REQUEST['add'])){
		$getRoomItemId = $_GET['add'];
		$getPc = $_GET['pc'];
		$pcToUpdate = $getPc + 1;
		
		mysqli_query($conn,"UPDATE room_item SET ri_pc=$pcToUpdate WHERE ri_id=$getRoomItemId");
		header("Location: ?pagecontent=room_item&room=$getRoomId");
		telegramItemUpdate();
	}

	if(isset($_REQUEST['sub'])){
		$getRoomItemId = $_GET['sub'];
		$getPc = $_GET['pc'];
		$pcToUpdate = $getPc - 1;
		
		mysqli_query($conn,"UPDATE room_item SET ri_pc=$pcToUpdate WHERE ri_id=$getRoomItemId");
		header("Location: ?pagecontent=room_item&room=$getRoomId");
		telegramItemUpdate();
	}

function isItemSelected($room,$item){ global $conn;
	$result = mysqli_query($conn,"SELECT * FROM room_item WHERE r_id=$room AND i_id=$item");
	return mysqli_fetch_array($result);
}
?>