<?php

include_once ("includes/setup.inc.php");
//Header("Content-type: application/xml");
Header("Cache-Control: no-cache");

$num_errors = 0;
$klinik = fetch_postget_val("klinik", $_POST, $_GET);
$start = fetch_postget_val("min", $_POST, $_GET);
$end = fetch_postget_val("max", $_POST, $_GET);
$dateTimeNow = dateTimeNow();

$slot_minute = 30;
$slot_seconds = $slot_minute * 60;

$indicator_Query = "SELECT m_vatklinik_appointment.*,  m_pemilik.nama_pemilik, m_pemilik.tel_pemilik, m_pemilik_pet.nama_pet, i_haiwan_peliharaan.desk_haiwan_peliharaan
					FROM m_vatklinik_appointment
					JOIN m_pemilik ON m_pemilik.id_pemilik = m_vatklinik_appointment.id_pemilik
					JOIN m_pemilik_pet ON m_pemilik_pet.id_pemilik_pet = m_vatklinik_appointment.id_pemilik_pet
					JOIN i_haiwan_peliharaan ON m_pemilik_pet.id_haiwan_peliharaan = i_haiwan_peliharaan.id_haiwan_peliharaan
					WHERE is_active AND id_vatklinik = ? AND appointment_date BETWEEN '$start' AND '$end'";
$PDO_stmt = $PDO->prepare($indicator_Query);
$PDO_stmt->bindValue(1, $klinik, PDO::PARAM_INT);
$PDO_stmt->execute();
$appointmentTime_List = [];
while($result = $PDO_stmt->fetch(PDO::FETCH_ASSOC))
{
	$end_datetime = date("Y-m-d H:i:s", strtotime($result['appointment_date'].' '.$result['appointment_time']) + $slot_seconds);

	$appointment = [];
	$appointment['title'] = $result['desk_haiwan_peliharaan'];
	$appointment['start'] = $result['appointment_date'].' '.$result['appointment_time'];
	$appointment['end'] = $end_datetime;
	$appointment['description'] = 'Pemilik : '.$result['nama_pemilik'].'<br>'.'Tel : '.$result['tel_pemilik'].'<br>'.'Nama Pet : '.$result['nama_pet'].'<br>';
	$appointment['className'] = "fc-event-light fc-event-solid-primary";
	$appointmentTime_List[] = $appointment;
}

echo json_encode($appointmentTime_List);
?>