Merge pull request #1150 from AndreasK79/dxatlas_grid_export

Dxatlas grid export
这个提交包含在:
Andreas Kristiansen 2021-09-15 19:15:33 +02:00 提交者 GitHub
当前提交 1ad0343ed0
找不到此签名对应的密钥
GPG 密钥 ID: 4AEE18F83AFDEB23
共有 6 个文件被更改,包括 460 次插入1 次删除

查看文件

@ -0,0 +1,122 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Dxatlas extends CI_Controller {
public function index() {
$this->load->model('user_model');
if(!$this->user_model->authorize(99)) { $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); redirect('dashboard'); }
$this->load->model('modes');
$this->load->model('dxcc');
$this->load->model('logbook_model');
$this->load->model('stations');
$data['station_profile'] = $this->stations->all(); // Used in the view for station location select
$data['worked_bands'] = $this->dxcc->get_worked_bands(); // Used in the view for band select
$data['modes'] = $this->modes->active(); // Used in the view for mode select
$data['dxcc'] = $this->logbook_model->fetchDxcc(); // Used in the view for dxcc select
$data['page_title'] = "DX Atlas Gridsquare Export";
$this->load->view('interface_assets/header', $data);
$this->load->view('dxatlas/index');
$this->load->view('interface_assets/footer');
}
public function export() {
$this->load->model('dxatlas_model');
// Parameters
$station_id = $this->security->xss_clean($this->input->post('station_profile'));
$band = $this->security->xss_clean($this->input->post('band'));
$mode = $this->security->xss_clean($this->input->post('mode'));
$dxcc = $this->security->xss_clean($this->input->post('dxcc_id'));
$cqz = $this->security->xss_clean($this->input->post('cqz'));
$propagation = $this->security->xss_clean($this->input->post('prop_mode'));
$fromdate = $this->security->xss_clean($this->input->post('fromdate'));
$todate = $this->security->xss_clean($this->input->post('todate'));
// Get QSOs with Valid QRAs
$grids = $this->dxatlas_model->get_gridsquares($station_id, $band, $mode, $dxcc, $cqz, $propagation, $fromdate, $todate);
$this->generateFiles($grids['worked'], $grids['confirmed'], $band);
}
function generateFiles($wkdArray, $cfmArray, $band) {
$gridCfmArray = [];
$gridWkdArray = [];
$fieldCfmArray = [];
$fieldWkdArray = [];
foreach ($cfmArray as $grid) {
$field = substr($grid, 0, 2);
if (!in_array($field, $fieldCfmArray)) {
$fieldCfmArray[] = $field;
}
$gridCfmArray[] = $grid;
}
foreach ($wkdArray as $grid) {
$field = substr($grid, 0, 2);
if (!in_array($field, $fieldCfmArray)) {
if (!in_array($field, $fieldWkdArray)) {
$fieldWkdArray[] = $field;
}
}
if (!in_array($grid, $gridCfmArray)) {
$gridWkdArray[] = $grid;
}
}
$gridWkdString = '';
$gridCfmString = '';
asort($gridWkdArray);
asort($gridCfmArray);
asort($fieldWkdArray);
asort($fieldCfmArray);
foreach ($fieldWkdArray as $fields) {
$gridWkdString .= $fields . "\r\n";
}
foreach ($gridWkdArray as $grids) {
$gridWkdString .= $grids . "\r\n";
}
foreach ($fieldCfmArray as $fields) {
$gridCfmString .= $fields . "\r\n";
}
foreach ($gridCfmArray as $grids) {
$gridCfmString .= $grids . "\r\n";
}
$this->makeZip($gridWkdString, $gridCfmString, $band);
}
function makeZip($gridWkdString, $gridCfmString, $band) {
$zipFileName = 'dxatlas_gridsquares_'. $band . '.zip';
// Prepare File
$file = tempnam("tmp", "zip");
$zip = new ZipArchive();
$zip->open($file, ZipArchive::OVERWRITE);
// Stuff with content
$zip->addFromString($band . '_grids.wkd', $gridWkdString);
$zip->addFromString($band . '_grids.cfm', $gridCfmString);
// Close and send to users
$zip->close();
$length = filesize($file);
header('Content-Type: application/zip');
header('Content-Length: ' . $length);
header('Content-Disposition: attachment; filename="' . $zipFileName . '"');
readfile($file);
unlink($file);
}
}

