<?php
// pievieno datubazes savienojumu
require_once 'db_connection.php';

// nolasam menesi un gadu no GET pieprasijuma
$month = $_GET['month'];
$year = $_GET['year'];

// sagatavo SQL pieprasijumu, lai iegutu unikalos notikumu datumus konkretajam menesim un gadam
$sql = "SELECT DISTINCT DATE_FORMAT(event_date, '%Y-%m-%d') as date FROM events WHERE MONTH(event_date) = ? AND YEAR(event_date) = ?";
$stmt = $pdo->prepare($sql);
$stmt->execute([$month, $year]);

// iegust datumus un atgriez tos JSON formata
$dates = $stmt->fetchAll(PDO::FETCH_COLUMN);
header('Content-Type: application/json');
echo json_encode($dates);
?>
