diff --git a/application/libraries/Geojson.php b/application/libraries/Geojson.php index 8d3890dc2..db4b87772 100644 --- a/application/libraries/Geojson.php +++ b/application/libraries/Geojson.php @@ -66,11 +66,17 @@ class Geojson { ]; private $qra; + private $geojsonFile = null; + private $geojsonData = null; - public function __construct() { + public function __construct($dxcc = null) { $CI =& get_instance(); $CI->load->library('qra'); $this->qra = $CI->qra; + if ($dxcc !== null) { + $this->geojsonFile = "assets/json/geojson/states_{$dxcc}.geojson"; + $this->geojsonData = $this->loadGeoJsonFile($geojsonFile); + } } // ============================================================================ @@ -114,14 +120,16 @@ class Geojson { return null; } - $geojsonFile = "assets/json/geojson/states_{$dxcc}.geojson"; - $geojsonData = $this->loadGeoJsonFile($geojsonFile); + if ($this->geojsonFile === null) { + $this->geojsonFile = "assets/json/geojson/states_{$dxcc}.geojson"; + $this->geojsonData = $this->loadGeoJsonFile($this->geojsonFile); + } - if ($geojsonData === null) { + if ($this->geojsonData === null) { return null; } - return $this->findFeatureContainingPoint($lat, $lng, $geojsonData); + return $this->findFeatureContainingPoint($lat, $lng, $this->geojsonData); } /** diff --git a/application/models/Logbookadvanced_model.php b/application/models/Logbookadvanced_model.php index f5a7522d7..c7f0bce01 100644 --- a/application/models/Logbookadvanced_model.php +++ b/application/models/Logbookadvanced_model.php @@ -1583,7 +1583,7 @@ class Logbookadvanced_model extends CI_Model { * @return array Result array with success, dxcc_name, dxcc_number, state_code, skipped */ function fixStateBatch($dxcc) { - $this->load->library('Geojson'); + $this->load->library('Geojson', $dxcc); // Get QSO data $sql = "SELECT COL_PRIMARY_KEY, COL_CALL, COL_GRIDSQUARE, COL_DXCC, COL_STATE, d.name as dxcc_name, station_profile.station_profile_name @@ -1605,13 +1605,17 @@ class Logbookadvanced_model extends CI_Model { } $results = []; - - $count = 0; + $batch_updates = []; foreach ($query->result() as $qso) { - $result = $this->fixStateSingle($qso->COL_PRIMARY_KEY); + $result = $this->fixStateDxcc($qso); + if ($result['success']) { - $count++; + // Prepare data for batch update + $batch_updates[] = [ + 'COL_PRIMARY_KEY' => $qso->COL_PRIMARY_KEY, + 'COL_STATE' => $result['state_code'] + ]; } else { $result['station_profile_name'] = $qso->station_profile_name; $result['id'] = $qso->COL_PRIMARY_KEY; @@ -1620,11 +1624,59 @@ class Logbookadvanced_model extends CI_Model { } } + // Perform batch update if there are any updates + $count = 0; + if (!empty($batch_updates)) { + $this->db->update_batch($this->config->item('table_name'), $batch_updates, 'COL_PRIMARY_KEY'); + $count = count($batch_updates); + } + $results['count'] = $count; return $results; } + /** + * Fix state for a batch of QSOs, based on the DXCC + * Note: This now only validates and prepares data + * + * @param object $qso QSO object + * @return array Result array with success, dxcc_name, dxcc_number, state_code, skipped + */ + function fixStateDxcc($qso) { + $callsign = $qso->COL_CALL ?? 'Unknown'; + $dxcc = (int)$qso->COL_DXCC; + $gridsquare = $qso->COL_GRIDSQUARE; + $state = $qso->COL_STATE ?? ''; + $dxcc_name = $qso->dxcc_name ?? 'Unknown'; + + // Find state from gridsquare + $state = $this->geojson->findStateFromGridsquare($gridsquare, $dxcc); + + if ($state === null || !isset($state['code'])) { + return [ + 'success' => false, + 'skipped' => false, + 'callsign' => $callsign, + 'dxcc_number' => $dxcc, + 'dxcc_name' => $dxcc_name, + 'gridsquare' => $gridsquare, + 'reason' => 'State not found in GeoJSON' + ]; + } + + // Return success with state info + return [ + 'success' => true, + 'skipped' => false, + 'callsign' => $callsign, + 'dxcc_number' => $dxcc, + 'dxcc_name' => $dxcc_name, + 'state_code' => $state['code'], + 'state_name' => $state['name'] ?? null + ]; + } + function getStateListQsos($dxcc) { $sql = "SELECT col_primary_key, col_call, col_time_on, col_mode, col_submode, col_band, col_state, col_gridsquare, d.name as dxcc_name, station_profile.station_profile_name FROM " . $this->config->item('table_name') . " qsos JOIN station_profile ON qsos.station_id = station_profile.station_id @@ -1724,29 +1776,41 @@ class Logbookadvanced_model extends CI_Model { $result = $this->getMissingGridQsos(); $count = 0; + $batch_updates = []; + $this->db->trans_start(); + if (count($result) > 0) { + if (!$this->load->is_loaded('callbook')) { + $this->load->library('callbook'); + } + foreach ($result as $row) { $callsign = $row->col_call; - if (!$this->load->is_loaded('callbook')) { - $this->load->library('callbook'); - } - $callbook = $this->callbook->getCallbookData($callsign); if (isset($callbook)) { if (isset($callbook['error'])) { log_message('error', "Error: " . $callbook['error']); } else { - if ($callbook['gridsquare'] != '') { - $sql = "update " . $this->config->item('table_name') . " set COL_GRIDSQUARE = ? where COL_PRIMARY_KEY = ?"; - $this->db->query($sql, array($callbook['gridsquare'], $row->col_primary_key)); - $count++; + if (isset($callbook['gridsquare']) && $callbook['gridsquare'] != '') { + // Prepare data for batch update + $batch_updates[] = [ + 'COL_PRIMARY_KEY' => $row->col_primary_key, + 'COL_GRIDSQUARE' => $callbook['gridsquare'] + ]; } } } } + + // Perform batch update if there are any updates + if (!empty($batch_updates)) { + $this->db->update_batch($this->config->item('table_name'), $batch_updates, 'COL_PRIMARY_KEY'); + $count = count($batch_updates); + } } + $this->db->trans_complete(); return $count; @@ -1758,7 +1822,7 @@ class Logbookadvanced_model extends CI_Model { WHERE station_profile.user_id = ? AND (qsos.COL_GRIDSQUARE IS NULL OR qsos.COL_GRIDSQUARE = '') AND (qsos.COL_VUCC_GRIDS IS NULL OR qsos.COL_VUCC_GRIDS = '') - ORDER BY COL_TIME_ON DESC limit 250"; + ORDER BY COL_TIME_ON DESC limit 150"; $query = $this->db->query($sql, [$this->session->userdata('user_id')]); diff --git a/application/views/logbookadvanced/dbtoolsdialog.php b/application/views/logbookadvanced/dbtoolsdialog.php index 543052a43..c9a14318c 100644 --- a/application/views/logbookadvanced/dbtoolsdialog.php +++ b/application/views/logbookadvanced/dbtoolsdialog.php @@ -90,12 +90,12 @@ - config->item('callbook_batch_lookup')): ?> + config->item('callbook_batch_lookup') ?? true): ?>

-

+

- diff --git a/application/views/logbookadvanced/showMissingDxccQsos.php b/application/views/logbookadvanced/showMissingDxccQsos.php index f98c3049a..4f6b58f7f 100644 --- a/application/views/logbookadvanced/showMissingDxccQsos.php +++ b/application/views/logbookadvanced/showMissingDxccQsos.php @@ -1,3 +1,12 @@ +session->userdata('user_date_format')) { + // If Logged in and session exists + $custom_date_format = $this->session->userdata('user_date_format'); +} else { + // Get Default date format from /config/wavelog.php + $custom_date_format = $this->config->item('qso_date_format'); +} +?>
0): ?>
@@ -14,14 +23,14 @@ - + col_primary_key . ')">' . htmlspecialchars($qso->col_call) . ''; ?> - col_time_on)); ?> + col_time_on)); ?> col_mode; ?> col_band; ?> col_state; ?>