diff --git a/application/controllers/Logbookadvanced.php b/application/controllers/Logbookadvanced.php index 246d0c9f7..4e7e9d12f 100644 --- a/application/controllers/Logbookadvanced.php +++ b/application/controllers/Logbookadvanced.php @@ -876,6 +876,8 @@ class Logbookadvanced extends CI_Controller { } public function updateDistances() { + if(!clubaccess_check(9)) return; + $this->load->model('logbookadvanced_model'); $result = $this->logbookadvanced_model->update_distances_batch(); @@ -968,6 +970,8 @@ class Logbookadvanced extends CI_Controller { } public function batchFix() { + if(!clubaccess_check(9)) return; + $type = $this->input->post('type', true); $this->load->model('logbookadvanced_model'); $result = $this->logbookadvanced_model->batchFix($type); diff --git a/application/models/Logbookadvanced_model.php b/application/models/Logbookadvanced_model.php index 7c32c5251..f5a7522d7 100644 --- a/application/models/Logbookadvanced_model.php +++ b/application/models/Logbookadvanced_model.php @@ -1485,6 +1485,8 @@ class Logbookadvanced_model extends CI_Model { return $this->check_missing_cq_zones(); case 'checkituzones': return $this->check_missing_itu_zones(); + case 'checkgrids': + return $this->getMissingGridQsos(); return null; } } @@ -1707,6 +1709,8 @@ class Logbookadvanced_model extends CI_Model { return $this->fixCqZones(); case 'ituzones': return $this->fixItuZones(); + case 'grids': + return $this->check_missing_grid(); default: return null; } @@ -1716,21 +1720,14 @@ class Logbookadvanced_model extends CI_Model { Another function moved from update to the advanced logbook, to be used in the dbtools section. It did not have filter on user or location. */ - public function check_missing_grid_id() { - // get all records with no COL_GRIDSQUARE - $sql = "select COL_PRIMARY_KEY, COL_CALL, COL_TIME_ON, COL_TIME_OFF from " . $this->config->item('table_name') . - " join station_profile on " . $this->config->item('table_name') . ".station_id = station_profile.station_id - where station_profile.user_id = ? - and (COL_GRIDSQUARE is NULL or COL_GRIDSQUARE = '') - AND (COL_VUCC_GRIDS is NULL or COL_VUCC_GRIDS = '')"; - - $result = $this->db->query($sql, array($this->session->userdata('user_id'))); + public function check_missing_grid() { + $result = $this->getMissingGridQsos(); $count = 0; $this->db->trans_start(); - if ($result->num_rows() > 0) { - foreach ($result->result_array() as $row) { - $callsign = $row['COL_CALL']; + if (count($result) > 0) { + foreach ($result as $row) { + $callsign = $row->col_call; if (!$this->load->is_loaded('callbook')) { $this->load->library('callbook'); } @@ -1739,11 +1736,11 @@ class Logbookadvanced_model extends CI_Model { if (isset($callbook)) { if (isset($callbook['error'])) { - $logerror = "Error: " . $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'])); + $this->db->query($sql, array($callbook['gridsquare'], $row->col_primary_key)); $count++; } } @@ -1752,6 +1749,19 @@ class Logbookadvanced_model extends CI_Model { } $this->db->trans_complete(); - return $count . ' updated'; + return $count; + } + + public function getMissingGridQsos() { + $sql = "SELECT col_primary_key, col_call, col_time_on, col_mode, col_submode, col_band, col_state, col_gridsquare, station_profile.station_profile_name FROM " . $this->config->item('table_name') . " qsos + JOIN station_profile ON qsos.station_id = station_profile.station_id + 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"; + + $query = $this->db->query($sql, [$this->session->userdata('user_id')]); + + return $query->result(); } } diff --git a/application/views/logbookadvanced/checkresult.php b/application/views/logbookadvanced/checkresult.php index 8eec47948..12bbc8364 100644 --- a/application/views/logbookadvanced/checkresult.php +++ b/application/views/logbookadvanced/checkresult.php @@ -15,6 +15,9 @@ switch ($type) { case 'checkituzones': check_missing_itu_zones($result); break; + case 'checkgrids': + check_missing_grids($result); + break; default: // Invalid type break; @@ -76,3 +79,13 @@ function check_missing_itu_zones($result) { ?>
+
+ +
+ + + config->item('callbook_batch_lookup')): ?> +
+
+
+

+

+
+
+ +
+
+ diff --git a/application/views/logbookadvanced/showUpdateResult.php b/application/views/logbookadvanced/showUpdateResult.php index 0f86ced7b..c4b5a3daa 100644 --- a/application/views/logbookadvanced/showUpdateResult.php +++ b/application/views/logbookadvanced/showUpdateResult.php @@ -19,6 +19,9 @@ switch ($type) { case 'ituzones': showItuzoneUpdateResult($result); break; + case 'grids': + showGridUpdateResult($result); + break; default: // Invalid type break; @@ -142,3 +145,8 @@ function showItuzoneUpdateResult($result) { echo '
' . __("Results for ITU zone update:") . '
'; echo ''; } + +function showGridUpdateResult($result) { + echo '
' . __("Results for gridsquare update:") . '
'; + echo ''; +} diff --git a/assets/js/sections/logbookadvanced.js b/assets/js/sections/logbookadvanced.js index 62b326fa3..8573ef84f 100644 --- a/assets/js/sections/logbookadvanced.js +++ b/assets/js/sections/logbookadvanced.js @@ -2417,3 +2417,58 @@ function saveOptions() { } }); } + + function checkGrids() { + $('#checkGridsBtn').prop("disabled", true).addClass("running"); + $('#closeButton').prop("disabled", true); + + $.ajax({ + url: base_url + 'index.php/logbookadvanced/checkDb', + data: { + type: 'checkgrids' + }, + type: 'POST', + success: function(response) { + $('#checkGridsBtn').prop("disabled", false).removeClass("running"); + $('#closeButton').prop("disabled", false); + $('.result').html(response); + }, + error: function(xhr, status, error) { + $('#checkGridsBtn').prop('disabled', false).text(''); + $('#closeButton').prop('disabled', false); + + let errorMsg = 'Error checking continent information'; + if (xhr.responseJSON && xhr.responseJSON.message) { + errorMsg += ': ' + xhr.responseJSON.message; + } + + BootstrapDialog.alert({ + title: 'Error', + message: errorMsg, + type: BootstrapDialog.TYPE_DANGER + }); + } + }); + } + + function fixMissingGrids() { + $('#updateGridsBtn').prop("disabled", true).addClass("running"); + $('#closeButton').prop("disabled", true); + $.ajax({ + url: base_url + 'index.php/logbookadvanced/batchFix', + data: { + type: 'grids' + }, + type: 'POST', + success: function (response) { + $('#updateGridsBtn').prop("disabled", false).removeClass("running"); + $('#closeButton').prop("disabled", false); + $('.result').html(response); + }, + error: function(xhr, status, error) { + $('#updateGridsBtn').prop("disabled", false).removeClass("running"); + $('#closeButton').prop("disabled", false); + $('.result').html(error); + } + }); + }