<?php
session_start(); 
		/*User Add Data page */

	
	if(!isset($_SESSION['linkarisecrm']))
	{
		header('Location: index.php');
		return;
	}
	
		$brmid=$_SESSION['linkarisebranchid'];
		$cmpmid=$_SESSION['linkarisecmpmid'];
	$umid = $_SESSION['linkariseumid'];

include("connect.php");
	date_default_timezone_set("Asia/Singapore");
	 $mdate1= date('Y-m-d');
// Prepare the SQL query to fetch events from the database
$sql = "SELECT * FROM res_booking_master,res_spot_master,res_slots_master where res_booking_master.spotmid=res_spot_master.spotmid and  res_booking_master.cmpmid=$cmpmid and res_booking_master.functionstartdate>='$mdate1' and res_booking_master.functionenddate>='$mdate1' and slotmid in (select slotmid from res_booking_detail where bookingmid=res_booking_master.bookingmid)";
$result = $conn->query($sql);

// Check if there are any results
if ($result->num_rows > 0) {
    $events = array();

    // Loop through the rows and fetch the event data
    while ($row = $result->fetch_assoc()) {
        $event = array(
            'id' => $row['bookingmid'],
            'title' =>$row['spotname']."-".explode(" ", $row['slotname'])[0],
            'start' => $row['functionstartdate'],
            'end' => $row['functionenddate']
        );

        // Add the event data to the events array
        $events[] = $event;
    }

    // Return the events as a JSON response
    header('Content-Type: application/json');
    echo json_encode($events);
} else {
    // No events found in the database
    header('Content-Type: application/json');
    echo json_encode(array());
}

// Close the database connection
$conn->close();
?>