查看文件

@ -0,0 +1,172 @@
<?php
class Dxatlas_model extends CI_Model
{
function __construct()
{
// Call the Model constructor
parent::__construct();
}
/*
* Fetches worked and confirmed gridsquare from the logbook
*/
function get_gridsquares($station_id, $band, $mode, $dxcc, $cqz, $propagation, $fromdate, $todate) {
$gridArray = $this->fetchGrids($station_id, $band, $mode, $dxcc, $cqz, $propagation, $fromdate, $todate);
if (isset($gridArray)) {
return $gridArray;
} else {
return 0;
}
}
/*
* Builds the array for worked and confirmed gridsquares
*/
function fetchGrids($station_id, $band, $mode, $dxcc, $cqz, $propagation, $fromdate, $todate) {
// Getting all the worked grids
$col_gridsquare_worked = $this->get_grids($station_id, $band, $mode, $dxcc, $cqz, $propagation, $fromdate, $todate, 'none', 'single');
$workedGridArray = array();
foreach ($col_gridsquare_worked as $workedgrid) {
array_push($workedGridArray, $workedgrid['gridsquare']);
}
$col_vucc_grids_worked = $this->get_grids($station_id, $band, $mode, $dxcc, $cqz, $propagation, $fromdate, $todate, 'none', 'multi');
foreach ($col_vucc_grids_worked as $gridSplit) {
$grids = explode(",", $gridSplit['col_vucc_grids']);
foreach($grids as $key) {
$grid_four = strtoupper(substr(trim($key),0,4));
if(!in_array($grid_four, $workedGridArray)){
array_push($workedGridArray, $grid_four);
}
}
}
// Getting all the confirmed grids
$col_gridsquare_confirmed = $this->get_grids($station_id, $band, $mode, $dxcc, $cqz, $propagation, $fromdate, $todate, 'both', 'single');
$confirmedGridArray = array();
foreach ($col_gridsquare_confirmed as $confirmedgrid) {
array_push($confirmedGridArray, $confirmedgrid['gridsquare']);
if(in_array($confirmedgrid['gridsquare'], $workedGridArray)){
$index = array_search($confirmedgrid['gridsquare'],$workedGridArray);
unset($workedGridArray[$index]);
}
}
$col_vucc_grids_confirmed = $this->get_grids($station_id, $band, $mode, $dxcc, $cqz, $propagation, $fromdate, $todate, 'both', 'multi');
foreach ($col_vucc_grids_confirmed as $gridSplit) {
$grids = explode(",", $gridSplit['col_vucc_grids']);
foreach($grids as $key) {
$grid_four = strtoupper(substr(trim($key),0,4));
if(!in_array($grid_four, $confirmedGridArray)){
array_push($confirmedGridArray, $grid_four);
}
if(in_array($grid_four, $workedGridArray)){
$index = array_search($grid_four,$workedGridArray);
unset($workedGridArray[$index]);
}
}
}
$vuccArray['worked'] = $workedGridArray;
$vuccArray['confirmed'] = $confirmedGridArray;
return $vuccArray;
}
/*
* Gets the grids from the datbase
*
* Filters:
*
* $band = filter on band
* $mode = filter on mode
* $dxcc = filter on dxx
* $cqz = filter on cq zone
* $propagation = Filter on propagation
* $fromdate = Date range from
* $todate = Date range to
* $column = Chooses if we fetch from col_gridsquare (only single grids) or col_vucc_grids (multisquares)
* $confirmationMethod - qsl, lotw or both, use anything else to skip confirmed
*
*/
function get_grids($station_id, $band, $mode, $dxcc, $cqz, $propagation, $fromdate, $todate, $confirmationMethod, $column) {
$sql = "";
if ($column == 'single') {
$sql .= "select distinct upper(substring(col_gridsquare, 1, 4)) gridsquare
from " . $this->config->item('table_name') .
" where col_gridsquare <> ''";
}
else if ($column == 'multi') {
$sql .= "select col_vucc_grids
from " . $this->config->item('table_name') .
" where col_vucc_grids <> '' ";
}
if ($station_id != "All") {
$sql .= ' and station_id = ' . $station_id;
}
if ($confirmationMethod == 'both') {
$sql .= " and (col_qsl_rcvd='Y' or col_lotw_qsl_rcvd='Y')";
}
else if ($confirmationMethod == 'qsl') {
$sql .= " and col_qsl_rcvd='Y'";
}
else if ($confirmationMethod == 'lotw') {
$sql .= " and col_lotw_qsl_rcvd='Y'";
}
if ($band != 'All') {
if ($band == 'SAT') {
$sql .= " and col_prop_mode ='" . $band . "'";
} else {
$sql .= " and col_prop_mode !='SAT'";
$sql .= " and col_band ='" . $band . "'";
}
}
if ($mode != 'All') {
$sql .= " and (COL_MODE = '" . $mode . "' or COL_SUBMODE = '" . $mode . "')";
}
if ($dxcc != 'All') {
$sql .= " and COL_DXCC ='" . $dxcc . "'";
}
if ($cqz != 'All') {
$sql .= " and COL_CQZ ='" . $cqz . "'";
}
if ($propagation != 'All') {
$sql .= " and COL_PROP_MODE ='" . $propagation . "'";
}
// If date is set, we format the date and add it to the where-statement
if ($fromdate != "") {
$from = DateTime::createFromFormat('d/m/Y', $fromdate);
$from = $from->format('Y-m-d');
$sql .= " and date(COL_TIME_ON) >='" . $from . "'";
}
if ($todate != "") {
$to = DateTime::createFromFormat('d/m/Y', $todate);
$to = $to->format('Y-m-d');
$sql .= " and date(COL_TIME_ON) <='" . $to . "'";
}
$query = $this->db->query($sql);
return $query->result_array();
}
}
?>

