diff --git a/application/controllers/Logbook.php b/application/controllers/Logbook.php index 95cb05ff..bf0d9bd1 100644 --- a/application/controllers/Logbook.php +++ b/application/controllers/Logbook.php @@ -878,7 +878,9 @@ class Logbook extends CI_Controller { /* return station bearing */ - function searchbearing($locator, $station_id = null) { + function searchbearing() { + $locator = xss_clean($this->input->post('grid')); + $station_id = xss_clean($this->input->post('stationProfile')); $this->load->library('Qra'); if($locator != null) { diff --git a/application/libraries/Qra.php b/application/libraries/Qra.php index a9122c29..627fade1 100644 --- a/application/libraries/Qra.php +++ b/application/libraries/Qra.php @@ -26,9 +26,12 @@ class Qra { $my = qra2latlong($tx); $stn = qra2latlong($rx); - $bearing = bearing($my[0], $my[1], $stn[0], $stn[1], $unit); - - return $bearing; + if ($my !== false && $stn !== false ) { + $bearing = bearing($my[0], $my[1], $stn[0], $stn[1], $unit); + return $bearing; + } else { + return false; + } } /* @@ -168,6 +171,11 @@ function qra2latlong($strQRA) { if (substr_count($strQRA, ',') == 3) { // Handle grid corners $grids = explode(',', $strQRA); + $gridlengths = array(strlen($grids[0]), strlen($grids[1]), strlen($grids[2]), strlen($grids[3])); + $same = array_count_values($gridlengths); + if (count($same) != 1) { + return false; + } $coords = array(0, 0); for($i=0; $i<4; $i++) { $cornercoords[$i] = qra2latlong($grids[$i]); @@ -178,6 +186,9 @@ function qra2latlong($strQRA) { } else if (substr_count($strQRA, ',') == 1) { // Handle grid lines $grids = explode(',', $strQRA); + if (strlen($grids[0]) != strlen($grids[1])) { + return false; + } $coords = array(0, 0); for($i=0; $i<2; $i++) { $linecoords[$i] = qra2latlong($grids[$i]); diff --git a/assets/js/sections/qso.js b/assets/js/sections/qso.js index 9e2c92d2..6b9cba5f 100644 --- a/assets/js/sections/qso.js +++ b/assets/js/sections/qso.js @@ -829,7 +829,20 @@ $("#locator").keyup(function(){ markers.addLayer(marker).addTo(mymap); }) - $('#locator_info').load(base_url +"index.php/logbook/searchbearing/" + $(this).val() + "/" + $('#stationProfile').val()).fadeIn("slow"); + $.ajax({ + url: base_url + 'index.php/logbook/searchbearing', + type: 'post', + data: { + grid: $(this).val(), + stationProfile: $('#stationProfile').val() + }, + success: function(data) { + $('#locator_info').html(data).fadeIn("slow"); + }, + error: function() { + $('#locator_info').text("Error loading bearing and distance").fadeIn("slow"); + }, + }); $.get(base_url + 'index.php/logbook/searchdistance/' + $(this).val() + "/" + $('#stationProfile').val(), function(result) { document.getElementById("distance").value = result; });