From 1a0748a92ef5c6f9da1f16c4b1dc59ed29876b08 Mon Sep 17 00:00:00 2001 From: Andreas Kristiansen <6977712+AndreasK79@users.noreply.github.com> Date: Sat, 25 Jan 2025 09:01:53 +0100 Subject: [PATCH] Added handling when trigger upload/download from GUI --- application/controllers/Clublog.php | 46 +++++++++++++++++++++++++++- application/models/Clublog_model.php | 18 +++++++---- application/views/clublog/export.php | 6 ++-- 3 files changed, 59 insertions(+), 11 deletions(-) diff --git a/application/controllers/Clublog.php b/application/controllers/Clublog.php index 61a2479f5..b642e4ee2 100644 --- a/application/controllers/Clublog.php +++ b/application/controllers/Clublog.php @@ -91,7 +91,7 @@ class Clublog extends CI_Controller } /* - * Used for displaying the uid for manually selecting log for upload to qrz + * Used for displaying the uid for manually selecting log for upload to Clublog */ public function export() { $this->load->model('user_model'); @@ -115,4 +115,48 @@ class Clublog extends CI_Controller $this->load->view('clublog/export'); $this->load->view('interface_assets/footer'); } + + public function uploadlog($station_id) { + $this->load->model('clublog_model'); + + $users = $this->clublog_model->get_clublog_users($this->session->userdata('user_id')); + + if (!empty($users)) { + foreach ($users as $user) { + $r = $this->clublog_model->uploadUser($user->user_id, $user->user_clublog_name, $user->user_clublog_password, $station_id); + } + } else { + $r = __("No user has configured Clublog."); + } + + echo $r; + } + + public function importlog() { + $this->load->model('user_model'); + if(!$this->user_model->authorize(2)) { $this->session->set_flashdata('error', __("You're not allowed to do that!")); redirect('dashboard'); } + + $data['page_title'] = __("Clublog QSL Import"); + + $this->load->model('logbook_model'); + + $customDate = $this->input->post('from'); + if ($customDate != NULL) { + $clublog_last_date = date($customDate); + } else { + // Query the logbook to determine when the last LoTW confirmation was + $clublog_last_date = null; + } + $users = $this->clublog_model->get_clublog_users($this->session->userdata('user_id')); + + if (!empty($users)) { + foreach ($users as $user) { + $r = $this->clublog_model->downloadUser($user->user_id, $user->user_clublog_name, $user->user_clublog_password, $clublog_last_date); + } + } else { + $r = __("No user has configured Clublog."); + } + + echo $r; + } } diff --git a/application/models/Clublog_model.php b/application/models/Clublog_model.php index 6eea7cb2d..0da8f416a 100644 --- a/application/models/Clublog_model.php +++ b/application/models/Clublog_model.php @@ -3,15 +3,18 @@ class Clublog_model extends CI_Model { - function get_clublog_users() { + function get_clublog_users($userid = null) { $this->db->select('user_clublog_name, user_clublog_password, user_id'); $this->db->where('coalesce(user_clublog_name, "") != ""'); $this->db->where('coalesce(user_clublog_password, "") != ""'); + if ($userid !== null) { + $this->db->where('user_id', $userid); + } $query = $this->db->get($this->config->item('auth_table')); return $query->result(); } - function uploadUser($userid, $username, $password) { + function uploadUser($userid, $username, $password, $station_id = null) { $clean_username = $this->security->xss_clean($username); $clean_passord = $this->security->xss_clean($password); $clean_userid = $this->security->xss_clean($userid); @@ -30,7 +33,7 @@ class Clublog_model extends CI_Model $this->load->library('AdifHelper'); } - $station_profiles = $this->all_with_count($clean_userid); + $station_profiles = $this->all_with_count($clean_userid, $station_id); if ($station_profiles->num_rows()) { foreach ($station_profiles->result() as $station_row) { @@ -127,7 +130,7 @@ class Clublog_model extends CI_Model return $return . "\n"; } - function downloadUser($userid, $username, $password) { + function downloadUser($userid, $username, $password, $clublog_last_date = null) { $clean_username = $this->security->xss_clean($username); $clean_password = $this->security->xss_clean($password); $clean_userid = $this->security->xss_clean($userid); @@ -148,7 +151,7 @@ class Clublog_model extends CI_Model if ($station_profiles->num_rows()) { foreach ($station_profiles->result() as $station_row) { - $lastrec = $this->clublog_last_qsl_rcvd_date($station_row->station_callsign); + $lastrec = $clublog_last_date ?? $this->clublog_last_qsl_rcvd_date($station_row->station_callsign); $url = 'https://clublog.org/getmatches.php?api=608df94896cb9c5421ae748235492b43815610c9&email=' . $clean_username . '&password=' . $clean_password . '&callsign=' . $station_row->station_callsign . '&startyear=' . substr($lastrec, 0, 4) . '&startmonth=' . substr($lastrec, 4, 2) . '&startday=' . substr($lastrec, 6, 2); $request = curl_init($url); @@ -296,11 +299,14 @@ class Clublog_model extends CI_Model return $query; } - function all_with_count($userid) { + function all_with_count($userid, $station_id) { $this->db->select('station_profile.station_id, station_profile.station_callsign, count(' . $this->config->item('table_name') . '.station_id) as qso_total'); $this->db->from('station_profile'); $this->db->join($this->config->item('table_name'), 'station_profile.station_id = ' . $this->config->item('table_name') . '.station_id', 'left'); $this->db->group_by('station_profile.station_id'); + if ($station_id !== null) { + $this->db->where('station_profile.station_id', $station_id); + } $this->db->where('station_profile.user_id', $userid); $this->db->where('station_profile.clublogignore', 0); $this->db->group_start(); diff --git a/application/views/clublog/export.php b/application/views/clublog/export.php index 34a9195bb..a3baaf33a 100644 --- a/application/views/clublog/export.php +++ b/application/views/clublog/export.php @@ -24,8 +24,6 @@ ".__("The next automatic Upload to Clublog will happen at: ").$next_run_up."

"; } ?>

- config->item('disable_manual_clublog'))) { echo '

Warning This might take a while as QSO uploads are processed sequentially.

'; } ?> - result()) { echo ' @@ -49,7 +47,7 @@ echo '' . $station->notcount . ''; echo '' . $station->totcount . ''; if (!($this->config->item('disable_manual_clublog'))) { - echo ''; + echo ' ' . __("Upload") .''; } else { echo ' '; } @@ -67,7 +65,7 @@ config->item('disable_manual_clublog'))) { ?>
-
+ ".__("The next automatic Download from Clublog-QSLs will happen at: ").$next_run_down."

"; } ?>