Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
Weblate
2024-07-31 04:20:17 +00:00
5 changed files with 129 additions and 2 deletions

View File

@@ -237,6 +237,106 @@ class API extends CI_Controller {
}
/*
*
* Function: get_contacts_adif
* Task: allows third party software to pull ADIF QSO data from wavelog after a baseline of the last fetched QSO id
*/
function get_contacts_adif() {
//set header
header('Content-type: application/json');
//load API model
$this->load->model('api_model');
// Decode JSON and store
$obj = json_decode(file_get_contents("php://input"), true);
if ($obj === NULL) {
http_response_code(400);
echo json_encode(['status' => 'failed', 'reason' => "wrong JSON"]);
return;
}
//do authorization
if(!isset($obj['key']) || $this->api_model->authorize($obj['key']) == 0) {
http_response_code(401);
echo json_encode(['status' => 'failed', 'reason' => "missing api key"]);
return;
}
//check for relevant fields in JSON input
if(!isset($obj['station_id']) or !isset($obj['fetchfromid']))
{
http_response_code(400);
echo json_encode(['status' => 'failed', 'reason' => "Not all required fields were present in input JSON"]);
return;
}
//extract relevant data to variables
$key = $obj['key'];
$station_id = $obj['station_id'];
$fetchfromid = $obj['fetchfromid'];
//check if goalpost is numeric as an additional layer of SQL injection prevention
if(!is_numeric($fetchfromid))
{
http_response_code(400);
echo json_encode(['status' => 'failed', 'reason' => "Invalid fetchfromid."]);
return;
}
//make sure the goalpost is an integer
$fetchfromid = (int)$fetchfromid;
//load stations API
$this->load->model('stations');
//get all stations of user to check if station_id should be readable
$userid = $this->api_model->key_userid($key);
$station_ids = array();
$stations=$this->stations->all_of_user($userid);
//extract to array
foreach ($stations->result() as $row) {
array_push($station_ids, $row->station_id);
}
//return error if station not accessible for the API key
if(!in_array($station_id, $station_ids))
{
http_response_code(401);
echo json_encode(['status' => 'failed', 'reason' => "Station ID not accessible for this API key"]);
return;
}
//load adif data module
$this->load->model('adif_data');
$data['qsos'] = $this->adif_data->export_past_id($station_id, $fetchfromid);
$qso_count = count($data['qsos']->result());
//if no new QSOs are ready, return that
if($qso_count <= 0)
{
http_response_code(200);
echo json_encode(['status' => 'successfull', 'message' => 'No new QSOs available.', 'lastfetchedid' => $fetchfromid, 'exported_qsos' => 0, 'adif' => null]);
}
//convert data to ADIF
$adif_content = $this->load->view('adif/data/exportapi', $data, TRUE);
//get new goalpost
$lastfetchedid = 0;
foreach ($data['qsos']->result() as $row) {
$lastfetchedid = max($lastfetchedid, $row->COL_PRIMARY_KEY);
}
//return API result
http_response_code(200);
echo json_encode(['status' => 'successfull', 'message' => 'Export successfull', 'lastfetchedid' => $lastfetchedid, 'exported_qsos' => $qso_count, 'adif' => $adif_content]);
}
// API function to check if a callsign is in the logbook already
function logbook_check_callsign() {
header('Content-type: application/json');

View File

@@ -137,6 +137,20 @@ class adif_data extends CI_Model {
return $this->db->get();
}
function export_past_id($station_id, $fetchfromid) {
//create query
$this->db->select(''.$this->config->item('table_name').'.*, station_profile.*, dxcc_entities.name as station_country');
$this->db->from($this->config->item('table_name'));
$this->db->where($this->config->item('table_name').'.station_id', $station_id);
$this->db->where($this->config->item('table_name').".COL_PRIMARY_KEY > " , $fetchfromid); //only get values past the fetchfromid value
$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');
$this->db->join('dxcc_entities', 'station_profile.station_dxcc = dxcc_entities.adif', 'left outer');
//return result
return $this->db->get();
}
function export_lotw() {
$this->load->model('stations');
$active_station_id = $this->stations->find_active();

View File

@@ -0,0 +1,13 @@
Wavelog ADIF export
<ADIF_VER:5>3.1.4
<PROGRAMID:<?php echo strlen($this->config->item('app_name')); ?>><?php echo $this->config->item('app_name')."\r\n"; ?>
<PROGRAMVERSION:<?php echo strlen($this->optionslib->get_option('version')); ?>><?php echo $this->optionslib->get_option('version')."\r\n"; ?>
<EOH>
<?php
$CI =& get_instance();
$CI->load->library('AdifHelper');
foreach ($qsos->result() as $qso) {
echo $CI->adifhelper->getAdifLine($qso);
}

View File

@@ -6,7 +6,7 @@
msgid ""
msgstr ""
"Report-Msgid-Bugs-To: translations@wavelog.org\n"
"POT-Creation-Date: 2024-07-30 21:59+0000\n"
"POT-Creation-Date: 2024-07-31 04:20+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"

View File

@@ -6,7 +6,7 @@
msgid ""
msgstr ""
"Report-Msgid-Bugs-To: translations@wavelog.org\n"
"POT-Creation-Date: 2024-07-30 21:59+0000\n"
"POT-Creation-Date: 2024-07-31 04:20+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"