Merge pull request #923 from int2001/exportall

Export all QSOs (of User) when chosing "Select station location"
This commit is contained in:
Joerg (DJ7NT)
2024-09-11 11:38:24 +02:00
committed by GitHub
4 changed files with 181 additions and 165 deletions

1
.gitignore vendored
View File

@@ -2,6 +2,7 @@
/application/config/config.php
/application/logs/*
/application/cache/*
/backup/*.adi
/uploads
/uploads/*.adi
/uploads/*.ADI

View File

@@ -42,7 +42,7 @@ class adif extends CI_Controller {
$this->load->model('adif_data');
$data['qsos'] = $this->adif_data->export_all();
$data['qsos'] = $this->adif_data->export_all(null, $this->input->post('from', true), $this->input->post('to', true));
$this->load->view('adif/data/exportall', $data);
}
@@ -83,10 +83,10 @@ class adif extends CI_Controller {
$station_id = $this->security->xss_clean($this->input->post('station_profile'));
// Used for exporting QSOs not previously exported to LoTW
if ($this->input->post('exportLotw') == 1) {
$exportLotw = true;
} else {
$exportLotw = false;
if ($this->input->post('exportLotw') == 1) {
$exportLotw = true;
} else {
$exportLotw = false;
}
$data['qsos'] = $this->adif_data->export_custom($this->input->post('from'), $this->input->post('to'), $station_id, $exportLotw);
@@ -95,29 +95,29 @@ class adif extends CI_Controller {
if ($this->input->post('markLotw') == 1) {
foreach ($data['qsos']->result() as $qso)
{
$this->adif_data->mark_lotw_sent($qso->COL_PRIMARY_KEY);
}
}
}
foreach ($data['qsos']->result() as $qso)
{
$this->adif_data->mark_lotw_sent($qso->COL_PRIMARY_KEY);
}
}
}
public function mark_lotw() {
// Set memory limit to unlimited to allow heavy usage
ini_set('memory_limit', '-1');
public function mark_lotw() {
// Set memory limit to unlimited to allow heavy usage
ini_set('memory_limit', '-1');
$station_id = $this->security->xss_clean($this->input->post('station_profile'));
$this->load->model('adif_data');
$this->load->model('adif_data');
$data['qsos'] = $this->adif_data->export_custom($this->input->post('from'), $this->input->post('to'), $station_id);
$data['qsos'] = $this->adif_data->export_custom($this->input->post('from'), $this->input->post('to'), $station_id);
foreach ($data['qsos']->result() as $qso)
{
$this->adif_data->mark_lotw_sent($qso->COL_PRIMARY_KEY);
}
foreach ($data['qsos']->result() as $qso)
{
$this->adif_data->mark_lotw_sent($qso->COL_PRIMARY_KEY);
}
$this->load->view('adif/mark_lotw', $data);
}
$this->load->view('adif/mark_lotw', $data);
}
public function export_lotw()
{
@@ -146,8 +146,8 @@ class adif extends CI_Controller {
$data['max_upload'] = ini_get('upload_max_filesize');
$data['station_profile'] = $this->stations->all_of_user();
$active_station_id = $this->stations->find_active();
$station_profile = $this->stations->profile($active_station_id);
$active_station_id = $this->stations->find_active();
$station_profile = $this->stations->profile($active_station_id);
$data['active_station_info'] = $station_profile->row();
$data['active_station_id'] = $active_station_id;
@@ -330,7 +330,7 @@ class adif extends CI_Controller {
$this->load->view('adif/dcl_success');
$this->load->view('interface_assets/footer');
}
}
}
}
/* End of file adif.php */

View File

