From 1e3b08588671add4f6b01e8091af74349df77965 Mon Sep 17 00:00:00 2001 From: Peter Goodhall Date: Sun, 6 Sep 2020 16:26:15 +0100 Subject: [PATCH] Building function for automatic lotw downloads --- application/controllers/Lotw.php | 44 ++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/application/controllers/Lotw.php b/application/controllers/Lotw.php index e60b53e9..5e32894e 100644 --- a/application/controllers/Lotw.php +++ b/application/controllers/Lotw.php @@ -513,6 +513,50 @@ class Lotw extends CI_Controller { $this->load->view('interface_assets/footer'); } + public function lotw_download() { + $this->load->model('user_model'); + $this->load->model('logbook_model'); + + $file = $config['upload_path'] . 'lotwreport_download.adi'; + + // Get credentials for LoTW + $query = $this->user_model->get_by_id($user_id); + $q = $query->row(); + $data['user_lotw_name'] = $q->user_lotw_name; + $data['user_lotw_password'] = $q->user_lotw_password; + + // Get URL for downloading LoTW + $query = $query = $this->db->query('SELECT lotw_download_url FROM config'); + $q = $query->row(); + $lotw_url = $q->lotw_download_url; + + // Validate that LoTW credentials are not empty + // TODO: We don't actually see the error message + if ($data['user_lotw_name'] == '' || $data['user_lotw_password'] == '') + { + $this->session->set_flashdata('warning', 'You have not defined your ARRL LoTW credentials!'); redirect('lotw/import'); + } + + $lotw_last_qsl_date = date('Y-m-d', strtotime($this->logbook_model->lotw_last_qsl_date())); + + // Build URL for LoTW report file + $lotw_url .= "?"; + $lotw_url .= "login=" . $data['user_lotw_name']; + $lotw_url .= "&password=" . $data['user_lotw_password']; + $lotw_url .= "&qso_query=1&qso_qsl='yes'&qso_qsldetail='yes'&qso_mydetail='yes'"; + + //TODO: Option to specifiy whether we download location data from LoTW or not + //$lotw_url .= "&qso_qsldetail=\"yes\"; + + $lotw_url .= "&qso_qslsince="; + $lotw_url .= "$lotw_last_qsl_date"; + + file_put_contents($file, file_get_contents($lotw_url)); + + ini_set('memory_limit', '-1'); + $this->loadFromFile($file); + } + public function import() { $this->load->model('user_model'); if(!$this->user_model->authorize(2)) { $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); redirect('dashboard'); }