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): ?>
QSOs with missing state and gridsquares with 6 or more characters found for the following DXCC's:
+= __("QSOs with missing state and gridsquares with 6 or more characters found for the following DXCC's:"); ?>
-| Prefix | -DXCC | -QSOs | += __("Prefix"); ?> | += __("DXCC"); ?> | += __("QSOs"); ?> | += __("Action"); ?> | prefix; ?> | + | + + | @@ -32,7 +38,7 @@
|---|