forked from CitadelOnTheMove/agt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cityInfo.php
44 lines (30 loc) · 1021 Bytes
/
cityInfo.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
<?php
include_once 'Config.php';
include_once CLASSES . 'Util.class.php';
include_once CLASSES . 'Database.class.php';
include_once CLASSES . 'City.class.php';
if (isset($_GET['cityName']) && isset($_GET['lat']) && isset($_GET['lon'])) {
echo City::getCityId($_GET['cityName'], $_GET['lat'], $_GET['lon']);
} else {
/**
* Echoes a json array with the cities stored in the database
* @return json all City[] objects
*/
$cities = array();
Database::connect();
$sqlCity = "SELECT * FROM cities";
foreach (Database::$dbh->query($sqlCity) as $city) {
$id = $city['id'];
$name = $city['name'];
$lat = $city['latitude'];
$lon = $city['longitude'];
$city = new City($id, $name, $lat, $lon, null);
if (!in_array($city, $cities)) {
$cities[] = $city;
}
}
Database::disconnect();
$arr = array('cities' => $cities);
Util::printJsonObj($arr);
}
?>