From 197eceeb790de7d3efb75a48d613f2eddc150728 Mon Sep 17 00:00:00 2001 From: Andreas <6977712+AndreasK79@users.noreply.github.com> Date: Thu, 25 Nov 2021 20:18:44 +0100 Subject: [PATCH 1/2] [QRZ Logbook] V2 fix for user_id --- application/controllers/Qrz.php | 2 +- application/models/Logbook_model.php | 9 +++++++-- application/models/Stations.php | 3 ++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/application/controllers/Qrz.php b/application/controllers/Qrz.php index c663d6ff..2c036967 100644 --- a/application/controllers/Qrz.php +++ b/application/controllers/Qrz.php @@ -108,7 +108,7 @@ class Qrz extends CI_Controller { $data['page_title'] = "QRZ Logbook"; - $data['station_profiles'] = $this->stations->all(); + $data['station_profiles'] = $this->stations->all_of_user(); $data['station_profile'] = $this->stations->stations_with_qrz_api_key(); $this->load->view('interface_assets/header', $data); diff --git a/application/models/Logbook_model.php b/application/models/Logbook_model.php index 3879173e..46e53642 100755 --- a/application/models/Logbook_model.php +++ b/application/models/Logbook_model.php @@ -383,7 +383,7 @@ class Logbook_model extends CI_Model { */ function exists_qrz_api_key($station_id) { $sql = 'select qrzapikey, qrzrealtime from station_profile - where station_id = ' . $station_id; + where station_id = ' . $station_id . ' and station_profile.user_id = ' . $this->session->userdata('user_id'); $query = $this->db->query($sql); @@ -444,6 +444,10 @@ class Logbook_model extends CI_Model { * $primarykey is the unique id for that QSO in the logbook */ function mark_qrz_qsos_sent($primarykey) { + if (!$this->check_qso_is_accessible($primarykey)) { + return; + } + $data = array( 'COL_QRZCOM_QSO_UPLOAD_DATE' => date("Y-m-d H:i:s", strtotime("now")), 'COL_QRZCOM_QSO_UPLOAD_STATUS' => 'Y', @@ -913,7 +917,8 @@ class Logbook_model extends CI_Model { ' and (COL_QRZCOM_QSO_UPLOAD_STATUS is NULL or COL_QRZCOM_QSO_UPLOAD_STATUS = "" or COL_QRZCOM_QSO_UPLOAD_STATUS = "M" - or COL_QRZCOM_QSO_UPLOAD_STATUS = "N")'; + or COL_QRZCOM_QSO_UPLOAD_STATUS = "N") + and station_profile.user_id = ' . $this->session->userdata('user_id'); $query = $this->db->query($sql); return $query; diff --git a/application/models/Stations.php b/application/models/Stations.php index c4db7311..e6ba15af 100644 --- a/application/models/Stations.php +++ b/application/models/Stations.php @@ -269,7 +269,8 @@ class Stations extends CI_Model { " where COL_QRZCOM_QSO_UPLOAD_STATUS = 'Y' group by station_id ) as totc on station_profile.station_id = totc.station_id - where coalesce(station_profile.qrzapikey, '') <> ''"; + where coalesce(station_profile.qrzapikey, '') <> '' + and station_profile.user_id = " . $this->session->userdata('user_id'); $query = $this->db->query($sql); return $query; From 4ac4f612cb904789c19a3b821e840272dbfb1096 Mon Sep 17 00:00:00 2001 From: Andreas <6977712+AndreasK79@users.noreply.github.com> Date: Thu, 25 Nov 2021 20:43:31 +0100 Subject: [PATCH 2/2] [QRZ Logbook] Had to revert a few changes. Can't check user_id everywhere, since that will break cron --- application/controllers/Qrz.php | 7 +++---- application/models/Logbook_model.php | 11 +++-------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/application/controllers/Qrz.php b/application/controllers/Qrz.php index 2c036967..13d35421 100644 --- a/application/controllers/Qrz.php +++ b/application/controllers/Qrz.php @@ -24,10 +24,9 @@ class Qrz extends CI_Controller { $station_ids = $this->logbook_model->get_station_id_with_qrz_api(); if ($station_ids) { - foreach ($station_ids as $station_id) { - $result = $this->logbook_model->exists_qrz_api_key($station_id); - $qrz_api_key = $result->qrzapikey; - if($this->mass_upload_qsos($station_id, $qrz_api_key)) { + foreach ($station_ids as $station) { + $qrz_api_key = $station->qrzapikey; + if($this->mass_upload_qsos($station->station_id, $qrz_api_key)) { echo "QSOs have been uploaded to QRZ.com."; log_message('info', 'QSOs have been uploaded to QRZ.com.'); } else{ diff --git a/application/models/Logbook_model.php b/application/models/Logbook_model.php index 46e53642..4adec590 100755 --- a/application/models/Logbook_model.php +++ b/application/models/Logbook_model.php @@ -444,10 +444,6 @@ class Logbook_model extends CI_Model { * $primarykey is the unique id for that QSO in the logbook */ function mark_qrz_qsos_sent($primarykey) { - if (!$this->check_qso_is_accessible($primarykey)) { - return; - } - $data = array( 'COL_QRZCOM_QSO_UPLOAD_DATE' => date("Y-m-d H:i:s", strtotime("now")), 'COL_QRZCOM_QSO_UPLOAD_STATUS' => 'Y', @@ -917,8 +913,7 @@ class Logbook_model extends CI_Model { ' and (COL_QRZCOM_QSO_UPLOAD_STATUS is NULL or COL_QRZCOM_QSO_UPLOAD_STATUS = "" or COL_QRZCOM_QSO_UPLOAD_STATUS = "M" - or COL_QRZCOM_QSO_UPLOAD_STATUS = "N") - and station_profile.user_id = ' . $this->session->userdata('user_id'); + or COL_QRZCOM_QSO_UPLOAD_STATUS = "N")'; $query = $this->db->query($sql); return $query; @@ -928,12 +923,12 @@ 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 from station_profile + $sql = 'select station_id, qrzapikey from station_profile where coalesce(qrzapikey, "") <> ""'; $query = $this->db->query($sql); - $result = $query->row(); + $result = $query->result(); if ($result) { return $result;