diff --git a/application/controllers/Logbookadvanced.php b/application/controllers/Logbookadvanced.php index e19768668..0cd00b110 100644 --- a/application/controllers/Logbookadvanced.php +++ b/application/controllers/Logbookadvanced.php @@ -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'] = ''; + + header("Content-Type: application/json"); + print json_encode($result); + } + } diff --git a/application/models/Logbookadvanced_model.php b/application/models/Logbookadvanced_model.php index 6415c3324..a2a05b5d5 100644 --- a/application/models/Logbookadvanced_model.php +++ b/application/models/Logbookadvanced_model.php @@ -1,5 +1,6 @@ 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; + } } diff --git a/application/views/logbookadvanced/checkresult.php b/application/views/logbookadvanced/checkresult.php index 8353786a7..a7ce37d6b 100644 --- a/application/views/logbookadvanced/checkresult.php +++ b/application/views/logbookadvanced/checkresult.php @@ -1,4 +1,14 @@ 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) { ?>
+
+ "; + echo __("Execution time: ") . round($result['execution_time'], 2) . "s.
"; + echo __("Number of potential QSOs with wrong DXCC: ") . count($result['result']); + + if ($result) { ?> +
+ +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
' . htmlspecialchars($qso['callsign']) . ''; ?>
+
+ + +
-
+
@@ -80,17 +80,16 @@
-
+

-

-
- config->item('callbook_batch_lookup') ?? true): ?> + config->item('callbook_batch_lookup') ?? true) && $this->config->item('callbook')): ?>
@@ -107,7 +106,7 @@
-
+
diff --git a/assets/js/sections/logbookadvanced.js b/assets/js/sections/logbookadvanced.js index 4d4ac7834..01fee69f6 100644 --- a/assets/js/sections/logbookadvanced.js +++ b/assets/js/sections/logbookadvanced.js @@ -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(''); + $('#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); + } + }); + }