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..c1cfff09 100644 --- a/application/controllers/Lotw.php +++ b/application/controllers/Lotw.php @@ -142,31 +142,21 @@ 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'], $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.'); @@ -225,10 +215,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 +234,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'); @@ -443,6 +430,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..53d16e15 --- /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..2fbd8f5f 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'); @@ -20,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'); @@ -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/adif_views/adif_export.php b/application/views/lotw_views/adif_views/adif_export.php index beae7f16..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; ?> -adif); ?>>adif; ?> +cert_dxcc_id); ?>>cert_dxcc_id; ?> station_gridsquare)) { ?>station_gridsquare); ?>>station_gridsquare; ?> diff --git a/application/views/lotw_views/index.php b/application/views/lotw_views/index.php index 24b42e2f..9bed8842 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 ); @@ -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'); ?> 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'); ?> -
-