diff --git a/application/controllers/Qrbcalc.php b/application/controllers/Qrbcalc.php index 2056ae154..247b492e6 100644 --- a/application/controllers/Qrbcalc.php +++ b/application/controllers/Qrbcalc.php @@ -23,8 +23,13 @@ class Qrbcalc extends CI_Controller { } public function calculate() { - $locator1 = $this->input->post("locator1"); - $locator2 = $this->input->post("locator2"); + + if(!$this->load->is_loaded('Qra')) { + $this->load->library('Qra'); + } + + $locator1 = strtoupper($this->input->post("locator1", TRUE)); + $locator2 = strtoupper($this->input->post("locator2", TRUE)); if ($this->session->userdata('user_measurement_base') == NULL) { $measurement_base = $this->config->item('measurement_base'); @@ -33,34 +38,39 @@ class Qrbcalc extends CI_Controller { $measurement_base = $this->session->userdata('user_measurement_base'); } - switch ($measurement_base) { - case 'M': - $var_dist = " miles"; - break; - case 'N': - $var_dist = " nautic miles"; - break; - case 'K': - $var_dist = " kilometers"; - break; - } - - if(!$this->load->is_loaded('Qra')) { - $this->load->library('Qra'); - } - - $data['result'] = $this->qra->bearing($locator1, $locator2, $measurement_base); - $data['distance'] = $this->qra->distance($locator1, $locator2, $measurement_base) . $var_dist; - $data['bearing'] = $this->qra->get_bearing($locator1, $locator2) . "º"; $latlng1 = $this->qra->qra2latlong($locator1); $latlng2 = $this->qra->qra2latlong($locator2); $latlng1[0] = number_format((float)$latlng1[0], 3, '.', '');; $latlng1[1] = number_format((float)$latlng1[1], 3, '.', '');; $latlng2[0] = number_format((float)$latlng2[0], 3, '.', '');; $latlng2[1] = number_format((float)$latlng2[1], 3, '.', '');; + $distance = $this->qra->distance($locator1, $locator2, $measurement_base); + $text_latlng1 = $locator1 . ' ' . sprintf(__("Latitude: %s, Longitude: %s"), $latlng1[0], $latlng1[1]); + $text_latlng2 = $locator2 . ' ' . sprintf(__("Latitude: %s, Longitude: %s"), $latlng2[0], $latlng2[1]); + + switch ($measurement_base) { + case 'M': + $var_dist = sprintf(_ngettext("The distance between %s and %s is %s mile.", "The distance between %s and %s is %s miles.", intval($distance)), $locator1, $locator2, $distance); + break; + case 'N': + $var_dist = sprintf(_ngettext("The distance between %s and %s is %s nautical mile.", "The distance between %s and %s is %s nautical miles.", intval($distance)), $locator1, $locator2, $distance); + break; + case 'K': + $var_dist = sprintf(_ngettext("The distance between %s and %s is %s kilometer.", "The distance between %s and %s is %s kilometers.", intval($distance)), $locator1, $locator2, $distance); + break; + } + + $data['result'] = $this->qra->bearing($locator1, $locator2, $measurement_base); + $data['distance'] = $var_dist; + $data['bearing'] = sprintf(__("The bearing is %s."), $this->qra->get_bearing($locator1, $locator2) . "º"); $data['latlng1'] = $latlng1; + $data['text_latlng1'] = $text_latlng1; + $data['text_latlng2'] = $text_latlng2; $data['latlng2'] = $latlng2; + + $data['latlong_info_text'] = __("Negative latitudes are south of the equator, negative longitudes are west of Greenwich."); + header('Content-Type: application/json'); echo json_encode($data); } diff --git a/application/views/interface_assets/footer.php b/application/views/interface_assets/footer.php index bc0066750..4625b603a 100644 --- a/application/views/interface_assets/footer.php +++ b/application/views/interface_assets/footer.php @@ -46,6 +46,8 @@ var lang_admin_clear = ""; var lang_lotw_propmode_hint = ""; var lang_no_states_for_dxcc_available = ""; + var lang_qrbcalc_title = ''; + var lang_qrbcalc_errmsg = ''; diff --git a/application/views/qrbcalc/index.php b/application/views/qrbcalc/index.php index ecf7ad8e1..2e7aa2d6f 100644 --- a/application/views/qrbcalc/index.php +++ b/application/views/qrbcalc/index.php @@ -2,14 +2,14 @@
- " aria-label="locator1"> + " aria-label="locator1">
- +
diff --git a/assets/js/sections/common.js b/assets/js/sections/common.js index 6ea5bc158..d6ae419d3 100644 --- a/assets/js/sections/common.js +++ b/assets/js/sections/common.js @@ -602,9 +602,9 @@ function spawnQrbCalculator(locator1, locator2) { type: 'post', success: function (html) { BootstrapDialog.show({ - title: 'Compute QRB and QTF', + title: lang_qrbcalc_title, size: BootstrapDialog.SIZE_WIDE, - cssClass: 'lookup-dialog', + cssClass: 'lookup-dialog bg-black bg-opacity-50', nl2br: false, message: html, onshown: function(dialog) { @@ -666,28 +666,36 @@ function calculateQrb() { 'locator2': locator2}, success: function (html) { - var result = "
Negative latitudes are south of the equator, negative longitudes are west of Greenwich.
"; - result += ' ' + locator1.toUpperCase() + ' Latitude = ' + html['latlng1'][0] + ' Longitude = ' + html['latlng1'][1] + '
'; - result += ' ' + locator2.toUpperCase() + ' Latitude = ' + html['latlng2'][0] + ' Longitude = ' + html['latlng2'][1] + '
'; - result += 'Distance between ' + locator1.toUpperCase() + ' and ' + locator2.toUpperCase() + ' is ' + html['distance'] + '.
'; - result += 'The bearing is ' + html['bearing'] + '.
'; + var result = "
" + html['latlong_info_text'] + "

"; + result += html['text_latlng1'] + '
'; + result += html['text_latlng2'] + '

'; + result += html['distance'] + ' '; + result += html['bearing'] + '
'; $(".qrbResult").html(result); newpath(html['latlng1'], html['latlng2'], locator1, locator2); } }); } else { - $('.qrbResult').html(''); + $("#mapqrb").hide(); + $('.qrbResult').html(''); } } function validateLocator(locator) { - vucc_gridno = locator.split(",").length; - if(vucc_gridno == 3 || vucc_gridno > 4) { + const regex = /^[A-R]{2}[0-9]{2}([A-X]{2}([0-9]{2}([A-X]{2})?)?)?$/i; + const locators = locator.split(","); + + if (locators.length === 3 || locators.length > 4) { return false; } - if(locator.length < 4 && !(/^[a-rA-R]{2}[0-9]{2}[a-xA-X]{0,2}[0-9]{0,2}[a-xA-X]{0,2}$/.test(locator))) { - return false; + + for (let i = 0; i < locators.length; i++) { + let loc = locators[i].trim(); + + if (!regex.test(loc)) { + return false; + } } return true;