From 5b3279d762af85961e9bb181d483b8e346a71a23 Mon Sep 17 00:00:00 2001 From: Andreas Kristiansen <6977712+AndreasK79@users.noreply.github.com> Date: Sun, 24 Nov 2024 15:34:56 +0100 Subject: [PATCH 01/17] [Callbook] Refactor so it's easier to add new callbooks --- application/controllers/Logbook.php | 164 ++++------------- application/libraries/Callbook.php | 262 +++++++++++++++++++++++++++ application/libraries/qrzcq.php | 147 +++++++++++++++ application/models/Logbook_model.php | 93 ++-------- 4 files changed, 457 insertions(+), 209 deletions(-) create mode 100644 application/libraries/Callbook.php create mode 100644 application/libraries/qrzcq.php diff --git a/application/controllers/Logbook.php b/application/controllers/Logbook.php index 9f77851bd3..ca03bc86a0 100644 --- a/application/controllers/Logbook.php +++ b/application/controllers/Logbook.php @@ -825,82 +825,33 @@ function partial($id, $band = null) { $html .= ""; return $html; } else { - 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); - } - $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 (isset($callsign['callsign']['dxcc'])) { - $this->load->model('logbook_model'); - $entity = $this->logbook_model->get_entity($callsign['callsign']['dxcc']); - $callsign['callsign']['dxcc_name'] = $entity['name']; - $callsign['dxcc_worked'] = $this->logbook_model->check_if_dxcc_worked_in_logbook($callsign['callsign']['dxcc'], null, $this->session->userdata('user_default_band')); - $callsign['dxcc_confirmed'] = $this->logbook_model->check_if_dxcc_cnfmd_in_logbook($callsign['callsign']['dxcc'], null, $this->session->userdata('user_default_band')); - } - } 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); - } + if (!$this->load->is_loaded('callbook')) { + $this->load->library('callbook'); + } - $callsign['callsign'] = $this->hamqth->search($id, $this->session->userdata('hamqth_session_key')); + $callsign['callsign'] = $this->callbook->getCallbookData($id); - // 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($id, $this->session->userdata('hamqth_session_key')); - } - if (isset($data['callsign']['gridsquare'])) { - $this->load->model('logbook_model'); - $callsign['grid_worked'] = $this->logbook_model->check_if_grid_worked_in_logbook(strtoupper(substr($data['callsign']['gridsquare'],0,4)), null, $this->session->userdata('user_default_band'))->num_rows(); - } - if (isset($callsign['callsign']['dxcc'])) { - $this->load->model('logbook_model'); - $entity = $this->logbook_model->get_entity($callsign['callsign']['dxcc']); - $callsign['callsign']['dxcc_name'] = $entity['name']; - $callsign['dxcc_worked'] = $this->logbook_model->check_if_dxcc_worked_in_logbook($callsign['callsign']['dxcc'], null, $this->session->userdata('user_default_band')); - $callsign['dxcc_confirmed'] = $this->logbook_model->check_if_dxcc_cnfmd_in_logbook($callsign['callsign']['dxcc'], null, $this->session->userdata('user_default_band')); - } - if (isset($callsign['callsign']['error'])) { - $callsign['error'] = $callsign['callsign']['error']; - } - } else { - $callsign['error'] = 'Lookup not configured. Please review configuration.'; - } - - // There's no hamli integration? Disabled for now. - /*else { - // Lookup using hamli - $this->load->library('hamli'); + if (isset($callsign['callsign']['dxcc'])) { + $this->load->model('logbook_model'); + $entity = $this->logbook_model->get_entity($callsign['callsign']['dxcc']); + $callsign['callsign']['dxcc_name'] = $entity['name']; + $callsign['dxcc_worked'] = $this->logbook_model->check_if_dxcc_worked_in_logbook($callsign['callsign']['dxcc'], null, $this->session->userdata('user_default_band')); + $callsign['dxcc_confirmed'] = $this->logbook_model->check_if_dxcc_cnfmd_in_logbook($callsign['callsign']['dxcc'], null, $this->session->userdata('user_default_band')); + } - $callsign['callsign'] = $this->hamli->callsign($id); - }*/ + if (isset($callsign['callsign']['gridsquare'])) { + $this->load->model('logbook_model'); + $callsign['grid_worked'] = $this->logbook_model->check_if_grid_worked_in_logbook(strtoupper(substr($callsign['callsign']['gridsquare'],0,4)), null, $band)->num_rows(); + } - if (isset($callsign['callsign']['gridsquare'])) { - $this->load->model('logbook_model'); - $callsign['grid_worked'] = $this->logbook_model->check_if_grid_worked_in_logbook(strtoupper(substr($callsign['callsign']['gridsquare'],0,4)), null, $band)->num_rows(); - } - if (isset($callsign['callsign']['error'])) { - $callsign['error'] = $callsign['callsign']['error']; - } + if (isset($callsign['callsign']['error'])) { + $callsign['error'] = $callsign['callsign']['error']; + } - $callsign['id'] = strtoupper($id); - $callsign['lotw_lastupload'] = $this->logbook_model->check_last_lotw($id); - return $this->load->view('search/result', $callsign, true); + $callsign['id'] = strtoupper($id); + $callsign['lotw_lastupload'] = $this->logbook_model->check_last_lotw($id); + return $this->load->view('search/result', $callsign, true); } } @@ -937,65 +888,24 @@ function search_result($id="", $id2="") { $data['results'] = $iota_search; $this->load->view('view_log/partial/log_ajax.php', $data); } else { - 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); - } - - $data['callsign'] = $this->qrz->search($id, $this->session->userdata('qrz_session_key'), $this->config->item('use_fullname')); - if (isset($data['callsign']['gridsquare'])) { - $data['grid_worked'] = $this->logbook_model->check_if_grid_worked_in_logbook(strtoupper(substr($data['callsign']['gridsquare'],0,4)), null, $this->session->userdata('user_default_band'))->num_rows(); - } - if (isset($data['callsign']['dxcc'])) { - $entity = $this->logbook_model->get_entity($data['callsign']['dxcc']); - $data['callsign']['dxcc_name'] = $entity['name']; - $data['dxcc_worked'] = $this->logbook_model->check_if_dxcc_worked_in_logbook($data['callsign']['dxcc'], null, $this->session->userdata('user_default_band')); - $data['dxcc_confirmed'] = $this->logbook_model->check_if_dxcc_cnfmd_in_logbook($data['callsign']['dxcc'], null, $this->session->userdata('user_default_band')); - } - 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 (!$this->load->is_loaded('callbook')) { + $this->load->library('callbook'); + } - // 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($id, $this->session->userdata('hamqth_session_key')); - } - if (isset($data['callsign']['gridsquare'])) { - $data['grid_worked'] = $this->logbook_model->check_if_grid_worked_in_logbook(strtoupper(substr($data['callsign']['gridsquare'],0,4)), null, $this->session->userdata('user_default_band'))->num_rows(); - } - if (isset($data['callsign']['dxcc'])) { - $entity = $this->logbook_model->get_entity($data['callsign']['dxcc']); - $data['callsign']['dxcc_name'] = $entity['name']; - $data['dxcc_worked'] = $this->logbook_model->check_if_dxcc_worked_in_logbook($data['callsign']['dxcc'], null, $this->session->userdata('user_default_band')); - $data['dxcc_confirmed'] = $this->logbook_model->check_if_dxcc_cnfmd_in_logbook($data['callsign']['dxcc'], null, $this->session->userdata('user_default_band')); - } - if (isset($data['callsign']['error'])) { - $data['error'] = $data['callsign']['error']; - } - } else { - $data['error'] = 'Lookup not configured. Please review configuration.'; - } /*else { - // Lookup using hamli - $this->load->library('hamli'); + $data['callsign'] = $this->callbook->getCallbookData($id); - $data['callsign'] = $this->hamli->callsign($id); - }*/ + if (isset($data['callsign']['gridsquare'])) { + $data['grid_worked'] = $this->logbook_model->check_if_grid_worked_in_logbook(strtoupper(substr($data['callsign']['gridsquare'],0,4)), null, $this->session->userdata('user_default_band'))->num_rows(); + } + if (isset($data['callsign']['dxcc'])) { + $entity = $this->logbook_model->get_entity($data['callsign']['dxcc']); + $data['callsign']['dxcc_name'] = $entity['name']; + $data['dxcc_worked'] = $this->logbook_model->check_if_dxcc_worked_in_logbook($data['callsign']['dxcc'], null, $this->session->userdata('user_default_band')); + $data['dxcc_confirmed'] = $this->logbook_model->check_if_dxcc_cnfmd_in_logbook($data['callsign']['dxcc'], null, $this->session->userdata('user_default_band')); + } + if (isset($data['callsign']['error'])) { + $data['error'] = $data['callsign']['error']; + } $data['id'] = strtoupper($id); $data['lotw_lastupload'] = $this->logbook_model->check_last_lotw($id); diff --git a/application/libraries/Callbook.php b/application/libraries/Callbook.php new file mode 100644 index 0000000000..e903034723 --- /dev/null +++ b/application/libraries/Callbook.php @@ -0,0 +1,262 @@ +ci = & get_instance(); + } + + // TODO: + // + // Implement the following: + // - Check that username/password is set + // - Check for use_fullname + // - Implement that reduced logic + public function getCallbookData($callsign) { + switch ($this->ci->config->item('callbook')) { + case 'qrz': return $this->qrz($this->ci->config->item('qrz_username'), $this->ci->config->item('qrz_password'), $callsign); + break; + case 'qrzcq': return $this->qrzcq($this->ci->config->item('qrzcq_username'), $this->ci->config->item('qrzcq_password'), $callsign); + break; + case 'hamqth': return $this->hamqth($this->ci->config->item('hamqth_username'), $this->ci->config->item('hamqth_password'), $callsign); + break; + } + } + + function qrz($username, $password, $callsign) { + if (!$this->ci->load->is_loaded('qrz')) { + $this->ci->load->library('qrz'); + } + + if (!$this->ci->session->userdata('qrz_session_key')) { + $qrz_session_key = $this->ci->qrz->session($username, $password); + $this->ci->session->set_userdata('qrz_session_key', $qrz_session_key); + } + + $callbook = $this->ci->qrz->search($callsign, $this->ci->session->userdata('qrz_session_key')); + + return $callbook; + } + + function qrzcq($username, $password, $callsign) { + if (!$this->ci->load->is_loaded('qrzcq')) { + $this->ci->load->library('qrzcq'); + } + + if (!$this->ci->session->userdata('qrzcq_session_key')) { + $qrzcq_session_key = $this->ci->qrzcq->session($username, $password); + $this->ci->session->set_userdata('qrzcq_session_key', $qrzcq_session_key); + } + + $callbook = $this->ci->qrzcq->search($callsign, $this->ci->session->userdata('qrzcq_session_key')); + + return $callbook; + } + + function hamqth($username, $password, $callsign) { + // Load the HamQTH library + if (!$this->ci->load->is_loaded('hamqth')) { + $this->ci->load->library('hamqth'); + } + + if (!$this->ci->session->userdata('hamqth_session_key')) { + $hamqth_session_key = $this->ci->hamqth->session($username, $password); + $this->ci->session->set_userdata('hamqth_session_key', $hamqth_session_key); + } + + $callbook = $this->ci->hamqth->search($callsign, $this->ci->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->ci->hamqth->session($username, $password); + $this->ci->session->set_userdata('hamqth_session_key', $hamqth_session_key); + $callbook = $this->ci->hamqth->search($callsign, $this->ci->session->userdata('hamqth_session_key')); + } + + return $callbook; + } +} + +// This is the one that needs to be implemented above: +// 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'), $use_fullname); + + // // We need to handle, if the sessionkey is invalid + // if ($callbook['error'] ?? '' == 'Invalid session key') { + // $this->qrz->set_session($this->config->item('qrz_username'), $this->config->item('qrz_password')); + // $callbook = $this->qrz->search($callsign, $this->session->userdata('qrz_session_key'), $use_fullname); + // } + + // // If the callsign contains a slash we have a pre- or suffix. If then the result is "Not found" we can try again with the plain call + // if (strpos($callbook['error'] ?? '', 'Not found') !== false && strpos($callsign, "/") !== false) { + // $plaincall = $this->get_plaincall($callsign); + // // Now try again but give back reduced data, as we can't validate location and stuff (true at the end) + // $callbook = $this->qrz->search($plaincall, $this->session->userdata('qrz_session_key'), $use_fullname, true); + // } + // } + + // 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); + // } + + // // if the callsign contains a pre- or suffix we only give back reduced data to avoid wrong data (location and other things are not valid then) + // if (strpos($callsign, "/") !== false) { + // $reduced = true; + // } else { + // $reduced = false; + // } + // $callbook = $this->hamqth->search($callsign, $this->session->userdata('hamqth_session_key'), $reduced); + + // // 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')); + // } + // } + +// this is from grid, but ignore I think + // if ($this->config->item('callbook') == "qrz" && $this->config->item('qrz_username') != null && $this->config->item('qrz_password') != null) { + // // Lookup using QRZ + // if (!$this->load->is_loaded('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 + // if (!$this->load->is_loaded('hamqth')) { + // $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')); + // } + // } + + + // This is from logbook.php, probably ignore: + // 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); + // } + // $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 (isset($callsign['callsign']['dxcc'])) { + // $this->load->model('logbook_model'); + // $entity = $this->logbook_model->get_entity($callsign['callsign']['dxcc']); + // $callsign['callsign']['dxcc_name'] = $entity['name']; + // $callsign['dxcc_worked'] = $this->logbook_model->check_if_dxcc_worked_in_logbook($callsign['callsign']['dxcc'], null, $this->session->userdata('user_default_band')); + // $callsign['dxcc_confirmed'] = $this->logbook_model->check_if_dxcc_cnfmd_in_logbook($callsign['callsign']['dxcc'], null, $this->session->userdata('user_default_band')); + // } + // } else if ($this->config->item('callbook') == "qrzcq" && $this->config->item('qrzcq_username') != null && $this->config->item('qrzcq_password') != null) { + // // Lookup using QRZCQ + // $this->load->library('qrzcq'); + + // if(!$this->session->userdata('qrzcq_session_key')) { + // $qrzcq_session_key = $this->qrzcq->session($this->config->item('qrzcq_username'), $this->config->item('qrzcq_password')); + // $this->session->set_userdata('qrzcq_session_key', $qrzcq_session_key); + // } + // $callsign['callsign'] = $this->qrzcq->search($id, $this->session->userdata('qrzcq_session_key'), $this->config->item('use_fullname')); + + // if (empty($callsign['callsign']['callsign'])) { + // $qrzcq_session_key = $this->qrzcq->session($this->config->item('qrz_username'), $this->config->item('qrzcq_password')); + // $this->session->set_userdata('qrz_session_key', $qrzcq_session_key); + // $callsign['callsign'] = $this->qrzcq->search($id, $this->session->userdata('qrzcq_session_key'), $this->config->item('use_fullname')); + // } + // if (isset($callsign['callsign']['dxcc'])) { + // $this->load->model('logbook_model'); + // $entity = $this->logbook_model->get_entity($callsign['callsign']['dxcc']); + // $callsign['callsign']['dxcc_name'] = $entity['name']; + // $callsign['dxcc_worked'] = $this->logbook_model->check_if_dxcc_worked_in_logbook($callsign['callsign']['dxcc'], null, $this->session->userdata('user_default_band')); + // $callsign['dxcc_confirmed'] = $this->logbook_model->check_if_dxcc_cnfmd_in_logbook($callsign['callsign']['dxcc'], null, $this->session->userdata('user_default_band')); + // } + // } 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($id, $this->session->userdata('hamqth_session_key')); + // } + // if (isset($data['callsign']['gridsquare'])) { + // $this->load->model('logbook_model'); + // $callsign['grid_worked'] = $this->logbook_model->check_if_grid_worked_in_logbook(strtoupper(substr($data['callsign']['gridsquare'],0,4)), null, $this->session->userdata('user_default_band'))->num_rows(); + // } + // if (isset($callsign['callsign']['dxcc'])) { + // $this->load->model('logbook_model'); + // $entity = $this->logbook_model->get_entity($callsign['callsign']['dxcc']); + // $callsign['callsign']['dxcc_name'] = $entity['name']; + // $callsign['dxcc_worked'] = $this->logbook_model->check_if_dxcc_worked_in_logbook($callsign['callsign']['dxcc'], null, $this->session->userdata('user_default_band')); + // $callsign['dxcc_confirmed'] = $this->logbook_model->check_if_dxcc_cnfmd_in_logbook($callsign['callsign']['dxcc'], null, $this->session->userdata('user_default_band')); + // } + // if (isset($callsign['callsign']['error'])) { + // $callsign['error'] = $callsign['callsign']['error']; + // } + // } else { + // $callsign['error'] = 'Lookup not configured. Please review configuration.'; + // } + + // There's no hamli integration? Disabled for now. + /*else { + // Lookup using hamli + $this->load->library('hamli'); + + $callsign['callsign'] = $this->hamli->callsign($id); + }*/ diff --git a/application/libraries/qrzcq.php b/application/libraries/qrzcq.php new file mode 100644 index 0000000000..4612c0cadf --- /dev/null +++ b/application/libraries/qrzcq.php @@ -0,0 +1,147 @@ +optionslib->get_option('version')); + $xml = curl_exec($ch); + curl_close($ch); + + // Create XML object + $xml = simplexml_load_string($xml); + + // Return Session Key + return (string) $xml->Session->Key; + } + + // Set Session Key session. + public function set_session($username, $password) { + + $ci = & get_instance(); + + // URL to the XML Source + $xml_feed_url = 'https://ssl.qrzcq.com/?username='.$username.';password='.urlencode($password).';agent=wavelog'; + + // CURL Functions + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $xml_feed_url); + curl_setopt($ch, CURLOPT_HEADER, false); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); + curl_setopt($ch, CURLOPT_TIMEOUT, 10); + curl_setopt($ch, CURLOPT_USERAGENT, 'Wavelog/'.$ci->optionslib->get_option('version')); + $xml = curl_exec($ch); + curl_close($ch); + + // Create XML object + $xml = simplexml_load_string($xml); + + $key = (string) $xml->Session->Key; + + $ci->session->set_userdata('qrz_session_key', $key); + + return true; + } + + + public function search($callsign, $key, $use_fullname = false, $reduced = false) { + $data = null; + $ci = & get_instance(); + try { + // URL to the XML Source + $xml_feed_url = 'https://ssl.qrzcq.com/current/?s=' . $key . ';callsign=' . $callsign . ''; + + // CURL Functions + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $xml_feed_url); + curl_setopt($ch, CURLOPT_HEADER, false); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); + curl_setopt($ch, CURLOPT_TIMEOUT, 10); + curl_setopt($ch, CURLOPT_USERAGENT, 'Wavelog/'.$ci->optionslib->get_option('version')); + $xml = curl_exec($ch); + $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); + curl_close($ch); + if ($httpcode != 200) return $data['error'] = 'Problems with qrzcq.com communication'; // Exit function if no 200. If request fails, 0 is returned + + // Create XML object + $xml = simplexml_load_string($xml); + if (!empty($xml->Session->Error)) { + return $data['error'] = $xml->Session->Error; + } + + // Return Required Fields + $data['callsign'] = (string)$xml->Callsign->call; + + if ($use_fullname === true) { + $data['name'] = (string)$xml->Callsign->fname. ' ' . (string)$xml->Callsign->name; + } else { + $data['name'] = (string)$xml->Callsign->fname; + } + + // we always give back the name, no matter if reduced data or not + $data['name'] = trim($data['name']); + + // Sanitize gridsquare to allow only up to 8 characters + $unclean_gridsquare = (string)$xml->Callsign->grid; // Get the gridsquare from QRZ convert to string + $clean_gridsquare = strlen($unclean_gridsquare) > 8 ? substr($unclean_gridsquare,0,8) : $unclean_gridsquare; // Trim gridsquare to 8 characters max + + if ($reduced == false) { + + $data['gridsquare'] = $clean_gridsquare; + $data['city'] = (string)$xml->Callsign->addr2; + $data['lat'] = (string)$xml->Callsign->lat; + $data['long'] = (string)$xml->Callsign->lon; + $data['dxcc'] = (string)$xml->Callsign->dxcc; + $data['state'] = (string)$xml->Callsign->state; + $data['iota'] = (string)$xml->Callsign->iota; + $data['qslmgr'] = (string)$xml->Callsign->qslmgr; + $data['image'] = (string)$xml->Callsign->image; + $data['ituz'] = (string)$xml->Callsign->ituzone; + $data['cqz'] = (string)$xml->Callsign->cqzone; + + if ($xml->Callsign->country == "United States") { + $data['us_county'] = (string)$xml->Callsign->county; + } else { + $data['us_county'] = null; + } + + } else { + + $data['gridsquare'] = ''; + $data['city'] = ''; + $data['lat'] = ''; + $data['long'] = ''; + $data['dxcc'] = ''; + $data['state'] = ''; + $data['iota'] = ''; + $data['qslmgr'] = (string)$xml->Callsign->qslmgr; + $data['image'] = (string)$xml->Callsign->image; + $data['us_county'] = ''; + $data['ituz'] = ''; + $data['cqz'] = ''; + + } + } finally { + + return $data; + } + } +} diff --git a/application/models/Logbook_model.php b/application/models/Logbook_model.php index c7d8762a48..96865f6020 100644 --- a/application/models/Logbook_model.php +++ b/application/models/Logbook_model.php @@ -278,8 +278,8 @@ function create_qso() { $distance=null; if ( (($this->input->post('distance') ?? '') != '') && (is_numeric($this->input->post('distance'))) ) { $distance=$this->input->post('distance'); - } - + } + // Create array with QSO Data $data = array( 'COL_TIME_ON' => $datetime, @@ -2389,7 +2389,7 @@ function check_if_dxcc_cnfmd_in_logbook_api($user_default_confirmation,$dxcc, $s $binding=[]; if ($station_ids == null) { return []; - } + } $extrawhere = $this->qsl_default_where($user_default_confirmation); @@ -4270,7 +4270,7 @@ function import($record, $station_id = "0", $skipDuplicate = false, $markClublog 'COL_CREDIT_GRANTED' => (!empty($record['credit_granted'])) ? $record['credit_granted'] : '', 'COL_CREDIT_SUBMITTED' => (!empty($record['credit_submitted'])) ? $record['credit_submitted'] : '', 'COL_DARC_DOK' => (!empty($record['darc_dok'])) ? strtoupper($record['darc_dok']) : '', - 'COL_DISTANCE' => $distance, + 'COL_DISTANCE' => $distance, 'COL_DXCC' => $dxcc[0], 'COL_EMAIL' => (!empty($record['email'])) ? $record['email'] : '', 'COL_EQ_CALL' => (!empty($record['eq_call'])) ? $record['eq_call'] : '', @@ -4448,7 +4448,7 @@ function import($record, $station_id = "0", $skipDuplicate = false, $markClublog } else { $this->add_qso($data, $skipexport); } - + } else { $my_error .= "Date/Time: " . ($time_on ?? 'N/A') . " Callsign: " . ($record['call'] ?? 'N/A') . " Band: " . ($band ?? 'N/A') . " ".__("Duplicate for")." ". ($station_profile_call ?? 'N/A') . "
"; } @@ -4983,40 +4983,12 @@ public function check_missing_grid_id($all) { 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 - if (!$this->load->is_loaded('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->load->is_loaded('callbook')) { + $this->load->library('callbook'); } - if ($this->config->item('callbook') == "hamqth" && $this->config->item('hamqth_username') != null && $this->config->item('hamqth_password') != null) { - // Load the HamQTH library - if (!$this->load->is_loaded('hamqth')) { - $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->callbook->getCallbookData($callsign); - $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)) { if (isset($callbook['error'])) { printf("Error: " . $callbook['error'] . "
"); @@ -5112,55 +5084,12 @@ function get_plaincall($callsign) { public function loadCallBook($callsign, $use_fullname = false) { $callbook = null; try { - 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'), $use_fullname); - - // We need to handle, if the sessionkey is invalid - if ($callbook['error'] ?? '' == 'Invalid session key') { - $this->qrz->set_session($this->config->item('qrz_username'), $this->config->item('qrz_password')); - $callbook = $this->qrz->search($callsign, $this->session->userdata('qrz_session_key'), $use_fullname); - } - - // If the callsign contains a slash we have a pre- or suffix. If then the result is "Not found" we can try again with the plain call - if (strpos($callbook['error'] ?? '', 'Not found') !== false && strpos($callsign, "/") !== false) { - $plaincall = $this->get_plaincall($callsign); - // Now try again but give back reduced data, as we can't validate location and stuff (true at the end) - $callbook = $this->qrz->search($plaincall, $this->session->userdata('qrz_session_key'), $use_fullname, true); - } + if (!$this->load->is_loaded('callbook')) { + $this->load->library('callbook'); } - 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'); + $callbook = $this->callbook->getCallbookData($callsign); - 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); - } - - // if the callsign contains a pre- or suffix we only give back reduced data to avoid wrong data (location and other things are not valid then) - if (strpos($callsign, "/") !== false) { - $reduced = true; - } else { - $reduced = false; - } - $callbook = $this->hamqth->search($callsign, $this->session->userdata('hamqth_session_key'), $reduced); - - // 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')); - } - } } finally { return $callbook; } From b2542f6b7299678452ba145026c5c00bd34448e9 Mon Sep 17 00:00:00 2001 From: Andreas Kristiansen <6977712+AndreasK79@users.noreply.github.com> Date: Sun, 24 Nov 2024 17:23:37 +0100 Subject: [PATCH 02/17] Implemented username/password in config check --- application/libraries/Callbook.php | 164 ++++++----------------------- 1 file changed, 30 insertions(+), 134 deletions(-) diff --git a/application/libraries/Callbook.php b/application/libraries/Callbook.php index e903034723..529c312775 100644 --- a/application/libraries/Callbook.php +++ b/application/libraries/Callbook.php @@ -15,23 +15,32 @@ public function __construct() { } // TODO: - // // Implement the following: - // - Check that username/password is set - // - Check for use_fullname - // - Implement that reduced logic + // - Implement callsign reduced logic public function getCallbookData($callsign) { switch ($this->ci->config->item('callbook')) { - case 'qrz': return $this->qrz($this->ci->config->item('qrz_username'), $this->ci->config->item('qrz_password'), $callsign); + case 'qrz': + if ($this->ci->config->item('qrz_username') == null || $this->ci->config->item('qrz_password') == null) { + return 'Lookup not configured. Please review configuration.'; + } + return $this->qrz($this->ci->config->item('qrz_username'), $this->ci->config->item('qrz_password'), $callsign, $this->ci->config->item('use_fullname')); break; - case 'qrzcq': return $this->qrzcq($this->ci->config->item('qrzcq_username'), $this->ci->config->item('qrzcq_password'), $callsign); + case 'qrzcq': + if ($this->ci->config->item('qrzcq_username') == null || $this->ci->config->item('qrzcq_password') == null) { + return 'Lookup not configured. Please review configuration.'; + } + return $this->qrzcq($this->ci->config->item('qrzcq_username'), $this->ci->config->item('qrzcq_password'), $callsign); break; - case 'hamqth': return $this->hamqth($this->ci->config->item('hamqth_username'), $this->ci->config->item('hamqth_password'), $callsign); + case 'hamqth': + if ($this->ci->config->item('hamqth_username') == null || $this->ci->config->item('hamqth_password') == null) { + return 'Lookup not configured. Please review configuration.'; + } + return $this->hamqth($this->ci->config->item('hamqth_username'), $this->ci->config->item('hamqth_password'), $callsign); break; } } - function qrz($username, $password, $callsign) { + function qrz($username, $password, $callsign, $fullname) { if (!$this->ci->load->is_loaded('qrz')) { $this->ci->load->library('qrz'); } @@ -41,7 +50,13 @@ function qrz($username, $password, $callsign) { $this->ci->session->set_userdata('qrz_session_key', $qrz_session_key); } - $callbook = $this->ci->qrz->search($callsign, $this->ci->session->userdata('qrz_session_key')); + $callbook = $this->ci->qrz->search($callsign, $this->ci->session->userdata('qrz_session_key'), $fullname); + + if ($callbook['error'] ?? '' == 'Invalid session key') { + $qrz_session_key = $this->ci->qrz->session($username, $password); + $this->ci->session->set_userdata('qrz_session_key', $qrz_session_key); + $callbook = $this->ci->qrz->search($callsign, $this->ci->session->userdata('qrz_session_key'), $fullname); + } return $callbook; } @@ -58,6 +73,12 @@ function qrzcq($username, $password, $callsign) { $callbook = $this->ci->qrzcq->search($callsign, $this->ci->session->userdata('qrzcq_session_key')); + if ($callbook['error'] ?? '' == 'Invalid session key') { + $qrzcq_session_key = $this->ci->qrzcq->session($username, $password); + $this->ci->session->set_userdata('qrzcq_session_key', $qrzcq_session_key); + $callbook = $this->ci->qrzcq->search($callsign, $this->ci->session->userdata('qrzcq_session_key')); + } + return $callbook; } @@ -135,128 +156,3 @@ function hamqth($username, $password, $callsign) { // $callbook = $this->hamqth->search($callsign, $this->session->userdata('hamqth_session_key')); // } // } - -// this is from grid, but ignore I think - // if ($this->config->item('callbook') == "qrz" && $this->config->item('qrz_username') != null && $this->config->item('qrz_password') != null) { - // // Lookup using QRZ - // if (!$this->load->is_loaded('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 - // if (!$this->load->is_loaded('hamqth')) { - // $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')); - // } - // } - - - // This is from logbook.php, probably ignore: - // 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); - // } - // $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 (isset($callsign['callsign']['dxcc'])) { - // $this->load->model('logbook_model'); - // $entity = $this->logbook_model->get_entity($callsign['callsign']['dxcc']); - // $callsign['callsign']['dxcc_name'] = $entity['name']; - // $callsign['dxcc_worked'] = $this->logbook_model->check_if_dxcc_worked_in_logbook($callsign['callsign']['dxcc'], null, $this->session->userdata('user_default_band')); - // $callsign['dxcc_confirmed'] = $this->logbook_model->check_if_dxcc_cnfmd_in_logbook($callsign['callsign']['dxcc'], null, $this->session->userdata('user_default_band')); - // } - // } else if ($this->config->item('callbook') == "qrzcq" && $this->config->item('qrzcq_username') != null && $this->config->item('qrzcq_password') != null) { - // // Lookup using QRZCQ - // $this->load->library('qrzcq'); - - // if(!$this->session->userdata('qrzcq_session_key')) { - // $qrzcq_session_key = $this->qrzcq->session($this->config->item('qrzcq_username'), $this->config->item('qrzcq_password')); - // $this->session->set_userdata('qrzcq_session_key', $qrzcq_session_key); - // } - // $callsign['callsign'] = $this->qrzcq->search($id, $this->session->userdata('qrzcq_session_key'), $this->config->item('use_fullname')); - - // if (empty($callsign['callsign']['callsign'])) { - // $qrzcq_session_key = $this->qrzcq->session($this->config->item('qrz_username'), $this->config->item('qrzcq_password')); - // $this->session->set_userdata('qrz_session_key', $qrzcq_session_key); - // $callsign['callsign'] = $this->qrzcq->search($id, $this->session->userdata('qrzcq_session_key'), $this->config->item('use_fullname')); - // } - // if (isset($callsign['callsign']['dxcc'])) { - // $this->load->model('logbook_model'); - // $entity = $this->logbook_model->get_entity($callsign['callsign']['dxcc']); - // $callsign['callsign']['dxcc_name'] = $entity['name']; - // $callsign['dxcc_worked'] = $this->logbook_model->check_if_dxcc_worked_in_logbook($callsign['callsign']['dxcc'], null, $this->session->userdata('user_default_band')); - // $callsign['dxcc_confirmed'] = $this->logbook_model->check_if_dxcc_cnfmd_in_logbook($callsign['callsign']['dxcc'], null, $this->session->userdata('user_default_band')); - // } - // } 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($id, $this->session->userdata('hamqth_session_key')); - // } - // if (isset($data['callsign']['gridsquare'])) { - // $this->load->model('logbook_model'); - // $callsign['grid_worked'] = $this->logbook_model->check_if_grid_worked_in_logbook(strtoupper(substr($data['callsign']['gridsquare'],0,4)), null, $this->session->userdata('user_default_band'))->num_rows(); - // } - // if (isset($callsign['callsign']['dxcc'])) { - // $this->load->model('logbook_model'); - // $entity = $this->logbook_model->get_entity($callsign['callsign']['dxcc']); - // $callsign['callsign']['dxcc_name'] = $entity['name']; - // $callsign['dxcc_worked'] = $this->logbook_model->check_if_dxcc_worked_in_logbook($callsign['callsign']['dxcc'], null, $this->session->userdata('user_default_band')); - // $callsign['dxcc_confirmed'] = $this->logbook_model->check_if_dxcc_cnfmd_in_logbook($callsign['callsign']['dxcc'], null, $this->session->userdata('user_default_band')); - // } - // if (isset($callsign['callsign']['error'])) { - // $callsign['error'] = $callsign['callsign']['error']; - // } - // } else { - // $callsign['error'] = 'Lookup not configured. Please review configuration.'; - // } - - // There's no hamli integration? Disabled for now. - /*else { - // Lookup using hamli - $this->load->library('hamli'); - - $callsign['callsign'] = $this->hamli->callsign($id); - }*/ From eb70e66b326778b7540ee29c123fc3b82324ff4b Mon Sep 17 00:00:00 2001 From: Andreas Kristiansen <6977712+AndreasK79@users.noreply.github.com> Date: Mon, 25 Nov 2024 10:34:11 +0100 Subject: [PATCH 03/17] Fixed correct return of error --- application/libraries/Callbook.php | 9 ++++++--- application/libraries/qrzcq.php | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/application/libraries/Callbook.php b/application/libraries/Callbook.php index 529c312775..b078dda850 100644 --- a/application/libraries/Callbook.php +++ b/application/libraries/Callbook.php @@ -21,19 +21,22 @@ public function getCallbookData($callsign) { switch ($this->ci->config->item('callbook')) { case 'qrz': if ($this->ci->config->item('qrz_username') == null || $this->ci->config->item('qrz_password') == null) { - return 'Lookup not configured. Please review configuration.'; + $callbook['error'] = 'Lookup not configured. Please review configuration.'; + return $callbook; } return $this->qrz($this->ci->config->item('qrz_username'), $this->ci->config->item('qrz_password'), $callsign, $this->ci->config->item('use_fullname')); break; case 'qrzcq': if ($this->ci->config->item('qrzcq_username') == null || $this->ci->config->item('qrzcq_password') == null) { - return 'Lookup not configured. Please review configuration.'; + $callbook['error'] = 'Lookup not configured. Please review configuration.'; + return $callbook; } return $this->qrzcq($this->ci->config->item('qrzcq_username'), $this->ci->config->item('qrzcq_password'), $callsign); break; case 'hamqth': if ($this->ci->config->item('hamqth_username') == null || $this->ci->config->item('hamqth_password') == null) { - return 'Lookup not configured. Please review configuration.'; + $callbook['error'] = 'Lookup not configured. Please review configuration.'; + return $callbook; } return $this->hamqth($this->ci->config->item('hamqth_username'), $this->ci->config->item('hamqth_password'), $callsign); break; diff --git a/application/libraries/qrzcq.php b/application/libraries/qrzcq.php index 4612c0cadf..0baeb96184 100644 --- a/application/libraries/qrzcq.php +++ b/application/libraries/qrzcq.php @@ -55,7 +55,7 @@ public function set_session($username, $password) { $key = (string) $xml->Session->Key; - $ci->session->set_userdata('qrz_session_key', $key); + $ci->session->set_userdata('qrzcq_session_key', $key); return true; } From 0e4b17ce13ae502ec1235f618de7d9d2cd7b07e6 Mon Sep 17 00:00:00 2001 From: Andreas Kristiansen <6977712+AndreasK79@users.noreply.github.com> Date: Mon, 25 Nov 2024 12:21:07 +0100 Subject: [PATCH 04/17] Implemented reduced call --- application/libraries/Callbook.php | 117 +++++++++++++---------------- application/libraries/qrzcq.php | 2 +- 2 files changed, 55 insertions(+), 64 deletions(-) diff --git a/application/libraries/Callbook.php b/application/libraries/Callbook.php index b078dda850..313b7915f9 100644 --- a/application/libraries/Callbook.php +++ b/application/libraries/Callbook.php @@ -18,32 +18,38 @@ public function __construct() { // Implement the following: // - Implement callsign reduced logic public function getCallbookData($callsign) { + $reduced = false; + + if (strpos($callsign, "/") !== false) { + $reduced = true; + } + switch ($this->ci->config->item('callbook')) { 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.'; return $callbook; } - return $this->qrz($this->ci->config->item('qrz_username'), $this->ci->config->item('qrz_password'), $callsign, $this->ci->config->item('use_fullname')); + return $this->qrz($this->ci->config->item('qrz_username'), $this->ci->config->item('qrz_password'), $callsign, $this->ci->config->item('use_fullname'), $reduced); break; case 'qrzcq': if ($this->ci->config->item('qrzcq_username') == null || $this->ci->config->item('qrzcq_password') == null) { $callbook['error'] = 'Lookup not configured. Please review configuration.'; return $callbook; } - return $this->qrzcq($this->ci->config->item('qrzcq_username'), $this->ci->config->item('qrzcq_password'), $callsign); + return $this->qrzcq($this->ci->config->item('qrzcq_username'), $this->ci->config->item('qrzcq_password'), $callsign, $reduced); break; case 'hamqth': if ($this->ci->config->item('hamqth_username') == null || $this->ci->config->item('hamqth_password') == null) { $callbook['error'] = 'Lookup not configured. Please review configuration.'; return $callbook; } - return $this->hamqth($this->ci->config->item('hamqth_username'), $this->ci->config->item('hamqth_password'), $callsign); + return $this->hamqth($this->ci->config->item('hamqth_username'), $this->ci->config->item('hamqth_password'), $callsign, $reduced); break; } } - function qrz($username, $password, $callsign, $fullname) { + function qrz($username, $password, $callsign, $fullname, $reduced) { if (!$this->ci->load->is_loaded('qrz')) { $this->ci->load->library('qrz'); } @@ -53,18 +59,24 @@ function qrz($username, $password, $callsign, $fullname) { $this->ci->session->set_userdata('qrz_session_key', $qrz_session_key); } - $callbook = $this->ci->qrz->search($callsign, $this->ci->session->userdata('qrz_session_key'), $fullname); + $callbook = $this->ci->qrz->search($callsign, $this->ci->session->userdata('qrz_session_key'), $fullname, $reduced); if ($callbook['error'] ?? '' == 'Invalid session key') { $qrz_session_key = $this->ci->qrz->session($username, $password); $this->ci->session->set_userdata('qrz_session_key', $qrz_session_key); - $callbook = $this->ci->qrz->search($callsign, $this->ci->session->userdata('qrz_session_key'), $fullname); + $callbook = $this->ci->qrz->search($callsign, $this->ci->session->userdata('qrz_session_key'), $fullname, $reduced); + } + + if (strpos($callbook['error'] ?? '', 'Not found') !== false && strpos($callsign, "/") !== false) { + $plaincall = $this->get_plaincall($callsign); + // Now try again but give back reduced data, as we can't validate location and stuff (true at the end) + $callbook = $this->ci->qrz->search($plaincall, $this->ci->session->userdata('qrz_session_key'), $fullname, true); } return $callbook; } - function qrzcq($username, $password, $callsign) { + function qrzcq($username, $password, $callsign, $reduced) { if (!$this->ci->load->is_loaded('qrzcq')) { $this->ci->load->library('qrzcq'); } @@ -74,18 +86,24 @@ function qrzcq($username, $password, $callsign) { $this->ci->session->set_userdata('qrzcq_session_key', $qrzcq_session_key); } - $callbook = $this->ci->qrzcq->search($callsign, $this->ci->session->userdata('qrzcq_session_key')); + $callbook = $this->ci->qrzcq->search($callsign, $this->ci->session->userdata('qrzcq_session_key'), $reduced); if ($callbook['error'] ?? '' == 'Invalid session key') { $qrzcq_session_key = $this->ci->qrzcq->session($username, $password); $this->ci->session->set_userdata('qrzcq_session_key', $qrzcq_session_key); - $callbook = $this->ci->qrzcq->search($callsign, $this->ci->session->userdata('qrzcq_session_key')); + $callbook = $this->ci->qrzcq->search($callsign, $this->ci->session->userdata('qrzcq_session_key'), $reduced); + } + + if (strpos($callbook['error'] ?? '', 'Not found') !== false && strpos($callsign, "/") !== false) { + $plaincall = $this->get_plaincall($callsign); + // Now try again but give back reduced data, as we can't validate location and stuff (true at the end) + $callbook = $this->ci->qrzcq->search($plaincall, $this->ci->session->userdata('qrzcq_session_key'), true); } return $callbook; } - function hamqth($username, $password, $callsign) { + function hamqth($username, $password, $callsign, $reduced) { // Load the HamQTH library if (!$this->ci->load->is_loaded('hamqth')) { $this->ci->load->library('hamqth'); @@ -96,66 +114,39 @@ function hamqth($username, $password, $callsign) { $this->ci->session->set_userdata('hamqth_session_key', $hamqth_session_key); } - $callbook = $this->ci->hamqth->search($callsign, $this->ci->session->userdata('hamqth_session_key')); + $callbook = $this->ci->hamqth->search($callsign, $this->ci->session->userdata('hamqth_session_key'), $reduced); // 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->ci->hamqth->session($username, $password); $this->ci->session->set_userdata('hamqth_session_key', $hamqth_session_key); - $callbook = $this->ci->hamqth->search($callsign, $this->ci->session->userdata('hamqth_session_key')); + $callbook = $this->ci->hamqth->search($callsign, $this->ci->session->userdata('hamqth_session_key'), $reduced); + } + + if (strpos($callbook['error'] ?? '', 'Not found') !== false && strpos($callsign, "/") !== false) { + $plaincall = $this->get_plaincall($callsign); + // Now try again but give back reduced data, as we can't validate location and stuff (true at the end) + $callbook = $this->ci->hamqth->search($plaincall, $this->ci->session->userdata('hamqth_session_key'), true); } return $callbook; } -} -// This is the one that needs to be implemented above: -// 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'), $use_fullname); - - // // We need to handle, if the sessionkey is invalid - // if ($callbook['error'] ?? '' == 'Invalid session key') { - // $this->qrz->set_session($this->config->item('qrz_username'), $this->config->item('qrz_password')); - // $callbook = $this->qrz->search($callsign, $this->session->userdata('qrz_session_key'), $use_fullname); - // } - - // // If the callsign contains a slash we have a pre- or suffix. If then the result is "Not found" we can try again with the plain call - // if (strpos($callbook['error'] ?? '', 'Not found') !== false && strpos($callsign, "/") !== false) { - // $plaincall = $this->get_plaincall($callsign); - // // Now try again but give back reduced data, as we can't validate location and stuff (true at the end) - // $callbook = $this->qrz->search($plaincall, $this->session->userdata('qrz_session_key'), $use_fullname, true); - // } - // } - - // 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); - // } - - // // if the callsign contains a pre- or suffix we only give back reduced data to avoid wrong data (location and other things are not valid then) - // if (strpos($callsign, "/") !== false) { - // $reduced = true; - // } else { - // $reduced = false; - // } - // $callbook = $this->hamqth->search($callsign, $this->session->userdata('hamqth_session_key'), $reduced); - - // // 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')); - // } - // } + function get_plaincall($callsign) { + $split_callsign = explode('/', $callsign); + if (count($split_callsign) == 1) { // case F0ABC --> return cel 0 // + $lookupcall = $split_callsign[0]; + } else if (count($split_callsign) == 3) { // case EA/F0ABC/P --> return cel 1 // + $lookupcall = $split_callsign[1]; + } else { // case F0ABC/P --> return cel 0 OR case EA/FOABC --> retunr 1 (normaly not exist) // + if (in_array(strtoupper($split_callsign[1]), array('P', 'M', 'MM', 'QRP', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'))) { + $lookupcall = $split_callsign[0]; + } else if (strlen($split_callsign[1]) > 3) { // Last Element longer than 3 chars? Take that as call + $lookupcall = $split_callsign[1]; + } else { // Last Element up to 3 Chars? Take first element as Call + $lookupcall = $split_callsign[0]; + } + } + return $lookupcall; + } +} diff --git a/application/libraries/qrzcq.php b/application/libraries/qrzcq.php index 0baeb96184..79acbed8e7 100644 --- a/application/libraries/qrzcq.php +++ b/application/libraries/qrzcq.php @@ -61,7 +61,7 @@ public function set_session($username, $password) { } - public function search($callsign, $key, $use_fullname = false, $reduced = false) { + public function search($callsign, $key, $reduced = false) { $data = null; $ci = & get_instance(); try { From 6b8fb0040c095ff13d44bf920bd29d1d65ccba73 Mon Sep 17 00:00:00 2001 From: Andreas Kristiansen <6977712+AndreasK79@users.noreply.github.com> Date: Mon, 25 Nov 2024 12:28:17 +0100 Subject: [PATCH 05/17] Fixed fullname in qrzcq --- application/libraries/qrzcq.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/application/libraries/qrzcq.php b/application/libraries/qrzcq.php index 79acbed8e7..4b946c78cb 100644 --- a/application/libraries/qrzcq.php +++ b/application/libraries/qrzcq.php @@ -90,11 +90,7 @@ public function search($callsign, $key, $reduced = false) { // Return Required Fields $data['callsign'] = (string)$xml->Callsign->call; - if ($use_fullname === true) { - $data['name'] = (string)$xml->Callsign->fname. ' ' . (string)$xml->Callsign->name; - } else { - $data['name'] = (string)$xml->Callsign->fname; - } + $data['name'] = (string)$xml->Callsign->fname; // we always give back the name, no matter if reduced data or not $data['name'] = trim($data['name']); From 8a843f608634de7748f2bfd70ea5e5bd64c00037 Mon Sep 17 00:00:00 2001 From: Andreas Kristiansen <6977712+AndreasK79@users.noreply.github.com> Date: Mon, 25 Nov 2024 12:31:31 +0100 Subject: [PATCH 06/17] Fixed qrzcq url --- application/libraries/qrzcq.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/application/libraries/qrzcq.php b/application/libraries/qrzcq.php index 4b946c78cb..74f0a7fcb0 100644 --- a/application/libraries/qrzcq.php +++ b/application/libraries/qrzcq.php @@ -37,7 +37,7 @@ public function set_session($username, $password) { $ci = & get_instance(); // URL to the XML Source - $xml_feed_url = 'https://ssl.qrzcq.com/?username='.$username.';password='.urlencode($password).';agent=wavelog'; + $xml_feed_url = 'https://ssl.qrzcq.com/xml/?username='.$username.';password='.urlencode($password).';agent=wavelog'; // CURL Functions $ch = curl_init(); @@ -66,7 +66,7 @@ public function search($callsign, $key, $reduced = false) { $ci = & get_instance(); try { // URL to the XML Source - $xml_feed_url = 'https://ssl.qrzcq.com/current/?s=' . $key . ';callsign=' . $callsign . ''; + $xml_feed_url = 'https://ssl.qrzcq.com/xml/?s=' . $key . ';callsign=' . $callsign . ''; // CURL Functions $ch = curl_init(); From a522d3095c50eb8ac4a839099ee5b7bd0ce94cc2 Mon Sep 17 00:00:00 2001 From: Andreas Kristiansen <6977712+AndreasK79@users.noreply.github.com> Date: Mon, 25 Nov 2024 12:41:34 +0100 Subject: [PATCH 07/17] Added error if no callbook is entered in config --- application/libraries/Callbook.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/application/libraries/Callbook.php b/application/libraries/Callbook.php index 313b7915f9..5dbd6ca839 100644 --- a/application/libraries/Callbook.php +++ b/application/libraries/Callbook.php @@ -46,6 +46,9 @@ public function getCallbookData($callsign) { } return $this->hamqth($this->ci->config->item('hamqth_username'), $this->ci->config->item('hamqth_password'), $callsign, $reduced); break; + default: + $callbook['error'] = 'No callbook defined. Please review configuration.'; + return $callbook; } } From 6f2bade524d0c17aafb6f109b0ad0a85bec09021 Mon Sep 17 00:00:00 2001 From: Andreas Kristiansen <6977712+AndreasK79@users.noreply.github.com> Date: Mon, 25 Nov 2024 12:41:47 +0100 Subject: [PATCH 08/17] Fixed qrzcq column mapping --- application/libraries/qrzcq.php | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/application/libraries/qrzcq.php b/application/libraries/qrzcq.php index 74f0a7fcb0..bfd53e43ef 100644 --- a/application/libraries/qrzcq.php +++ b/application/libraries/qrzcq.php @@ -90,28 +90,28 @@ public function search($callsign, $key, $reduced = false) { // Return Required Fields $data['callsign'] = (string)$xml->Callsign->call; - $data['name'] = (string)$xml->Callsign->fname; + $data['name'] = (string)$xml->Callsign->name; // we always give back the name, no matter if reduced data or not $data['name'] = trim($data['name']); // Sanitize gridsquare to allow only up to 8 characters - $unclean_gridsquare = (string)$xml->Callsign->grid; // Get the gridsquare from QRZ convert to string + $unclean_gridsquare = (string)$xml->Callsign->locator; // Get the gridsquare from QRZ convert to string $clean_gridsquare = strlen($unclean_gridsquare) > 8 ? substr($unclean_gridsquare,0,8) : $unclean_gridsquare; // Trim gridsquare to 8 characters max if ($reduced == false) { $data['gridsquare'] = $clean_gridsquare; - $data['city'] = (string)$xml->Callsign->addr2; - $data['lat'] = (string)$xml->Callsign->lat; - $data['long'] = (string)$xml->Callsign->lon; - $data['dxcc'] = (string)$xml->Callsign->dxcc; - $data['state'] = (string)$xml->Callsign->state; - $data['iota'] = (string)$xml->Callsign->iota; - $data['qslmgr'] = (string)$xml->Callsign->qslmgr; - $data['image'] = (string)$xml->Callsign->image; - $data['ituz'] = (string)$xml->Callsign->ituzone; - $data['cqz'] = (string)$xml->Callsign->cqzone; + $data['city'] = (string)$xml->Callsign->city; + $data['lat'] = (string)$xml->Callsign->latitude; + $data['long'] = (string)$xml->Callsign->longitude; + $data['dxcc'] = (string)$xml->Callsign->dxcc; + $data['state'] = (string)$xml->Callsign->state; + $data['iota'] = (string)$xml->Callsign->iota; + $data['image'] = (string)$xml->Callsign->qslpic; + $data['ituz'] = (string)$xml->Callsign->itu; + $data['cqz'] = (string)$xml->Callsign->cq; + $data['continent'] = (string)$xml->Callsign->continent; if ($xml->Callsign->country == "United States") { $data['us_county'] = (string)$xml->Callsign->county; From b5de192ce97fcc2e57aa9da89075326fcb997016 Mon Sep 17 00:00:00 2001 From: Andreas Kristiansen <6977712+AndreasK79@users.noreply.github.com> Date: Mon, 25 Nov 2024 12:44:29 +0100 Subject: [PATCH 09/17] More mapping fixes for qrzcq --- application/libraries/qrzcq.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/application/libraries/qrzcq.php b/application/libraries/qrzcq.php index bfd53e43ef..7a3ac13d96 100644 --- a/application/libraries/qrzcq.php +++ b/application/libraries/qrzcq.php @@ -112,6 +112,7 @@ public function search($callsign, $key, $reduced = false) { $data['ituz'] = (string)$xml->Callsign->itu; $data['cqz'] = (string)$xml->Callsign->cq; $data['continent'] = (string)$xml->Callsign->continent; + $data['county'] = (string)$xml->Callsign->county; if ($xml->Callsign->country == "United States") { $data['us_county'] = (string)$xml->Callsign->county; @@ -128,9 +129,8 @@ public function search($callsign, $key, $reduced = false) { $data['dxcc'] = ''; $data['state'] = ''; $data['iota'] = ''; - $data['qslmgr'] = (string)$xml->Callsign->qslmgr; - $data['image'] = (string)$xml->Callsign->image; - $data['us_county'] = ''; + $data['image'] = (string)$xml->Callsign->qslpic; + $data['county'] = ''; $data['ituz'] = ''; $data['cqz'] = ''; From 7fb32fbb342c67cdbda15c504f4556a410ab4b8f Mon Sep 17 00:00:00 2001 From: Andreas Kristiansen <6977712+AndreasK79@users.noreply.github.com> Date: Mon, 25 Nov 2024 12:50:26 +0100 Subject: [PATCH 10/17] Fixed comment --- application/libraries/qrzcq.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/libraries/qrzcq.php b/application/libraries/qrzcq.php index 7a3ac13d96..d6b35c58fb 100644 --- a/application/libraries/qrzcq.php +++ b/application/libraries/qrzcq.php @@ -1,7 +1,7 @@ Date: Mon, 25 Nov 2024 13:10:55 +0100 Subject: [PATCH 11/17] Column fixes --- application/libraries/qrzcq.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/application/libraries/qrzcq.php b/application/libraries/qrzcq.php index d6b35c58fb..031de65283 100644 --- a/application/libraries/qrzcq.php +++ b/application/libraries/qrzcq.php @@ -112,12 +112,12 @@ public function search($callsign, $key, $reduced = false) { $data['ituz'] = (string)$xml->Callsign->itu; $data['cqz'] = (string)$xml->Callsign->cq; $data['continent'] = (string)$xml->Callsign->continent; - $data['county'] = (string)$xml->Callsign->county; if ($xml->Callsign->country == "United States") { $data['us_county'] = (string)$xml->Callsign->county; } else { $data['us_county'] = null; + $data['county'] = (string)$xml->Callsign->county; } } else { @@ -131,6 +131,7 @@ public function search($callsign, $key, $reduced = false) { $data['iota'] = ''; $data['image'] = (string)$xml->Callsign->qslpic; $data['county'] = ''; + $data['us_county'] = ''; $data['ituz'] = ''; $data['cqz'] = ''; From 948c4afc545182b6a4d9b742cd6040108c97d4b1 Mon Sep 17 00:00:00 2001 From: phl0 Date: Mon, 25 Nov 2024 13:48:35 +0100 Subject: [PATCH 12/17] Rename class file --- application/libraries/{qrzcq.php => Qrzcq.php} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename application/libraries/{qrzcq.php => Qrzcq.php} (100%) diff --git a/application/libraries/qrzcq.php b/application/libraries/Qrzcq.php similarity index 100% rename from application/libraries/qrzcq.php rename to application/libraries/Qrzcq.php From 6b573f360cff8e38a8ec56631a8d4ff821b8813e Mon Sep 17 00:00:00 2001 From: phl0 Date: Mon, 25 Nov 2024 14:12:46 +0100 Subject: [PATCH 13/17] Handle non-premium qrzcq --- application/libraries/Qrzcq.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/application/libraries/Qrzcq.php b/application/libraries/Qrzcq.php index 031de65283..edbb7ac90c 100644 --- a/application/libraries/Qrzcq.php +++ b/application/libraries/Qrzcq.php @@ -27,6 +27,10 @@ public function session($username, $password) { // Create XML object $xml = simplexml_load_string($xml); + if (isset($xml->Session->Error)) { + log_message('debug', 'Error: '.$xml->Session->Error); + } + // Return Session Key return (string) $xml->Session->Key; } From 888f9c974336a4b11dd14fad386fe4f25abba2f8 Mon Sep 17 00:00:00 2001 From: phl0 Date: Mon, 25 Nov 2024 14:33:05 +0100 Subject: [PATCH 14/17] Handle errors when querying qrzcq (i.e. non-premium) --- application/libraries/Callbook.php | 9 +++++++-- application/libraries/Qrzcq.php | 11 +++++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/application/libraries/Callbook.php b/application/libraries/Callbook.php index 5dbd6ca839..a7f24c7a28 100644 --- a/application/libraries/Callbook.php +++ b/application/libraries/Callbook.php @@ -85,8 +85,13 @@ function qrzcq($username, $password, $callsign, $reduced) { } if (!$this->ci->session->userdata('qrzcq_session_key')) { - $qrzcq_session_key = $this->ci->qrzcq->session($username, $password); - $this->ci->session->set_userdata('qrzcq_session_key', $qrzcq_session_key); + $result = $this->ci->qrzcq->session($username, $password); + if ($result[0] == 0) { + $this->ci->session->set_userdata('qrzcq_session_key', $result[1]); + } else { + $data['error'] = __("QRZCQ Error").": ".$result[1]; + return $data; + } } $callbook = $this->ci->qrzcq->search($callsign, $this->ci->session->userdata('qrzcq_session_key'), $reduced); diff --git a/application/libraries/Qrzcq.php b/application/libraries/Qrzcq.php index edbb7ac90c..de1968b73a 100644 --- a/application/libraries/Qrzcq.php +++ b/application/libraries/Qrzcq.php @@ -27,12 +27,15 @@ public function session($username, $password) { // Create XML object $xml = simplexml_load_string($xml); - if (isset($xml->Session->Error)) { - log_message('debug', 'Error: '.$xml->Session->Error); + if (isset($xml->Session->Key)) { + $result = array( 0, (string) $xml->Session->Key); + } else if (isset($xml->Session->Error)) { + $result = array( 1, (string) $xml->Session->Error); + } else { + $result = array( 2, 'Unknown error'); } - // Return Session Key - return (string) $xml->Session->Key; + return $result; } // Set Session Key session. From a4100a4149abc66b811d5840315cd5a31c2d8f7a Mon Sep 17 00:00:00 2001 From: Andreas Kristiansen <6977712+AndreasK79@users.noreply.github.com> Date: Mon, 25 Nov 2024 18:42:41 +0100 Subject: [PATCH 15/17] Trying to fix reduce call problem --- application/controllers/Logbook.php | 48 +++++++++++++---------------- application/libraries/Callbook.php | 30 ++++++++---------- application/views/search/result.php | 8 ++--- 3 files changed, 38 insertions(+), 48 deletions(-) diff --git a/application/controllers/Logbook.php b/application/controllers/Logbook.php index ca03bc86a0..13882f3689 100644 --- a/application/controllers/Logbook.php +++ b/application/controllers/Logbook.php @@ -127,12 +127,12 @@ function json($tempcallsign, $tempband, $tempmode, $tempstation_id = null, $date $return['dxcc'] = $this->dxcheck($callsign,$date); - $lookupcall=$this->logbook_model->get_plaincall($callsign); - - $return['partial'] = $this->partial($lookupcall, $band); + $lookupcall = $this->logbook_model->get_plaincall($callsign); $callbook = $this->logbook_model->loadCallBook($callsign, $this->config->item('use_fullname')); + $return['partial'] = $this->partial($lookupcall, $callbook, $callsign, $band); + if ($this->session->userdata('user_measurement_base') == NULL) { $measurement_base = $this->config->item('measurement_base'); } else { @@ -614,7 +614,7 @@ function view($id) { $this->load->view('interface_assets/footer'); } - function partial($id, $band = null) { + function partial($lookupcall, $callbook, $callsign, $band = null) { $this->load->model('user_model'); if(!$this->user_model->authorize($this->config->item('auth_mode'))) { return; } @@ -631,10 +631,10 @@ function partial($id, $band = null) { $this->db->where_in('station_profile.station_id', $logbooks_locations_array); $this->db->group_start(); - $this->db->where($this->config->item('table_name').'.COL_CALL', $id); - $this->db->or_like($this->config->item('table_name').'.COL_CALL', '/'.$id,'before'); - $this->db->or_like($this->config->item('table_name').'.COL_CALL', $id.'/','after'); - $this->db->or_like($this->config->item('table_name').'.COL_CALL', '/'.$id.'/'); + $this->db->where($this->config->item('table_name').'.COL_CALL', $lookupcall); + $this->db->or_like($this->config->item('table_name').'.COL_CALL', '/'.$lookupcall,'before'); + $this->db->or_like($this->config->item('table_name').'.COL_CALL', $lookupcall.'/','after'); + $this->db->or_like($this->config->item('table_name').'.COL_CALL', '/'.$lookupcall.'/'); $this->db->group_end(); $this->db->order_by($this->config->item('table_name').".COL_TIME_ON", "desc"); @@ -825,33 +825,29 @@ function partial($id, $band = null) { $html .= ""; return $html; } else { + $callsigninfo['callsign'] = $callbook; - if (!$this->load->is_loaded('callbook')) { - $this->load->library('callbook'); - } - - $callsign['callsign'] = $this->callbook->getCallbookData($id); - - if (isset($callsign['callsign']['dxcc'])) { + if (isset($callsigninfo['callsign']['dxcc'])) { $this->load->model('logbook_model'); - $entity = $this->logbook_model->get_entity($callsign['callsign']['dxcc']); - $callsign['callsign']['dxcc_name'] = $entity['name']; - $callsign['dxcc_worked'] = $this->logbook_model->check_if_dxcc_worked_in_logbook($callsign['callsign']['dxcc'], null, $this->session->userdata('user_default_band')); - $callsign['dxcc_confirmed'] = $this->logbook_model->check_if_dxcc_cnfmd_in_logbook($callsign['callsign']['dxcc'], null, $this->session->userdata('user_default_band')); + $entity = $this->logbook_model->get_entity($callsigninfo['callsign']['dxcc']); + $callsigninfo['callsign']['dxcc_name'] = $entity['name']; + $callsigninfo['dxcc_worked'] = $this->logbook_model->check_if_dxcc_worked_in_logbook($callsigninfo['callsign']['dxcc'], null, $this->session->userdata('user_default_band')); + $callsigninfo['dxcc_confirmed'] = $this->logbook_model->check_if_dxcc_cnfmd_in_logbook($callsigninfo['callsign']['dxcc'], null, $this->session->userdata('user_default_band')); } - if (isset($callsign['callsign']['gridsquare'])) { + if (isset($callsigninfo['callsign']['gridsquare'])) { $this->load->model('logbook_model'); - $callsign['grid_worked'] = $this->logbook_model->check_if_grid_worked_in_logbook(strtoupper(substr($callsign['callsign']['gridsquare'],0,4)), null, $band)->num_rows(); + $callsigninfo['grid_worked'] = $this->logbook_model->check_if_grid_worked_in_logbook(strtoupper(substr($callsigninfo['callsign']['gridsquare'],0,4)), null, $band)->num_rows(); } - if (isset($callsign['callsign']['error'])) { - $callsign['error'] = $callsign['callsign']['error']; + if (isset($callsigninfo['callsign']['error'])) { + $callsigninfo['error'] = $callsigninfo['callsign']['error']; } - $callsign['id'] = strtoupper($id); - $callsign['lotw_lastupload'] = $this->logbook_model->check_last_lotw($id); - return $this->load->view('search/result', $callsign, true); + $callsigninfo['lookupcall'] = strtoupper($lookupcall); + $callsigninfo['realcall'] = strtoupper($callsign); + $callsigninfo['lotw_lastupload'] = $this->logbook_model->check_last_lotw($callsign); + return $this->load->view('search/result', $callsigninfo, true); } } diff --git a/application/libraries/Callbook.php b/application/libraries/Callbook.php index a7f24c7a28..06cd40f91e 100644 --- a/application/libraries/Callbook.php +++ b/application/libraries/Callbook.php @@ -18,33 +18,27 @@ public function __construct() { // Implement the following: // - Implement callsign reduced logic public function getCallbookData($callsign) { - $reduced = false; - - if (strpos($callsign, "/") !== false) { - $reduced = true; - } - switch ($this->ci->config->item('callbook')) { 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.'; return $callbook; } - return $this->qrz($this->ci->config->item('qrz_username'), $this->ci->config->item('qrz_password'), $callsign, $this->ci->config->item('use_fullname'), $reduced); + return $this->qrz($this->ci->config->item('qrz_username'), $this->ci->config->item('qrz_password'), $callsign, $this->ci->config->item('use_fullname')); break; case 'qrzcq': if ($this->ci->config->item('qrzcq_username') == null || $this->ci->config->item('qrzcq_password') == null) { $callbook['error'] = 'Lookup not configured. Please review configuration.'; return $callbook; } - return $this->qrzcq($this->ci->config->item('qrzcq_username'), $this->ci->config->item('qrzcq_password'), $callsign, $reduced); + return $this->qrzcq($this->ci->config->item('qrzcq_username'), $this->ci->config->item('qrzcq_password'), $callsign); break; case 'hamqth': if ($this->ci->config->item('hamqth_username') == null || $this->ci->config->item('hamqth_password') == null) { $callbook['error'] = 'Lookup not configured. Please review configuration.'; return $callbook; } - return $this->hamqth($this->ci->config->item('hamqth_username'), $this->ci->config->item('hamqth_password'), $callsign, $reduced); + return $this->hamqth($this->ci->config->item('hamqth_username'), $this->ci->config->item('hamqth_password'), $callsign); break; default: $callbook['error'] = 'No callbook defined. Please review configuration.'; @@ -52,7 +46,7 @@ public function getCallbookData($callsign) { } } - function qrz($username, $password, $callsign, $fullname, $reduced) { + function qrz($username, $password, $callsign, $fullname) { if (!$this->ci->load->is_loaded('qrz')) { $this->ci->load->library('qrz'); } @@ -62,12 +56,12 @@ function qrz($username, $password, $callsign, $fullname, $reduced) { $this->ci->session->set_userdata('qrz_session_key', $qrz_session_key); } - $callbook = $this->ci->qrz->search($callsign, $this->ci->session->userdata('qrz_session_key'), $fullname, $reduced); + $callbook = $this->ci->qrz->search($callsign, $this->ci->session->userdata('qrz_session_key'), $fullname); if ($callbook['error'] ?? '' == 'Invalid session key') { $qrz_session_key = $this->ci->qrz->session($username, $password); $this->ci->session->set_userdata('qrz_session_key', $qrz_session_key); - $callbook = $this->ci->qrz->search($callsign, $this->ci->session->userdata('qrz_session_key'), $fullname, $reduced); + $callbook = $this->ci->qrz->search($callsign, $this->ci->session->userdata('qrz_session_key'), $fullname); } if (strpos($callbook['error'] ?? '', 'Not found') !== false && strpos($callsign, "/") !== false) { @@ -79,7 +73,7 @@ function qrz($username, $password, $callsign, $fullname, $reduced) { return $callbook; } - function qrzcq($username, $password, $callsign, $reduced) { + function qrzcq($username, $password, $callsign) { if (!$this->ci->load->is_loaded('qrzcq')) { $this->ci->load->library('qrzcq'); } @@ -94,12 +88,12 @@ function qrzcq($username, $password, $callsign, $reduced) { } } - $callbook = $this->ci->qrzcq->search($callsign, $this->ci->session->userdata('qrzcq_session_key'), $reduced); + $callbook = $this->ci->qrzcq->search($callsign, $this->ci->session->userdata('qrzcq_session_key')); if ($callbook['error'] ?? '' == 'Invalid session key') { $qrzcq_session_key = $this->ci->qrzcq->session($username, $password); $this->ci->session->set_userdata('qrzcq_session_key', $qrzcq_session_key); - $callbook = $this->ci->qrzcq->search($callsign, $this->ci->session->userdata('qrzcq_session_key'), $reduced); + $callbook = $this->ci->qrzcq->search($callsign, $this->ci->session->userdata('qrzcq_session_key')); } if (strpos($callbook['error'] ?? '', 'Not found') !== false && strpos($callsign, "/") !== false) { @@ -111,7 +105,7 @@ function qrzcq($username, $password, $callsign, $reduced) { return $callbook; } - function hamqth($username, $password, $callsign, $reduced) { + function hamqth($username, $password, $callsign) { // Load the HamQTH library if (!$this->ci->load->is_loaded('hamqth')) { $this->ci->load->library('hamqth'); @@ -122,13 +116,13 @@ function hamqth($username, $password, $callsign, $reduced) { $this->ci->session->set_userdata('hamqth_session_key', $hamqth_session_key); } - $callbook = $this->ci->hamqth->search($callsign, $this->ci->session->userdata('hamqth_session_key'), $reduced); + $callbook = $this->ci->hamqth->search($callsign, $this->ci->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->ci->hamqth->session($username, $password); $this->ci->session->set_userdata('hamqth_session_key', $hamqth_session_key); - $callbook = $this->ci->hamqth->search($callsign, $this->ci->session->userdata('hamqth_session_key'), $reduced); + $callbook = $this->ci->hamqth->search($callsign, $this->ci->session->userdata('hamqth_session_key')); } if (strpos($callbook['error'] ?? '', 'Not found') !== false && strpos($callsign, "/") !== false) { diff --git a/application/views/search/result.php b/application/views/search/result.php index 8fbe57a289..602f0684a0 100644 --- a/application/views/search/result.php +++ b/application/views/search/result.php @@ -1,9 +1,9 @@
-

