diff options
| author | Asa Venton <asav1410@gmail.com> | 2019-10-18 21:07:50 +0100 | 
|---|---|---|
| committer | Asa Venton <asav1410@gmail.com> | 2019-10-18 21:07:50 +0100 | 
| commit | bf914a5ed0a5173dea527aa0dc319ae3425018a3 (patch) | |
| tree | 947b4bb9e45429a47ba46edb1fb11daea1d8e07a /index.php | |
initial commit
Diffstat (limited to 'index.php')
| -rw-r--r-- | index.php | 146 | 
1 files changed, 146 insertions, 0 deletions
diff --git a/index.php b/index.php new file mode 100644 index 0000000..13f03af --- /dev/null +++ b/index.php @@ -0,0 +1,146 @@ +<!DOCTYPE HTML> +<html> + +<head> +<title>bus.of.je</title> +</head> + +<style> +table { +    border-collapse: collapse; +} +tr:nth-child(even) {background-color: #f2f2f2;} +</style> + +<body> +<h2>bus.of.je | Liberty Bus Timetables</h2> + +<?php + +// TODO: tidy up HTML creation +// TODO: make it pretty + +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){ +    case "routes": +      $result = $timetables['timetables']; +      break; +    case "trips": +      $result = $timetables['timetables'][$route]['timetable'][$direction][$day]['trips']; +      break; +    case "stoplist": +      $result = $timetables['timetables'][$route]['timetable'][$direction]['stops_list']; +      break; +    case "schedule": +      $result = $timetables['timetables'][$route]; +      break; +    case "meta": +      $result = $timetables['meta']; +      break; +    case "service": +      $result = json_decode(file_get_contents("service_updates.json"), true); +    default: +      break; +  } +  if (!$result) { +    $result = False; +  } +  return $result; +} + +$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 '<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>'; +    } +  } +  // 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); +          // print timetable info while setting display friendly case for directions +          // TODO: add linebreaks between end of table and next table title +          echo '<p><br><b>' . ucfirst($direction) . ' | ' . $displayDay . '</b>'; +          echo '<table align="left" border="1" cellpadding="3" width="100%">'; +          $trips = getData('trips', $route, $direction, $day); +          // TODO: sort stopList by stopList['order'] +          // TODO: must be a more efficient way to search for $rowStop['stop_name'] in $trip? +          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']) { +                  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>'; +          } +          echo '</table><br><br></p>'; +        } +      } +    } +  } +} +// print landing page if no route is selected +else { +  $routes = getData('routes', false, false, false); +  $meta = getData('meta', false, false, false); +  echo '<h3>' . $meta['name']. ' | ' . $meta['from'] . ' - ' . $meta['to'] . '</h3>'; +  echo '<h4>Service Updates:</h4>\n<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>'; +} +?> + +</p> +</body> + +</html>  | 
