Added handling when trigger upload/download from GUI

This commit is contained in:
Andreas Kristiansen
2025-01-25 09:01:53 +01:00
parent 9ea04dbc0e
commit 1a0748a92e
3 changed files with 59 additions and 11 deletions

View File

@@ -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;
}
}

View File

@@ -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();

View File

@@ -24,8 +24,6 @@
<?php if (($next_run_up ?? '') != '') { echo "<p>".__("The next automatic Upload to Clublog will happen at: ").$next_run_up."</p>"; } ?>
<p><?= __("Here you can see all QSOs which have not been previously uploaded to a Clublog logbook."); ?></p>
<p><?= __("You need to set a username and password in your user account. You will also need to enable upload for each station profile ."); ?></p>
<?php if (!($this->config->item('disable_manual_clublog'))) { echo '<p><span class="badge text-bg-warning">Warning</span> This might take a while as QSO uploads are processed sequentially.</p>'; } ?>
<?php
if ($station_profile->result()) {
echo '
@@ -49,7 +47,7 @@
echo '<td id ="notcount'.$station->station_id.'">' . $station->notcount . '</td>';
echo '<td id ="totcount'.$station->station_id.'">' . $station->totcount . '</td>';
if (!($this->config->item('disable_manual_clublog'))) {
echo '<td><button id="clublogUpload" type="button" name="clublogUpload" class="btn btn-primary btn-sm ld-ext-right ld-ext-right-'.$station->station_id.'" onclick="ExportClublog('. $station->station_id .')"><i class="fas fa-cloud-upload-alt"></i> ' . __("Upload") . '<div class="ld ld-ring ld-spin"></div></button></td>';
echo '<td><a href="' . site_url('clublog/uploadlog') . '/' . $station->station_id . '" class="btn btn-sm btn-primary"><i class="fas fa-cloud-upload-alt"></i> ' . __("Upload") .'</a></td>';
} else {
echo '<td>&nbsp;</td>';
}
@@ -67,7 +65,7 @@
<?php if (!($this->config->item('disable_manual_clublog'))) { ?>
<div class="tab-pane fade" id="import" role="tabpanel" aria-labelledby="home-tab">
<form class="form" action="<?php echo site_url('clublog/import_clublog'); ?>" method="post" enctype="multipart/form-data">
<form class="form" action="<?php echo site_url('clublog/importlog'); ?>" method="post" enctype="multipart/form-data">
<?php if (($next_run_down ?? '') != '') { echo "<p>".__("The next automatic Download from Clublog-QSLs will happen at: ").$next_run_down."</p>"; } ?>
<p><span class="badge text-bg-warning"><?= __("Warning"); ?></span> <?= __("If no startdate is given then all QSOs after last confirmation will be downloaded/updated!"); ?></p>
<div class="row">