diff --git a/application/controllers/Lotw.php b/application/controllers/Lotw.php
index 3e1ab4793..7722681f4 100644
--- a/application/controllers/Lotw.php
+++ b/application/controllers/Lotw.php
@@ -19,13 +19,12 @@ class Lotw extends CI_Controller {
*/
/* Controls who can access the controller and its functions */
- function __construct()
- {
+ function __construct() {
parent::__construct();
$this->load->helper(array('form', 'url'));
if (ENVIRONMENT == 'maintenance' && $this->session->userdata('user_id') == '') {
- echo __("Maintenance Mode is active. Try again later.")."\n";
+ echo __("Maintenance Mode is active. Try again later.")."\n";
redirect('user/login');
}
}
@@ -468,8 +467,7 @@ class Lotw extends CI_Controller {
| Internal function that takes the LoTW ADIF and imports into the log
|
*/
- private function loadFromFile($filepath, $display_view = "TRUE")
- {
+ private function loadFromFile($filepath, $station_ids, $display_view = "TRUE") {
// Figure out how we should be marking QSLs confirmed via LoTW
$query = $query = $this->db->query('SELECT lotw_rcvd_mark FROM config');
@@ -488,127 +486,126 @@ class Lotw extends CI_Controller {
$this->adif_parser->initialize();
$tableheaders = "
";
- $tableheaders .= "";
- $tableheaders .= "| Station Callsign | ";
- $tableheaders .= "QSO Date | ";
- $tableheaders .= "Call | ";
- $tableheaders .= "Mode | ";
- $tableheaders .= "LoTW QSL Received | ";
- $tableheaders .= "Date LoTW Confirmed | ";
- $tableheaders .= "State | ";
- $tableheaders .= "Gridsquare | ";
- $tableheaders .= "IOTA | ";
- $tableheaders .= "Log Status | ";
- $tableheaders .= "LoTW Status | ";
- $tableheaders .= "
";
+ $tableheaders .= "";
+ $tableheaders .= "| Station Callsign | ";
+ $tableheaders .= "QSO Date | ";
+ $tableheaders .= "Call | ";
+ $tableheaders .= "Mode | ";
+ $tableheaders .= "LoTW QSL Received | ";
+ $tableheaders .= "Date LoTW Confirmed | ";
+ $tableheaders .= "State | ";
+ $tableheaders .= "Gridsquare | ";
+ $tableheaders .= "IOTA | ";
+ $tableheaders .= "Log Status | ";
+ $tableheaders .= "LoTW Status | ";
+ $tableheaders .= "
";
- $table = "";
- while($record = $this->adif_parser->get_record()) {
- // Check for LoTW confirmation in ADIF record and skip if not existent
- if (!isset($record['app_lotw_rxqsl'])) {
- continue;
- }
-
- $time_on = date('Y-m-d', strtotime($record['qso_date'])) ." ".date('H:i', strtotime($record['time_on']));
-
- $qsl_date = date('Y-m-d H:i', strtotime($record['app_lotw_rxqsl']));
-
- if (isset($record['time_off'])) {
- $time_off = date('Y-m-d', strtotime($record['qso_date'])) ." ".date('H:i', strtotime($record['time_off']));
- } else {
- $time_off = date('Y-m-d', strtotime($record['qso_date'])) ." ".date('H:i', strtotime($record['time_on']));
- }
-
- // If we have a positive match from LoTW, record it in the DB according to the user's preferences
- if ($record['qsl_rcvd'] == "Y")
- {
- $record['qsl_rcvd'] = $config['lotw_rcvd_mark'];
- }
-
- $status = $this->logbook_model->import_check($time_on, $record['call'], $record['band'], $record['mode'], $record['station_callsign']);
-
- if($status[0] == "Found") {
- $qso_id4lotw=$status[1];
- if (isset($record['state'])) {
- $state = $record['state'];
- } else {
- $state = "";
- }
- // Present only if the QSLing station specified a single valid grid square value in its station location uploaded to LoTW.
- $qsl_gridsquare = "";
- if (isset($record['gridsquare'])) {
- if (strlen($record['gridsquare']) > strlen($status[2] ?? '') || substr(strtoupper($status[2] ?? ''), 0, 4) != substr(strtoupper($record['gridsquare']), 0, 4)) {
- $qsl_gridsquare = $record['gridsquare'];
- }
- }
-
- if (isset($record['vucc_grids'])) {
- $qsl_vucc_grids = $record['vucc_grids'];
- } else {
- $qsl_vucc_grids = "";
- }
-
- if (isset($record['iota'])) {
- $iota = $record['iota'];
- } else {
- $iota = "";
- }
-
- if (isset($record['cnty'])) {
- $cnty = $record['cnty'];
- } else {
- $cnty = "";
- }
-
- if (isset($record['cqz'])) {
- $cqz = $record['cqz'];
- } else {
- $cqz = "";
- }
-
- if (isset($record['ituz'])) {
- $ituz = $record['ituz'];
- } else {
- $ituz = "";
- }
-
- $lotw_status = $this->logbook_model->lotw_update($time_on, $record['call'], $record['band'], $qsl_date, $record['qsl_rcvd'], $state, $qsl_gridsquare, $qsl_vucc_grids, $iota, $cnty, $cqz, $ituz, $record['station_callsign'],$qso_id4lotw);
-
- $table .= "";
- $table .= "| ".$record['station_callsign']." | ";
- $table .= "".$time_on." | ";
- $table .= "".$record['call']." | ";
- $table .= "".$record['mode']." | ";
- $table .= "".$record['qsl_rcvd']." | ";
- $table .= "".$qsl_date." | ";
- $table .= "".$state." | ";
- $table .= "".($qsl_gridsquare != '' ? $qsl_gridsquare : $qsl_vucc_grids)." | ";
- $table .= "".$iota." | ";
- $table .= "QSO Record: ".$status[0]." | ";
- $table .= "LoTW Record: ".$lotw_status." | ";
- $table .= "
";
- } else {
- $table .= "";
- $table .= "| ".$record['station_callsign']." | ";
- $table .= "".$time_on." | ";
- $table .= "".$record['call']." | ";
- $table .= "".$record['mode']." | ";
- $table .= "".$record['qsl_rcvd']." | ";
- $table .= " | ";
- $table .= " | ";
- $table .= " | ";
- $table .= " | ";
- $table .= "QSO Record: ".$status[0]." | ";
- $table .= " | ";
- $table .= "
";
- }
+ $table = "";
+ while($record = $this->adif_parser->get_record()) {
+ // Check for LoTW confirmation in ADIF record and skip if not existent
+ if (!isset($record['app_lotw_rxqsl'])) {
+ continue;
}
- if ($table != "")
+ $time_on = date('Y-m-d', strtotime($record['qso_date'])) ." ".date('H:i', strtotime($record['time_on']));
+
+ $qsl_date = date('Y-m-d H:i', strtotime($record['app_lotw_rxqsl']));
+
+ if (isset($record['time_off'])) {
+ $time_off = date('Y-m-d', strtotime($record['qso_date'])) ." ".date('H:i', strtotime($record['time_off']));
+ } else {
+ $time_off = date('Y-m-d', strtotime($record['qso_date'])) ." ".date('H:i', strtotime($record['time_on']));
+ }
+
+ // If we have a positive match from LoTW, record it in the DB according to the user's preferences
+ if ($record['qsl_rcvd'] == "Y")
{
- $table .= "
";
- $data['lotw_table_headers'] = $tableheaders;
- $data['lotw_table'] = $table;
+ $record['qsl_rcvd'] = $config['lotw_rcvd_mark'];
+ }
+
+ $status = $this->logbook_model->import_check($time_on, $record['call'], $record['band'], $record['mode'], $record['station_callsign'], $station_ids);
+
+ if($status[0] == "Found") {
+ $qso_id4lotw=$status[1];
+ if (isset($record['state'])) {
+ $state = $record['state'];
+ } else {
+ $state = "";
+ }
+ // Present only if the QSLing station specified a single valid grid square value in its station location uploaded to LoTW.
+ $qsl_gridsquare = "";
+ if (isset($record['gridsquare'])) {
+ if (strlen($record['gridsquare']) > strlen($status[2] ?? '') || substr(strtoupper($status[2] ?? ''), 0, 4) != substr(strtoupper($record['gridsquare']), 0, 4)) {
+ $qsl_gridsquare = $record['gridsquare'];
+ }
+ }
+
+ if (isset($record['vucc_grids'])) {
+ $qsl_vucc_grids = $record['vucc_grids'];
+ } else {
+ $qsl_vucc_grids = "";
+ }
+
+ if (isset($record['iota'])) {
+ $iota = $record['iota'];
+ } else {
+ $iota = "";
+ }
+
+ if (isset($record['cnty'])) {
+ $cnty = $record['cnty'];
+ } else {
+ $cnty = "";
+ }
+
+ if (isset($record['cqz'])) {
+ $cqz = $record['cqz'];
+ } else {
+ $cqz = "";
+ }
+
+ if (isset($record['ituz'])) {
+ $ituz = $record['ituz'];
+ } else {
+ $ituz = "";
+ }
+
+ $lotw_status = $this->logbook_model->lotw_update($time_on, $record['call'], $record['band'], $qsl_date, $record['qsl_rcvd'], $state, $qsl_gridsquare, $qsl_vucc_grids, $iota, $cnty, $cqz, $ituz, $record['station_callsign'],$qso_id4lotw, $station_ids);
+
+ $table .= "";
+ $table .= "| ".$record['station_callsign']." | ";
+ $table .= "".$time_on." | ";
+ $table .= "".$record['call']." | ";
+ $table .= "".$record['mode']." | ";
+ $table .= "".$record['qsl_rcvd']." | ";
+ $table .= "".$qsl_date." | ";
+ $table .= "".$state." | ";
+ $table .= "".($qsl_gridsquare != '' ? $qsl_gridsquare : $qsl_vucc_grids)." | ";
+ $table .= "".$iota." | ";
+ $table .= "QSO Record: ".$status[0]." | ";
+ $table .= "LoTW Record: ".$lotw_status." | ";
+ $table .= "
";
+ } else {
+ $table .= "";
+ $table .= "| ".$record['station_callsign']." | ";
+ $table .= "".$time_on." | ";
+ $table .= "".$record['call']." | ";
+ $table .= "".$record['mode']." | ";
+ $table .= "".$record['qsl_rcvd']." | ";
+ $table .= " | ";
+ $table .= " | ";
+ $table .= " | ";
+ $table .= " | ";
+ $table .= "QSO Record: ".$status[0]." | ";
+ $table .= " | ";
+ $table .= "
";
+ }
+ }
+
+ if ($table != "") {
+ $table .= "";
+ $data['lotw_table_headers'] = $tableheaders;
+ $data['lotw_table'] = $table;
}
unlink($filepath);
@@ -642,6 +639,7 @@ class Lotw extends CI_Controller {
function lotw_download($sync_user_id = null) {
$this->load->model('user_model');
$this->load->model('logbook_model');
+ $this->load->model('Stations');
$query = $this->user_model->get_all_lotw_users();
@@ -655,6 +653,7 @@ class Lotw extends CI_Controller {
foreach ($query->result() as $user) {
if ( ($sync_user_id != null) && ($sync_user_id != $user->user_id) ) { continue; }
+ $station_ids=$this->Stations->all_station_ids_of_user($user->user_id);
// Validate that LoTW credentials are not empty
// TODO: We don't actually see the error message
@@ -708,7 +707,7 @@ class Lotw extends CI_Controller {
}
ini_set('memory_limit', '-1');
- $result = $this->loadFromFile($file, false);
+ $result = $this->loadFromFile($file, $station_ids, false);
}
return $result;
} else {
@@ -718,12 +717,14 @@ class Lotw extends CI_Controller {
public function import() { // Is only called via frontend. Cron uses "upload". within download the download is called
$this->load->model('user_model');
+ $this->load->model('Stations');
if(!$this->user_model->authorize(2)) {
$this->session->set_flashdata('error', __("You're not allowed to do that!"));
redirect('dashboard');
exit();
}
+ $station_ids=$this->Stations->all_station_ids_of_user($this->session->userdata['user_id']);
if (!($this->config->item('disable_manual_lotw'))) {
$data['page_title'] = __("LoTW ADIF Import");
@@ -759,8 +760,7 @@ class Lotw extends CI_Controller {
if ($customDate != NULL) {
$lotw_last_qsl_date = date($customDate);
- }
- else {
+ } else {
// Query the logbook to determine when the last LoTW confirmation was
$lotw_last_qsl_date = date('Y-m-d', strtotime($this->logbook_model->lotw_last_qsl_date($this->session->userdata['user_id'])));
}
@@ -788,7 +788,7 @@ class Lotw extends CI_Controller {
file_put_contents($file, $content);
ini_set('memory_limit', '-1');
- $this->loadFromFile($file);
+ $this->loadFromFile($file, $station_ids);
} else {
print "LoTW download failed for user ".$data['user_lotw_name'].": ".curl_strerror(curl_errno($ch))." (".curl_errno($ch).").";
}
@@ -805,9 +805,7 @@ class Lotw extends CI_Controller {
$this->load->view('lotw/import', $data);
$this->load->view('interface_assets/footer');
}
- }
- else
- {
+ } else {
if ( ! $this->upload->do_upload())
{
@@ -818,12 +816,10 @@ class Lotw extends CI_Controller {
$this->load->view('interface_assets/header', $data);
$this->load->view('lotw/import', $data);
$this->load->view('interface_assets/footer');
- }
- else
- {
+ } else {
$data = array('upload_data' => $this->upload->data());
- $this->loadFromFile('./uploads/'.$data['upload_data']['file_name']);
+ $this->loadFromFile('./uploads/'.$data['upload_data']['file_name'], $station_ids);
}
}
} else {
diff --git a/application/models/Logbook_model.php b/application/models/Logbook_model.php
index 3ad463f09..634ed601c 100644
--- a/application/models/Logbook_model.php
+++ b/application/models/Logbook_model.php
@@ -3369,7 +3369,7 @@ function check_if_callsign_worked_in_logbook($callsign, $StationLocationsArray =
}
}
- function lotw_update($datetime, $callsign, $band, $qsl_date, $qsl_status, $state, $qsl_gridsquare, $qsl_vucc_grids, $iota, $cnty, $cqz, $ituz, $station_callsign, $qsoid) {
+ function lotw_update($datetime, $callsign, $band, $qsl_date, $qsl_status, $state, $qsl_gridsquare, $qsl_vucc_grids, $iota, $cnty, $cqz, $ituz, $station_callsign, $qsoid, $station_ids) {
$data = array(
'COL_LOTW_QSLRDATE' => $qsl_date,
@@ -3396,7 +3396,7 @@ function check_if_callsign_worked_in_logbook($callsign, $StationLocationsArray =
}
// Check if QRZ or ClubLog is already uploaded. If so, set qso to reupload to qrz.com (M) or clublog
- $qsql = "select COL_CLUBLOG_QSO_UPLOAD_STATUS as CL_STATE, COL_QRZCOM_QSO_UPLOAD_STATUS as QRZ_STATE from ".$this->config->item('table_name')." where COL_BAND=? and COL_CALL=? and COL_STATION_CALLSIGN=? and date_format(COL_TIME_ON, '%Y-%m-%d %H:%i') = ? and COL_PRIMARY_KEY = ?";
+ $qsql = "select COL_CLUBLOG_QSO_UPLOAD_STATUS as CL_STATE, COL_QRZCOM_QSO_UPLOAD_STATUS as QRZ_STATE from ".$this->config->item('table_name')." where COL_BAND=? and COL_CALL=? and COL_STATION_CALLSIGN=? and date_format(COL_TIME_ON, '%Y-%m-%d %H:%i') = ? and COL_PRIMARY_KEY = ? and station_id in (".$station_ids.')';
$query = $this->db->query($qsql, array($band, $callsign,$station_callsign,$datetime,$qsoid));
$row = $query->row();
if (($row->QRZ_STATE ?? '') == 'Y') {
@@ -3415,7 +3415,7 @@ function check_if_callsign_worked_in_logbook($callsign, $StationLocationsArray =
$this->db->where('date_format(COL_TIME_ON, \'%Y-%m-%d %H:%i\') = ',$datetime);
$this->db->where('COL_STATION_CALLSIGN', $station_callsign);
$this->db->where('COL_PRIMARY_KEY', $qsoid);
-
+ $this->db->where('station_id in ('.$station_ids.')');
$this->db->update($this->config->item('table_name'), $data);
unset($data);
@@ -3430,6 +3430,7 @@ function check_if_callsign_worked_in_logbook($callsign, $StationLocationsArray =
$this->db->where('COL_BAND', $band);
$this->db->where('COL_PRIMARY_KEY', $qsoid);
$this->db->join('station_profile', $this->config->item('table_name').'.station_id = station_profile.station_id', 'left outer');
+ $this->db->where('station_profile.station_id in ('.$station_ids.')');
$this->db->limit(1);
$query = $this->db->get($this->config->item('table_name'));
$row = $query->row();
diff --git a/application/models/Stations.php b/application/models/Stations.php
index a2c99d26c..58673fd49 100644
--- a/application/models/Stations.php
+++ b/application/models/Stations.php
@@ -36,6 +36,24 @@ class Stations extends CI_Model {
return $this->db->get('station_profile');
}
+ function all_station_ids_of_user($userid = null) {
+ if ($userid == null) {
+ $userid=$this->session->userdata('user_id'); // Fallback to session-uid, if userid is omitted
+ }
+ $this->db->select('station_profile.station_id');
+ $this->db->where('user_id', $userid);
+ $query=$this->db->get('station_profile');
+ if ($query->num_rows() > 0){
+ foreach ($query->result() as $row) {
+ array_push($a_station_ids, $row->station_id);
+ }
+ $station_ids=implode(', ', $a_station_ids);
+ return $station_ids;
+ } else {
+ return '';
+ }
+ }
+
function callsigns_of_user($userid = null) {
if ($userid == null) {
$userid=$this->session->userdata('user_id'); // Fallback to session-uid, if userid is omitted