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 750e1352..027a9536 100755 --- a/application/models/Logbook_model.php +++ b/application/models/Logbook_model.php @@ -1477,28 +1477,49 @@ 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); + $this->db->group_start(); + $this->db->where('COL_VUCC_GRIDS'); + $this->db->or_where('COL_VUCC_GRIDS', ''); + $this->db->group_end(); + 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"; }