kopia lustrzana https://github.com/magicbug/Cloudlog
Add archive status for LoTW certificates
Introduces an 'archived' boolean column to the lotw_certs table via migration, adds model and controller logic to toggle archive status, and updates the view to display and allow archiving/unarchiving of certificates. This enables users to mark LoTW certificates as archived for better management.WillItBreak
rodzic
82a5edc9b7
commit
67a652bce6
|
@ -22,7 +22,7 @@ $config['migration_enabled'] = TRUE;
|
|||
|
|
||||
*/
|
||||
|
||||
$config['migration_version'] = 208;
|
||||
$config['migration_version'] = 209;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
|
@ -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/');
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* Class Migration_lotw_cert_archive_status
|
||||
*
|
||||
* Adds a simple boolean `archived` column to the `lotw_certs` table so
|
||||
* certificates can be marked as archived.
|
||||
*/
|
||||
class Migration_lotw_cert_archive_status extends CI_Migration {
|
||||
|
||||
public function up()
|
||||
{
|
||||
if (! $this->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');
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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(
|
||||
|
|
|
@ -78,12 +78,16 @@
|
|||
<?php $current_date = date('Y-m-d H:i:s'); ?>
|
||||
<?php $warning_date = date('Y-m-d H:i:s', strtotime($row->date_expires.'-30 days')); ?>
|
||||
|
||||
<?php if ($current_date > $row->date_expires) { ?>
|
||||
<span class="badge text-bg-danger"><?php echo lang('lotw_expired'); ?></span>
|
||||
<?php } else if ($current_date <= $row->date_expires && $current_date > $warning_date) { ?>
|
||||
<span class="badge text-bg-warning"><?php echo lang('lotw_expiring'); ?></span>
|
||||
<?php if ($row->archived) { ?>
|
||||
<span class="badge text-bg-secondary"><?php echo 'Archived'; ?></span>
|
||||
<?php } else { ?>
|
||||
<span class="badge text-bg-success"><?php echo lang('lotw_valid'); ?></span>
|
||||
<?php if ($current_date > $row->date_expires) { ?>
|
||||
<span class="badge text-bg-danger"><?php echo lang('lotw_expired'); ?></span>
|
||||
<?php } else if ($current_date <= $row->date_expires && $current_date > $warning_date) { ?>
|
||||
<span class="badge text-bg-warning"><?php echo lang('lotw_expiring'); ?></span>
|
||||
<?php } else { ?>
|
||||
<span class="badge text-bg-success"><?php echo lang('lotw_valid'); ?></span>
|
||||
<?php } ?>
|
||||
<?php } ?>
|
||||
|
||||
<?php if ($row->last_upload) {
|
||||
|
@ -94,6 +98,15 @@
|
|||
<?php } ?>
|
||||
</td>
|
||||
<td>
|
||||
<?php if ($row->archived) { ?>
|
||||
<a class="btn btn-outline-info btn-sm me-1" href="<?php echo site_url('lotw/toggle_archive_cert/'.$row->lotw_cert_id); ?>" role="button">
|
||||
<i class="fas fa-box-open"></i> Unarchive
|
||||
</a>
|
||||
<?php } else { ?>
|
||||
<a class="btn btn-outline-secondary btn-sm me-1" href="<?php echo site_url('lotw/toggle_archive_cert/'.$row->lotw_cert_id); ?>" role="button">
|
||||
<i class="fas fa-archive"></i> Archive
|
||||
</a>
|
||||
<?php } ?>
|
||||
<a class="btn btn-outline-danger btn-sm" href="<?php echo site_url('lotw/delete_cert/'.$row->lotw_cert_id); ?>" role="button"><i class="far fa-trash-alt"></i> <?php echo lang('lotw_btn_delete'); ?></a>
|
||||
</td>
|
||||
</tr>
|
||||
|
|
Ładowanie…
Reference in New Issue