From fc793a11603874e1574199fc9bcbf754e6ddcc33 Mon Sep 17 00:00:00 2001 From: HB9HIL Date: Fri, 15 Dec 2023 23:04:34 +0100 Subject: [PATCH] added hrdlog_username --- application/config/migration.php | 2 +- application/controllers/Hrdlog.php | 14 ++++++---- .../migrations/162_hrdlog_username.php | 28 +++++++++++++++++++ application/models/Logbook_model.php | 28 ++++++++++--------- application/models/Stations.php | 2 ++ application/views/station_profile/create.php | 9 ++++-- application/views/station_profile/edit.php | 5 ++++ 7 files changed, 66 insertions(+), 22 deletions(-) create mode 100644 application/migrations/162_hrdlog_username.php diff --git a/application/config/migration.php b/application/config/migration.php index f18b8cfe..ed1cc07a 100644 --- a/application/config/migration.php +++ b/application/config/migration.php @@ -22,7 +22,7 @@ $config['migration_enabled'] = TRUE; | */ -$config['migration_version'] = 161; +$config['migration_version'] = 162; /* |-------------------------------------------------------------------------- diff --git a/application/controllers/Hrdlog.php b/application/controllers/Hrdlog.php index eca9ef47..78e449ad 100644 --- a/application/controllers/Hrdlog.php +++ b/application/controllers/Hrdlog.php @@ -20,8 +20,9 @@ class Hrdlog extends CI_Controller { if ($station_ids) { foreach ($station_ids as $station) { + $hrdlog_username = $station->hrdlog_username; $hrdlog_code = $station->hrdlog_code; - if($this->mass_upload_qsos($station->station_id, $hrdlog_code)) { + if($this->mass_upload_qsos($station->station_id, $hrdlog_username, $hrdlog_code)) { echo "QSOs have been uploaded to hrdlog.net."; log_message('info', 'QSOs have been uploaded to hrdlog.net.'); } else{ @@ -48,7 +49,7 @@ class Hrdlog extends CI_Controller { * Function gets all QSOs from given station_id, that are not previously uploaded to hrdlog. * Adif is build for each qso, and then uploaded, one at a time */ - function mass_upload_qsos($station_id, $hrdlog_code) { + function mass_upload_qsos($station_id, $hrdlog_username, $hrdlog_code) { $i = 0; $data['qsos'] = $this->logbook_model->get_hrdlog_qsos($station_id); $errormessages=array(); @@ -61,9 +62,9 @@ class Hrdlog extends CI_Controller { $adif = $CI->adifhelper->getAdifLine($qso); if ($qso->COL_HRDLOG_QSO_UPLOAD_STATUS == 'M') { - $result = $this->logbook_model->push_qso_to_hrdlog($hrdlog_code, $qso->COL_STATION_CALLSIGN,$adif, true); + $result = $this->logbook_model->push_qso_to_hrdlog($hrdlog_username, $hrdlog_code, $adif, true); } else { - $result = $this->logbook_model->push_qso_to_hrdlog($hrdlog_code, $qso->COL_STATION_CALLSIGN,$adif); + $result = $this->logbook_model->push_qso_to_hrdlog($hrdlog_username, $hrdlog_code, $adif); } if ( ($result['status'] == 'OK') || ( ($result['status'] == 'error') || ($result['status'] == 'duplicate')) ){ @@ -126,10 +127,11 @@ class Hrdlog extends CI_Controller { $postData = $this->input->post(); $this->load->model('logbook_model'); - $result = $this->logbook_model->exists_hrdlog_code($postData['station_id']); + $result = $this->logbook_model->exists_hrdlog_credentials($postData['station_id']); + $hrdlog_username = $result->hrdlog_username; $hrdlog_code = $result->hrdlog_code; header('Content-type: application/json'); - $result = $this->mass_upload_qsos($postData['station_id'], $hrdlog_code); + $result = $this->mass_upload_qsos($postData['station_id'], $hrdlog_username, $hrdlog_code); if ($result['status'] == 'OK') { $stationinfo = $this->stations->stations_with_hrdlog_code(); $info = $stationinfo->result(); diff --git a/application/migrations/162_hrdlog_username.php b/application/migrations/162_hrdlog_username.php new file mode 100644 index 00000000..bdfab65c --- /dev/null +++ b/application/migrations/162_hrdlog_username.php @@ -0,0 +1,28 @@ +db->field_exists('hrdlog_username', 'station_profile')) { + $fields = array( + 'hrdlog_username VARCHAR(20) DEFAULT NULL AFTER hrdlog_code', + ); + $this->dbforge->add_column('station_profile', $fields); + } + } + + public function down() + { + if ($this->db->field_exists('hrdlog_username', 'station_profile')) { + $this->dbforge->drop_column('station_profile', 'hrdlog_username'); + } + } +} \ No newline at end of file diff --git a/application/models/Logbook_model.php b/application/models/Logbook_model.php index 5ea0f871..0df5ed62 100755 --- a/application/models/Logbook_model.php +++ b/application/models/Logbook_model.php @@ -278,7 +278,7 @@ class Logbook_model extends CI_Model { $data['COL_MY_GRIDSQUARE'] = strtoupper(trim($station['station_gridsquare'])); } - if ($this->exists_hrdlog_code($station_id)) { + if ($this->exists_hrdlog_credentials($station_id)) { $data['COL_HRDLOG_QSO_UPLOAD_STATUS'] = 'N'; } @@ -602,15 +602,15 @@ class Logbook_model extends CI_Model { } $result = ''; - $result = $this->exists_hrdlog_code($data['station_id']); + $result = $this->exists_hrdlog_credentials($data['station_id']); // Push qso to hrdlog if code is set, and realtime upload is enabled, and we're not importing an adif-file - if (isset($result->hrdlog_code) && $result->hrdlogrealtime == 1) { + if (isset($result->hrdlog_code) && isset($result->hrdlog_username) && $result->hrdlogrealtime == 1) { $CI =& get_instance(); $CI->load->library('AdifHelper'); $qso = $this->get_qso($last_id,true)->result(); $adif = $CI->adifhelper->getAdifLine($qso[0]); - $result = $this->push_qso_to_hrdlog($result->hrdlog_code, $data['COL_STATION_CALLSIGN'], $adif); + $result = $this->push_qso_to_hrdlog($result->hrdlog_username, $result->hrdlog_code, $adif); if ( ($result['status'] == 'OK') || ( ($result['status'] == 'error') || ($result['status'] == 'duplicate') || ($result['status'] == 'auth_error') )){ $this->mark_hrdlog_qsos_sent($last_id); } @@ -652,10 +652,10 @@ class Logbook_model extends CI_Model { } /* - * Function checks if a HRDLog Code exists in the table with the given station id + * Function checks if a HRDLog Code and Username exists in the table with the given station id */ - function exists_hrdlog_code($station_id) { - $sql = 'select hrdlog_code, hrdlogrealtime from station_profile + function exists_hrdlog_credentials($station_id) { + $sql = 'select hrdlog_username, hrdlog_code, hrdlogrealtime from station_profile where station_id = ?'; $query = $this->db->query($sql,$station_id); @@ -762,7 +762,7 @@ class Logbook_model extends CI_Model { * Function uploads a QSO to HRDLog with the API given. * $adif contains a line with the QSO in the ADIF format. QSO ends with an */ - function push_qso_to_hrdlog($apikey, $station_callsign, $adif, $replaceoption = false) { + function push_qso_to_hrdlog($hrdlog_username, $apikey, $adif, $replaceoption = false) { $url = 'https://robot.hrdlog.net/newentry.aspx'; $post_data['Code'] = $apikey; @@ -772,7 +772,7 @@ class Logbook_model extends CI_Model { } $post_data['ADIFData'] = $adif; - $post_data['Callsign'] = $station_callsign; + $post_data['Callsign'] = $hrdlog_username; $post_encoded=http_build_query($post_data); @@ -1213,7 +1213,7 @@ class Logbook_model extends CI_Model { 'COL_CNTY' => $uscounty ); - if ($this->exists_hrdlog_code($data['station_id'])) { + if ($this->exists_hrdlog_credentials($data['station_id'])) { $data['COL_HRDLOG_QSO_UPLOAD_STATUS'] = 'M'; } @@ -1745,9 +1745,11 @@ class Logbook_model extends CI_Model { * Function returns all the station_id's with HRDLOG Code */ function get_station_id_with_hrdlog_code() { - $sql = 'select station_id, hrdlog_code from station_profile - where coalesce(hrdlog_code, "") <> ""'; - + $sql = 'SELECT station_id, hrdlog_username, hrdlog_code + FROM station_profile + WHERE coalesce(hrdlog_username, "") <> "" + AND coalesce(hrdlog_code, "") <> ""'; + $query = $this->db->query($sql); $result = $query->result(); diff --git a/application/models/Stations.php b/application/models/Stations.php index 46ae25e3..a3e71ac4 100644 --- a/application/models/Stations.php +++ b/application/models/Stations.php @@ -101,6 +101,7 @@ class Stations extends CI_Model { 'station_itu' => xss_clean($this->input->post('station_itu', true)), 'state' => $state, 'eqslqthnickname' => xss_clean($this->input->post('eqslnickname', true)), + 'hrdlog_username' => xss_clean($this->input->post('hrdlog_username', true)), 'hrdlog_code' => xss_clean($this->input->post('hrdlog_code', true)), 'hrdlogrealtime' => xss_clean($this->input->post('hrdlogrealtime', true)), 'clublogrealtime' => xss_clean($this->input->post('clublogrealtime', true)), @@ -150,6 +151,7 @@ class Stations extends CI_Model { 'station_itu' => xss_clean($this->input->post('station_itu', true)), 'state' => $state, 'eqslqthnickname' => xss_clean($this->input->post('eqslnickname', true)), + 'hrdlog_username' => xss_clean($this->input->post('hrdlog_username', true)), 'hrdlog_code' => xss_clean($this->input->post('hrdlog_code', true)), 'hrdlogrealtime' => xss_clean($this->input->post('hrdlogrealtime', true)), 'clublogrealtime' => xss_clean($this->input->post('clublogrealtime', true)), diff --git a/application/views/station_profile/create.php b/application/views/station_profile/create.php index 833ab867..34ae4f43 100644 --- a/application/views/station_profile/create.php +++ b/application/views/station_profile/create.php @@ -265,12 +265,17 @@
-
+
+ + + Your HRDlog Username +
+
-
+
hrdlog_username; } ?>"> + Your HRDlog Username +
hrdlog_code; } ?>">