From 13c66289b41246eb727339e782623ad9d6a110be Mon Sep 17 00:00:00 2001 From: AndreasK79 Date: Thu, 4 Jun 2020 21:56:32 +0200 Subject: [PATCH] Fixes for uploading modified QSOs to QRZ.com --- application/controllers/Qrz.php | 10 +++++++--- application/models/Logbook_model.php | 8 ++++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/application/controllers/Qrz.php b/application/controllers/Qrz.php index 52c2b9ad..dc8e2857 100644 --- a/application/controllers/Qrz.php +++ b/application/controllers/Qrz.php @@ -54,14 +54,19 @@ class Qrz extends CI_Controller { * Adif is build for each qso, and then uploaded, one at a time */ function mass_upload_qsos($station_id, $qrz_api_key) { - $i = 0; $data['qsos'] = $this->logbook_model->get_qrz_qsos($station_id); if ($data['qsos']) { foreach ($data['qsos'] as $qso) { $adif = $this->logbook_model->create_adif_from_data($qso); - $result = $this->logbook_model->push_qso_to_qrz($qrz_api_key, $adif); + + if ($qso['COL_QRZCOM_QSO_UPLOAD_STATUS'] == 'M') { + $result = $this->logbook_model->push_qso_to_qrz($qrz_api_key, $adif, true); + } else { + $result = $this->logbook_model->push_qso_to_qrz($qrz_api_key, $adif); + } + if ($result) { $this->markqso($qso['COL_PRIMARY_KEY']); $i++; @@ -112,7 +117,6 @@ class Qrz extends CI_Controller { header('Content-type: application/json'); if ($i = $this->mass_upload_qsos($postData['station_id'], $qrz_api_key)) { - $stationinfo = $this->stations->stations_with_qrz_api_key(); $info = $stationinfo->result(); diff --git a/application/models/Logbook_model.php b/application/models/Logbook_model.php index 438dffae..9071d712 100755 --- a/application/models/Logbook_model.php +++ b/application/models/Logbook_model.php @@ -360,13 +360,17 @@ class Logbook_model extends CI_Model { * Function uploads a QSO to QRZ with the API given. * $adif contains a line with the QSO in the ADIF format. QSO ends with an */ - function push_qso_to_qrz($apikey, $adif) { + function push_qso_to_qrz($apikey, $adif, $replaceoption = false) { $url = 'http://logbook.qrz.com/api'; // TODO: Move this to database $post_data['KEY'] = $apikey; $post_data['ACTION'] = 'INSERT'; $post_data['ADIF'] = $adif; + if ($replaceoption) { + $post_data['OPTION'] = 'REPLACE'; + } + $ch = curl_init( $url ); curl_setopt( $ch, CURLOPT_POST, true); curl_setopt( $ch, CURLOPT_POSTFIELDS, $post_data); @@ -376,7 +380,7 @@ class Logbook_model extends CI_Model { $content = curl_exec($ch); if ($content){ - if (stristr($content,'RESULT=OK')) { + if (stristr($content,'RESULT=OK') || stristr($content,'RESULT=REPLACE')) { return true; } else {