mirror of
https://github.com/wavelog/wavelog.git
synced 2026-03-22 10:24:14 +00:00
Merge pull request #2714 from AndreasK79/dbtools_dxcc_fix
Dbtools dxcc fix
This commit is contained in:
@@ -992,4 +992,17 @@ class Logbookadvanced extends CI_Controller {
|
||||
$this->load->view('logbookadvanced/dupesearchdialog');
|
||||
}
|
||||
|
||||
function fixDxccSelected() {
|
||||
if(!clubaccess_check(9)) return;
|
||||
|
||||
$ids = xss_clean($this->input->post('ids'));
|
||||
|
||||
$this->load->model('logbookadvanced_model');
|
||||
$result = $this->logbookadvanced_model->fixDxccSelected($ids);
|
||||
$result['message'] = '<div class="alert alert-' . ($result['count'] == 0 ? 'danger' : 'success') . '" role="alert">' . sprintf(__("DXCC updated for %d QSO(s)."), $result['count']) . '</div>';
|
||||
|
||||
header("Content-Type: application/json");
|
||||
print json_encode($result);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
use Wavelog\QSLManager\QSO;
|
||||
use Wavelog\Dxcc\Dxcc;
|
||||
|
||||
class Logbookadvanced_model extends CI_Model {
|
||||
|
||||
@@ -1536,8 +1537,10 @@ class Logbookadvanced_model extends CI_Model {
|
||||
return $this->check_missing_distance();
|
||||
case 'checkcontinent':
|
||||
return $this->check_qsos_missing_continent();
|
||||
case 'checkdxcc':
|
||||
case 'checkmissingdxcc':
|
||||
return $this->check_missing_dxcc();
|
||||
case 'checkdxcc':
|
||||
return $this->check_dxcc();
|
||||
case 'checkstate':
|
||||
return $this->check_missing_state();
|
||||
case 'checkcqzones':
|
||||
@@ -1887,4 +1890,94 @@ class Logbookadvanced_model extends CI_Model {
|
||||
|
||||
return $query->result();
|
||||
}
|
||||
|
||||
public function check_dxcc() {
|
||||
|
||||
$i = 0;
|
||||
$result = array();
|
||||
|
||||
$callarray = $this->getQsos();
|
||||
|
||||
// Starting clock time in seconds
|
||||
$start_time = microtime(true);
|
||||
$dxccobj = new Dxcc(null);
|
||||
|
||||
foreach ($callarray->result() as $call) {
|
||||
|
||||
$i++;
|
||||
$dxcc = $dxccobj->dxcc_lookup($call->col_call, $call->date);
|
||||
|
||||
$dxcc['adif'] = (isset($dxcc['adif'])) ? $dxcc['adif'] : 0;
|
||||
$dxcc['entity'] = (isset($dxcc['entity'])) ? $dxcc['entity'] : 'None';
|
||||
|
||||
if ($call->col_dxcc != $dxcc['adif']) {
|
||||
$result[] = array(
|
||||
'callsign' => $call->col_call,
|
||||
'qso_date' => $call->date,
|
||||
'station_profile' => $call->station_profile_name,
|
||||
'existing_dxcc' => $call->col_country,
|
||||
'existing_adif' => $call->col_dxcc,
|
||||
'result_country' => ucwords(strtolower($dxcc['entity']), "- (/"),
|
||||
'result_adif' => $dxcc['adif'],
|
||||
'id' => $call->col_primary_key,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// End clock time in seconds
|
||||
$end_time = microtime(true);
|
||||
|
||||
// Calculate script execution time
|
||||
$execution_time = ($end_time - $start_time);
|
||||
|
||||
$data['execution_time'] = $execution_time;
|
||||
$data['calls_tested'] = $i;
|
||||
$data['result'] = $result;
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
function getQsos() {
|
||||
$sql = 'select distinct col_country, col_call, col_dxcc, date(col_time_on) date, station_profile.station_profile_name, col_primary_key
|
||||
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 = ?';
|
||||
$params[] = array($this->session->userdata('user_id'));
|
||||
|
||||
$sql .= ' order by station_profile.station_profile_name asc, date desc';
|
||||
|
||||
$query = $this->db->query($sql, $params);
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
function fixDxccSelected($ids) {
|
||||
$sql = "select COL_PRIMARY_KEY, COL_CALL, COL_TIME_ON, COL_TIME_OFF, station_profile.station_profile_name 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 " . $this->config->item('table_name') . ".col_primary_key in ?";
|
||||
|
||||
$r = $this->db->query($sql, array($this->session->userdata('user_id'), json_decode($ids, true)));
|
||||
|
||||
$count = 0;
|
||||
$dxccobj = new Dxcc(null);
|
||||
|
||||
if ($r->num_rows() > 0) { //query dxcc_prefixes
|
||||
$sql = "update " . $this->config->item('table_name') . " set COL_COUNTRY = ?, COL_DXCC = ? where COL_PRIMARY_KEY = ?";
|
||||
$q = $this->db->conn_id->prepare($sql);
|
||||
foreach ($r->result_array() as $row) {
|
||||
$qso_date = $row['COL_TIME_OFF'] == '' ? $row['COL_TIME_ON'] : $row['COL_TIME_OFF'];
|
||||
$qso_date = date("Y-m-d", strtotime($qso_date));
|
||||
$dxcc = $dxccobj->dxcc_lookup($row['COL_CALL'], $qso_date);
|
||||
$dxcc['adif'] = (isset($dxcc['adif'])) ? $dxcc['adif'] : 0;
|
||||
$dxcc['entity'] = (isset($dxcc['entity'])) ? $dxcc['entity'] : 'None';
|
||||
if ($dxcc['adif'] != 'Not Found') {
|
||||
$q->execute(array(addslashes(ucwords(strtolower($dxcc['entity']), "- (/")), $dxcc['adif'], $row['COL_PRIMARY_KEY']));
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$result['count'] = $count;
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,14 @@
|
||||
<?php
|
||||
// Get Date format
|
||||
if($this->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');
|
||||
}
|
||||
|
||||
|
||||
switch ($type) {
|
||||
case 'checkdistance':
|
||||
check_missing_distance($result);
|
||||
@@ -6,7 +16,7 @@ switch ($type) {
|
||||
case 'checkcontinent':
|
||||
check_qsos_missing_continent($result);
|
||||
break;
|
||||
case 'checkdxcc':
|
||||
case 'checkmissingdxcc':
|
||||
check_missing_dxcc($result);
|
||||
break;
|
||||
case 'checkcqzones':
|
||||
@@ -18,6 +28,9 @@ switch ($type) {
|
||||
case 'checkgrids':
|
||||
check_missing_grids($result);
|
||||
break;
|
||||
case 'checkdxcc':
|
||||
check_dxcc($result, $custom_date_format);
|
||||
break;
|
||||
default:
|
||||
// Invalid type
|
||||
break;
|
||||
@@ -97,3 +110,47 @@ function check_missing_grids($result) { ?>
|
||||
<?= __("Update now") ?><div class="ld ld-ring ld-spin"></div>
|
||||
</button>
|
||||
<?php }
|
||||
|
||||
function check_dxcc($result, $custom_date_format) { ?>
|
||||
<h5><?= __("DXCC Check Results") ?></h5>
|
||||
<?php
|
||||
echo __("Callsigns tested: ") . $result['calls_tested'] . ". <br />";
|
||||
echo __("Execution time: ") . round($result['execution_time'], 2) . "s. <br />";
|
||||
echo __("Number of potential QSOs with wrong DXCC: ") . count($result['result']);
|
||||
|
||||
if ($result) { ?>
|
||||
<br />
|
||||
<button type="button" class="mt-2 mb-2 btn btn-sm btn-primary ld-ext-right" id="fixSelectedDxccBtn" onclick="fixDxccSelected(true)">
|
||||
<?= __("Update selected") ?><div class="ld ld-ring ld-spin"></div>
|
||||
</button>
|
||||
<div class="dxcctablediv"></div>
|
||||
|
||||
<div class="table-responsive" style="max-height:60vh; overflow:auto;">
|
||||
<table class="table table-sm table-striped table-bordered table-condensed" id="dxccCheckTable">
|
||||
<thead>
|
||||
<tr>
|
||||
<th><div class="form-check"><input class="form-check-input mt-2" type="checkbox" id="checkBoxAllDxcc" /></div></th>
|
||||
<th><?= __("Callsign"); ?></th>
|
||||
<th><?= __("QSO Date"); ?></th>
|
||||
<th><?= __("Station Profile"); ?></th>
|
||||
<th><?= __("Existing DXCC"); ?></th>
|
||||
<th><?= __("Result DXCC"); ?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($result['result'] as $qso): ?>
|
||||
<tr id="qsoID-<?php echo $qso['id']; ?>">
|
||||
<td><div class="form-check"><input class="row-check form-check-input mt-1" type="checkbox" /></div></td>
|
||||
<td><?php echo '<a id="edit_qso" href="javascript:displayQso(' . $qso['id'] . ')">' . htmlspecialchars($qso['callsign']) . '</a>'; ?></td>
|
||||
<td><?php echo date($custom_date_format, strtotime($qso['qso_date'])); ?></td>
|
||||
<td><?php echo $qso['station_profile']; ?></td>
|
||||
<td><?php echo htmlspecialchars(ucwords(strtolower($qso['existing_dxcc']), "- (/"), ENT_QUOTES, 'UTF-8'); ?></td>
|
||||
<td><?php echo htmlspecialchars(ucwords(strtolower($qso['result_country']), "- (/"), ENT_QUOTES, 'UTF-8'); ?></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<?php }
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<div class="container">
|
||||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<div class="col-md-5">
|
||||
<h5><?= __("Data Repair Tools") ?>
|
||||
<a href="https://github.com/wavelog/wavelog/wiki/Advanced-Logbook#database-tools-dbtools" target="_blank" rel="noopener noreferrer" class="btn btn-sm btn-info me-1 ld-ext-right">
|
||||
<?= __("Wiki Help") ?></a>
|
||||
@@ -80,17 +80,16 @@
|
||||
|
||||
<div class="list-group-item d-flex justify-content-between align-items-center">
|
||||
<div>
|
||||
<h6 class="mb-1"><?= __("Re-check DXCC for all QSOs in the logbook") ?></h6>
|
||||
<h6 class="mb-1"><?= __("Check all QSOs in the logbook for incorrect DXCC") ?></h6>
|
||||
<p class="mb-1 small text-muted"><?= __("Use Wavelog to determine DXCC for all QSOs.") ?></p>
|
||||
<p class="mb-1 small alert-danger"><?= __("This will overwrite ALL existing DXCC information!") ?></p>
|
||||
</div>
|
||||
<div class="d-flex nowrap">
|
||||
<button type="button" class="btn btn-sm btn-primary me-1 ld-ext-right" id="updateDxccBtn" onclick="fixMissingDxcc(true)">
|
||||
<?= __("Run") ?><div class="ld ld-ring ld-spin"></div>
|
||||
<button type="button" class="btn btn-sm btn-success me-1 ld-ext-right" id="checkDxccBtn" onclick="checkDxcc()">
|
||||
<?= __("Check") ?><div class="ld ld-ring ld-spin"></div>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<?php if ($this->config->item('callbook_batch_lookup') ?? true): ?>
|
||||
<?php if (($this->config->item('callbook_batch_lookup') ?? true) && $this->config->item('callbook')): ?>
|
||||
<div class="list-group-item d-flex justify-content-between align-items-center">
|
||||
<div>
|
||||
<h6 class="mb-1"><?= __("Lookup QSOs with missing grid in callbook") ?></h6>
|
||||
@@ -107,7 +106,7 @@
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6 result"></div>
|
||||
<div class="col-md-7 result"></div>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
@@ -1319,7 +1319,7 @@ $(document).ready(function () {
|
||||
success: function (html) {
|
||||
BootstrapDialog.show({
|
||||
title: 'Database tools',
|
||||
size: BootstrapDialog.SIZE_WIDE,
|
||||
size: BootstrapDialog.SIZE_EXTRAWIDE,
|
||||
cssClass: 'options',
|
||||
nl2br: false,
|
||||
message: html,
|
||||
@@ -2059,7 +2059,7 @@ function saveOptions() {
|
||||
$.ajax({
|
||||
url: base_url + 'index.php/logbookadvanced/checkDb',
|
||||
data: {
|
||||
type: 'checkdxcc'
|
||||
type: 'checkmissingdxcc'
|
||||
},
|
||||
type: 'POST',
|
||||
success: function(response) {
|
||||
@@ -2514,3 +2514,108 @@ function saveOptions() {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function checkDxcc() {
|
||||
$('#checkDxccBtn').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) {
|
||||
$('#checkDxccBtn').prop("disabled", false).removeClass("running");
|
||||
$('#closeButton').prop("disabled", false);
|
||||
$('.result').html(response);
|
||||
rebind_checkbox_trigger_dxcc();
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
$('#checkDxccBtn').prop('disabled', false).text('<?= __("Check") ?>');
|
||||
$('#closeButton').prop('disabled', false);
|
||||
|
||||
let errorMsg = 'Error checking DXCC information';
|
||||
if (xhr.responseJSON && xhr.responseJSON.message) {
|
||||
errorMsg += ': ' + xhr.responseJSON.message;
|
||||
}
|
||||
|
||||
BootstrapDialog.alert({
|
||||
title: 'Error',
|
||||
message: errorMsg,
|
||||
type: BootstrapDialog.TYPE_DANGER
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function rebind_checkbox_trigger_dxcc() {
|
||||
$('#checkBoxAllDxcc').change(function (event) {
|
||||
if (this.checked) {
|
||||
$('#dxccCheckTable tbody tr').each(function (i) {
|
||||
selectQsoIDDxcc($(this).first().closest('tr').attr('id')?.replace(/\D/g, ''));
|
||||
});
|
||||
} else {
|
||||
$('#dxccCheckTable tbody tr').each(function (i) {
|
||||
unselectQsoIDDxcc($(this).first().closest('tr').attr('id')?.replace(/\D/g, ''));
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function selectQsoIDDxcc(qsoID) {
|
||||
var element = $("#qsoID-" + qsoID);
|
||||
element.find("input[type=checkbox]").prop("checked", true);
|
||||
element.addClass('activeRow');
|
||||
}
|
||||
|
||||
function unselectQsoIDDxcc(qsoID) {
|
||||
var element = $("#qsoID-" + qsoID);
|
||||
element.find("input[type=checkbox]").prop("checked", false);
|
||||
element.removeClass('activeRow');
|
||||
$('#checkBoxAllDxcc').prop("checked", false);
|
||||
}
|
||||
|
||||
function fixDxccSelected() {
|
||||
let id_list = [];
|
||||
$('#dxccCheckTable tbody input:checked').each(function () {
|
||||
let id = $(this).closest('tr').attr('id')?.replace(/\D/g, '');
|
||||
id_list.push(id);
|
||||
});
|
||||
|
||||
if (id_list.length === 0) {
|
||||
BootstrapDialog.alert({
|
||||
title: lang_gen_advanced_logbook_info,
|
||||
message: lang_gen_advanced_logbook_select_at_least_one_row,
|
||||
type: BootstrapDialog.TYPE_INFO,
|
||||
closable: false,
|
||||
draggable: false,
|
||||
callback: function (result) {
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
$('#fixSelectedDxccBtn').prop("disabled", true).addClass("running");
|
||||
$('#closeButton').prop("disabled", true);
|
||||
|
||||
$.ajax({
|
||||
url: base_url + 'index.php/logbookadvanced/fixDxccSelected',
|
||||
type: 'post',
|
||||
data: {'ids': JSON.stringify(id_list, null, 2)},
|
||||
success: function(data) {
|
||||
$('#fixSelectedDxccBtn').prop("disabled", false).removeClass("running");
|
||||
$('#closeButton').prop("disabled", false);
|
||||
id_list.forEach(function(id) {
|
||||
let row = $("#dxccCheckTable tbody tr#qsoID-" + id);
|
||||
row.remove();
|
||||
});
|
||||
$('.dxcctablediv').html(data.message);
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
$('#fixSelectedDxccBtn').prop("disabled", false).removeClass("running");
|
||||
$('#closeButton').prop("disabled", false);
|
||||
$('.result').html(error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user