From 61d3856e411b841f7580c23a8684a5db55b2030c Mon Sep 17 00:00:00 2001 From: int2001 Date: Wed, 11 Sep 2024 08:25:06 +0000 Subject: [PATCH 1/4] Export all QSOs (of User) when chosing "Select station location" at export --- application/controllers/Adif.php | 56 +++--- application/models/Adif_data.php | 289 ++++++++++++++++--------------- 2 files changed, 177 insertions(+), 168 deletions(-) diff --git a/application/controllers/Adif.php b/application/controllers/Adif.php index d23170830..981f54680 100644 --- a/application/controllers/Adif.php +++ b/application/controllers/Adif.php @@ -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); } @@ -77,47 +77,41 @@ class adif extends CI_Controller { public function export_custom() { // Set memory limit to unlimited to allow heavy usage ini_set('memory_limit', '-1'); - $this->load->model('adif_data'); - $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); - $this->load->view('adif/data/exportall', $data); - 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 +140,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 +324,7 @@ class adif extends CI_Controller { $this->load->view('adif/dcl_success'); $this->load->view('interface_assets/footer'); } - } + } } /* End of file adif.php */ diff --git a/application/models/Adif_data.php b/application/models/Adif_data.php index f4a6694e4..c45e2cac2 100644 --- a/application/models/Adif_data.php +++ b/application/models/Adif_data.php @@ -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,137 @@ 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) { + log_message("Error","All"); + 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(); From 9cb6b4a176d1fdcb0d17aa62f3ed30dde859b85c Mon Sep 17 00:00:00 2001 From: int2001 Date: Wed, 11 Sep 2024 08:36:26 +0000 Subject: [PATCH 2/4] Removed Debug and re-added empty lines --- application/controllers/Adif.php | 6 ++++++ application/models/Adif_data.php | 1 - 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/application/controllers/Adif.php b/application/controllers/Adif.php index 981f54680..5b72a561d 100644 --- a/application/controllers/Adif.php +++ b/application/controllers/Adif.php @@ -77,17 +77,23 @@ class adif extends CI_Controller { public function export_custom() { // Set memory limit to unlimited to allow heavy usage ini_set('memory_limit', '-1'); + $this->load->model('adif_data'); + $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; } + $data['qsos'] = $this->adif_data->export_custom($this->input->post('from'), $this->input->post('to'), $station_id, $exportLotw); + $this->load->view('adif/data/exportall', $data); + if ($this->input->post('markLotw') == 1) { foreach ($data['qsos']->result() as $qso) { diff --git a/application/models/Adif_data.php b/application/models/Adif_data.php index c45e2cac2..399f1ed24 100644 --- a/application/models/Adif_data.php +++ b/application/models/Adif_data.php @@ -118,7 +118,6 @@ class adif_data extends CI_Model { // be sure that station belongs to user $this->load->model('Stations'); if ($station_id == 0) { - log_message("Error","All"); return $this->export_all($api_key = null,$from, $to, $exportLotw); } else { if (!$this->Stations->check_station_is_accessible($station_id)) { From 70d599b50fb7a2285f5ecb24d2a3a0377e8f0256 Mon Sep 17 00:00:00 2001 From: HB9HIL Date: Wed, 11 Sep 2024 10:55:37 +0200 Subject: [PATCH 3/4] renamed option to all and added label --- application/views/adif/import.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/application/views/adif/import.php b/application/views/adif/import.php index a1a46a813..0cd9727da 100644 --- a/application/views/adif/import.php +++ b/application/views/adif/import.php @@ -174,8 +174,9 @@

+

- +

- +

From 8a8399663b528d1a25595e8fbbabb632d5338fbd Mon Sep 17 00:00:00 2001 From: HB9HIL Date: Wed, 11 Sep 2024 10:55:51 +0200 Subject: [PATCH 4/4] git ignore adi files in backup folder --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 73593cbf0..b591caf8a 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ /application/config/config.php /application/logs/* /application/cache/* +/backup/*.adi /uploads /uploads/*.adi /uploads/*.ADI