diff --git a/application/controllers/Logbook.php b/application/controllers/Logbook.php index 66ae7b81..56f98ae8 100644 --- a/application/controllers/Logbook.php +++ b/application/controllers/Logbook.php @@ -128,6 +128,7 @@ class Logbook extends CI_Controller { "dxcc" => false, "callsign_name" => "", "callsign_qra" => "", + "callsign_distance" => 0, "callsign_qth" => "", "callsign_iota" => "", "callsign_state" => "", @@ -155,6 +156,7 @@ class Logbook extends CI_Controller { $return['callsign_name'] = $this->logbook_model->call_name($callsign); $return['callsign_qra'] = $this->logbook_model->call_qra($callsign); + $return['callsign_distance'] = $this->distance($return['callsign_qra'], $station_id); $return['callsign_qth'] = $this->logbook_model->call_qth($callsign); $return['callsign_iota'] = $this->logbook_model->call_iota($callsign); $return['qsl_manager'] = $this->logbook_model->call_qslvia($callsign); @@ -186,6 +188,7 @@ class Logbook extends CI_Controller { { $return['callsign_name'] = $callbook['name']; $return['callsign_qra'] = $callbook['gridsquare']; + $return['callsign_distance'] = $callbook['distance']; $return['callsign_qth'] = $callbook['city']; $return['callsign_iota'] = $callbook['iota']; $return['callsign_state'] = $callbook['state']; @@ -979,6 +982,36 @@ class Logbook extends CI_Controller { return ""; } + /* return distance */ + function distance($locator, $station_id = null) { + $distance = 0; + $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'); + + } + return round($distance, 0); + } + function qralatlng($qra) { $this->load->library('Qra'); $latlng = $this->qra->qra2latlong($qra); diff --git a/application/models/Logbook_model.php b/application/models/Logbook_model.php index db8771de..d2b1a2dd 100755 --- a/application/models/Logbook_model.php +++ b/application/models/Logbook_model.php @@ -199,7 +199,7 @@ class Logbook_model extends CI_Model { 'COL_QTH' => $this->input->post('qth'), 'COL_PROP_MODE' => $prop_mode, 'COL_IOTA' => $this->input->post('iota_ref') == null ? '' : trim($this->input->post('iota_ref')), - 'COL_DISTANCE' => "0", + 'COL_DISTANCE' => $this->input->post('distance'), 'COL_FREQ_RX' => $this->parse_frequency($this->input->post('freq_display_rx')), 'COL_ANT_AZ' => null, 'COL_ANT_EL' => null, diff --git a/application/views/qso/index.php b/application/views/qso/index.php index 07918274..b649aa2f 100755 --- a/application/views/qso/index.php +++ b/application/views/qso/index.php @@ -142,6 +142,8 @@ + +
diff --git a/assets/js/sections/qso.js b/assets/js/sections/qso.js index df22c366..d2062dc6 100644 --- a/assets/js/sections/qso.js +++ b/assets/js/sections/qso.js @@ -506,6 +506,11 @@ $("#callsign").focusout(function() { $('#locator').val(result.callsign_qra); $('#locator_info').html(result.bearing); + if (result.callsign_distance != "" && result.callsign_distance != 0) + { + document.getElementById("distance").value = result.callsign_distance; + } + if (result.callsign_qra != "") { if (result.workedBefore)