kopia lustrzana https://github.com/magicbug/Cloudlog
[Cabrillo export] Added contest export for cabrillo
rodzic
853720592b
commit
3a415a5587
|
@ -0,0 +1,82 @@
|
|||
<?php
|
||||
|
||||
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
|
||||
/*
|
||||
This controller contains features for Cabrillo
|
||||
*/
|
||||
|
||||
class Cabrillo extends CI_Controller {
|
||||
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$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'); }
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$data['page_title'] = "Export Cabrillo";
|
||||
|
||||
$this->load->model('Contesting_model');
|
||||
|
||||
$data['contestyears'] = $this->Contesting_model->get_logged_years();
|
||||
|
||||
$footerData = [];
|
||||
$footerData['scripts'] = [
|
||||
'assets/js/sections/cabrillo.js'
|
||||
];
|
||||
|
||||
$this->load->view('interface_assets/header', $data);
|
||||
$this->load->view('cabrillo/index');
|
||||
$this->load->view('interface_assets/footer', $footerData);
|
||||
}
|
||||
|
||||
public function getContests() {
|
||||
$this->load->model('Contesting_model');
|
||||
$result = $this->Contesting_model->get_logged_contests($this->input->post('year'));
|
||||
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode($result);
|
||||
}
|
||||
|
||||
public function getContestDates() {
|
||||
$this->load->model('Contesting_model');
|
||||
$result = $this->Contesting_model->get_contest_dates($this->input->post('year'), $this->input->post('contestid'));
|
||||
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode($result);
|
||||
}
|
||||
|
||||
public function export() {
|
||||
// Set memory limit to unlimited to allow heavy usage
|
||||
ini_set('memory_limit', '-1');
|
||||
$this->load->model('Contesting_model');
|
||||
|
||||
$contest_id = $this->security->xss_clean($this->input->post('contestid'));
|
||||
$fromto = $this->security->xss_clean($this->input->post('contestdates'));
|
||||
|
||||
$fromto = explode(',', $fromto);
|
||||
|
||||
$from = $fromto[0];
|
||||
$to = $fromto[1];
|
||||
|
||||
$data['qsos'] = $this->Contesting_model->export_custom($from, $to, $contest_id);
|
||||
|
||||
$data['contest_id'] = $contest_id;
|
||||
$data['callsign'] = '';
|
||||
$data['claimed_score'] = '';
|
||||
$data['operators'] = '';
|
||||
$data['club'] = '';
|
||||
$data['name'] = '';
|
||||
$data['address1'] = '';
|
||||
$data['address2'] = '';
|
||||
$data['address3'] = '';
|
||||
$data['soapbox'] = '';
|
||||
|
||||
$this->load->view('cabrillo/export', $data);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
class Cabrilloformat {
|
||||
|
||||
public function header($contest_id, $callsign, $claimed_score, $operators, $club, $name, $address1, $address2, $address3, $soapbox) {
|
||||
$cab_header = "";
|
||||
$cab_header .= "START-OF-LOG: 3.0"."\r\n";
|
||||
$cab_header .= "CONTEST: ".$contest_id."\r\n";
|
||||
$cab_header .= "CALLSIGN: ".$callsign."\r\n";
|
||||
|
||||
if($claimed_score != null) {
|
||||
$cab_header .= "CLAIMED-SCORE: ".$claimed_score."\r\n";
|
||||
}
|
||||
|
||||
$cab_header .= "OPERATORS: ".$operators."\r\n";
|
||||
|
||||
if($club != null) {
|
||||
$cab_header .= "CLUB: ".$club."\r\n";
|
||||
}
|
||||
|
||||
$cab_header .= "NAME: ".$name."\r\n";
|
||||
$cab_header .= "ADDRESS: ".$address1."\r\n";
|
||||
$cab_header .= "ADDRESS: ".$address2."\r\n";
|
||||
$cab_header .= "ADDRESS: ".$address3."\r\n";
|
||||
$cab_header .= "SOAPBOX: ".$soapbox."\r\n";
|
||||
|
||||
return $cab_header;
|
||||
|
||||
}
|
||||
|
||||
public function footer() {
|
||||
return "END-OF-LOG:";
|
||||
}
|
||||
|
||||
public function qso($qso) {
|
||||
$freq = substr($qso->COL_FREQ, 0, -3);
|
||||
|
||||
if($qso->COL_MODE == "SSB") {
|
||||
$mode = "PH";
|
||||
} elseif($qso->COL_MODE == "RTTY") {
|
||||
$mode = "RY";
|
||||
} else {
|
||||
$mode = $qso->COL_MODE;
|
||||
}
|
||||
|
||||
$time = substr($qso->COL_TIME_ON, 0, -3);
|
||||
|
||||
$time = str_replace(":","",$time);
|
||||
|
||||
if ($qso->COL_STX_STRING != "") {
|
||||
|
||||
if($qso->COL_SRX_STRING != "") {
|
||||
$rx_string = $qso->COL_SRX_STRING;
|
||||
} else {
|
||||
$rx_string = "--";
|
||||
}
|
||||
|
||||
return "QSO: ".$freq." ".$mode." ".$time." ".$qso->station_callsign."\t".$qso->COL_RST_SENT." ".$qso->COL_STX." ".$qso->COL_STX_STRING."\t".$qso->COL_CALL."\t".$qso->COL_RST_RCVD." ".$qso->COL_STX." ".$rx_string."\n";
|
||||
} else {
|
||||
return "QSO: ".$freq." ".$mode." ".$time." ".$qso->station_callsign."\t".$qso->COL_RST_SENT." ".$qso->COL_STX."\t".$qso->COL_CALL."\t".$qso->COL_RST_RCVD." ".$qso->COL_STX."\n";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -160,4 +160,107 @@ class Contesting_model extends CI_Model {
|
|||
|
||||
return $query;
|
||||
}
|
||||
|
||||
function export_custom($from, $to, $contest_id) {
|
||||
$CI =& get_instance();
|
||||
$CI->load->model('Stations');
|
||||
$station_id = $CI->Stations->find_active();
|
||||
|
||||
$this->db->select(''.$this->config->item('table_name').'.*, station_profile.*');
|
||||
$this->db->from($this->config->item('table_name'));
|
||||
$this->db->where($this->config->item('table_name').'.station_id', $station_id);
|
||||
|
||||
// If date is set, we format the date and add it to the where-statement
|
||||
if ($from != 0) {
|
||||
$from = DateTime::createFromFormat('Y-m-d', $from);
|
||||
$from = $from->format('Y-m-d');
|
||||
$this->db->where("date(".$this->config->item('table_name').".COL_TIME_ON) >= '".$from."'");
|
||||
}
|
||||
if ($to != 0) {
|
||||
$to = DateTime::createFromFormat('Y-m-d', $to);
|
||||
$to = $to->format('Y-m-d');
|
||||
$this->db->where("date(".$this->config->item('table_name').".COL_TIME_ON) <= '".$to."'");
|
||||
}
|
||||
|
||||
$this->db->where($this->config->item('table_name').'.COL_CONTEST_ID', $contest_id);
|
||||
|
||||
$this->db->order_by($this->config->item('table_name').".COL_TIME_ON", "ASC");
|
||||
|
||||
$this->db->join('station_profile', 'station_profile.station_id = '.$this->config->item('table_name').'.station_id');
|
||||
|
||||
return $this->db->get();
|
||||
}
|
||||
|
||||
function get_logged_contests2() {
|
||||
$CI =& get_instance();
|
||||
$CI->load->model('Stations');
|
||||
$station_id = $CI->Stations->find_active();
|
||||
|
||||
$sql = "select col_contest_id, min(date(col_time_on)) mindate, max(date(col_time_on)) maxdate, year(col_time_on) year, month(col_time_on) month
|
||||
from logbook l
|
||||
where coalesce(COL_CONTEST_ID, '') <> ''
|
||||
and station_id =" . $station_id;
|
||||
|
||||
$sql .= " group by COL_CONTEST_ID , year(col_time_on), month(col_time_on) order by year(col_time_on) desc";
|
||||
|
||||
$data = $this->db->query($sql);
|
||||
|
||||
return ($data->result());
|
||||
}
|
||||
|
||||
function get_logged_years() {
|
||||
$CI =& get_instance();
|
||||
$CI->load->model('Stations');
|
||||
$station_id = $CI->Stations->find_active();
|
||||
|
||||
$sql = "select distinct year(col_time_on) year
|
||||
from logbook l
|
||||
where coalesce(COL_CONTEST_ID, '') <> ''
|
||||
and station_id =" . $station_id;
|
||||
|
||||
$sql .= " order by year(col_time_on) desc";
|
||||
|
||||
$data = $this->db->query($sql);
|
||||
|
||||
return ($data->result());
|
||||
}
|
||||
|
||||
function get_logged_contests($year) {
|
||||
$year = $this->security->xss_clean($year);
|
||||
|
||||
$CI =& get_instance();
|
||||
$CI->load->model('Stations');
|
||||
$station_id = $CI->Stations->find_active();
|
||||
|
||||
$sql = "select distinct col_contest_id
|
||||
from logbook l
|
||||
where coalesce(COL_CONTEST_ID, '') <> ''
|
||||
and station_id =" . $station_id .
|
||||
" and year(col_time_on) ='" . $year . "'";
|
||||
|
||||
$sql .= " order by COL_CONTEST_ID asc";
|
||||
|
||||
$data = $this->db->query($sql);
|
||||
|
||||
return $data->result();
|
||||
}
|
||||
|
||||
function get_contest_dates($year, $contestid) {
|
||||
$year = $this->security->xss_clean($year);
|
||||
$contestid = $this->security->xss_clean($contestid);
|
||||
|
||||
$CI =& get_instance();
|
||||
$CI->load->model('Stations');
|
||||
$station_id = $CI->Stations->find_active();
|
||||
|
||||
$sql = "select min(date(col_time_on)) mindate, max(date(col_time_on)) maxdate
|
||||
from logbook l
|
||||
where coalesce(COL_CONTEST_ID, '') <> ''
|
||||
and station_id =" . $station_id .
|
||||
" and year(col_time_on) ='" . $year . "' and col_contest_id ='" . $contestid . "'";
|
||||
|
||||
$data = $this->db->query($sql);
|
||||
|
||||
return $data->result();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
header('Content-Type: text/plain; charset=utf-8');
|
||||
header('Content-Disposition: attachment; filename="'.$this->session->userdata('user_callsign').'-'.date('dmY-Hi').'.log"');
|
||||
|
||||
$CI =& get_instance();
|
||||
$CI->load->library('Cabrilloformat');
|
||||
|
||||
echo $CI->cabrilloformat->header($contest_id, $callsign, $claimed_score, $operators, $club, $name, $address1, $address2, $address3, $soapbox);
|
||||
foreach ($qsos->result() as $row) {
|
||||
echo $CI->cabrilloformat->qso($row);
|
||||
}
|
||||
echo $CI->cabrilloformat->footer();
|
|
@ -0,0 +1,41 @@
|
|||
<div class="container">
|
||||
|
||||
<br>
|
||||
|
||||
<h2><?php echo $page_title; ?></h2>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
Export a contest to a Cabrillo log
|
||||
</div>
|
||||
<div class="card-body">
|
||||
|
||||
<?php
|
||||
echo '<div class="contests">';
|
||||
if ($contestyears) { ?>
|
||||
|
||||
<form class="form" action="<?php echo site_url('cabrillo/export'); ?>" method="post" enctype="multipart/form-data">
|
||||
<div class="form-group form-inline row">
|
||||
<div class="col-md-2 control-label" for="year">Select year: </div>
|
||||
<select id="year" class="custom-select my-1 mr-sm-2 col-md-2" name="year">
|
||||
<?php foreach ($contestyears as $row) { ?>
|
||||
<option value="<?php echo $row->year; ?>"><?php echo $row->year;?></option>
|
||||
<?php } ?>
|
||||
</select>
|
||||
<button id="button1id" type="button" onclick="loadContests();" name="button1id" class="btn btn-sm btn-primary"> Proceed</button>
|
||||
</div>
|
||||
<div class="form-group form-inline row contestname">
|
||||
</div>
|
||||
<div class="form-group form-inline row contestdates">
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<?php }
|
||||
else {
|
||||
echo 'No contests were found in your log.';
|
||||
}
|
||||
?>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
|
@ -230,6 +230,8 @@
|
|||
|
||||
<a class="dropdown-item" href="<?php echo site_url('csv');?>" title="SOTA CSV Export"><i class="fas fa-sync"></i> SOTA CSV Export</a>
|
||||
|
||||
<a class="dropdown-item" href="<?php echo site_url('cabrillo');?>" title="Cabrillo Export"><i class="fas fa-sync"></i> Cabrillo Export</a>
|
||||
|
||||
<div class="dropdown-divider"></div>
|
||||
|
||||
<?php
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
function loadContests() {
|
||||
$(".stationinfo").empty();
|
||||
$(".searchinfo").empty();
|
||||
$.ajax({
|
||||
url: base_url+'index.php/cabrillo/getContests',
|
||||
type: 'post',
|
||||
data: {'year': $("#year").val()},
|
||||
success: function (data) {
|
||||
$(".contestname").append('<div class="col-md-2 control-label" for="contestid">Select contest: </div>' +
|
||||
'<select class="custom-select my-1 mr-sm-2 col-md-3" id="contestid" name="contestid">' +
|
||||
'</select>' +
|
||||
' <button onclick="loadContestDates();" class="btn btn-sm btn-primary" type="button">Proceed</button>');
|
||||
|
||||
$.each(data, function(key, value) {
|
||||
$('#contestid')
|
||||
.append($("<option></option>")
|
||||
.attr("value",value.col_contest_id)
|
||||
.text(value.col_contest_id));
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function loadContestDates() {
|
||||
$.ajax({
|
||||
url: base_url+'index.php/cabrillo/getContestDates',
|
||||
type: 'post',
|
||||
data: {'year': $("#year").val(),
|
||||
'contestid': $("#contestid").val()},
|
||||
success: function (data) {
|
||||
$(".contestdates").append('<div class="col-md-2 control-label" for="contestdates">Select daterange: </div>' +
|
||||
'<select class="custom-select my-1 mr-sm-2 col-md-3" id="contestdates" name="contestdates">' +
|
||||
'</select>' +
|
||||
' <button class="btn btn-sm btn-primary" type="submit">Export</button>');
|
||||
|
||||
$.each(data, function(key, value) {
|
||||
$('#contestdates')
|
||||
.append($("<option></option>")
|
||||
.attr("value", value.mindate + ',' + value.maxdate)
|
||||
.text(value.mindate + ' - ' + value.maxdate));
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
Ładowanie…
Reference in New Issue