Merge pull request #2349 from AndreasK79/label_start_at

[Labels] Added a dialog for the user to specify from which label the print should start.
pull/2354/head
Peter Goodhall 2023-07-30 11:51:29 +01:00 zatwierdzone przez GitHub
commit b6332162e5
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
5 zmienionych plików z 93 dodań i 34 usunięć

Wyświetl plik

@ -1,4 +1,4 @@
<?php
<?php
require_once './src/Label/vendor/autoload.php';
use Cloudlog\Label\PDF_Label;
@ -12,7 +12,7 @@ class Labels extends CI_Controller {
|--------------------------------------------------------------------------
| Controller: Labels
|--------------------------------------------------------------------------
|
|
| This Controller handles all things Labels, creating, editing and printing
|
|
@ -31,8 +31,8 @@ class Labels extends CI_Controller {
|--------------------------------------------------------------------------
| Function: index
|--------------------------------------------------------------------------
|
| Nothing fancy just shows the main display of how many labels are waiting
|
| Nothing fancy just shows the main display of how many labels are waiting
| to be printed per station profile.
|
*/
@ -60,7 +60,7 @@ class Labels extends CI_Controller {
|--------------------------------------------------------------------------
| Function: create
|--------------------------------------------------------------------------
|
|
| Shows the form used to create a label type.
|
*/
@ -79,7 +79,7 @@ class Labels extends CI_Controller {
$this->load->view('interface_assets/footer');
}
else
{
{
$this->load->model('labels_model');
$this->labels_model->addLabel();
@ -98,14 +98,15 @@ class Labels extends CI_Controller {
public function print($station_id) {
$clean_id = xss_clean($station_id);
$offset = xss_clean($this->input->post('startat'));
$this->load->model('labels_model');
$result = $this->labels_model->export_printrequested($clean_id);
$this->prepareLabel($result);
$this->prepareLabel($result, false, $offset);
}
function prepareLabel($qsos, $jscall = false) {
function prepareLabel($qsos, $jscall = false, $offset = 1) {
$this->load->model('labels_model');
$label = $this->labels_model->getDefaultLabel();
$label->font='DejaVuSans'; // Fix font to DejaVuSans
@ -114,16 +115,16 @@ class Labels extends CI_Controller {
try {
if ($label) {
$pdf = new PDF_Label(array(
'paper-size' => $label->paper_type,
'metric' => $label->metric,
'marginLeft' => $label->marginleft,
'marginTop' => $label->margintop,
'NX' => $label->nx,
'NY' => $label->ny,
'SpaceX' => $label->spacex,
'SpaceY' => $label->spacey,
'width' => $label->width,
'height' => $label->height,
'paper-size' => $label->paper_type,
'metric' => $label->metric,
'marginLeft' => $label->marginleft,
'marginTop' => $label->margintop,
'NX' => $label->nx,
'NY' => $label->ny,
'SpaceX' => $label->spacex,
'SpaceY' => $label->spacey,
'width' => $label->width,
'height' => $label->height,
'font-size' => $label->font_size
));
} else {
@ -132,7 +133,7 @@ class Labels extends CI_Controller {
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.');
$this->session->set_flashdata('error', 'You need to create a label and set it to be used for print.');
redirect('labels');
}
}
@ -142,7 +143,7 @@ class Labels extends CI_Controller {
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.');
$this->session->set_flashdata('error', 'Something went wrong! The label could not be generated. Check label size and font size.');
redirect('labels');
}
}
@ -160,30 +161,41 @@ class Labels extends CI_Controller {
if ($qsos->num_rows() > 0) {
if ($label->qsos == 1) {
$this->makeMultiQsoLabel($qsos->result(), $pdf,1);
$this->makeMultiQsoLabel($qsos->result(), $pdf, 1, $offset);
} else {
$this->makeMultiQsoLabel($qsos->result(), $pdf, $label->qsos);
$this->makeMultiQsoLabel($qsos->result(), $pdf, $label->qsos, $offset);
}
} else {
$this->session->set_flashdata('message', '0 QSOs found for print!');
$this->session->set_flashdata('message', '0 QSOs found for print!');
redirect('labels');
}
$pdf->Output();
}
function makeMultiQsoLabel($qsos, $pdf, $numberofqsos) {
function makeMultiQsoLabel($qsos, $pdf, $numberofqsos, $offset) {
$text = '';
$current_callsign = '';
$current_sat = '';
$current_sat_mode = '';
$current_sat_bandrx = '';
$qso_data = [];
if ($offset !== 1) {
for ($i = 1; $i < $offset; $i++) {
$pdf->Add_Label('');
}
}
foreach($qsos as $qso) {
if (($qso->COL_SAT_NAME !== $current_sat) || ($qso->COL_CALL !== $current_callsign)) {
if (($this->pretty_sat_mode($qso->COL_SAT_MODE) !== $current_sat_mode) || ($qso->COL_SAT_NAME !== $current_sat) || ($qso->COL_CALL !== $current_callsign) || // Call, SAT or SAT-Mode differs?
( ($qso->COL_BAND_RX !== $current_sat_bandrx) && ($this->pretty_sat_mode($qso->COL_SAT_MODE) !== '')) ) {
// ((($qso->COL_SAT_NAME ?? '' !== $current_sat) || ($qso->COL_CALL !== $current_callsign)) && ($qso->COL_SAT_NAME ?? '' !== '') && ($col->COL_BAND_RX ?? '' !== $current_sat_bandrx))) {
if (!empty($qso_data)) {
$this->finalizeData($pdf, $current_callsign, $qso_data, $numberofqsos);
$qso_data = [];
}
$current_callsign = $qso->COL_CALL;
$current_sat = $qso->COL_SAT_NAME;
$current_sat_mode = $this->pretty_sat_mode($qso->COL_SAT_MODE);
$current_sat_bandrx = $qso->COL_BAND_RX ?? '';
}
$qso_data[] = [
@ -193,7 +205,8 @@ class Labels extends CI_Controller {
'rst' => $qso->COL_RST_SENT,
'mygrid' => $qso->station_gridsquare,
'sat' => $qso->COL_SAT_NAME,
'sat_mode' => $qso->COL_SAT_MODE,
'sat_mode' => $this->pretty_sat_mode($qso->COL_SAT_MODE ?? ''),
'sat_band_rx' => ($qso->COL_BAND_RX ?? ''),
'qsl_recvd' => $qso->COL_QSL_RCVD
];
}
@ -202,8 +215,12 @@ class Labels extends CI_Controller {
}
}
// New begin
function pretty_sat_mode($sat_mode) {
return(strlen($sat_mode ?? '') == 2 ? (strtoupper($sat_mode[0]).'/'.strtoupper($sat_mode[1])) : strtoupper($sat_mode ?? ''));
}
function finalizeData($pdf, $current_callsign, &$preliminaryData, $qso_per_label) {
$tableData = [];
$count_qso = 0;
$qso=[];
@ -220,6 +237,7 @@ class Labels extends CI_Controller {
$tableData[] = $rowData;
$count_qso++;
if($count_qso == $qso_per_label){
$this->generateLabel($pdf, $current_callsign, $tableData,$count_qso,$qso);
$tableData = []; // reset the data
@ -242,7 +260,13 @@ class Labels extends CI_Controller {
$text .= "\n";
$text .= $builder->renderTable();
if($qso['sat'] != "") {
$text .= "\n".'Satellite: '.$qso['sat'].' Mode: '.(strlen($qso['sat_mode']) == 2 ? (strtoupper($qso['sat_mode'][0]).'/'.strtoupper($qso['sat_mode'][1])) : strtoupper($qso['sat_mode']));
if (($qso['sat_mode'] == '') && ($qso['sat_band_rx'] !== '')) {
$text .= "\n".'Satellite: '.$qso['sat'].' Band RX: '.$qso['sat_band_rx'];
} elseif (($qso['sat_mode'] == '') && ($qso['sat_band_rx'] == '')) {
$text .= "\n".'Satellite: '.$qso['sat'];
} else {
$text .= "\n".'Satellite: '.$qso['sat'].' Mode: '.$qso['sat_mode'];
}
}
$text .= "\nThanks for the QSO".($numofqsos>1 ? 's' : '');
$text .= " | ".($qso['qsl_recvd'] == 'Y' ? 'TNX' : 'PSE')." QSL";
@ -268,14 +292,14 @@ class Labels extends CI_Controller {
public function updateLabel($id) {
$this->load->model('labels_model');
$this->labels_model->updateLabel($id);
$this->session->set_flashdata('message', 'Label was saved.');
$this->session->set_flashdata('message', 'Label was saved.');
redirect('labels');
}
public function delete($id) {
$this->load->model('labels_model');
$this->labels_model->deleteLabel($id);
$this->session->set_flashdata('warning', 'Label was deleted.');
$this->session->set_flashdata('warning', 'Label was deleted.');
redirect('labels');
}
@ -285,4 +309,8 @@ class Labels extends CI_Controller {
$this->labels_model->saveDefaultLabel($id);
}
public function startAtLabel() {
$data['stationid'] = xss_clean($this->input->post('stationid'));
$this->load->view('labels/startatform', $data);
}
}

Wyświetl plik

@ -125,6 +125,8 @@ class Labels_model extends CI_Model {
$this->db->order_by("COL_DXCC", "ASC");
$this->db->order_by("COL_CALL", "ASC");
$this->db->order_by("COL_SAT_NAME", "ASC");
$this->db->order_by("COL_SAT_MODE", "ASC");
$this->db->order_by("COL_BAND_RX", "ASC");
$this->db->order_by("COL_TIME_ON", "ASC");
$this->db->order_by("COL_MODE", "ASC");
$query = $this->db->get($this->config->item('table_name'));

Wyświetl plik

@ -27,7 +27,7 @@
<div class="card-body">
<a href="<?php echo site_url('labels/create'); ?>" class="btn btn-outline-primary btn-sm">Create New Label Type</a>
<?php if ($labels) {
echo '<br/><br/>';?>
@ -96,7 +96,7 @@
echo '<td>' . $qso->station_gridsquare . '</td>';
echo '<td>' . $qso->count . '</td>';
echo '<td><a href="'. site_url('qslprint') . '" class="btn btn-outline-info btn-sm"><i class="fas fa-search"></i></a></td>';
echo '<td><a href="'. site_url('labels/print/' . $qso->station_id) . '" class="btn btn-outline-success btn-sm"><i class="fas fa-print"></i></a></td>';
echo '<td><button class="btn btn-outline-success btn-sm printbutton" onclick="printat('.$qso->station_id.')"><i class="fas fa-print"></i></button></td>';
echo '</tr>';
} ?>
</tbody>
@ -105,4 +105,4 @@
</div>
</div>
</div>
</div>

Wyświetl plik

@ -0,0 +1,4 @@
<form method="post" action="<?php echo site_url('labels/print/'.$stationid) ?>" class="form-inline">
<input class="form-control input-group-sm" type="number" id="startat" name="startat" value="1">
<button type="submit" id="button1id" name="button1id" class="btn btn-primary ld-ext-right">Print</button>
</form>

Wyświetl plik

@ -2,7 +2,7 @@ $('.labeltable').on('click', 'input[type="checkbox"]', function() {
var clickedlabelid = $(this).closest('tr').attr("class");
clickedlabelid = clickedlabelid.match(/\d+/)[0];
saveDefault(clickedlabelid);
$('input:checkbox').not(this).prop('checked', false);
$('input:checkbox').not(this).prop('checked', false);
});
function saveDefault(id) {
@ -13,4 +13,29 @@ function saveDefault(id) {
success: function (html) {
}
});
}
}
function printat(stationid) {
$.ajax({
url: base_url + 'index.php/labels/startAtLabel',
type: 'post',
data: {'stationid': stationid},
success: function (html) {
BootstrapDialog.show({
title: 'Start printing at which label?',
size: BootstrapDialog.SIZE_NORMAL,
cssClass: 'qso-dialog',
nl2br: false,
message: html,
onshown: function(dialog) {
},
buttons: [{
label: 'Close',
action: function (dialogItself) {
dialogItself.close();
}
}]
});
}
});
}