From 8660d3d3ce6d0a22e5ecfbaf59743ca044dd6def Mon Sep 17 00:00:00 2001 From: Jeremy Brown Date: Tue, 10 Nov 2020 22:13:25 -0500 Subject: [PATCH] Does a lookup on qrz/hamqth on api or when entering by hand. Names and grid squares are returned and populated if not already set. Full names are set since they are not shown unless logged in. --- application/controllers/Logbook.php | 33 +------------------ application/models/Logbook_model.php | 48 ++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 32 deletions(-) diff --git a/application/controllers/Logbook.php b/application/controllers/Logbook.php index d7a781994..ddadc4b91 100755 --- a/application/controllers/Logbook.php +++ b/application/controllers/Logbook.php @@ -138,39 +138,8 @@ class Logbook extends CI_Controller { return; } + $callbook = $this->logbook_model->loadCallBook($callsign); - 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)) { diff --git a/application/models/Logbook_model.php b/application/models/Logbook_model.php index b5bd539bc..907379d86 100755 --- a/application/models/Logbook_model.php +++ b/application/models/Logbook_model.php @@ -1791,6 +1791,16 @@ class Logbook_model extends CI_Model { } } + // if we are doing lookups and grid square and name aren't set, do the lookup now + + $callbook = $this->loadCallBook(strtoupper($record['call'])); + if (isset($callbook)) { + $record['name']= $callbook['name']; + if (empty($record['gridsquare'])) { + $record['gridsquare'] = $callbook['gridsquare']; + } + } + if (!$skip) { // Create array with QSO Data use ?: @@ -2158,6 +2168,42 @@ class Logbook_model extends CI_Model { } } + public function loadCallBook($callsign) + { + 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')); + } + } + return $callbook; + } public function update_all_station_ids() { @@ -2271,4 +2317,6 @@ function validateADIFDate($date, $format = 'Ymd') $d = DateTime::createFromFormat($format, $date); return $d && $d->format($format) == $date; } + + ?>