kopia lustrzana https://github.com/magicbug/Cloudlog
add stations_id to eqsl functions
rodzic
4b4724d872
commit
1d11d00ea8
|
@ -74,10 +74,11 @@ class eqsl extends CI_Controller {
|
||||||
$this->eqslimporter->from_callsign_and_QTH(
|
$this->eqslimporter->from_callsign_and_QTH(
|
||||||
$eqsl_location['station_callsign'],
|
$eqsl_location['station_callsign'],
|
||||||
$eqsl_location['eqslqthnickname'],
|
$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') {
|
} elseif ($this->input->post('eqslimport') == 'upload') {
|
||||||
$station_id4upload=$this->input->post('station_profile');
|
$station_id4upload=$this->input->post('station_profile');
|
||||||
|
@ -97,7 +98,7 @@ class eqsl extends CI_Controller {
|
||||||
$data = array('upload_data' => $this->upload->data());
|
$data = array('upload_data' => $this->upload->data());
|
||||||
|
|
||||||
$this->load->library('EqslImporter');
|
$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();
|
$eqsl_results[] = $this->eqslimporter->import();
|
||||||
}
|
}
|
||||||
|
@ -728,7 +729,8 @@ class eqsl extends CI_Controller {
|
||||||
$this->eqslimporter->from_callsign_and_QTH(
|
$this->eqslimporter->from_callsign_and_QTH(
|
||||||
$eqsl_location['station_callsign'],
|
$eqsl_location['station_callsign'],
|
||||||
$eqsl_location['eqslqthnickname'],
|
$eqsl_location['eqslqthnickname'],
|
||||||
$config['upload_path']
|
$config['upload_path'],
|
||||||
|
$eqsl_location['station_id']
|
||||||
);
|
);
|
||||||
|
|
||||||
$eqsl_results[] = $this->eqslimporter->fetch($password);
|
$eqsl_results[] = $this->eqslimporter->fetch($password);
|
||||||
|
|
|
@ -8,6 +8,7 @@ class EqslImporter
|
||||||
private $callsign;
|
private $callsign;
|
||||||
private $qth_nickname;
|
private $qth_nickname;
|
||||||
private $adif_file;
|
private $adif_file;
|
||||||
|
private $station_id;
|
||||||
|
|
||||||
// CodeIgniter super-ojbect
|
// CodeIgniter super-ojbect
|
||||||
private $CI;
|
private $CI;
|
||||||
|
@ -26,24 +27,26 @@ class EqslImporter
|
||||||
$this->adif_file = $adif_file;
|
$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(
|
$this->init(
|
||||||
$qth . " - " . $callsign,
|
$qth . " - " . $callsign,
|
||||||
self::safe_filepath($callsign, $qth, $upload_path)
|
self::safe_filepath($callsign, $qth, $upload_path, $station_id)
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->callsign = $callsign;
|
$this->callsign = $callsign;
|
||||||
$this->qth_nickname = $qth;
|
$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->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
|
// generate a sanitized file name from a callsign and a QTH nickname
|
||||||
private static function safe_filepath($callsign, $qth, $upload_path) {
|
private static function safe_filepath($callsign, $qth, $upload_path, $station_id) {
|
||||||
$eqsl_id = $callsign . '-' . $qth;
|
$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 '.'
|
// 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);
|
$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
|
// 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)) {
|
if (empty($password) || empty($this->callsign)) {
|
||||||
return $this->result('Missing username and/or password');
|
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');
|
$query = $this->CI->db->query('SELECT eqsl_rcvd_mark FROM config');
|
||||||
$q = $query->row();
|
$q = $query->row();
|
||||||
$config['eqsl_rcvd_mark'] = $q->eqsl_rcvd_mark;
|
$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->load_from_file($this->adif_file);
|
||||||
$this->CI->adif_parser->initialize();
|
$this->CI->adif_parser->initialize();
|
||||||
|
@ -156,14 +160,14 @@ class EqslImporter
|
||||||
$record['qsl_sent'] = $config['eqsl_rcvd_mark'];
|
$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;
|
$qsoid = 0;
|
||||||
if ($status[0] == "Found") {
|
if ($status[0] == "Found") {
|
||||||
$qsoid = $status[1];
|
$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) {
|
if ($dupe == false) {
|
||||||
$updated += 1;
|
$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 {
|
} else {
|
||||||
$dupes += 1;
|
$dupes += 1;
|
||||||
$eqsl_status = "Already received an eQSL for this QSO.";
|
$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 IS NOT NULL');
|
||||||
$this->db->where('eqslqthnickname !=', '');
|
$this->db->where('eqslqthnickname !=', '');
|
||||||
$this->db->from('station_profile');
|
$this->db->from('station_profile');
|
||||||
$this->db->select('station_callsign, eqslqthnickname');
|
$this->db->select('station_callsign, eqslqthnickname, station_id');
|
||||||
$this->db->distinct(TRUE);
|
$this->db->distinct(TRUE);
|
||||||
|
|
||||||
return $this->db->get();
|
return $this->db->get();
|
||||||
|
@ -156,9 +156,10 @@ class Eqslmethods_model extends CI_Model {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update a QSO with eQSL QSL info
|
// 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
|
// 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(
|
$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_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
|
'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_STATION_CALLSIGN', $station_callsign);
|
||||||
$this->db->where('COL_BAND', $band);
|
$this->db->where('COL_BAND', $band);
|
||||||
$this->db->where('COL_MODE', $mode);
|
$this->db->where('COL_MODE', $mode);
|
||||||
|
$this->db->where('station_id', $station_id);
|
||||||
|
|
||||||
$this->db->update($this->config->item('table_name'), $data);
|
$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
|
// 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->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 )');
|
||||||
$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_MODE', $mode);
|
||||||
$this->db->where('COL_STATION_CALLSIGN', $station_callsign);
|
$this->db->where('COL_STATION_CALLSIGN', $station_callsign);
|
||||||
$this->db->where('COL_EQSL_QSL_RCVD', $qsl_status);
|
$this->db->where('COL_EQSL_QSL_RCVD', $qsl_status);
|
||||||
|
$this->db->where('station_id', $station_id);
|
||||||
$this->db->limit(1);
|
$this->db->limit(1);
|
||||||
|
|
||||||
$query = $this->db->get($this->config->item('table_name'));
|
$query = $this->db->get($this->config->item('table_name'));
|
||||||
|
|
|
@ -2976,9 +2976,8 @@ class Logbook_model extends CI_Model
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Used to check if the qso is already in the database */
|
/* Used to check if the qso is already in the database */
|
||||||
function import_check($datetime, $callsign, $band, $mode, $station_callsign)
|
function import_check($datetime, $callsign, $band, $mode, $station_callsign, $station_id = null) {
|
||||||
{
|
$mode=$this->get_main_mode_from_mode($mode);
|
||||||
$mode = $this->get_main_mode_from_mode($mode);
|
|
||||||
|
|
||||||
$this->db->select('COL_PRIMARY_KEY, COL_TIME_ON, COL_CALL, COL_BAND');
|
$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 )');
|
$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_BAND', $band);
|
||||||
$this->db->where('COL_MODE', $mode);
|
$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'));
|
$query = $this->db->get($this->config->item('table_name'));
|
||||||
|
|
||||||
if ($query->num_rows() > 0) {
|
if ($query->num_rows() > 0) {
|
||||||
|
|
Ładowanie…
Reference in New Issue