diff options
Diffstat (limited to 'index.php')
-rwxr-xr-x[-rw-r--r--] | index.php | 196 |
1 files changed, 100 insertions, 96 deletions
diff --git a/index.php b/index.php index ac19989..351a2af 100644..100755 --- 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,119 +48,122 @@ 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 $stopList by $stopList['order'] using usort -function cmp($a, $b) { - return $a['order'] - $b['order']; +function cmp($a, $b) +{ + return $a['order'] - $b['order']; } $servUpdates = getData('service', false, false, false); if (isset($_GET['route'])) { - echo '<a href="index.php">Home</a>'; - $route = $_GET['route']; - $days = array('mon_fri', 'sat', 'sun'); - $directions = array('outbound', 'inbound'); - $schedule = getData('schedule', $route, false, false); - $routeUpdates = array(); - echo '<h3>'. $schedule['service_number'] . ' - ' . $schedule['service_name'] . '</h3>'; - - // print service updates for current timetable - foreach ($servUpdates as $update) { - if(in_array($route, $update['services'])) { - array_push($routeUpdates, $update['content']); + echo '<a href="index.php">Home</a>'; + $route = $_GET['route']; + $days = array('mon_fri', 'sat', 'sun'); + $directions = array('outbound', 'inbound'); + $schedule = getData('schedule', $route, false, false); + $routeUpdates = array(); + echo '<h3>'. $schedule['service_number'] . ' - ' . $schedule['service_name'] . '</h3>'; + + // 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 '<h4> Service Updates:</h4>'; - foreach ($routeUpdates as $update) { - echo $update . '<br>'; + if (!empty($routeUpdates)) { + echo '<h4> Service Updates:</h4>'; + foreach ($routeUpdates as $update) { + echo $update . '<br>'; + } } - } - - //print friday only gmp_legend - echo '<table align="left" border="1" cellpadding="3" style="background-color: #039DFF;"><tr><td>Friday Only</td><tr><table>'; - - // 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; - case "sat": - $displayDay = "Saturday"; - break; - case "sun": - $displayDay = "Sunday"; - break; - default: - 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 - echo ' '; - echo '<h3>' . ucfirst($direction) . ' | ' . $displayDay . '</h3>'; - echo '<table align="left" border="1" cellpadding="3" width="100%">'; - // search for $stopList['stop_name'] in each trip and print time in row on table - foreach ($stopList as $rowStop) { - echo '<tr><td><b>' . $rowStop['stop_name'] . '</b></td>'; - 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 '<td class="frionly">' . $stop['departure_time'] . '</td>'; - } else { - echo '<td>' . $stop['departure_time'] . '</td>'; + + //print friday only gmp_legend + echo '<table align="left" border="1" cellpadding="3" style="background-color: #039DFF;"><tr><td>Friday Only</td><tr><table>'; + + // 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; + case "sat": + $displayDay = "Saturday"; + break; + case "sun": + $displayDay = "Sunday"; + break; + default: + 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 + echo ' '; + echo '<h3>' . ucfirst($direction) . ' | ' . $displayDay . '</h3>'; + echo '<table align="left" border="1" cellpadding="3" width="100%">'; + // search for $stopList['stop_name'] in each trip and print time in row on table + foreach ($stopList as $rowStop) { + echo '<tr><td><b>' . $rowStop['stop_name'] . '</b></td>'; + 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 '<td class="frionly">' . $stop['departure_time'] . '</td>'; + } else { + echo '<td>' . $stop['departure_time'] . '</td>'; + } + $found=true; + } + } + // print something to show bus doesn't use this stop on this trip e.g. route variation + if ($found != true) { + echo '<td>----</td>'; + } + } + echo '</tr>'; } - $found=True; + echo '</table>'; } - } - // print something to show bus doesn't use this stop on this trip e.g. route variation - if ($found != True) { - echo '<td>----</td>'; - } } - echo '</tr>'; - } - echo '</table>'; } - } } - } } // print landing page if no route is selected else { - $routes = getData('routes', false, false, false); - $meta = getData('meta', false, false, false); - if ($meta['from'] == '-- --- ----') { - echo '<h3>' . $meta['name']. '</h3>'; - } else { - echo '<h3>' . $meta['name']. ' | ' . $meta['from'] . ' - ' . $meta['to'] . '</h3>'; - } - if (!empty($routeUpdates)) { - echo '<h4>Service Updates:</h4><p>'; - foreach ($servUpdates as $update) { - echo $update['content'] . '- <b>Affected Routes: </b>' . implode(", ",$update['services']) . '<br><br>'; - } - } - foreach ($routes as $route) { - echo '<h4><a href="index.php?route=' . $route['service_number'] . '">' . $route['service_number'] . ' - ' . $route['service_name'] . '</a></h4>'; - } - echo '</p>'; + $routes = getData('routes', false, false, false); + // sort $routes + uksort($routes, 'strnatcmp'); + $meta = getData('meta', false, false, false); + if ($meta['from'] == '-- --- ----') { + echo '<h3>' . $meta['name']. '</h3>'; + } else { + echo '<h3>' . $meta['name']. ' | ' . $meta['from'] . ' - ' . $meta['to'] . '</h3>'; + } + if (!empty($routeUpdates)) { + echo '<h4>Service Updates:</h4><p>'; + foreach ($servUpdates as $update) { + echo $update['content'] . '- <b>Affected Routes: </b>' . implode(", ", $update['services']) . '<br><br>'; + } + } + foreach ($routes as $route) { + echo '<h4><a href="index.php?route=' . $route['service_number'] . '">' . $route['service_number'] . ' - ' . $route['service_name'] . '</a></h4>'; + } + echo '</p>'; } ?> |