Skip to content

Commit

Permalink
New Button to Set Location to current Position
Browse files Browse the repository at this point in the history
  • Loading branch information
bbdoc committed Jan 4, 2021
1 parent dbc4113 commit 04d4a7b
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 34 deletions.
39 changes: 34 additions & 5 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ class="mr-2 d-none d-lg-inline text-gray-600 small"><?php echo $_SESSION['userna

<!-- Begin Page Content -->
<div class="container-fluid col-lg-8 col-md-12">

<!-- Profile Settings Modal -->
<?php include "./modal/profile_settings_modal.php"; ?>

Expand Down Expand Up @@ -246,7 +245,7 @@ class="mr-2 d-none d-lg-inline text-gray-600 small"><?php echo $_SESSION['userna
if ($enabled==0) {
?>
<div class="alert alert-danger alert-dismissible fade show" role="alert">
<?php echo i8ln("Your alarms are currently disabled !"); ?>
<?php echo i8ln("Your alarms are currently disabled!"); ?>
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
Expand Down Expand Up @@ -288,14 +287,19 @@ class="mr-2 d-none d-lg-inline text-gray-600 small"><?php echo $_SESSION['userna
data-target="#areasModal">
<i class="fas fa-edit"></i>
</button>
<?php } ?>
<?php } ?>
<?php if ($disable_location <> "True") { ?>
<h6 class="m-0 font-weight-bold text-dark"><?php echo i8ln("LOCATION"); ?></h6>
<!-- Button trigger modal -->
<!-- Button trigger modal -->
<div align="right">
<button type="button" class="btn btn-success btn-circle btn-md" onclick="getLocation()">
<i class="fas fa-map-marker-alt"></i>
</button>
<button type="button" class="btn btn-success btn-circle btn-md" data-toggle="modal"
data-target="#locationModal">
<i class="fas fa-edit"></i>
</button>
</button>
</div>
<?php } ?>

</div>
Expand Down Expand Up @@ -345,6 +349,30 @@ class="mr-2 d-none d-lg-inline text-gray-600 small"><?php echo $_SESSION['userna
<div class="col mr-2">
<div class="row">

<div id="position_error_div" style="display:none;" class="col-xl-12 col-lg-4 col-md-6 col-sm-12 text-center">
<div id="PERMISSION_DENIED" style="display:none;" class="alert alert-danger" role="alert">
<b><?php echo i8ln("Could not set Location"); ?></b>.<br>
<?php echo i8ln("User denied the request for Geolocation"); ?>.
</div>
<div id="POSITION_UNAVAILABLE" style="display:none;" class="alert alert-danger" role="alert">
<b><?php echo i8ln("Could not set Location"); ?></b>.<br>
<?php echo i8ln("Location information is unavailable"); ?>.
</div>
<div id="TIMEOUT" style="display:none;" class="alert alert-danger" role="alert">
<b><?php echo i8ln("Could not set Location"); ?></b>.<br>
<?php echo i8ln("The request to get user location timed out"); ?>.
</div>
<div id="UNKNOWN_ERROR" style="display:none;" class="alert alert-danger" role="alert">
<b><?php echo i8ln("Could not set Location"); ?></b>.<br>
<?php echo i8ln("An unknown error occurred"); ?>.
</div>
<div id="NOT_SUPPORTED" style="display:none;" class="alert alert-danger" role="alert">
<b><?php echo i8ln("Could not set Location"); ?></b>.<br>
<?php echo i8ln("Geolocation is not supported by this browser"); ?>.
</div>
</div>


<?php
if ($latitude == "0.0000000000" && $longitude == "0.0000000000") {
?>
Expand Down Expand Up @@ -1589,6 +1617,7 @@ class="btn btn-danger"><?php echo i8ln("DELETE"); ?></a>

<!-- Custom scripts for all pages-->
<script src="js/scripts.js"></script>
<script type="text/javascript" src="js/get_position.js?v=<?=time();?>"></script>
<script src="https://cdn.jsdelivr.net/gh/gitbrent/[email protected]/js/bootstrap4-toggle.min.js"></script>

</body>
Expand Down
37 changes: 37 additions & 0 deletions js/get_position.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

var error_div = document.getElementById("position_error_div");

function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(setPosition, showError);
} else {
error_div.style.display = "block"
document.getElementById("NOT_SUPPORTED").style.display = "block"
}
}

function setPosition(position) {
window.location = './set_location.php?lat=' + position.coords.latitude + '&lon=' + position.coords.longitude;
}

function showError(error) {
switch(error.code) {
case error.PERMISSION_DENIED:
error_div.style.display = "block"
document.getElementById("PERMISSION_DENIED").style.display = "block"
break;
case error.POSITION_UNAVAILABLE:
error_div.style.display = "block"
document.getElementById("POSITION_UNAVAILABLE").style.display = "block"
break;
case error.TIMEOUT:
error_div.style.display = "block"
document.getElementById("TIMEOUT").style.display = "block"
break;
case error.UNKNOWN_ERROR:
error_div.style.display = "block"
document.getElementById("UNKNOWN_ERROR").style.display = "block"
break;
}
}

2 changes: 1 addition & 1 deletion locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"MIN Rank":"Ranking Min",
"MAX Rank":"Ranking Max",
"AREAS":"GEBIETE",
"Your alarms are currently disabled !":"Deine Nachrichten sind aktuell deaktiviert",
"Your alarms are currently disabled!":"Deine Nachrichten sind aktuell deaktiviert",
"You Request couldn't not be handled":"Fehler bei deiner Eingabe: ",
"Your location is not set. Distance settings won't be taken into account.":"Dein Standort ist nicht gesetzt. </br>Distanzen werden nicht berücksichtigt!</br>",
"Distance":"Distanz",
Expand Down
16 changes: 11 additions & 5 deletions locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"MIN Rank":"Ranking Min",
"MAX Rank":"Ranking Max",
"AREAS":"ZONES",
"Your alarms are currently disabled !":"Vos alarmes sont désactivées",
"Your alarms are currently disabled!":"Vos alarmes sont désactivées",
"You Request couldn't not be handled":"Votre demande n'a pas pû être traitée",
"Your location is not set. Distance settings won't be taken into account.":"Votre localisation n'est pas configurée. Les paramètres de distance ne seront pas pris en compte",
"Distance":"Distance",
Expand Down Expand Up @@ -130,11 +130,17 @@
"Delete tracking for Eggs Level":"Supprimer le Suivi des Oeufs Niveau",
"This will delete tracking for Eggs Level":"Cette action supprimrea le suivi des Oeufs Niveau",
"Delete tracking for Raids Level":"Supprimer le Suivi des Raids Niveau",
"This will delete tracking for Raids Level":"Cette action supprimrea le suivi des Raids Niveau",
"This will delete tracking for Raids Level":"Cette action supprimera le suivi des Raids Niveau",
"Delete Raid tracking for":"Supprimer le Suivi des Raids",
"This will delete Raid tracking for":"Cette action supprimrea le suivi des Raids",
"This will delete Raid tracking for":"Cette action supprimera le suivi des Raids",
"Delete Quests tracking for":"Supprimer le Suivi des Quêtes",
"This will delete Quests tracking for":"Cette action supprimrea le suivi des Quêtes",
"This will delete Quests tracking for":"Cette action supprimera le suivi des Quêtes",
"Delete Quests Item tracking":"Supprimer le Suivi de l'object de Quêtes",
"This will delete Quests tracking for this item":"Cette action supprimrea le suivi de l'object de Quêtes"
"This will delete Quests tracking for this item":"Cette action supprimera le suivi de l'object de Quêtes",
"Could not set Location":"Impossible d'obtenir la position",
"User denied the request for Geolocation":"L'utilisateur a bloqué l'accès à la localisation",
"Location information is unavailable":"L'information de localisation n'est pas disponible",
"The request to get user location timed out":"La demande de localisation a expiré",
"An unknown error occurred":"Une erreur inconnue s'est produite",
"Geolocation is not supported by this browser":"La géolocalisation n'est pas supportée par ce navigateur"
}
2 changes: 1 addition & 1 deletion locales/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"MIN Rank":"Ranking Min",
"MAX Rank":"Ranking Max",
"AREAS":"ZONES",
"Your alarms are currently disabled !":"Je alarmen staan uit!",
"Your alarms are currently disabled!":"Je alarmen staan uit!",
"You Request couldn't not be handled":"Je aanvraag kon niet verwerkt worden.",
"Your location is not set. Distance settings won't be taken into account.":"Je locatie is niet ingesteld. Er zal geen rekening gehouden worden met instellingen mbt afstand",
"Distance":"Afstand",
Expand Down
2 changes: 1 addition & 1 deletion locales/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"MIN Rank":"MIN Ranking",
"MAX Rank":"MAX Ranking",
"AREAS":"OBSZARY",
"Your alarms are currently disabled !":"Twoje powiadomienia są obecnie wyłączone",
"Your alarms are currently disabled!":"Twoje powiadomienia są obecnie wyłączone!",
"You Request couldn't not be handled":"Nie udało się wykonać tej czynności",
"Your location is not set. Distance settings won't be taken into account.":"Lokalizacja nie została ustawiona. Filtr dotyczący doległości nie będzie funkcjonować.",
"Distance":"Odległość",
Expand Down
2 changes: 1 addition & 1 deletion locales/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"MIN Rank":"Ranking Min.",
"MAX Rank":"Ranking Max.",
"AREAS":"ÁREAS",
"Your alarms are currently disabled !":"Os teus alarmes encontram-se desativados!",
"Your alarms are currently disabled!":"Os teus alarmes encontram-se desativados!",
"You Request couldn't not be handled":"O teu pedido não pode ser processado.",
"Your location is not set. Distance settings won't be taken into account.":"A tua localização não está definida. Pedidos de alertas com distância não serão enviados até que definas a tua localização.",
"Distance":"Distância",
Expand Down
47 changes: 27 additions & 20 deletions set_location.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,41 @@
include "./config.php";
include "./db_connect.php";

$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'];
}
}
if ( isset($_GET['lat']) && isset($_GET['lon']) ) {

$street = str_replace(" ", "%20", $_POST['street']);
$city = str_replace(" ", "%20", $_POST['city']);
$lat = $_GET['lat'];
$lon = $_GET['lon'];

} else {

$filepath="$nominatim/?addressdetails=1&q=".$street."%20".$city."&format=json&limit=1";
$request = file_get_contents($filepath);
$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'];
}
}

if ( $request == "[]" ) {
header("Location: $redirect_url?return=error_update_location");
exit();
$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);
$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; }
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 = ?");
Expand Down

0 comments on commit 04d4a7b

Please sign in to comment.