From cdf942d3bddeb2b49b901cf90f6a52050041b67d Mon Sep 17 00:00:00 2001 From: Andreas Kristiansen <6977712+AndreasK79@users.noreply.github.com> Date: Sun, 7 Dec 2025 14:18:20 +0100 Subject: [PATCH] Tweaked layout a bit and implemented checks for continent/dxcc/distance --- application/models/Logbookadvanced_model.php | 43 ++++++ .../views/logbookadvanced/dbtoolsdialog.php | 58 ++++---- assets/js/sections/logbookadvanced.js | 131 ++++++++++++++---- 3 files changed, 173 insertions(+), 59 deletions(-) diff --git a/application/models/Logbookadvanced_model.php b/application/models/Logbookadvanced_model.php index 924af2f26..fbeb85691 100644 --- a/application/models/Logbookadvanced_model.php +++ b/application/models/Logbookadvanced_model.php @@ -1448,6 +1448,49 @@ class Logbookadvanced_model extends CI_Model { } public function runCheckDb($type) { + switch ($type) { + case 'checkdistance': + return $this->check_missing_distance(); + case 'checkcontinent': + return $this->check_qsos_missing_continent(); + case 'checkdxcc': + return $this->check_missing_dxcc(); + 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, '') = ''"; + + $bindings[] = [$this->session->userdata('user_id')]; + + $query = $this->db->query($sql, $bindings); + return $query->result(); + } + + 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 = ? + and (coalesce(col_cont, '') = '' or col_cont not in ('AF', 'AN', 'AS', 'EU', 'NA', 'OC', 'SA'))"; + + $bindings[] = [$this->session->userdata('user_id')]; + + $query = $this->db->query($sql, $bindings); + return $query->result(); + } + + 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')); diff --git a/application/views/logbookadvanced/dbtoolsdialog.php b/application/views/logbookadvanced/dbtoolsdialog.php index e1ae53af0..bca0ea9d0 100644 --- a/application/views/logbookadvanced/dbtoolsdialog.php +++ b/application/views/logbookadvanced/dbtoolsdialog.php @@ -9,11 +9,11 @@
= __("Update missing or incorrect CQ zone information") ?>
= __("Update missing or incorrect ITU zone information") ?>
= __("Update missing or incorrect continent information") ?>
= __("Update missing or incorrect state/province information") ?>
= __("Calculate and update distance information for QSOs") ?>
= __("Identify QSOs that are missing DXCC information") ?>
= __("Use Wavelog to determine DXCC for all QSOs. This will overwrite existing DXCC information.") ?>
+= __("Use Wavelog to determine DXCC for all QSOs.") ?>
+= __("This will overwrite existing DXCC information!") ?>
QSO to update found: ' + (response[0].count) + '
'; + url: base_url + 'index.php/logbookadvanced/checkDb', + data: { + type: 'checkdistance' + }, + type: 'POST', + success: function(response) { + $('#checkUpdateDistancesBtn').prop("disabled", false).removeClass("running"); + $('#closeButton').prop("disabled", false); + // Create a nice display for the results + let resultHtml = 'QSO to update found: ' + (response[0].count) + '
'; - $('.result').html(resultHtml); - }, - error: function(xhr, status, error) { - $('#checkUpdateDistancesBtn').prop('disabled', false).text('= __("Check") ?>'); - $('#closeButton').prop('disabled', false); + $('.result').html(resultHtml); + }, + error: function(xhr, status, error) { + $('#checkUpdateDistancesBtn').prop('disabled', false).text('= __("Check") ?>'); + $('#closeButton').prop('disabled', false); - let errorMsg = '= __("Error checking distance information") ?>'; - if (xhr.responseJSON && xhr.responseJSON.message) { - errorMsg += ': ' + xhr.responseJSON.message; + let errorMsg = '= __("Error checking distance information") ?>'; + if (xhr.responseJSON && xhr.responseJSON.message) { + errorMsg += ': ' + xhr.responseJSON.message; + } + + BootstrapDialog.alert({ + title: '= __("Error") ?>', + message: errorMsg, + type: BootstrapDialog.TYPE_DANGER + }); } - - BootstrapDialog.alert({ - title: '= __("Error") ?>', - message: errorMsg, - type: BootstrapDialog.TYPE_DANGER - }); - } - }); - - + }); + } + + function checkMissingDxcc() { + $('#checkMissingDxccsBtn').prop("disabled", true).addClass("running"); + $('#closeButton').prop("disabled", true); + + + $.ajax({ + url: base_url + 'index.php/logbookadvanced/checkDb', + data: { + type: 'checkdxcc' + }, + type: 'POST', + success: function(response) { + $('#checkMissingDxccsBtn').prop("disabled", false).removeClass("running"); + $('#closeButton').prop("disabled", false); + // Create a nice display for the results + let resultHtml = 'QSOs without DXCC information found: ' + (response[0].count) + '
'; + + $('.result').html(resultHtml); + }, + error: function(xhr, status, error) { + $('#checkMissingDxccsBtn').prop('disabled', false).text('= __("Check") ?>'); + $('#closeButton').prop('disabled', false); + + let errorMsg = '= __("Error checking distance information") ?>'; + if (xhr.responseJSON && xhr.responseJSON.message) { + errorMsg += ': ' + xhr.responseJSON.message; + } + + BootstrapDialog.alert({ + title: '= __("Error") ?>', + message: errorMsg, + type: BootstrapDialog.TYPE_DANGER + }); + } + }); + } + + function checkFixContinent() { + $('#checkFixContinentBtn').prop("disabled", true).addClass("running"); + $('#closeButton').prop("disabled", true); + + $.ajax({ + url: base_url + 'index.php/logbookadvanced/checkDb', + data: { + type: 'checkcontinent' + }, + type: 'POST', + success: function(response) { + $('#checkFixContinentBtn').prop("disabled", false).removeClass("running"); + $('#closeButton').prop("disabled", false); + // Create a nice display for the results + let resultHtml = 'QSOs without missing or invalid continent information found: ' + (response[0].count) + '
'; + + $('.result').html(resultHtml); + }, + error: function(xhr, status, error) { + $('#checkFixContinentBtn').prop('disabled', false).text('= __("Check") ?>'); + $('#closeButton').prop('disabled', false); + + let errorMsg = '= __("Error checking distance information") ?>'; + if (xhr.responseJSON && xhr.responseJSON.message) { + errorMsg += ': ' + xhr.responseJSON.message; + } + + BootstrapDialog.alert({ + title: '= __("Error") ?>', + message: errorMsg, + type: BootstrapDialog.TYPE_DANGER + }); + } + }); }