diff --git a/application/controllers/Labels.php b/application/controllers/Labels.php index 628b4dcd..9b813de0 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, true); + } + 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, $jscall = false) { + $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( @@ -119,17 +124,29 @@ 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/'); - + $pdf->AddPage(); - + if ($label->font == 'DejaVuSans') { $pdf->AddFont($label->font,'','DejaVuSansMono.ttf',true); $pdf->SetFont($label->font); @@ -137,13 +154,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/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/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/models/Logbookadvanced_model.php b/application/models/Logbookadvanced_model.php index d94e1565..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 @@ -216,6 +217,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/application/views/logbookadvanced/index.php b/application/views/logbookadvanced/index.php index ed417d8b..45539220 100644 --- a/application/views/logbookadvanced/index.php +++ b/application/views/logbookadvanced/index.php @@ -15,7 +15,9 @@