<?php include_once "config/siteconfig.php"; ?>


<?php
// Check if 'value' is sent via POST
if (isset($_POST['year']) || isset($_POST['filterid'])) {
    // $year = $_POST['year'] ?? date('Y');  // Get the value from the AJAX request

    // Perform cURL request
    $ch = curl_init();


    // Build POST data
    $postData = array();
    if (isset($_POST['filterid'])) {
        $postData['filterid'] = $_POST['filterid'] ?? date('m');
    }
    if (isset($_POST['year'])) {
        $postData['year'] = $_POST['year'] ?? date('Y');
    }

    // URL to send the cURL request to (replace this with your desired endpoint)
    $url = APIURL . '/website/leaderboard';

    // Set cURL options
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postData));
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

    // Execute cURL request and get response
    $response = curl_exec($ch);

    // Check for errors
    if ($response === false) {
        echo 'cURL Error: ' . curl_error($ch);
    } else {
        // Send the response back to JavaScript
        echo $response;
        /*$yearlyWinners   = ( !empty($result) && isset($result['status']) && $result['status'] == '1' && isset($result['yearlyWinners']) ) ? $result['yearlyWinners'] : array();
        echo $yearlyWinners;*/
    }

    // Close the cURL session
    curl_close($ch);
} else {
    echo 'No value received';
}
?>