查看文件

@ -0,0 +1,137 @@
<div class="container">
<br>
<h2><?php echo $page_title; ?></h2>
<div class="card">
<div class="card-header">
Export your logbook for use in DX Atlas to display worked / confirmed gridsquares.
</div>
<div class="alert alert-warning" role="alert">
Only QSOs with a gridsquare defined will be exported!
</div>
<div class="card-body">
<form class="form" action="<?php echo site_url('dxatlas/export'); ?>" method="post" enctype="multipart/form-data">
<div class="form-row">
<div class="form-group col-md-3">
<label for="station_profile"><?php echo $this->lang->line('cloudlog_station_profile'); ?></label>
<select name="station_profile" class="station_id custom-select">
<option value="All">All</option>
<?php foreach ($station_profile->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>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-3">
<label for="band">Band</label>
<select id="band" name="band" class="custom-select">
<option value="All" <?php if ($this->input->post('band') == "All" || $this->input->method() !== 'post') echo ' selected'; ?> >Every band</option>
<?php foreach($worked_bands as $band) {
echo '<option value="' . $band . '"';
if ($this->input->post('band') == $band) echo ' selected';
echo '>' . $band . '</option>'."\n";
} ?>
</select>
</div>
<div class="form-group col-md-3">
<label for="mode">Mode</label>
<select id="mode" name="mode" class="form-control custom-select">
<option value="All">All</option>
<?php
foreach($modes->result() as $mode){
if ($mode->submode == null) {
echo '<option value="' . $mode->mode . '">'. $mode->mode . '</option>'."\n";
} else {
echo '<option value="' . $mode->submode . '">' . $mode->submode . '</option>'."\n";
}
}
?>
</select>
</div>
<div class="form-group col-md-4">
<label for="dxcc_id">DXCC</label>
<select class="custom-select" id="dxcc_id" name="dxcc_id">
<option value="All">All</option>
<?php
foreach($dxcc as $d){
echo '<option value=' . $d->adif . '>' . $d->prefix . ' - ' . ucwords(strtolower(($d->name))) . '</option>';
}
?>
</select>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-3">
<label for="cqz">CQ Zone</label>
<select class="custom-select" id="cqz" name="cqz">
<option value="All">All</option>
<?php
for ($i = 1; $i<=40; $i++) {
echo '<option value="'. $i . '">'. $i .'</option>';
}
?>
</select>
</div>
<div class="form-group col-md-5">
<label for="selectPropagation">Propagation Mode</label>
<select class="custom-select" id="selectPropagation" name="prop_mode">
<option value="All">All</option>
<option value="AUR">Aurora</option>
<option value="AUE">Aurora-E</option>
<option value="BS">Back scatter</option>
<option value="ECH">EchoLink</option>
<option value="EME">Earth-Moon-Earth</option>
<option value="ES">Sporadic E</option>
<option value="FAI">Field Aligned Irregularities</option>
<option value="F2">F2 Reflection</option>
<option value="INTERNET">Internet-assisted</option>
<option value="ION">Ionoscatter</option>
<option value="IRL">IRLP</option>
<option value="MS">Meteor scatter</option>
<option value="RPT">Terrestrial or atmospheric repeater or transponder</option>
<option value="RS">Rain scatter</option>
<option value="SAT">Satellite</option>
<option value="TEP">Trans-equatorial</option>
<option value="TR">Tropospheric ducting</option>
</select>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-3">
<label for="datetimepicker1">From date:</label>
<div class="dxatlasdatepicker input-group date col-md-12" id="datetimepicker1" data-target-input="nearest">
<input name="fromdate" type="text" placeholder="DD/MM/YYYY" class="form-control datetimepicker-input" data-target="#datetimepicker1"/>
<div class="input-group-append" data-target="#datetimepicker1" data-toggle="datetimepicker">
<div class="input-group-text"><i class="fa fa-calendar"></i></div>
</div>
</div>
</div>
<div class="form-group col-md-3">
<label for="datetimepicker2">To date:</label>
<div class="dxatlasdatepicker input-group date col-md-12" id="datetimepicker2" data-target-input="nearest">
<input name="todate" "totype="text" placeholder="DD/MM/YYYY" class="form-control datetimepicker-input" data-target="#datetimepicker2"/>
<div class="input-group-append" data-target="#datetimepicker2" data-toggle="datetimepicker">
<div class="input-group-text"><i class="fa fa-calendar"></i></div>
</div>
</div>
</div>
</div>
<br>
<button type="submit" class="btn btn-primary mb-2" value="Export">Export</button>
</form>
</div>
</div>
</div>

查看文件

@ -2024,6 +2024,24 @@ function deleteQsl(id) {
<script src="<?php echo base_url() ;?>assets/js/sections/contestingnames.js"></script> <script src="<?php echo base_url() ;?>assets/js/sections/contestingnames.js"></script>
<?php } ?> <?php } ?>
<?php if ($this->uri->segment(1) == "dxatlas") { ?>
<script type="text/javascript" src="<?php echo base_url(); ?>assets/js/moment.min.js"></script>
<script type="text/javascript" src="<?php echo base_url(); ?>assets/js/tempusdominus-bootstrap-4.min.js"></script>
<script>
$(function () {
$('#datetimepicker1').datetimepicker({
format: 'DD/MM/YYYY',
});
});
$(function () {
$('#datetimepicker2').datetimepicker({
format: 'DD/MM/YYYY',
});
});
</script>
<?php } ?>
<?php if ($this->uri->segment(1) == "qslprint") { ?> <?php if ($this->uri->segment(1) == "qslprint") { ?>
<script> <script>
function deleteFromQslQueue(id) { function deleteFromQslQueue(id) {

查看文件

@ -197,6 +197,8 @@
<a class="dropdown-item" href="<?php echo site_url('kml');?>" title="KML Export for Google Earth"><i class="fas fa-sync"></i> KML Export</a> <a class="dropdown-item" href="<?php echo site_url('kml');?>" title="KML Export for Google Earth"><i class="fas fa-sync"></i> KML Export</a>
<a class="dropdown-item" href="<?php echo site_url('dxatlas');?>" title="DX Atlas Gridsquare Export"><i class="fas fa-sync"></i> DX Atlas Gridsquare Export</a>
<div class="dropdown-divider"></div> <div class="dropdown-divider"></div>
<a class="dropdown-item" href="<?php echo site_url('lotw');?>" title="Synchronise with Logbook of the World (LotW)"><i class="fas fa-sync"></i> Logbook of the World</a> <a class="dropdown-item" href="<?php echo site_url('lotw');?>" title="Synchronise with Logbook of the World (LotW)"><i class="fas fa-sync"></i> Logbook of the World</a>

查看文件

@ -242,4 +242,12 @@ color: #ffffff;
.was-map-dialog .modal-dialog { .was-map-dialog .modal-dialog {
max-width: 73% !important; max-width: 73% !important;
} }
} }
/*
* Timepicker alignment
*/
.dxatlasdatepicker {
padding-right: 0;
padding-left: 0;
}