From 3efcbf0b0d659c9d974522254db2f1ab107281dd Mon Sep 17 00:00:00 2001 From: phl0 Date: Fri, 25 Aug 2023 16:26:25 +0200 Subject: [PATCH 1/7] Convert bearing lookup to POST request --- application/controllers/Logbook.php | 4 +++- application/libraries/Qra.php | 17 ++++++++++++++--- assets/js/sections/qso.js | 15 ++++++++++++++- 3 files changed, 31 insertions(+), 5 deletions(-) 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; }); From 6b9ad004adc352d4caff4c1e52bfc02e4f0e9313 Mon Sep 17 00:00:00 2001 From: phl0 Date: Mon, 28 Aug 2023 15:21:56 +0200 Subject: [PATCH 2/7] Changed qralatlng to post --- application/controllers/Logbook.php | 4 ++- assets/js/sections/qso.js | 41 ++++++++++++++++++----------- 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/application/controllers/Logbook.php b/application/controllers/Logbook.php index bf0d9bd1..7c198db7 100644 --- a/application/controllers/Logbook.php +++ b/application/controllers/Logbook.php @@ -1012,7 +1012,9 @@ class Logbook extends CI_Controller { return $latlng; } - function qralatlngjson($qra) { + function qralatlngjson() { + $qra = xss_clean($this->input->post('qra')); + log_message('debug','TEST QRA '.$qra); $this->load->library('Qra'); $latlng = $this->qra->qra2latlong($qra); print json_encode($latlng); diff --git a/assets/js/sections/qso.js b/assets/js/sections/qso.js index 6b9cba5f..777a82db 100644 --- a/assets/js/sections/qso.js +++ b/assets/js/sections/qso.js @@ -811,23 +811,32 @@ $("#locator").keyup(function(){ } if(qra_input.length >= 4 && $(this).val().length > 0) { - $.getJSON(base_url + 'index.php/logbook/qralatlngjson/' + $(this).val(), function(result) - { - // Set Map to Lat/Long - markers.clearLayers(); - if (typeof result !== "undefined") { - var redIcon = L.icon({ - iconUrl: icon_dot_url, - iconSize: [18, 18], // size of the icon - }); + $.ajax({ + url: base_url + 'index.php/logbook/qralatlngjson', + type: 'post', + data: { + qra: $(this).val(), + }, + success: function(data) { + // Set Map to Lat/Long + result = JSON.parse(data); + markers.clearLayers(); + if (typeof result[0] !== "undefined" && typeof result[1] !== "undefined") { + var redIcon = L.icon({ + iconUrl: icon_dot_url, + iconSize: [18, 18], // size of the icon + }); - var marker = L.marker([result[0], result[1]], {icon: redIcon}); - mymap.setZoom(8); - mymap.panTo([result[0], result[1]]); - mymap.setView([result[0], result[1]], 8); - } - markers.addLayer(marker).addTo(mymap); - }) + var marker = L.marker([result[0], result[1]], {icon: redIcon}); + mymap.setZoom(8); + mymap.panTo([result[0], result[1]]); + mymap.setView([result[0], result[1]], 8); + markers.addLayer(marker).addTo(mymap); + } + }, + error: function() { + }, + }); $.ajax({ url: base_url + 'index.php/logbook/searchbearing', From 8929f17886ce54dbd7c3668a4e9dd2aa6a62e8cc Mon Sep 17 00:00:00 2001 From: phl0 Date: Tue, 29 Aug 2023 23:20:32 +0200 Subject: [PATCH 3/7] Also change ajax calls for QSO log view to post --- application/views/interface_assets/footer.php | 35 ++++++++++++------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/application/views/interface_assets/footer.php b/application/views/interface_assets/footer.php index 262abec5..3affa290 100644 --- a/application/views/interface_assets/footer.php +++ b/application/views/interface_assets/footer.php @@ -981,18 +981,29 @@ $(document).on('keypress',function(e) { var markers = L.layerGroup(); var pos = [51.505, -0.09]; var mymap = L.map('qsomap').setView(pos, 12); - station_gridsquare != "") { ?> - $.getJSON('logbook/qralatlngjson/', function(result) { - mymap.panTo([result[0], result[1]]); - pos = result; - }) - config->item('locator')) { ?> - $.getJSON('logbook/qralatlngjson/config->item('locator'); ?>', function(result) { - mymap.panTo([result[0], result[1]]); - pos = result; - }) - + $.ajax({ + url: base_url + 'index.php/logbook/qralatlngjson', + type: 'post', + data: { +station_gridsquare != "") { ?> + qra: '', +config->item('locator')) { ?> + qra: 'config->item('locator'); ?>', + + // Fallback to London in case all else fails + qra: 'IO91WM', + + }, + success: function(data) { + result = JSON.parse(data); + if (typeof result[0] !== "undefined" && typeof result[1] !== "undefined") { + mymap.panTo([result[0], result[1]]); + pos = result; + } + }, + error: function() { + }, + }); L.tileLayer('optionslib->get_option('option_map_tile_server');?>', { maxZoom: 18, From a84aa06965837b8f2e9e9a2c1707db44558a2502 Mon Sep 17 00:00:00 2001 From: phl0 Date: Tue, 29 Aug 2023 23:38:24 +0200 Subject: [PATCH 4/7] Move searchdistance to POST parameters --- application/controllers/Logbook.php | 4 +++- assets/js/sections/common.js | 15 +++++++++++++-- assets/js/sections/qso.js | 17 ++++++++++++++--- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/application/controllers/Logbook.php b/application/controllers/Logbook.php index 7c198db7..6efb85f5 100644 --- a/application/controllers/Logbook.php +++ b/application/controllers/Logbook.php @@ -917,7 +917,9 @@ class Logbook extends CI_Controller { } /* return distance */ - function searchdistance($locator, $station_id = null) { + function searchdistance() { + $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/assets/js/sections/common.js b/assets/js/sections/common.js index 158b1228..a5d1298a 100644 --- a/assets/js/sections/common.js +++ b/assets/js/sections/common.js @@ -153,8 +153,19 @@ function qso_edit(id) { $('#locator').change(function(){ if ($(this).val().length >= 4) { $('#locator_info').load(base_url + "index.php/logbook/searchbearing/" + $(this).val() + "/" + $('#stationProfile').val()).fadeIn("slow"); - $.get(base_url + 'index.php/logbook/searchdistance/' + $(this).val() + "/" + $('#stationProfile').val(), function(result) { - document.getElementById("distance").value = result; + $.ajax({ + url: base_url + 'index.php/logbook/searchdistance', + type: 'post', + data: { + grid: $(this).val(), + stationProfile: $('#stationProfile').val() + }, + success: function(data) { + document.getElementById("distance").value = data; + }, + error: function() { + document.getElementById("distance").value = 'Error calculating distance!'; + }, }); } }); diff --git a/assets/js/sections/qso.js b/assets/js/sections/qso.js index 777a82db..1d1e6a2e 100644 --- a/assets/js/sections/qso.js +++ b/assets/js/sections/qso.js @@ -849,11 +849,22 @@ $("#locator").keyup(function(){ $('#locator_info').html(data).fadeIn("slow"); }, error: function() { - $('#locator_info').text("Error loading bearing and distance").fadeIn("slow"); + $('#locator_info').text("Error loading bearing!").fadeIn("slow"); }, }); - $.get(base_url + 'index.php/logbook/searchdistance/' + $(this).val() + "/" + $('#stationProfile').val(), function(result) { - document.getElementById("distance").value = result; + $.ajax({ + url: base_url + 'index.php/logbook/searchdistance', + type: 'post', + data: { + grid: $(this).val(), + stationProfile: $('#stationProfile').val() + }, + success: function(data) { + document.getElementById("distance").value = data; + }, + error: function() { + document.getElementById("distance").value = 'Error calculating distance!'; + }, }); } } From a5f7a7629044bd3dc50e534d72e7772df912ef5f Mon Sep 17 00:00:00 2001 From: phl0 Date: Tue, 29 Aug 2023 23:40:51 +0200 Subject: [PATCH 5/7] Remove debug statement --- application/controllers/Logbook.php | 1 - 1 file changed, 1 deletion(-) diff --git a/application/controllers/Logbook.php b/application/controllers/Logbook.php index 6efb85f5..e5a68639 100644 --- a/application/controllers/Logbook.php +++ b/application/controllers/Logbook.php @@ -1016,7 +1016,6 @@ class Logbook extends CI_Controller { function qralatlngjson() { $qra = xss_clean($this->input->post('qra')); - log_message('debug','TEST QRA '.$qra); $this->load->library('Qra'); $latlng = $this->qra->qra2latlong($qra); print json_encode($latlng); From 23f45ee5be4398248d9a7b6fd1e0d0492eff0f0c Mon Sep 17 00:00:00 2001 From: phl0 Date: Tue, 29 Aug 2023 23:46:07 +0200 Subject: [PATCH 6/7] earch bearing also converted to POST --- assets/js/sections/common.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/assets/js/sections/common.js b/assets/js/sections/common.js index a5d1298a..4be6246b 100644 --- a/assets/js/sections/common.js +++ b/assets/js/sections/common.js @@ -152,7 +152,20 @@ function qso_edit(id) { $('#locator').change(function(){ if ($(this).val().length >= 4) { - $('#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!").fadeIn("slow"); + }, + }); $.ajax({ url: base_url + 'index.php/logbook/searchdistance', type: 'post', From 8135924345bfc528d1ecea8cc7cbe620ecdf875a Mon Sep 17 00:00:00 2001 From: phl0 Date: Tue, 29 Aug 2023 23:48:59 +0200 Subject: [PATCH 7/7] ADIF field should be filled with null in case of failure --- assets/js/sections/common.js | 2 +- assets/js/sections/qso.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/assets/js/sections/common.js b/assets/js/sections/common.js index 4be6246b..4f677864 100644 --- a/assets/js/sections/common.js +++ b/assets/js/sections/common.js @@ -177,7 +177,7 @@ function qso_edit(id) { document.getElementById("distance").value = data; }, error: function() { - document.getElementById("distance").value = 'Error calculating distance!'; + document.getElementById("distance").value = null; }, }); } diff --git a/assets/js/sections/qso.js b/assets/js/sections/qso.js index 1d1e6a2e..96b52ea4 100644 --- a/assets/js/sections/qso.js +++ b/assets/js/sections/qso.js @@ -863,7 +863,7 @@ $("#locator").keyup(function(){ document.getElementById("distance").value = data; }, error: function() { - document.getElementById("distance").value = 'Error calculating distance!'; + document.getElementById("distance").value = null; }, }); }