This repository has been archived by the owner on Mar 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
194 lines (175 loc) · 6.49 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
<!DOCTYPE xhtml>
<html>
<head>
<!-- Include meta tag to ensure proper rendering and touch zooming -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Include jQuery Mobile stylesheets -->
<link rel="stylesheet" href="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css">
<!-- Include the jQuery library -->
<script src="https://code.jquery.com/jquery-2.2.3.min.js"></script>
<!-- Include the jQuery Mobile library -->
<script src="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
<title>BXLBusBerry</title>
</head>
<?php
error_reporting(-1);
require 'api.inc.php';
require 'vendor/autoload.php';
use GuzzleHttp\Client;
$client = new Client([
'base_uri' => 'https://stib-mivb-api.herokuapp.com',
'headers' => ['content-type' => 'text/xml'],
'timeout' => 2.0,
]);
$Stib = new Stib();
//$lines = $Stib->GetLines($client);
//echo '<pre>';print_r($lines);print '</pre>';
//$schedule = $Stib->GetLine($client, 92);
//echo '<pre>';print_r($schedule);print '</pre>';
//$Stops = $Stib->GetDirection($client, $schedule->id, 2);
//echo '<pre>';print_r($Stops);print '</pre>';
//$time = $Stib->GetStop ($client, 6420, "VANDERKINDERE");
//echo '<pre>';print_r($time);print '</pre>';
function PresentLines($Stib, $client)
{
echo '<table data-role="table" data-mode="columntoggle" class="ui-responsive" id="myTable">
<thead>
<tr>';
echo '<th>LineID</th>';
echo '<th data-priority="1">LineName</th>';
echo '<th data-priority="2">LineMode</th>';
echo '</tr>
</thead>
<tbody>';
$lines = $Stib->GetLines($client);
foreach ($lines as $key => $value)
{
foreach ($value as $line)
{
echo '<tr>';
echo "<td><a href='#' onclick = 'GetLine(".$line['id'].")' id='".$line['id']."' class='".$line['id']."'>".$line['id']."</a></td>";
echo "<td>".$line['name']."</td>";
echo "<td>".$line['mode']."</td>";
echo '</tr>';
}
}
echo '</tbody>
</table>';
}
function GetLine($Stib, $client, $line)
{
echo '<table data-role="table" data-mode="columntoggle" class="ui-responsive" id="myTable">
<thead>
<tr>';
echo '<th>Direction</th>';
echo '<th data-priority="1">LineDirection</th>';
echo '<th data-priority="2">LineName</th>';
echo '</tr>
</thead>
<tbody>';
$currentline = $Stib->GetLine($client, $line);
foreach ($currentline->directions as $key => $value)
{
echo '<tr>';
echo "<td><a href='#' onclick = 'GetStops(".$currentline->id.", ".$value.")' id='".$currentline->id."' class='".$currentline->id."'>".$value."</a></td>";
echo "<td>".$key."</td>";
echo "<td>".$currentline->name."</td>";
echo '</tr>';
}
echo '</tbody>
</table>';
}
function GetStops($Stib, $client, $line, $direction)
{
echo '<table data-role="table" data-mode="columntoggle" class="ui-responsive" id="myTable">
<thead>
<tr>';
echo '<th>Stop name</th>';
echo '<th data-priority="1">Line</th>';
echo '<th data-priority="2">StopID</th>';
echo '</tr>
</thead>
<tbody>';
$Stops = $Stib->GetDirection($client, $line, $direction);
// echo '<pre>';print_r($Stops->line);print '</pre>';
foreach ($Stops->line['stops'] as $stop)
{
echo '<tr>';
echo "<td><a href='#' onclick = 'GetStop(".$stop['id'].", \"".$stop['name']."\")' id='".$stop['id']."' class='".$stop['id']."'>".$stop['name']."</a></td>";
echo "<td>".$line."</td>";
echo "<td>".$stop['id']."</td>";
echo '</tr>';
}
echo '</tbody>
</table>';
}
function GetTime($Stib, $client, $StopID, $StopName)
{
echo "<button onclick = 'GetStop(".$StopID.", \"".$StopName."\")'>Reload</button>";
echo '<table data-role="table" data-mode="columntoggle" class="ui-responsive" id="myTable">
<thead>
<tr>';
echo '<th>Destination</th>';
echo '<th data-priority="1">Minutes</th>';
echo '<th data-priority="2">Line</th>';
echo '<th>Schedule</th>';
echo '<th>Stop</th>';
echo '</tr>
</thead>
<tbody>';
$time = $Stib->GetStop ($client, $StopID, $StopName);
echo '<pre>';print_r($time);print '</pre>';
foreach ($time->results as $stop)
{
echo '<tr>';
echo "<td>".$stop['destination']."</td>";
echo "<td>".$stop['minutes']."</td>";
echo "<td>".$stop['line']."</td>";
$schedule = date('G:i', strtotime($stop['when']));
echo "<td>".$schedule."</td>";
echo "<td>".$time->name."</td>";
echo '</tr>';
}
echo '</tbody>
</table>';
}
?>
<body>
<script language = "javascript" type = "text/javascript">
function GetLine(line){
$.ajax({url: "index.php?GetLine=1&LineNumber="+line, success: function(result){
$("#presentation").html(result);
}});
}
function GetStops(line, direction){
$.ajax({url: "index.php?GetStops=1&LineNumber="+line+"&Direction="+direction, success: function(result){
$("#presentation").html(result);
}});
}
function GetStop(stopid, stopname){
$.ajax({url: "index.php?GetStop=1&StopID="+stopid+"&StopName="+stopname, success: function(result){
$("#presentation").html(result);
}});
}
</script>
<div id='presentation' name="presentation">
<?php
if (isset($_GET['GetLine']) && isset($_GET['LineNumber']))
{
GetLine($Stib, $client, $_GET['LineNumber']);
}
elseif (isset($_GET['GetStops']) && isset($_GET['LineNumber']) && isset($_GET['Direction']))
{
GetStops($Stib, $client, $_GET['LineNumber'], $_GET['Direction']);
}
elseif (isset($_GET['GetStop']) && isset($_GET['StopID']) && isset($_GET['StopName']))
{
GetTime($Stib, $client, $_GET['StopID'], $_GET['StopName']);
}
else
{
PresentLines($Stib, $client);
}
?>
</div>
</body>