From ebd626c71da5e5f1b928093ce8ce7ac3167c5f60 Mon Sep 17 00:00:00 2001 From: Asa Venton Date: Wed, 3 Mar 2021 11:45:01 +0000 Subject: Make style consistent. Sort $routes before printing to homepage. --- index.php | 169 ++++++++++++++++++++++++++++++++------------------------------ 1 file changed, 86 insertions(+), 83 deletions(-) mode change 100644 => 100755 index.php (limited to 'index.php') diff --git a/index.php b/index.php old mode 100644 new mode 100755 index 24e9d6c..930c51d --- a/index.php +++ b/index.php @@ -26,9 +26,10 @@ tr:nth-child(even) {background-color: #f2f2f2;} ini_set('display_errors', 1); error_reporting(~0); -function getData($type, $route, $direction, $day) { - $timetables = json_decode(file_get_contents("timetable_full.json"), true); - switch ($type){ +function getData($type, $route, $direction, $day) +{ + $timetables = json_decode(file_get_contents("timetable_full.json"), true); + switch ($type) { case "routes": return $timetables['timetables']; break; @@ -47,47 +48,49 @@ function getData($type, $route, $direction, $day) { case "service": return json_decode(file_get_contents("service_updates.json"), true); default: - return False; + return false; break; } } -// function to sort $stopList by $stopList['order'] using usort -function cmp($a, $b) { - return $a['order'] - $b['order']; +// function to $stopList by $stopList['order'] using usort +function cmp($a, $b) +{ + return $a['order'] - $b['order']; } $servUpdates = getData('service', false, false, false); if (isset($_GET['route'])) { - $route = $_GET['route']; - $days = array('mon_fri', 'sat', 'sun'); - $directions = array('outbound', 'inbound'); - $schedule = getData('schedule', $route, false, false); - $routeUpdates = array(); - echo '

'. $schedule['service_number'] . ' - ' . $schedule['service_name'] . '

'; - - // print service updates for current timetable - foreach ($servUpdates as $update) { - if(in_array($route, $update['services'])) { - array_push($routeUpdates, $update['content']); + echo 'Home'; + $route = $_GET['route']; + $days = array('mon_fri', 'sat', 'sun'); + $directions = array('outbound', 'inbound'); + $schedule = getData('schedule', $route, false, false); + $routeUpdates = array(); + echo '

'. $schedule['service_number'] . ' - ' . $schedule['service_name'] . '

'; + + // print service updates for current timetable + foreach ($servUpdates as $update) { + if (in_array($route, $update['services'])) { + array_push($routeUpdates, $update['content']); + } } - } - if (!empty($routeUpdates)) { - echo '

Service Updates:

'; - foreach ($routeUpdates as $update) { - echo $update . '
'; + if (!empty($routeUpdates)) { + echo '

Service Updates:

'; + foreach ($routeUpdates as $update) { + echo $update . '
'; + } } - } - //print friday only legend - echo '
Friday Only

'; + //print friday only gmp_legend + echo '
Friday Only
'; - // print timetables - foreach ($days as $day) { - if ($schedule['schedule'][$day] == 'true') { - // set display friendly variables for days - switch ($day){ + // print timetables + foreach ($days as $day) { + if ($schedule['schedule'][$day] == 'true') { + // set display friendly variables for days + switch ($day) { case "mon_fri": $displayDay = "Mon - Fri"; break; @@ -101,66 +104,66 @@ if (isset($_GET['route'])) { break; } - foreach ($directions as $direction) { - if ($schedule['directions'][$direction] == 'true') { - $stopList = getData('stoplist', $route, $direction, false); - // usort to sort stoplist - usort($stopList,"cmp"); - $trips = getData('trips', $route, $direction, $day); - // print timetable info while setting display friendly case for directions - // TODO: add linebreaks between end of table and next table title - echo '

' . ucfirst($direction) . ' | ' . $displayDay . '

'; - echo '
'; - // search for $stopList['stop_name'] in each trip and print time in row on table - foreach ($stopList as $rowStop) { - echo ''; - foreach ($trips as $trip) { - $found=False; - foreach ($trip['stops'] as $stop) { - if ($stop['stop_name'] == $rowStop['stop_name']) { - // check if bus runs on Friday only by checking another day, in this case Monday, (it doesn't matter which as the only variation is Friday only busses) and apply custom color to cells - if (($day == 'mon_fri') && ($trip['days_of_operation']['mon'] == False)) { - echo ''; - } else { - echo ''; + foreach ($directions as $direction) { + if ($schedule['directions'][$direction] == 'true') { + $stopList = getData('stoplist', $route, $direction, false); + // usort to sort stoplist + usort($stopList, "cmp"); + $trips = getData('trips', $route, $direction, $day); + // print timetable info while setting display friendly case for directions + echo ' '; + echo '

' . ucfirst($direction) . ' | ' . $displayDay . '

'; + echo '
' . $rowStop['stop_name'] . '' . $stop['departure_time'] . '' . $stop['departure_time'] . '
'; + // search for $stopList['stop_name'] in each trip and print time in row on table + foreach ($stopList as $rowStop) { + echo ''; + foreach ($trips as $trip) { + $found=false; + foreach ($trip['stops'] as $stop) { + if ($stop['stop_name'] == $rowStop['stop_name']) { + // check if bus runs on friday only by checking another day (in this case thursday) and apply custom color to cells + if (($day == 'mon_fri') && ($trip['days_of_operation']['mon'] == false)) { + echo ''; + } else { + echo ''; + } + $found=true; + } + } + // print something to show bus doesn't use this stop on this trip e.g. route variation + if ($found != true) { + echo ''; + } + } + echo ''; } - $found=True; + echo '
' . $rowStop['stop_name'] . '' . $stop['departure_time'] . '' . $stop['departure_time'] . '----
'; } - } - // print something to show bus doesn't use this stop on this trip e.g. during a route variation - if ($found != True) { - echo '----'; - } } - echo ''; - } - echo ''; } - } } - } } // print landing page if no route is selected else { - $routes = getData('routes', false, false, false); - // print timetable season and valid from/to dates - $meta = getData('meta', false, false, false); - // sometimes valid from/to dates aren't available so we don't print them - if ($meta['from'] == '-- --- ----') { - echo '

' . $meta['name']. '

'; - } else { - echo '

' . $meta['name']. ' | ' . $meta['from'] . ' - ' . $meta['to'] . '

'; - } - echo '

Service Updates:

'; - // print service updates - foreach ($servUpdates as $update) { - echo $update['content'] . '- Affected Routes: ' . implode(", ",$update['services']) . '

'; - } - // print routes - foreach ($routes as $route) { - echo '

' . $route['service_number'] . ' - ' . $route['service_name'] . '

'; - } - echo '

'; + $routes = getData('routes', false, false, false); + // sort $routes + uksort($routes, 'strnatcmp'); + $meta = getData('meta', false, false, false); + if ($meta['from'] == '-- --- ----') { + echo '

' . $meta['name']. '

'; + } else { + echo '

' . $meta['name']. ' | ' . $meta['from'] . ' - ' . $meta['to'] . '

'; + } + if (!empty($routeUpdates)) { + echo '

Service Updates:

'; + foreach ($servUpdates as $update) { + echo $update['content'] . '- Affected Routes: ' . implode(", ", $update['services']) . '

'; + } + } + foreach ($routes as $route) { + echo '

' . $route['service_number'] . ' - ' . $route['service_name'] . '

'; + } + echo '

'; } ?> -- cgit v1.2.3