From e8bfe6ed7fb123e545f07fa8208d70149a127c32 Mon Sep 17 00:00:00 2001 From: phl0 Date: Wed, 15 Nov 2023 17:11:45 +0100 Subject: [PATCH 1/2] HamQTH Lookup for search --- application/controllers/Logbook.php | 27 ++++++++++++++++++++++++++- application/libraries/Hamqth.php | 2 +- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/application/controllers/Logbook.php b/application/controllers/Logbook.php index 223f1c9c..fa5d33f3 100644 --- a/application/controllers/Logbook.php +++ b/application/controllers/Logbook.php @@ -937,8 +937,33 @@ function worked_grid_before($gridsquare, $type, $band, $mode) if (isset($data['callsign']['error'])) { $data['error'] = $data['callsign']['error']; } + } else 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); + } + + $data['callsign'] = $this->hamqth->search($id, $this->session->userdata('hamqth_session_key')); + + // If HamQTH session has expired, start a new session and retry the search. + if($data['callsign']['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); + $data['callsign'] = $this->hamqth->search($callsign, $this->session->userdata('hamqth_session_key')); + } + if (isset($data['callsign']['gridsquare'])) { + $CI = &get_instance(); + $CI->load->model('logbook_model'); + $data['grid_worked'] = $CI->logbook_model->check_if_grid_worked_in_logbook(strtoupper(substr($data['callsign']['gridsquare'],0,4)), 0, $this->session->userdata('user_default_band')); + } + if (isset($data['callsign']['error'])) { + $data['error'] = $data['callsign']['error']; + } } else { - $data['error'] = 'Lookup not configured or set to hamqth. Currently only qrz is supported.'; + $data['error'] = 'Lookup not configured. Please review configuration.'; } /*else { // Lookup using hamli $this->load->library('hamli'); diff --git a/application/libraries/Hamqth.php b/application/libraries/Hamqth.php index f2646735..1b71449b 100644 --- a/application/libraries/Hamqth.php +++ b/application/libraries/Hamqth.php @@ -71,7 +71,7 @@ class Hamqth { // Create XML object $xml = simplexml_load_string($xml); - if (empty($xml)) return; + if (!empty($xml->session->error)) return $data['error'] = $xml->session->error; // Return Required Fields $data['callsign'] = (string)$xml->search->callsign; From 528c2ed3fd8078f1a11a628940c83fe4c8dd8158 Mon Sep 17 00:00:00 2001 From: phl0 Date: Wed, 15 Nov 2023 20:17:44 +0100 Subject: [PATCH 2/2] Implement hamqth lookup for QSO log view --- application/controllers/Logbook.php | 40 +++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/application/controllers/Logbook.php b/application/controllers/Logbook.php index fa5d33f3..3fa7c0f7 100644 --- a/application/controllers/Logbook.php +++ b/application/controllers/Logbook.php @@ -851,16 +851,40 @@ function worked_grid_before($gridsquare, $type, $band, $mode) $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); } - $callsign['callsign'] = $this->qrz->search($id, $this->session->userdata('qrz_session_key'), $this->config->item('use_fullname')); + $callsign['callsign'] = $this->qrz->search($id, $this->session->userdata('qrz_session_key'), $this->config->item('use_fullname')); - if (empty($callsign['callsign']['callsign'])) - { - $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); - $callsign['callsign'] = $this->qrz->search($id, $this->session->userdata('qrz_session_key'), $this->config->item('use_fullname')); - } + if (empty($callsign['callsign']['callsign'])) { + $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); + $callsign['callsign'] = $this->qrz->search($id, $this->session->userdata('qrz_session_key'), $this->config->item('use_fullname')); + } + } else 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); + } + + $callsign['callsign'] = $this->hamqth->search($id, $this->session->userdata('hamqth_session_key')); + + // If HamQTH session has expired, start a new session and retry the search. + if($callsign['callsign']['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); + $callsign['callsign'] = $this->hamqth->search($callsign, $this->session->userdata('hamqth_session_key')); + } + if (isset($data['callsign']['gridsquare'])) { + $CI = &get_instance(); + $CI->load->model('logbook_model'); + $callsign['grid_worked'] = $CI->logbook_model->check_if_grid_worked_in_logbook(strtoupper(substr($data['callsign']['gridsquare'],0,4)), 0, $this->session->userdata('user_default_band')); + } + if (isset($callsign['callsign']['error'])) { + $callsign['error'] = $callsign['callsign']['error']; + } } else { - $callsign['error'] = 'Lookup not configured or set to hamqth. Currently only qrz is supported.'; + $callsign['error'] = 'Lookup not configured. Please review configuration.'; } // There's no hamli integration? Disabled for now.