Merge pull request #2111 from AndreasK79/eqsl_cron_job

[eQSL] Added cron job for eQSL
这个提交包含在:
Andreas Kristiansen 2023-05-05 14:47:48 +02:00 提交者 GitHub
当前提交 ef3bb13d6f
找不到此签名对应的密钥
GPG 密钥 ID: 4AEE18F83AFDEB23
共有 4 个文件被更改,包括 434 次插入382 次删除

查看文件

@ -3,8 +3,7 @@
class eqsl extends CI_Controller {
/* Controls who can access the controller and its functions */
function __construct()
{
function __construct() {
parent::__construct();
$this->load->helper(array('form', 'url'));
@ -29,7 +28,7 @@ class eqsl extends CI_Controller {
$this->load->library('upload', $config);
$this->load->model('logbook_model');
$this->load->model('eqslmethods_model');
$eqsl_results = array();
if ($this->input->post('eqslimport') == 'fetch')
@ -100,17 +99,16 @@ class eqsl extends CI_Controller {
ini_set('memory_limit', '-1');
set_time_limit(0);
$this->load->model('logbook_model');
$this->load->model('eqslmethods_model');
$data['page_title'] = "eQSL QSO Upload";
$custom_date_format = $this->session->userdata('user_date_format');
if ($this->input->post('eqslexport') == "export")
{
if ($this->input->post('eqslexport') == "export") {
// Get credentials for eQSL
$query = $this->user_model->get_by_id($this->session->userdata('user_id'));
$q = $query->row();
$data['user_eqsl_name'] = $q->user_eqsl_name;
$q = $query->row();
$data['user_eqsl_name'] = $q->user_eqsl_name;
$data['user_eqsl_password'] = $q->user_eqsl_password;
// Validate that eQSL credentials are not empty
@ -121,347 +119,39 @@ class eqsl extends CI_Controller {
// Grab the list of QSOs to send information about
// perform an HTTP get on each one, and grab the status back
$qslsnotsent = $this->logbook_model->eqsl_not_yet_sent();
$qslsnotsent = $this->eqslmethods_model->eqsl_not_yet_sent();
$rows = "<tr>";
foreach ($qslsnotsent->result_array() as $qsl) {
$table = "<table width=\"100%\">";
$table .= "<tr class=\"titles\">";
$table .= "<td>Date</td>";
$table .= "<td>Time</td>";
$table .= "<td>Call</td>";
$table .= "<td>Mode</td>";
$table .= "<td>Submode</td>";
$table .= "<td>Band</td>";
$table .= "<td>Result</td>";
$table .= "<tr>";
// Build out the ADIF info string according to specs http://eqsl.cc/qslcard/ADIFContentSpecs.cfm
foreach ($qslsnotsent->result_array() as $qsl)
{
// eQSL username changes for linked account.
// i.e. when operating /P it must be callsign/p
// the password, however, is always the same as the main account
$data['user_eqsl_name'] = $qsl['station_callsign'];
$adif = $this->generateAdif($qsl, $data);
$COL_QSO_DATE = date('Ymd',strtotime($qsl['COL_TIME_ON']));
$COL_TIME_ON = date('Hi',strtotime($qsl['COL_TIME_ON']));
$status = $this->uploadQso($adif, $qsl);
# Set up the single record file
$adif = "http://www.eqsl.cc/qslcard/importADIF.cfm?";
$adif .= "ADIFData=CloudlogUpload%20";
/* Handy reference of escaping chars
"<" = 3C
">" = 3E
":" = 3A
" " = 20
"_" = 5F
"-" = 2D
"." = 2E
*/
$adif .= "%3C";
$adif .= "ADIF%5FVER";
$adif .= "%3A";
$adif .= "4";
$adif .= "%3E";
$adif .= "1%2E00 ";
$adif .= "%20";
$adif .= "%3C";
$adif .= "EQSL%5FUSER";
$adif .= "%3A";
$adif .= strlen($data['user_eqsl_name']);
$adif .= "%3E";
$adif .= $data['user_eqsl_name'];
$adif .= "%20";
$adif .= "%3C";
$adif .= "EQSL%5FPSWD";
$adif .= "%3A";
$adif .= strlen($data['user_eqsl_password']);
$adif .= "%3E";
$adif .= urlencode($data['user_eqsl_password']);
$adif .= "%20";
$adif .= "%3C";
$adif .= "EOH";
$adif .= "%3E";
# Lay out the required fields
$adif .= "%3C";
$adif .= "QSO%5FDATE";
$adif .= "%3A";
$adif .= "8";
$adif .= "%3E";
$adif .= $COL_QSO_DATE;
$adif .= "%20";
$adif .= "%3C";
$adif .= "TIME%5FON";
$adif .= "%3A";
$adif .= "4";
$adif .= "%3E";
$adif .= $COL_TIME_ON;
$adif .= "%20";
$adif .= "%3C";
$adif .= "CALL";
$adif .= "%3A";
$adif .= strlen($qsl['COL_CALL']);
$adif .= "%3E";
$adif .= $qsl['COL_CALL'];
$adif .= "%20";
$adif .= "%3C";
$adif .= "MODE";
$adif .= "%3A";
$adif .= strlen($qsl['COL_MODE']);
$adif .= "%3E";
$adif .= $qsl['COL_MODE'];
$adif .= "%20";
$timestamp = strtotime($qsl['COL_TIME_ON']);
$rows .= "<td>".date($custom_date_format, $timestamp)."</td>";
$rows .= "<td>".date('H:i', $timestamp)."</td>";
$rows .= "<td>".str_replace("0","&Oslash;",$qsl['COL_CALL'])."</td>";
$rows .= "<td>".$qsl['COL_MODE']."</td>";
if(isset($qsl['COL_SUBMODE'])) {
$adif .= "%3C";
$adif .= "SUBMODE";
$adif .= "%3A";
$adif .= strlen($qsl['COL_SUBMODE']);
$adif .= "%3E";
$adif .= $qsl['COL_SUBMODE'];
$adif .= "%20";
$rows .= "<td>".$qsl['COL_SUBMODE']."</td>";
} else {
$rows .= "<td></td>";
}
$adif .= "%3C";
$adif .= "BAND";
$adif .= "%3A";
$adif .= strlen($qsl['COL_BAND']);
$adif .= "%3E";
$adif .= $qsl['COL_BAND'];
$adif .= "%20";
# End all the required fields
// adding RST_Sent
$adif .= "%3C";
$adif .= "RST%5FSENT";
$adif .= "%3A";
$adif .= strlen($qsl['COL_RST_SENT']);
$adif .= "%3E";
$adif .= $qsl['COL_RST_SENT'];
$adif .= "%20";
// adding prop mode if it isn't blank
if ($qsl['COL_PROP_MODE']){
$adif .= "%3C";
$adif .= "PROP%5FMODE";
$adif .= "%3A";
$adif .= strlen($qsl['COL_PROP_MODE']);
$adif .= "%3E";
$adif .= $qsl['COL_PROP_MODE'];
$adif .= "%20";
}
// adding sat name if it isn't blank
if ($qsl['COL_SAT_NAME'] != ''){
$adif .= "%3C";
$adif .= "SAT%5FNAME";
$adif .= "%3A";
$adif .= strlen($qsl['COL_SAT_NAME']);
$adif .= "%3E";
$adif .= str_replace('-', '%2D', $qsl['COL_SAT_NAME']);
$adif .= "%20";
}
// adding sat mode if it isn't blank
if ($qsl['COL_SAT_MODE'] != ''){
$adif .= "%3C";
$adif .= "SAT%5FMODE";
$adif .= "%3A";
$adif .= strlen($qsl['COL_SAT_MODE']);
$adif .= "%3E";
$adif .= $qsl['COL_SAT_MODE'];
$adif .= "%20";
}
// adding qslmsg if it isn't blank
if ($qsl['COL_QSLMSG'] != ''){
$adif .= "%3C";
$adif .= "QSLMSG";
$adif .= "%3A";
$adif .= strlen($qsl['COL_QSLMSG']);
$adif .= "%3E";
$adif .= $qsl['COL_QSLMSG'];
$adif .= "%20";
}
if ($qsl['eqslqthnickname'] != ''){
$adif .= "%3C";
$adif .= "APP%5FEQSL%5FQTH%5FNICKNAME";
$adif .= "%3A";
$adif .= strlen($qsl['eqslqthnickname']);
$adif .= "%3E";
$adif .= $qsl['eqslqthnickname'];
$adif .= "%20";
}
// adding sat mode if it isn't blank
if ($qsl['station_gridsquare'] != ''){
$adif .= "%3C";
$adif .= "MY%5FGRIDSQUARE";
$adif .= "%3A";
$adif .= strlen($qsl['station_gridsquare']);
$adif .= "%3E";
$adif .= $qsl['station_gridsquare'];
$adif .= "%20";
}
# Tie a bow on it!
$adif .= "%3C";
$adif .= "EOR";
$adif .= "%3E";
# Make sure we don't have any spaces
$adif = str_replace(" ", '%20', $adif);
$status = "";
// begin script
$ch = curl_init();
// basic curl options for all requests
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
// use the URL we built
curl_setopt($ch, CURLOPT_URL, $adif);
$result = curl_exec($ch);
$chi = curl_getinfo($ch);
curl_close($ch);
/* Time for some error handling
Things we might get back
Result: 0 out of 0 records added -> eQSL didn't understand the format
Result: 1 out of 1 records added -> Fantastic
Error: No match on eQSL_User/eQSL_Pswd -> eQSL credentials probably wrong
Warning: Y=2013 M=08 D=11 F6ARS 15M JT65 Bad record: Duplicate
Result: 0 out of 1 records added -> Dupe, OM!
*/
if ($chi['http_code'] == "200")
{
if (stristr($result, "Result: 1 out of 1 records added"))
{
$status = "Sent";
$this->logbook_model->eqsl_mark_sent($qsl['COL_PRIMARY_KEY']);
}
else
{
if (stristr($result, "Error: No match on eQSL_User/eQSL_Pswd"))
{
$this->session->set_flashdata('warning', 'Your eQSL username and/or password is incorrect.'); redirect('eqsl/export');
}
else
{
if (stristr($result, "Result: 0 out of 0 records added"))
{
$this->session->set_flashdata('warning', 'Something went wrong with eQSL.cc!'); redirect('eqsl/export');
}
else
{
if (stristr($result, "Bad record: Duplicate"))
{
$status = "Duplicate";
# Mark the QSL as sent if this is a dupe.
$this->logbook_model->eqsl_mark_sent($qsl['COL_PRIMARY_KEY']);
}
}
}
}
}
else
{
if ($chi['http_code'] == "500")
{
$this->session->set_flashdata('warning', 'eQSL.cc is experiencing issues. Please try exporting QSOs later.'); redirect('eqsl/export');
}
else
{
if ($chi['http_code'] == "400")
{
$this->session->set_flashdata('warning', 'There was an error in one of the QSOs. You might want to manually upload them.'); redirect('eqsl/export');
$status = "Error";
}
else
{
if ($chi['http_code'] == "404")
{
$this->session->set_flashdata('warning', 'It seems that the eQSL site has changed. Please open up an issue on GitHub.'); redirect('eqsl/export');
}
}
}
}
$table .= "<tr>";
$timestamp = strtotime($qsl['COL_TIME_ON']);
$table .= "<td>".date($custom_date_format, $timestamp)."</td>";
$table .= "<td>".date('H:i', $timestamp)."</td>";
$table .= "<td>".str_replace("0","&Oslash;",$qsl['COL_CALL'])."</td>";
$table .= "<td>".$qsl['COL_MODE']."</td>";
if(isset($qsl['COL_SUBMODE'])) {
$table .= "<td>".$qsl['COL_SUBMODE']."</td>";
} else {
$table .= "<td></td>";
}
$table .= "<td>".$qsl['COL_BAND']."</td>";
$table .= "<td>".$status."</td>";
$table .= "<tr>";
$rows .= "<td>".$qsl['COL_BAND']."</td>";
$rows .= "<td>".$status."</td>";
}
$table .= "</table>";
// Dump out a table with the results
$data['eqsl_results_table'] = $table;
log_message('debug', $result);
}
else
{
$qslsnotsent = $this->logbook_model->eqsl_not_yet_sent();
if ($qslsnotsent->num_rows() > 0)
{
$table = "<table width=\"100%\">";
$table .= "<tr class=\"titles\">";
$table .= "<td>Date</td>";
$table .= "<td>Time</td>";
$table .= "<td>Call</td>";
$table .= "<td>Mode</td>";
$table .= "<td>Submode</td>";
$table .= "<td>Band</td>";
$table .= "<td>eQSL QTH Nickname</td>";
$table .= "<tr>";
foreach ($qslsnotsent->result_array() as $qsl)
{
$table .= "<tr>";
$timestamp = strtotime($qsl['COL_TIME_ON']);
$table .= "<td>".date($custom_date_format, $timestamp)."</td>";
$table .= "<td>".date('H:i', $timestamp)."</td>";
$table .= "<td><a href=\"javascript:displayQso(" . $qsl['COL_PRIMARY_KEY'] . ")\">" . str_replace("0","&Oslash;",strtoupper($qsl['COL_CALL'])) . "</a></td>";
$table .= "<td>".$qsl['COL_MODE']."</td>";
if(isset($qsl['COL_SUBMODE'])) {
$table .= "<td>".$qsl['COL_SUBMODE']."</td>";
} else {
$table .= "<td></td>";
}
$table .= "<td>".$qsl['COL_BAND']."</td>";
$table .= "<td>".$qsl['eqslqthnickname']."</td>";
$table .= "<tr>";
}
$table .= "</table>";
$data['eqsl_table'] = $table;
$rows .= "</tr>";
$data['eqsl_table'] = $this->generateResultTable($custom_date_format, $rows);
} else {
$qslsnotsent = $this->eqslmethods_model->eqsl_not_yet_sent();
if ($qslsnotsent->num_rows() > 0) {
$data['eqsl_table'] = $this->writeEqslNotSent($qslsnotsent->result_array(), $custom_date_format);
}
}
@ -470,6 +160,309 @@ class eqsl extends CI_Controller {
$this->load->view('interface_assets/footer');
}
function uploadQso($adif, $qsl) {
$this->load->model('eqslmethods_model');
$status = "";
// begin script
$ch = curl_init();
// basic curl options for all requests
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
// use the URL we built
curl_setopt($ch, CURLOPT_URL, $adif);
$result = curl_exec($ch);
$chi = curl_getinfo($ch);
curl_close($ch);
/* Time for some error handling
Things we might get back
Result: 0 out of 0 records added -> eQSL didn't understand the format
Result: 1 out of 1 records added -> Fantastic
Error: No match on eQSL_User/eQSL_Pswd -> eQSL credentials probably wrong
Warning: Y=2013 M=08 D=11 F6ARS 15M JT65 Bad record: Duplicate
Result: 0 out of 1 records added -> Dupe, OM!
*/
if ($chi['http_code'] == "200") {
if (stristr($result, "Result: 1 out of 1 records added")) {
$status = "Sent";
$this->eqslmethods_model->eqsl_mark_sent($qsl['COL_PRIMARY_KEY']);
} else {
if (stristr($result, "Error: No match on eQSL_User/eQSL_Pswd")) {
$this->session->set_flashdata('warning', 'Your eQSL username and/or password is incorrect.'); redirect('eqsl/export');
} else {
if (stristr($result, "Result: 0 out of 0 records added")) {
$this->session->set_flashdata('warning', 'Something went wrong with eQSL.cc!'); redirect('eqsl/export');
} else {
if (stristr($result, "Bad record: Duplicate")) {
$status = "Duplicate";
# Mark the QSL as sent if this is a dupe.
$this->eqslmethods_model->eqsl_mark_sent($qsl['COL_PRIMARY_KEY']);
}
}
}
}
} else {
if ($chi['http_code'] == "500") {
$this->session->set_flashdata('warning', 'eQSL.cc is experiencing issues. Please try exporting QSOs later.'); redirect('eqsl/export');
} else {
if ($chi['http_code'] == "400") {
$this->session->set_flashdata('warning', 'There was an error in one of the QSOs. You might want to manually upload them.'); redirect('eqsl/export');
$status = "Error";
} else {
if ($chi['http_code'] == "404") {
$this->session->set_flashdata('warning', 'It seems that the eQSL site has changed. Please open up an issue on GitHub.'); redirect('eqsl/export');
}
}
}
}
log_message('debug', $result);
return $status;
}
function generateResultTable($custom_date_format, $rows) {
$table = '<table = style="width:100%" class="table-sm table table-bordered table-hover table-striped table-condensed text-center">';
$table .= "<thead><tr class=\"titles\">";
$table .= "<th>Date</th>";
$table .= "<th>Time</th>";
$table .= "<th>Call</th>";
$table .= "<th>Mode</th>";
$table .= "<th>Submode</th>";
$table .= "<th>Band</th>";
$table .= "<th>Status</th>";
$table .= "</tr></thead><tbody>";
$table .= $rows;
$table .= "</tbody></table>";
return $table;
}
// Build out the ADIF info string according to specs http://eqsl.cc/qslcard/ADIFContentSpecs.cfm
function generateAdif($qsl, $data) {
$COL_QSO_DATE = date('Ymd',strtotime($qsl['COL_TIME_ON']));
$COL_TIME_ON = date('Hi',strtotime($qsl['COL_TIME_ON']));
# Set up the single record file
$adif = "http://www.eqsl.cc/qslcard/importADIF.cfm?";
$adif .= "ADIFData=CloudlogUpload%20";
/* Handy reference of escaping chars
"<" = 3C
">" = 3E
":" = 3A
" " = 20
"_" = 5F
"-" = 2D
"." = 2E
*/
$adif .= "%3C";
$adif .= "ADIF%5FVER";
$adif .= "%3A";
$adif .= "4";
$adif .= "%3E";
$adif .= "1%2E00 ";
$adif .= "%20";
$adif .= "%3C";
$adif .= "EQSL%5FUSER";
$adif .= "%3A";
$adif .= strlen($data['user_eqsl_name']);
$adif .= "%3E";
$adif .= $data['user_eqsl_name'];
$adif .= "%20";
$adif .= "%3C";
$adif .= "EQSL%5FPSWD";
$adif .= "%3A";
$adif .= strlen($data['user_eqsl_password']);
$adif .= "%3E";
$adif .= urlencode($data['user_eqsl_password']);
$adif .= "%20";
$adif .= "%3C";
$adif .= "EOH";
$adif .= "%3E";
# Lay out the required fields
$adif .= "%3C";
$adif .= "QSO%5FDATE";
$adif .= "%3A";
$adif .= "8";
$adif .= "%3E";
$adif .= $COL_QSO_DATE;
$adif .= "%20";
$adif .= "%3C";
$adif .= "TIME%5FON";
$adif .= "%3A";
$adif .= "4";
$adif .= "%3E";
$adif .= $COL_TIME_ON;
$adif .= "%20";
$adif .= "%3C";
$adif .= "CALL";
$adif .= "%3A";
$adif .= strlen($qsl['COL_CALL']);
$adif .= "%3E";
$adif .= $qsl['COL_CALL'];
$adif .= "%20";
$adif .= "%3C";
$adif .= "MODE";
$adif .= "%3A";
$adif .= strlen($qsl['COL_MODE']);
$adif .= "%3E";
$adif .= $qsl['COL_MODE'];
$adif .= "%20";
if(isset($qsl['COL_SUBMODE'])) {
$adif .= "%3C";
$adif .= "SUBMODE";
$adif .= "%3A";
$adif .= strlen($qsl['COL_SUBMODE']);
$adif .= "%3E";
$adif .= $qsl['COL_SUBMODE'];
$adif .= "%20";
}
$adif .= "%3C";
$adif .= "BAND";
$adif .= "%3A";
$adif .= strlen($qsl['COL_BAND']);
$adif .= "%3E";
$adif .= $qsl['COL_BAND'];
$adif .= "%20";
# End all the required fields
// adding RST_Sent
$adif .= "%3C";
$adif .= "RST%5FSENT";
$adif .= "%3A";
$adif .= strlen($qsl['COL_RST_SENT']);
$adif .= "%3E";
$adif .= $qsl['COL_RST_SENT'];
$adif .= "%20";
// adding prop mode if it isn't blank
if ($qsl['COL_PROP_MODE']){
$adif .= "%3C";
$adif .= "PROP%5FMODE";
$adif .= "%3A";
$adif .= strlen($qsl['COL_PROP_MODE']);
$adif .= "%3E";
$adif .= $qsl['COL_PROP_MODE'];
$adif .= "%20";
}
// adding sat name if it isn't blank
if ($qsl['COL_SAT_NAME'] != ''){
$adif .= "%3C";
$adif .= "SAT%5FNAME";
$adif .= "%3A";
$adif .= strlen($qsl['COL_SAT_NAME']);
$adif .= "%3E";
$adif .= str_replace('-', '%2D', $qsl['COL_SAT_NAME']);
$adif .= "%20";
}
// adding sat mode if it isn't blank
if ($qsl['COL_SAT_MODE'] != ''){
$adif .= "%3C";
$adif .= "SAT%5FMODE";
$adif .= "%3A";
$adif .= strlen($qsl['COL_SAT_MODE']);
$adif .= "%3E";
$adif .= $qsl['COL_SAT_MODE'];
$adif .= "%20";
}
// adding qslmsg if it isn't blank
if ($qsl['COL_QSLMSG'] != ''){
$adif .= "%3C";
$adif .= "QSLMSG";
$adif .= "%3A";
$adif .= strlen($qsl['COL_QSLMSG']);
$adif .= "%3E";
$adif .= $qsl['COL_QSLMSG'];
$adif .= "%20";
}
if ($qsl['eqslqthnickname'] != ''){
$adif .= "%3C";
$adif .= "APP%5FEQSL%5FQTH%5FNICKNAME";
$adif .= "%3A";
$adif .= strlen($qsl['eqslqthnickname']);
$adif .= "%3E";
$adif .= $qsl['eqslqthnickname'];
$adif .= "%20";
}
// adding sat mode if it isn't blank
if ($qsl['station_gridsquare'] != ''){
$adif .= "%3C";
$adif .= "MY%5FGRIDSQUARE";
$adif .= "%3A";
$adif .= strlen($qsl['station_gridsquare']);
$adif .= "%3E";
$adif .= $qsl['station_gridsquare'];
$adif .= "%20";
}
# Tie a bow on it!
$adif .= "%3C";
$adif .= "EOR";
$adif .= "%3E";
# Make sure we don't have any spaces
$adif = str_replace(" ", '%20', $adif);
return $adif;
}
function writeEqslNotSent($qslsnotsent, $custom_date_format) {
$table = '<table = style="width:100%" class="table-sm table table-bordered table-hover table-striped table-condensed text-center">';
$table .= "<thead><tr class=\"titles\">";
$table .= "<th>Date</th>";
$table .= "<th>Time</th>";
$table .= "<th>Call</th>";
$table .= "<th>Mode</th>";
$table .= "<th>Submode</th>";
$table .= "<th>Band</th>";
$table .= "<th>eQSL QTH Nickname</th>";
$table .= "</tr></thead><tbody>";
foreach ($qslsnotsent as $qsl)
{
$table .= "<tr>";
$timestamp = strtotime($qsl['COL_TIME_ON']);
$table .= "<td>".date($custom_date_format, $timestamp)."</td>";
$table .= "<td>".date('H:i', $timestamp)."</td>";
$table .= "<td><a href=\"javascript:displayQso(" . $qsl['COL_PRIMARY_KEY'] . ")\">" . str_replace("0","&Oslash;",strtoupper($qsl['COL_CALL'])) . "</a></td>";
$table .= "<td>".$qsl['COL_MODE']."</td>";
if(isset($qsl['COL_SUBMODE'])) {
$table .= "<td>".$qsl['COL_SUBMODE']."</td>";
} else {
$table .= "<td></td>";
}
$table .= "<td>".$qsl['COL_BAND']."</td>";
$table .= "<td>".$qsl['eqslqthnickname']."</td>";
$table .= "</tr>";
}
$table .= "</tbody></table>";
return $table;
}
function image($id) {
$this->load->library('electronicqsl');
$this->load->model('Eqsl_images');
@ -529,7 +522,6 @@ class eqsl extends CI_Controller {
}
public function tools() {
// Check logged in
$this->load->model('user_model');
if(!$this->user_model->authorize(2)) { $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); redirect('dashboard'); }
@ -543,7 +535,6 @@ class eqsl extends CI_Controller {
}
public function mark_all_sent() {
// Check logged in
$this->load->model('user_model');
if(!$this->user_model->authorize(2)) { $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); redirect('dashboard'); }
@ -557,4 +548,34 @@ class eqsl extends CI_Controller {
redirect('eqsl/tools');
}
/*
* Used for CRON job
*/
public function upload() {
$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);
}
}
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);
$qslsnotsent = $this->eqslmethods_model->eqsl_not_yet_sent($clean_userid);
foreach ($qslsnotsent->result_array() as $qsl) {
$data['user_eqsl_name'] = $qsl['station_callsign'];
$adif = $this->generateAdif($qsl, $data);
$status = $this->uploadQso($adif, $qsl);
}
}
} // end class

查看文件

@ -18,6 +18,61 @@ class Eqslmethods_model extends CI_Model {
$this->db->update($this->config->item('table_name'), $data);
}
function get_eqsl_users() {
$this->db->select('user_eqsl_name, user_eqsl_password, user_id');
$this->db->where('coalesce(user_eqsl_name, "") != ""');
$this->db->where('coalesce(user_eqsl_password, "") != ""');
$query = $this->db->get($this->config->item('auth_table'));
return $query->result();
}
// Show all QSOs we need to send to eQSL
function eqsl_not_yet_sent($userid = null) {
$CI =& get_instance();
if ($userid == null) {
$CI->load->model('logbooks_model');
$logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook'));
} else {
$CI->load->model('Stations');
$stations = $CI->Stations->all_of_user();
$logbooks_locations_array = array();
foreach ($stations->result() as $row) {
array_push($logbooks_locations_array, $row->station_id);
}
}
$this->db->select('station_profile.*, '.$this->config->item('table_name').'.COL_PRIMARY_KEY, '.$this->config->item('table_name').'.COL_TIME_ON, '.$this->config->item('table_name').'.COL_CALL, '.$this->config->item('table_name').'.COL_MODE, '.$this->config->item('table_name').'.COL_SUBMODE, '.$this->config->item('table_name').'.COL_BAND, '.$this->config->item('table_name').'.COL_COMMENT, '.$this->config->item('table_name').'.COL_RST_SENT, '.$this->config->item('table_name').'.COL_PROP_MODE, '.$this->config->item('table_name').'.COL_SAT_NAME, '.$this->config->item('table_name').'.COL_SAT_MODE, '.$this->config->item('table_name').'.COL_QSLMSG');
$this->db->from('station_profile');
$this->db->join($this->config->item('table_name'),'station_profile.station_id = '.$this->config->item('table_name').'.station_id');
$this->db->where("coalesce(station_profile.eqslqthnickname, '') <> ''");
$this->db->where($this->config->item('table_name').'.COL_CALL !=', '');
$this->db->group_start();
$this->db->where($this->config->item('table_name').'.COL_EQSL_QSL_SENT is null');
$this->db->or_where($this->config->item('table_name').'.COL_EQSL_QSL_SENT', '');
$this->db->or_where($this->config->item('table_name').'.COL_EQSL_QSL_SENT', 'R');
$this->db->or_where($this->config->item('table_name').'.COL_EQSL_QSL_SENT', 'Q');
$this->db->or_where($this->config->item('table_name').'.COL_EQSL_QSL_SENT', 'N');
$this->db->group_end();
$this->db->where_in('station_profile.station_id', $logbooks_locations_array);
return $this->db->get();
}
// Mark the QSO as sent to eQSL
function eqsl_mark_sent($primarykey) {
$data = array(
'COL_EQSL_QSLSDATE' => date('Y-m-d H:i:s'), // eQSL doesn't give us a date, so let's use current
'COL_EQSL_QSL_SENT' => 'Y',
);
$this->db->where('COL_PRIMARY_KEY', $primarykey);
$this->db->update($this->config->item('table_name'), $data);
return "eQSL Sent";
}
}
?>

查看文件

@ -2573,20 +2573,6 @@ class Logbook_model extends CI_Model {
return "Updated";
}
// Mark the QSO as sent to eQSL
function eqsl_mark_sent($primarykey) {
$data = array(
'COL_EQSL_QSLSDATE' => date('Y-m-d H:i:s'), // eQSL doesn't give us a date, so let's use current
'COL_EQSL_QSL_SENT' => 'Y',
);
$this->db->where('COL_PRIMARY_KEY', $primarykey);
$this->db->update($this->config->item('table_name'), $data);
return "eQSL Sent";
}
// Get the last date we received an eQSL
function eqsl_last_qsl_rcvd_date($callsign, $nickname) {
$qso_table_name = $this->config->item('table_name');
@ -2637,29 +2623,6 @@ class Logbook_model extends CI_Model {
}
}
// Show all QSOs we need to send to eQSL
function eqsl_not_yet_sent() {
$CI =& get_instance();
$CI->load->model('logbooks_model');
$logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook'));
$this->db->select('station_profile.*, '.$this->config->item('table_name').'.COL_PRIMARY_KEY, '.$this->config->item('table_name').'.COL_TIME_ON, '.$this->config->item('table_name').'.COL_CALL, '.$this->config->item('table_name').'.COL_MODE, '.$this->config->item('table_name').'.COL_SUBMODE, '.$this->config->item('table_name').'.COL_BAND, '.$this->config->item('table_name').'.COL_COMMENT, '.$this->config->item('table_name').'.COL_RST_SENT, '.$this->config->item('table_name').'.COL_PROP_MODE, '.$this->config->item('table_name').'.COL_SAT_NAME, '.$this->config->item('table_name').'.COL_SAT_MODE, '.$this->config->item('table_name').'.COL_QSLMSG');
$this->db->from('station_profile');
$this->db->join($this->config->item('table_name'),'station_profile.station_id = '.$this->config->item('table_name').'.station_id');
$this->db->where("coalesce(station_profile.eqslqthnickname, '') <> ''");
$this->db->where($this->config->item('table_name').'.COL_CALL !=', '');
$this->db->group_start();
$this->db->where($this->config->item('table_name').'.COL_EQSL_QSL_SENT is null');
$this->db->or_where($this->config->item('table_name').'.COL_EQSL_QSL_SENT', '');
$this->db->or_where($this->config->item('table_name').'.COL_EQSL_QSL_SENT', 'R');
$this->db->or_where($this->config->item('table_name').'.COL_EQSL_QSL_SENT', 'Q');
$this->db->or_where($this->config->item('table_name').'.COL_EQSL_QSL_SENT', 'N');
$this->db->group_end();
$this->db->where_in('station_profile.station_id', $logbooks_locations_array);
return $this->db->get();
}
/*
* $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
@ -3901,6 +3864,4 @@ function validateADIFDate($date, $format = 'Ymd')
$d = DateTime::createFromFormat($format, $date);
return $d && $d->format($format) == $date;
}
?>

查看文件

@ -2672,6 +2672,21 @@ function deleteQsl(id) {
</script>
<?php } ?>
<?php if ($this->uri->segment(1) == "eqsl") { ?>
<script>
$('.table').DataTable({
"stateSave": true,
"pageLength": 25,
responsive: false,
"scrollY": "400px",
"scrollCollapse": true,
"paging": false,
"scrollX": true,
});
</script>
<?php } ?>
<?php if ($this->uri->segment(1) == "qslprint") { ?>
<script>
function deleteFromQslQueue(id) {