From dfe682b4bfad032aa2739233809f7b528e022511 Mon Sep 17 00:00:00 2001 From: Luca <61653175+iu2frl@users.noreply.github.com> Date: Tue, 9 Dec 2025 17:44:25 +0100 Subject: [PATCH] Implementing callbook failover logic --- application/libraries/Callbook.php | 46 +++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 10 deletions(-) diff --git a/application/libraries/Callbook.php b/application/libraries/Callbook.php index ba51201f5..0bc80ab56 100644 --- a/application/libraries/Callbook.php +++ b/application/libraries/Callbook.php @@ -18,7 +18,40 @@ class Callbook { // Implement the following: // - Implement callsign reduced logic public function getCallbookData($callsign) { - switch ($this->ci->config->item('callbook')) { + // Load callbook configuration from config.php + $source_callbooks = $this->ci->config->item('callbook'); + + // Check if the source callbook is a single element or an array + if (is_array($source_callbooks)) { + // Parse each callbook in the array until we get a valid result + foreach ($source_callbooks as $source) { + $callbook = $this->queryCallbook($callsign, $source); + if (!isset($callbook['error'])) { + break; + } + } + } + else { + // Single callbook lookup (default behavior) + $callbook = $this->queryCallbook($callsign, $source_callbooks); + } + + // Handle callbook specific fields + if (! array_key_exists('geoloc', $callbook)) { + $callbook['geoloc'] = ''; + } + + // qrz.com gives AA00aa if the user deleted his grid from the profile + $this->ci->load->library('qra'); + if (!array_key_exists('gridsquare', $callbook) || !$this->ci->qra->validate_grid($callbook['gridsquare'])) { + $callbook['gridsquare'] = ''; + } + + return $callbook; + } + + function queryCallbook($callsign, $source) { + switch ($source) { case 'qrz': if ($this->ci->config->item('qrz_username') == null || $this->ci->config->item('qrz_password') == null) { $callbook['error'] = 'Lookup not configured. Please review configuration.'; @@ -46,15 +79,8 @@ class Callbook { default: $callbook['error'] = 'No callbook defined. Please review configuration.'; } - // Handle callbook specific fields - if (! array_key_exists('geoloc', $callbook)) { - $callbook['geoloc'] = ''; - } - // qrz.com gives AA00aa if the user deleted his grid from the profile - $this->ci->load->library('qra'); - if (!array_key_exists('gridsquare', $callbook) || !$this->ci->qra->validate_grid($callbook['gridsquare'])) { - $callbook['gridsquare'] = ''; - } + + log_message('debug', 'Callbook lookup for '.$callsign.' using '.$source.': '.(isset($callbook['error']) ? $callbook['error'] : 'Success')); return $callbook; }