<?php

date_default_timezone_set("America/New_York");
require_once "./orm/Station.php";
require_once "./orm/Trip.php";
//if(isset($_SERVER['PATH_INFO'])) {
$path_components = explode('/', $_SERVER['PATH_INFO']);
//}
if ($_SERVER['REQUEST_METHOD'] == 'GET') {
    // query
    if (count($path_components) >= 2 && $path_components[1] != '') {
        if ($path_components[1] == 'station') {
            if (count($path_components) == 2) {
                //url: ~/station
                $all_stations = Station::getAllStations();
                // return all station
                if ($all_stations == null) {
                    // Stations info not found
                    header("HTTP/1.1 404 Not Found");
                    print "Data for all stations are null";
                    exit;
                }
                header("Content-type: application/json");
                print json_encode($all_stations);
                exit;
            }
            if (count($path_components) >= 4) {
                $date1 = '';
                $date2 = '';
                if (count($path_components) == 7) {
                    $date1 = $path_components[5];