@@ -2,51 +2,62 @@
class adif_data extends CI_Model {
function export_all($api_key = null) {
$CI =& get_instance();
$CI->load->model('logbooks_model');
if ($api_key != null) {
$CI->load->model('api_model');
if (strpos($this->api_model->access($api_key), 'r') !== false) {
$this->api_model->update_last_used($api_key);
$user_id = $this->api_model->key_userid($api_key);
$logbooks_locations_array = $this->list_station_locations($user_id);
}
} else {
$logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook'));
}
$this->db->select($this->config->item('table_name').'.*, station_profile.*, dxcc_entities.name as station_country');
$this->db->order_by("COL_TIME_ON", "ASC");
$this->db->join('station_profile', 'station_profile.station_id = '.$this->config->item('table_name').'.station_id');
$this->db->where_in('station_profile.station_id', $logbooks_locations_array);
$this->db->join('dxcc_entities', 'station_profile.station_dxcc = dxcc_entities.adif');
$query = $this->db->get($this->config->item('table_name'));
return $query;
}
function list_station_locations($user_id) {
$this->db->where('user_id', $user_id);
$query = $this->db->get('station_profile');
if ($query->num_rows() == 0) {
return array();
function export_all($api_key = null,$from = null, $to = null, $exportLotw = false) {
$this->load->model('logbooks_model');
if ($api_key != null) {
$this->load->model('api_model');
if (strpos($this->api_model->access($api_key), 'r') !== false) {
$this->api_model->update_last_used($api_key);
$user_id = $this->api_model->key_userid($api_key);
$logbooks_locations_array = $this->list_station_locations($user_id);
}
} else {
$this->load->model('stations');
$logbooks_locations_array = $this->list_station_locations($this->session->userdata('user_id'));
}
$locations_array = array();
foreach ($query->result() as $row) {
array_push($locations_array, $row->station_id);
}
return $locations_array;
$this->db->select($this->config->item('table_name').'.*, station_profile.*, dxcc_entities.name as station_country');
$this->db->order_by("COL_TIME_ON", "ASC");
$this->db->join('station_profile', 'station_profile.station_id = '.$this->config->item('table_name').'.station_id');
if ($from) {
$this->db->where("date(".$this->config->item('table_name').".COL_TIME_ON) >= ", $from);
}
if ($to) {
$this->db->where("date(".$this->config->item('table_name').".COL_TIME_ON) <= ",$to);
}
if ($exportLotw) {
$this->db->group_start();
$this->db->where($this->config->item('table_name').".COL_LOTW_QSL_SENT != 'Y'");
$this->db->or_where($this->config->item('table_name').".COL_LOTW_QSL_SENT", NULL);
$this->db->group_end();
}
$this->db->where_in('station_profile.station_id', $logbooks_locations_array);
$this->db->join('dxcc_entities', 'station_profile.station_dxcc = dxcc_entities.adif');
$query = $this->db->get($this->config->item('table_name'));
return $query;
}
function export_printrequested($station_id = NULL) {
$this->load->model('stations');
$active_station_id = $this->stations->find_active();
function list_station_locations($user_id) {
$this->db->where('user_id', $user_id);
$query = $this->db->get('station_profile');
$this->db->select($this->config->item('table_name').'.*, station_profile.*, dxcc_entities.name as station_country');
if ($query->num_rows() == 0) {
return array();
}
$locations_array = array();
foreach ($query->result() as $row) {
array_push($locations_array, $row->station_id);
}
return $locations_array;
}
function export_printrequested($station_id = NULL) {
$this->load->model('stations');
$active_station_id = $this->stations->find_active();
$this->db->select($this->config->item('table_name').'.*, station_profile.*, dxcc_entities.name as station_country');
if ($station_id == NULL) {
$this->db->where($this->config->item('table_name').'.station_id', $active_station_id);
@@ -54,133 +65,136 @@ class adif_data extends CI_Model {
$this->db->where($this->config->item('table_name').'.station_id', $station_id);
}
$this->db->join('station_profile', 'station_profile.station_id = '.$this->config->item('table_name').'.station_id');
$this->db->join('dxcc_entities', 'station_profile.station_dxcc = dxcc_entities.adif');
// always filter user. this ensures that even if the station_id is from another user no inaccesible QSOs will be returned
$this->db->where('station_profile.user_id', $this->session->userdata('user_id'));
$this->db->where_in('COL_QSL_SENT', array('R', 'Q'));
$this->db->order_by("COL_TIME_ON", "ASC");
$query = $this->db->get($this->config->item('table_name'));
$this->db->join('station_profile', 'station_profile.station_id = '.$this->config->item('table_name').'.station_id');
$this->db->join('dxcc_entities', 'station_profile.station_dxcc = dxcc_entities.adif');
// always filter user. this ensures that even if the station_id is from another user no inaccesible QSOs will be returned
$this->db->where('station_profile.user_id', $this->session->userdata('user_id'));
$this->db->where_in('COL_QSL_SENT', array('R', 'Q'));
$this->db->order_by("COL_TIME_ON", "ASC");
$query = $this->db->get($this->config->item('table_name'));
return $query;
}
return $query;
}
function sat_all() {
$this->load->model('stations');
$active_station_id = $this->stations->find_active();
function sat_all() {
$this->load->model('stations');
$active_station_id = $this->stations->find_active();
$this->db->select(''.$this->config->item('table_name').'.*, station_profile.*, dxcc_entities.name as station_country');
$this->db->from($this->config->item('table_name'));
$this->db->where($this->config->item('table_name').'.station_id', $active_station_id);
$this->db->where($this->config->item('table_name').'.COL_PROP_MODE', 'SAT');
$this->db->select(''.$this->config->item('table_name').'.*, station_profile.*, dxcc_entities.name as station_country');
$this->db->from($this->config->item('table_name'));
$this->db->where($this->config->item('table_name').'.station_id', $active_station_id);
$this->db->where($this->config->item('table_name').'.COL_PROP_MODE', 'SAT');
$this->db->order_by($this->config->item('table_name').".COL_TIME_ON", "ASC");
$this->db->order_by($this->config->item('table_name').".COL_TIME_ON", "ASC");
$this->db->join('station_profile', 'station_profile.station_id = '.$this->config->item('table_name').'.station_id');
$this->db->join('dxcc_entities', 'station_profile.station_dxcc = dxcc_entities.adif', 'left outer');
$this->db->join('station_profile', 'station_profile.station_id = '.$this->config->item('table_name').'.station_id');
$this->db->join('dxcc_entities', 'station_profile.station_dxcc = dxcc_entities.adif', 'left outer');
return $this->db->get();
}
return $this->db->get();
}
function satellte_lotw() {
$this->load->model('stations');
$active_station_id = $this->stations->find_active();
function satellte_lotw() {
$this->load->model('stations');
$active_station_id = $this->stations->find_active();
$this->db->select(''.$this->config->item('table_name').'.*, station_profile.*, dxcc_entities.name as station_country');
$this->db->from($this->config->item('table_name'));
$this->db->where($this->config->item('table_name').'.station_id', $active_station_id);
$this->db->where($this->config->item('table_name').'.COL_PROP_MODE', 'SAT');
$this->db->select(''.$this->config->item('table_name').'.*, station_profile.*, dxcc_entities.name as station_country');
$this->db->from($this->config->item('table_name'));
$this->db->where($this->config->item('table_name').'.station_id', $active_station_id);
$this->db->where($this->config->item('table_name').'.COL_PROP_MODE', 'SAT');
$where = $this->config->item('table_name').".COL_LOTW_QSLRDATE IS NOT NULL";
$this->db->where($where);
$where = $this->config->item('table_name').".COL_LOTW_QSLRDATE IS NOT NULL";
$this->db->where($where);
$this->db->order_by($this->config->item('table_name').".COL_TIME_ON", "ASC");
$this->db->order_by($this->config->item('table_name').".COL_TIME_ON", "ASC");
$this->db->join('station_profile', 'station_profile.station_id = '.$this->config->item('table_name').'.station_id');
$this->db->join('dxcc_entities', 'station_profile.station_dxcc = dxcc_entities.adif', 'left outer');
$this->db->join('station_profile', 'station_profile.station_id = '.$this->config->item('table_name').'.station_id');
$this->db->join('dxcc_entities', 'station_profile.station_dxcc = dxcc_entities.adif', 'left outer');
return $this->db->get();
}
return $this->db->get();
}
function export_custom($from, $to, $station_id, $exportLotw = false) {
// be sure that station belongs to user
$CI =& get_instance();
$CI->load->model('Stations');
if (!$CI->Stations->check_station_is_accessible($station_id)) {
return;
}
function export_custom($from, $to, $station_id, $exportLotw = false) {
// be sure that station belongs to user
$this->load->model('Stations');
if ($station_id == 0) {
return $this->export_all($api_key = null,$from, $to, $exportLotw);
} else {
if (!$this->Stations->check_station_is_accessible($station_id)) {
return;
}
$this->db->select(''.$this->config->item('table_name').'.*, station_profile.*, dxcc_entities.name as station_country');
$this->db->from($this->config->item('table_name'));
$this->db->where($this->config->item('table_name').'.station_id', $station_id);
$this->db->select(''.$this->config->item('table_name').'.*, station_profile.*, dxcc_entities.name as station_country');
$this->db->from($this->config->item('table_name'));
$this->db->where($this->config->item('table_name').'.station_id', $station_id);
// If date is set, we format the date and add it to the where-statement
if ($from) {
$this->db->where("date(".$this->config->item('table_name').".COL_TIME_ON) >= '".$from."'");
}
if ($to) {
$this->db->where("date(".$this->config->item('table_name').".COL_TIME_ON) <= '".$to."'");
}
if ($exportLotw) {
$this->db->group_start();
$this->db->where($this->config->item('table_name').".COL_LOTW_QSL_SENT != 'Y'");
$this->db->or_where($this->config->item('table_name').".COL_LOTW_QSL_SENT", NULL);
$this->db->group_end();
}
// If date is set, we format the date and add it to the where-statement
if ($from) {
$this->db->where("date(".$this->config->item('table_name').".COL_TIME_ON) >= ", $from);
}
if ($to) {
$this->db->where("date(".$this->config->item('table_name').".COL_TIME_ON) <= ",$to);
}
if ($exportLotw) {
$this->db->group_start();
$this->db->where($this->config->item('table_name').".COL_LOTW_QSL_SENT != 'Y'");
$this->db->or_where($this->config->item('table_name').".COL_LOTW_QSL_SENT", NULL);
$this->db->group_end();
}
$this->db->order_by($this->config->item('table_name').".COL_TIME_ON", "ASC");
$this->db->order_by($this->config->item('table_name').".COL_TIME_ON", "ASC");
$this->db->join('station_profile', 'station_profile.station_id = '.$this->config->item('table_name').'.station_id');
$this->db->join('dxcc_entities', 'station_profile.station_dxcc = dxcc_entities.adif', 'left outer');
$this->db->join('station_profile', 'station_profile.station_id = '.$this->config->item('table_name').'.station_id');
$this->db->join('dxcc_entities', 'station_profile.station_dxcc = dxcc_entities.adif', 'left outer');
return $this->db->get();
}
return $this->db->get();
}
}
function export_past_id($station_id, $fetchfromid) {
//create query
$this->db->select(''.$this->config->item('table_name').'.*, station_profile.*, dxcc_entities.name as station_country');
$this->db->from($this->config->item('table_name'));
$this->db->where($this->config->item('table_name').'.station_id', $station_id);
$this->db->where($this->config->item('table_name').".COL_PRIMARY_KEY > " , $fetchfromid); //only get values past the fetchfromid value
$this->db->order_by($this->config->item('table_name').".COL_TIME_ON", "ASC");
$this->db->join('station_profile', 'station_profile.station_id = '.$this->config->item('table_name').'.station_id');
$this->db->join('dxcc_entities', 'station_profile.station_dxcc = dxcc_entities.adif', 'left outer');
function export_past_id($station_id, $fetchfromid) {
//create query
$this->db->select(''.$this->config->item('table_name').'.*, station_profile.*, dxcc_entities.name as station_country');
$this->db->from($this->config->item('table_name'));
$this->db->where($this->config->item('table_name').'.station_id', $station_id);
$this->db->where($this->config->item('table_name').".COL_PRIMARY_KEY > " , $fetchfromid); //only get values past the fetchfromid value
$this->db->order_by($this->config->item('table_name').".COL_TIME_ON", "ASC");
$this->db->join('station_profile', 'station_profile.station_id = '.$this->config->item('table_name').'.station_id');
$this->db->join('dxcc_entities', 'station_profile.station_dxcc = dxcc_entities.adif', 'left outer');
//return result
return $this->db->get();
}
//return result
return $this->db->get();
}
function export_lotw() {
$this->load->model('stations');
$active_station_id = $this->stations->find_active();
function export_lotw() {
$this->load->model('stations');
$active_station_id = $this->stations->find_active();
$this->db->select(''.$this->config->item('table_name').'.*, station_profile.*, dxcc_entities.name as station_country');
$this->db->from($this->config->item('table_name'));
$this->db->where($this->config->item('table_name').'.station_id', $active_station_id);
$this->db->group_start();
$this->db->where($this->config->item('table_name').".COL_LOTW_QSL_SENT != 'Y'");
$this->db->or_where($this->config->item('table_name').".COL_LOTW_QSL_SENT", NULL);
$this->db->group_end();
$this->db->select(''.$this->config->item('table_name').'.*, station_profile.*, dxcc_entities.name as station_country');
$this->db->from($this->config->item('table_name'));
$this->db->where($this->config->item('table_name').'.station_id', $active_station_id);
$this->db->group_start();
$this->db->where($this->config->item('table_name').".COL_LOTW_QSL_SENT != 'Y'");
$this->db->or_where($this->config->item('table_name').".COL_LOTW_QSL_SENT", NULL);
$this->db->group_end();
$this->db->order_by($this->config->item('table_name').".COL_TIME_ON", "ASC");
$this->db->order_by($this->config->item('table_name').".COL_TIME_ON", "ASC");
$this->db->join('station_profile', 'station_profile.station_id = '.$this->config->item('table_name').'.station_id');
$this->db->join('dxcc_entities', 'station_profile.station_dxcc = dxcc_entities.adif', 'left outer');
$this->db->join('station_profile', 'station_profile.station_id = '.$this->config->item('table_name').'.station_id');
$this->db->join('dxcc_entities', 'station_profile.station_dxcc = dxcc_entities.adif', 'left outer');
return $this->db->get();
}
return $this->db->get();
}
function mark_lotw_sent($id) {
$data = array(
'COL_LOTW_QSL_SENT' => 'Y'
);
function mark_lotw_sent($id) {
$data = array(
'COL_LOTW_QSL_SENT' => 'Y'
);
$this->db->set('COL_LOTW_QSLSDATE', 'now()', FALSE);
$this->db->where('COL_PRIMARY_KEY', $id);
$this->db->update($this->config->item('table_name'), $data);
}
$this->db->where('COL_PRIMARY_KEY', $id);
$this->db->update($this->config->item('table_name'), $data);
}
function sig_all($type) {
$CI =& get_instance();

View File

@@ -174,8 +174,9 @@
<form class="form" action="<?php echo site_url('adif/export_custom'); ?>" method="post" enctype="multipart/form-data">
<h5 class="card-title"><?= __("Take your logbook file anywhere!") ?> </h5>
<p class="card-text"><?= __("Exporting ADIFs allows you to import contacts into third party applications like LoTW, Awards or just for keeping a backup.") ?> </p>
<div class="small form-text text-muted"><?= __("Select Station Location") ?></div>
<select name="station_profile" class="form-select mb-2 me-sm-2 w-50 w-lg-100">
<option value="0"><?= __("Select Station Location") ?></option>
<option value="0"><?= __("All") ?></option>
<?php foreach ($station_profile->result() as $station) { ?>
<option value="<?php echo $station->station_id; ?>" <?php if ($station->station_id == $this->stations->find_active()) {
echo " selected =\"selected\"";
@@ -183,10 +184,10 @@
<?php } ?>
</select>
<br>
<label for="from"><?= __("From date") . ": " ?></label>
<div class="small form-text text-muted"><?= __("From date") . ":"; ?></div>
<input name="from" id="from" type="date" class="form-control w-auto">
<br>
<label for="to"><?= __("To date") . ": " ?></label>
<div class="small form-text text-muted"><?= __("To date") . ":"; ?></div>
<input name="to" id="to" type="date" class="form-control w-auto">
<br>