From a96bbab727d9408a95153ddfa39c87890dd08dd3 Mon Sep 17 00:00:00 2001 From: Andreas Kristiansen <6977712+AndreasK79@users.noreply.github.com> Date: Tue, 4 Nov 2025 10:13:41 +0100 Subject: [PATCH 01/11] [Station Location] Import / export --- application/controllers/Stationsetup.php | 82 +++++++++++ application/models/Stationsetup_model.php | 62 +++++++- .../views/stationsetup/locationlist.php | 136 +++++++++++++++--- 3 files changed, 256 insertions(+), 24 deletions(-) diff --git a/application/controllers/Stationsetup.php b/application/controllers/Stationsetup.php index baa6ac730..26d0320a0 100644 --- a/application/controllers/Stationsetup.php +++ b/application/controllers/Stationsetup.php @@ -528,4 +528,86 @@ class Stationsetup extends CI_Controller { $this->load->view('stationsetup/locationlist'); $this->load->view('interface_assets/footer'); } + + public function export_locations() { + $this->load->model('stationsetup_model'); + + $locations = $this->stationsetup_model->list_all_locations(); + + // Output as JSON + $this->output + ->set_content_type('application/json') + ->set_output(json_encode($locations)); + } + + public function import_locations(){ + if (empty($_FILES['file']['tmp_name'])) { + $this->output + ->set_content_type('application/json') + ->set_output(json_encode(['status' => 'error', 'message' => 'No file uploaded'])); + return; + } + + $fileContent = file_get_contents($_FILES['file']['tmp_name']); + $locations = json_decode($fileContent, true); + + if ($locations === null) { + $this->output + ->set_content_type('application/json') + ->set_output(json_encode(['status' => 'error', 'message' => 'Invalid JSON file'])); + return; + } + + // Load your model + $this->load->model('stationsetup_model'); + + $imported = 0; + foreach ($locations as $loc) { + // Data for station_profile + $dbdata = [ + 'station_active' => 0, + 'station_profile_name' => $loc['station_profile_name'] ?? null, + 'station_gridsquare' => $loc['station_gridsquare'] ?? null, + 'station_city' => $loc['station_city'] ?? null, + 'station_iota' => $loc['station_iota'] ?? null, + 'station_sota' => $loc['station_sota'] ?? null, + 'station_callsign' => $loc['station_callsign'] ?? null, + 'station_power' => $loc['station_power'] ?? null, + 'station_dxcc' => $loc['station_dxcc'] ?? null, + 'station_cq' => $loc['station_cq'] ?? null, + 'station_itu' => $loc['station_itu'] ?? null, + 'station_sig' => $loc['station_sig'] ?? null, + 'station_sig_info' => $loc['station_sig_info'] ?? null, + 'station_wwff' => $loc['station_wwff'] ?? null, + 'station_pota' => $loc['station_pota'] ?? null, + 'state' => $loc['state'] ?? null, + 'station_cnty' => $loc['station_cnty'] ?? null, + 'qrzrealtime' => $loc['qrzrealtime'] ?? 0, + 'oqrs' => $loc['oqrs'] ?? 0, + 'oqrs_text' => $loc['oqrs_text'] ?? null, + 'oqrs_email' => $loc['oqrs_email'] ?? null, + 'webadifrealtime' => $loc['webadifrealtime'] ?? null, + 'clublogignore' => $loc['clublogignore'] ?? 1, + 'clublogrealtime' => $loc['clublogrealtime'] ?? 0, + 'hrdlogrealtime' => $loc['hrdlogrealtime'] ?? 0, + 'hrdlog_username' => $loc['hrdlog_username'] ?? null, + 'eqslqthnickname' => $loc['eqslqthnickname'] ?? null, + 'webadifapiurl' => 'https://qo100dx.club/api', + 'user_id' => $this->session->userdata('user_id'), + ]; + + // Data for user_options + $optiondata = [ + 'eqsl_default_qslmsg' => $loc['eqsl_default_qslmsg'] ?? null, + ]; + + // Insert or update location in DB + $imported += $this->stationsetup_model->save_location($dbdata, $optiondata); + } + + $this->output + ->set_content_type('application/json') + ->set_output(json_encode(['status' => 'success', 'message' => "$imported locations imported."])); + } + } diff --git a/application/models/Stationsetup_model.php b/application/models/Stationsetup_model.php index 81d4aa9fc..d162f503c 100644 --- a/application/models/Stationsetup_model.php +++ b/application/models/Stationsetup_model.php @@ -234,7 +234,7 @@ class Stationsetup_model extends CI_Model { } function list_all_locations() { - $sql = "select dxcc_entities.end, station_profile.station_id, station_profile_name, station_gridsquare, station_city, station_iota, station_sota, station_callsign, station_power, station_dxcc, dxcc_entities.name as dxccname, dxcc_entities.prefix as dxccprefix, station_cnty, station_cq, station_itu, station_active, eqslqthnickname, state, county, station_sig, station_sig_info, qrzrealtime, station_wwff, station_pota, oqrs, oqrs_text, oqrs_email, webadifrealtime, clublogrealtime, clublogignore, hrdlogrealtime, creation_date, last_modified + $sql = "select dxcc_entities.end, station_profile.station_id, station_profile_name, station_profile.hrdlog_username, station_gridsquare, station_city, station_iota, station_sota, station_callsign, station_power, station_dxcc, dxcc_entities.name as dxccname, dxcc_entities.prefix as dxccprefix, station_cnty, station_cq, station_itu, station_active, eqslqthnickname, state, county, station_sig, station_sig_info, qrzrealtime, station_wwff, station_pota, oqrs, oqrs_text, oqrs_email, webadifrealtime, clublogrealtime, clublogignore, hrdlogrealtime, creation_date, last_modified from station_profile join dxcc_entities on station_profile.station_dxcc = dxcc_entities.adif where user_id = ?"; @@ -254,6 +254,66 @@ class Stationsetup_model extends CI_Model { return $result; } + + public function save_location($dbdata, $optiondata) { + // Make sure we have the needed fields + if (empty($dbdata['station_profile_name']) || empty($dbdata['station_callsign'])) { + return false; + } + + // Check if a location exists with same parameters + $sql = " + SELECT * + FROM station_profile + WHERE station_profile_name = ? + AND station_callsign = ? + AND station_gridsquare = ? + AND station_city = ? + AND station_iota = ? + AND station_sota = ? + AND state = ? + AND station_cnty = ? + AND station_dxcc = ? + AND station_wwff = ? + AND station_pota = ? + AND station_sig = ? + AND station_sig_info = ? + AND user_id = ?; + "; + + $query = $this->db->query($sql, [ + $dbdata['station_profile_name'], + $dbdata['station_callsign'], + $dbdata['station_gridsquare'], + $dbdata['station_city'], + $dbdata['station_iota'], + $dbdata['station_sota'], + $dbdata['state'], + $dbdata['station_cnty'], + $dbdata['station_dxcc'], + $dbdata['station_wwff'], + $dbdata['station_pota'], + $dbdata['station_sig'], + $dbdata['station_sig_info'], + $this->session->userdata('user_id') + ]); + + if ($query->num_rows() > 0) { + // Location already exists + return 0; + } else { + // Insert new location + $this->db->insert('station_profile', $dbdata); + $location_id = $this->db->insert_id(); + + if (!empty(trim($optiondata['eqsl_default_qslmsg']))) { + $this->user_options_model->set_option('eqsl_default_qslmsg', 'key_station_id', array($location_id => $optiondata['eqsl_default_qslmsg'])); + } + } + + return 1; + } + } ?> diff --git a/application/views/stationsetup/locationlist.php b/application/views/stationsetup/locationlist.php index 3398beed3..4b59e290e 100644 --- a/application/views/stationsetup/locationlist.php +++ b/application/views/stationsetup/locationlist.php @@ -1,3 +1,4 @@ +

@@ -33,6 +34,7 @@ ClubLog realtime upload ClubLog Ignore HRDLog realtime upload + HRDLog username Created Last Modified @@ -72,6 +74,7 @@ clublogrealtime ? 'Yes' : 'No' ?> clublogignore ? 'Yes' : 'No' ?> hrdlogrealtime ? 'Yes' : 'No' ?> + hrdlog_username; ?> creation_date; ?> last_modified; ?> @@ -85,27 +88,114 @@
+ From ac6f6a216557df205690f1ac060b5ea61286db65 Mon Sep 17 00:00:00 2001 From: Andreas Kristiansen <6977712+AndreasK79@users.noreply.github.com> Date: Tue, 4 Nov 2025 11:21:12 +0100 Subject: [PATCH 02/11] Added xss_clean --- application/controllers/Stationsetup.php | 52 ++++++++++++------------ 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/application/controllers/Stationsetup.php b/application/controllers/Stationsetup.php index 26d0320a0..fa2083b15 100644 --- a/application/controllers/Stationsetup.php +++ b/application/controllers/Stationsetup.php @@ -566,32 +566,32 @@ class Stationsetup extends CI_Controller { // Data for station_profile $dbdata = [ 'station_active' => 0, - 'station_profile_name' => $loc['station_profile_name'] ?? null, - 'station_gridsquare' => $loc['station_gridsquare'] ?? null, - 'station_city' => $loc['station_city'] ?? null, - 'station_iota' => $loc['station_iota'] ?? null, - 'station_sota' => $loc['station_sota'] ?? null, - 'station_callsign' => $loc['station_callsign'] ?? null, - 'station_power' => $loc['station_power'] ?? null, - 'station_dxcc' => $loc['station_dxcc'] ?? null, - 'station_cq' => $loc['station_cq'] ?? null, - 'station_itu' => $loc['station_itu'] ?? null, - 'station_sig' => $loc['station_sig'] ?? null, - 'station_sig_info' => $loc['station_sig_info'] ?? null, - 'station_wwff' => $loc['station_wwff'] ?? null, - 'station_pota' => $loc['station_pota'] ?? null, - 'state' => $loc['state'] ?? null, - 'station_cnty' => $loc['station_cnty'] ?? null, - 'qrzrealtime' => $loc['qrzrealtime'] ?? 0, - 'oqrs' => $loc['oqrs'] ?? 0, - 'oqrs_text' => $loc['oqrs_text'] ?? null, - 'oqrs_email' => $loc['oqrs_email'] ?? null, - 'webadifrealtime' => $loc['webadifrealtime'] ?? null, - 'clublogignore' => $loc['clublogignore'] ?? 1, - 'clublogrealtime' => $loc['clublogrealtime'] ?? 0, - 'hrdlogrealtime' => $loc['hrdlogrealtime'] ?? 0, - 'hrdlog_username' => $loc['hrdlog_username'] ?? null, - 'eqslqthnickname' => $loc['eqslqthnickname'] ?? null, + 'station_profile_name' => xss_clean($loc['station_profile_name']) ?? null, + 'station_gridsquare' => xss_clean($loc['station_gridsquare']) ?? null, + 'station_city' => xss_clean($loc['station_city']) ?? null, + 'station_iota' => xss_clean($loc['station_iota']) ?? null, + 'station_sota' => xss_clean($loc['station_sota']) ?? null, + 'station_callsign' => xss_clean($loc['station_callsign']) ?? null, + 'station_power' => xss_clean($loc['station_power']) ?? null, + 'station_dxcc' => xss_clean($loc['station_dxcc']) ?? null, + 'station_cq' => xss_clean($loc['station_cq']) ?? null, + 'station_itu' => xss_clean($loc['station_itu']) ?? null, + 'station_sig' => xss_clean($loc['station_sig']) ?? null, + 'station_sig_info' => xss_clean($loc['station_sig_info']) ?? null, + 'station_wwff' => xss_clean($loc['station_wwff']) ?? null, + 'station_pota' => xss_clean($loc['station_pota']) ?? null, + 'state' => xss_clean($loc['state']) ?? null, + 'station_cnty' => xss_clean($loc['station_cnty']) ?? null, + 'qrzrealtime' => xss_clean($loc['qrzrealtime']) ?? 0, + 'oqrs' => xss_clean($loc['oqrs']) ?? 0, + 'oqrs_text' => xss_clean($loc['oqrs_text']) ?? null, + 'oqrs_email' => xss_clean($loc['oqrs_email']) ?? null, + 'webadifrealtime' => xss_clean($loc['webadifrealtime']) ?? null, + 'clublogignore' => xss_clean($loc['clublogignore']) ?? 1, + 'clublogrealtime' => xss_clean($loc['clublogrealtime']) ?? 0, + 'hrdlogrealtime' => xss_clean($loc['hrdlogrealtime']) ?? 0, + 'hrdlog_username' => xss_clean($loc['hrdlog_username']) ?? null, + 'eqslqthnickname' => xss_clean($loc['eqslqthnickname']) ?? null, 'webadifapiurl' => 'https://qo100dx.club/api', 'user_id' => $this->session->userdata('user_id'), ]; From aaec66d512d32f3d39604dbdf05f7d8e5b0d4482 Mon Sep 17 00:00:00 2001 From: Andreas Kristiansen <6977712+AndreasK79@users.noreply.github.com> Date: Tue, 4 Nov 2025 11:23:41 +0100 Subject: [PATCH 03/11] Added loading of user_options_model --- application/models/Stationsetup_model.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/application/models/Stationsetup_model.php b/application/models/Stationsetup_model.php index d162f503c..1e87c6f70 100644 --- a/application/models/Stationsetup_model.php +++ b/application/models/Stationsetup_model.php @@ -242,6 +242,7 @@ class Stationsetup_model extends CI_Model { $query = $this->db->query($sql, array($this->session->userdata('user_id'))); $result = $query->result(); + $this->load->model('user_options_model'); foreach($result as $location) { $options_object = $this->user_options_model->get_options('eqsl_default_qslmsg', array('option_name' => 'key_station_id', 'option_key' => $location->station_id))->result(); @@ -307,6 +308,7 @@ class Stationsetup_model extends CI_Model { $location_id = $this->db->insert_id(); if (!empty(trim($optiondata['eqsl_default_qslmsg']))) { + $this->load->model('user_options_model'); $this->user_options_model->set_option('eqsl_default_qslmsg', 'key_station_id', array($location_id => $optiondata['eqsl_default_qslmsg'])); } } From 6d533bc0b520c8b8439085962f9864f5375e757f Mon Sep 17 00:00:00 2001 From: Andreas Kristiansen <6977712+AndreasK79@users.noreply.github.com> Date: Tue, 4 Nov 2025 11:29:40 +0100 Subject: [PATCH 04/11] 1K limit --- application/controllers/Stationsetup.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/application/controllers/Stationsetup.php b/application/controllers/Stationsetup.php index fa2083b15..a869b8edb 100644 --- a/application/controllers/Stationsetup.php +++ b/application/controllers/Stationsetup.php @@ -563,6 +563,12 @@ class Stationsetup extends CI_Controller { $imported = 0; foreach ($locations as $loc) { + if ($imported >= 1000){ + $this->output + ->set_content_type('application/json') + ->set_output(json_encode(['status' => 'success', 'message' => "$imported locations imported. Maximum limit of 1000 locations reached."])); + return; // Prevent importing more than 1000 locations at once + } // Data for station_profile $dbdata = [ 'station_active' => 0, From d74ebdf07cfbed27b9974944445647f741ec213f Mon Sep 17 00:00:00 2001 From: Andreas Kristiansen <6977712+AndreasK79@users.noreply.github.com> Date: Wed, 5 Nov 2025 07:40:40 +0100 Subject: [PATCH 05/11] Remove check for empty locations --- application/views/stationsetup/locationlist.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/application/views/stationsetup/locationlist.php b/application/views/stationsetup/locationlist.php index 4b59e290e..1d1149649 100644 --- a/application/views/stationsetup/locationlist.php +++ b/application/views/stationsetup/locationlist.php @@ -1,7 +1,6 @@

-
@@ -82,9 +81,6 @@
- -
No station locations found.
-