From 8dd3f290a76fb4b11037fe5e8902cac0f6b4f761 Mon Sep 17 00:00:00 2001 From: Andreas <6977712+AndreasK79@users.noreply.github.com> Date: Tue, 27 Jun 2023 15:03:12 +0200 Subject: [PATCH 1/6] [Advanced Logbook] Now can print label from advanced logbook --- application/controllers/Labels.php | 36 ++++++++++--------- application/models/Labels_model.php | 12 +++++++ application/views/logbookadvanced/index.php | 3 ++ assets/js/sections/logbookadvanced.js | 39 +++++++++++++++++++++ 4 files changed, 74 insertions(+), 16 deletions(-) diff --git a/application/controllers/Labels.php b/application/controllers/Labels.php index 628b4dcd..908a23bd 100644 --- a/application/controllers/Labels.php +++ b/application/controllers/Labels.php @@ -87,22 +87,27 @@ class Labels extends CI_Controller { } + public function printids() { + $ids = xss_clean(json_decode($this->input->post('id'))); + $this->load->model('labels_model'); + $result = $this->labels_model->export_printrequestedids($ids); + + $this->prepareLabel($result); + } + public function print($station_id) { $clean_id = xss_clean($station_id); $this->load->model('labels_model'); $result = $this->labels_model->export_printrequested($clean_id); + $this->prepareLabel($result); + } + + function prepareLabel($qsos) { + $this->load->model('labels_model'); $label = $this->labels_model->getDefaultLabel(); - - // require_once('fpdf.php'); - // require('PDF_Label.php'); - // require_once APPPATH."/src/Label/PDF_Label.php"; - // require_once APPPATH."/src/Label/fpdf.php"; - - // Example of custom format - // $pdf = new PDF_Label(array('paper-size'=>'A4', 'metric'=>'mm', 'marginLeft'=>1, 'marginTop'=>1, 'NX'=>2, 'NY'=>7, 'SpaceX'=>0, 'SpaceY'=>0, 'width'=>99, 'height'=>38, 'font-size'=>14)); - + try { if ($label) { $pdf = new PDF_Label(array( @@ -127,9 +132,9 @@ class Labels extends CI_Controller { redirect('labels'); } define('FPDF_FONTPATH', './src/Label/font/'); - + $pdf->AddPage(); - + if ($label->font == 'DejaVuSans') { $pdf->AddFont($label->font,'','DejaVuSansMono.ttf',true); $pdf->SetFont($label->font); @@ -137,13 +142,12 @@ class Labels extends CI_Controller { $pdf->AddFont($label->font); $pdf->SetFont($label->font); } - - - if ($result->num_rows() > 0) { + + if ($qsos->num_rows() > 0) { if ($label->qsos == 1) { - $this->makeOneQsoLabel($result->result(), $pdf); + $this->makeOneQsoLabel($qsos->result(), $pdf); } else { - $this->makeMultiQsoLabel($result->result(), $pdf, $label->qsos); + $this->makeMultiQsoLabel($qsos->result(), $pdf, $label->qsos); } } else { $this->session->set_flashdata('message', '0 QSOs found for print!'); diff --git a/application/models/Labels_model.php b/application/models/Labels_model.php index 91c62027..c0c50494 100644 --- a/application/models/Labels_model.php +++ b/application/models/Labels_model.php @@ -127,4 +127,16 @@ class Labels_model extends CI_Model { return $query; } + + function export_printrequestedids($ids) { + $this->db->select($this->config->item('table_name').'.*, station_profile.*, dxcc_entities.name as station_country'); + $this->db->join('station_profile', 'station_profile.station_id = '.$this->config->item('table_name').'.station_id'); + $this->db->join('dxcc_entities', 'station_profile.station_dxcc = dxcc_entities.adif'); + $this->db->where('station_profile.user_id', $this->session->userdata('user_id')); + $this->db->where_in('COL_PRIMARY_KEY', $ids); + $this->db->order_by("COL_DXCC", "ASC"); + $query = $this->db->get($this->config->item('table_name')); + + return $query; + } } \ No newline at end of file diff --git a/application/views/logbookadvanced/index.php b/application/views/logbookadvanced/index.php index ed417d8b..230df578 100644 --- a/application/views/logbookadvanced/index.php +++ b/application/views/logbookadvanced/index.php @@ -191,7 +191,10 @@ + + + diff --git a/assets/js/sections/logbookadvanced.js b/assets/js/sections/logbookadvanced.js index 70f026da..05156ac4 100644 --- a/assets/js/sections/logbookadvanced.js +++ b/assets/js/sections/logbookadvanced.js @@ -348,6 +348,45 @@ $(document).ready(function () { $('#notRequired').click(function (event) { handleQsl('I','', 'notRequired'); }); + $('#receivedBureau').click(function (event) { + }); + $('#receivedDirect').click(function (event) { + }); + + $('#printLabel').click(function (event) { + var elements = $('#qsoList tbody input:checked'); + var nElements = elements.length; + if (nElements == 0) { + return; + } + $('#printLabel').prop("disabled", true); + + var id_list=[]; + + elements.each(function() { + let id = $(this).first().closest('tr').data('qsoID') + id_list.push(id); + }); + + $.ajax({ + url: base_url + 'index.php/labels/printids', + type: 'post', + data: {'id': JSON.stringify(id_list, null, 2) }, + xhr:function(){ + var xhr = new XMLHttpRequest(); + xhr.responseType= 'blob' + return xhr; + }, + success: function(data) { + if(data){ + var file = new Blob([data], {type: 'application/pdf'}); + var fileURL = URL.createObjectURL(file); + window.open(fileURL); + } + $('#printLabel').prop("disabled", false); + } + }); + }); $('#searchForm').on('reset', function(e) { setTimeout(function() { From cf05c9017dd7552ad20d24cac4eea82345cab3af Mon Sep 17 00:00:00 2001 From: Andreas <6977712+AndreasK79@users.noreply.github.com> Date: Tue, 27 Jun 2023 22:22:24 +0200 Subject: [PATCH 2/6] [Advanced Logbook] Unselects QSOs after printing label --- assets/js/sections/logbookadvanced.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/assets/js/sections/logbookadvanced.js b/assets/js/sections/logbookadvanced.js index 05156ac4..ecfad2ad 100644 --- a/assets/js/sections/logbookadvanced.js +++ b/assets/js/sections/logbookadvanced.js @@ -383,6 +383,9 @@ $(document).ready(function () { var fileURL = URL.createObjectURL(file); window.open(fileURL); } + $.each(id_list, function(k, v) { + unselectQsoID(this); + }); $('#printLabel').prop("disabled", false); } }); From aa139017d9a38f75335ec34d2a60219feb2a9ab4 Mon Sep 17 00:00:00 2001 From: Andreas <6977712+AndreasK79@users.noreply.github.com> Date: Wed, 28 Jun 2023 08:27:44 +0200 Subject: [PATCH 3/6] [Advanced Logbook] Received QSL (direct/bureau) can be set --- application/controllers/Logbookadvanced.php | 28 +++++++++++++++++ application/models/Logbookadvanced_model.php | 19 +++++++++++ assets/js/sections/logbookadvanced.js | 33 ++++++++++++++++++++ 3 files changed, 80 insertions(+) diff --git a/application/controllers/Logbookadvanced.php b/application/controllers/Logbookadvanced.php index 19daff37..b2ed5e60 100644 --- a/application/controllers/Logbookadvanced.php +++ b/application/controllers/Logbookadvanced.php @@ -184,4 +184,32 @@ class Logbookadvanced extends CI_Controller { header("Content-Type: application/json"); print json_encode($q); } + + function update_qsl_received() { + $this->load->model('logbookadvanced_model'); + + $ids = xss_clean($this->input->post('id')); + $user_id = (int)$this->session->userdata('user_id'); + $method = xss_clean($this->input->post('method')); + $sent = xss_clean($this->input->post('sent')); + + $status = $this->logbookadvanced_model->updateQslReceived($ids, $user_id, $method, $sent); + + $data = $this->logbookadvanced_model->getQsosForAdif($ids, $user_id); + + $results = $data->result('array'); + + $qsos = []; + foreach ($results as $data) { + $qsos[] = new QSO($data); + } + + $q = []; + foreach ($qsos as $qso) { + $q[] = $qso->toArray(); + } + + header("Content-Type: application/json"); + print json_encode($q); + } } \ No newline at end of file diff --git a/application/models/Logbookadvanced_model.php b/application/models/Logbookadvanced_model.php index f0571352..4fcdab99 100644 --- a/application/models/Logbookadvanced_model.php +++ b/application/models/Logbookadvanced_model.php @@ -136,6 +136,7 @@ class Logbookadvanced_model extends CI_Model { FROM " . $this->config->item('table_name') . " qsos INNER JOIN station_profile ON qsos.station_id = station_profile.station_id LEFT OUTER JOIN dxcc_entities ON qsos.COL_MY_DXCC = dxcc_entities.adif + LEFT OUTER JOIN lotw_users ON qsos.col_call=lotw_users.callsign WHERE station_profile.user_id = ? $where $order @@ -215,6 +216,24 @@ class Logbookadvanced_model extends CI_Model { } } + public function updateQslReceived($ids, $user_id, $method, $sent) { + $this->load->model('user_model'); + + if(!$this->user_model->authorize(2)) { + return array('message' => 'Error'); + } else { + $data = array( + 'COL_QSLRDATE' => date('Y-m-d H:i:s'), + 'COL_QSL_RCVD' => $sent, + 'COL_QSL_RCVD_VIA' => $method + ); + $this->db->where_in('COL_PRIMARY_KEY', json_decode($ids, true)); + $this->db->update($this->config->item('table_name'), $data); + + return array('message' => 'OK'); + } + } + public function updateQsoWithCallbookInfo($qsoID, $qso, $callbook) { $updatedData = array(); if (!empty($callbook['name']) && empty($qso['COL_NAME'])) { diff --git a/assets/js/sections/logbookadvanced.js b/assets/js/sections/logbookadvanced.js index ecfad2ad..8d688be0 100644 --- a/assets/js/sections/logbookadvanced.js +++ b/assets/js/sections/logbookadvanced.js @@ -349,8 +349,10 @@ $(document).ready(function () { handleQsl('I','', 'notRequired'); }); $('#receivedBureau').click(function (event) { + handleQslReceived('Y','B', 'receivedBureau'); }); $('#receivedDirect').click(function (event) { + handleQslReceived('Y','D', 'receivedDirect'); }); $('#printLabel').click(function (event) { @@ -428,6 +430,37 @@ $(document).ready(function () { }); } + function handleQslReceived(sent, method, tag) { + var elements = $('#qsoList tbody input:checked'); + var nElements = elements.length; + if (nElements == 0) { + return; + } + $('#'+tag).prop("disabled", true); + var id_list=[]; + elements.each(function() { + let id = $(this).first().closest('tr').data('qsoID') + id_list.push(id); + }); + $.ajax({ + url: base_url + 'index.php/logbookadvanced/update_qsl_received', + type: 'post', + data: {'id': JSON.stringify(id_list, null, 2), + 'sent' : sent, + 'method' : method + }, + success: function(data) { + if (data !== []) { + $.each(data, function(k, v) { + updateRow(this); + unselectQsoID(this.qsoID); + }); + } + $('#'+tag).prop("disabled", false); + } + }); + } + $('#checkBoxAll').change(function (event) { if (this.checked) { $('#qsoList tbody tr').each(function (i) { From e2b442d39ce0b51aaca51b1d6ea1b2bc31dfc401 Mon Sep 17 00:00:00 2001 From: Andreas <6977712+AndreasK79@users.noreply.github.com> Date: Wed, 28 Jun 2023 09:17:48 +0200 Subject: [PATCH 4/6] [Advanced Logbook] Fixed update query --- application/models/Logbookadvanced_model.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/application/models/Logbookadvanced_model.php b/application/models/Logbookadvanced_model.php index 4fcdab99..490450cf 100644 --- a/application/models/Logbookadvanced_model.php +++ b/application/models/Logbookadvanced_model.php @@ -132,10 +132,11 @@ class Logbookadvanced_model extends CI_Model { $order = $this->getSortorder($sortorder); $sql = " - SELECT *, dxcc_entities.name AS station_country + SELECT qsos.*, d2.*, lotw_users.*, station_profile.*, dxcc_entities.name AS station_country FROM " . $this->config->item('table_name') . " qsos INNER JOIN station_profile ON qsos.station_id = station_profile.station_id LEFT OUTER JOIN dxcc_entities ON qsos.COL_MY_DXCC = dxcc_entities.adif + LEFT OUTER JOIN dxcc_entities d2 ON qsos.COL_DXCC = d2.adif LEFT OUTER JOIN lotw_users ON qsos.col_call=lotw_users.callsign WHERE station_profile.user_id = ? $where From 4254a37642b47ca22c8926157dbc8232c9151bb3 Mon Sep 17 00:00:00 2001 From: Andreas <6977712+AndreasK79@users.noreply.github.com> Date: Wed, 28 Jun 2023 12:24:38 +0200 Subject: [PATCH 5/6] [Advanced Logbook] Added some error handling when printing labels --- application/controllers/Labels.php | 24 ++++++++++++++++++------ assets/js/sections/logbookadvanced.js | 17 ++++++++++++++++- 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/application/controllers/Labels.php b/application/controllers/Labels.php index 908a23bd..9b813de0 100644 --- a/application/controllers/Labels.php +++ b/application/controllers/Labels.php @@ -92,7 +92,7 @@ class Labels extends CI_Controller { $this->load->model('labels_model'); $result = $this->labels_model->export_printrequestedids($ids); - $this->prepareLabel($result); + $this->prepareLabel($result, true); } public function print($station_id) { @@ -104,7 +104,7 @@ class Labels extends CI_Controller { $this->prepareLabel($result); } - function prepareLabel($qsos) { + function prepareLabel($qsos, $jscall = false) { $this->load->model('labels_model'); $label = $this->labels_model->getDefaultLabel(); @@ -124,12 +124,24 @@ class Labels extends CI_Controller { 'font-size' => $label->font_size )); } else { - $this->session->set_flashdata('error', 'You need to create a label and set it to be used for print.'); - redirect('labels'); + if ($jscall) { + header('Content-Type: application/json'); + echo json_encode(array('message' => 'You need to create a label and set it to be used for print.')); + return; + } else { + $this->session->set_flashdata('error', 'You need to create a label and set it to be used for print.'); + redirect('labels'); + } } } catch (\Throwable $th) { - $this->session->set_flashdata('error', 'Something went wrong! The label could not be generated. Check label size and font size.'); - redirect('labels'); + if ($jscall) { + header('Content-Type: application/json'); + echo json_encode(array('message' => 'Something went wrong! The label could not be generated. Check label size and font size.')); + return; + } else { + $this->session->set_flashdata('error', 'Something went wrong! The label could not be generated. Check label size and font size.'); + redirect('labels'); + } } define('FPDF_FONTPATH', './src/Label/font/'); diff --git a/assets/js/sections/logbookadvanced.js b/assets/js/sections/logbookadvanced.js index 8813af4e..f447c8d2 100644 --- a/assets/js/sections/logbookadvanced.js +++ b/assets/js/sections/logbookadvanced.js @@ -389,7 +389,22 @@ $(document).ready(function () { unselectQsoID(this); }); $('#printLabel').prop("disabled", false); - } + }, + error: function (data) { + BootstrapDialog.alert({ + title: 'ERROR', + message: 'Something went wrong with label print. Go to labels and check if you have defined a label, and that it is set for print!', + type: BootstrapDialog.TYPE_DANGER, + closable: false, + draggable: false, + callback: function (result) { + } + }); + $.each(id_list, function(k, v) { + unselectQsoID(this); + }); + $('#printLabel').prop("disabled", false); + }, }); }); From dec43405936d9ac9d6d46d4c712001aada6f4133 Mon Sep 17 00:00:00 2001 From: Andreas <6977712+AndreasK79@users.noreply.github.com> Date: Wed, 28 Jun 2023 12:26:46 +0200 Subject: [PATCH 6/6] [Advanced Logbook] Added collapsable filters and actions --- application/views/logbookadvanced/index.php | 70 +++++++++++---------- 1 file changed, 38 insertions(+), 32 deletions(-) diff --git a/application/views/logbookadvanced/index.php b/application/views/logbookadvanced/index.php index 230df578..45539220 100644 --- a/application/views/logbookadvanced/index.php +++ b/application/views/logbookadvanced/index.php @@ -15,7 +15,9 @@
+
" method="post"> +
@@ -164,41 +166,47 @@
-
- - -
-
-
- - -
+
- +
+ +
With selected : - - - - - - - - - - - - - - + + + + + + + + + + + + + +
+
+
+
+ + + + + + +
+
+ @@ -231,6 +239,4 @@
- - - + \ No newline at end of file