mirror of
https://github.com/wavelog/wavelog.git
synced 2026-03-22 10:24:14 +00:00
Add POTA ref import function
This commit is contained in:
@@ -355,6 +355,74 @@ class adif extends CI_Controller {
|
||||
$this->load->view('interface_assets/footer');
|
||||
}
|
||||
}
|
||||
|
||||
public function pota() {
|
||||
$this->load->model('stations');
|
||||
$data['station_profile'] = $this->stations->all_of_user();
|
||||
|
||||
$data['page_title'] = __("POTA Import");
|
||||
$data['tab'] = "potab";
|
||||
|
||||
$config['upload_path'] = './uploads/';
|
||||
$config['allowed_types'] = 'adi|ADI|adif|ADIF';
|
||||
|
||||
$this->load->library('upload', $config);
|
||||
|
||||
if ( ! $this->upload->do_upload()) {
|
||||
$data['error'] = $this->upload->display_errors();
|
||||
|
||||
$data['max_upload'] = ini_get('upload_max_filesize');
|
||||
|
||||
$this->load->view('interface_assets/header', $data);
|
||||
$this->load->view('adif/import', $data);
|
||||
$this->load->view('interface_assets/footer');
|
||||
} else {
|
||||
$data = array('upload_data' => $this->upload->data());
|
||||
|
||||
ini_set('memory_limit', '-1');
|
||||
set_time_limit(0);
|
||||
|
||||
$this->load->model('logbook_model');
|
||||
|
||||
if (!$this->load->is_loaded('adif_parser')) {
|
||||
$this->load->library('adif_parser');
|
||||
}
|
||||
|
||||
$this->adif_parser->load_from_file('./uploads/'.$data['upload_data']['file_name']);
|
||||
|
||||
$this->adif_parser->initialize();
|
||||
$error_count = array(0, 0, 0);
|
||||
$custom_errors = "";
|
||||
while($record = $this->adif_parser->get_record())
|
||||
{
|
||||
if(count($record) == 0) {
|
||||
break;
|
||||
};
|
||||
|
||||
$pota_result = $this->logbook_model->update_pota($record);
|
||||
if (!empty($pota_result)) {
|
||||
switch ($pota_result[0]) {
|
||||
case 0:
|
||||
$error_count[0]++;
|
||||
break;
|
||||
case 1:
|
||||
$error_count[1]++;
|
||||
break;
|
||||
case 2:
|
||||
$custom_errors .= $pota_result[1];
|
||||
$error_count[2]++;
|
||||
}
|
||||
}
|
||||
};
|
||||
unlink('./uploads/'.$data['upload_data']['file_name']);
|
||||
$data['pota_error_count'] = $error_count;
|
||||
$data['pota_errors'] = $custom_errors;
|
||||
$data['page_title'] = __("POTA Data Imported");
|
||||
$this->load->view('interface_assets/header', $data);
|
||||
$this->load->view('adif/pota_success');
|
||||
$this->load->view('interface_assets/footer');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* End of file adif.php */
|
||||
|
||||
@@ -4840,6 +4840,55 @@ class Logbook_model extends CI_Model {
|
||||
}
|
||||
}
|
||||
|
||||
function update_pota($record) {
|
||||
$this->load->model('logbooks_model');
|
||||
$custom_date_format = $this->session->userdata('user_date_format');
|
||||
$logbooks_locations_array = $this->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook'));
|
||||
|
||||
if (isset($record['call'])) {
|
||||
$call = strtoupper($record['call']);
|
||||
} else {
|
||||
return array(3, 'Callsign not found');
|
||||
}
|
||||
|
||||
// Join date+time
|
||||
$time_on = date('Y-m-d', strtotime($record['qso_date'])) . " " . date('H:i', strtotime($record['time_on']));
|
||||
|
||||
// Store Band
|
||||
if (isset($record['band'])) {
|
||||
$band = strtolower($record['band']);
|
||||
} else {
|
||||
$band = '';
|
||||
}
|
||||
|
||||
if (isset($record['mode'])) {
|
||||
$mode = $record['mode'];
|
||||
} else {
|
||||
$mode = '';
|
||||
}
|
||||
|
||||
if (isset($record['pota_ref'])) {
|
||||
$pota_ref = $record['pota_ref'];
|
||||
} else {
|
||||
$pota_ref = '';
|
||||
}
|
||||
|
||||
if ($pota_ref != '') {
|
||||
$sql = "SELECT COL_PRIMARY_KEY, COL_POTA_REF FROM ".$this->config->item('table_name')." WHERE COL_CALL = ? AND COL_TIME_ON >= DATE_ADD(DATE_FORMAT(?, '%Y-%m-%d %H:%i' ), INTERVAL -15 MINUTE) AND COL_TIME_ON <= DATE_ADD(DATE_FORMAT(?, '%Y-%m-%d %H:%i' ), INTERVAL +15 MINUTE) AND UPPER(COL_BAND) = ? AND UPPER(COL_MODE) = ? AND station_id IN ?;";
|
||||
$check = $this->db->query($sql, array($call, $time_on, $time_on, strtoupper($band), strtoupper($mode), $logbooks_locations_array));
|
||||
if ($check->num_rows() != 1) {
|
||||
return array(2, $result['message'] = "<tr><td>" . date($custom_date_format, strtotime($record['qso_date'])) . "</td><td>" . date('H:i', strtotime($record['time_on'])) . "</td><td>" . str_replace('0', 'Ø', $call) . "</td><td>" . $band . "</td><td>" . $mode . "</td><td></td><td><a href='https://pota.app/#/park/".$pota_ref."' _target='_blank'>".$pota_ref."</a></td><td>" . __("QSO could not be matched") . "</td></tr>");
|
||||
} else {
|
||||
if (str_contains(($check->row()->COL_POTA_REF ?? ''), $pota_ref)) {
|
||||
return array(1, $result['message'] = "<tr><td>" . date($custom_date_format, strtotime($record['qso_date'])) . "</td><td>" . date('H:i', strtotime($record['time_on'])) . "</td><td>" . str_replace('0', 'Ø', $call) . "</td><td>" . $band . "</td><td>" . $mode . "</td><td>".$check->row()->COL_POTA_REF."</td><td><a href='https://pota.app/#/park/".$pota_ref."' _target='_blank'>".$pota_ref."</a></td><td>" . __("POTA reference already in log") . "</td></tr>");
|
||||
} else {
|
||||
$this->set_pota_ref($check->row()->COL_PRIMARY_KEY, $check->row()->COL_POTA_REF, $pota_ref);
|
||||
return array(0, $result['message'] = "<tr><td>" . date($custom_date_format, strtotime($record['qso_date'])) . "</td><td>" . date('H:i', strtotime($record['time_on'])) . "</td><td>" . str_replace('0', 'Ø', $call) . "</td><td>" . $band . "</td><td>" . $mode . "</td><td>".$check->row()->COL_POTA_REF."</td><td><a href='https://pota.app/#/park/".$pota_ref."' _target='_blank'>".$pota_ref."</a></td><td>" . __("QSO updated") . " (" . $check->row()->COL_POTA_REF . ($check->row()->COL_POTA_REF != '' ? ',' : "") . $pota_ref . ")</td></tr>");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function set_dok($key, $dok) {
|
||||
$data = array(
|
||||
'COL_DARC_DOK' => $dok,
|
||||
@@ -4850,6 +4899,21 @@ class Logbook_model extends CI_Model {
|
||||
return;
|
||||
}
|
||||
|
||||
function set_pota_ref($key, $existing_pota, $new_pota) {
|
||||
if ($existing_pota == '') {
|
||||
$data = array(
|
||||
'COL_POTA_REF' => $new_pota,
|
||||
);
|
||||
} else {
|
||||
$data = array(
|
||||
'COL_POTA_REF' => $existing_pota.",".$new_pota,
|
||||
);
|
||||
}
|
||||
$this->db->where(array('COL_PRIMARY_KEY' => $key));
|
||||
$this->db->update($this->config->item('table_name'), $data);
|
||||
return;
|
||||
}
|
||||
|
||||
function get_main_mode_from_mode($mode) {
|
||||
return ($this->get_main_mode_if_submode($mode) == null ? $mode : $this->get_main_mode_if_submode($mode));
|
||||
}
|
||||
|
||||
@@ -35,6 +35,15 @@
|
||||
echo 'false';
|
||||
} ?>"><?= __("DARC DCL") ?></a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link <?php if ($showtab == 'potab') {
|
||||
echo 'active';
|
||||
} ?>" id="potab-tab" data-bs-toggle="tab" href="#potab" role="tab" aria-controls="potab" aria-selected="<?php if ($showtab == 'potab') {
|
||||
echo 'true';
|
||||
} else {
|
||||
echo 'false';
|
||||
} ?>"><?= __("POTA") ?></a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link <?php if ($showtab == 'cbr') {
|
||||
echo 'active';
|
||||
@@ -356,6 +365,25 @@
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="tab-pane <?php if ($showtab == 'potab') {
|
||||
echo 'active';
|
||||
} else {
|
||||
echo 'fade';
|
||||
} ?>" id="potab" role="tabpanel" aria-labelledby="potab-tab">
|
||||
<?php if (isset($error) && $showtab == 'potab') { ?>
|
||||
<div class="alert alert-danger" role="alert">
|
||||
<?php echo $error; ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<p><span class="badge text-bg-warning"><?= __("Important") ?></span> <?= ("This function can be used to import POTA references from POTA hunter log in ADIF format. It will only import references for existing QSOs. It will not import QSO data itself.") ?></p>
|
||||
<form class="form" action="<?php echo site_url('adif/pota'); ?>" method="post" enctype="multipart/form-data">
|
||||
|
||||
<input class="form-control w-auto mb-2 me-sm-2" type="file" name="userfile" size="20" />
|
||||
<button type="submit" class="btn btn-sm btn-primary mb-2" value="Upload"><?= __("Upload") ?></button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="tab-pane <?php if ($showtab == 'cbr') {
|
||||
echo 'active';
|
||||
} else {
|
||||
|
||||
45
application/views/adif/pota_success.php
Normal file
45
application/views/adif/pota_success.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<div class="container">
|
||||
<br>
|
||||
<?php if($this->session->flashdata('message')) { ?>
|
||||
<!-- Display Message -->
|
||||
<div class="alert-message error">
|
||||
<p><?php echo $this->session->flashdata('message'); ?></p>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<?= __("Results of POTA Update");?>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<?php if($pota_error_count[0] > 0) { ?>
|
||||
<h3 class="card-title"><?= __("Yay, its updated!"); ?></h3>
|
||||
<p class="card-text"><?= __("POTA references for existing QSOs has been updated.")?></p>
|
||||
<?php } else { ?>
|
||||
<h3 class="card-title"><?= __("No QSOs found which could be updated.")?></h3>
|
||||
<?php } ?>
|
||||
<div class="alert alert-info" role="alert">
|
||||
<?= __("QSOs updated")?>: <?php echo $pota_error_count[0] ?> / <?= __("QSOs ignored")?>: <?php echo $pota_error_count[1] ?> / <?= __("QSOs unmatched")?>: <?php echo $pota_error_count[2] ?>
|
||||
</div>
|
||||
<?php if($pota_errors) { ?>
|
||||
<h3><?= __("POTA Update Errors")?></h3>
|
||||
<p><?= __("There is different data for POTA references in your log compared to imported data or QSO data could not be matched")?></p>
|
||||
<table width="100%">
|
||||
<tr class="titles">
|
||||
<td><?= __("Date"); ?></td>
|
||||
<td><?= __("Time"); ?></td>
|
||||
<td><?= __("Call"); ?></td>
|
||||
<td><?= __("Band"); ?></td>
|
||||
<td><?= __("Mode"); ?></td>
|
||||
<td><?= __("POTA REF in Log"); ?></td>
|
||||
<td><?= __("POTA REF in ADIF"); ?></td>
|
||||
<td><?= __("Status"); ?></td>
|
||||
</tr>
|
||||
<?php echo $pota_errors; ?>
|
||||
</table>
|
||||
<?php } ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
Reference in New Issue
Block a user