UI for uploading QSOs to QRZ.com Added 2 css files for dynamic loading button. https://github.com/loadingio/ldButton/tree/master/dist and https://github.com/loadingio/loading.css/tree/master/dist

This commit is contained in:
AndreasK79 2020-05-20 19:43:13 +02:00
parent 1b0de2d26b
commit 97440b2161
8 changed files with 203 additions and 15 deletions

View File

@ -11,14 +11,13 @@ class Qrz extends CI_Controller {
$this->config->load('config');
}
// Upload QSO to QRZ.com
/*
* Upload QSO to QRZ.com
* When called from the url cloudlog/qrz/upload, the function loops through all station_id's with a qrz api key defined.
* All QSOs not previously uploaded, will then be uploaded, one at a time
*/
public function upload() {
$this->config->load('config');
ini_set('memory_limit', '-1');
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$this->setOptions();
$this->load->model('logbook_model');
@ -27,7 +26,13 @@ class Qrz extends CI_Controller {
if ($station_ids) {
foreach ($station_ids as $station_id) {
$qrz_api_key = $this->logbook_model->exists_qrz_api_key($station_id);
$this->mass_upload_qsos($station_id, $qrz_api_key);
if($this->mass_upload_qsos($station_id, $qrz_api_key)) {
echo "QSOs has been uploaded to QRZ.com.";
log_message('info', 'QSOs has been uploaded to QRZ.com.');
} else{
echo "No QSOs found for upload.";
log_message('info', 'No QSOs found for upload.');
}
}
} else {
echo "No station_id's with a QRZ API Key found";
@ -36,7 +41,21 @@ class Qrz extends CI_Controller {
}
function setOptions() {
$this->config->load('config');
ini_set('memory_limit', '-1');
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
}
/*
* Function gets all QSOs from given station_id, that are not previously uploaded to qrz.
* Adif is build for each qso, and then uploaded, one at a time
*/
function mass_upload_qsos($station_id, $qrz_api_key) {
$i = 0;
$data['qsos'] = $this->logbook_model->get_qrz_qsos($station_id);
if ($data['qsos']) {
@ -45,17 +64,66 @@ class Qrz extends CI_Controller {
$result = $this->logbook_model->push_qso_to_qrz($qrz_api_key, $adif);
if ($result) {
$this->markqso($qso['COL_PRIMARY_KEY']);
$i++;
}
}
echo "QSOs has been uploaded to QRZ.com.";
log_message('info', 'QSOs has been uploaded to QRZ.com.');
return $i;
} else {
echo "No QSOs found for upload.";
log_message('info', 'No QSOs found for upload.');
return $i;
}
}
/*
* Function marks QSO with given primarykey as uploaded to qrz
*/
function markqso($primarykey) {
$this->logbook_model->mark_qrz_qsos_sent($primarykey);
}
}
/*
* Used for displaying the uid for manually selecting log for upload to qrz
*/
public function export() {
$this->load->model('stations');
$data['page_title'] = "QRZ.com Export";
$data['station_profile'] = $this->stations->stations_with_qrz_api_key();
$active_station_id = $this->stations->find_active();
$station_profile = $this->stations->profile($active_station_id);
$data['active_station_info'] = $station_profile->row();
$this->load->view('interface_assets/header', $data);
$this->load->view('qrz/export');
$this->load->view('interface_assets/footer');
}
/*
* Used for ajax-function when selecting log for upload to qrz
*/
public function upload_station() {
$this->setOptions();
$this->load->model('stations');
$postData = $this->input->post();
$this->load->model('logbook_model');
$qrz_api_key = $this->logbook_model->exists_qrz_api_key($postData['station_id']);
header('Content-type: application/json');
if ($i = $this->mass_upload_qsos($postData['station_id'], $qrz_api_key)) {
$stationinfo = $this->stations->stations_with_qrz_api_key();
$info = $stationinfo->result();
$data['status'] = 'OK';
$data['info'] = $info;
$data['infomessage'] = $i . " QSOs are now uploaded to QRZ.com";
echo json_encode($data);
} else {
$data['status'] = 'Error';
$data['info'] = 'Error, no QSOs to upload found';
echo json_encode($data);
}
}
}

View File

@ -829,7 +829,7 @@ class Logbook_model extends CI_Model {
function get_qrz_qsos($station_id){
$sql = 'select * from ' . $this->config->item('table_name') .
' where station_id = ' . $station_id .
' and (COL_QRZCOM_QSO_UPLOAD_STATUS = NULL
' and (COL_QRZCOM_QSO_UPLOAD_STATUS is NULL
or COL_QRZCOM_QSO_UPLOAD_STATUS = ""
or COL_QRZCOM_QSO_UPLOAD_STATUS = "M"
or COL_QRZCOM_QSO_UPLOAD_STATUS = "N")';

View File

@ -190,6 +190,34 @@ class Stations extends CI_Model {
}
}
function stations_with_qrz_api_key() {
$sql = "select station_profile.station_id, station_profile.station_profile_name, station_profile.station_callsign, modc.modcount, notc.notcount, totc.totcount
from station_profile
left outer join (
select count(*) modcount, station_id
from ". $this->config->item('table_name') .
" where COL_QRZCOM_QSO_UPLOAD_STATUS = 'M'
group by station_id
) as modc on station_profile.station_id = modc.station_id
left outer join (
select count(*) notcount, station_id
from " . $this->config->item('table_name') .
" where (coalesce(COL_QRZCOM_QSO_UPLOAD_STATUS, '') = ''
or COL_QRZCOM_QSO_UPLOAD_STATUS = 'N')
group by station_id
) as notc on station_profile.station_id = notc.station_id
left outer join (
select count(*) totcount, station_id
from " . $this->config->item('table_name') .
" where COL_QRZCOM_QSO_UPLOAD_STATUS = 'Y'
group by station_id
) as totc on station_profile.station_id = totc.station_id
where coalesce(station_profile.qrzapikey, '') <> ''";
$query = $this->db->query($sql);
return $query;
}
}
?>

