diff --git a/application/controllers/Logbookadvanced.php b/application/controllers/Logbookadvanced.php index 1ca6422da..4a6d417b2 100644 --- a/application/controllers/Logbookadvanced.php +++ b/application/controllers/Logbookadvanced.php @@ -905,4 +905,19 @@ class Logbookadvanced extends CI_Controller { } } + + public function fixStateBatch() { + if(!clubaccess_check(9)) return; + + $this->load->model('logbook_model'); + $this->load->model('logbookadvanced_model'); + + $dxcc = $this->input->post('dxcc', true); + + // Process for batch QSO state fix + $result = $this->logbookadvanced_model->fixStateBatch($dxcc); + + header("Content-Type: application/json"); + echo json_encode($result); + } } diff --git a/application/libraries/Geojson.php b/application/libraries/Geojson.php index 618143f42..c832fcbe5 100644 --- a/application/libraries/Geojson.php +++ b/application/libraries/Geojson.php @@ -134,6 +134,15 @@ class Geojson { return isset(self::SUPPORTED_STATES[$dxcc]) && self::SUPPORTED_STATES[$dxcc]['enabled'] === true; } + /** + * Retrieve list of DXCC entities that support state/province lookups + * + * @return array List of supported DXCC entities + */ + public function getSupportedDxccs() { + return self::SUPPORTED_STATES; + } + // ============================================================================ // COORDINATE CONVERSION // ============================================================================ diff --git a/application/models/Logbookadvanced_model.php b/application/models/Logbookadvanced_model.php index 0124843fa..3dfe433bf 100644 --- a/application/models/Logbookadvanced_model.php +++ b/application/models/Logbookadvanced_model.php @@ -1457,18 +1457,18 @@ class Logbookadvanced_model extends CI_Model { return $this->check_missing_dxcc(); case 'checkstate': return $this->check_missing_state(); + case 'checkcqzones': + return $this->check_missing_cq_zones(); + case 'checkituzones': + return $this->check_missing_itu_zones(); return null; } } public function check_missing_dxcc() { - $this->load->model('logbooks_model'); - $logbooks_locations_array = $this->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); - $sql = "select count(*) as count from " . $this->config->item('table_name') . " join station_profile on " . $this->config->item('table_name') . ".station_id = station_profile.station_id - where " . $this->config->item('table_name') . ".station_id in (" . implode(',', array_map('intval', $logbooks_locations_array)) . ") - and user_id = ? and coalesce(col_dxcc, '') = ''"; + where user_id = ? and coalesce(col_dxcc, '') = ''"; $bindings[] = [$this->session->userdata('user_id')]; @@ -1477,13 +1477,9 @@ class Logbookadvanced_model extends CI_Model { } public function check_qsos_missing_continent() { - $this->load->model('logbooks_model'); - $logbooks_locations_array = $this->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); - $sql = "select count(*) as count from " . $this->config->item('table_name') . " join station_profile on " . $this->config->item('table_name') . ".station_id = station_profile.station_id - where " . $this->config->item('table_name') . ".station_id in (" . implode(',', array_map('intval', $logbooks_locations_array)) . ") - and user_id = ? + where user_id = ? and (coalesce(col_cont, '') = '' or col_cont not in ('AF', 'AN', 'AS', 'EU', 'NA', 'OC', 'SA'))"; $bindings[] = [$this->session->userdata('user_id')]; @@ -1493,13 +1489,9 @@ class Logbookadvanced_model extends CI_Model { } public function check_missing_distance() { - $this->load->model('logbooks_model'); - $logbooks_locations_array = $this->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); - $sql = "select count(*) as count from " . $this->config->item('table_name') . " join station_profile on " . $this->config->item('table_name') . ".station_id = station_profile.station_id - where " . $this->config->item('table_name') . ".station_id in (" . implode(',', array_map('intval', $logbooks_locations_array)) . ") - and user_id = ? and coalesce(col_distance, '') = ''"; + where user_id = ? and coalesce(col_distance, '') = ''"; $bindings[] = [$this->session->userdata('user_id')]; @@ -1526,4 +1518,64 @@ class Logbookadvanced_model extends CI_Model { $query = $this->db->query($sql, $bindings); return $query->result(); } + + public function check_missing_cq_zones() { + $sql = "select count(*) as count from " . $this->config->item('table_name') . " + join station_profile on " . $this->config->item('table_name') . ".station_id = station_profile.station_id + where user_id = ? and coalesce(col_cqz, '') = ''"; + + $bindings[] = [$this->session->userdata('user_id')]; + + $query = $this->db->query($sql, $bindings); + return $query->result(); + } + + public function check_missing_itu_zones() { + $sql = "select count(*) as count from " . $this->config->item('table_name') . " + join station_profile on " . $this->config->item('table_name') . ".station_id = station_profile.station_id + where user_id = ? and coalesce(col_ituz, '') = ''"; + + $bindings[] = [$this->session->userdata('user_id')]; + + $query = $this->db->query($sql, $bindings); + return $query->result(); + } + + /** + * Fix state for a batch of QSOs using GeoJSON lookup + * + * @param int $dxcc DXCC entity number for which to fix states + * @return array Result array with success, dxcc_name, dxcc_number, state_code, skipped + */ + function fixStateBatch($dxcc) { + $this->load->library('Geojson'); + + // Get QSO data + $sql = "SELECT COL_PRIMARY_KEY, COL_CALL, COL_GRIDSQUARE, COL_DXCC, COL_STATE, d.name as dxcc_name + FROM " . $this->config->item('table_name') . " qsos + JOIN station_profile ON qsos.station_id = station_profile.station_id + LEFT JOIN dxcc_entities d ON qsos.COL_DXCC = d.adif + WHERE qsos.COL_DXCC = ? AND station_profile.user_id = ? + AND (qsos.COL_STATE IS NULL OR qsos.COL_STATE = '') + AND LENGTH(COALESCE(qsos.COL_GRIDSQUARE, '')) >= 6"; + + $query = $this->db->query($sql, [$dxcc, $this->session->userdata('user_id')]); + + if ($query->num_rows() === 0) { + return [ + 'success' => false, + 'skipped' => true, + 'reason' => 'QSOs not found' + ]; + } + + $results = []; + + foreach ($query->result() as $qso) { + $result = $this->fixStateSingle($qso->COL_PRIMARY_KEY); + $results []= $result; + } + + return $results; + } } diff --git a/application/views/logbookadvanced/checkresult.php b/application/views/logbookadvanced/checkresult.php index e1a86a04d..10dc34aa1 100644 --- a/application/views/logbookadvanced/checkresult.php +++ b/application/views/logbookadvanced/checkresult.php @@ -1,15 +1,16 @@ 0): ?>
-
State Check Results
-

QSOs with missing state and gridsquares with 6 or more characters found for the following DXCC's:

+
+

-
+
- - - + + + + @@ -24,6 +25,11 @@ + @@ -32,7 +38,7 @@
-
State Check Results
-

No issues found. All QSOs have proper state information.

+
+

diff --git a/application/views/logbookadvanced/dbtoolsdialog.php b/application/views/logbookadvanced/dbtoolsdialog.php index bca0ea9d0..69c7398d9 100644 --- a/application/views/logbookadvanced/dbtoolsdialog.php +++ b/application/views/logbookadvanced/dbtoolsdialog.php @@ -1,7 +1,11 @@
-
+
+ +
@@ -12,9 +16,6 @@ -
@@ -27,9 +28,6 @@ -
@@ -42,9 +40,6 @@ -
@@ -57,9 +52,6 @@ - @@ -72,9 +64,6 @@ - @@ -87,9 +76,6 @@ - diff --git a/assets/js/sections/logbookadvanced.js b/assets/js/sections/logbookadvanced.js index 2b9f2d161..c6c38f4d8 100644 --- a/assets/js/sections/logbookadvanced.js +++ b/assets/js/sections/logbookadvanced.js @@ -2044,7 +2044,7 @@ function saveOptions() { $('#closeButton').prop("disabled", false); // Create a nice display for the results let resultHtml = '
Distance Check Results
'; - resultHtml += '

QSO to update found: ' + (response[0].count) + '

'; + resultHtml += '

QSO to update found: ' + (response[0].count) + '

'; $('.result').html(resultHtml); }, @@ -2082,7 +2082,7 @@ function saveOptions() { $('#closeButton').prop("disabled", false); // Create a nice display for the results let resultHtml = '
DXCC Check Results
'; - resultHtml += '

QSOs without DXCC information found: ' + (response[0].count) + '

'; + resultHtml += '

QSOs without DXCC information found: ' + (response[0].count) + '

'; $('.result').html(resultHtml); }, @@ -2119,7 +2119,7 @@ function saveOptions() { $('#closeButton').prop("disabled", false); // Create a nice display for the results let resultHtml = '
Continent Check Results
'; - resultHtml += '

QSOs with missing or invalid continent information found: ' + (response[0].count) + '

'; + resultHtml += '

QSOs with missing or invalid continent information found: ' + (response[0].count) + '

'; $('.result').html(resultHtml); }, @@ -2175,27 +2175,27 @@ function saveOptions() { }); } - function checkFixState2() { - $('#checkFixStateBtn').prop("disabled", true).addClass("running"); + function checkFixCqZones() { + $('#checkFixCqZonesBtn').prop("disabled", true).addClass("running"); $('#closeButton').prop("disabled", true); $.ajax({ url: base_url + 'index.php/logbookadvanced/checkDb', data: { - type: 'checkstate' + type: 'checkcqzones' }, type: 'POST', success: function(response) { - $('#checkFixStateBtn').prop("disabled", false).removeClass("running"); + $('#checkFixCqZonesBtn').prop("disabled", false).removeClass("running"); $('#closeButton').prop("disabled", false); // Create a nice display for the results - let resultHtml = '
State Check Results
'; - resultHtml += '

QSOs with missing state and gridsquares with 6 or more characters found: ' + (response[0].count) + '

'; + let resultHtml = '
CQ Zone Check Results
'; + resultHtml += '

QSOs with missing CQ zone information found: ' + (response[0].count) + '

'; $('.result').html(resultHtml); }, error: function(xhr, status, error) { - $('#checkFixStateBtn').prop('disabled', false).text(''); + $('#checkFixCqZonesBtn').prop('disabled', false).text(''); $('#closeButton').prop('disabled', false); let errorMsg = ''; @@ -2211,3 +2211,61 @@ function saveOptions() { } }); } + + function checkFixItuZones() { + $('#checkFixItuZonesBtn').prop("disabled", true).addClass("running"); + $('#closeButton').prop("disabled", true); + + $.ajax({ + url: base_url + 'index.php/logbookadvanced/checkDb', + data: { + type: 'checkituzones' + }, + type: 'POST', + success: function(response) { + $('#checkFixItuZonesBtn').prop("disabled", false).removeClass("running"); + $('#closeButton').prop("disabled", false); + // Create a nice display for the results + let resultHtml = '
ITU Zone Check Results
'; + resultHtml += '

QSOs with missing ITU zone information found: ' + (response[0].count) + '

'; + + $('.result').html(resultHtml); + }, + error: function(xhr, status, error) { + $('#checkFixItuZonesBtn').prop('disabled', false).text(''); + $('#closeButton').prop('disabled', false); + + let errorMsg = ''; + if (xhr.responseJSON && xhr.responseJSON.message) { + errorMsg += ': ' + xhr.responseJSON.message; + } + + BootstrapDialog.alert({ + title: '', + message: errorMsg, + type: BootstrapDialog.TYPE_DANGER + }); + } + }); + } + + function fixState(dxcc) { + $('#fixStateButton').prop("disabled", true).addClass("running"); + + $.ajax({ + url: base_url + 'index.php/logbookadvanced/fixStateBatch', + type: 'post', + data: { + 'dxcc': dxcc + }, + success: function (response) { + $('#fixStateButton').prop("disabled", false).removeClass("running"); + }, + error: function () { + $('#fixStateButton').prop("disabled", false).removeClass("running"); + } + }); + } + + +
PrefixDXCCQSOs
prefix; ?> + +