From 02c10858c0701cc80ce964efe0d0be9d98d0e0c4 Mon Sep 17 00:00:00 2001 From: Peter Goodhall Date: Fri, 16 Aug 2019 12:06:19 +0100 Subject: [PATCH] When you change the QRA field in the QSO input, it will check gridsquare and return whether worked or not based on SAT or if sat_name isn't filled out it will do band/mode --- application/controllers/Logbook.php | 32 ++++++++++++ application/views/interface_assets/footer.php | 51 ++++++++++++++++++- 2 files changed, 82 insertions(+), 1 deletion(-) diff --git a/application/controllers/Logbook.php b/application/controllers/Logbook.php index 865b391f..d0071e10 100755 --- a/application/controllers/Logbook.php +++ b/application/controllers/Logbook.php @@ -161,6 +161,38 @@ class Logbook extends CI_Controller { return false; } + /* + * Function: jsonlookupgrid + * + * Usage: Used to look up gridsquares when creating a QSO to check whether its needed or not + */ + function jsonlookupgrid($gridsquare, $type, $band, $mode) { + $return = [ + "workedBefore" => false, + ]; + + if($type == "SAT") { + $this->db->where('COL_PROP_MODE', 'SAT'); + } else { + $this->db->where('COL_MODE', $mode); + $this->db->where('COL_BAND', $band); + $this->db->where('COL_PROP_MODE !=','SAT'); + + } + + $this->db->like('SUBSTRING(COL_GRIDSQUARE, 1, 4)', substr($gridsquare, 0, 4)); + $query = $this->db->get($this->config->item('table_name'), 1, 0); + foreach ($query->result() as $workedBeforeRow) + { + $return['workedBefore'] = true; + } + + header('Content-Type: application/json'); + echo json_encode($return, JSON_PRETTY_PRINT); + + return; + } + /* Used to generate maps for displaying on /logbook/ */ function qso_map() { diff --git a/application/views/interface_assets/footer.php b/application/views/interface_assets/footer.php index 3caefa38..59d09b64 100644 --- a/application/views/interface_assets/footer.php +++ b/application/views/interface_assets/footer.php @@ -384,7 +384,56 @@ $(document).ready(function(){ if ($(this).val()) { var qra_input = $(this).val(); - if(qra_input.length > 3) { + var qra_lookup = qra_input.substring(0, 4); + + if(qra_lookup.length >= 4) { + + // Check Log if satname is provided + if($("#sat_name" ).val() != "") { + + //logbook/jsonlookupgrid/io77/SAT/0/0 + + $.getJSON('logbook/jsonlookupgrid/' + qra_lookup.toUpperCase() + '/SAT/0/0', function(result) + { + // Reset CSS values before updating + $('#locator').removeClass("workedGrid"); + $('#locator').removeClass("newGrid"); + $('#locator').attr('title', ''); + + if (result.workedBefore) + { + $('#locator').addClass("workedGrid"); + $('#locator').attr('title', 'Grid was already worked in the past'); + } + else + { + $('#locator').addClass("newGrid"); + $('#locator').attr('title', 'New grid!'); + } + }) + } else { + $.getJSON('logbook/jsonlookupgrid/' + qra_lookup.toUpperCase() + '/0/' + $("#band").val() +'/' + $("#mode").val(), function(result) + { + // Reset CSS values before updating + $('#locator').removeClass("workedGrid"); + $('#locator').removeClass("newGrid"); + $('#locator').attr('title', ''); + + if (result.workedBefore) + { + $('#locator').addClass("workedGrid"); + $('#locator').attr('title', 'Grid was already worked in the past'); + } + else + { + $('#locator').addClass("newGrid"); + $('#locator').attr('title', 'New grid!'); + } + }) + } + } + + if(qra_input.length >= 4) { $.getJSON('logbook/qralatlngjson/' + $(this).val(), function(result) { // Set Map to Lat/Long