View File

@ -1243,5 +1243,35 @@ $(document).ready(function(){
</script>
<?php } ?>
<?php if ($this->uri->segment(1) == "qrz") { ?>
<script>
function ExportQrz(station_id) {
$(".ld-ext-right").addClass('running');
$(".ld-ext-right").prop('disabled', true);
var baseURL= "<?php echo base_url();?>";
$.ajax({
url: baseURL + 'index.php/qrz/upload_station',
type: 'post',
data: {'station_id': station_id},
success: function (data) {
$(".ld-ext-right").removeClass('running');
$(".ld-ext-right").prop('disabled', false);
if (data.status == 'OK') {
$.each(data.info, function(index, value){
$('#modcount'+value.station_id).html(value.modcount);
$('#notcount'+value.station_id).html(value.notcount);
$('#totcount'+value.station_id).html(value.totcount);
});
$(".card-body").append('<div class="alert alert-success" role="alert"><a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>' + data.infomessage + '</div>');
}
else {
$(".card-body").append('<div class="alert alert-danger" role="alert"><a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>' + data.info + '</div>');
}
}
});
}
</script>
<?php } ?>
</body>
</html>

View File

@ -24,7 +24,12 @@
<link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>assets/plugins/quill/quill.snow.css" />
<?php } ?>
<?php if ($this->uri->segment(1) == "qso") { ?>
<?php if ($this->uri->segment(1) == "qrz") { ?>
<link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>assets/css/loading.min.css" />
<link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>assets/css/ldbtn.min.css" />
<?php } ?>
<?php if ($this->uri->segment(1) == "qso") { ?>
<link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>assets/plugins/select2/css/select2.min.css" />
<?php } ?>
<?php if ($this->uri->segment(1) == "adif") { ?>
@ -111,6 +116,10 @@
<a class="dropdown-item" href="<?php echo site_url('eqsl/import');?>" title="eQSL Import/Export"><i class="fas fa-sync"></i> eQSL Import/Export</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="<?php echo site_url('qrz/export');?>" title="QRZ.com Export"><i class="fas fa-sync"></i> QRZ.com export</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="<?php echo site_url('qslprint');?>" title="Print Requested QSLs"><i class="fas fa-print"></i> Print Requested QSLs</a>

View File

@ -0,0 +1,51 @@
<div class="container adif">
<h1>QRZ.com functions</h1>
<div class="card">
<div class="card-header">
<h5 class="card-title"><?php echo $page_title; ?></h5>
</div>
<div class="card-body">
<p>Here you can upload all QSOs to QRZ.com, which have not been previously uploaded. This might take a while, since only 1 QSO is uploaded at a time.
You need to set a QRZ API Key in your station profile. Only a station profile with an API Key set, is diplayed in the table below.</p>
<?php
if ($station_profile->result()) {
echo '
<table class="table table-bordered table-hover table-striped table-condensed text-center">
<thead>
<tr>
<td>Profile name</td>
<td>Station callsign</td>
<td>Edited QSOs not uploaded</td>
<td>Total QSOs not uploaded</td>
<td>Total QSOs uploaded</td>
<td></td>
</thead>
<tbody>';
foreach ($station_profile->result() as $station) { // Fills the table with the data
echo '<tr>';
echo '<td>' . $station->station_profile_name . '</td>';
echo '<td>' . $station->station_callsign . '</td>';
echo '<td id ="modcount'.$station->station_id.'">' . $station->modcount . '</td>';
echo '<td id ="notcount'.$station->station_id.'">' . $station->notcount . '</td>';
echo '<td id ="totcount'.$station->station_id.'">' . $station->totcount . '</td>';
echo '<td><button id="qrzUpload" type="button" name="qrzUpload" class="btn btn-primary btn-sm ld-ext-right" onclick="ExportQrz('. $station->station_id .')">Export<div class="ld ld-ring ld-spin"></div></button></td>';
echo '</tr>';
}
echo '</tfoot></table></div>';
}
else {
echo '<div class="alert alert-danger" role="alert"><a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>Nothing found!</div>';
}
?>
</div>
</div>
</div>

1
assets/css/ldbtn.min.css vendored Normal file
View File

@ -0,0 +1 @@
.ld-ext-right,.ld-ext-left,.ld-ext-bottom,.ld-ext-top,.ld-over,.ld-over-inverse,.ld-over-full,.ld-over-full-inverse{position:relative;transition:all .3s;transition-timing-function:ease-in}.ld-ext-right>.ld,.ld-ext-left>.ld,.ld-ext-bottom>.ld,.ld-ext-top>.ld,.ld-over>.ld,.ld-over-inverse>.ld,.ld-over-full>.ld,.ld-over-full-inverse>.ld{position:absolute;top:50%;left:50%;width:1em;height:1em;margin:-0.5em;opacity:0;z-index:-1;transition:all .3s;transition-timing-function:ease-in}.ld-ext-right>.ld>*,.ld-ext-left>.ld>*,.ld-ext-bottom>.ld>*,.ld-ext-top>.ld>*,.ld-over>.ld>*,.ld-over-inverse>.ld>*,.ld-over-full>.ld>*,.ld-over-full-inverse>.ld>*{width:1em;height:1em;position:absolute;top:50%;left:50%;transform:translate(-0.5em,-0.5em)}.ld-ext-right.running>.ld,.ld-ext-left.running>.ld,.ld-ext-bottom.running>.ld,.ld-ext-top.running>.ld,.ld-over.running>.ld,.ld-over-inverse.running>.ld,.ld-over-full.running>.ld,.ld-over-full-inverse.running>.ld{opacity:1;z-index:auto;visibility:visible}.ld-ext-right.running{padding-right:2.5em !important}.ld-ext-right>.ld{top:50%;left:auto;right:1.25em}.ld-ext-left.running{padding-left:2.5em !important}.ld-ext-left>.ld{top:50%;right:auto;left:1.25em}.ld-ext-bottom.running{padding-bottom:2.5em !important}.ld-ext-bottom>.ld{top:auto;left:50%;bottom:1.25em}.ld-ext-top.running{padding-top:2.5em !important}.ld-ext-top>.ld{bottom:auto;left:50%;top:1.25em}.ld-over:before,.ld-over-inverse:before,.ld-over-full:before,.ld-over-full-inverse:before{content:" ";display:block;opacity:0;position:absolute;z-index:-1;top:0;left:0;width:100%;height:100%;transition:all .3s;transition-timing-function:ease-in;background:rgba(240,240,240,0.8)}.ld-over.running>.ld,.ld-over-inverse.running>.ld,.ld-over-full.running>.ld,.ld-over-full-inverse.running>.ld{z-index:4001}.ld-over.running:before,.ld-over-inverse.running:before,.ld-over-full.running:before,.ld-over-full-inverse.running:before{opacity:1;z-index:4000;display:block}.ld-over-full.running>.ld,.ld-over-full-inverse.running>.ld,.ld-over-full.running:before,.ld-over-full-inverse.running:before{position:fixed}.ld-over-full>.ld{color:rgba(0,0,0,0.8)}.ld-over-full:before,.ld-over-full-inverse:before{background:rgba(255,255,255,0.8)}.ld-over-inverse>.ld{color:rgba(255,255,255,0.8)}.ld-over-inverse:before{background:rgba(0,0,0,0.6)}.ld-over-full-inverse>.ld{color:rgba(255,255,255,0.8)}.ld-over-full-inverse:before{background:rgba(0,0,0,0.6)}

1
assets/css/loading.min.css vendored Normal file

File diff suppressed because one or more lines are too long