<?php

require_once $base_path . 'classes/checkframework.php';
if (is_array($_POST) && count($_POST) > 0) {
    $from_date = $_POST['from_date'];
    $to_date = $_POST['to_date'];
    $courts = $_POST['courts'];
    $username = $_POST['username'];
    $court_names = array();
    if (is_array($courts) && count($courts) > 0) {
        $court_names = Court::get_names($courts);
    } else {
        $court_names = array('összes');
    }
    $ret = array();
    try {
        $reservations = Reservation::get_report($from_date, $to_date, $courts, $username);
    } catch (Exception $e) {
        $ret = array('success' => false, 'error' => 'invalid_date');
    }
    if (count($ret) == 0) {
        $date = date('Y-m-d');
        $ret['adminUser'] = $admin_username;
        $ret['date'] = $date;
        $ret['dateFrom'] = $from_date;
        $ret['dateTo'] = $to_date;
        $ret['courts'] = $court_names;
        $ret['reservationsCount'] = count($reservations);
        $ret['reservations'] = array();
        $income = 0;
        $users_tmp = array();