-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
140 lines (133 loc) · 4.31 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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="css/style.css">
<?php
header('Refresh: 30;'); //Consider using another method of refreshing the table
include ('php/functions.php');
$authKey = getAuthKey(); //Fetch a time based key
$currentDate = date('y-m-d'); //Is used to calculate remaining time until departure
$currentTime = date('H:i');
$friesId = getId('Doktor Fries Torg', $authKey)['LocationList']['StopLocation'][0]['id']; //Gets the specific ID for our stop. Navigation in the json decoded array is shown here
$estridsId = getId('Syster Estrids Gata', $authKey)['LocationList']['StopLocation'][0]['id'];
$sahlgrenskaId = getId('Sahlgrenska huvudentré', $authKey)['LocationList']['StopLocation'][0]['id'];
$fries = (getDeparture($friesId, $currentDate, $currentTime, $authKey)['DepartureBoard']); //Similar to ID but instead fetches all available departures for the gived ID. Some optimization could be used here
$estrids = (getDeparture($estridsId, $currentDate, $currentTime, $authKey)['DepartureBoard']);
$sahlgrenska = (getDeparture($sahlgrenskaId, $currentDate, $currentTime, $authKey)['DepartureBoard']);
$stations = array($fries, $estrids, $sahlgrenska); //puts everything in one array. all departures on Doktor Fries Torg can be found in index 0 for example.
?>
<title>PiTrafik 1.0</title>
</head>
<body>
<div class="info">
<div class="servertime"><?php
if (date('Y-m-d') == $stations[0]['serverdate']) {
$day = date('l');
$date = date('j');
$month = date('F');
//Could not get date() to properly display Swedish letters
switch ($day) {
case 'Monday':
$day = 'Måndag';
break;
case 'Tuesday':
$day = 'Tisdag';
break;
case 'Wednesday':
$day = 'Onsdag';
break;
case 'Thursday':
$day = 'Torsdag';
break;
case 'Friday':
$day = 'Fredag';
break;
case 'Saturday':
$day = 'Lördag';
break;
case 'Sunday':
$day = 'Söndag';
break;
}
switch ($month) {
case 'January':
$month = 'Januari';
break;
case 'February':
$month = 'Februari';
break;
case 'May':
$month = 'Maj';
break;
case 'June':
$month = 'Juni';
break;
case 'July':
$month = 'Juli';
break;
case 'August':
$month = 'Augusti';
break;
case 'October':
$month = 'Oktober';
break;
}
echo $day.'<br>'.$date.' '.$month.'<br>'.$stations[0]['servertime'];
}
?></div>
<p class="title">PiTrafik</p>
<img class="logo" src="img/Raspberry_Pi_Logo.png">
</div>
<?php
$serverTime = $stations[0]['servertime'];
//3 big boxes
for ($j=0; $j <sizeOf($stations); $j++) {
?>
<div class="stationname">
<?php
echo $stations[$j]['Departure'][0]['stop'];
?>
</div>
<div class="station">
<div class="pointers">
<div class="linje">Linje</div>
<div class="direction">Destination</div>
<div class="departure">Avgår om (min)</div>
</div>
<?php
//Info about the 7 next departures
for ($i=0; $i < 7; $i++) {
$bgColor = $stations[$j]['Departure'][$i]['bgColor'];
$fgColor = $stations[$j]['Departure'][$i]['fgColor'];
?>
<div class="name" style="color:<?php echo $bgColor;?>; background-color: <?php echo $fgColor; ?>;">
<?php echo $stations[$j]['Departure'][$i]['sname']; ?>
</div>
<div class="direction">
<?php echo $stations[$j]['Departure'][$i]['direction']; ?>
</div>
<div class="departure">
<?php
if (isset($stations[$j]['Departure'][$i]['rtTime'])) {
if (getRemainingTime($serverTime, $stations[$j]['Departure'][$i]['rtTime'])==0) { //If departure is now
echo 'Nu ('.$stations[$j]['Departure'][$i]['rtTime'].')';
}
else {
echo getRemainingTime($serverTime, $stations[$j]['Departure'][$i]['rtTime']).' ('.$stations[$j]['Departure'][$i]['rtTime'].')'; //print remaining time
}
}
else {
echo getRemainingTime($serverTime, $stations[$j]['Departure'][$i]['time']).' ('.$stations[$j]['Departure'][$i]['time'].')';
}
?>
</div>
<?php
}
?>
</div>
<?php
}
?>
</body>
</html>