+

-

+

-

+

@@ -26,7 +26,7 @@
- Date: Tue, 26 Nov 2024 09:46:40 +0100 Subject: [PATCH 16/17] Decoupled dxcc from callbook data because of reduced call logic --- application/controllers/Logbook.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/application/controllers/Logbook.php b/application/controllers/Logbook.php index 13882f3689..42bda1db35 100644 --- a/application/controllers/Logbook.php +++ b/application/controllers/Logbook.php @@ -827,12 +827,18 @@ function partial($lookupcall, $callbook, $callsign, $band = null) { } else { $callsigninfo['callsign'] = $callbook; - if (isset($callsigninfo['callsign']['dxcc'])) { + if ($callsigninfo['callsign']['dxcc'] !== "") { $this->load->model('logbook_model'); $entity = $this->logbook_model->get_entity($callsigninfo['callsign']['dxcc']); $callsigninfo['callsign']['dxcc_name'] = $entity['name']; $callsigninfo['dxcc_worked'] = $this->logbook_model->check_if_dxcc_worked_in_logbook($callsigninfo['callsign']['dxcc'], null, $this->session->userdata('user_default_band')); $callsigninfo['dxcc_confirmed'] = $this->logbook_model->check_if_dxcc_cnfmd_in_logbook($callsigninfo['callsign']['dxcc'], null, $this->session->userdata('user_default_band')); + } else { + $this->load->model('logbook_model'); + $dxcc = $this->logbook_model->check_dxcc_table($callsign, date('Ymd', time())); + $callsigninfo['callsign']['dxcc_name'] = $dxcc[1]; + $callsigninfo['dxcc_worked'] = $this->logbook_model->check_if_dxcc_worked_in_logbook($dxcc[0], null, $this->session->userdata('user_default_band')); + $callsigninfo['dxcc_confirmed'] = $this->logbook_model->check_if_dxcc_cnfmd_in_logbook($dxcc[0], null, $this->session->userdata('user_default_band')); } if (isset($callsigninfo['callsign']['gridsquare'])) { From 627a92d6d51115487ed05d8cf2cff0e9772a9146 Mon Sep 17 00:00:00 2001 From: Andreas Kristiansen <6977712+AndreasK79@users.noreply.github.com> Date: Tue, 26 Nov 2024 17:21:11 +0100 Subject: [PATCH 17/17] Do not fetch data twice, pass it on instead --- application/controllers/Logbook.php | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/application/controllers/Logbook.php b/application/controllers/Logbook.php index 42bda1db35..32665b82ec 100644 --- a/application/controllers/Logbook.php +++ b/application/controllers/Logbook.php @@ -97,7 +97,8 @@ function json($tempcallsign, $tempband, $tempmode, $tempstation_id = null, $date // Check Database for all other data $this->load->model('logbook_model'); - $lotw_days=$this->logbook_model->check_last_lotw($callsign); + $lotw_days = $this->logbook_model->check_last_lotw($callsign); + if ($lotw_days != null) { $lotw_member="active"; } else { @@ -131,7 +132,7 @@ function json($tempcallsign, $tempband, $tempmode, $tempstation_id = null, $date $callbook = $this->logbook_model->loadCallBook($callsign, $this->config->item('use_fullname')); - $return['partial'] = $this->partial($lookupcall, $callbook, $callsign, $band); + $return['partial'] = $this->partial($lookupcall, $callbook, $callsign, $return['dxcc'], $lotw_days, $band); if ($this->session->userdata('user_measurement_base') == NULL) { $measurement_base = $this->config->item('measurement_base'); @@ -614,7 +615,7 @@ function view($id) { $this->load->view('interface_assets/footer'); } - function partial($lookupcall, $callbook, $callsign, $band = null) { + function partial($lookupcall, $callbook, $callsign, $dxcc, $lotw_days, $band = null) { $this->load->model('user_model'); if(!$this->user_model->authorize($this->config->item('auth_mode'))) { return; } @@ -827,18 +828,11 @@ function partial($lookupcall, $callbook, $callsign, $band = null) { } else { $callsigninfo['callsign'] = $callbook; - if ($callsigninfo['callsign']['dxcc'] !== "") { - $this->load->model('logbook_model'); - $entity = $this->logbook_model->get_entity($callsigninfo['callsign']['dxcc']); - $callsigninfo['callsign']['dxcc_name'] = $entity['name']; - $callsigninfo['dxcc_worked'] = $this->logbook_model->check_if_dxcc_worked_in_logbook($callsigninfo['callsign']['dxcc'], null, $this->session->userdata('user_default_band')); - $callsigninfo['dxcc_confirmed'] = $this->logbook_model->check_if_dxcc_cnfmd_in_logbook($callsigninfo['callsign']['dxcc'], null, $this->session->userdata('user_default_band')); - } else { + if ($dxcc['adif'] !== 0) { $this->load->model('logbook_model'); - $dxcc = $this->logbook_model->check_dxcc_table($callsign, date('Ymd', time())); - $callsigninfo['callsign']['dxcc_name'] = $dxcc[1]; - $callsigninfo['dxcc_worked'] = $this->logbook_model->check_if_dxcc_worked_in_logbook($dxcc[0], null, $this->session->userdata('user_default_band')); - $callsigninfo['dxcc_confirmed'] = $this->logbook_model->check_if_dxcc_cnfmd_in_logbook($dxcc[0], null, $this->session->userdata('user_default_band')); + $callsigninfo['callsign']['dxcc_name'] = $dxcc['entity']; + $callsigninfo['dxcc_worked'] = $this->logbook_model->check_if_dxcc_worked_in_logbook($dxcc['adif'], null, $this->session->userdata('user_default_band')); + $callsigninfo['dxcc_confirmed'] = $this->logbook_model->check_if_dxcc_cnfmd_in_logbook($dxcc['adif'], null, $this->session->userdata('user_default_band')); } if (isset($callsigninfo['callsign']['gridsquare'])) { @@ -852,7 +846,7 @@ function partial($lookupcall, $callbook, $callsign, $band = null) { $callsigninfo['lookupcall'] = strtoupper($lookupcall); $callsigninfo['realcall'] = strtoupper($callsign); - $callsigninfo['lotw_lastupload'] = $this->logbook_model->check_last_lotw($callsign); + $callsigninfo['lotw_lastupload'] = $lotw_days; return $this->load->view('search/result', $callsigninfo, true); } } @@ -909,7 +903,8 @@ function search_result($id="", $id2="") { $data['error'] = $data['callsign']['error']; } - $data['id'] = strtoupper($id); + $data['lookupcall'] = strtoupper($id); + $data['realcall'] = strtoupper($id); $data['lotw_lastupload'] = $this->logbook_model->check_last_lotw($id); $this->load->view('search/result', $data); pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy