diff --git a/application/config/migration.php b/application/config/migration.php index d1869307..1bbb1a0a 100644 --- a/application/config/migration.php +++ b/application/config/migration.php @@ -22,7 +22,7 @@ $config['migration_enabled'] = TRUE; | */ -$config['migration_version'] = 208; +$config['migration_version'] = 209; /* |-------------------------------------------------------------------------- diff --git a/application/controllers/Lotw.php b/application/controllers/Lotw.php index 753a8bec..d391d855 100644 --- a/application/controllers/Lotw.php +++ b/application/controllers/Lotw.php @@ -378,6 +378,31 @@ class Lotw extends CI_Controller { redirect('/lotw/'); } + /* + |-------------------------------------------------------------------------- + | Function: toggle_archive_cert + |-------------------------------------------------------------------------- + | + | Toggles the archive status of a LoTW certificate + | + */ + public function toggle_archive_cert($cert_id) { + $this->load->model('user_model'); + if(!$this->user_model->authorize(2)) { $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); redirect('dashboard'); } + + $this->load->model('LotwCert'); + + $result = $this->LotwCert->toggle_archive_certificate($this->session->userdata('user_id'), $cert_id); + + if($result['archived']) { + $this->session->set_flashdata('Success', 'Certificate Archived.'); + } else { + $this->session->set_flashdata('Success', 'Certificate Unarchived.'); + } + + redirect('/lotw/'); + } + /* |-------------------------------------------------------------------------- diff --git a/application/migrations/209_lotw_cert_archive_status.php b/application/migrations/209_lotw_cert_archive_status.php new file mode 100644 index 00000000..c7dd27aa --- /dev/null +++ b/application/migrations/209_lotw_cert_archive_status.php @@ -0,0 +1,30 @@ +db->field_exists('archived', 'lotw_certs')) { + $fields = array( + 'archived BOOLEAN DEFAULT FALSE', + ); + + $this->dbforge->add_column('lotw_certs', $fields); + } + } + + public function down() + { + if ($this->db->field_exists('archived', 'lotw_certs')) { + $this->dbforge->drop_column('lotw_certs', 'archived'); + } + } +} diff --git a/application/models/LotwCert.php b/application/models/LotwCert.php index 1dab4515..f2d2c9a8 100644 --- a/application/models/LotwCert.php +++ b/application/models/LotwCert.php @@ -12,7 +12,7 @@ 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, dxcc_entities.end as cert_dxcc_end, 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->select('lotw_certs.lotw_cert_id as lotw_cert_id, lotw_certs.callsign as callsign, dxcc_entities.name as cert_dxcc, dxcc_entities.end as cert_dxcc_end, 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, lotw_certs.archived as archived'); $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'); @@ -77,6 +77,29 @@ class LotwCert extends CI_Model { $this->db->delete('lotw_certs'); } + function toggle_archive_certificate($user_id, $lotw_cert_id) { + // First get current archive status + $this->db->select('archived'); + $this->db->where('lotw_cert_id', $lotw_cert_id); + $this->db->where('user_id', $user_id); + $query = $this->db->get('lotw_certs'); + + if($query->num_rows() == 0) { + return false; + } + + $current_status = $query->row()->archived; + $new_status = $current_status ? 0 : 1; + + // Update the archive status + $data = array('archived' => $new_status); + $this->db->where('lotw_cert_id', $lotw_cert_id); + $this->db->where('user_id', $user_id); + $this->db->update('lotw_certs', $data); + + return array('archived' => $new_status); + } + function last_upload($certID) { $data = array( diff --git a/application/views/lotw_views/index.php b/application/views/lotw_views/index.php index 741c666a..70dda4fe 100644 --- a/application/views/lotw_views/index.php +++ b/application/views/lotw_views/index.php @@ -78,12 +78,16 @@ date_expires.'-30 days')); ?> - $row->date_expires) { ?> - - date_expires && $current_date > $warning_date) { ?> - + archived) { ?> + - + $row->date_expires) { ?> + + date_expires && $current_date > $warning_date) { ?> + + + + last_upload) { @@ -94,6 +98,15 @@