2023-07-29 18:02:18 +00:00
|
|
|
<?php
|
2023-06-02 16:50:27 +00:00
|
|
|
|
2023-07-28 06:04:16 +00:00
|
|
|
require_once './src/Label/vendor/autoload.php';
|
2023-06-02 16:50:27 +00:00
|
|
|
use Cloudlog\Label\PDF_Label;
|
2023-06-12 06:20:24 +00:00
|
|
|
use Cloudlog\Label\tfpdf;
|
|
|
|
use Cloudlog\Label\font\unifont\ttfonts;
|
2023-06-02 16:50:27 +00:00
|
|
|
|
|
|
|
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
|
|
|
|
|
|
|
class Labels extends CI_Controller {
|
2023-07-28 07:51:52 +00:00
|
|
|
/*
|
2023-06-02 16:50:27 +00:00
|
|
|
|--------------------------------------------------------------------------
|
|
|
|
| Controller: Labels
|
|
|
|
|--------------------------------------------------------------------------
|
2023-07-29 18:02:18 +00:00
|
|
|
|
|
2023-06-02 16:50:27 +00:00
|
|
|
| This Controller handles all things Labels, creating, editing and printing
|
|
|
|
|
|
|
|
|
|
|
2023-07-28 07:51:52 +00:00
|
|
|
*/
|
2023-06-02 16:50:27 +00:00
|
|
|
|
|
|
|
function __construct() {
|
|
|
|
parent::__construct();
|
|
|
|
$this->load->helper(array('form', 'url', 'psr4_autoloader'));
|
|
|
|
|
|
|
|
$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'); }
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|--------------------------------------------------------------------------
|
|
|
|
| Function: index
|
|
|
|
|--------------------------------------------------------------------------
|
2023-07-29 18:02:18 +00:00
|
|
|
|
|
|
|
|
| Nothing fancy just shows the main display of how many labels are waiting
|
2023-06-02 16:50:27 +00:00
|
|
|
| to be printed per station profile.
|
|
|
|
|
|
2023-07-28 07:51:52 +00:00
|
|
|
*/
|
2023-06-02 16:50:27 +00:00
|
|
|
public function index() {
|
|
|
|
$data['page_title'] = "QSL Card Labels";
|
|
|
|
|
|
|
|
$this->load->model('labels_model');
|
|
|
|
|
|
|
|
$data['labels'] = $this->labels_model->fetchLabels($this->session->userdata('user_id'));
|
|
|
|
|
|
|
|
$data['qsos'] = $this->labels_model->fetchQsos($this->session->userdata('user_id'));
|
|
|
|
|
|
|
|
$footerData = [];
|
|
|
|
$footerData['scripts'] = [
|
|
|
|
'assets/js/sections/labels.js',
|
|
|
|
];
|
|
|
|
|
|
|
|
$this->load->view('interface_assets/header', $data);
|
|
|
|
$this->load->view('labels/index');
|
|
|
|
$this->load->view('interface_assets/footer', $footerData);
|
2023-07-28 07:51:52 +00:00
|
|
|
|
2023-06-02 16:50:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
|--------------------------------------------------------------------------
|
|
|
|
| Function: create
|
|
|
|
|--------------------------------------------------------------------------
|
2023-07-29 18:02:18 +00:00
|
|
|
|
|
2023-06-02 16:50:27 +00:00
|
|
|
| Shows the form used to create a label type.
|
|
|
|
|
|
2023-07-28 07:51:52 +00:00
|
|
|
*/
|
2023-06-02 16:50:27 +00:00
|
|
|
public function create() {
|
2023-07-28 07:51:52 +00:00
|
|
|
|
2023-06-02 16:50:27 +00:00
|
|
|
$data['page_title'] = "Create Label Type";
|
|
|
|
|
|
|
|
$this->load->library('form_validation');
|
|
|
|
|
|
|
|
$this->form_validation->set_rules('label_name', 'Label Name', 'required');
|
|
|
|
|
|
|
|
if ($this->form_validation->run() == FALSE)
|
|
|
|
{
|
|
|
|
$this->load->view('interface_assets/header', $data);
|
|
|
|
$this->load->view('labels/create');
|
|
|
|
$this->load->view('interface_assets/footer');
|
|
|
|
}
|
|
|
|
else
|
2023-07-29 18:02:18 +00:00
|
|
|
{
|
2023-06-02 16:50:27 +00:00
|
|
|
$this->load->model('labels_model');
|
|
|
|
$this->labels_model->addLabel();
|
2023-07-28 07:51:52 +00:00
|
|
|
|
2023-06-02 16:50:27 +00:00
|
|
|
redirect('labels');
|
|
|
|
}
|
2023-07-28 07:51:52 +00:00
|
|
|
|
2023-06-02 16:50:27 +00:00
|
|
|
}
|
|
|
|
|
2023-06-27 13:03:12 +00:00
|
|
|
public function printids() {
|
|
|
|
$ids = xss_clean(json_decode($this->input->post('id')));
|
|
|
|
$this->load->model('labels_model');
|
|
|
|
$result = $this->labels_model->export_printrequestedids($ids);
|
|
|
|
|
2023-06-28 10:24:38 +00:00
|
|
|
$this->prepareLabel($result, true);
|
2023-06-27 13:03:12 +00:00
|
|
|
}
|
|
|
|
|
2023-06-02 16:50:27 +00:00
|
|
|
public function print($station_id) {
|
|
|
|
$clean_id = xss_clean($station_id);
|
2023-07-29 18:49:45 +00:00
|
|
|
$offset = xss_clean($this->input->post('startat'));
|
2023-06-02 16:50:27 +00:00
|
|
|
|
|
|
|
$this->load->model('labels_model');
|
2023-06-14 14:28:12 +00:00
|
|
|
$result = $this->labels_model->export_printrequested($clean_id);
|
|
|
|
|
2023-07-29 18:49:45 +00:00
|
|
|
$this->prepareLabel($result, false, $offset);
|
2023-06-27 13:03:12 +00:00
|
|
|
}
|
2023-07-28 07:51:52 +00:00
|
|
|
|
2023-07-29 18:49:45 +00:00
|
|
|
function prepareLabel($qsos, $jscall = false, $offset = 1) {
|
2023-06-27 13:03:12 +00:00
|
|
|
$this->load->model('labels_model');
|
2023-06-02 16:50:27 +00:00
|
|
|
$label = $this->labels_model->getDefaultLabel();
|
2023-07-28 07:51:52 +00:00
|
|
|
$label->font='DejaVuSans'; // Fix font to DejaVuSans
|
|
|
|
|
|
|
|
|
2023-06-03 16:22:11 +00:00
|
|
|
try {
|
|
|
|
if ($label) {
|
|
|
|
$pdf = new PDF_Label(array(
|
2023-07-29 18:02:18 +00:00
|
|
|
'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,
|
2023-06-03 16:22:11 +00:00
|
|
|
'font-size' => $label->font_size
|
2023-06-05 14:53:06 +00:00
|
|
|
));
|
2023-06-03 16:22:11 +00:00
|
|
|
} else {
|
2023-06-28 10:24:38 +00:00
|
|
|
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 {
|
2023-07-29 18:02:18 +00:00
|
|
|
$this->session->set_flashdata('error', 'You need to create a label and set it to be used for print.');
|
2023-06-28 10:24:38 +00:00
|
|
|
redirect('labels');
|
|
|
|
}
|
2023-06-03 16:22:11 +00:00
|
|
|
}
|
|
|
|
} catch (\Throwable $th) {
|
2023-06-28 10:24:38 +00:00
|
|
|
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 {
|
2023-07-29 18:02:18 +00:00
|
|
|
$this->session->set_flashdata('error', 'Something went wrong! The label could not be generated. Check label size and font size.');
|
2023-06-28 10:24:38 +00:00
|
|
|
redirect('labels');
|
|
|
|
}
|
2023-06-02 16:50:27 +00:00
|
|
|
}
|
2023-06-12 06:20:24 +00:00
|
|
|
define('FPDF_FONTPATH', './src/Label/font/');
|
2023-07-28 07:51:52 +00:00
|
|
|
|
2023-06-02 16:50:27 +00:00
|
|
|
$pdf->AddPage();
|
2023-07-28 07:51:52 +00:00
|
|
|
|
|
|
|
if ($label->font == 'DejaVuSans') { // leave this here, for future Use
|
2023-06-12 06:20:24 +00:00
|
|
|
$pdf->AddFont($label->font,'','DejaVuSansMono.ttf',true);
|
|
|
|
$pdf->SetFont($label->font);
|
|
|
|
} else {
|
|
|
|
$pdf->AddFont($label->font);
|
|
|
|
$pdf->SetFont($label->font);
|
|
|
|
}
|
2023-07-28 07:51:52 +00:00
|
|
|
|
2023-06-27 13:03:12 +00:00
|
|
|
if ($qsos->num_rows() > 0) {
|
2023-06-06 15:36:30 +00:00
|
|
|
if ($label->qsos == 1) {
|
2023-07-29 18:49:45 +00:00
|
|
|
$this->makeMultiQsoLabel($qsos->result(), $pdf, 1, $offset);
|
2023-06-05 14:53:06 +00:00
|
|
|
} else {
|
2023-07-29 18:49:45 +00:00
|
|
|
$this->makeMultiQsoLabel($qsos->result(), $pdf, $label->qsos, $offset);
|
2023-06-02 16:50:27 +00:00
|
|
|
}
|
|
|
|
} else {
|
2023-07-29 18:02:18 +00:00
|
|
|
$this->session->set_flashdata('message', '0 QSOs found for print!');
|
2023-06-05 14:53:06 +00:00
|
|
|
redirect('labels');
|
2023-06-02 16:50:27 +00:00
|
|
|
}
|
|
|
|
$pdf->Output();
|
2023-06-05 14:53:06 +00:00
|
|
|
}
|
|
|
|
|
2023-07-29 18:49:45 +00:00
|
|
|
function makeMultiQsoLabel($qsos, $pdf, $numberofqsos, $offset) {
|
2023-06-05 14:53:06 +00:00
|
|
|
$text = '';
|
|
|
|
$current_callsign = '';
|
2023-07-28 08:28:17 +00:00
|
|
|
$current_sat = '';
|
2023-06-05 14:53:06 +00:00
|
|
|
$qso_data = [];
|
2023-07-30 05:46:25 +00:00
|
|
|
if ($offset !== 1) {
|
|
|
|
for ($i = 1; $i < $offset; $i++) {
|
|
|
|
$pdf->Add_Label('');
|
|
|
|
}
|
|
|
|
}
|
2023-06-05 14:53:06 +00:00
|
|
|
foreach($qsos as $qso) {
|
2023-07-28 08:28:17 +00:00
|
|
|
if (($qso->COL_SAT_NAME !== $current_sat) || ($qso->COL_CALL !== $current_callsign)) {
|
2023-06-05 14:53:06 +00:00
|
|
|
if (!empty($qso_data)) {
|
2023-07-30 05:46:25 +00:00
|
|
|
$this->finalizeData($pdf, $current_callsign, $qso_data, $numberofqsos);
|
2023-06-05 14:53:06 +00:00
|
|
|
$qso_data = [];
|
|
|
|
}
|
|
|
|
$current_callsign = $qso->COL_CALL;
|
2023-07-28 08:28:17 +00:00
|
|
|
$current_sat = $qso->COL_SAT_NAME;
|
2023-06-05 14:53:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$qso_data[] = [
|
|
|
|
'time' => $qso->COL_TIME_ON,
|
|
|
|
'band' => $qso->COL_BAND,
|
|
|
|
'mode' => $qso->COL_MODE,
|
|
|
|
'rst' => $qso->COL_RST_SENT,
|
|
|
|
'mygrid' => $qso->station_gridsquare,
|
|
|
|
'sat' => $qso->COL_SAT_NAME,
|
2023-07-30 05:46:25 +00:00
|
|
|
'sat_mode' => ($qso->COL_SAT_MODE ?? ''),
|
2023-07-28 09:24:01 +00:00
|
|
|
'qsl_recvd' => $qso->COL_QSL_RCVD
|
2023-06-05 14:53:06 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
if (!empty($qso_data)) {
|
2023-07-30 05:46:25 +00:00
|
|
|
$this->finalizeData($pdf, $current_callsign, $qso_data, $numberofqsos);
|
2023-06-05 14:53:06 +00:00
|
|
|
}
|
|
|
|
}
|
2023-07-28 07:51:52 +00:00
|
|
|
// New begin
|
2023-07-28 06:04:16 +00:00
|
|
|
|
2023-07-30 05:46:25 +00:00
|
|
|
function finalizeData($pdf, $current_callsign, &$preliminaryData, $qso_per_label) {
|
2023-07-29 18:49:45 +00:00
|
|
|
|
2023-07-28 06:36:57 +00:00
|
|
|
$tableData = [];
|
|
|
|
$count_qso = 0;
|
|
|
|
$qso=[];
|
|
|
|
foreach ($preliminaryData as $key => $row) {
|
|
|
|
$qso=$row;
|
2023-07-28 10:13:15 +00:00
|
|
|
$time = strtotime($qso['time']);
|
2023-07-28 13:13:21 +00:00
|
|
|
$myFormatForView = date("d.m.y H:i", $time);
|
2023-07-28 06:36:57 +00:00
|
|
|
$rowData = [
|
2023-07-28 13:13:21 +00:00
|
|
|
'Date/Time' => $myFormatForView,
|
2023-07-28 06:36:57 +00:00
|
|
|
'Band' => $row['band'],
|
|
|
|
'Mode' => $row['mode'],
|
|
|
|
'RST' => $row['rst'],
|
|
|
|
];
|
|
|
|
$tableData[] = $rowData;
|
|
|
|
$count_qso++;
|
|
|
|
|
2023-07-30 05:46:25 +00:00
|
|
|
|
2023-07-28 06:36:57 +00:00
|
|
|
if($count_qso == $qso_per_label){
|
2023-07-30 05:46:25 +00:00
|
|
|
$this->generateLabel($pdf, $current_callsign, $tableData,$count_qso,$qso);
|
2023-07-28 06:36:57 +00:00
|
|
|
$tableData = []; // reset the data
|
|
|
|
$count_qso = 0; // reset the counter
|
|
|
|
}
|
|
|
|
unset($preliminaryData[$key]);
|
|
|
|
}
|
|
|
|
// generate label for remaining QSOs
|
|
|
|
if($count_qso > 0){
|
2023-07-30 05:46:25 +00:00
|
|
|
$this->generateLabel($pdf, $current_callsign, $tableData,$count_qso,$qso);
|
2023-07-28 06:36:57 +00:00
|
|
|
$preliminaryData = []; // reset the data
|
|
|
|
}
|
|
|
|
}
|
2023-07-28 06:04:16 +00:00
|
|
|
|
2023-07-30 05:46:25 +00:00
|
|
|
function generateLabel($pdf, $current_callsign, $tableData,$numofqsos,$qso){
|
2023-07-28 07:51:52 +00:00
|
|
|
$builder = new \AsciiTable\Builder();
|
|
|
|
$builder->addRows($tableData);
|
|
|
|
$text = "Confirming QSO".($numofqsos>1 ? 's' : '')." with ";
|
|
|
|
$text .= $current_callsign;
|
|
|
|
$text .= "\n";
|
|
|
|
$text .= $builder->renderTable();
|
|
|
|
if($qso['sat'] != "") {
|
2023-07-28 10:37:49 +00:00
|
|
|
$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']));
|
2023-06-05 14:53:06 +00:00
|
|
|
}
|
2023-07-28 07:51:52 +00:00
|
|
|
$text .= "\nThanks for the QSO".($numofqsos>1 ? 's' : '');
|
2023-07-28 09:31:39 +00:00
|
|
|
$text .= " | ".($qso['qsl_recvd'] == 'Y' ? 'TNX' : 'PSE')." QSL";
|
2023-07-28 07:51:52 +00:00
|
|
|
$pdf->Add_Label($text);
|
2023-06-02 16:50:27 +00:00
|
|
|
}
|
|
|
|
|
2023-07-28 07:51:52 +00:00
|
|
|
// New End
|
|
|
|
|
2023-06-03 06:46:52 +00:00
|
|
|
public function edit($id) {
|
|
|
|
$this->load->model('labels_model');
|
|
|
|
|
|
|
|
$cleanid = $this->security->xss_clean($id);
|
|
|
|
|
|
|
|
$data['label'] = $this->labels_model->getLabel($cleanid);
|
2023-06-02 16:50:27 +00:00
|
|
|
|
2023-06-03 06:46:52 +00:00
|
|
|
$data['page_title'] = "Edit Label";
|
|
|
|
|
|
|
|
$this->load->view('interface_assets/header', $data);
|
|
|
|
$this->load->view('labels/edit');
|
|
|
|
$this->load->view('interface_assets/footer');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function updateLabel($id) {
|
|
|
|
$this->load->model('labels_model');
|
|
|
|
$this->labels_model->updateLabel($id);
|
2023-07-29 18:02:18 +00:00
|
|
|
$this->session->set_flashdata('message', 'Label was saved.');
|
2023-06-03 06:46:52 +00:00
|
|
|
redirect('labels');
|
2023-06-02 16:50:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function delete($id) {
|
|
|
|
$this->load->model('labels_model');
|
|
|
|
$this->labels_model->deleteLabel($id);
|
2023-07-29 18:02:18 +00:00
|
|
|
$this->session->set_flashdata('warning', 'Label was deleted.');
|
2023-06-02 16:50:27 +00:00
|
|
|
redirect('labels');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function saveDefaultLabel() {
|
|
|
|
$id = $this->input->post('id');
|
|
|
|
$this->load->model('labels_model');
|
|
|
|
$this->labels_model->saveDefaultLabel($id);
|
|
|
|
}
|
|
|
|
|
2023-07-29 18:02:18 +00:00
|
|
|
public function startAtLabel() {
|
2023-07-29 18:49:45 +00:00
|
|
|
$data['stationid'] = xss_clean($this->input->post('stationid'));
|
2023-07-29 18:02:18 +00:00
|
|
|
$this->load->view('labels/startatform', $data);
|
|
|
|
}
|
2023-07-28 06:04:16 +00:00
|
|
|
}
|