From b39715e0c5054af3bc8abe2b5f1335bc43fbf53a Mon Sep 17 00:00:00 2001 From: Randy T Date: Tue, 30 Mar 2021 21:04:49 -0400 Subject: [PATCH 1/3] Add function for Gridsquare Update --- application/controllers/Update.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/application/controllers/Update.php b/application/controllers/Update.php index fca57ffc..f77f22d8 100644 --- a/application/controllers/Update.php +++ b/application/controllers/Update.php @@ -224,6 +224,11 @@ class Update extends CI_Controller { $this->logbook_model->check_missing_dxcc_id($all); } + + public function check_missing_grid($all = false){ + $this->load->model('logbook_model'); + $this->logbook_model->check_missing_grid_id($all); + } public function update_clublog_scp() { $strFile = "./updates/clublog_scp.txt"; From f1b5f00bcdf9ab5f78cbe71632041e60ffb2d968 Mon Sep 17 00:00:00 2001 From: Randy T Date: Tue, 30 Mar 2021 21:12:55 -0400 Subject: [PATCH 2/3] Add function for Gridsquare Update --- application/models/Logbook_model.php | 63 ++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/application/models/Logbook_model.php b/application/models/Logbook_model.php index 397e030c..c1a8e4cf 100755 --- a/application/models/Logbook_model.php +++ b/application/models/Logbook_model.php @@ -2170,7 +2170,70 @@ class Logbook_model extends CI_Model { print("$count updated\n"); } + + public function check_missing_grid_id($all){ + // get all records with no COL_GRIDSQUARE + $this->db->select("COL_PRIMARY_KEY, COL_CALL, COL_TIME_ON, COL_TIME_OFF"); + // check which to update - records with no Gridsquare or all records + $this->db->where("COL_GRIDSQUARE is NULL or COL_GRIDSQUARE = ''"); + + $r = $this->db->get($this->config->item('table_name')); + + $count = 0; + $this->db->trans_start(); + if ($r->num_rows() > 0){ + foreach($r->result_array() as $row){ + $callsign = $row['COL_CALL']; + if ($this->config->item('callbook') == "qrz" && $this->config->item('qrz_username') != null && $this->config->item('qrz_password') != null) + { + // Lookup using QRZ + $this->load->library('qrz'); + + if(!$this->session->userdata('qrz_session_key')) { + $qrz_session_key = $this->qrz->session($this->config->item('qrz_username'), $this->config->item('qrz_password')); + $this->session->set_userdata('qrz_session_key', $qrz_session_key); + } + + $callbook = $this->qrz->search($callsign, $this->session->userdata('qrz_session_key')); + } + + if ($this->config->item('callbook') == "hamqth" && $this->config->item('hamqth_username') != null && $this->config->item('hamqth_password') != null) + { + // Load the HamQTH library + $this->load->library('hamqth'); + + if(!$this->session->userdata('hamqth_session_key')) { + $hamqth_session_key = $this->hamqth->session($this->config->item('hamqth_username'), $this->config->item('hamqth_password')); + $this->session->set_userdata('hamqth_session_key', $hamqth_session_key); + } + + $callbook = $this->hamqth->search($callsign, $this->session->userdata('hamqth_session_key')); + + // If HamQTH session has expired, start a new session and retry the search. + if($callbook['error'] == "Session does not exist or expired") { + $hamqth_session_key = $this->hamqth->session($this->config->item('hamqth_username'), $this->config->item('hamqth_password')); + $this->session->set_userdata('hamqth_session_key', $hamqth_session_key); + $callbook = $this->hamqth->search($callsign, $this->session->userdata('hamqth_session_key')); + } + } + if (isset($callbook)) + { + $return['callsign_qra'] = $callbook['gridsquare']; + } + if ($return['callsign_qra'] != ''){ + $sql = sprintf("update %s set COL_GRIDSQUARE = '%s' where COL_PRIMARY_KEY=%d", + $this->config->item('table_name'), $return['callsign_qra'], $row['COL_PRIMARY_KEY']); + $this->db->query($sql); + printf("Updating %s to %s\n
", $row['COL_PRIMARY_KEY'], $return['callsign_qra']); + $count++; + } + } + } + $this->db->trans_complete(); + + print("$count updated\n"); + } public function check_for_station_id() { $this->db->where('station_id =', 'NULL'); From c20c9bb59f195d05f0a9b796799fdceed0978246 Mon Sep 17 00:00:00 2001 From: Peter Goodhall Date: Wed, 31 Mar 2021 15:41:11 +0100 Subject: [PATCH 3/3] Make sure that VUCC_Grid hasn't been filled in before adding a gridsquare to the COL_gridsquare --- application/models/Logbook_model.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/application/models/Logbook_model.php b/application/models/Logbook_model.php index c1a8e4cf..f95f39d9 100755 --- a/application/models/Logbook_model.php +++ b/application/models/Logbook_model.php @@ -2178,6 +2178,9 @@ class Logbook_model extends CI_Model { // check which to update - records with no Gridsquare or all records $this->db->where("COL_GRIDSQUARE is NULL or COL_GRIDSQUARE = ''"); + $where = "(COL_GRIDSQUARE is NULL or COL_GRIDSQUARE = '') AND (COL_VUCC_GRIDS is NULL or COL_VUCC_GRIDS = '')"; + $this->db->where($where); + $r = $this->db->get($this->config->item('table_name')); $count = 0;