From c0a2134f62cae9a0a2a0a996be77cdcaf9cb8b9a Mon Sep 17 00:00:00 2001 From: Andreas <6977712+AndreasK79@users.noreply.github.com> Date: Thu, 22 Jul 2021 17:16:49 +0200 Subject: [PATCH] [QSL Print] Delete now works. Added a working station profile selector, which changes table and links when changed. --- application/controllers/Qslprint.php | 37 +++++++++-- application/models/Adif_data.php | 9 ++- application/models/Logbook_model.php | 62 +++++++++++-------- application/models/Qslprint_model.php | 36 +++++++---- application/views/interface_assets/footer.php | 46 ++++++++------ application/views/qslprint/index.php | 25 +++++--- application/views/qslprint/qslprint.php | 41 ++++++++++++ 7 files changed, 184 insertions(+), 72 deletions(-) create mode 100644 application/views/qslprint/qslprint.php diff --git a/application/controllers/Qslprint.php b/application/controllers/Qslprint.php index e43d116d..fc2f2c00 100644 --- a/application/controllers/Qslprint.php +++ b/application/controllers/Qslprint.php @@ -35,9 +35,15 @@ class QSLPrint extends CI_Controller { // Set memory limit to unlimited to allow heavy usage ini_set('memory_limit', '-1'); + if ($this->uri->segment(3) == 'All') { + $station_id = NULL; + } else { + $station_id = $this->security->xss_clean($this->uri->segment(3)); + } + $this->load->model('adif_data'); - $data['qsos'] = $this->adif_data->export_printrequested(); + $data['qsos'] = $this->adif_data->export_printrequested($station_id); $this->load->view('adif/data/exportall', $data); } @@ -47,9 +53,15 @@ class QSLPrint extends CI_Controller { // Set memory limit to unlimited to allow heavy usage ini_set('memory_limit', '-1'); + if ($this->uri->segment(3) == 'All') { + $station_id = NULL; + } else { + $station_id = $this->security->xss_clean($this->uri->segment(3)); + } + $this->load->model('logbook_model'); - $myData = $this->logbook_model->get_qsos_for_printing(); + $myData = $this->logbook_model->get_qsos_for_printing($station_id); // file name $filename = 'qsl_export.csv'; @@ -102,24 +114,41 @@ class QSLPrint extends CI_Controller { } function qsl_printed() { + + if ($this->uri->segment(3) == 'All') { + $station_id = NULL; + } else { + $station_id = $this->security->xss_clean($this->uri->segment(3)); + } + $this->load->model('qslprint_model'); $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'); } // Update Logbook to Mark Paper Card Received - $this->qslprint_model->mark_qsos_printed(); + $this->qslprint_model->mark_qsos_printed($station_id); $this->session->set_flashdata('notice', 'QSOs are marked as sent via buro'); redirect('logbook'); } - public function delete_from_qsl_queue($id) { + public function delete_from_qsl_queue() { + $id = $this->input->post('id'); $this->load->model('qslprint_model'); $this->qslprint_model->delete_from_qsl_queue($this->security->xss_clean($id)); } + + public function get_qsos_for_print_ajax() { + $station_id = $this->input->post('station_id'); + $this->load->model('qslprint_model'); + + $data['qsos'] = $this->qslprint_model->get_qsos_for_print_ajax($this->security->xss_clean($station_id)); + $data['station_id'] = $station_id; + $this->load->view('qslprint/qslprint', $data); + } } /* End of file Qslprint.php */ diff --git a/application/models/Adif_data.php b/application/models/Adif_data.php index 9d765c09..21774729 100644 --- a/application/models/Adif_data.php +++ b/application/models/Adif_data.php @@ -19,11 +19,16 @@ class adif_data extends CI_Model { return $query; } - function export_printrequested() { + function export_printrequested($station_id = NULL) { $this->load->model('stations'); $active_station_id = $this->stations->find_active(); - $this->db->where($this->config->item('table_name').'.station_id', $active_station_id); + if ($station_id == NULL) { + $this->db->where($this->config->item('table_name').'.station_id', $active_station_id); + } else { + $this->db->where($this->config->item('table_name').'.station_id', $station_id); + } + $this->db->join('station_profile', 'station_profile.station_id = '.$this->config->item('table_name').'.station_id'); $this->db->where_in('COL_QSL_SENT', array('R', 'Q')); $this->db->order_by("COL_TIME_ON", "ASC"); diff --git a/application/models/Logbook_model.php b/application/models/Logbook_model.php index 733dc39a..db5ebe77 100755 --- a/application/models/Logbook_model.php +++ b/application/models/Logbook_model.php @@ -755,37 +755,45 @@ class Logbook_model extends CI_Model { $this->db->update($this->config->item('table_name'), $data); } - function get_qsos_for_printing() { + function get_qsos_for_printing($station_id2 = null) { $CI =& get_instance(); $CI->load->model('Stations'); $station_id = $CI->Stations->find_active(); - $query = $this->db->query('SELECT - STATION_CALLSIGN, - COL_PRIMARY_KEY, - COL_CALL, - COL_QSL_VIA, - COL_TIME_ON, - COL_MODE, - COL_SUBMODE, - COL_FREQ, - UPPER(COL_BAND) as COL_BAND, - COL_RST_SENT, - COL_SAT_NAME, - COL_SAT_MODE, - COL_QSL_RCVD, - COL_COMMENT, - (CASE WHEN COL_QSL_VIA != \'\' THEN COL_QSL_VIA ELSE COL_CALL END) AS COL_ROUTING, - ADIF, - ENTITY - FROM '.$this->config->item('table_name').', dxcc_prefixes, station_profile - WHERE - COL_QSL_SENT in (\'R\', \'Q\') - and (CASE WHEN COL_QSL_VIA != \'\' THEN COL_QSL_VIA ELSE COL_CALL END) like CONCAT(dxcc_prefixes.call,\'%\') - and (end is null or end > now()) - and '.$this->config->item('table_name').'.station_id = '.$station_id.' - and '.$this->config->item('table_name').'.station_id = station_profile.station_id - ORDER BY adif, col_routing'); + $sql = 'SELECT + STATION_CALLSIGN, + COL_PRIMARY_KEY, + COL_CALL, + COL_QSL_VIA, + COL_TIME_ON, + COL_MODE, + COL_SUBMODE, + COL_FREQ, + UPPER(COL_BAND) as COL_BAND, + COL_RST_SENT, + COL_SAT_NAME, + COL_SAT_MODE, + COL_QSL_RCVD, + COL_COMMENT, + (CASE WHEN COL_QSL_VIA != \'\' THEN COL_QSL_VIA ELSE COL_CALL END) AS COL_ROUTING, + ADIF, + ENTITY + FROM '.$this->config->item('table_name').', dxcc_prefixes, station_profile + WHERE + COL_QSL_SENT in (\'R\', \'Q\') + and (CASE WHEN COL_QSL_VIA != \'\' THEN COL_QSL_VIA ELSE COL_CALL END) like CONCAT(dxcc_prefixes.call,\'%\') + and (end is null or end > now()) + and ' . $this->config->item('table_name') . '.station_id = station_profile.station_id'; + + if ($station_id2 == NULL) { + $sql .= ' and ' . $this->config->item('table_name') . '.station_id = ' . $station_id; + } else { + $sql .= ' and ' . $this->config->item('table_name') . '.station_id = ' . $station_id2; + } + + $sql .= ' ORDER BY adif, col_routing'; + + $query = $this->db->query($sql); return $query; } diff --git a/application/models/Qslprint_model.php b/application/models/Qslprint_model.php index b6a65064..354e2460 100644 --- a/application/models/Qslprint_model.php +++ b/application/models/Qslprint_model.php @@ -7,7 +7,7 @@ class Qslprint_model extends CI_Model { parent::__construct(); } - function mark_qsos_printed() { + function mark_qsos_printed($station_id2 = NULL) { $CI =& get_instance(); $CI->load->model('Stations'); $station_id = $CI->Stations->find_active(); @@ -19,17 +19,26 @@ class Qslprint_model extends CI_Model { ); $this->db->where_in("COL_QSL_SENT", array("R","Q")); - $this->db->where("station_id", $station_id); + + if ($station_id2 == NULL) { + $this->db->where("station_id", $station_id); + } else { + $this->db->where("station_id", $station_id2); + } + $this->db->update($this->config->item('table_name'), $data); } - function get_qsos_for_print() { - $CI =& get_instance(); - $CI->load->model('Stations'); + /* + * We list out the QSL's ready for print. + * station_id is not provided when loading page. + * It will be provided when calling the function when the dropdown is changed and the javascript fires + */ + function get_qsos_for_print($station_id = 'All') { + if ($station_id != 'All') { + $this->db->where($this->config->item('table_name').'.station_id', $station_id); + } - $active_station_id = $this->stations->find_active(); - - $this->db->where($this->config->item('table_name').'.station_id', $active_station_id); $this->db->join('station_profile', 'station_profile.station_id = '.$this->config->item('table_name').'.station_id'); $this->db->where_in('COL_QSL_SENT', array('R', 'Q')); $this->db->order_by("COL_TIME_ON", "ASC"); @@ -38,17 +47,18 @@ class Qslprint_model extends CI_Model { return $query; } - function delete_from_qsl_queue($id) { - $CI =& get_instance(); - $CI->load->model('Stations'); - $station_id = $CI->Stations->find_active(); + function get_qsos_for_print_ajax($station_id) { + $query = $this->get_qsos_for_print($station_id); + return $query; + } + + function delete_from_qsl_queue($id) { $data = array( 'COL_QSL_SENT' => "N", ); $this->db->where("COL_PRIMARY_KEY", $id); - //$this->db->where("station_id", $station_id); $this->db->update($this->config->item('table_name'), $data); return true; diff --git a/application/views/interface_assets/footer.php b/application/views/interface_assets/footer.php index 256b8f95..c81f81c4 100644 --- a/application/views/interface_assets/footer.php +++ b/application/views/interface_assets/footer.php @@ -2026,28 +2026,38 @@ function deleteQsl(id) { uri->segment(1) == "qslprint") { ?> diff --git a/application/views/qslprint/index.php b/application/views/qslprint/index.php index 188b40dd..ccc1c6c7 100644 --- a/application/views/qslprint/index.php +++ b/application/views/qslprint/index.php @@ -17,8 +17,9 @@
- + result() as $station) { ?> @@ -31,7 +32,8 @@ result())) { + echo '
'; + if ($qsos->result() != NULL) { echo ' @@ -58,14 +60,21 @@ } echo '
'; + ?> + +

