当前提交
aef5af5b4f
共有 5 个文件被更改,包括 113 次插入 和 92 次删除
|
|
@ -13,8 +13,8 @@ class eqsl extends CI_Controller {
|
|||
if(!$this->user_model->authorize(2)) { $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); redirect('dashboard'); }
|
||||
|
||||
// Check if eQSL Nicknames have been defined
|
||||
$this->load->model('stations');
|
||||
$eqsl_locations = $this->stations->all_of_user_with_eqsl_nick_defined();
|
||||
$this->load->model('eqslmethods_model');
|
||||
$eqsl_locations = $this->eqslmethods_model->all_of_user_with_eqsl_nick_defined();
|
||||
if($eqsl_locations->num_rows() == 0) {
|
||||
show_error("eQSL Nicknames in Station Profiles aren't defined");
|
||||
exit;
|
||||
|
|
@ -28,8 +28,6 @@ class eqsl extends CI_Controller {
|
|||
|
||||
$this->load->library('upload', $config);
|
||||
|
||||
$this->load->model('eqslmethods_model');
|
||||
|
||||
$eqsl_results = array();
|
||||
if ($this->input->post('eqslimport') == 'fetch')
|
||||
{
|
||||
|
|
@ -472,6 +470,7 @@ class eqsl extends CI_Controller {
|
|||
|
||||
if($this->Eqsl_images->get_image($id) == "No Image") {
|
||||
$this->load->model('logbook_model');
|
||||
$this->load->model('user_model');
|
||||
$qso_query = $this->logbook_model->get_qso($id);
|
||||
$qso = $qso_query->row();
|
||||
$qso_timestamp = strtotime($qso->COL_TIME_ON);
|
||||
|
|
@ -554,19 +553,40 @@ class eqsl extends CI_Controller {
|
|||
/*
|
||||
* Used for CRON job
|
||||
*/
|
||||
public function upload() {
|
||||
public function sync() {
|
||||
ini_set('memory_limit', '-1');
|
||||
set_time_limit(0);
|
||||
$this->load->model('eqslmethods_model');
|
||||
|
||||
$users = $this->eqslmethods_model->get_eqsl_users();
|
||||
|
||||
foreach ($users as $user) {
|
||||
$this->uploadUser($user->user_id, $user->user_eqsl_name, $user->user_eqsl_password);
|
||||
$this->downloadUser($user->user_id, $user->user_eqsl_name, $user->user_eqsl_password);
|
||||
}
|
||||
}
|
||||
|
||||
public function downloadUser($userid, $username, $password) {
|
||||
$this->load->library('EqslImporter');
|
||||
$this->load->model('eqslmethods_model');
|
||||
|
||||
$config['upload_path'] = './uploads/';
|
||||
$eqsl_locations = $this->eqslmethods_model->all_of_user_with_eqsl_nick_defined($userid);
|
||||
|
||||
$eqsl_results = array();
|
||||
|
||||
foreach ($eqsl_locations->result_array() as $eqsl_location) {
|
||||
$this->eqslimporter->from_callsign_and_QTH(
|
||||
$eqsl_location['station_callsign'],
|
||||
$eqsl_location['eqslqthnickname'],
|
||||
$config['upload_path']
|
||||
);
|
||||
|
||||
$eqsl_results[] = $this->eqslimporter->fetch($password);
|
||||
}
|
||||
}
|
||||
|
||||
function uploadUser($userid, $username, $password) {
|
||||
ini_set('memory_limit', '-1');
|
||||
set_time_limit(0);
|
||||
$data['user_eqsl_name'] = $this->security->xss_clean($username);
|
||||
$data['user_eqsl_password'] = $this->security->xss_clean($password);
|
||||
$clean_userid = $this->security->xss_clean($userid);
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ class EqslImporter
|
|||
|
||||
$this->CI->load->model('logbook_model');
|
||||
$this->CI->load->library('adif_parser');
|
||||
$this->CI->load->model('eqslmethods_model');
|
||||
}
|
||||
|
||||
private function init($name, $adif_file) {
|
||||
|
|
@ -62,7 +63,7 @@ class EqslImporter
|
|||
$eqsl_url = $q->eqsl_download_url;
|
||||
|
||||
// Query the logbook to determine when the last eQSL confirmation was
|
||||
$eqsl_last_qsl_date = $this->CI->logbook_model->eqsl_last_qsl_rcvd_date($this->callsign, $this->qth_nickname);
|
||||
$eqsl_last_qsl_date = $this->CI->eqslmethods_model->eqsl_last_qsl_rcvd_date($this->callsign, $this->qth_nickname);
|
||||
|
||||
// Build parameters for eQSL inbox file
|
||||
$eqsl_params = http_build_query(array(
|
||||
|
|
@ -157,10 +158,10 @@ class EqslImporter
|
|||
$qsoid = 0;
|
||||
if ($status[0] == "Found") {
|
||||
$qsoid = $status[1];
|
||||
$dupe = $this->CI->logbook_model->eqsl_dupe_check($time_on, $record['call'], $record['band'], $config['eqsl_rcvd_mark']);
|
||||
$dupe = $this->CI->eqslmethods_model->eqsl_dupe_check($time_on, $record['call'], $record['band'], $config['eqsl_rcvd_mark']);
|
||||
if ($dupe == false) {
|
||||
$updated += 1;
|
||||
$eqsl_status = $this->CI->logbook_model->eqsl_update($time_on, $record['call'], $record['band'], $config['eqsl_rcvd_mark']);
|
||||
$eqsl_status = $this->CI->eqslmethods_model->eqsl_update($time_on, $record['call'], $record['band'], $config['eqsl_rcvd_mark']);
|
||||
} else {
|
||||
$dupes += 1;
|
||||
$eqsl_status = "Already received an eQSL for this QSO.";
|
||||
|
|
|
|||
|
|
@ -81,6 +81,88 @@ class Eqslmethods_model extends CI_Model {
|
|||
return "eQSL Sent";
|
||||
}
|
||||
|
||||
// Returns all the distinct callsign, eqsl nick pair for the current user/supplied user
|
||||
function all_of_user_with_eqsl_nick_defined($userid = null) {
|
||||
if ($userid == null) {
|
||||
$this->db->where('user_id', $this->session->userdata('user_id'));
|
||||
} else {
|
||||
$this->db->where('user_id', $userid);
|
||||
}
|
||||
|
||||
$this->db->where('eqslqthnickname IS NOT NULL');
|
||||
$this->db->where('eqslqthnickname !=', '');
|
||||
$this->db->from('station_profile');
|
||||
$this->db->select('station_callsign, eqslqthnickname');
|
||||
$this->db->distinct(TRUE);
|
||||
|
||||
return $this->db->get();
|
||||
}
|
||||
|
||||
// Get the last date we received an eQSL
|
||||
function eqsl_last_qsl_rcvd_date($callsign, $nickname) {
|
||||
$qso_table_name = $this->config->item('table_name');
|
||||
$this->db->from($qso_table_name);
|
||||
|
||||
$this->db->join('station_profile',
|
||||
'station_profile.station_id = '.$qso_table_name.'.station_id AND station_profile.eqslqthnickname != ""');
|
||||
$this->db->where('station_profile.station_callsign', $callsign);
|
||||
$this->db->where('station_profile.eqslqthnickname', $nickname);
|
||||
|
||||
$this->db->select("DATE_FORMAT(COL_EQSL_QSLRDATE,'%Y%m%d') AS COL_EQSL_QSLRDATE", FALSE);
|
||||
$this->db->where('COL_EQSL_QSLRDATE IS NOT NULL');
|
||||
$this->db->order_by("COL_EQSL_QSLRDATE", "desc");
|
||||
$this->db->limit(1);
|
||||
|
||||
$query = $this->db->get();
|
||||
$row = $query->row();
|
||||
|
||||
if (isset($row->COL_EQSL_QSLRDATE)){
|
||||
return $row->COL_EQSL_QSLRDATE;
|
||||
} else {
|
||||
// No previous date (first time import has run?), so choose UNIX EPOCH!
|
||||
// Note: date is yyyy/mm/dd format
|
||||
return '1970/01/01';
|
||||
}
|
||||
}
|
||||
|
||||
// Update a QSO with eQSL QSL info
|
||||
// We could also probably use this use this: http://eqsl.cc/qslcard/VerifyQSO.txt
|
||||
// http://www.eqsl.cc/qslcard/ImportADIF.txt
|
||||
function eqsl_update($datetime, $callsign, $band, $qsl_status) {
|
||||
$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
|
||||
);
|
||||
|
||||
$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_CALL', $callsign);
|
||||
$this->db->where('COL_BAND', $band);
|
||||
|
||||
$this->db->update($this->config->item('table_name'), $data);
|
||||
|
||||
return "Updated";
|
||||
}
|
||||
|
||||
// Determine if we've already received an eQSL for this QSO
|
||||
function eqsl_dupe_check($datetime, $callsign, $band, $qsl_status) {
|
||||
$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_CALL', $callsign);
|
||||
$this->db->where('COL_BAND', $band);
|
||||
$this->db->where('COL_EQSL_QSL_RCVD', $qsl_status);
|
||||
$this->db->limit(1);
|
||||
|
||||
$query = $this->db->get($this->config->item('table_name'));
|
||||
$row = $query->row();
|
||||
|
||||
if ($row != null) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
@ -2553,76 +2553,6 @@ class Logbook_model extends CI_Model {
|
|||
return '1900-01-01 00:00:00.000';
|
||||
}
|
||||
|
||||
//////////////////////////////
|
||||
// Update a QSO with eQSL QSL info
|
||||
// We could also probably use this use this: http://eqsl.cc/qslcard/VerifyQSO.txt
|
||||
// http://www.eqsl.cc/qslcard/ImportADIF.txt
|
||||
function eqsl_update($datetime, $callsign, $band, $qsl_status) {
|
||||
$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
|
||||
);
|
||||
|
||||
$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_CALL', $callsign);
|
||||
$this->db->where('COL_BAND', $band);
|
||||
|
||||
$this->db->update($this->config->item('table_name'), $data);
|
||||
|
||||
return "Updated";
|
||||
}
|
||||
|
||||
// Get the last date we received an eQSL
|
||||
function eqsl_last_qsl_rcvd_date($callsign, $nickname) {
|
||||
$qso_table_name = $this->config->item('table_name');
|
||||
$this->db->from($qso_table_name);
|
||||
|
||||
$this->db->join('station_profile',
|
||||
'station_profile.station_id = '.$qso_table_name.'.station_id AND station_profile.eqslqthnickname != ""');
|
||||
$this->db->where('station_profile.station_callsign', $callsign);
|
||||
$this->db->where('station_profile.eqslqthnickname', $nickname);
|
||||
|
||||
$this->db->select("DATE_FORMAT(COL_EQSL_QSLRDATE,'%Y%m%d') AS COL_EQSL_QSLRDATE", FALSE);
|
||||
$this->db->where('COL_EQSL_QSLRDATE IS NOT NULL');
|
||||
$this->db->order_by("COL_EQSL_QSLRDATE", "desc");
|
||||
$this->db->limit(1);
|
||||
|
||||
$query = $this->db->get();
|
||||
$row = $query->row();
|
||||
|
||||
if (isset($row->COL_EQSL_QSLRDATE)){
|
||||
return $row->COL_EQSL_QSLRDATE;
|
||||
}else{
|
||||
// No previous date (first time import has run?), so choose UNIX EPOCH!
|
||||
// Note: date is yyyy/mm/dd format
|
||||
return '1970/01/01';
|
||||
}
|
||||
}
|
||||
|
||||
// Determine if we've already received an eQSL for this QSO
|
||||
function eqsl_dupe_check($datetime, $callsign, $band, $qsl_status) {
|
||||
$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_CALL', $callsign);
|
||||
$this->db->where('COL_BAND', $band);
|
||||
$this->db->where('COL_EQSL_QSL_RCVD', $qsl_status);
|
||||
$this->db->limit(1);
|
||||
|
||||
$query = $this->db->get($this->config->item('table_name'));
|
||||
$row = $query->row();
|
||||
|
||||
if ($row != null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* $skipDuplicate - used in ADIF import to skip duplicate checking when importing QSOs
|
||||
* $markLoTW - used in ADIF import to mark QSOs as exported to LoTW when importing QSOs
|
||||
|
|
|
|||
|
|
@ -397,18 +397,6 @@ class Stations extends CI_Model {
|
|||
return $query->num_rows();
|
||||
}
|
||||
|
||||
// Returns all the distinct callsing, eqsl nick pair for the current user
|
||||
function all_of_user_with_eqsl_nick_defined() {
|
||||
$this->db->where('user_id', $this->session->userdata('user_id'));
|
||||
$this->db->where('eqslqthnickname IS NOT NULL');
|
||||
$this->db->where('eqslqthnickname !=', '');
|
||||
$this->db->from('station_profile');
|
||||
$this->db->select('station_callsign, eqslqthnickname');
|
||||
$this->db->distinct(TRUE);
|
||||
|
||||
return $this->db->get();
|
||||
}
|
||||
|
||||
public function check_station_is_accessible($id) {
|
||||
// check if station belongs to user
|
||||
$this->db->select('station_id');
|
||||
|
|
|
|||
正在加载…
在新工单中引用