78 lines
2.8 KiB
PHP
78 lines
2.8 KiB
PHP
<?php
|
|
require_once '../includes/db_intranet.php';
|
|
|
|
header('Content-Type: application/json');
|
|
|
|
if (!$intranet_pdo) {
|
|
echo json_encode([]);
|
|
exit;
|
|
}
|
|
|
|
$start = $_GET['start'] ?? '';
|
|
$end = $_GET['end'] ?? '';
|
|
|
|
try {
|
|
$sql = "SELECT * FROM booking_car";
|
|
$params = [];
|
|
|
|
if ($start && $end) {
|
|
$sql .= " WHERE booking_car_request_date_start >= ? AND booking_car_request_date_start <= ?";
|
|
$params = [
|
|
date('Y-m-d', strtotime($start)),
|
|
date('Y-m-d', strtotime($end))
|
|
];
|
|
}
|
|
|
|
$stmt = $intranet_pdo->prepare($sql);
|
|
$stmt->execute($params);
|
|
$bookings = $stmt->fetchAll();
|
|
|
|
$events = [];
|
|
foreach ($bookings as $b) {
|
|
$statusText = trim($b['booking_car_request_status'] ?? '');
|
|
$area = trim($b['booking_car_request_area'] ?? '');
|
|
$color = '#3b82f6'; // blue-500 (ในสมุย)
|
|
|
|
if ($area === 'นอกเกาะสมุย') {
|
|
$color = '#f97316'; // orange-500 (นอกสมุย)
|
|
}
|
|
|
|
$startTime = !empty($b['booking_car_request_time_start']) ? $b['booking_car_request_time_start'] : '00:00:00';
|
|
$endTime = !empty($b['booking_car_request_time_end']) ? $b['booking_car_request_time_end'] : '23:59:59';
|
|
|
|
$startDate = $b['booking_car_request_date_start'];
|
|
$endDate = !empty($b['booking_car_request_date_end']) ? $b['booking_car_request_date_end'] : $startDate;
|
|
|
|
$currentDate = $startDate;
|
|
while (strtotime($currentDate) <= strtotime($endDate)) {
|
|
$events[] = [
|
|
'id' => $b['booking_car_id'] . '_' . $currentDate,
|
|
'title' => $title,
|
|
'start' => $currentDate . 'T' . $startTime,
|
|
'end' => $currentDate . 'T' . $endTime,
|
|
'backgroundColor' => 'transparent',
|
|
'borderColor' => 'transparent',
|
|
'extendedProps' => [
|
|
'iconColor' => $color,
|
|
'name' => $b['booking_car_request_name'],
|
|
'phone' => $b['booking_car_request_phone'],
|
|
'purpose' => $b['booking_car_request_title'],
|
|
'type' => $b['booking_car_request_type'],
|
|
'status' => $statusText,
|
|
'station' => $b['booking_car_request_station'],
|
|
'desc' => $b['booking_car_request_description'],
|
|
'link' => $b['booking_car_request_link_view'],
|
|
'date' => date('d/m/', strtotime($currentDate)) . (date('Y', strtotime($currentDate)) + 543) . ($startTime != '00:00:00' ? ' ' . date('H:i', strtotime($startTime)) : '')
|
|
]
|
|
];
|
|
$currentDate = date('Y-m-d', strtotime($currentDate . ' +1 day'));
|
|
}
|
|
}
|
|
|
|
echo json_encode($events);
|
|
|
|
} catch (PDOException $e) {
|
|
echo json_encode([]);
|
|
}
|
|
?>
|