From 4f6b47e2152a6fc72bc8e6402731690bc050bb45 Mon Sep 17 00:00:00 2001 From: HB9HIL Date: Thu, 19 Dec 2024 22:21:51 +0100 Subject: [PATCH] fix adding qso to list (incl. prev qsl) --- application/controllers/Qslprint.php | 10 +++ application/models/Qslprint_model.php | 20 +++++ application/views/qslprint/qsolist.php | 1 - assets/js/sections/qslprint.js | 117 +++++++++++++++---------- 4 files changed, 102 insertions(+), 46 deletions(-) diff --git a/application/controllers/Qslprint.php b/application/controllers/Qslprint.php index 9ed492eec..ae4fceea5 100644 --- a/application/controllers/Qslprint.php +++ b/application/controllers/Qslprint.php @@ -197,6 +197,16 @@ class QSLPrint extends CI_Controller { $this->load->view('oqrs/showoqrs', $data); } + public function get_previous_qsl() { + $id = $this->security->xss_clean($this->input->post('id')); + + $this->load->model('qslprint_model'); + + $number_qsls = $this->qslprint_model->get_previous_qsls($id); + header('Content-Type: application/json'); + echo json_encode($number_qsls); + } + } /* End of file Qslprint.php */ diff --git a/application/models/Qslprint_model.php b/application/models/Qslprint_model.php index 8fab52775..bfaedf738 100644 --- a/application/models/Qslprint_model.php +++ b/application/models/Qslprint_model.php @@ -146,6 +146,26 @@ class Qslprint_model extends CI_Model { return $query; } + function get_previous_qsls($qso_id) { + if (empty($qso_id)) { + return 0; + } + + $table_name = $this->config->item('table_name'); + $sql = "SELECT COUNT(COL_PRIMARY_KEY) AS previous_qsl + FROM $table_name + WHERE COL_QSL_SENT = 'Y' + AND station_id = (SELECT station_id FROM $table_name WHERE COL_PRIMARY_KEY = ?) + AND (COL_CALL, COL_MODE, COL_BAND, COALESCE(COL_SAT_NAME, '')) = + (SELECT COL_CALL, COL_MODE, COL_BAND, COALESCE(COL_SAT_NAME, '') + FROM $table_name + WHERE COL_PRIMARY_KEY = ?) + GROUP BY COL_CALL, COL_MODE, COL_BAND, COL_SAT_NAME"; + + // we only return the count of previous QSLs as an integer + return (int) $this->db->query($sql, [$qso_id, $qso_id])->row()->previous_qsl; + } + function show_oqrs($id) { $this->db->select('requesttime as "Request time", requestcallsign as "Requester", email as "Email", note as "Note"'); $this->db->join('station_profile', 'station_profile.station_id = oqrs.station_id'); diff --git a/application/views/qslprint/qsolist.php b/application/views/qslprint/qsolist.php index db288a769..a9245606b 100644 --- a/application/views/qslprint/qsolist.php +++ b/application/views/qslprint/qsolist.php @@ -197,7 +197,6 @@ if ($qsos->result() != NULL) { } echo ''; echo ''; - echo ''; } echo ''; diff --git a/assets/js/sections/qslprint.js b/assets/js/sections/qslprint.js index ad50d2994..308b1ea72 100644 --- a/assets/js/sections/qslprint.js +++ b/assets/js/sections/qslprint.js @@ -1,3 +1,5 @@ +let qsoDialogInstance = null; + function deleteFromQslQueue(id) { BootstrapDialog.confirm({ title: 'DANGER', @@ -25,7 +27,7 @@ function openQsoList(callsign) { type: 'post', data: {'callsign': callsign}, success: function(html) { - BootstrapDialog.show({ + qsoDialogInstance = BootstrapDialog.show({ title: 'QSO List', size: BootstrapDialog.SIZE_WIDE, cssClass: 'qso-dialog', @@ -46,51 +48,76 @@ function openQsoList(callsign) { } function addQsoToPrintQueue(id) { - $.ajax({ - url: base_url + 'index.php/qslprint/add_qso_to_print_queue', - type: 'post', - data: {'id': id}, - success: function(html) { - var callSign = $("#qsolist_"+id).find("td:eq(0)").text(); - var formattedCallSign = callSign.replace(/0/g, "Ø").toUpperCase(); - var line = ''; - line += '
'; - line += ''; - line += ''; - line += ''; - line += formattedCallSign; - line += ''; - line += ''; - line += 'Lookup ' + formattedCallSign + ' on QRZ.com'; - line += ' '; - line += ''; - line += 'Lookup ' + formattedCallSign + ' on HamQTH'; - line += ' '; - line += ''; - line += 'Lookup ' + formattedCallSign + ' on eQSL.cc'; - line += ''; - line += ''; - line += ''; + $.ajax({ + url: base_url + 'index.php/qslprint/get_previous_qsl', + type: 'post', + data: { 'id': id }, + success: function(result) { + let prev_qsl = result; + let prev_qsl_html; - line += ''+$("#qsolist_"+id).find("td:eq(1)").text()+''; - line += ''+$("#qsolist_"+id).find("td:eq(2)").text()+''; - line += ''+$("#qsolist_"+id).find("td:eq(3)").text()+''; - line += ''+$("#qsolist_"+id).find("td:eq(4)").text()+''; - line += ''+$("#qsolist_"+id).find("td:eq(5)").text()+''; - line += ''+$("#qsolist_"+id).find("td:eq(6)").text()+''; - line += ''+$("#qsolist_"+id).find("td:eq(9)").text()+''; - line += ''+$("#qsolist_"+id).find("td:eq(7)").text()+''; - line += ''+$("#qsolist_"+id).find("td:eq(8)").text()+''; - line += ''+$("#qsolist_"+id).find("td:eq(10)").text()+''; - line += ''+$("#previous_qsl_"+id).html()+''; - line += ''; - line += ''; - line += ''; - line += ''; - $('#qslprint_table tr:last').after(line); - $("#qsolist_"+id).remove();'' - } - }); + if (prev_qsl > 0) { + prev_qsl_html = '' + prev_qsl + ''; + } else { + prev_qsl_html = '0'; + } + + $.ajax({ + url: base_url + 'index.php/qslprint/add_qso_to_print_queue', + type: 'post', + data: {'id': id}, + success: function(html) { + if (qsoDialogInstance) { + qsoDialogInstance.close(); + } + var callSign = $("#qsolist_"+id).find("td:eq(0)").text(); + var formattedCallSign = callSign.replace(/0/g, "Ø").toUpperCase(); + var line = ''; + line += '
'; + line += ''; + line += ''; + line += ''; + line += formattedCallSign; + line += ''; + line += ''; + line += 'Lookup ' + formattedCallSign + ' on QRZ.com'; + line += ' '; + line += ''; + line += 'Lookup ' + formattedCallSign + ' on HamQTH'; + line += ' '; + line += ''; + line += 'Lookup ' + formattedCallSign + ' on eQSL.cc'; + line += ''; + line += ''; + line += ''; + + line += ''+$("#qsolist_"+id).find("td:eq(1)").text()+''; + line += ''+$("#qsolist_"+id).find("td:eq(2)").text()+''; + line += ''+$("#qsolist_"+id).find("td:eq(3)").text()+''; + line += ''+$("#qsolist_"+id).find("td:eq(4)").text()+''; + line += ''+$("#qsolist_"+id).find("td:eq(5)").text()+''; + line += ''+$("#qsolist_"+id).find("td:eq(6)").text()+''; + line += ''+$("#qsolist_"+id).find("td:eq(9)").text()+''; + line += ''+$("#qsolist_"+id).find("td:eq(7)").text()+''; + line += ''+$("#qsolist_"+id).find("td:eq(8)").text()+''; + line += ''+$("#qsolist_"+id).find("td:eq(10)").text()+''; + line += ''+prev_qsl_html+''; + line += ''; + line += ''; + line += ''; + line += ''; + $('#qslprint_table tr:last').after(line); + $("#qsolist_"+id).remove(); + }, + error: function() { + console.error('Error adding QSO to print queue.'); + } + }); + }, + error: function() { + console.error('Error fetching previous QSL.'); + } + }); } $(".station_id").change(function(){