diff --git a/application/controllers/Logbook.php b/application/controllers/Logbook.php index 56f98ae8..b2eaee15 100644 --- a/application/controllers/Logbook.php +++ b/application/controllers/Logbook.php @@ -952,6 +952,36 @@ class Logbook extends CI_Controller { return ""; } + /* return distance */ + function searchdistance($locator, $station_id = null) { + $this->load->library('Qra'); + + if($locator != null) { + if (isset($station_id)) { + // be sure that station belongs to user + $this->load->model('Stations'); + if (!$this->Stations->check_station_is_accessible($station_id)) { + return 0; + } + + // get station profile + $station_profile = $this->Stations->profile_clean($station_id); + + // get locator + $mylocator = $station_profile->station_gridsquare; + } else if($this->session->userdata('user_locator') != null){ + $mylocator = $this->session->userdata('user_locator'); + } else { + $mylocator = $this->config->item('locator'); + } + + $distance = $this->qra->distance($mylocator, $locator, 'K'); + + echo round($distance, 0); + } + return 0; + } + /* return station bearing */ function bearing($locator, $unit = 'M', $station_id = null) { $this->load->library('Qra'); diff --git a/assets/js/sections/qso.js b/assets/js/sections/qso.js index d2062dc6..b72576ce 100644 --- a/assets/js/sections/qso.js +++ b/assets/js/sections/qso.js @@ -711,6 +711,9 @@ $("#locator").keyup(function(){ }) $('#locator_info').load("logbook/searchbearing/" + $(this).val() + "/" + $('#stationProfile').val()).fadeIn("slow"); + $.get('logbook/searchdistance/' + $(this).val() + "/" + $('#stationProfile').val(), function(result) { + document.getElementById("distance").value = result; + }); } } });