diff --git a/application/controllers/Logbook.php b/application/controllers/Logbook.php
index 9f77851bd..ca03bc86a 100644
--- a/application/controllers/Logbook.php
+++ b/application/controllers/Logbook.php
@@ -825,82 +825,33 @@ class Logbook extends CI_Controller {
$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 (!$this->load->is_loaded('callbook')) {
+ $this->load->library('callbook');
+ }
- 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');
+ $callsign['callsign'] = $this->callbook->getCallbookData($id);
- 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 (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->hamqth->search($id, $this->session->userdata('hamqth_session_key'));
+ 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 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.';
- }
+ if (isset($callsign['callsign']['error'])) {
+ $callsign['error'] = $callsign['callsign']['error'];
+ }
- // There's no hamli integration? Disabled for now.
- /*else {
- // Lookup using hamli
- $this->load->library('hamli');
-
- $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']['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 @@ class Logbook extends CI_Controller {
$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->load->is_loaded('callbook')) {
+ $this->load->library('callbook');
+ }
- 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->callbook->getCallbookData($id);
- $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 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->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 000000000..e90303472
--- /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 000000000..4612c0cad
--- /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 c7d8762a4..96865f602 100644
--- a/application/models/Logbook_model.php
+++ b/application/models/Logbook_model.php
@@ -278,8 +278,8 @@ class Logbook_model extends CI_Model {
$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 @@ class Logbook_model extends CI_Model {
$binding=[];
if ($station_ids == null) {
return [];
- }
+ }
$extrawhere = $this->qsl_default_where($user_default_confirmation);
@@ -4270,7 +4270,7 @@ class Logbook_model extends CI_Model {
'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 @@ class Logbook_model extends CI_Model {
} 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 @@ class Logbook_model extends CI_Model {
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');
- }
+ $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);
- }
-
- $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 @@ class Logbook_model extends CI_Model {
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;
}