forked from bbdoc/PoracleWeb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
set_location.php
63 lines (48 loc) · 1.57 KB
/
set_location.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
<?php
include "./config.php";
include "./db_connect.php";
if ( isset($_GET['lat']) && isset($_GET['lon']) ) {
$lat = $_GET['lat'];
$lon = $_GET['lon'];
} else {
$config = file_get_contents("$poracle_dir/config/local.json");
$json = json_decode($config, true);
foreach ($json as $key => $value) {
if ($key == "geocoding") {
$nominatim=$value['providerURL'];
}
}
$street = str_replace(" ", "%20", $_POST['street']);
$city = str_replace(" ", "%20", $_POST['city']);
$filepath="$nominatim/?addressdetails=1&q=".$street."%20".$city."&format=json&limit=1";
$request = file_get_contents($filepath);
if ( $request == "[]" ) {
header("Location: $redirect_url?return=error_update_location");
exit();
}
$json = json_decode($request, true);
foreach ($json as $key => $value) {
foreach ($value as $key => $value2) {
if ($key == "lat") { $lat = $value2; }
if ($key == "lon") { $lon = $value2; }
}
}
}
$stmt = $conn->prepare("UPDATE humans set latitude = ?, longitude = ? WHERE id = ?");
if (false === $stmt) {
header("Location: $redirect_url?return=sql_error&phase=ESL1&sql=$stmt->error");
exit();
}
$rs = $stmt->bind_param("sss", $lat, $lon, $_SESSION['id']);
if (false === $rs) {
header("Location: $redirect_url?return=sql_error&phase=ESL2&sql=$stmt->error");
exit();
}
$rs = $stmt->execute();
if (false === $rs) {
header("Location: $redirect_url?return=sql_error&phase=ESL3&sql=$stmt->error");
exit();
}
header("Location: $redirect_url?return=success_update_location");
exit();
?>