Merge branch 'dev' into cronmanager

This commit is contained in:
HB9HIL
2024-04-26 19:01:49 +02:00
committed by GitHub
7 changed files with 186 additions and 66 deletions

View File

@@ -224,8 +224,7 @@ class adif extends CI_Controller {
$this->adif_parser->initialize();
$custom_errors = "";
$alladif=[];
while($record = $this->adif_parser->get_record())
{
while($record = $this->adif_parser->get_record()) {
if ($contest != '') {
$record['contest_id']=$contest;
}

View File

@@ -160,7 +160,10 @@ class API extends CI_Controller {
*/
function qso($dryrun = false) {
header('Content-type: application/json');
set_time_limit(0);
ini_set('memory_limit', '-1');
session_write_close();
$this->load->model('api_model');
$this->load->model('stations');
@@ -169,7 +172,9 @@ class API extends CI_Controller {
$return_count = 0;
// Decode JSON and store
$obj = json_decode(file_get_contents("php://input"), true);
$raw = file_get_contents("php://input");
$obj = json_decode($raw,true);
$raw='';
if ($obj === NULL) {
echo json_encode(['status' => 'failed', 'reason' => "wrong JSON"]);
die();
@@ -182,6 +187,7 @@ class API extends CI_Controller {
}
$userid = $this->api_model->key_userid($obj['key']);
$this->api_model->update_last_used(($obj['key']));
if(!isset($obj['station_profile_id']) || $this->stations->check_station_against_user($obj['station_profile_id'], $userid) == false) {
http_response_code(401);
@@ -198,49 +204,32 @@ class API extends CI_Controller {
// Feed in the ADIF string
$this->adif_parser->feed($obj['string']);
// Create QSO Record
while($record = $this->adif_parser->get_record())
{
if(count($record) == 0)
{
break;
};
if( !($dryrun) && (isset($obj['station_profile_id']))) {
if(isset($record['station_callsign']) && $this->stations->check_station_against_callsign($obj['station_profile_id'], $record['station_callsign']) == false) {
http_response_code(401);
echo json_encode(['status' => 'failed', 'reason' => "station callsign does not match station callsign in station profile."]);
die();
}
$obj['string']='';
$return_msg=[];
$return_count=0;
if( !($dryrun) && (isset($obj['station_profile_id']))) {
$custom_errors = "";
$alladif=[];
gc_collect_cycles();
while($record = $this->adif_parser->get_record()) {
if(!(isset($record['call'])) || (trim($record['call']) == '')) {
http_response_code(401);
echo json_encode(['status' => 'failed', 'reason' => "QSO Call is empty."]);
die();
continue;
}
if(count($record) == 0) {
break;
};
array_push($alladif,$record);
$return_count++;
};
$record=''; // free memory
gc_collect_cycles();
$custom_errors = $this->logbook_model->import_bulk($alladif, $obj['station_profile_id'], false, false, false, false, false, false, true, false, true, false);
$alladif=[];
$return_msg[]='';
} else {
$return_msg[]='Dryrun works';
}
if ( ((!(isset($record['distance']))) || ($record['distance'] == '')) && ((isset($record['gridsquare'])) && ($record['gridsquare'] != '')) ) {
$mygrid=$this->stations->gridsquare_from_station($obj['station_profile_id']);
$this->load->library('Qra');
$record['distance'] = $this->qra->distance($mygrid, $record['gridsquare'], 'K');
}
$this->api_model->update_last_used(($obj['key']));
$msg = $this->logbook_model->import($record, $obj['station_profile_id'], NULL, NULL, NULL, NULL, NULL, NULL, false, false, true);
if ( $msg == "" ) {
$return_count++;
} else {
$return_msg[] = $msg;
}
} else {
$return_msg[]='Dryrun works';
}
};
http_response_code(201);
echo json_encode(['status' => 'created', 'type' => $obj['type'], 'string' => $obj['string'], 'imported_count' => $return_count, 'messages' => $return_msg ]);

View File

@@ -329,6 +329,31 @@ class Awards extends CI_Controller {
$this->load->view('interface_assets/footer', $footerData);
}
public function jcc_export() {
$this->load->model('Jcc_model');
$postdata['qsl'] = $this->security->xss_clean($this->input->post('qsl'));
$postdata['lotw'] = $this->security->xss_clean($this->input->post('lotw'));
$postdata['eqsl'] = $this->security->xss_clean($this->input->post('eqsl'));
$postdata['qrz'] = $this->security->xss_clean($this->input->post('qrz'));
$postdata['worked'] = $this->security->xss_clean($this->input->post('worked'));
$postdata['confirmed'] = $this->security->xss_clean($this->input->post('confirmed'));
$postdata['notworked'] = $this->security->xss_clean($this->input->post('notworked'));
$postdata['band'] = $this->security->xss_clean($this->input->post('band'));
$postdata['mode'] = $this->security->xss_clean($this->input->post('mode'));
$qsos = $this->Jcc_model->exportJcc($postdata);
$fp = fopen( 'php://output', 'w' );
$i=1;
fputcsv($fp, array('No', 'Callsign', 'Date', 'Band', 'Mode', 'Remarks'), ';');
foreach ($qsos as $qso) {
fputcsv($fp, array($i, $qso['call'], $qso['date'], ($qso['prop_mode'] != null ? $qso['band'].' / '.$qso['prop_mode'] : $qso['band']), $qso['mode'], $qso['cnty'].' - '.$qso['jcc']), ';');
$i++;
}
fclose($fp);
return;
}
public function vucc() {
$this->load->model('vucc');
$this->load->model('bands');

View File

@@ -825,9 +825,8 @@ class Jcc_model extends CI_Model {
);
function get_jcc_array($bands, $postdata) {
$CI =& get_instance();
$CI->load->model('logbooks_model');
$logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook'));
$this->load->model('logbooks_model');
$logbooks_locations_array = $this->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook'));
if (!$logbooks_locations_array) {
return null;
@@ -1020,9 +1019,8 @@ class Jcc_model extends CI_Model {
*/
function get_jcc_summary($bands, $postdata)
{
$CI =& get_instance();
$CI->load->model('logbooks_model');
$logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook'));
$this->load->model('logbooks_model');
$logbooks_locations_array = $this->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook'));
if (!$logbooks_locations_array) {
return null;
@@ -1131,5 +1129,59 @@ class Jcc_model extends CI_Model {
$sql .= " and COL_CNTY in (".implode(',', array_keys($this->jaCities)).")";
return $sql;
}
function exportJcc($postdata) {
$this->load->model('logbooks_model');
$logbooks_locations_array = $this->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook'));
if (!$logbooks_locations_array) {
return null;
}
$location_list = "'".implode("','",$logbooks_locations_array)."'";
$jccArray = array_keys($this->jaCities);
$sql = "SELECT distinct col_cnty FROM " . $this->config->item('table_name') . " thcv
where station_id in (" . $location_list . ")";
if ($postdata['mode'] != 'All') {
$sql .= " and (col_mode = '" . $postdata['mode'] . "' or col_submode = '" . $postdata['mode'] . "')";
}
$sql .= $this->addStateToQuery();
$sql .= $this->genfunctions->addBandToQuery($postdata['band']);
$sql .= $this->genfunctions->addQslToQuery($postdata);
$sql .= ' ORDER BY COL_CNTY ASC';
$query = $this->db->query($sql);
$jccs = array();
foreach($query->result() as $line) {
$jccs[] = $line->col_cnty;
}
$qsos = array();
foreach($jccs as $jcc) {
$qso = $this->getFirstQso($location_list, $jcc, $postdata);
$qsos[] = array('call' => $qso[0]->COL_CALL, 'date' => $qso[0]->COL_TIME_ON, 'band' => $qso[0]->COL_BAND, 'mode' => $qso[0]->COL_MODE, 'prop_mode' => $qso[0]->COL_PROP_MODE, 'cnty' => $qso[0]->COL_CNTY, 'jcc' => $this->jaCities[$qso[0]->COL_CNTY]);
}
return $qsos;
}
function getFirstQso($location_list, $jcc, $postdata) {
$sql = 'SELECT COL_CNTY, COL_CALL, COL_TIME_ON, COL_BAND, COL_MODE, COL_PROP_MODE FROM '.$this->config->item('table_name').' t1
WHERE station_id in ('.$location_list.')';
if ($postdata['mode'] != 'All') {
$sql .= " and (col_mode = '" . $postdata['mode'] . "' or col_submode = '" . $postdata['mode'] . "')";
}
$sql .= $this->addStateToQuery();
$sql .= $this->genfunctions->addBandToQuery($postdata['band']);
$sql .= $this->genfunctions->addQslToQuery($postdata);
$sql .= ' AND COL_CNTY = \''.$jcc.'\'';
$sql .= ' ORDER BY COL_TIME_ON ASC LIMIT 1';
$query = $this->db->query($sql);
return $query->result();
}
}
?>

View File

@@ -3344,22 +3344,24 @@ function lotw_last_qsl_date($user_id) {
return '1900-01-01 00:00:00.000';
}
function import_bulk($records, $station_id = "0", $skipDuplicate = false, $markClublog = false, $markLotw = false, $dxccAdif = false, $markQrz = false, $markHrd = false,$skipexport = false, $operatorName = false, $apicall = false, $skipStationCheck = false) {
$custom_errors='';
$a_qsos=[];
foreach ($records as $record) {
$one_error = $this->logbook_model->import($record, $station_id, $skipDuplicate, $markClublog, $markLotw,$dxccAdif, $markQrz, $markHrd, $skipexport, $operatorName, $apicall, $skipStationCheck, true);
if ($one_error['error'] ?? '' != '') {
$custom_errors.=$one_error['error']."<br/>";
} else {
array_push($a_qsos,$one_error['raw_qso'] ?? '');
}
}
if (count($a_qsos)>0) {
$this->db->insert_batch($this->config->item('table_name'), $a_qsos);
}
return $custom_errors;
}
function import_bulk($records, $station_id = "0", $skipDuplicate = false, $markClublog = false, $markLotw = false, $dxccAdif = false, $markQrz = false, $markHrd = false,$skipexport = false, $operatorName = false, $apicall = false, $skipStationCheck = false) {
$custom_errors='';
$a_qsos=[];
foreach ($records as $record) {
$one_error = $this->logbook_model->import($record, $station_id, $skipDuplicate, $markClublog, $markLotw,$dxccAdif, $markQrz, $markHrd, $skipexport, $operatorName, $apicall, $skipStationCheck, true);
if ($one_error['error'] ?? '' != '') {
$custom_errors.=$one_error['error']."<br/>";
} else {
array_push($a_qsos,$one_error['raw_qso'] ?? '');
}
}
$records='';
gc_collect_cycles();
if (count($a_qsos)>0) {
$this->db->insert_batch($this->config->item('table_name'), $a_qsos);
}
return $custom_errors;
}
/*
* $skipDuplicate - used in ADIF import to skip duplicate checking when importing QSOs
* $markLoTW - used in ADIF import to mark QSOs as exported to LoTW when importing QSOs
@@ -4004,6 +4006,8 @@ function lotw_last_qsl_date($user_id) {
if ($batchmode) {
$raw_qso=$this->add_qso($data, $skipexport, $batchmode);
$returner['raw_qso']=$raw_qso;
$data='';
$raw_qso='';
} else {
$this->add_qso($data, $skipexport);
}
@@ -4016,6 +4020,7 @@ function lotw_last_qsl_date($user_id) {
} else {
$returner=$my_error;
}
$record=[];
return $returner;
}

View File

@@ -98,6 +98,7 @@
<div class="col-md-10">
<button id="button2id" type="reset" name="button2id" class="btn btn-sm btn-warning">Reset</button>
<button id="button1id" type="submit" name="button1id" class="btn btn-sm btn-primary">Show</button>
<button id="button3id" type="button" onclick="export_qsos();" name="button3id" class="btn btn-sm btn-info">Export</button>
</div>
</div>

View File

@@ -15,4 +15,53 @@ $(document).ready(function () {
'csv'
]
});
});
});
function export_qsos() {
$.ajax({
url: base_url + 'index.php/awards/jcc_export',
type: 'post',
xhrFields: {
responseType: 'text/csv;charset=utf8',
},
data: {
band: $('#band2').val(),
mode: $('#mode').val(),
worked: +$('#worked').prop('checked'),
confirmed: +$('#confirmed').prop('checked'),
notworked: +$('#notworked').prop('checked'),
qsl: +$('#qsl').prop('checked'),
lotw: +$('#lotw').prop('checked'),
qrz: +$('#qrz').prop('checked'),
eqsl: +$('#eqsl').prop('checked'),
includedeleted: +$('#includedeleted').prop('checked'),
Africa: +$('#Africa').prop('checked'),
Asia: +$('#Asia').prop('checked'),
Europe: +$('#Europe').prop('checked'),
NorthAmerica: +$('#NorthAmerica').prop('checked'),
SouthAmerica: +$('#SouthAmerica').prop('checked'),
Oceania: +$('#Oceania').prop('checked'),
Antarctica: +$('#Antarctica').prop('checked'),
sat: $("#sats").val(),
orbit: $("#orbits").val(),
},
success: function(data) {
var a = document.createElement('a');
var fileData = ['\ufeff'+data];
console.log(fileData);
var blob = new Blob(fileData,{
type: "text/csv;charset=utf-8;"
});
var url = URL.createObjectURL(blob);
a.href = url;
a.download = 'qso_export.csv';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
},
error: function() {
console.log("error");
},
});
}