kopia lustrzana https://github.com/magicbug/Cloudlog
Controller, Migrationscript and View for HRDLog
rodzic
a6b04edd5c
commit
6253650190
|
@ -0,0 +1,176 @@
|
|||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
/*
|
||||
Controller to interact with the hrdlog.net API
|
||||
*/
|
||||
|
||||
class Hrdlog extends CI_Controller {
|
||||
|
||||
// Show frontend if there is one
|
||||
public function index() {
|
||||
$this->config->load('config');
|
||||
}
|
||||
|
||||
/*
|
||||
* Upload QSO to hrdlog.net
|
||||
* When called from the url cloudlog/hrdlog/upload, the function loops through all station_id's with a hrdlog code defined.
|
||||
* All QSOs not previously uploaded, will then be uploaded, one at a time
|
||||
*/
|
||||
public function upload() {
|
||||
$this->setOptions();
|
||||
|
||||
$this->load->model('logbook_model');
|
||||
|
||||
$station_ids = $this->logbook_model->get_station_id_with_hrdlog_code();
|
||||
|
||||
if ($station_ids) {
|
||||
foreach ($station_ids as $station) {
|
||||
$hrdlog_code = $station->hrdlog_code;
|
||||
if($this->mass_upload_qsos($station->station_id, $hrdlog_code)) {
|
||||
echo "QSOs have been uploaded to hrdlog.net.";
|
||||
log_message('info', 'QSOs have been uploaded to hrdlog.net.');
|
||||
} else{
|
||||
echo "No QSOs found for upload.";
|
||||
log_message('info', 'No QSOs found for upload.');
|
||||
}
|
||||
}
|
||||
} else {
|
||||
echo "No station profiles with a hrdlog Code found.";
|
||||
log_message('error', "No station profiles with a hrdlog Code found.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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 hrdlog.
|
||||
* Adif is build for each qso, and then uploaded, one at a time
|
||||
*/
|
||||
function mass_upload_qsos($station_id, $hrdlog_code) {
|
||||
$i = 0;
|
||||
$data['qsos'] = $this->logbook_model->get_hrdlog_qsos($station_id);
|
||||
$errormessages=array();
|
||||
|
||||
$CI =& get_instance();
|
||||
$CI->load->library('AdifHelper');
|
||||
|
||||
if ($data['qsos']) {
|
||||
foreach ($data['qsos']->result() as $qso) {
|
||||
$adif = $CI->adifhelper->getAdifLine($qso);
|
||||
|
||||
if ($qso->COL_HRDLOG_QSO_UPLOAD_STATUS == 'M') {
|
||||
$result = $this->logbook_model->push_qso_to_hrdlog($hrdlog_code, $qso->COL_STATION_CALLSIGN,$adif, true);
|
||||
} else {
|
||||
$result = $this->logbook_model->push_qso_to_hrdlog($hrdlog_code, $qso->COL_STATION_CALLSIGN,$adif);
|
||||
}
|
||||
|
||||
if ( ($result['status'] == 'OK') || ( ($result['status'] == 'error') || ($result['status'] == 'duplicate')) ){
|
||||
$this->markqso($qso->COL_PRIMARY_KEY);
|
||||
$i++;
|
||||
} elseif ((substr($result['status'],0,11) == 'auth_error')) {
|
||||
log_message('error', 'hrdlog upload failed for qso: Call: ' . $qso->COL_CALL . ' Band: ' . $qso->COL_BAND . ' Mode: ' . $qso->COL_MODE . ' Time: ' . $qso->COL_TIME_ON);
|
||||
log_message('error', 'hrdlog upload failed with the following message: ' .$result['message']);
|
||||
log_message('error', 'hrdlog upload stopped for Station_ID: ' .$station_id);
|
||||
$errormessages[] = $result['message'] . 'Invalid HRDLog-Code, stopped at Call: ' . $qso->COL_CALL . ' Band: ' . $qso->COL_BAND . ' Mode: ' . $qso->COL_MODE . ' Time: ' . $qso->COL_TIME_ON;
|
||||
break; /* If key is invalid, immediate stop syncing for more QSOs of this station */
|
||||
} else {
|
||||
log_message('error', 'hrdlog upload failed for qso: Call: ' . $qso->COL_CALL . ' Band: ' . $qso->COL_BAND . ' Mode: ' . $qso->COL_MODE . ' Time: ' . $qso->COL_TIME_ON);
|
||||
log_message('error', 'hrdlog upload failed with the following message: ' .$result['message']);
|
||||
$errormessages[] = $result['message'] . ' Call: ' . $qso->COL_CALL . ' Band: ' . $qso->COL_BAND . ' Mode: ' . $qso->COL_MODE . ' Time: ' . $qso->COL_TIME_ON;
|
||||
}
|
||||
}
|
||||
$result['status'] = 'OK';
|
||||
$result['count'] = $i;
|
||||
$result['errormessages'] = $errormessages;
|
||||
return $result;
|
||||
} else {
|
||||
$result['status'] = 'Error';
|
||||
$result['count'] = $i;
|
||||
$result['errormessages'] = $errormessages;
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Function marks QSO with given primarykey as uploaded to hrdlog
|
||||
*/
|
||||
function markqso($primarykey) {
|
||||
$this->logbook_model->mark_hrdlog_qsos_sent($primarykey);
|
||||
}
|
||||
|
||||
/*
|
||||
* Used for displaying the uid for manually selecting log for upload to hrdlog
|
||||
*/
|
||||
public function export() {
|
||||
$this->load->model('stations');
|
||||
|
||||
$data['page_title'] = "HRDlog.net Logbook";
|
||||
|
||||
$data['station_profiles'] = $this->stations->all_of_user();
|
||||
$data['station_profile'] = $this->stations->stations_with_hrdlog_code();
|
||||
|
||||
$this->load->view('interface_assets/header', $data);
|
||||
$this->load->view('hrdlog/export');
|
||||
$this->load->view('interface_assets/footer');
|
||||
}
|
||||
|
||||
/*
|
||||
* Used for ajax-function when selecting log for upload to hrdlog
|
||||
*/
|
||||
public function upload_station() {
|
||||
$this->setOptions();
|
||||
$this->load->model('stations');
|
||||
|
||||
$postData = $this->input->post();
|
||||
|
||||
$this->load->model('logbook_model');
|
||||
$result = $this->logbook_model->exists_hrdlog_code($postData['station_id']);
|
||||
$hrdlog_code = $result->hrdlog_code;
|
||||
header('Content-type: application/json');
|
||||
$result = $this->mass_upload_qsos($postData['station_id'], $hrdlog_code);
|
||||
if ($result['status'] == 'OK') {
|
||||
$stationinfo = $this->stations->stations_with_hrdlog_code();
|
||||
$info = $stationinfo->result();
|
||||
|
||||
$data['status'] = 'OK';
|
||||
$data['info'] = $info;
|
||||
$data['infomessage'] = $result['count'] . " QSOs are now uploaded to hrdlog";
|
||||
$data['errormessages'] = $result['errormessages'];
|
||||
echo json_encode($data);
|
||||
} else {
|
||||
$data['status'] = 'Error';
|
||||
$data['info'] = 'Error: No QSOs found to upload.';
|
||||
$data['errormessages'] = $result['errormessages'];
|
||||
echo json_encode($data);
|
||||
}
|
||||
}
|
||||
|
||||
public function mark_hrdlog() {
|
||||
// Set memory limit to unlimited to allow heavy usage
|
||||
ini_set('memory_limit', '-1');
|
||||
|
||||
$station_id = $this->security->xss_clean($this->input->post('station_profile'));
|
||||
|
||||
$this->load->model('adif_data');
|
||||
|
||||
$data['qsos'] = $this->adif_data->export_custom($this->input->post('from'), $this->input->post('to'), $station_id);
|
||||
|
||||
$this->load->model('logbook_model');
|
||||
|
||||
foreach ($data['qsos']->result() as $qso)
|
||||
{
|
||||
$this->logbook_model->mark_hrdlog_qsos_sent($qso->COL_PRIMARY_KEY);
|
||||
}
|
||||
|
||||
$this->load->view('interface_assets/header', $data);
|
||||
$this->load->view('hrdlog/mark_hrdlog', $data);
|
||||
$this->load->view('interface_assets/footer');
|
||||
}
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
class Migration_add_hrdlog_fields extends CI_Migration {
|
||||
|
||||
public function up()
|
||||
{
|
||||
if (!$this->db->field_exists('hrdlogrealtime', 'station_profile')) {
|
||||
$fields = array(
|
||||
'hrdlogrealtime tinyint(1)'
|
||||
);
|
||||
$this->dbforge->add_column('station_profile', $fields);
|
||||
}
|
||||
|
||||
if (!$this->db->field_exists('hrdlog_code', 'station_profile')) {
|
||||
$fields = array(
|
||||
'hrdlog_code varchar(20) DEFAULT NULL',
|
||||
);
|
||||
$this->dbforge->add_column('station_profile', $fields);
|
||||
}
|
||||
|
||||
if ( (!$this->db->field_exists('COL_HRDLOG_QSO_UPLOAD_DATE', $this->config->item('table_name'))) &&
|
||||
(!$this->db->field_exists('COL_HRDLOG_QSO_UPLOAD_STATUS', $this->config->item('table_name')))) {
|
||||
$fields = array(
|
||||
'COL_HRDLOG_QSO_UPLOAD_DATE datetime default NULL',
|
||||
'COL_HRDLOG_QSO_UPLOAD_STATUS varchar(10) default NULL'
|
||||
);
|
||||
$this->dbforge->add_column($this->config->item('table_name'), $fields);
|
||||
}
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
if ($this->db->field_exists('hrdlogrealtime', 'station_profile')) {
|
||||
$this->dbforge->drop_column('station_profile', 'hrdlogrealtime');
|
||||
}
|
||||
if ($this->db->field_exists('hrdlog_code', 'station_profile')) {
|
||||
$this->dbforge->drop_column('station_profile', 'hrdlog_code');
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,96 @@
|
|||
|
||||
<div class="container adif">
|
||||
|
||||
<h2><?php echo $page_title; ?></h2>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<ul class="nav nav-tabs card-header-tabs pull-right" role="tablist">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link active" id="export-tab" data-toggle="tab" href="#export" role="tab" aria-controls="import" aria-selected="true">Upload Logbook</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" id="mark-tab" data-toggle="tab" href="#mark" role="tab" aria-controls="export" aria-selected="false">Mark QSOs</a>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="card-body">
|
||||
<div class="tab-content">
|
||||
<div class="tab-pane active" id="export" role="tabpanel" aria-labelledby="export-tab">
|
||||
<p>Here you can see and upload all QSOs which have not been previously uploaded to a HRDLog logbook.</p>
|
||||
<p>You need to set a HRDLog Logbook API Code in your station profile. Only station profiles with an API Key set are displayed.</p>
|
||||
<p>The Code can be demanded at <a href="http://www.hrdlog.net/EditUser.aspx" target="new" class="link">http://www.hrdlog.net/EditUser.aspx</a></p>
|
||||
<p><span class="badge badge-warning">Warning</span>This might take a while as QSO uploads are processed sequentially.</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>Actions</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="HrdlogUpload" type="button" name="HrdlogUpload" class="btn btn-primary btn-sm ld-ext-right" onclick="ExportHrd('. $station->station_id .')"><i class="fas fa-cloud-upload-alt"></i> Upload<div class="ld ld-ring ld-spin"></div></button></td>';
|
||||
echo '</tr>';
|
||||
}
|
||||
echo '</tfoot></table>';
|
||||
|
||||
}
|
||||
else {
|
||||
echo '<div class="alert alert-danger" role="alert"><a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>Nothing found!</div>';
|
||||
}
|
||||
?>
|
||||
|
||||
</div>
|
||||
<div class="tab-pane fade" id="mark" role="tabpanel" aria-labelledby="home-tab">
|
||||
|
||||
<form class="form" action="<?php echo site_url('hrdlog/mark_hrdlog'); ?>" method="post" enctype="multipart/form-data">
|
||||
<select name="station_profile" class="custom-select mb-4 mr-sm-4" style="width: 30%;">
|
||||
<option value="0">Select Station Location</option>
|
||||
<?php foreach ($station_profiles->result() as $station) { ?>
|
||||
<option value="<?php echo $station->station_id; ?>">Callsign: <?php echo $station->station_callsign; ?> (<?php echo $station->station_profile_name; ?>)</option>
|
||||
<?php } ?>
|
||||
</select>
|
||||
<p><span class="badge badge-warning">Warning</span> If a date range is not selected then all QSOs will be marked!</p>
|
||||
<p class="card-text">From date:</p>
|
||||
<div class="row">
|
||||
<div class="input-group date col-md-3" id="datetimepicker5" data-target-input="nearest">
|
||||
<input name="from" type="text" placeholder="DD/MM/YYYY" class="form-control datetimepicker-input" data-target="#datetimepicker1"/>
|
||||
<div class="input-group-append" data-target="#datetimepicker5" data-toggle="datetimepicker">
|
||||
<div class="input-group-text"><i class="fa fa-calendar"></i></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<p class="card-text">To date:</p>
|
||||
<div class="row">
|
||||
<div class="input-group date col-md-3" id="datetimepicker6" data-target-input="nearest">
|
||||
<input name="to" "totype="text" placeholder="DD/MM/YYYY" class="form-control datetimepicker-input" data-target="#datetimepicker2"/>
|
||||
<div class="input-group-append" data-target="#datetimepicker6" data-toggle="datetimepicker">
|
||||
<div class="input-group-text"><i class="fa fa-calendar"></i></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<br>
|
||||
<button type="submit" class="btn-sm btn-primary" value="Export">Mark QSOs as exported to HRDLog Logbook</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
|
@ -0,0 +1,22 @@
|
|||
<div class="container">
|
||||
<br>
|
||||
<?php if($this->session->flashdata('message')) { ?>
|
||||
<!-- Display Message -->
|
||||
<div class="alert-message error">
|
||||
<p><?php echo $this->session->flashdata('message'); ?></p>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
QSOs marked
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<h3 class="card-title">Yay, it's done!</h3>
|
||||
<p class="card-text">The QSOs are marked as exported to HRDLog Logbook.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
|
Ładowanie…
Reference in New Issue