diff --git a/application/controllers/Lotw.php b/application/controllers/Lotw.php index bf4f48e2c..a709c5e6c 100644 --- a/application/controllers/Lotw.php +++ b/application/controllers/Lotw.php @@ -93,6 +93,7 @@ class Lotw extends CI_Controller { | | do_cert_upload is called from cert_upload form submit and handles uploading | and processing of p12 files and storing the data into mysql + | Now supports HTMX requests for modal-based uploads | */ public function do_cert_upload() @@ -106,6 +107,9 @@ class Lotw extends CI_Controller { echo "You must install php OpenSSL for LoTW functions to work"; } + // Check if this is an HTMX request + $is_htmx = $this->input->get_request_header('HX-Request'); + // create folder to store certs while processing if (!file_exists('./uploads/lotw/certs')) { mkdir('./uploads/lotw/certs', 0755, true); @@ -119,17 +123,21 @@ class Lotw extends CI_Controller { if ( ! $this->upload->do_upload('userfile')) { // Upload of P12 Failed - $error = array('error' => $this->upload->display_errors()); + $error = $this->upload->display_errors(); - // Load DXCC Countrys List + // If HTMX request, return just the error message + if($is_htmx) { + echo ''; + return; + } + + // Otherwise load the full form page + $data = array('error' => $error); $data['dxcc_list'] = $this->dxcc->list(); - - // Set Page Title $data['page_title'] = "Logbook of the World"; - // Load Views $this->load->view('interface_assets/header', $data); - $this->load->view('lotw_views/upload_cert', $error); + $this->load->view('lotw_views/upload_cert', $data); $this->load->view('interface_assets/footer'); } else @@ -152,20 +160,28 @@ class Lotw extends CI_Controller { $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.'); + $success_msg = $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'], $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 Updated.'); - + $success_msg = $info['issued_callsign'].' Certificate Updated.'; } // p12 certificate processed time to delete the file unlink($data['upload_data']['full_path']); + // If HTMX request, return just the success message + if($is_htmx) { + echo ''; + return; + } + + // Otherwise load the full page + $this->session->set_flashdata('Success', $success_msg); + // Get Array of the logged in users LoTW certs. $data['lotw_cert_results'] = $this->LotwCert->lotw_certs($this->session->userdata('user_id')); @@ -176,12 +192,31 @@ class Lotw extends CI_Controller { $this->load->view('interface_assets/header', $data); $this->load->view('lotw_views/index'); $this->load->view('interface_assets/footer'); - - - } } + /* + |-------------------------------------------------------------------------- + | Function: cert_table_refresh + |-------------------------------------------------------------------------- + | + | Returns the certificate table for HTMX refresh after upload + | + */ + public function cert_table_refresh() { + $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'); } + + // Load model + $this->load->model('LotwCert'); + + // Get Array of the logged in users LoTW certs. + $data['lotw_cert_results'] = $this->LotwCert->lotw_certs($this->session->userdata('user_id')); + + // Load just the cert table partial + $this->load->view('lotw_views/cert_table', $data); + } + /* |-------------------------------------------------------------------------- | Function: lotw_upload diff --git a/application/views/lotw_views/cert_table.php b/application/views/lotw_views/cert_table.php new file mode 100644 index 000000000..d89a308aa --- /dev/null +++ b/application/views/lotw_views/cert_table.php @@ -0,0 +1,112 @@ + + + + + + + + + +num_rows() > 0) { ?> + +
+ + + + + + + + + + + + + + + + + result() as $row) { ?> + + + + + + + + + + + + + +
callsign; ?>cert_dxcc == '' ? '- NONE -' : ucfirst($row->cert_dxcc); if ($row->cert_dxcc_end != NULL) { echo ' '.lang('gen_hamradio_deleted_dxcc').''; } ?>qso_start_date)) { + $valid_qso_start = strtotime( $row->qso_start_date ); + $new_valid_qso_start = date($this->config->item('qso_date_format'), $valid_qso_start ); + echo $new_valid_qso_start; + } else { + echo "n/a"; + } ?> + qso_end_date)) { + $valid_qso_end = strtotime( $row->qso_end_date ); + $new_valid_qso_end = date($this->config->item('qso_date_format'), $valid_qso_end ); + echo $new_valid_qso_end; + } else { + echo "n/a"; + } ?> + date_created ); + $new_valid_from = date($this->config->item('qso_date_format'), $valid_from ); + echo $new_valid_from; ?> + + date_expires ); + $new_valid_to = date($this->config->item('qso_date_format'), $valid_to ); + echo $new_valid_to; ?> + + + date_expires.'-30 days')); ?> + + archived) { ?> + + + $row->date_expires) { ?> + + date_expires && $current_date > $warning_date) { ?> + + + + + + + last_upload) { + $last_upload = date($this->config->item('qso_date_format').' H:i:s', strtotime( $row->last_upload )); ?> + + + + + + archived) { ?> + + Unarchive + + + + Archive + + + +
+
+ + + + diff --git a/application/views/lotw_views/index.php b/application/views/lotw_views/index.php index 70dda4fef..4db66be9d 100644 --- a/application/views/lotw_views/index.php +++ b/application/views/lotw_views/index.php @@ -6,129 +6,19 @@
- +
-
- - - - - - - - - num_rows() > 0) { ?> - -
- - - - - - - - - - - - - - - - - result() as $row) { ?> - - - - - - - - - - - - - -
callsign; ?>cert_dxcc == '' ? '- NONE -' : ucfirst($row->cert_dxcc); if ($row->cert_dxcc_end != NULL) { echo ' '.lang('gen_hamradio_deleted_dxcc').''; } ?>qso_start_date)) { - $valid_qso_start = strtotime( $row->qso_start_date ); - $new_valid_qso_start = date($this->config->item('qso_date_format'), $valid_qso_start ); - echo $new_valid_qso_start; - } else { - echo "n/a"; - } ?> - qso_end_date)) { - $valid_qso_end = strtotime( $row->qso_end_date ); - $new_valid_qso_end = date($this->config->item('qso_date_format'), $valid_qso_end ); - echo $new_valid_qso_end; - } else { - echo "n/a"; - } ?> - date_created ); - $new_valid_from = date($this->config->item('qso_date_format'), $valid_from ); - echo $new_valid_from; ?> - - date_expires ); - $new_valid_to = date($this->config->item('qso_date_format'), $valid_to ); - echo $new_valid_to; ?> - - - date_expires.'-30 days')); ?> - - archived) { ?> - - - $row->date_expires) { ?> - - date_expires && $current_date > $warning_date) { ?> - - - - - - - last_upload) { - $last_upload = date($this->config->item('qso_date_format').' H:i:s', strtotime( $row->last_upload )); ?> - - - - - - archived) { ?> - - Unarchive - - - - Archive - - - -
-
- - - - - -
+
+ load->view('lotw_views/cert_table', array('lotw_cert_results' => $lotw_cert_results)); ?> +

- + + num_rows() > 0) { ?>
@@ -146,9 +36,13 @@
+ + +load->view('lotw_views/upload_cert_modal'); ?> + + +