Merge pull request #2227 from AndreasK79/printlabel_advancedlogbook

[Avanced Logbook] Can print labels
这个提交包含在:
Peter Goodhall 2023-06-29 11:00:13 +01:00 提交者 GitHub
当前提交 c53b6cdbff
找不到此签名对应的密钥
GPG 密钥 ID: 4AEE18F83AFDEB23
共有 6 个文件被更改,包括 224 次插入50 次删除

查看文件

@ -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,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/');
@ -138,12 +155,11 @@ class Labels extends CI_Controller {
$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!');

查看文件

@ -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);
}
}

查看文件

@ -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;
}
}

查看文件

@ -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'])) {

查看文件

@ -15,7 +15,9 @@
</div>
<?php } ?>
<div class="row">
<form id="searchForm" name="searchForm" action="<?php echo base_url()."index.php/logbookadvanced/search";?>" method="post">
<div class="filterbody collapse">
<div class="form-row">
<div class="form-group col-lg-2 col-md-2 col-sm-3 col-xl">
<label class="form-label" for="dateFrom">From</label>
@ -164,38 +166,47 @@
<option value="V">Verified</option>
</select>
</div>
<div class="form-group col-lg-2 col-md-2 col-sm-3 col-xl">
<label for="qsoResults"># Results</label>
<select id="qsoResults" name="qsoResults" class="form-control form-control-sm">
<option value="250">250</option>
<option value="1000">1000</option>
<option value="2500">2500</option>
<option value="5000">5000</option>
</select>
</div>
<div class="form-group col-lg col-md-3 col-sm-3 col-xl-1">
<label>&nbsp;</label><br>
<button type="submit" class="btn btn-sm btn-primary" id="searchButton">Search</button>
<button type="reset" class="btn btn-sm btn-danger" id="resetButton">Reset</button>
</div>
</div>
</form>
</div>
<div class="actionbody collapse">
<div class="mb-2">
<span class="h6">With selected :</span>
<button type="button" class="btn btn-sm btn-primary" id="btnUpdateFromCallbook">Update from Callbook</button>
<button type="button" class="btn btn-sm btn-primary" id="queueBureau">Queue Bureau</button>
<button type="button" class="btn btn-sm btn-primary" id="queueDirect">Queue Direct</button>
<button type="button" class="btn btn-sm btn-primary" id="queueElectronic">Queue Electronic</button>
<button type="button" class="btn btn-sm btn-success" id="sentBureau">Sent Bureau</button>
<button type="button" class="btn btn-sm btn-success" id="sentDirect">Sent Direct</button>
<button type="button" class="btn btn-sm btn-success" id="sentElectronic">Sent Electronic</button>
<button type="button" class="btn btn-sm btn-warning" id="dontSend">Not Sent</button>
<button type="button" class="btn btn-sm btn-warning" id="notRequired">QSL Not Required</button>
<button type="button" class="btn btn-sm btn-info" id="exportAdif">Create ADIF</button>
<button type="button" class="btn btn-sm btn-danger" id="deleteQsos">Delete</button>
<button type="button" class="btn btn-sm btn-primary mr-1" id="btnUpdateFromCallbook">Update from Callbook</button>
<button type="button" class="btn btn-sm btn-primary mr-1" id="queueBureau">Queue Bureau</button>
<button type="button" class="btn btn-sm btn-primary mr-1" id="queueDirect">Queue Direct</button>
<button type="button" class="btn btn-sm btn-primary mr-1" id="queueElectronic">Queue Electronic</button>
<button type="button" class="btn btn-sm btn-success mr-1" id="sentBureau">Sent Bureau</button>
<button type="button" class="btn btn-sm btn-success mr-1" id="sentDirect">Sent Direct</button>
<button type="button" class="btn btn-sm btn-success mr-1" id="sentElectronic">Sent Electronic</button>
<button type="button" class="btn btn-sm btn-warning mr-1" id="dontSend">Not Sent</button>
<button type="button" class="btn btn-sm btn-warning mr-1" id="notRequired">QSL Not Required</button>
<button type="button" class="btn btn-sm btn-warning mr-1" id="receivedBureau">Received (bureau)</button>
<button type="button" class="btn btn-sm btn-warning mr-1" id="receivedDirect">Received (direct)</button>
<button type="button" class="btn btn-sm btn-info mr-1" id="exportAdif">Create ADIF</button>
<button type="button" class="btn btn-sm btn-info mr-1" id="printLabel">Print Label</button>
<button type="button" class="btn btn-sm btn-danger mr-1" id="deleteQsos">Delete</button>
<span id="infoBox"></span>
</div>
</div>
</div>
<div class="form-row pt-2">
<div class="form-group form-inline col-lg d-flex flex-row justify-content-center align-items-center">
<button type="button" class="btn btn-sm btn-primary mr-1" data-toggle="collapse" data-target=".filterbody">Filters</button>
<button type="button" class="btn btn-sm btn-primary mr-1" data-toggle="collapse" data-target=".actionbody">Actions</button>
<label for="qsoResults" class="mr-2"># Results</label>
<select id="qsoResults" name="qsoResults" class="form-control form-control-sm mr-2">
<option value="250">250</option>
<option value="1000">1000</option>
<option value="2500">2500</option>
<option value="5000">5000</option>
</select>
<button type="submit" class="btn btn-sm btn-primary mr-1" id="searchButton">Search</button>
<button type="reset" class="btn btn-sm btn-danger mr-1" id="resetButton">Reset</button>
</div>
</div>
</form>
<table style="width:100%" class="table-sm table table-bordered table-hover table-striped table-condensed text-center" id="qsoList">
<thead>
<tr>
@ -228,6 +239,4 @@
<tbody>
</tbody>
</table>
</div>

查看文件

@ -348,6 +348,65 @@ $(document).ready(function () {
$('#notRequired').click(function (event) {
handleQsl('I','', 'notRequired');
});
$('#receivedBureau').click(function (event) {
handleQslReceived('Y','B', 'receivedBureau');
});
$('#receivedDirect').click(function (event) {
handleQslReceived('Y','D', 'receivedDirect');
});
$('#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);
}
$.each(id_list, function(k, v) {
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);
},
});
});
$('#searchForm').on('reset', function(e) {
setTimeout(function() {
@ -386,6 +445,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) {