mirror of
https://github.com/magicbug/Cloudlog
synced 2024-11-22 17:52:16 +00:00
Merge pull request #2961 from dg0tm/eqsl_fix_stationsid
add stations_id to eqsl functions
This commit is contained in:
commit
e96d6ef3fc
@ -73,10 +73,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');
|
||||
@ -96,7 +97,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();
|
||||
}
|
||||
@ -726,7 +727,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);
|
||||
|
@ -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.";
|
||||
|
@ -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'));
|
||||
|
@ -2984,9 +2984,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 )');
|
||||
@ -2996,6 +2995,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) {
|
||||
|
Loading…
Reference in New Issue
Block a user