Export requested QSLs to CSV-file

+ +

Export requested QSLs to ADIF-file

+ +

Mark requested QSLs as sent

+ + ×No QSL\'s to print were found!
'; } ?> -

Export requested QSLs to CSV-file

- -

Export requested QSLs to ADIF-file

- -

Mark requested QSLs as sent

+
diff --git a/application/views/qslprint/qslprint.php b/application/views/qslprint/qslprint.php new file mode 100644 index 00000000..d63558b9 --- /dev/null +++ b/application/views/qslprint/qslprint.php @@ -0,0 +1,41 @@ +result() != NULL) { + echo ' + + + + + + + + + + + '; + + foreach ($qsos->result() as $qsl) { + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + } + + echo '
'.$this->lang->line('gen_hamradio_callsign').'DateTimeModeBandStation
' . $qsl->COL_CALL . '' . $qsl->COL_TIME_ON . '' . $qsl->COL_TIME_ON . ''; if($qsl->COL_SAT_NAME != null) { echo $qsl->COL_SAT_NAME; } else { echo strtolower($qsl->COL_BAND); }; echo ''; echo $qsl->COL_SUBMODE==null?$qsl->COL_MODE:$qsl->COL_SUBMODE; echo '' . $qsl->station_callsign . '
'; + ?> + +

Export requested QSLs to CSV-file

+ +

Export requested QSLs to ADIF-file

+ +

Mark requested QSLs as sent

+ +×No QSL\'s to print were found!'; +} +?>