From 19c72eb75ade2c39e8f7f7cd389ac15e68518f12 Mon Sep 17 00:00:00 2001 From: phl0 Date: Wed, 19 Apr 2023 15:32:32 +0200 Subject: [PATCH 1/6] Use DXCC ID from LotW certificate (rather than selecting DXCC manually) --- application/config/migration.php | 2 +- application/controllers/Lotw.php | 7 ++-- .../migrations/118_make_lotw_use_dxcc_id.php | 37 +++++++++++++++++++ application/models/LotwCert.php | 10 +++-- application/views/lotw_views/index.php | 2 +- application/views/lotw_views/upload_cert.php | 13 ------- 6 files changed, 49 insertions(+), 22 deletions(-) create mode 100644 application/migrations/118_make_lotw_use_dxcc_id.php diff --git a/application/config/migration.php b/application/config/migration.php index 7c7fc559..7b38f822 100644 --- a/application/config/migration.php +++ b/application/config/migration.php @@ -21,7 +21,7 @@ $config['migration_enabled'] = TRUE; | be upgraded / downgraded to. | */ -$config['migration_version'] = 117; +$config['migration_version'] = 118; /* |-------------------------------------------------------------------------- diff --git a/application/controllers/Lotw.php b/application/controllers/Lotw.php index e5be23f0..dae87a32 100644 --- a/application/controllers/Lotw.php +++ b/application/controllers/Lotw.php @@ -153,20 +153,20 @@ class Lotw extends CI_Controller { } // Check to see if certificate is already in the system - $new_certificate = $this->LotwCert->find_cert($info['issued_callsign'], $dxcc, $this->session->userdata('user_id')); + $new_certificate = $this->LotwCert->find_cert($info['issued_callsign'], $info['dxcc-id'], $this->session->userdata('user_id')); if($new_certificate == 0) { // New Certificate Store in Database // Store Certificate Data into MySQL - $this->LotwCert->store_certificate($this->session->userdata('user_id'), $info['issued_callsign'], $dxcc, $info['validFrom'], $info['validTo_Date'], $info['qso-first-date'], $info['qso-end-date'], $info['pem_key'], $info['general_cert']); + $this->LotwCert->store_certificate($this->session->userdata('user_id'), $info['issued_callsign'], $info['dxcc-id'], $info['validFrom'], $info['validTo_Date'], $info['qso-first-date'], $info['qso-end-date'], $info['pem_key'], $info['general_cert']); // Cert success flash message $this->session->set_flashdata('Success', $info['issued_callsign'].' Certificate Imported.'); } else { // Certificate is in the system time to update - $this->LotwCert->update_certificate($this->session->userdata('user_id'), $info['issued_callsign'], $dxcc, $info['validFrom'], $info['validTo_Date'], $info['pem_key'], $info['general_cert']); + $this->LotwCert->update_certificate($this->session->userdata('user_id'), $info['issued_callsign'], $info['dxcc-id'], $info['validFrom'], $info['validTo_Date'], $info['pem_key'], $info['general_cert']); // Cert success flash message $this->session->set_flashdata('Success', $info['issued_callsign'].' Certificate Updated.'); @@ -443,6 +443,7 @@ class Lotw extends CI_Controller { // https://oidref.com/1.3.6.1.4.1.12348.1 $data['qso-first-date'] = $certdata['extensions']['1.3.6.1.4.1.12348.1.2']; $data['qso-end-date'] = $certdata['extensions']['1.3.6.1.4.1.12348.1.3']; + $data['dxcc-id'] = $certdata['extensions']['1.3.6.1.4.1.12348.1.4']; return $data; } diff --git a/application/migrations/118_make_lotw_use_dxcc_id.php b/application/migrations/118_make_lotw_use_dxcc_id.php new file mode 100644 index 00000000..69fd7d2c --- /dev/null +++ b/application/migrations/118_make_lotw_use_dxcc_id.php @@ -0,0 +1,37 @@ +db->field_exists('cert_dxcc_id', 'lotw_certs')) { + $this->dbforge->add_column('lotw_certs', $fields); + } + + $sql = 'UPDATE `lotw_certs` JOIN `dxcc_entities` ON `lotw_certs`.`cert_dxcc` = `dxcc_entities`.`name` SET `lotw_certs`.`cert_dxcc_id` = `dxcc_entities`.`adif`;'; + $this->db->query($sql); + + $this->dbforge->drop_column('lotw_certs', 'cert_dxcc'); + } + + public function down() + { + $fields = array( + 'cert_dxcc VARCHAR(255) NOT NULL AFTER `callsign`', + ); + + if (!$this->db->field_exists('cert_dxcc', 'lotw_certs')) { + $this->dbforge->add_column('lotw_certs', $fields); + } + + $sql = 'UPDATE `lotw_certs` JOIN `dxcc_entities` ON `lotw_certs`.`cert_dxcc_id` = `dxcc_entities`.`adif` SET `lotw_certs`.`cert_dxcc` = `dxcc_entities`.`name`;'; + $this->db->query($sql); + + $this->dbforge->drop_column('lotw_certs', 'cert_dxcc_id'); + } +} diff --git a/application/models/LotwCert.php b/application/models/LotwCert.php index 185e3fa2..28862ff0 100644 --- a/application/models/LotwCert.php +++ b/application/models/LotwCert.php @@ -12,7 +12,9 @@ class LotwCert extends CI_Model { */ function lotw_certs($user_id) { + $this->db->select('lotw_certs.lotw_cert_id as lotw_cert_id, lotw_certs.callsign as callsign, dxcc_entities.name as cert_dxcc, lotw_certs.qso_start_date as qso_start_date, lotw_certs.qso_end_date as qso_end_date, lotw_certs.date_created as date_created, lotw_certs.date_expires as date_expires, lotw_certs.last_upload as last_upload'); $this->db->where('user_id', $user_id); + $this->db->join('dxcc_entities','lotw_certs.cert_dxcc_id = dxcc_entities.adif','left'); $this->db->order_by('cert_dxcc', 'ASC'); $query = $this->db->get('lotw_certs'); @@ -29,7 +31,7 @@ class LotwCert extends CI_Model { function find_cert($callsign, $dxcc, $user_id) { $this->db->where('user_id', $user_id); - $this->db->where('cert_dxcc', $dxcc); + $this->db->where('cert_dxcc_id', $dxcc); $this->db->where('callsign', $callsign); $query = $this->db->get('lotw_certs'); @@ -40,7 +42,7 @@ class LotwCert extends CI_Model { $data = array( 'user_id' => $user_id, 'callsign' => $callsign, - 'cert_dxcc' => $dxcc, + 'cert_dxcc_id' => $dxcc, 'date_created' => $date_created, 'date_expires' => $date_expires, 'qso_start_date' => $qso_start_date, @@ -54,7 +56,7 @@ class LotwCert extends CI_Model { function update_certificate($user_id, $callsign, $dxcc, $date_created, $date_expires, $cert_key, $general_cert) { $data = array( - 'cert_dxcc' => $dxcc, + 'cert_dxcc_id' => $dxcc, 'date_created' => $date_created, 'date_expires' => $date_expires, 'cert_key' => $cert_key, @@ -63,7 +65,7 @@ class LotwCert extends CI_Model { $this->db->where('user_id', $user_id); $this->db->where('callsign', $callsign); - $this->db->where('cert_dxcc', $dxcc); + $this->db->where('cert_dxcc_id', $dxcc); $this->db->update('lotw_certs', $data); } diff --git a/application/views/lotw_views/index.php b/application/views/lotw_views/index.php index 24b42e2f..14f8e376 100644 --- a/application/views/lotw_views/index.php +++ b/application/views/lotw_views/index.php @@ -44,7 +44,7 @@ result() as $row) { ?> callsign; ?> - cert_dxcc); ?> + cert_dxcc == '' ? '- NONE -' : ucfirst($row->cert_dxcc); ?> qso_start_date)) { $valid_qso_start = strtotime( $row->qso_start_date ); diff --git a/application/views/lotw_views/upload_cert.php b/application/views/lotw_views/upload_cert.php index 78018d41..e9aa6e61 100644 --- a/application/views/lotw_views/upload_cert.php +++ b/application/views/lotw_views/upload_cert.php @@ -32,19 +32,6 @@ -
- - num_rows() > 0) { ?> - - - lang->line('lotw_certificate_dxcc_help_text'); ?> -
- From 607a3a72d974202bbf61b521f0804d29b0cc2ae0 Mon Sep 17 00:00:00 2001 From: phl0 Date: Wed, 19 Apr 2023 22:06:32 +0200 Subject: [PATCH 2/6] Use DXCC ID from LotW cert for uploads --- application/controllers/Lotw.php | 7 ++----- application/models/LotwCert.php | 2 +- application/views/lotw_views/adif_views/adif_export.php | 2 +- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/application/controllers/Lotw.php b/application/controllers/Lotw.php index dae87a32..9799d086 100644 --- a/application/controllers/Lotw.php +++ b/application/controllers/Lotw.php @@ -225,10 +225,10 @@ class Lotw extends CI_Controller { // Get Certificate Data $this->load->model('LotwCert'); $data['station_profile'] = $station_profile; - $data['lotw_cert_info'] = $this->LotwCert->lotw_cert_details($station_profile->station_callsign, $station_profile->station_country); + $data['lotw_cert_info'] = $this->LotwCert->lotw_cert_details($station_profile->station_callsign, $station_profile->station_dxcc); // If Station Profile has no LOTW Cert continue on. - if(!isset($data['lotw_cert_info']->cert_dxcc)) { + if(!isset($data['lotw_cert_info']->cert_dxcc_id)) { continue; } @@ -244,9 +244,6 @@ class Lotw extends CI_Controller { continue; } - $this->load->model('Dxcc'); - $data['station_profile_dxcc'] = $this->Dxcc->lookup_country($data['lotw_cert_info']->cert_dxcc); - // Get QSOs $this->load->model('Logbook_model'); diff --git a/application/models/LotwCert.php b/application/models/LotwCert.php index 28862ff0..2fbd8f5f 100644 --- a/application/models/LotwCert.php +++ b/application/models/LotwCert.php @@ -22,7 +22,7 @@ class LotwCert extends CI_Model { } function lotw_cert_details($callsign, $dxcc) { - $this->db->where('cert_dxcc', $dxcc); + $this->db->where('cert_dxcc_id', $dxcc); $this->db->where('callsign', $callsign); $query = $this->db->get('lotw_certs'); diff --git a/application/views/lotw_views/adif_views/adif_export.php b/application/views/lotw_views/adif_views/adif_export.php index beae7f16..2d86d8a9 100644 --- a/application/views/lotw_views/adif_views/adif_export.php +++ b/application/views/lotw_views/adif_views/adif_export.php @@ -17,7 +17,7 @@ $cert2 = str_replace("-----END CERTIFICATE-----", "", $cert1); 1 callsign); ?>>callsign; ?> -adif); ?>>adif; ?> +cert_dxcc_id); ?>>cert_dxcc_d; ?> station_gridsquare)) { ?>station_gridsquare); ?>>station_gridsquare; ?> From dde42136eebee4e19916b5a6b0df221ccb136c30 Mon Sep 17 00:00:00 2001 From: phl0 Date: Wed, 19 Apr 2023 22:10:44 +0200 Subject: [PATCH 3/6] Set default value in case DXCC id is missing --- application/migrations/118_make_lotw_use_dxcc_id.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/migrations/118_make_lotw_use_dxcc_id.php b/application/migrations/118_make_lotw_use_dxcc_id.php index 69fd7d2c..53d16e15 100644 --- a/application/migrations/118_make_lotw_use_dxcc_id.php +++ b/application/migrations/118_make_lotw_use_dxcc_id.php @@ -6,7 +6,7 @@ class Migration_make_lotw_use_dxcc_id extends CI_Migration public function up() { $fields = array( - 'cert_dxcc_id SMALLINT(6) NOT NULL AFTER `cert_dxcc`', + 'cert_dxcc_id SMALLINT(6) DEFAULT 0 NOT NULL AFTER `cert_dxcc`', ); if (!$this->db->field_exists('cert_dxcc_id', 'lotw_certs')) { From 56b25e072ee99bf7d69597137bcab19b8063246d Mon Sep 17 00:00:00 2001 From: phl0 Date: Wed, 19 Apr 2023 22:18:33 +0200 Subject: [PATCH 4/6] Delete (now) stray code (assuming there is no LotW cert without DXCC id --- application/controllers/Lotw.php | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/application/controllers/Lotw.php b/application/controllers/Lotw.php index 9799d086..c1cfff09 100644 --- a/application/controllers/Lotw.php +++ b/application/controllers/Lotw.php @@ -142,16 +142,6 @@ class Lotw extends CI_Controller { $info = $this->decrypt_key($data['upload_data']['full_path']); - // Check DXCC & Store Country Name - $this->load->model('Logbook_model'); - - if($this->input->post('dxcc') != "") { - $dxcc = $this->input->post('dxcc'); - } else{ - $dxcc_check = $this->Logbook_model->check_dxcc_table($info['issued_callsign'], $info['validFrom']); - $dxcc = $dxcc_check[1]; - } - // Check to see if certificate is already in the system $new_certificate = $this->LotwCert->find_cert($info['issued_callsign'], $info['dxcc-id'], $this->session->userdata('user_id')); From 398e43dbc467e349e0b2059abff6409dcbac8a99 Mon Sep 17 00:00:00 2001 From: phl0 Date: Wed, 19 Apr 2023 22:24:02 +0200 Subject: [PATCH 5/6] Fix typo --- application/views/lotw_views/adif_views/adif_export.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/views/lotw_views/adif_views/adif_export.php b/application/views/lotw_views/adif_views/adif_export.php index 2d86d8a9..39b9e0cf 100644 --- a/application/views/lotw_views/adif_views/adif_export.php +++ b/application/views/lotw_views/adif_views/adif_export.php @@ -17,7 +17,7 @@ $cert2 = str_replace("-----END CERTIFICATE-----", "", $cert1); 1 callsign); ?>>callsign; ?> -cert_dxcc_id); ?>>cert_dxcc_d; ?> +cert_dxcc_id); ?>>cert_dxcc_id; ?> station_gridsquare)) { ?>station_gridsquare); ?>>station_gridsquare; ?> From 5decf0b35343493894f837b1e563ea1f2b040c1b Mon Sep 17 00:00:00 2001 From: phl0 Date: Thu, 20 Apr 2023 08:07:29 +0200 Subject: [PATCH 6/6] Appyly custom date format also to status badge --- application/views/lotw_views/index.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/application/views/lotw_views/index.php b/application/views/lotw_views/index.php index 14f8e376..9bed8842 100644 --- a/application/views/lotw_views/index.php +++ b/application/views/lotw_views/index.php @@ -86,8 +86,9 @@ lang->line('lotw_valid'); ?> - last_upload) { ?> - last_upload; ?> + last_upload) { + $last_upload = date($this->config->item('qso_date_format').' H:i:s', strtotime( $row->last_upload )); ?> + lang->line('lotw_not_synced'); ?>