Added state check

This commit is contained in:
Andreas Kristiansen
2025-12-07 15:55:52 +01:00
parent cdf942d3bd
commit 2ddf698af7
4 changed files with 142 additions and 5 deletions

View File

@@ -893,10 +893,16 @@ class Logbookadvanced extends CI_Controller {
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);
if ($type == 'checkstate') {
$data['result'] = $this->logbookadvanced_model->runCheckDb($type);
$this->load->view('logbookadvanced/checkresult', $data);
} else {
$result = $this->logbookadvanced_model->runCheckDb($type);
header("Content-Type: application/json");
echo json_encode($result);
}
}
}

View File

@@ -1455,6 +1455,8 @@ class Logbookadvanced_model extends CI_Model {
return $this->check_qsos_missing_continent();
case 'checkdxcc':
return $this->check_missing_dxcc();
case 'checkstate':
return $this->check_missing_state();
return null;
}
}
@@ -1504,4 +1506,24 @@ class Logbookadvanced_model extends CI_Model {
$query = $this->db->query($sql, $bindings);
return $query->result();
}
public function check_missing_state() {
$this->load->library('Geojson');
$supported_dxcc_list = $this->geojson->getSupportedDxccs();
$supported_dxcc_array = array_keys($supported_dxcc_list);
$sql = "select count(*) as count, col_dxcc, dxcc_entities.name as dxcc_name, dxcc_entities.prefix from " . $this->config->item('table_name') . "
join station_profile on " . $this->config->item('table_name') . ".station_id = station_profile.station_id
join dxcc_entities on " . $this->config->item('table_name') . ".col_dxcc = dxcc_entities.adif
where user_id = ? and coalesce(col_state, '') = ''
and col_dxcc in (" . implode(',', array_map('intval', $supported_dxcc_array)) . ")
and length(col_gridsquare) >= 6
group by col_dxcc, dxcc_entities.name, dxcc_entities.prefix
order by dxcc_entities.prefix";
$bindings[] = [$this->session->userdata('user_id')];
$query = $this->db->query($sql, $bindings);
return $query->result();
}
}

View File

@@ -0,0 +1,38 @@
<?php if (isset($result) && is_array($result) && count($result) > 0): ?>
<div class="col-md-12 result">
<h5>State Check Results</h5>
<p><strong>QSOs with missing state and gridsquares with 6 or more characters found for the following DXCC's:</strong></p>
<div class="table-responsive" style="max-height:70vh; overflow:auto;">
<table class="table table-sm table-striped table-bordered table-condensed mb-0">
<thead>
<tr>
<th>Prefix</th>
<th>DXCC</th>
<th>QSOs</th>
</tr>
</thead>
<tbody>
<?php foreach ($result as $index => $item): ?>
<?php
$rawName = isset($item->dxcc_name) ? $item->dxcc_name : '';
$formattedName = ucwords(strtolower($rawName), "- (/");
$name = htmlspecialchars($formattedName, ENT_QUOTES, 'UTF-8');
$qsos = isset($item->count) ? intval($item->count) : 0;
?>
<tr>
<td><?php echo $item->prefix; ?></td>
<td><?php echo $name; ?></td>
<td><?php echo $qsos; ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
<?php else: ?>
<div class="col-md-12 result">
<h5>State Check Results</h5>
<p>No issues found. All QSOs have proper state information.</p>
</div>
<?php endif; ?>

View File

@@ -2119,7 +2119,7 @@ function saveOptions() {
$('#closeButton').prop("disabled", false);
// Create a nice display for the results
let resultHtml = '<h5>Continent Check Results</h5>';
resultHtml += '<p><strong>QSOs without missing or invalid continent information found:</strong> ' + (response[0].count) + '</p>';
resultHtml += '<p><strong>QSOs with missing or invalid continent information found:</strong> ' + (response[0].count) + '</p>';
$('.result').html(resultHtml);
},
@@ -2140,3 +2140,74 @@ function saveOptions() {
}
});
}
function checkFixState() {
$('#checkFixStateBtn').prop("disabled", true).addClass("running");
$('#closeButton').prop("disabled", true);
$.ajax({
url: base_url + 'index.php/logbookadvanced/checkDb',
data: {
type: 'checkstate'
},
type: 'POST',
success: function(response) {
$('#checkFixStateBtn').prop("disabled", false).removeClass("running");
$('#closeButton').prop("disabled", false);
$('.result').html(response);
},
error: function(xhr, status, error) {
$('#checkFixStateBtn').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 checkFixState2() {
$('#checkFixStateBtn').prop("disabled", true).addClass("running");
$('#closeButton').prop("disabled", true);
$.ajax({
url: base_url + 'index.php/logbookadvanced/checkDb',
data: {
type: 'checkstate'
},
type: 'POST',
success: function(response) {
$('#checkFixStateBtn').prop("disabled", false).removeClass("running");
$('#closeButton').prop("disabled", false);
// Create a nice display for the results
let resultHtml = '<h5>State Check Results</h5>';
resultHtml += '<p><strong>QSOs with missing state and gridsquares with 6 or more characters found:</strong> ' + (response[0].count) + '</p>';
$('.result').html(resultHtml);
},
error: function(xhr, status, error) {
$('#checkFixStateBtn').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
});
}
});
}