<?php
header('Access-Control-Allow-Origin: *');
header(
    'Access-Control-Allow-Methods: HEAD, GET, POST, PUT, PATCH, DELETE, OPTIONS'
);
header(
    'Access-Control-Allow-Headers: X-API-KEY, Origin, X-Requested-With, Content-Type, Accept, Access-Control-Request-Method,Access-Control-Request-Headers, Authorization'
);
header('Content-Type: application/json');
$method = $_SERVER['REQUEST_METHOD'];
if ($method == 'OPTIONS') {
    header('Access-Control-Allow-Origin: *');
    header(
        'Access-Control-Allow-Headers: X-API-KEY, Origin, X-Requested-With, Content-Type, Accept, Access-Control-Request-Method,Access-Control-Request-Headers, Authorization'
    );
    header('HTTP/1.1 200 OK');
    die();
}

include '../../../../config/db.php';
$data = [];
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
    $currentDate = Date('y:m:d', strtotime('+1 days'));
    $nextDate = Date('y:m:d', strtotime('+7 days'));
    $query = "SELECT * FROM Clock WHERE ClockDate BETWEEN '$currentDate' AND '$nextDate' ";
    if ($result = mysqli_query($con, $query)) {
        $i = 0;
        while ($rows = mysqli_fetch_assoc($result)) {
            $data[$i]['ClockId'] = $rows['ClockId'];
            $data[$i]['ClockDate'] = $rows['ClockDate'];
            $data[$i]['DayClockFrom'] = $rows['DayClockFrom'];
            $data[$i]['DayClockTo'] = $rows['DayClockTo'];
            $data[$i]['NightClockFrom'] = $rows['NightClockFrom'];
            $data[$i]['NightClockTo'] = $rows['NightClockTo'];
            $data[$i]['Sunrise'] = $rows['Sunrise'];
            $data[$i]['Sunset'] = $rows['Sunset'];
            $data[$i]['DateCreated'] = $rows['DateCreated'];
            $i++;
        }
        echo json_encode($data);
    }
} else {
    echo json_encode([
        'status' => -1,
    ]);
    die();
}
