From 969b079ae7848d26bc4f4d96c3bdef06b4db71a9 Mon Sep 17 00:00:00 2001 From: Andreas Kristiansen <6977712+AndreasK79@users.noreply.github.com> Date: Tue, 2 Dec 2025 07:59:17 +0100 Subject: [PATCH] [Advanced Logbook] Started on dbtools --- application/controllers/Logbookadvanced.php | 15 +++ application/models/Logbookadvanced_model.php | 15 +++ .../views/logbookadvanced/dbtoolsdialog.php | 117 ++++++++++++++++++ application/views/logbookadvanced/index.php | 1 + assets/js/sections/logbookadvanced.js | 65 ++++++++++ 5 files changed, 213 insertions(+) create mode 100644 application/views/logbookadvanced/dbtoolsdialog.php diff --git a/application/controllers/Logbookadvanced.php b/application/controllers/Logbookadvanced.php index 8b963fefa..301bf6139 100644 --- a/application/controllers/Logbookadvanced.php +++ b/application/controllers/Logbookadvanced.php @@ -884,4 +884,19 @@ class Logbookadvanced extends CI_Controller { public function callbookDialog() { $this->load->view('logbookadvanced/callbookdialog'); } + + public function dbtoolsDialog() { + $this->load->view('logbookadvanced/dbtoolsdialog'); + } + + public function checkDb() { + if(!clubaccess_check(9)) return; + + $type = $this->input->post('type', true); + + $this->load->model('logbookadvanced_model'); + $result = $this->logbookadvanced_model->runCheckDb($type); + header("Content-Type: application/json"); + print json_encode($result); + } } diff --git a/application/models/Logbookadvanced_model.php b/application/models/Logbookadvanced_model.php index f283af058..924af2f26 100644 --- a/application/models/Logbookadvanced_model.php +++ b/application/models/Logbookadvanced_model.php @@ -1446,4 +1446,19 @@ class Logbookadvanced_model extends CI_Model { return $recordcount; } + + public function runCheckDb($type) { + $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, '') = ''"; + + $bindings[] = [$this->session->userdata('user_id')]; + + $query = $this->db->query($sql, $bindings); + return $query->result(); + } } diff --git a/application/views/logbookadvanced/dbtoolsdialog.php b/application/views/logbookadvanced/dbtoolsdialog.php new file mode 100644 index 000000000..e1ae53af0 --- /dev/null +++ b/application/views/logbookadvanced/dbtoolsdialog.php @@ -0,0 +1,117 @@ +
+
+
+
+
+
+
+
+

+
+
+ + +
+
+ +
+
+
+

+
+
+ + +
+
+ +
+
+
+

+
+
+ + +
+
+ +
+
+
+

+
+
+ + +
+
+ +
+
+
+

+
+
+ + +
+
+ +
+
+
+

+
+
+ + +
+
+ +
+
+
+

+
+
+ + +
+
+ +
+
+
+ + +
+
diff --git a/application/views/logbookadvanced/index.php b/application/views/logbookadvanced/index.php index 3d636282b..51710bd4a 100644 --- a/application/views/logbookadvanced/index.php +++ b/application/views/logbookadvanced/index.php @@ -771,6 +771,7 @@ $options = json_decode($options); + diff --git a/assets/js/sections/logbookadvanced.js b/assets/js/sections/logbookadvanced.js index be429fae7..526f8239a 100644 --- a/assets/js/sections/logbookadvanced.js +++ b/assets/js/sections/logbookadvanced.js @@ -1335,6 +1335,31 @@ $(document).ready(function () { }); }); + $('#dbtools').click(function (event) { + $.ajax({ + url: base_url + 'index.php/logbookadvanced/dbtoolsDialog', + type: 'post', + success: function (html) { + BootstrapDialog.show({ + title: 'Database tools', + size: BootstrapDialog.SIZE_WIDE, + cssClass: 'options', + nl2br: false, + message: html, + buttons: [ + { + label: lang_admin_close, + cssClass: 'btn btn-sm btn-secondary', + id: 'closeButton', + action: function (dialogItself) { + dialogItself.close(); + } + }], + }); + } + }); + }); + function runUpdateDistancesFix(dialogItself) { $('#updateDistanceButton').prop("disabled", true).addClass("running"); $('#closeButton').prop("disabled", true); @@ -2002,3 +2027,43 @@ function saveOptions() { dateFrom.value = ''; dateTo.value = ''; } + + function checkUpdateDistances() { + $('#checkUpdateDistancesBtn').prop("disabled", true).addClass("running"); + $('#closeButton').prop("disabled", true); + + + $.ajax({ + url: base_url + 'index.php/logbookadvanced/checkDb', + data: { + type: 'distance' + }, + type: 'POST', + success: function(response) { + $('#checkUpdateDistancesBtn').prop("disabled", false).removeClass("running"); + $('#closeButton').prop("disabled", false); + // Create a nice display for the results + let resultHtml = '
Distance Check Results
'; + resultHtml += '

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

'; + + $('.result').html(resultHtml); + }, + error: function(xhr, status, error) { + $('#checkUpdateDistancesBtn').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 + }); + } + }); + + + }