From 1d11d00ea83c32f971eac4ddd6102028416d7362 Mon Sep 17 00:00:00 2001 From: Christoph Kottke Date: Tue, 26 Sep 2023 11:39:15 +0200 Subject: [PATCH] add stations_id to eqsl functions --- application/controllers/Eqsl.php | 10 +++++---- application/libraries/EqslImporter.php | 26 ++++++++++++++---------- application/models/Eqslmethods_model.php | 11 ++++++---- application/models/Logbook_model.php | 9 +++++--- 4 files changed, 34 insertions(+), 22 deletions(-) diff --git a/application/controllers/Eqsl.php b/application/controllers/Eqsl.php index 76c266b6..4e6561d8 100644 --- a/application/controllers/Eqsl.php +++ b/application/controllers/Eqsl.php @@ -74,10 +74,11 @@ class eqsl extends CI_Controller { $this->eqslimporter->from_callsign_and_QTH( $eqsl_location['station_callsign'], $eqsl_location['eqslqthnickname'], - $config['upload_path'] + $config['upload_path'], + $eqsl_location['station_id'] ); - $eqsl_results[] = $this->eqslimporter->fetch($eqsl_password,$eqsl_force_from_date); + $eqsl_results[] = $this->eqslimporter->fetch($eqsl_password, $eqsl_force_from_date); } } elseif ($this->input->post('eqslimport') == 'upload') { $station_id4upload=$this->input->post('station_profile'); @@ -97,7 +98,7 @@ class eqsl extends CI_Controller { $data = array('upload_data' => $this->upload->data()); $this->load->library('EqslImporter'); - $this->eqslimporter->from_file('./uploads/'.$data['upload_data']['file_name'],$station_callsign); + $this->eqslimporter->from_file('./uploads/'.$data['upload_data']['file_name'], $station_callsign, $station_id4upload); $eqsl_results[] = $this->eqslimporter->import(); } @@ -728,7 +729,8 @@ class eqsl extends CI_Controller { $this->eqslimporter->from_callsign_and_QTH( $eqsl_location['station_callsign'], $eqsl_location['eqslqthnickname'], - $config['upload_path'] + $config['upload_path'], + $eqsl_location['station_id'] ); $eqsl_results[] = $this->eqslimporter->fetch($password); diff --git a/application/libraries/EqslImporter.php b/application/libraries/EqslImporter.php index d84ad812..7a057fce 100644 --- a/application/libraries/EqslImporter.php +++ b/application/libraries/EqslImporter.php @@ -8,6 +8,7 @@ class EqslImporter private $callsign; private $qth_nickname; private $adif_file; + private $station_id; // CodeIgniter super-ojbect private $CI; @@ -26,24 +27,26 @@ class EqslImporter $this->adif_file = $adif_file; } - public function from_callsign_and_QTH($callsign, $qth, $upload_path) { + public function from_callsign_and_QTH($callsign, $qth, $upload_path, $station_id) { $this->init( $qth . " - " . $callsign, - self::safe_filepath($callsign, $qth, $upload_path) + self::safe_filepath($callsign, $qth, $upload_path, $station_id) ); $this->callsign = $callsign; $this->qth_nickname = $qth; + $this->station_id = $station_id; } - public function from_file($adif_file,$station_callsign) { + public function from_file($adif_file, $station_callsign, $station_id) { $this->init('ADIF upload', $adif_file); - $this->callsign=$station_callsign; + $this->callsign = $station_callsign; + $this->station_id = $station_id; } // generate a sanitized file name from a callsign and a QTH nickname - private static function safe_filepath($callsign, $qth, $upload_path) { - $eqsl_id = $callsign . '-' . $qth; + private static function safe_filepath($callsign, $qth, $upload_path, $station_id) { + $eqsl_id = sprintf('%s-%s_%03d', $callsign, $qth, $station_id); // Replace anything which isn't a word, whitespace, number or any of the following caracters -_~,;[](). with a '.' $eqsl_id = mb_ereg_replace("([^\w\s\d\-_~,;\[\]\(\).])", '.', $eqsl_id); @@ -53,7 +56,7 @@ class EqslImporter } // Download confirmed QSO from eQSL inbox and import them - public function fetch($password, $eqsl_force_from_date="") { + public function fetch($password, $eqsl_force_from_date = false) { if (empty($password) || empty($this->callsign)) { return $this->result('Missing username and/or password'); } @@ -137,7 +140,8 @@ class EqslImporter $query = $this->CI->db->query('SELECT eqsl_rcvd_mark FROM config'); $q = $query->row(); $config['eqsl_rcvd_mark'] = $q->eqsl_rcvd_mark; - $station_callsign=$this->callsign; + $station_callsign = $this->callsign; + $station_id = $this->station_id; $this->CI->adif_parser->load_from_file($this->adif_file); $this->CI->adif_parser->initialize(); @@ -156,14 +160,14 @@ class EqslImporter $record['qsl_sent'] = $config['eqsl_rcvd_mark']; } - $status = $this->CI->logbook_model->import_check($time_on, $record['call'], $record['band'], $record['mode'],$station_callsign); + $status = $this->CI->logbook_model->import_check($time_on, $record['call'], $record['band'], $record['mode'], $station_callsign, $station_id); $qsoid = 0; if ($status[0] == "Found") { $qsoid = $status[1]; - $dupe = $this->CI->eqslmethods_model->eqsl_dupe_check($time_on, $record['call'], $record['band'], $record['mode'],$config['eqsl_rcvd_mark'],$station_callsign); + $dupe = $this->CI->eqslmethods_model->eqsl_dupe_check($time_on, $record['call'], $record['band'], $record['mode'], $config['eqsl_rcvd_mark'], $station_callsign, $station_id); if ($dupe == false) { $updated += 1; - $eqsl_status = $this->CI->eqslmethods_model->eqsl_update($time_on, $record['call'], $record['band'], $record['mode'], $config['eqsl_rcvd_mark'],$station_callsign); + $eqsl_status = $this->CI->eqslmethods_model->eqsl_update($time_on, $record['call'], $record['band'], $record['mode'], $config['eqsl_rcvd_mark'], $station_callsign, $station_id); } else { $dupes += 1; $eqsl_status = "Already received an eQSL for this QSO."; diff --git a/application/models/Eqslmethods_model.php b/application/models/Eqslmethods_model.php index 13e05dc6..4d782f5b 100644 --- a/application/models/Eqslmethods_model.php +++ b/application/models/Eqslmethods_model.php @@ -122,7 +122,7 @@ class Eqslmethods_model extends CI_Model { $this->db->where('eqslqthnickname IS NOT NULL'); $this->db->where('eqslqthnickname !=', ''); $this->db->from('station_profile'); - $this->db->select('station_callsign, eqslqthnickname'); + $this->db->select('station_callsign, eqslqthnickname, station_id'); $this->db->distinct(TRUE); return $this->db->get(); @@ -156,9 +156,10 @@ class Eqslmethods_model extends CI_Model { } // Update a QSO with eQSL QSL info - // We could also probably use this use this: https://eqsl.cc/qslcard/VerifyQSO.txt + // We could also probably use this: + // https://eqsl.cc/qslcard/VerifyQSO.txt // https://www.eqsl.cc/qslcard/ImportADIF.txt - function eqsl_update($datetime, $callsign, $band, $mode, $qsl_status,$station_callsign) { + function eqsl_update($datetime, $callsign, $band, $mode, $qsl_status, $station_callsign, $station_id) { $data = array( 'COL_EQSL_QSLRDATE' => date('Y-m-d H:i:s'), // eQSL doesn't give us a date, so let's use current 'COL_EQSL_QSL_RCVD' => $qsl_status @@ -170,6 +171,7 @@ class Eqslmethods_model extends CI_Model { $this->db->where('COL_STATION_CALLSIGN', $station_callsign); $this->db->where('COL_BAND', $band); $this->db->where('COL_MODE', $mode); + $this->db->where('station_id', $station_id); $this->db->update($this->config->item('table_name'), $data); @@ -177,7 +179,7 @@ class Eqslmethods_model extends CI_Model { } // Determine if we've already received an eQSL for this QSO - function eqsl_dupe_check($datetime, $callsign, $band, $mode, $qsl_status,$station_callsign) { + function eqsl_dupe_check($datetime, $callsign, $band, $mode, $qsl_status, $station_callsign, $station_id) { $this->db->select('COL_EQSL_QSLRDATE'); $this->db->where('COL_TIME_ON >= DATE_ADD(DATE_FORMAT("'.$datetime.'", \'%Y-%m-%d %H:%i\' ), INTERVAL -15 MINUTE )'); $this->db->where('COL_TIME_ON <= DATE_ADD(DATE_FORMAT("'.$datetime.'", \'%Y-%m-%d %H:%i\' ), INTERVAL 15 MINUTE )'); @@ -186,6 +188,7 @@ class Eqslmethods_model extends CI_Model { $this->db->where('COL_MODE', $mode); $this->db->where('COL_STATION_CALLSIGN', $station_callsign); $this->db->where('COL_EQSL_QSL_RCVD', $qsl_status); + $this->db->where('station_id', $station_id); $this->db->limit(1); $query = $this->db->get($this->config->item('table_name')); diff --git a/application/models/Logbook_model.php b/application/models/Logbook_model.php index 8b1d06b3..08459fd2 100755 --- a/application/models/Logbook_model.php +++ b/application/models/Logbook_model.php @@ -2976,9 +2976,8 @@ class Logbook_model extends CI_Model } /* Used to check if the qso is already in the database */ - function import_check($datetime, $callsign, $band, $mode, $station_callsign) - { - $mode = $this->get_main_mode_from_mode($mode); + function import_check($datetime, $callsign, $band, $mode, $station_callsign, $station_id = null) { + $mode=$this->get_main_mode_from_mode($mode); $this->db->select('COL_PRIMARY_KEY, COL_TIME_ON, COL_CALL, COL_BAND'); $this->db->where('COL_TIME_ON >= DATE_ADD(DATE_FORMAT("' . $datetime . '", \'%Y-%m-%d %H:%i\' ), INTERVAL -15 MINUTE )'); @@ -2988,6 +2987,10 @@ class Logbook_model extends CI_Model $this->db->where('COL_BAND', $band); $this->db->where('COL_MODE', $mode); + if(isset($station_id) && $station_id > 0) { + $this->db->where('station_id', $station_id); + } + $query = $this->db->get($this->config->item('table_name')); if ($query->num_rows() > 0) {