From bac7683a1a97eb99c17ce2cdba32b58ca0a5a12f Mon Sep 17 00:00:00 2001 From: int2001 Date: Tue, 30 Apr 2024 14:02:51 +0000 Subject: [PATCH] Autodisable QRZ-Upload if AUTH-Error // Logic-part --- application/controllers/Qrz.php | 49 ++++++++++++++++------------ application/models/Logbook_model.php | 2 +- 2 files changed, 29 insertions(+), 22 deletions(-) diff --git a/application/controllers/Qrz.php b/application/controllers/Qrz.php index a4507bdd9..cebf21192 100644 --- a/application/controllers/Qrz.php +++ b/application/controllers/Qrz.php @@ -36,12 +36,14 @@ class Qrz extends CI_Controller { if ($station_ids) { foreach ($station_ids as $station) { $qrz_api_key = $station->qrzapikey; - if($this->mass_upload_qsos($station->station_id, $qrz_api_key, true)) { - echo "QSOs have been uploaded to QRZ.com."; - log_message('info', 'QSOs have been uploaded to QRZ.com.'); - } else{ - echo "No QSOs found for upload."; - log_message('info', 'No QSOs found for upload.'); + if ($station->qrzrealtime>=0) { + if($this->mass_upload_qsos($station->station_id, $qrz_api_key, true)) { + echo "QSOs have been uploaded to QRZ.com. for station_id ".$station->station_id; + } else{ + echo "No QSOs found for upload and station_id ".$station->station_id; + } + } else { + echo "Station ".$station->station_id." disabled for upload to QRZ.com."; } } } else { @@ -84,11 +86,10 @@ class Qrz extends CI_Controller { $i++; $result['status'] = 'OK'; } elseif ( ($result['status']=='error') && (substr($result['message'],0,11) == 'STATUS=AUTH')) { - log_message('error', 'QRZ upload failed for qso: Call: ' . $qso->COL_CALL . ' Band: ' . $qso->COL_BAND . ' Mode: ' . $qso->COL_MODE . ' Time: ' . $qso->COL_TIME_ON); - log_message('error', 'QRZ upload failed with the following message: ' .$result['message']); - log_message('error', 'QRZ upload stopped for Station_ID: ' .$station_id); + log_message('error', 'QRZ upload failed for qso for Station_ID '.$station_id.' // Call: ' . $qso->COL_CALL . ' Band: ' . $qso->COL_BAND . ' Mode: ' . $qso->COL_MODE . ' Time: ' . $qso->COL_TIME_ON . ' // Message: '.$result['message']); $errormessages[] = $result['message'] . ' Call: ' . $qso->COL_CALL . ' Band: ' . $qso->COL_BAND . ' Mode: ' . $qso->COL_MODE . ' Time: ' . $qso->COL_TIME_ON; $result['status'] = 'Error'; + /* 'Update station_profile set qrz_realtime=-1 where station_id=?',$station_id) break; /* If key is invalid, immediate stop syncing for more QSOs of this station */ } else { log_message('error', 'QRZ upload failed for qso: Call: ' . $qso->COL_CALL . ' Band: ' . $qso->COL_BAND . ' Mode: ' . $qso->COL_MODE . ' Time: ' . $qso->COL_TIME_ON); @@ -148,21 +149,27 @@ class Qrz extends CI_Controller { $this->load->model('logbook_model'); $result = $this->logbook_model->exists_qrz_api_key($postData['station_id']); $qrz_api_key = $result->qrzapikey; + $qrz_enabled = $result->qrzrealtime; header('Content-type: application/json'); - $result = $this->mass_upload_qsos($postData['station_id'], $qrz_api_key); - if ($result['status'] == 'OK') { - $stationinfo = $this->stations->stations_with_qrz_api_key(); - $info = $stationinfo->result(); + if ($qrz_enabled>=0) { + $result = $this->mass_upload_qsos($postData['station_id'], $qrz_api_key); + if ($result['status'] == 'OK') { + $stationinfo = $this->stations->stations_with_qrz_api_key(); + $info = $stationinfo->result(); - $data['status'] = 'OK'; - $data['info'] = $info; - $data['infomessage'] = $result['count'] . " QSOs are now uploaded to QRZ.com"; - $data['errormessages'] = $result['errormessages']; - echo json_encode($data); + $data['status'] = 'OK'; + $data['info'] = $info; + $data['infomessage'] = $result['count'] . " QSOs are now uploaded to QRZ.com"; + $data['errormessages'] = $result['errormessages']; + echo json_encode($data); + } else { + $data['status'] = 'Error'; + $data['info'] = 'Error: No QSOs found to upload.'; + $data['errormessages'] = $result['errormessages']; + echo json_encode($data); + } } else { - $data['status'] = 'Error'; - $data['info'] = 'Error: No QSOs found to upload.'; - $data['errormessages'] = $result['errormessages']; + $data['status']='QRZ Disabled for station'.$this->security->xss_clean($postData['station_id']); echo json_encode($data); } } diff --git a/application/models/Logbook_model.php b/application/models/Logbook_model.php index 55f544e58..6f55eeb89 100755 --- a/application/models/Logbook_model.php +++ b/application/models/Logbook_model.php @@ -1875,7 +1875,7 @@ class Logbook_model extends CI_Model { * Function returns all the station_id's with QRZ API Key's */ function get_station_id_with_qrz_api() { - $sql = 'select station_id, qrzapikey from station_profile + $sql = 'select station_id, qrzapikey, qrzrealtime from station_profile where coalesce(qrzapikey, "") <> ""'; $query = $this->db->query($sql);