function hosts_and_services_data($type, $state_filter = NULL, $name_filter = NULL, $host_filter = NULL)
{
    global $NagiosData;
    global $NagiosUser;
    $data = $NagiosData->getProperty($type);
    //add filter for user-level filtering
    if (!$NagiosUser->is_admin()) {
        //print $type;
        $data = user_filtering($data, $type);
    }
    $data_in = $data;
    if ($state_filter) {
        if ($state_filter == 'PROBLEMS' || $state_filter == 'UNHANDLED' || $state_filter == 'ACKNOWLEDGED') {
            $data = array_merge(get_by_state('UNKNOWN', $data_in), get_by_state('CRITICAL', $data_in), get_by_state('WARNING', $data_in), get_by_state('UNREACHABLE', $data_in), get_by_state('DOWN', $data_in));
            if ($state_filter == 'UNHANDLED') {
                //loop and return array
                $unhandled = array();
                foreach ($data as $d) {
                    if ($d['problem_has_been_acknowledged'] == 0 && $d['scheduled_downtime_depth'] == 0) {
                        $unhandled[] = $d;
                    }
                }
                $data = $unhandled;
            }
            //end unhandled if
            if ($state_filter == 'ACKNOWLEDGED') {
                //loop and return array
                $acknowledged = array();
                foreach ($data as $d) {
                    if ($d['problem_has_been_acknowledged'] > 0 || $d['scheduled_downtime_depth'] > 0) {
                        $acknowledged[] = $d;
                    }
                }
                $data = $acknowledged;
            }
            //end acknowledged if
        } elseif ($state_filter == 'PENDING' || $state_filter == 'OK' || $state_filter == 'UP') {
            $filtered = array();
            //pending
            if ($state_filter == 'PENDING') {
                foreach ($data as $d) {
                    if ($d['current_state'] == 0 && $d['last_check'] == 0) {
                        $filtered[] = $d;
                    }
                }
            } else {
                foreach ($data as $d) {
                    if ($d['current_state'] == 0 && $d['last_check'] != 0) {
                        $filtered[] = $d;
                    }
                }
            }
            $data = $filtered;
        } else {
            $s = $type == 'services' ? true : false;
            $data = get_by_state($state_filter, $data, $s);
        }
    }
    //end IF $state_filter
    if ($name_filter) {
        $name_data = get_by_name($name_filter, $data);
        $service_data = get_by_name($name_filter, $data, 'service_description');
        $data = $name_data;
        //array_dump($data);
        foreach ($service_data as $i => $service) {
            if (!isset($data[$i])) {
                $data[$i] = $service;
            }
        }
        $data = array_values($data);
    }
    if ($host_filter) {
        $name_data = get_by_name($name_filter, $data, 'host_name', $host_filter);
        $service_data = get_by_name($name_filter, $data, 'service_description', $host_filter);
        $data = $name_data;
        //array_dump($service_data);
        foreach ($service_data as $i => $service) {
            if (!isset($data[$i])) {
                $data[$i] = $service;
            }
        }
        $data = array_values($data);
    }
    //var_dump($data);
    return $data;
}
function get_services_by_state($state, $service_data)
{
    return get_by_state($state, $service_data, true);
}