From 614452b07e83828ea5c9d27d0a9ea823b4188c87 Mon Sep 17 00:00:00 2001 From: KT3PJ Date: Tue, 27 Jul 2021 18:49:54 -0400 Subject: [PATCH] Add the gridsquare from LotW QSL to the logbook The gridsquare from the QSL will now update the log if the gridsquare was not previously populated, or if the LotW gridsquare is more specific than what previously existed. Previously the gridsquare was not being used from the LotW QSL record. This will enable the map above the logbook to more accurately display where the QSL was with instead of default values. - Add 'qsl_gridsquare' to the logbook_model.php:lotw_update implementation. - Refactor code in lotw_update to remove duplicate code. - Add gridsquare into the LotW output table on what is imported. --- application/controllers/Lotw.php | 11 ++++++- application/models/Logbook_model.php | 47 +++++++++++++++++++--------- 2 files changed, 42 insertions(+), 16 deletions(-) diff --git a/application/controllers/Lotw.php b/application/controllers/Lotw.php index 084b83b2..49be4a47 100644 --- a/application/controllers/Lotw.php +++ b/application/controllers/Lotw.php @@ -466,6 +466,7 @@ class Lotw extends CI_Controller { $tableheaders .= "LoTW QSL Received"; $tableheaders .= "Date LoTW Confirmed"; $tableheaders .= "State"; + $tableheaders .= "Gridsquare"; $tableheaders .= "Log Status"; $tableheaders .= "LoTW Status"; $tableheaders .= ""; @@ -512,8 +513,15 @@ class Lotw extends CI_Controller { } else { $state = ""; } + // Present only if the QSLing station specified a single valid grid square value in its station location uploaded to LoTW. + if (isset($record['gridsquare'])) { + $qsl_gridsquare = $record['gridsquare']; + } else { + $qsl_gridsquare = ""; + } - $lotw_status = $this->logbook_model->lotw_update($time_on, $record['call'], $record['band'], $qsl_date, $record['qsl_rcvd'], $state); + + $lotw_status = $this->logbook_model->lotw_update($time_on, $record['call'], $record['band'], $qsl_date, $record['qsl_rcvd'], $state, $qsl_gridsquare); } @@ -525,6 +533,7 @@ class Lotw extends CI_Controller { $table .= "".$record['qsl_rcvd'].""; $table .= "".$qsl_date.""; $table .= "".$state.""; + $table .= "".$qsl_gridsquare.""; $table .= "QSO Record: ".$status.""; $table .= "LoTW Record: ".$lotw_status.""; $table .= ""; diff --git a/application/models/Logbook_model.php b/application/models/Logbook_model.php index f6d773c2..7bdba991 100755 --- a/application/models/Logbook_model.php +++ b/application/models/Logbook_model.php @@ -1401,28 +1401,45 @@ class Logbook_model extends CI_Model { } } - function lotw_update($datetime, $callsign, $band, $qsl_date, $qsl_status, $state) { + function lotw_update($datetime, $callsign, $band, $qsl_date, $qsl_status, $state, $qsl_gridsquare) { - if($state != "") { - $data = array( - 'COL_LOTW_QSLRDATE' => $qsl_date, - 'COL_LOTW_QSL_RCVD' => $qsl_status, - 'COL_LOTW_QSL_SENT' => 'Y', - 'COL_STATE' => $state - ); - } else { - $data = array( - 'COL_LOTW_QSLRDATE' => $qsl_date, - 'COL_LOTW_QSL_RCVD' => $qsl_status, - 'COL_LOTW_QSL_SENT' => 'Y' - ); - } + $data = array( + 'COL_LOTW_QSLRDATE' => $qsl_date, + 'COL_LOTW_QSL_RCVD' => $qsl_status, + 'COL_LOTW_QSL_SENT' => 'Y' + ); + if($state != "") { + $data['COL_STATE'] = $state; + } $this->db->where('date_format(COL_TIME_ON, \'%Y-%m-%d %H:%i\') = "'.$datetime.'"'); $this->db->where('COL_CALL', $callsign); $this->db->where('COL_BAND', $band); $this->db->update($this->config->item('table_name'), $data); + unset($data); + + if($qsl_gridsquare != "") { + $data = array( + 'COL_GRIDSQUARE' => $qsl_gridsquare + ); + $this->db->where('date_format(COL_TIME_ON, \'%Y-%m-%d %H:%i\') = "'.$datetime.'"'); + $this->db->where('COL_CALL', $callsign); + $this->db->where('COL_BAND', $band); + if(strlen($qsl_gridsquare) > 4) { + $this->db->group_start(); + $this->db->where('COL_GRIDSQUARE', ""); + $this->db->or_where('COL_GRIDSQUARE', substr($qsl_gridsquare, 0, 4)); + if(strlen($qsl_gridsquare) > 6) { + $this->db->or_where('COL_GRIDSQUARE', substr($qsl_gridsquare, 0, 6)); + } + $this->db->group_end(); + } else { + $this->db->where('COL_GRIDSQUARE', ""); + } + + $this->db->update($this->config->item('table_name'), $data); + } return "Updated"; }