From 2afa5697c6ebc8dcd6e5613d2af5e4d13a79bb63 Mon Sep 17 00:00:00 2001 From: Peter Goodhall Date: Mon, 17 Jun 2019 15:10:43 +0100 Subject: [PATCH] Added function to API to allow adding a QSO by sending ADIF --- application/controllers/Api.php | 43 +++++++++++++++++++++++++++++++++ application/controllers/Qso.php | 1 - 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/application/controllers/Api.php b/application/controllers/Api.php index 8d71329a..c04ef585 100644 --- a/application/controllers/Api.php +++ b/application/controllers/Api.php @@ -336,6 +336,49 @@ class API extends CI_Controller { return $arguments; } + + function qso() { + header('Content-type: application/json'); + + $this->load->model('api_model'); + + // Decode JSON and store + $obj = json_decode(file_get_contents("php://input"), true); + + if(!isset($obj['key']) || $this->api_model->authorize($obj['key']) == 0) { + echo json_encode(['status' => 'failed', 'reason' => "missing api key"]); + die(); + } + + if($obj['type'] == "adif" && $obj['string'] != "") { + // Load the logbook model for adding QSO records + $this->load->model('logbook_model'); + + // Load ADIF Parser + $this->load->library('adif_parser'); + + // 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; + }; + + $this->logbook_model->import($record); + + }; + + echo json_encode(['status' => 'success', 'type' => $obj['type'], 'string' => $obj['string']]); + + } + + } + + /* ENDPOINT for Rig Control */ function radio() { diff --git a/application/controllers/Qso.php b/application/controllers/Qso.php index 5cad61ac..84dd207d 100755 --- a/application/controllers/Qso.php +++ b/application/controllers/Qso.php @@ -1,7 +1,6 @@