38960-vm/api/doctor_holidays.php
2026-03-22 10:04:41 +00:00

33 lines
948 B
PHP

<?php
require_once __DIR__ . '/../db/config.php';
require_once __DIR__ . '/../helpers.php';
// Prevent caching
header('Cache-Control: no-cache, no-store, must-revalidate');
header('Pragma: no-cache');
header('Expires: 0');
header('Content-Type: application/json');
$db = db();
$doctor_id = $_GET['doctor_id'] ?? null;
if (!$doctor_id) {
echo json_encode(['success' => false, 'error' => 'Missing doctor_id']);
exit;
}
try {
// $doctor_id is expected to be employee_id now
$stmt = $db->prepare("
SELECT start_date, end_date, reason
FROM leave_requests
WHERE employee_id = ? AND status = 'Approved' AND end_date >= CURDATE()
");
$stmt->execute([$doctor_id]);
$holidays = $stmt->fetchAll(PDO::FETCH_ASSOC);
echo json_encode(['success' => true, 'holidays' => $holidays]);
} catch (PDOException $e) {
echo json_encode(['success' => false, 'error' => 'DB Error: ' . $e->getMessage()]);
}