From 64827f45063c81c7eaf19692f6480a9efe14b484 Mon Sep 17 00:00:00 2001 From: Andreas <6977712+AndreasK79@users.noreply.github.com> Date: Sat, 1 May 2021 19:52:13 +0200 Subject: [PATCH] [ADIF Import] Added option to always use login call as operator. Request by OE3IDE. --- application/controllers/Adif.php | 2 +- application/controllers/Api.php | 8 ++-- application/controllers/Lotw.php | 68 ++++++++++++++-------------- application/models/Logbook_model.php | 12 +++-- application/views/adif/import.php | 9 ++++ 5 files changed, 57 insertions(+), 42 deletions(-) diff --git a/application/controllers/Adif.php b/application/controllers/Adif.php index 32282650..3864f0be 100644 --- a/application/controllers/Adif.php +++ b/application/controllers/Adif.php @@ -226,7 +226,7 @@ class adif extends CI_Controller { $custom_errors .= $this->logbook_model->import($record, $this->input->post('station_profile'), - $this->input->post('skipDuplicate'), $this->input->post('markLotw'), $this->input->post('dxccAdif'), $this->input->post('markQrz'), true); + $this->input->post('skipDuplicate'), $this->input->post('markLotw'), $this->input->post('dxccAdif'), $this->input->post('markQrz'), true, $this->input->post('operatorName')); }; diff --git a/application/controllers/Api.php b/application/controllers/Api.php index 9db17851..9e88e859 100644 --- a/application/controllers/Api.php +++ b/application/controllers/Api.php @@ -60,7 +60,7 @@ class API extends CI_Controller { function edit($key) { $this->load->model('user_model'); - + if(!$this->user_model->authorize(99)) { $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); redirect('dashboard'); } $this->load->model('api_model'); @@ -426,12 +426,12 @@ class API extends CI_Controller { { break; }; - + if(isset($obj['station_profile_id'])) { - $this->logbook_model->import($record, $obj['station_profile_id'], NULL, NULL, NULL, NULL, false); + $this->logbook_model->import($record, $obj['station_profile_id'], NULL, NULL, NULL, NULL, false, false); } else { - $this->logbook_model->import($record, 0, NULL, NULL, NULL, NULL, false); + $this->logbook_model->import($record, 0, NULL, NULL, NULL, NULL, false, false); } }; diff --git a/application/controllers/Lotw.php b/application/controllers/Lotw.php index 7c0b7903..248fde4d 100644 --- a/application/controllers/Lotw.php +++ b/application/controllers/Lotw.php @@ -5,7 +5,7 @@ class Lotw extends CI_Controller { |-------------------------------------------------------------------------- | Controller: Lotw |-------------------------------------------------------------------------- - | + | | This Controller handles all things LOTW, upload and download. | | @@ -23,7 +23,7 @@ class Lotw extends CI_Controller { { parent::__construct(); $this->load->helper(array('form', 'url')); - + // Load language files $this->lang->load('lotw'); } @@ -32,7 +32,7 @@ class Lotw extends CI_Controller { |-------------------------------------------------------------------------- | Function: index |-------------------------------------------------------------------------- - | + | | Default function for the controller which loads when doing /lotw | this shows all the uploaded lotw p12 certificates the user has uploaded | @@ -65,7 +65,7 @@ class Lotw extends CI_Controller { |-------------------------------------------------------------------------- | Function: cert_upload |-------------------------------------------------------------------------- - | + | | Nothing fancy just shows the cert_upload form for uploading p12 files | */ @@ -83,14 +83,14 @@ class Lotw extends CI_Controller { // Load Views $this->load->view('interface_assets/header', $data); $this->load->view('lotw_views/upload_cert', array('error' => ' ' )); - $this->load->view('interface_assets/footer'); + $this->load->view('interface_assets/footer'); } /* |-------------------------------------------------------------------------- | Function: do_cert_upload |-------------------------------------------------------------------------- - | + | | do_cert_upload is called from cert_upload form submit and handles uploading | and processing of p12 files and storing the data into mysql | @@ -127,7 +127,7 @@ class Lotw extends CI_Controller { // Load Views $this->load->view('interface_assets/header', $data); $this->load->view('lotw_views/upload_cert', $error); - $this->load->view('interface_assets/footer'); + $this->load->view('interface_assets/footer'); } else { @@ -141,10 +141,10 @@ class Lotw extends CI_Controller { // Check DXCC & Store Country Name $this->load->model('Logbook_model'); - + if($this->input->post('dxcc') != "") { $dxcc = $this->input->post('dxcc'); - } else{ + } else{ $dxcc_check = $this->Logbook_model->check_dxcc_table($info['issued_callsign'], $info['validFrom']); $dxcc = $dxcc_check[1]; } @@ -193,7 +193,7 @@ class Lotw extends CI_Controller { |-------------------------------------------------------------------------- | Function: lotw_upload |-------------------------------------------------------------------------- - | + | | This function Uploads to LOTW | */ @@ -242,9 +242,9 @@ class Lotw extends CI_Controller { if(empty($data['qsos']->result())){ echo $station_profile->station_callsign." (".$station_profile->station_profile_name.") No QSOs to Upload
"; continue; - } + } - foreach ($data['qsos']->result() as $temp_qso) { + foreach ($data['qsos']->result() as $temp_qso) { array_push($qso_id_array, $temp_qso->COL_PRIMARY_KEY); } @@ -266,25 +266,25 @@ class Lotw extends CI_Controller { //The URL that accepts the file upload. $url = 'https://lotw.arrl.org/lotw/upload'; - + //The name of the field for the uploaded file. $uploadFieldName = 'upfile'; - + //The full path to the file that you want to upload $filePath = realpath($filename_for_saving); - + //Initiate cURL $ch = curl_init(); - + //Set the URL curl_setopt($ch, CURLOPT_URL, $url); - + //Set the HTTP request to POST curl_setopt($ch, CURLOPT_POST, true); - + //Tell cURL to return the output as a string. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - + //If the function curl_file_create exists if(function_exists('curl_file_create')){ //Use the recommended way, creating a CURLFile object. @@ -298,23 +298,23 @@ class Lotw extends CI_Controller { //starting with an @ curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false); } - + //Setup our POST fields $postFields = array( $uploadFieldName => $filePath ); - + curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields); - + //Execute the request $result = curl_exec($ch); - + //If an error occured, throw an exception //with the error message. if(curl_errno($ch)){ throw new Exception(curl_error($ch)); } - + $pos = strpos($result, ""); if ($pos === false) { @@ -353,7 +353,7 @@ class Lotw extends CI_Controller { |-------------------------------------------------------------------------- | Function: delete_cert |-------------------------------------------------------------------------- - | + | | Deletes LOTW certificate from the MySQL table | */ @@ -375,7 +375,7 @@ class Lotw extends CI_Controller { |-------------------------------------------------------------------------- | Function: decrypt_key |-------------------------------------------------------------------------- - | + | | Accepts p12 file and optional password and encrypts the file returning | the required fields for LOTW and the PEM Key | @@ -429,12 +429,12 @@ class Lotw extends CI_Controller { return $data; } - + /* |-------------------------------------------------------------------------- | Function: loadFromFile |-------------------------------------------------------------------------- - | + | | $filepath is the ADIF file, $display_view is used to hide the output if its internal script | | Internal function that takes the LoTW ADIF and imports into the log @@ -498,7 +498,7 @@ class Lotw extends CI_Controller { $station_id = $this->logbook_model->find_correct_station_id($record['station_callsign'], $record['my_gridsquare']); if ($station_id != NULL) { - $result = $this->logbook_model->import($record, $station_id, NULL, TRUE, NULL, NULL, true); // Create the Entry + $result = $this->logbook_model->import($record, $station_id, NULL, TRUE, NULL, NULL, true, false); // Create the Entry if ($result == "") { $lotw_status = 'QSO imported'; } else { @@ -557,8 +557,8 @@ class Lotw extends CI_Controller { |-------------------------------------------------------------------------- | Function: lotw_download |-------------------------------------------------------------------------- - | - | Collects users with LoTW usernames and passwords and runs through them + | + | Collects users with LoTW usernames and passwords and runs through them | downloading matching QSOs. | */ @@ -834,11 +834,11 @@ class Lotw extends CI_Controller { /* Load the ARRL LOTW User Activity CSV and saves into uploads/lotw_users.csv - */ + */ public function load_users() { $contents = file_get_contents('https://lotw.arrl.org/lotw-user-activity.csv', true); - if($contents === FALSE) { + if($contents === FALSE) { echo "something went wrong"; } else { $file = './updates/lotw_users.csv'; @@ -909,7 +909,7 @@ class Lotw extends CI_Controller { return array_search(strtoupper($satname),$arr,true); } - + /* | Function: mode_map | Requires: mode as $mode, submode as $submode diff --git a/application/models/Logbook_model.php b/application/models/Logbook_model.php index f95f39d9..7fc8bb0a 100755 --- a/application/models/Logbook_model.php +++ b/application/models/Logbook_model.php @@ -1502,7 +1502,7 @@ class Logbook_model extends CI_Model { * $markQrz - used in ADIF import to mark QSOs as exported to QRZ Logbook when importing QSOs * $skipexport - used in ADIF import to skip the realtime upload to QRZ Logbook when importing QSOs from ADIF */ - function import($record, $station_id = "0", $skipDuplicate = false, $markLotw = false, $dxccAdif = false, $markQrz = false, $skipexport = false) { + function import($record, $station_id = "0", $skipDuplicate = false, $markLotw = false, $dxccAdif = false, $markQrz = false, $skipexport = false, $operatorName = false) { $CI =& get_instance(); $CI->load->library('frequency'); $my_error = ""; @@ -1805,6 +1805,12 @@ class Logbook_model extends CI_Model { } } + if ($operatorName != false) { + $operatorName = $this->session->userdata('user_callsign'); + } else { + $operatorName = (!empty($record['operator'])) ? $record['operator'] : ''; + } + // If user checked to mark QSOs as uploaded to QRZ Logbook, or else we try to find info in ADIF import. if ($markQrz != null) { $input_qrzcom_qso_upload_status = 'Y'; @@ -1918,7 +1924,7 @@ class Logbook_model extends CI_Model { 'COL_NOTES_INTL' => (!empty($record['notes_intl'])) ? $record['notes_intl'] : '', 'COL_NR_BURSTS' => (!empty($record['nr_bursts'])) ? $record['nr_bursts'] : null, 'COL_NR_PINGS' => (!empty($record['nr_pings'])) ? $record['nr_pings'] : null, - 'COL_OPERATOR' => (!empty($record['operator'])) ? $record['operator'] : '', + 'COL_OPERATOR' => $operatorName, 'COL_OWNER_CALLSIGN' => (!empty($record['owner_callsign'])) ? $record['owner_callsign'] : '', 'COL_PFX' => (!empty($record['pfx'])) ? $record['pfx'] : '', 'COL_PRECEDENCE' => (!empty($record['precedence'])) ? $record['precedence'] : '', @@ -2170,7 +2176,7 @@ class Logbook_model extends CI_Model { print("$count updated\n"); } - + public function check_missing_grid_id($all){ // get all records with no COL_GRIDSQUARE $this->db->select("COL_PRIMARY_KEY, COL_CALL, COL_TIME_ON, COL_TIME_OFF"); diff --git a/application/views/adif/import.php b/application/views/adif/import.php index 5a7cd82a..7405abdf 100644 --- a/application/views/adif/import.php +++ b/application/views/adif/import.php @@ -82,6 +82,15 @@ +
+
+
+ + +
+
+
+